Struct synth_utils::ribbon_controller::RibbonController
source · pub struct RibbonController<const BUFFER_CAPACITY: usize> { /* private fields */ }Expand description
A synthesizer ribbon controller is represented here.
It is expected to use the provided sample_rate_to_capacity(sr) const function to calculate the const generic
BUFFER_CAPACITY argument. If in the future Rust offers a way to calculate the buffer capacity in a more
straightforward way this should be changed.
Implementations§
source§impl<const BUFFER_CAPACITY: usize> RibbonController<BUFFER_CAPACITY>
impl<const BUFFER_CAPACITY: usize> RibbonController<BUFFER_CAPACITY>
sourcepub fn new(
sample_rate_hz: f32,
softpot_ohms: f32,
dropper_resistor_ohms: f32,
pullup_resistor_ohms: f32
) -> Self
pub fn new( sample_rate_hz: f32, softpot_ohms: f32, dropper_resistor_ohms: f32, pullup_resistor_ohms: f32 ) -> Self
Ribbon::new(sr, sp, dr, pu) is a new Ribbon controller
Arguments:
-
sample_rate_hz- The sample rate in Hertz -
softpot_ohms- The end-to-end resistance of the softpot used, typically 10k or 20k -
dropper_resistor_ohms- The value of the resistor which sits between the top of the softpot and the positive voltage reference. -
pullup_resistor_ohms- The value of the wiper pullup reistor, shoudl be at least 10x softpot_ohms or larger
sourcepub fn poll(&mut self, raw_adc_value: f32)
pub fn poll(&mut self, raw_adc_value: f32)
rib.poll(raw_adc_value) updates the controller by polling the raw ADC signal. Must be called at the sample rate
Arguments
raw_adc_value- the raw ADC signal to poll in[0.0, 1.0], represents the finger position on the ribbon. Inputs outside of the range[0.0, 1.0]are undefined. Note that a small portion of the range at the top near +1.0 is expected to be “eaten” by the series resistor
sourcepub fn value(&self) -> f32
pub fn value(&self) -> f32
rib.value() is the current position value of the ribbon in [0.0, 1.0]
If the user’s finger is not pressing on the ribbon, the last valid value before they lifted their finger is returned.
The value is expanded to take up the whole [0.0, 1.0]range, so even though the input will not quite reach
+1.0 at the top end (due to the series resistance) the output will reach or at least come very close to +1.0
sourcepub fn finger_is_pressing(&self) -> bool
pub fn finger_is_pressing(&self) -> bool
rib.finger_is_pressing() is true iff the user is pressing on the ribbon.
sourcepub fn finger_just_pressed(&mut self) -> bool
pub fn finger_just_pressed(&mut self) -> bool
rib.finger_just_pressed() is true iff the user has just pressed the ribbon after having not touched it.
Self clearing
sourcepub fn finger_just_released(&mut self) -> bool
pub fn finger_just_released(&mut self) -> bool
rib.finger_just_released() is true iff the user has just lifted their finger off the ribbon.
Self clearing