pub struct MidiLearn { /* private fields */ }Expand description
MIDI Learn engine.
Implementations§
Source§impl MidiLearn
impl MidiLearn
Sourcepub fn start_learn(
&mut self,
param_id: impl Into<String>,
min_value: f32,
max_value: f32,
curve: MappingCurve,
)
pub fn start_learn( &mut self, param_id: impl Into<String>, min_value: f32, max_value: f32, curve: MappingCurve, )
Enters learn mode for a parameter.
The next MIDI CC message received will be mapped to this parameter.
§Arguments
param_id- Parameter identifiermin_value- Minimum parameter valuemax_value- Maximum parameter valuecurve- Mapping curve type
§Example
use aether_midi::{MidiLearn, MappingCurve};
let mut learn = MidiLearn::new();
// Enter learn mode for filter cutoff
learn.start_learn("filter_cutoff", 20.0, 20000.0, MappingCurve::Exponential);
// User moves a MIDI controller...
// The next CC message will be mapped to filter_cutoffSourcepub fn cancel_learn(&mut self)
pub fn cancel_learn(&mut self)
Exits learn mode without creating a mapping.
Sourcepub fn is_learning(&self) -> bool
pub fn is_learning(&self) -> bool
Checks if currently in learn mode.
Sourcepub fn process_cc(
&mut self,
channel: u8,
cc: u8,
value: u8,
) -> Option<(String, f32)>
pub fn process_cc( &mut self, channel: u8, cc: u8, value: u8, ) -> Option<(String, f32)>
Processes a MIDI CC message.
If in learn mode, creates a mapping. Otherwise, applies existing mappings.
§Arguments
channel- MIDI channel (1-16)cc- MIDI CC number (0-127)value- MIDI CC value (0-127)
§Returns
If a mapping exists (or was just created), returns Some((param_id, mapped_value)).
Otherwise returns None.
§Example
use aether_midi::{MidiLearn, MappingCurve};
let mut learn = MidiLearn::new();
// Enter learn mode
learn.start_learn("gain", 0.0, 1.0, MappingCurve::Linear);
// User moves CC 7 on channel 1
let result = learn.process_cc(1, 7, 64);
assert!(result.is_some());
let (param_id, value) = result.unwrap();
assert_eq!(param_id, "gain");
assert!((value - 0.5).abs() < 0.01); // 64/127 ≈ 0.5
// Now CC 7 is mapped to gain
let result = learn.process_cc(1, 7, 127);
assert!(result.is_some());
let (param_id, value) = result.unwrap();
assert_eq!(param_id, "gain");
assert!((value - 1.0).abs() < 0.01);Sourcepub fn add_mapping(
&mut self,
channel: u8,
cc: u8,
param_id: impl Into<String>,
min_value: f32,
max_value: f32,
curve: MappingCurve,
)
pub fn add_mapping( &mut self, channel: u8, cc: u8, param_id: impl Into<String>, min_value: f32, max_value: f32, curve: MappingCurve, )
Adds a mapping manually (without learn mode).
§Arguments
channel- MIDI channel (1-16)cc- MIDI CC number (0-127)param_id- Parameter identifiermin_value- Minimum parameter valuemax_value- Maximum parameter valuecurve- Mapping curve type
Sourcepub fn remove_mapping(&mut self, channel: u8, cc: u8) -> Option<MidiMapping>
pub fn remove_mapping(&mut self, channel: u8, cc: u8) -> Option<MidiMapping>
Sourcepub fn get_mapping(&self, channel: u8, cc: u8) -> Option<&MidiMapping>
pub fn get_mapping(&self, channel: u8, cc: u8) -> Option<&MidiMapping>
Gets a mapping.
Sourcepub fn mappings(&self) -> impl Iterator<Item = &MidiMapping>
pub fn mappings(&self) -> impl Iterator<Item = &MidiMapping>
Gets all mappings.
Sourcepub fn clear_mappings(&mut self)
pub fn clear_mappings(&mut self)
Clears all mappings.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for MidiLearn
impl RefUnwindSafe for MidiLearn
impl Send for MidiLearn
impl Sync for MidiLearn
impl Unpin for MidiLearn
impl UnsafeUnpin for MidiLearn
impl UnwindSafe for MidiLearn
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