pub struct PresetStateStore<const B: usize = MAX_BUTTONS, const E: usize = MAX_ENCODERS> { /* private fields */ }Expand description
Manages per-preset state and generates recall MIDI on switch.
Implementations§
Source§impl<const B: usize, const E: usize> PresetStateStore<B, E>
impl<const B: usize, const E: usize> PresetStateStore<B, E>
pub fn new() -> Self
Sourcepub fn current(&self) -> &PresetState<B, E>
pub fn current(&self) -> &PresetState<B, E>
Get a reference to the current active preset’s state.
Sourcepub fn current_mut(&mut self) -> &mut PresetState<B, E>
pub fn current_mut(&mut self) -> &mut PresetState<B, E>
Get a mutable reference to the current active preset’s state.
Sourcepub fn active_index(&self) -> u8
pub fn active_index(&self) -> u8
Current active preset index.
Sourcepub fn save_working(&mut self, working: &PresetState<B, E>)
pub fn save_working(&mut self, working: &PresetState<B, E>)
Save working state into the active preset slot (for serialization without switching).
Sourcepub fn set_state(&mut self, index: usize, state: PresetState<B, E>)
pub fn set_state(&mut self, index: usize, state: PresetState<B, E>)
Set state for a specific preset slot.
Sourcepub fn apply_defaults<const A: usize>(&mut self, presets: &[&Preset<B, E, A>])
pub fn apply_defaults<const A: usize>(&mut self, presets: &[&Preset<B, E, A>])
Reset state using preset defaults (after upload / first boot). Each preset’s declared initial state is applied.
Sourcepub fn switch<const A: usize>(
&mut self,
new_preset: u8,
working: &mut PresetState<B, E>,
preset: &Preset<B, E, A>,
) -> Vec<MidiMessage, 16>
pub fn switch<const A: usize>( &mut self, new_preset: u8, working: &mut PresetState<B, E>, preset: &Preset<B, E, A>, ) -> Vec<MidiMessage, 16>
Switch to a new preset. Saves current working state, loads new state, and returns MIDI messages to recall the new preset’s state to external gear.
Source§impl<const B: usize, const E: usize> PresetStateStore<B, E>
impl<const B: usize, const E: usize> PresetStateStore<B, E>
Sourcepub const EEPROM_MAX_PRESETS: usize
pub const EEPROM_MAX_PRESETS: usize
Maximum presets that fit in 128 bytes for this configuration.
Sourcepub fn cleared_eeprom() -> [u8; 128]
pub fn cleared_eeprom() -> [u8; 128]
Return a cleared EEPROM buffer (for writing after preset upload).
Sourcepub fn to_eeprom(&self, buf: &mut [u8; 128])
pub fn to_eeprom(&self, buf: &mut [u8; 128])
Serialize entire store to EEPROM buffer (128 bytes). Layout: [magic][active_preset][state0..stateN]
Sourcepub fn from_eeprom(buf: &[u8; 128]) -> Option<Self>
pub fn from_eeprom(buf: &[u8; 128]) -> Option<Self>
Deserialize from EEPROM buffer. Returns None if magic/version doesn’t match.