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

Lock-free SPSC buffer for MIDI events between the MIDI device thread and the audio thread. More...

#include <src/dsp/midi_device_buffer.h>

Public Member Functions

 MidiDeviceBuffer (const MidiDeviceBuffer &)=delete
MidiDeviceBuffer & operator= (const MidiDeviceBuffer &)=delete
 MidiDeviceBuffer (MidiDeviceBuffer &&)=delete
MidiDeviceBuffer & operator= (MidiDeviceBuffer &&)=delete
bool push (juce::MidiMessage &&message)
 Push a MIDI message onto the queue.
bool push (const juce::MidiMessage &message)
void drain (juce::MidiBuffer &output, units::sample_rate_t sample_rate, units::sample_u32_t nframes, std::optional< units::precise_second_t > block_start_time=std::nullopt) noexcept
 Drain all queued events into output, converting timestamps to sample offsets within the current audio block.
void clear () noexcept
 Discard all pending events without processing.

Static Public Attributes

static constexpr size_t kCapacity = 4096

Detailed Description

Lock-free SPSC buffer for MIDI events between the MIDI device thread and the audio thread.

MIDI thread calls push() with juce::MidiMessage objects carrying JUCE timestamps (seconds from Time::getMillisecondCounterHiRes() * 0.001).

Audio thread calls drain() to convert timestamps to sample offsets and append events to a juce::MidiBuffer.

Definition at line 25 of file midi_device_buffer.h.

Member Function Documentation

◆ clear()

void zrythm::dsp::MidiDeviceBuffer::clear ( )
noexcept

Discard all pending events without processing.

Called from the audio thread. RT-safe.

◆ drain()

void zrythm::dsp::MidiDeviceBuffer::drain ( juce::MidiBuffer & output,
units::sample_rate_t sample_rate,
units::sample_u32_t nframes,
std::optional< units::precise_second_t > block_start_time = std::nullopt )
noexcept

Drain all queued events into output, converting timestamps to sample offsets within the current audio block.

Called from the audio thread. RT-safe.

When block_start_time is provided, all events are offset relative to that wall-clock time, giving sample-accurate positioning within the block. When not provided, the first event is placed at sample 0 and subsequent events are offset relative to it.

Parameters
outputTarget MidiBuffer to append events to.
sample_rateCurrent sample rate.
nframesNumber of frames in the current audio block.
block_start_timeWall-clock time at block start, if available.

◆ push() [1/2]

bool zrythm::dsp::MidiDeviceBuffer::push ( const juce::MidiMessage & message)
inline

Definition at line 48 of file midi_device_buffer.h.

◆ push() [2/2]

bool zrythm::dsp::MidiDeviceBuffer::push ( juce::MidiMessage && message)

Push a MIDI message onto the queue.

Called from the MIDI device thread. Not necessarily RT-safe.

Parameters
messageMIDI message with a JUCE timestamp (seconds).
Returns
true if the message was enqueued, false if the queue was full.

Field Documentation

◆ kCapacity

size_t zrythm::dsp::MidiDeviceBuffer::kCapacity = 4096
staticconstexpr

Definition at line 28 of file midi_device_buffer.h.


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