OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
ossia::midi_note_tracker Struct Reference

Detailed Description

The notes a MIDI stream has started and not yet stopped.

Whoever cuts a stream short (a cable taken off, a node removed, an output rebound to another device) asks for what is left sounding and stops it at the far end, which otherwise never gets the note off.

One bit per (channel, pitch): a note on sets it, a note off clears it, so tracking a message is a mask and a store, and nothing is ever allocated. Releasing is conservative on purpose: a note off for a note that does not sound is ignored by receivers, a missing one is a note that never ends. Hence

  • a bit, not a count: two note ons for one pitch are stopped by one note off, the way MIDI 1 receivers take them;
  • the UMP groups are not part of the key: the notes are stopped on every group that carried a note on while some were held, almost always one;
  • "all notes off" and "reset all controllers" do not clear anything, since not every receiver honours them.

Tracking keeps no summary of the table up to date: that would be paid on every message, for the sake of a release that happens once.

The damper pedal is tracked along: notes released under a pedal that stays down ring forever just as well.

Public Member Functions

bool empty () const noexcept
 Looks at the whole table: for when a stream is cut, not for every tick.
void clear () noexcept
void track (const libremidi::ump &m) noexcept
template<typename Messages>
void track (const Messages &messages) noexcept
void track (const libremidi::ump *it, const libremidi::ump *end) noexcept
 A tick's worth at once.
template<typename Messages>
void release (Messages &out, int64_t timestamp=0) const
 Appends what stops everything held to out, stamped at timestamp: the pedals up, then a note off per note.
int count () const noexcept
 Number of notes held.

Public Attributes

std::array< uint64_t, channels *pitches/64 > notes {}
 Bit (channel * 128 + pitch).
uint16_t damper {}
 Channels whose damper pedal (CC 64) is down.
uint16_t groups {}
 UMP groups that carried a note on or a pedal.
bool midi1 {}
 The last note came as a MIDI 1 channel voice message: stop it in kind.

Static Public Attributes

static constexpr int channels = 16
static constexpr int pitches = 128

Member Function Documentation

◆ track()

void ossia::midi_note_tracker::track ( const libremidi::ump * it,
const libremidi::ump * end )
inlinenoexcept

A tick's worth at once.

The state other than the table is kept out of memory for the length of the loop: most messages of a stream are not notes, and those then cost a test and nothing else.

◆ release()

template<typename Messages>
void ossia::midi_note_tracker::release ( Messages & out,
int64_t timestamp = 0 ) const
inline

Appends what stops everything held to out, stamped at timestamp: the pedals up, then a note off per note.

The tracker is left untouched: the stream may go on elsewhere.

Member Data Documentation

◆ groups

uint16_t ossia::midi_note_tracker::groups {}

UMP groups that carried a note on or a pedal.

Only ever grows: it says where to send the note offs, not whether there is something to stop.