Skip to main content

PatternBlock

Struct PatternBlock 

Source
pub struct PatternBlock {
Show 14 fields pub steps: u8, pub rate: Rate, pub swing: u8, pub base_vel: u8, pub accent_vel: u8, pub default_gate: u8, pub mode: Mode, pub tonic: u8, pub lanes: [Lane; 8], pub playing: bool, pub pending_slot: Option<u8>, pub switch_quant: SwitchQuant, pub chain: [ChainEntry; 16], pub chain_len: u8,
}
Expand description

A whole pattern, as the audio thread holds it.

Every field is a plain scalar or an array of them: the type is Copy, nothing in it points anywhere, and a command carrying one is a memcpy.

Five of the fields — playing, pending_slot, switch_quant, chain and chain_len — describe the track rather than this pattern. They ride on the block because a block is how the UI thread says anything to the audio thread about a sequencer, and PatternPlayer::apply takes the most recent word on them from whichever slot arrived last. The UI keeps its own single copy and writes it into every block it sends, which is what phosphor-app’s single dispatch function exists to guarantee.

Fields§

§steps: u8

How many steps play, one of STEP_COUNTS.

Shortening a pattern masks: steps past the end keep their contents and come back when the pattern is lengthened again.

§rate: Rate§swing: u8

Swing as a percentage, 50 (straight) to 75 (fully triplet).

§base_vel: u8

Velocity of an ordinary step.

§accent_vel: u8

Velocity of an accented step.

§default_gate: u8

The gate a newly enabled step inherits.

§mode: Mode

The scale pitch walking and the diatonic chords work in.

§tonic: u8

Tonic pitch class for mode, 0..=11. Named tonic and not key because Step::key is a different thing one field away.

§lanes: [Lane; 8]§playing: bool

Whether this sequencer runs when the transport does.

§pending_slot: Option<u8>

A slot queued to take over at the next SwitchQuant point.

Queueing the slot that is already playing is not a switch, which is what makes a stale queue on the UI side harmless.

§switch_quant: SwitchQuant§chain: [ChainEntry; 16]§chain_len: u8

How many entries of chain are real. Zero means no chain, and the live slot is whatever was last selected or queued.

Implementations§

Source§

impl PatternBlock

Source

pub const SIZE: usize

How many bytes one of these is, and therefore what a SetPattern command costs to sit in the queue.

Source

pub const MIN_SWING: u8 = 50

Lowest swing setting: straight.

Source

pub const MAX_SWING: u8 = 75

Highest swing setting. At 75 the pair is 3:1, which is a triplet feel; past it the second note lands on the following step and the pattern reads as a different rhythm rather than a swung one.

Source

pub const fn empty() -> Self

An empty 16-step pattern at a sixteenth, straight, not running.

Source

pub fn step_count(&self) -> usize

How many steps actually play. Always at least one, never more than MAX_STEPS — a length out of range would otherwise index off the end of a lane or divide by zero.

Source

pub fn ticks_per_step(&self) -> i64

Source

pub fn length_ticks(&self) -> i64

One time through, in ticks.

Source

pub fn swing_offset(&self, step_index: usize) -> i64

How far an odd-numbered step is pushed late, in ticks.

MPC-style: the offset is a fraction of two steps, so 75% puts the off-beat three quarters of the way through the pair — a triplet feel — and 50% is straight. Integer arithmetic on purpose: the bounce and the live player run this same expression, so “the bounce swings identically” needs no tolerance at all.

Even step indices are never offset, which is what keeps the downbeat where the transport says it is.

Source

pub fn onset(&self, origin: i64, index: i64) -> i64

The tick step index fires at, counting from origin.

index is a global step number and may run past the end of the pattern or before its start: index 17 of a 16-step pattern is step 1 of the second time through.

Source

pub fn step_at(&self, origin: i64, tick: i64) -> usize

Which step is under tick, counting from origin. Swing is not applied: this is where the playhead is, not when a note fires.

Source

pub fn lane_audible(&self, lane: usize) -> bool

Whether a lane sounds, given the pattern’s mute and solo state.

Source

pub fn chain_entries(&self) -> &[ChainEntry]

The chain as real entries, ignoring anything past chain_len.

Trait Implementations§

Source§

impl Clone for PatternBlock

Source§

fn clone(&self) -> PatternBlock

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 Copy for PatternBlock

Source§

impl Debug for PatternBlock

Source§

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

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

impl Default for PatternBlock

Source§

fn default() -> Self

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

impl Eq for PatternBlock

Source§

impl PartialEq for PatternBlock

Source§

fn eq(&self, other: &PatternBlock) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for PatternBlock

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
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<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more