Zrythm v2.0.0-alpha.1+31.4967fd053471
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
zrythm::dsp::midi_event Namespace Reference

Factory functions and algorithms for MidiEvent containers. More...

Data Structures

struct  NoteOffBeforeNoteOnCompare
 Comparator for sorting MidiEvents by time, with noteOff before noteOn at the same timestamp. More...

Functions

template<typename TimeType>
MidiEvent< TimeType > make_note_on (midi_byte_t channel, midi_byte_t note_pitch, midi_byte_t velocity, TimeType time)
 Creates a note on event.
template<typename TimeType>
MidiEvent< TimeType > make_note_off (midi_byte_t channel, midi_byte_t note_pitch, TimeType time)
 Creates a note off event.
template<typename TimeType>
MidiEvent< TimeType > make_control_change (midi_byte_t channel, midi_byte_t controller, midi_byte_t value, TimeType time)
 Creates a control change event.
template<typename TimeType>
MidiEvent< TimeType > make_pitchbend (midi_byte_t channel, uint32_t pitchbend, TimeType time)
 Creates a pitchbend event.
template<typename TimeType>
MidiEvent< TimeType > make_channel_pressure (midi_byte_t channel, midi_byte_t value, TimeType time)
 Creates a channel pressure (aftertouch) event.
template<typename TimeType>
MidiEvent< TimeType > make_all_notes_off (midi_byte_t channel, TimeType time)
 Creates an all-notes-off event.
template<typename TimeType>
MidiEvent< TimeType > make_raw_rt (std::span< const midi_byte_t > raw, TimeType time) noexcept
 Creates a MIDI event from the given bytes, RT-safe.
template<typename TimeType>
MidiEvent< TimeType > make_raw (std::span< const midi_byte_t > raw, TimeType time)
 Creates a raw MIDI event from the given bytes.
template<std::ranges::random_access_range Container>
void sort_with_note_off_priority (Container &container)
 Sorts events by time, with noteOff before noteOn at the same timestamp.
template<std::ranges::random_access_range Container>
void sort (Container &container)
 Sorts events by time only.
template<std::ranges::random_access_range Container>
void set_channel (Container &container, midi_byte_t channel)
 Sets the MIDI channel on all events in the container.
template<typename TimeType, utils::MutableContainerOf< MidiEvent< TimeType > > DestContainer, std::ranges::range SrcContainer>
void append_in_range (DestContainer &dest, const SrcContainer &src, std::pair< TimeType, TimeType > range)
void sort_with_note_off_priority (MidiEventBuffer &buf) noexcept
void append_in_range (MidiEventBuffer &dst, const MidiEventBuffer &src, std::pair< units::sample_u32_t, units::sample_u32_t > range) noexcept
 Append events from src to dst, filtered by time range [range.first, range.second).

Detailed Description

Factory functions and algorithms for MidiEvent containers.

Function Documentation

◆ append_in_range() [1/2]

template<typename TimeType, utils::MutableContainerOf< MidiEvent< TimeType > > DestContainer, std::ranges::range SrcContainer>
void zrythm::dsp::midi_event::append_in_range ( DestContainer & dest,
const SrcContainer & src,
std::pair< TimeType, TimeType > range )

Definition at line 387 of file midi_event.h.

◆ append_in_range() [2/2]

void zrythm::dsp::midi_event::append_in_range ( MidiEventBuffer & dst,
const MidiEventBuffer & src,
std::pair< units::sample_u32_t, units::sample_u32_t > range )
inlinenoexcept

Append events from src to dst, filtered by time range [range.first, range.second).

Definition at line 368 of file midi_event_buffer.h.

◆ make_all_notes_off()

template<typename TimeType>
MidiEvent< TimeType > zrythm::dsp::midi_event::make_all_notes_off ( midi_byte_t channel,
TimeType time )

Creates an all-notes-off event.

Parameters
channelMIDI channel (0-based, 0-15).

