Skip to main content

BarSpectrum

Struct BarSpectrum 

Source
pub struct BarSpectrum { /* private fields */ }
Expand description

Levels as columns rising from the bottom, as cava and a graphic equaliser show a spectrum: each band (from dsp::bands, lowest first, falling under dsp::Falloff for cava’s look) a bar bar_width cells wide, gap cells apart, its top in eighths of a cell.

  • mirror draws the bands twice, the low ones in the middle and the high ones at both edges (cava’s mirrored layout); stereo puts one channel on each side, the left reversed.
  • Levels are scaled from 0 to the loudest band (or range); a level outside is drawn at the end it passes, a NaN as 0.
  • The bars are centred in the width they are given. When they do not fit, the gaps go first, then the bars narrow to a cell, then neighbouring bands share a column (the louder shown).
  • It fills the height it is given (a Layout region, an intuiTUIve node) unless height is set; given none, it is 8 rows. In ASCII, each bar is #s to the nearest whole cell.
use rich::Console;
use rich_ext::chart::BarSpectrum;

let console = Console::builder().width(7).color_system(None).build();
let bars = BarSpectrum::new([1.0, 0.5, 0.25]).range(1.0).height(2);
assert_eq!(console.render_export(&bars), " █     \n █ █ ▄ \n");
// Mirrored: the low bands in the middle.
let console = Console::builder().width(11).color_system(None).build();
let mirrored = bars.mirror(true);
assert_eq!(console.render_export(&mirrored), "    █ █    \n▄ █ █ █ █ ▄\n");

Implementations§

Source§

impl BarSpectrum

Source

pub fn new(bands: impl IntoIterator<Item = f64>) -> Self

A bar per band of bands, lowest frequency first.

Source

pub fn stereo( left: impl IntoIterator<Item = f64>, right: impl IntoIterator<Item = f64>, ) -> Self

Two channels, mirrored: left’s bands from the middle out to the left edge, right’s from the middle to the right edge.

Source

pub fn mirror(self, mirror: bool) -> Self

Draw the bands twice, the low ones in the middle (default false). A stereo spectrum is always mirrored.

Source

pub fn range(self, max: f64) -> Self

The level of a full bar (default: the loudest band). Bars start at 0.

Source

pub fn bar_width(self, cells: usize) -> Self

Cells a bar is wide (default 1, at least 1).

Source

pub fn gap(self, cells: usize) -> Self

Cells between bars (default 1).

Source

pub fn style(self, style: impl Into<String>) -> Self

The bars’ style: a theme key or a definition (default chart.bar).

Source

pub fn charset(self, charset: Charset) -> Self

Which glyphs to draw with (default Charset::Auto: blocks, or ASCII on an ASCII-only console).

Source

pub fn height(self, rows: usize) -> Self

Height in rows (at most 65535), whatever height it is given.

Source

pub fn bands(&self) -> (&[f64], Option<&[f64]>)

The bands, as given: the left channel’s (or the only one), and the right channel’s for a stereo spectrum.

Trait Implementations§

Source§

impl AccessibleText for BarSpectrum

Bar spectrum, 16 bands, mirrored, levels from 0 to 0.8, then the loudest band (Loudest: band 3 of 16, 0.8); a stereo one says each channel’s.

Source§

fn accessible_text(&self, _width: usize) -> String

The content as plain lines, laid out for width where layout matters.
Source§

impl Clone for BarSpectrum

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BarSpectrum

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Draw for BarSpectrum

Source§

fn draw( &self, console: &Console, options: &ConsoleOptions, screen: &mut Screen, rect: Rect, )

Draw into rect of screen, rendered with options (its width and height are the rectangle’s): the cells screen.write_lines(rect, &console.render_lines(self, options, false)) would give.
Source§

impl PartialEq for BarSpectrum

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Renderable for BarSpectrum

Source§

fn rich_render( &self, console: &Console, options: &ConsoleOptions, ) -> Vec<Segment>

Source§

fn measure(&self, _console: &Console, options: &ConsoleOptions) -> Measurement

The (minimum, maximum) cell width this renderable wants. Port of __rich_measure__. The default is what upstream’s Measurement.get returns for a renderable without one: anything from nothing to the whole width, (0, max_width).
Source§

fn fit_to_measurement(&self) -> bool

Whether a top-level Console::print shrinks this renderable to its measured width. Upstream renders every top-level renderable at the full console width, so the default is false; an extension may opt in.
Source§

fn vertical(&self) -> Option<VerticalAlign>

The vertical alignment a Table cell holding this renderable uses in place of its column’s. Upstream reads getattr(renderable, "vertical", None); Align sets it.
Source§

fn print_end_line(&self, _options: &ConsoleOptions) -> bool

Whether a top-level print ends this renderable’s last line. This port’s renderables separate lines, where upstream’s end each line with "\n", so a print adds the final line break. A renderable whose upstream output stops without one (Screen, LiveRender, a Rule whose end has no newline) returns false, and the next output continues its last line. options are the print’s options.
Source§

impl StructuralPartialEq for BarSpectrum

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more