Zrythm v2.0.0-alpha.1+31.4967fd053471
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
chord_audition_state.h
1// SPDX-FileCopyrightText: © 2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "dsp/chord_descriptor.h"
7#include "dsp/graph_node.h"
8#include "dsp/midi_event_buffer.h"
9
10#include <boost/container/static_vector.hpp>
11#include <farbot/RealtimeObject.hpp>
12
13namespace zrythm::dsp
14{
15
41{
42public:
43 static constexpr midi_byte_t kDefaultVelocity = 100;
44
46 {
47 std::uint8_t pitch;
48 std::uint8_t velocity;
49 bool operator== (const PitchEntry &) const = default;
50 };
51
57 using ActivePitches = boost::container::static_vector<PitchEntry, 128>;
58
67 void start (
68 const ChordDescriptor &descriptor,
69 midi_byte_t velocity = kDefaultVelocity);
70
78 void stop (const ChordDescriptor &descriptor);
79
86 void stop (const ChordDescriptor::ChordPitches &pitches);
87
93 void stopAll ();
94
101 void process (
102 MidiEventBuffer &out_events,
103 const graph::ProcessBlockInfo &time_nfo) noexcept [[clang::nonblocking]];
104
105private:
109 struct ActiveChordEntry
110 {
112 midi_byte_t velocity;
113 };
114
120 void rebuild_active_pitches ();
121
122 static constexpr size_t kMaxActiveChords = 32;
123
129 boost::container::static_vector<ActiveChordEntry, kMaxActiveChords>
130 active_chords_;
131
135 farbot::RealtimeObject<
137 farbot::RealtimeObjectOptions::nonRealtimeMutatable>
138 active_pitches_;
139
143 ActivePitches sounding_pitches_;
144};
145
146} // namespace zrythm::dsp
Realtime-safe chord audition state machine with polyphonic support.
void stopAll()
Stop all auditioning.
void process(MidiEventBuffer &out_events, const graph::ProcessBlockInfo &time_nfo) noexcept
Process audition state and generate MIDI events.
boost::container::static_vector< PitchEntry, 128 > ActivePitches
Merged pitch set shared between main and audio threads.
void stop(const ChordDescriptor &descriptor)
Stop auditioning a chord.
void stop(const ChordDescriptor::ChordPitches &pitches)
Stop auditioning by exact pitches.
void start(const ChordDescriptor &descriptor, midi_byte_t velocity=kDefaultVelocity)
Start auditioning a chord.
Describes a musical chord by its root note, type, accent, inversion, and optional bass note.
Packed contiguous buffer for RT MIDI events.
std::uint8_t midi_byte_t
MIDI byte.
Definition midi.h:43
Stack-allocated container for chord MIDI pitches.
Common struct to pass around during processing to avoid repeating the data in function arguments.
Definition graph_node.h:51