Struct Quantizer

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

A quantizer which converts smooth inputs into stairsteps is represented here.

Implementations§

Source§

impl Quantizer

Source

pub fn new() -> Self

Quantizer::new() is a new quantizer with all notes allowed.

Source

pub fn convert(&mut self, v_in: f32) -> Conversion

q.convert(val) is the quantized version of the input value.

The input is split into a stairstep component and fractional component.

§Arguments
  • v_in - the value to quantize, in volts, clamped to [0.0, V_MAX]
§Returns
  • Conversion - the input split into a stairstep and fractional portion
§Examples
let mut q = quantizer::Quantizer::new();
// input is a bit above C#, but C# is the closest note number
assert_eq!(q.convert(1.5 / 12.).note_num, 1);

// same input, but since C# is forbidden now D is the closest note
q.forbid(&[quantizer::Note::CSHARP]);
assert_eq!(q.convert(1.5 / 12.).note_num, 2);
Source

pub fn allow(&mut self, notes: &[Note])

q.allow(ns) allows notes ns, meaning they will be included in conversions

Any notes in ns that are already allowed are left unchanged

Source

pub fn forbid(&mut self, notes: &[Note])

q.forbid(ns) forbids notes ns, they will not be included in conversions even if they are the nearest note

Any notes in ns that are already forbidden are left unchanged

At least one note must always be left allowed. If ns would forbid every note, the last note in ns will not be forbidden and instead will be left allowed.

Source

pub fn is_allowed(&self, note: Note) -> bool

q.is_allowed(n) is true iff note n is allowed

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.