pub struct Quantizer { /* private fields */ }
Expand description
A quantizer which converts smooth inputs into stairsteps is represented here.
Implementations§
Source§impl Quantizer
impl Quantizer
Sourcepub fn convert(&mut self, v_in: f32) -> Conversion
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);
Sourcepub fn allow(&mut self, notes: &[Note])
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
Sourcepub fn forbid(&mut self, notes: &[Note])
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.
Sourcepub fn is_allowed(&self, note: Note) -> bool
pub fn is_allowed(&self, note: Note) -> bool
q.is_allowed(n)
is true iff note n
is allowed
Auto Trait Implementations§
impl Freeze for Quantizer
impl RefUnwindSafe for Quantizer
impl Send for Quantizer
impl Sync for Quantizer
impl Unpin for Quantizer
impl UnwindSafe for Quantizer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more