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: usizeCursor into preset_queue. Sequential navigation walks this;
random navigation rewrites it before reading.
transition: TransitionStateCrossfade 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: boolScroll Lock state. When true, [advance] / [retreat] return
None so the engine keeps showing the current preset.
mode: SelectionModeRandom 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
impl PresetManager
Sourcepub fn with_history_size(history_size: usize) -> Self
pub fn with_history_size(history_size: usize) -> Self
Create a new preset manager with a specific history cap.
Sourcepub fn attach_ratings_file(&mut self, path: PathBuf)
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.
Sourcepub fn add_preset<P: AsRef<Path>>(&mut self, path: P)
pub fn add_preset<P: AsRef<Path>>(&mut self, path: P)
Add a preset to the queue.
Sourcepub fn add_presets<P: AsRef<Path>>(&mut self, paths: &[P])
pub fn add_presets<P: AsRef<Path>>(&mut self, paths: &[P])
Add multiple presets to the queue.
Sourcepub fn next_preset(&mut self) -> Option<&Path>
pub fn next_preset(&mut self) -> Option<&Path>
Get the next preset path (sequential walk, ignores mode / lock).
Sourcepub fn prev_preset(&mut self) -> Option<&Path>
pub fn prev_preset(&mut self) -> Option<&Path>
Get the previous preset path (sequential walk, ignores mode / lock).
Sourcepub fn current_preset(&self) -> Option<&Path>
pub fn current_preset(&self) -> Option<&Path>
Get the current preset path.
Sourcepub fn random_preset(&mut self) -> Option<&Path>
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.
Sourcepub fn random_weighted_by_rating(&mut self) -> Option<&Path>
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.
Sourcepub fn advance(&mut self) -> Option<PathBuf>
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.
Sourcepub fn retreat(&mut self) -> Option<PathBuf>
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.
Sourcepub fn set_locked(&mut self, locked: bool)
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).
Sourcepub fn toggle_lock(&mut self) -> bool
pub fn toggle_lock(&mut self) -> bool
Flip the lock state and return the new value.
pub fn mode(&self) -> SelectionMode
pub fn set_mode(&mut self, mode: SelectionMode)
Sourcepub fn cycle_mode(&mut self) -> SelectionMode
pub fn cycle_mode(&mut self) -> SelectionMode
R keybind: cycle Random ↔ Sequential and return the new mode.
Sourcepub fn rating(&self, path: &Path) -> u8
pub fn rating(&self, path: &Path) -> u8
Rating of an arbitrary preset path. Unrated → DEFAULT_RATING.
Sourcepub fn current_rating(&self) -> Option<u8>
pub fn current_rating(&self) -> Option<u8>
Rating of the currently-cursor’d preset.
Sourcepub fn set_rating(&mut self, path: &Path, rating: u8)
pub fn set_rating(&mut self, path: &Path, rating: u8)
Set a preset’s rating (clamped to [0, 5]) and persist.
Sourcepub fn nudge_current_rating(&mut self, delta: i32) -> Option<u8>
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.
fn persist_ratings(&self)
Sourcepub fn start_transition(&mut self, duration: f32)
pub fn start_transition(&mut self, duration: f32)
Start a transition to the next preset.
Sourcepub fn update_transition(&mut self, delta_time: f32) -> bool
pub fn update_transition(&mut self, delta_time: f32) -> bool
Update transition state.
Sourcepub fn transition_progress(&self) -> f32
pub fn transition_progress(&self) -> f32
Get transition progress (0.0 to 1.0).
Sourcepub fn is_transitioning(&self) -> bool
pub fn is_transitioning(&self) -> bool
Check if transitioning.
Sourcepub fn preset_count(&self) -> usize
pub fn preset_count(&self) -> usize
Get number of presets in queue.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PresetManager
impl RefUnwindSafe for PresetManager
impl Send for PresetManager
impl Sync for PresetManager
impl Unpin for PresetManager
impl UnwindSafe for PresetManager
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
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().