Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
zrythm::dsp::MidiEventVector Class Referencefinal

A lock-free thread-safe vector of MidiEvents. More...

#include <src/dsp/midi_event.h>

Public Types

using ChordDescriptor = dsp::ChordDescriptor
using Iterator = std::vector<MidiEvent>::iterator
using ConstIterator = std::vector<MidiEvent>::const_iterator

Public Member Functions

Iterator begin ()
Iterator end ()
void erase (Iterator it, Iterator it_end)
ConstIterator begin () const
ConstIterator end () const
void push_back (const MidiEvent &ev)
void push_back (const std::vector< MidiEvent > &events)
MidiEvent pop_front ()
MidiEvent pop_back ()
void clear ()
size_t size () const
MidiEvent front () const
MidiEvent back () const
MidiEvent at (size_t index) const
void swap (MidiEventVector &other)
void remove_if (std::function< bool(const MidiEvent &)> predicate)
void remove (const MidiEvent &event)
 Removes all events that match event.
void foreach_event (std::function< void(const MidiEvent &)> func) const
size_t capacity () const
void print () const
void append_w_filter (const MidiEventVector &src, std::optional< std::array< bool, 16 > > channels, nframes_t local_offset, nframes_t nframes)
 Appends the events from src.
void append (const MidiEventVector &src, nframes_t local_offset, nframes_t nframes)
 Appends the events from src.
void transform_chord_and_append (MidiEventVector &src, std::function< const ChordDescriptor *(midi_byte_t)> note_number_to_chord_descriptor, midi_byte_t velocity_to_use, nframes_t local_offset, nframes_t nframes)
 Transforms the given MIDI input to the MIDI notes of the corresponding chord.
void add_note_on (midi_byte_t channel, midi_byte_t note_pitch, midi_byte_t velocity, midi_time_t time)
 Adds a note on event to the given MidiEvents.
void add_note_ons_from_chord_descr (const ChordDescriptor &descr, midi_byte_t channel, midi_byte_t velocity, midi_time_t time)
 Adds a note on for each note in the chord.
void add_note_offs_from_chord_descr (const ChordDescriptor &descr, midi_byte_t channel, midi_time_t time)
 Adds a note off for each note in the chord.
void add_cc_volume (midi_byte_t channel, midi_byte_t volume, midi_time_t time)
 Add CC volume event.
bool has_any () const
bool empty () const
void add_event_from_buf (midi_time_t time, midi_byte_t *buf, int buf_size)
 Parses a MidiEvent from a raw MIDI buffer.
void add_note_off (midi_byte_t channel, midi_byte_t note_pitch, midi_time_t time)
 Adds a note off event to the given MidiEvents.
void add_control_change (midi_byte_t channel, midi_byte_t controller, midi_byte_t control, midi_time_t time)
 Adds a control event to the given MidiEvents.
void add_song_pos (int64_t total_sixteenths, midi_time_t time)
 Adds a song position event to the queue.
void add_raw (uint8_t *buf, size_t buf_sz, midi_time_t time)
void add_simple (midi_byte_t byte1, midi_byte_t byte2, midi_byte_t byte3, midi_time_t time)
void add_pitchbend (midi_byte_t channel, uint32_t pitchbend, midi_time_t time)
 Adds a control event to the given MidiEvents.
void add_channel_pressure (midi_byte_t channel, midi_byte_t value, midi_time_t time)
void add_all_notes_off (midi_byte_t channel, midi_time_t time, bool with_lock)
 Queues MIDI note off to event queue.
void panic_without_lock ()
 Adds a note off message to every MIDI channel.
void panic ()
 Must only be called from the UI thread.
void write_to_midi_sequence (juce::MidiMessageSequence &sequence, bool update_matched_pairs) const
 Writes the events to a MIDI sequence.
void clear_duplicates ()
 Clears duplicates.
void sort ()
 Sorts the MidiEvents by time.
void set_channel (midi_byte_t channel)
 Sets the given MIDI channel on all applicable MIDI events.
void delete_event (const MidiEvent *ev)