Definition at line 260 of file midi_event.h.

◆ make_channel_pressure()

template<typename TimeType>
MidiEvent< TimeType > zrythm::dsp::midi_event::make_channel_pressure ( midi_byte_t channel,
midi_byte_t value,
TimeType time )

Creates a channel pressure (aftertouch) event.

Parameters
channelMIDI channel (0-based, 0-15).

Definition at line 241 of file midi_event.h.

◆ make_control_change()

template<typename TimeType>
MidiEvent< TimeType > zrythm::dsp::midi_event::make_control_change ( midi_byte_t channel,
midi_byte_t controller,
midi_byte_t value,
TimeType time )

Creates a control change event.

Parameters
channelMIDI channel (0-based, 0-15).

Definition at line 195 of file midi_event.h.

◆ make_note_off()

template<typename TimeType>
MidiEvent< TimeType > zrythm::dsp::midi_event::make_note_off ( midi_byte_t channel,
midi_byte_t note_pitch,
TimeType time )

Creates a note off event.

Parameters
channelMIDI channel (0-based, 0-15).

Definition at line 174 of file midi_event.h.

◆ make_note_on()

template<typename TimeType>
MidiEvent< TimeType > zrythm::dsp::midi_event::make_note_on ( midi_byte_t channel,
midi_byte_t note_pitch,
midi_byte_t velocity,
TimeType time )

Creates a note on event.

Parameters
channelMIDI channel (0-based, 0-15).

Definition at line 149 of file midi_event.h.

◆ make_pitchbend()

template<typename TimeType>
MidiEvent< TimeType > zrythm::dsp::midi_event::make_pitchbend ( midi_byte_t channel,
uint32_t pitchbend,
TimeType time )

Creates a pitchbend event.

Parameters
channelMIDI channel (0-based, 0-15).
pitchbend0 to 16384 (8192 = center).

Definition at line 219 of file midi_event.h.

◆ make_raw()

template<typename TimeType>
MidiEvent< TimeType > zrythm::dsp::midi_event::make_raw ( std::span< const midi_byte_t > raw,
TimeType time )

Creates a raw MIDI event from the given bytes.

Handles arbitrarily-sized payloads (including SysEx) by allocating external storage. Not RT-safe — use make_raw_rt() in RT contexts.

Definition at line 298 of file midi_event.h.

◆ make_raw_rt()

template<typename TimeType>
MidiEvent< TimeType > zrythm::dsp::midi_event::make_raw_rt ( std::span< const midi_byte_t > raw,
TimeType time )
noexcept

Creates a MIDI event from the given bytes, RT-safe.

Only handles inline messages (≤ inline_capacity bytes). Asserts on larger payloads — use make_raw() for those (not RT-safe).

Definition at line 280 of file midi_event.h.

◆ set_channel()

template<std::ranges::random_access_range Container>
void zrythm::dsp::midi_event::set_channel ( Container & container,
midi_byte_t channel )

Sets the MIDI channel on all events in the container.

Parameters
channelMIDI channel (0-based, 0-15).

Definition at line 365 of file midi_event.h.

◆ sort()

template<std::ranges::random_access_range Container>
void zrythm::dsp::midi_event::sort ( Container & container)

Sorts events by time only.

Event ordering at the same timestamp is preserved (stable sort). Producers (caches, input processors) are responsible for inserting events in the correct order.

Definition at line 352 of file midi_event.h.

◆ sort_with_note_off_priority() [1/2]

template<std::ranges::random_access_range Container>
void zrythm::dsp::midi_event::sort_with_note_off_priority ( Container & container)

Sorts events by time, with noteOff before noteOn at the same timestamp.

Definition at line 340 of file midi_event.h.

◆ sort_with_note_off_priority() [2/2]

void zrythm::dsp::midi_event::sort_with_note_off_priority ( MidiEventBuffer & buf)
inlinenoexcept

Definition at line 352 of file midi_event_buffer.h.