Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
message_collector.hpp File Reference

SPSC MIDI accumulator for UI-thread → audio-thread MIDI delivery. More...

#include <pulp/midi/buffer.hpp>
#include <pulp/midi/message.hpp>
#include <pulp/runtime/spsc_queue.hpp>
#include <algorithm>
#include <array>
#include <atomic>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <optional>

Go to the source code of this file.

Classes

struct  pulp::midi::TimestampedShortMessage
 Timestamped MIDI event in the collector queue. More...
struct  pulp::midi::MidiMessageCollectorTelemetry
class  pulp::midi::MidiMessageCollector< Capacity >

Namespaces

namespace  pulp
namespace  pulp::midi

Detailed Description

SPSC MIDI accumulator for UI-thread → audio-thread MIDI delivery.

MidiMessageCollector lets the UI / virtual-keyboard / scripting thread push timestamped MIDI events into a lock-free queue that the audio callback drains into the current block's MidiBuffer at the correct sample offsets.

Capacity is a compile-time parameter so the underlying queue allocates no heap memory in the audio thread. The default of 256 covers typical UI input rates (mouse + scripting) at any block size; larger consumers (sequencers playing back patterns) should pick a higher capacity at construction.

Usage:

// UI thread:
collector.push_now(MidiEvent::note_on(0, 60, 100), now_seconds);
// Audio thread (each block):
collector.drain_into(output_buffer, block_start_seconds,
block_end_seconds, sample_rate);
Definition message_collector.hpp:61
std::size_t drain_into(MidiBuffer &out, double block_start_seconds, int block_size_samples, double sample_rate)
Audio / consumer thread — drain queued events into out at the correct sample offsets within the curre...
Definition message_collector.hpp:91
bool push_now(const MidiEvent &event, double now_seconds)
UI / producer thread — push a MidiEvent timestamped at now_seconds.
Definition message_collector.hpp:68