|
Zrythm v2.0.0-alpha.1+31.4967fd053471
a highly automated and intuitive digital audio workstation
|
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 |
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:
Definition at line 40 of file chord_audition_state.h.
| 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.
|
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.
| 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.
| velocity | MIDI velocity to use (defaults to kDefaultVelocity). |
| 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.
| 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.
| void zrythm::dsp::ChordAuditionState::stopAll | ( | ) |
Stop all auditioning.
Main thread only. Clears all active pitches.
|
staticconstexpr |
Definition at line 43 of file chord_audition_state.h.