Detailed Description

A lock-free thread-safe vector of MidiEvents.

Not necessarily the best implementation, but it's good enough for now.

Definition at line 77 of file midi_event.h.

Member Typedef Documentation

◆ ChordDescriptor

◆ ConstIterator

using zrythm::dsp::MidiEventVector::ConstIterator = std::vector<MidiEvent>::const_iterator

Definition at line 86 of file midi_event.h.

◆ Iterator

using zrythm::dsp::MidiEventVector::Iterator = std::vector<MidiEvent>::iterator

Definition at line 85 of file midi_event.h.

Constructor & Destructor Documentation

◆ MidiEventVector()

zrythm::dsp::MidiEventVector::MidiEventVector ( )
inline

Definition at line 80 of file midi_event.h.

Member Function Documentation

◆ add_cc_volume()

void zrythm::dsp::MidiEventVector::add_cc_volume ( midi_byte_t channel,
midi_byte_t volume,
midi_time_t time )

Add CC volume event.

TODO

◆ add_control_change()

void zrythm::dsp::MidiEventVector::add_control_change ( midi_byte_t channel,
midi_byte_t controller,
midi_byte_t control,
midi_time_t time )

Adds a control event to the given MidiEvents.

Parameters
channelMIDI channel starting from 1.

◆ add_event_from_buf()

void zrythm::dsp::MidiEventVector::add_event_from_buf ( midi_time_t time,
midi_byte_t * buf,
int buf_size )

Parses a MidiEvent from a raw MIDI buffer.

This must be a full 3-byte message. If in 'running status' mode, the caller is responsible for prepending the status byte.

◆ add_note_off()

void zrythm::dsp::MidiEventVector::add_note_off ( midi_byte_t channel,
midi_byte_t note_pitch,
midi_time_t time )

Adds a note off event to the given MidiEvents.

Parameters
channelMIDI channel starting from 1.
queuedAdd to queued events instead.

◆ add_note_on()

void zrythm::dsp::MidiEventVector::add_note_on ( midi_byte_t channel,
midi_byte_t note_pitch,
midi_byte_t velocity,
midi_time_t time )

Adds a note on event to the given MidiEvents.

Parameters
channelMIDI channel starting from 1.
queuedAdd to queued events instead.

◆ add_pitchbend()

void zrythm::dsp::MidiEventVector::add_pitchbend ( midi_byte_t channel,
uint32_t pitchbend,
midi_time_t time )

Adds a control event to the given MidiEvents.

Parameters
channelMIDI channel starting from 1.
pitchbend0 to 16384.

◆ add_simple()

void zrythm::dsp::MidiEventVector::add_simple ( midi_byte_t byte1,
midi_byte_t byte2,
midi_byte_t byte3,
midi_time_t time )
inline

Definition at line 334 of file midi_event.h.

◆ add_song_pos()

void zrythm::dsp::MidiEventVector::add_song_pos ( int64_t total_sixteenths,
midi_time_t time )

Adds a song position event to the queue.

Parameters
total_sixteenthsTotal sixteenths.

◆ append()

void zrythm::dsp::MidiEventVector::append ( const MidiEventVector & src,
nframes_t local_offset,
nframes_t nframes )

Appends the events from src.

Parameters
local_offsetThe start frame offset from 0 in this cycle.
nframesNumber of frames to process.

◆ append_w_filter()

void zrythm::dsp::MidiEventVector::append_w_filter ( const MidiEventVector & src,
std::optional< std::array< bool, 16 > > channels,
nframes_t local_offset,
nframes_t nframes )

Appends the events from src.

Parameters
channelsAllowed channels (array of 16 booleans).
local_offsetThe local offset from 0 in this cycle.
nframesNumber of frames to process.

◆ at()

MidiEvent zrythm::dsp::MidiEventVector::at ( size_t index) const
inline

Definition at line 171 of file midi_event.h.

◆ back()

MidiEvent zrythm::dsp::MidiEventVector::back ( ) const
inline

Definition at line 165 of file midi_event.h.

