pub struct SnapshotSequencer { /* private fields */ }Expand description
The core sequencer state machine.
Driven by incoming CLOCK_TICK telemetry from the audio thread. Call
tick or tick_ext every time a clock
sample-position arrives; the sequencer checks whether the current step’s
duration has elapsed and advances if so, returning the p-lock parameter
commands for the new step.
§Thread safety
SnapshotSequencer is Send but not Sync. It should live inside
a single task (typically the tokio task that drains the telemetry
receiver). External control (start/stop/pattern change) uses a command
channel (see SequencerHandle).
Implementations§
Source§impl SnapshotSequencer
impl SnapshotSequencer
Sourcepub fn with_lib(snapshots: Vec<Snapshot>, patterns: Vec<Pattern>) -> Self
pub fn with_lib(snapshots: Vec<Snapshot>, patterns: Vec<Pattern>) -> Self
Create a sequencer pre-loaded with snapshots and patterns.
The first pattern in the vec becomes the active pattern.
Sourcepub fn add_snapshot(&mut self, snapshot: Snapshot)
pub fn add_snapshot(&mut self, snapshot: Snapshot)
Register or replace a named snapshot.
Sourcepub fn get_snapshot(&self, id: &str) -> Option<&Snapshot>
pub fn get_snapshot(&self, id: &str) -> Option<&Snapshot>
Get a snapshot by ID, if present.
Sourcepub fn remove_snapshot(&mut self, id: &str) -> bool
pub fn remove_snapshot(&mut self, id: &str) -> bool
Remove a snapshot by ID. Does not affect existing patterns.
Sourcepub fn add_pattern(&mut self, pattern: Pattern)
pub fn add_pattern(&mut self, pattern: Pattern)
Register or replace a named pattern.
Sourcepub fn get_pattern(&self, id: &str) -> Option<&Pattern>
pub fn get_pattern(&self, id: &str) -> Option<&Pattern>
Get a pattern by ID, if present.
Sourcepub fn remove_pattern(&mut self, id: &str) -> bool
pub fn remove_pattern(&mut self, id: &str) -> bool
Remove a pattern by ID. If it is the active pattern the sequencer stops.
Sourcepub fn set_active_pattern(&mut self, id: &str)
pub fn set_active_pattern(&mut self, id: &str)
Switch to a different pattern (may be empty).
Resets the step counter to 0. If the pattern does not exist the call is ignored.
Sourcepub fn active_pattern(&self) -> &str
pub fn active_pattern(&self) -> &str
Active pattern ID.
Sourcepub fn reset(&mut self, sample_pos: u64)
pub fn reset(&mut self, sample_pos: u64)
Reset the sequencer to step 0 at the given sample position.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Whether the sequencer is running.
Sourcepub fn current_step(&self) -> usize
pub fn current_step(&self) -> usize
Index of the current step within the active pattern.
Sourcepub fn latest_beat_position(&self) -> f32
pub fn latest_beat_position(&self) -> f32
Sourcepub fn is_new_beat(&self) -> bool
pub fn is_new_beat(&self) -> bool
Whether the latest clock tick was at a beat boundary.
Sourcepub fn is_new_bar(&self) -> bool
pub fn is_new_bar(&self) -> bool
Whether the latest clock tick was at a bar boundary.
Sourcepub fn tick(
&mut self,
sample_pos: u64,
sample_rate: f32,
tempo: f32,
) -> Vec<SetParameter>
pub fn tick( &mut self, sample_pos: u64, sample_rate: f32, tempo: f32, ) -> Vec<SetParameter>
Advance the sequencer by one clock tick (basic version).
Convenience wrapper around tick_ext that passes
default beat info (beat_position=0, no beat/bar boundaries).
Prefer tick_ext when beat-aware CLOCK_TICK telemetry is available.
Sourcepub fn tick_ext(
&mut self,
sample_pos: u64,
sample_rate: f32,
tempo: f32,
beat_position: f32,
is_new_beat: bool,
is_new_bar: bool,
) -> Vec<SetParameter>
pub fn tick_ext( &mut self, sample_pos: u64, sample_rate: f32, tempo: f32, beat_position: f32, is_new_beat: bool, is_new_bar: bool, ) -> Vec<SetParameter>
Advance the sequencer by one clock tick with beat-aware telemetry.
Call this from the telemetry listener task every time a CLOCK_TICK
event arrives from the audio thread. The extended parameters
(beat_position, is_new_beat, is_new_bar) are stored in the
sequencer state and can be queried by algorithmic sequencer logic
(see latest_beat_position,
is_new_beat,
is_new_bar).
Returns a batch of SetParameter values to push when a step
boundary is crossed, or an empty Vec if no step change occurred.
Trait Implementations§
Source§impl Clone for SnapshotSequencer
impl Clone for SnapshotSequencer
Source§fn clone(&self) -> SnapshotSequencer
fn clone(&self) -> SnapshotSequencer
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more