Skip to main content

MidiLearn

Struct MidiLearn 

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

MIDI Learn engine.

Implementations§

Source§

impl MidiLearn

Source

pub fn new() -> Self

Creates a new MIDI Learn engine.

Source

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 identifier
  • min_value - Minimum parameter value
  • max_value - Maximum parameter value
  • curve - 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_cutoff
Source

pub fn cancel_learn(&mut self)

Exits learn mode without creating a mapping.

Source

pub fn is_learning(&self) -> bool

Checks if currently in learn mode.

Source

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);
Source

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 identifier
  • min_value - Minimum parameter value
  • max_value - Maximum parameter value
  • curve - Mapping curve type
Source

pub fn remove_mapping(&mut self, channel: u8, cc: u8) -> Option<MidiMapping>

Removes a mapping.

§Arguments
  • channel - MIDI channel (1-16)
  • cc - MIDI CC number (0-127)
§Returns

The removed mapping, or None if no mapping existed.

Source

pub fn get_mapping(&self, channel: u8, cc: u8) -> Option<&MidiMapping>

Gets a mapping.

Source

pub fn mappings(&self) -> impl Iterator<Item = &MidiMapping>

Gets all mappings.

Source

pub fn clear_mappings(&mut self)

Clears all mappings.

Source

pub fn to_json(&self) -> Result<String, Error>

Saves mappings to JSON.

Source

pub fn from_json(&mut self, json: &str) -> Result<(), Error>

Loads mappings from JSON.

Trait Implementations§

Source§

impl Default for MidiLearn

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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.