◆ begin() [1/2]

Iterator zrythm::dsp::MidiEventVector::begin ( )
inline

Definition at line 89 of file midi_event.h.

◆ begin() [2/2]

ConstIterator zrythm::dsp::MidiEventVector::begin ( ) const
inline

Definition at line 107 of file midi_event.h.

◆ capacity()

size_t zrythm::dsp::MidiEventVector::capacity ( ) const
inline

Definition at line 203 of file midi_event.h.

◆ clear()

void zrythm::dsp::MidiEventVector::clear ( )
inline

Definition at line 147 of file midi_event.h.

◆ empty()

bool zrythm::dsp::MidiEventVector::empty ( ) const
inline

Definition at line 295 of file midi_event.h.

◆ end() [1/2]

Iterator zrythm::dsp::MidiEventVector::end ( )
inline

Definition at line 95 of file midi_event.h.

◆ end() [2/2]

ConstIterator zrythm::dsp::MidiEventVector::end ( ) const
inline

Definition at line 113 of file midi_event.h.

◆ erase()

void zrythm::dsp::MidiEventVector::erase ( Iterator it,
Iterator it_end )
inline

Definition at line 101 of file midi_event.h.

◆ foreach_event()

void zrythm::dsp::MidiEventVector::foreach_event ( std::function< void(const MidiEvent &)> func) const
inline

Definition at line 197 of file midi_event.h.

◆ front()

MidiEvent zrythm::dsp::MidiEventVector::front ( ) const
inline

Definition at line 159 of file midi_event.h.

◆ has_any()

bool zrythm::dsp::MidiEventVector::has_any ( ) const
inline

Definition at line 294 of file midi_event.h.

◆ panic_without_lock()

void zrythm::dsp::MidiEventVector::panic_without_lock ( )
inline

Adds a note off message to every MIDI channel.

Definition at line 364 of file midi_event.h.

◆ pop_back()

MidiEvent zrythm::dsp::MidiEventVector::pop_back ( )
inline

Definition at line 139 of file midi_event.h.

◆ pop_front()

MidiEvent zrythm::dsp::MidiEventVector::pop_front ( )
inline

Definition at line 131 of file midi_event.h.

◆ push_back() [1/2]

void zrythm::dsp::MidiEventVector::push_back ( const MidiEvent & ev)
inline

Definition at line 119 of file midi_event.h.

◆ push_back() [2/2]

void zrythm::dsp::MidiEventVector::push_back ( const std::vector< MidiEvent > & events)
inline

Definition at line 125 of file midi_event.h.

◆ remove()

void zrythm::dsp::MidiEventVector::remove ( const MidiEvent & event)
inline

Removes all events that match event.

Definition at line 192 of file midi_event.h.

◆ remove_if()

void zrythm::dsp::MidiEventVector::remove_if ( std::function< bool(const MidiEvent &)> predicate)
inline

Definition at line 183 of file midi_event.h.

◆ size()

size_t zrythm::dsp::MidiEventVector::size ( ) const
inline

Definition at line 153 of file midi_event.h.

◆ swap()

void zrythm::dsp::MidiEventVector::swap ( MidiEventVector & other)
inline

Definition at line 177 of file midi_event.h.

◆ transform_chord_and_append()

void zrythm::dsp::MidiEventVector::transform_chord_and_append ( MidiEventVector & src,
std::function< const ChordDescriptor *(midi_byte_t)> note_number_to_chord_descriptor,
midi_byte_t velocity_to_use,
nframes_t local_offset,
nframes_t nframes )

Transforms the given MIDI input to the MIDI notes of the corresponding chord.

Only C0~B0 are considered.

◆ write_to_midi_sequence()

void zrythm::dsp::MidiEventVector::write_to_midi_sequence ( juce::MidiMessageSequence & sequence,
bool update_matched_pairs ) const

Writes the events to a MIDI sequence.

This assumes that the event timestamps are in ticks.

Parameters
sequence
update_matched_pairsIf true, ensures there are note off events for every note on event.

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