Skip to main content

SnapshotSequencer

Struct SnapshotSequencer 

Source
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

Source

pub fn new() -> Self

Create a new, empty sequencer (no patterns, not running).

Source

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.

Source

pub fn add_snapshot(&mut self, snapshot: Snapshot)

Register or replace a named snapshot.

Source

pub fn get_snapshot(&self, id: &str) -> Option<&Snapshot>

Get a snapshot by ID, if present.

Source

pub fn remove_snapshot(&mut self, id: &str) -> bool

Remove a snapshot by ID. Does not affect existing patterns.

Source

pub fn add_pattern(&mut self, pattern: Pattern)

Register or replace a named pattern.

Source

pub fn get_pattern(&self, id: &str) -> Option<&Pattern>

Get a pattern by ID, if present.

Source

pub fn remove_pattern(&mut self, id: &str) -> bool

Remove a pattern by ID. If it is the active pattern the sequencer stops.

Source

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.

Source

pub fn active_pattern(&self) -> &str

Active pattern ID.

Source

pub fn start(&mut self)

Start or resume the sequencer from the current step.

Source

pub fn stop(&mut self)

Pause the sequencer (keeps current step position).

Source

pub fn reset(&mut self, sample_pos: u64)

Reset the sequencer to step 0 at the given sample position.

Source

pub fn is_running(&self) -> bool

Whether the sequencer is running.

Source

pub fn current_step(&self) -> usize

Index of the current step within the active pattern.

Source

pub fn latest_beat_position(&self) -> f32

Latest beat position received via tick_ext.

Updated on every clock tick; 0.0 if no tempo data or tick is used.

Source

pub fn is_new_beat(&self) -> bool

Whether the latest clock tick was at a beat boundary.

Source

pub fn is_new_bar(&self) -> bool

Whether the latest clock tick was at a bar boundary.

Source

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.

Source

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

Source§

fn clone(&self) -> SnapshotSequencer

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for SnapshotSequencer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SnapshotSequencer

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> AsAny for T
where T: 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert to &dyn std::any::Any
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert to &mut dyn std::any::Any
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V