Zrythm v2.0.0-alpha.1
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
zrythm::dsp::MidiEvent< TimeT > Struct Template Reference

Type-erased MIDI event with small-buffer optimization. More...

#include <src/dsp/midi_event.h>

Public Types

using InlineStorage = std::array<midi_byte_t, sizeof (const midi_byte_t *)>
using ExternalStorage = std::shared_ptr<const midi_byte_t[]>
using TimeType = TimeT

Public Member Functions

template<typename OtherTimeType>
 MidiEvent (const MidiEvent< OtherTimeType > &other) noexcept
 Converting constructor for compatible time types.
std::span< const midi_byte_tdata () const noexcept
void set_inline (std::span< const midi_byte_t > d) noexcept
void set_inline_rt (std::span< const midi_byte_t > d) noexcept
 RT-safe version of set_inline that only works on inline storage.
void set_external (std::shared_ptr< const midi_byte_t[]> ptr, uint16_t sz) noexcept
bool is_inline () const noexcept

Data Fields

std::variant< InlineStorage, ExternalStorage > storage
uint16_t size_ {}
 Number of valid MIDI bytes.
TimeType time_ {}
 Timestamp (meaning depends on TimeType).

Static Public Attributes

static constexpr size_t inline_capacity = InlineStorage{}.size ()

Friends

bool operator== (const MidiEvent &lhs, const MidiEvent &rhs) noexcept

Detailed Description

template<typename TimeT>
struct zrythm::dsp::MidiEvent< TimeT >

Type-erased MIDI event with small-buffer optimization.

Stores channel messages (≤3 bytes) inline in a fixed-size array sized to sizeof(pointer), and larger messages (e.g. sysex) via shared heap storage.

Note
Not realtime-safe. use MidiEventBuffer in RT contexts.
Template Parameters
TimeTThe timestamp type (e.g. units::sample_t, units::precise_tick_t).

Definition at line 34 of file midi_event.h.

Member Typedef Documentation

◆ ExternalStorage

template<typename TimeT>
using zrythm::dsp::MidiEvent< TimeT >::ExternalStorage = std::shared_ptr<const midi_byte_t[]>

Definition at line 37 of file midi_event.h.

◆ InlineStorage

template<typename TimeT>
using zrythm::dsp::MidiEvent< TimeT >::InlineStorage = std::array<midi_byte_t, sizeof (const midi_byte_t *)>

Definition at line 36 of file midi_event.h.

◆ TimeType

template<typename TimeT>
using zrythm::dsp::MidiEvent< TimeT >::TimeType = TimeT

Definition at line 38 of file midi_event.h.

Constructor & Destructor Documentation

◆ MidiEvent()

template<typename TimeT>
template<typename OtherTimeType>
zrythm::dsp::MidiEvent< TimeT >::MidiEvent ( const MidiEvent< OtherTimeType > & other)
inlinenoexcept

Converting constructor for compatible time types.

Allows implicit conversion e.g. from MidiEvent<Quantity<Sample, int>> to MidiEvent<Quantity<Sample, long>> (SampleBasedMidiEvent).

Definition at line 60 of file midi_event.h.

Member Function Documentation

◆ data()

template<typename TimeT>
std::span< const midi_byte_t > zrythm::dsp::MidiEvent< TimeT >::data ( ) const
inlinenoexcept

Definition at line 66 of file midi_event.h.

◆ is_inline()

template<typename TimeT>
bool zrythm::dsp::MidiEvent< TimeT >::is_inline ( ) const
inlinenoexcept

Definition at line 116 of file midi_event.h.

◆ set_external()

template<typename TimeT>
void zrythm::dsp::MidiEvent< TimeT >::set_external ( std::shared_ptr< const midi_byte_t[]> ptr,
uint16_t sz )
inlinenoexcept

Definition at line 109 of file midi_event.h.

◆ set_inline()

template<typename TimeT>
void zrythm::dsp::MidiEvent< TimeT >::set_inline ( std::span< const midi_byte_t > d)
inlinenoexcept

Definition at line 82 of file midi_event.h.

◆ set_inline_rt()

template<typename TimeT>
void zrythm::dsp::MidiEvent< TimeT >::set_inline_rt ( std::span< const midi_byte_t > d)
inlinenoexcept

RT-safe version of set_inline that only works on inline storage.

Asserts if the variant currently holds external storage — this must only be called on freshly-constructed or already-inline events.

Definition at line 99 of file midi_event.h.

◆ operator==

template<typename TimeT>
bool operator== ( const MidiEvent< TimeT > & lhs,
const MidiEvent< TimeT > & rhs )
friend

Definition at line 121 of file midi_event.h.

Field Documentation

◆ inline_capacity

template<typename TimeT>
size_t zrythm::dsp::MidiEvent< TimeT >::inline_capacity = InlineStorage{}.size ()
staticconstexpr

Definition at line 40 of file midi_event.h.

◆ size_

template<typename TimeT>
uint16_t zrythm::dsp::MidiEvent< TimeT >::size_ {}

Number of valid MIDI bytes.

Definition at line 46 of file midi_event.h.

◆ storage

template<typename TimeT>
std::variant<InlineStorage, ExternalStorage> zrythm::dsp::MidiEvent< TimeT >::storage

Definition at line 45 of file midi_event.h.

◆ time_

template<typename TimeT>
TimeType zrythm::dsp::MidiEvent< TimeT >::time_ {}

Timestamp (meaning depends on TimeType).

Definition at line 47 of file midi_event.h.


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