Skip to main content

PresetStateStore

Struct PresetStateStore 

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

Source

pub fn new() -> Self

Source

pub fn current(&self) -> &PresetState<B, E>

Get a reference to the current active preset’s state.

Source

pub fn current_mut(&mut self) -> &mut PresetState<B, E>

Get a mutable reference to the current active preset’s state.

Source

pub fn active_index(&self) -> u8

Current active preset index.

Source

pub fn save_working(&mut self, working: &PresetState<B, E>)

Save working state into the active preset slot (for serialization without switching).

Source

pub fn clear(&mut self)

Reset all state (presets changed, state is stale).

Source

pub fn set_state(&mut self, index: usize, state: PresetState<B, E>)

Set state for a specific preset slot.

Source

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.

Source

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>

Source

pub const EEPROM_MAX_PRESETS: usize

Maximum presets that fit in 128 bytes for this configuration.

Source

pub fn cleared_eeprom() -> [u8; 128]

Return a cleared EEPROM buffer (for writing after preset upload).

Source

pub fn to_eeprom(&self, buf: &mut [u8; 128])

Serialize entire store to EEPROM buffer (128 bytes). Layout: [magic][active_preset][state0..stateN]

Source

pub fn from_eeprom(buf: &[u8; 128]) -> Option<Self>

Deserialize from EEPROM buffer. Returns None if magic/version doesn’t match.

Trait Implementations§

Source§

impl<const B: usize, const E: usize> Clone for PresetStateStore<B, E>

Source§

fn clone(&self) -> PresetStateStore<B, E>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const B: usize, const E: usize> Default for PresetStateStore<B, E>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<const B: usize, const E: usize> Freeze for PresetStateStore<B, E>

§

impl<const B: usize, const E: usize> RefUnwindSafe for PresetStateStore<B, E>

§

impl<const B: usize, const E: usize> Send for PresetStateStore<B, E>

§

impl<const B: usize, const E: usize> Sync for PresetStateStore<B, E>

§

impl<const B: usize, const E: usize> Unpin for PresetStateStore<B, E>

§

impl<const B: usize, const E: usize> UnsafeUnpin for PresetStateStore<B, E>

§

impl<const B: usize, const E: usize> UnwindSafe for PresetStateStore<B, E>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.