|
Zrythm v2.0.0-alpha.1+31.4967fd053471
a highly automated and intuitive digital audio workstation
|
Packed contiguous buffer for RT MIDI events. More...
#include <src/dsp/midi_event_buffer.h>
Data Structures | |
| class | Iterator |
| Forward iterator over packed events. More... | |
Public Member Functions | |
| bool | push_back (units::sample_u32_t time, std::span< const midi_byte_t > event_data) noexcept |
| Append an event. | |
| void | clear () noexcept |
| Reset buffer. | |
| void | reserve (size_t bytes=kMaxReserveBytes) |
| Pre-allocate internal byte storage (and scratch/index buffers). | |
| void | swap (MidiEventBuffer &other) noexcept |
| bool | empty () const noexcept |
| size_t | size () const noexcept |
| Number of events (not bytes). | |
| size_t | size_in_bytes () const noexcept |
| Bytes used in storage. | |
| size_t | capacity () const noexcept |
| Bytes reserved in storage. | |
| MidiEventView | front () const noexcept |
| Iterator | begin () const noexcept |
| Iterator | end () const noexcept |
| template<typename Comp> | |
| void | sort (Comp &&comp) noexcept |
| Sort events using the given comparator on MidiEventView. | |
| template<typename Pred> | |
| void | remove_if (Pred &&pred) noexcept |
| Remove all events matching the predicate. | |
Static Public Member Functions | |
| static MidiEventBuffer | make_reserved () |
| Create a pre-allocated buffer suitable for test use. | |
Static Public Attributes | |
| static constexpr size_t | kHeaderSize = sizeof (uint16_t) + sizeof (uint32_t) |
| Bytes per event header: 2 (size) + 4 (timestamp). | |
| static constexpr size_t | kDefaultReserveBytes = 0x1000 |
| Default pre-allocation. | |
| static constexpr size_t | kMaxReserveBytes = 0x4000 |
| Max bytes to hold in queues. | |
Packed contiguous buffer for RT MIDI events.
Events are stored as: [uint16_t size][uint32_t timestamp][size bytes data]. Size-first layout allows easy chunk splitting — read 2 bytes to skip an event, or splice byte ranges directly.
Zero per-event heap allocation. Pre-allocate with reserve(), clear each cycle (no dealloc). Iteration yields non-owning MidiEventView objects.
RT-safety: reserve() must be called before any RT use. All internal storage (primary, scratch, index) is pre-allocated at that point. push_back(), sort(), remove_if(), and clear() never allocate as long as the pre-allocated capacity is not exceeded (asserted in debug).
Not thread-safe — one writer (RT thread), readers must synchronize externally.
Definition at line 73 of file midi_event_buffer.h.
|
inlinenoexcept |
Definition at line 225 of file midi_event_buffer.h.
|
inlinenoexcept |
Bytes reserved in storage.
Definition at line 217 of file midi_event_buffer.h.
|
inlinenoexcept |
Reset buffer.
No deallocation — storage is reused next cycle.
Definition at line 188 of file midi_event_buffer.h.
|
inlinenoexcept |
Definition at line 211 of file midi_event_buffer.h.
|
inlinenoexcept |
Definition at line 230 of file midi_event_buffer.h.
|
inlinenoexcept |
Definition at line 219 of file midi_event_buffer.h.
|
inlinestaticnodiscard |
Create a pre-allocated buffer suitable for test use.
The returned buffer has enough storage reserved for typical test scenarios, avoiding allocations during push_back.
Definition at line 91 of file midi_event_buffer.h.
|
inlinenoexcept |
Append an event.
memcpy's data into the internal byte storage.
Callers should reserve() enough space during prepare_for_processing to avoid drops. Critical callers (e.g. panic processor) should check the return value.
Definition at line 165 of file midi_event_buffer.h.
|
inlinenoexcept |
Remove all events matching the predicate.
Unpacks and repacks.
Definition at line 293 of file midi_event_buffer.h.
|
inline |
Pre-allocate internal byte storage (and scratch/index buffers).
Definition at line 195 of file midi_event_buffer.h.
|
inlinenoexcept |
Number of events (not bytes).
Definition at line 213 of file midi_event_buffer.h.
|
inlinenoexcept |
Bytes used in storage.
Definition at line 215 of file midi_event_buffer.h.
|
inlinenoexcept |
Sort events using the given comparator on MidiEventView.
Unpacks, sorts, and repacks. Not cheap — call only when needed.
Definition at line 242 of file midi_event_buffer.h.
|
inlinenoexcept |
Definition at line 203 of file midi_event_buffer.h.
|
staticconstexpr |
Default pre-allocation.
Definition at line 80 of file midi_event_buffer.h.
|
staticconstexpr |
Bytes per event header: 2 (size) + 4 (timestamp).
Definition at line 77 of file midi_event_buffer.h.
|
staticconstexpr |
Max bytes to hold in queues.
Definition at line 83 of file midi_event_buffer.h.