PresetManager

Struct PresetManager 

Source
pub struct PresetManager {
    preset_queue: VecDeque<PathBuf>,
    current_index: usize,
    transition: TransitionState,
    history: History<PathBuf>,
    locked: bool,
    mode: SelectionMode,
    ratings: HashMap<PathBuf, u8>,
    ratings_path: Option<PathBuf>,
}
Expand description

Preset manager handling library navigation, mode/lock/ratings, and crossfade transitions.

Fields§

§preset_queue: VecDeque<PathBuf>

Library queue — populated at startup by walking the preset dir.

§current_index: usize

Cursor into preset_queue. Sequential navigation walks this; random navigation rewrites it before reading.

§transition: TransitionState

Crossfade transition state.

§history: History<PathBuf>

History ring — records every preset actually loaded via [advance] (and friends) so Backspace can walk back through what the user has seen, not just the queue order.

§locked: bool

Scroll Lock state. When true, [advance] / [retreat] return None so the engine keeps showing the current preset.

§mode: SelectionMode

Random vs sequential selection mode.

§ratings: HashMap<PathBuf, u8>

Per-preset rating in [0, 5]. Unrated entries fall back to the default 3 when sampling. Sampling weight is 2^rating.

§ratings_path: Option<PathBuf>

Where ratings persist. None disables persistence (tests).

Implementations§

Source§

impl PresetManager

Source

pub fn new() -> Self

Create a new preset manager with no persistence.

Source

pub fn with_history_size(history_size: usize) -> Self

Create a new preset manager with a specific history cap.

Source

pub fn attach_ratings_file(&mut self, path: PathBuf)

Point the manager at a TOML file for persisted ratings and load whatever’s already on disk. Missing / unreadable / unparseable files fall back to “no ratings” — the call never fails.

Source

pub fn add_preset<P: AsRef<Path>>(&mut self, path: P)

Add a preset to the queue.

Source

pub fn add_presets<P: AsRef<Path>>(&mut self, paths: &[P])

Add multiple presets to the queue.

Source

pub fn next_preset(&mut self) -> Option<&Path>

Get the next preset path (sequential walk, ignores mode / lock).

Source

pub fn prev_preset(&mut self) -> Option<&Path>

Get the previous preset path (sequential walk, ignores mode / lock).

Source

pub fn current_preset(&self) -> Option<&Path>

Get the current preset path.

Source

pub fn random_preset(&mut self) -> Option<&Path>

Pick a uniformly-random preset (ignores ratings, mode, lock). Used by the beat detector for forced cuts where the user has asked for randomness independent of selection mode.

Source

pub fn random_weighted_by_rating(&mut self) -> Option<&Path>

Pick a rating-weighted random preset. Probability of selecting a preset is proportional to 2^rating(preset) — a rating-5 preset is 32× more likely than a rating-0 one. Unrated presets use DEFAULT_RATING.

Source

pub fn advance(&mut self) -> Option<PathBuf>

High-level “user pressed Space / Right arrow”: respect lock, dispatch on mode, record the result in history. Returns None when locked, when the queue is empty, or when the current implementation can’t produce a candidate.

Source

pub fn retreat(&mut self) -> Option<PathBuf>

History-aware “Backspace”: walks the history ring back one entry and returns it. Falls back to the sequential [prev_preset] when the history has no prior entry. Honours the lock.

Source

pub fn is_locked(&self) -> bool

True when preset changes are blocked.

Source

pub fn set_locked(&mut self, locked: bool)

Set the lock state outright (used by Scroll Lock keybind and by the GUI’s startup hydration from Settings::presets.locked).

Source

pub fn toggle_lock(&mut self) -> bool

Flip the lock state and return the new value.

Source

pub fn mode(&self) -> SelectionMode

Source

pub fn set_mode(&mut self, mode: SelectionMode)

Source

pub fn cycle_mode(&mut self) -> SelectionMode

R keybind: cycle Random ↔ Sequential and return the new mode.

Source

pub fn rating(&self, path: &Path) -> u8

Rating of an arbitrary preset path. Unrated → DEFAULT_RATING.

Source

pub fn current_rating(&self) -> Option<u8>

Rating of the currently-cursor’d preset.

Source

pub fn set_rating(&mut self, path: &Path, rating: u8)

Set a preset’s rating (clamped to [0, 5]) and persist.

Source

pub fn nudge_current_rating(&mut self, delta: i32) -> Option<u8>

Nudge the current preset’s rating by delta (+/-), clamped to [0, 5]. Returns the new rating, or None if no current preset.

Source

fn persist_ratings(&self)

Source

pub fn start_transition(&mut self, duration: f32)

Start a transition to the next preset.

Source

pub fn update_transition(&mut self, delta_time: f32) -> bool

Update transition state.

Source

pub fn transition_progress(&self) -> f32

Get transition progress (0.0 to 1.0).

Source

pub fn is_transitioning(&self) -> bool

Check if transitioning.

Source

pub fn clear(&mut self)

Clear all presets.

Source

pub fn preset_count(&self) -> usize

Get number of presets in queue.

Source

pub fn shuffle(&mut self)

Shuffle presets.

Trait Implementations§

Source§

impl Default for PresetManager

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
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,