Zrythm v2.0.0-alpha.1+31.4967fd053471
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
zrythm::dsp::ChordAuditionState Class Reference

Realtime-safe chord audition state machine with polyphonic support. More...

#include <src/dsp/chord_audition_state.h>

Data Structures

struct  PitchEntry

Public Types

using ActivePitches = boost::container::static_vector<PitchEntry, 128>
 Merged pitch set shared between main and audio threads.

Public Member Functions

void start (const ChordDescriptor &descriptor, midi_byte_t velocity=kDefaultVelocity)
 Start auditioning a chord.
void stop (const ChordDescriptor &descriptor)
 Stop auditioning a chord.
void stop (const ChordDescriptor::ChordPitches &pitches)
 Stop auditioning by exact pitches.
void stopAll ()
 Stop all auditioning.
void process (MidiEventBuffer &out_events, const graph::ProcessBlockInfo &time_nfo) noexcept
 Process audition state and generate MIDI events.

Static Public Attributes

static constexpr midi_byte_t kDefaultVelocity = 100

Detailed Description

Realtime-safe chord audition state machine with polyphonic support.

Supports multiple simultaneous chords (e.g., triggering from different pads or an external device). Pitches shared between chords are reference-counted so that stopping one chord doesn't cut off a pitch still used by another.

Retrigger behavior: When the active pitch set changes, process() sends note-offs for all previously sounding pitches and note-ons for all currently desired pitches, even pitches that are present in both sets. This "full retrigger" design is intentional — it ensures a clean envelope reset on every chord change.

Shared pitch velocity: When multiple active chords share a pitch, the velocity from whichever chord was started first wins. This self-corrects when any chord stops, because the full retrigger resends all remaining pitches with their correct velocities.

Thread safety:

  • start() and stop() are called from the main thread (non-realtime).
  • process() is called from the audio thread (realtime).
  • Active pitches are shared via farbot::RealtimeObject (lock-free).

Definition at line 40 of file chord_audition_state.h.

Member Typedef Documentation

◆ ActivePitches

using zrythm::dsp::ChordAuditionState::ActivePitches = boost::container::static_vector<PitchEntry, 128>

Merged pitch set shared between main and audio threads.

Sized for the full MIDI pitch range (128 unique pitches).

Definition at line 57 of file chord_audition_state.h.

Member Function Documentation

◆ process()

void zrythm::dsp::ChordAuditionState::process ( MidiEventBuffer & out_events,
const graph::ProcessBlockInfo & time_nfo )
noexcept

Process audition state and generate MIDI events.

Audio thread only. Diffs current active pitches against what is sounding. Sends note-offs for removed pitches and note-ons for added pitches.

◆ start()

void zrythm::dsp::ChordAuditionState::start ( const ChordDescriptor & descriptor,
midi_byte_t velocity = kDefaultVelocity )

Start auditioning a chord.

Main thread only. Adds the chord's pitches to the active set. Can be called multiple times for different (or same) chords.

Parameters
velocityMIDI velocity to use (defaults to kDefaultVelocity).

◆ stop() [1/2]

void zrythm::dsp::ChordAuditionState::stop ( const ChordDescriptor & descriptor)

Stop auditioning a chord.

Main thread only. Removes one matching chord entry from the active set. Shared pitches still used by other active chords will remain sounding. If no matching chord is found, this is a no-op.

◆ stop() [2/2]

void zrythm::dsp::ChordAuditionState::stop ( const ChordDescriptor::ChordPitches & pitches)

Stop auditioning by exact pitches.

Main thread only. As above, but matches on pitches directly, so a caller does not need to keep a (non-copyable) ChordDescriptor around.

◆ stopAll()

void zrythm::dsp::ChordAuditionState::stopAll ( )

Stop all auditioning.

Main thread only. Clears all active pitches.

Field Documentation

◆ kDefaultVelocity

midi_byte_t zrythm::dsp::ChordAuditionState::kDefaultVelocity = 100
staticconstexpr

Definition at line 43 of file chord_audition_state.h.


The documentation for this class was generated from the following file: