diff --git a/libs/ardour/midi_state_tracker.cc b/libs/ardour/midi_state_tracker.cc index 2861aa9b26..52420f45bb 100644 --- a/libs/ardour/midi_state_tracker.cc +++ b/libs/ardour/midi_state_tracker.cc @@ -198,6 +198,33 @@ MidiNoteTracker::resolve_notes (MidiSource& src, const MidiSource::Lock& lock, T _on = 0; } +void +MidiNoteTracker::flush_notes (MidiBuffer &dst, samplepos_t time) +{ + DEBUG_TRACE (PBD::DEBUG::MidiTrackers, string_compose ("%1 MB-flushing notes @ %2 on = %3\n", this, time, _on)); + + if (!_on) { + return; + } + + for (int channel = 0; channel < 16; ++channel) { + for (int note = 0; note < 128; ++note) { + while (_active_notes[note + 128 * channel]) { + uint8_t buffer[3] = { ((uint8_t) (MIDI_CMD_NOTE_ON | channel)), uint8_t (note), 0 }; + Evoral::Event noteoff (Evoral::MIDI_EVENT, time, 3, buffer, false); + /* note that we do not care about failure from + push_back() ... should we warn someone ? + */ + dst.push_back (noteoff); + _active_notes[note + 128 * channel]--; + DEBUG_TRACE (PBD::DEBUG::MidiTrackers, string_compose ("%1: MB-flushed note %2/%3 at %4\n", + this, (int) note, (int) channel, time)); + } + } + } + _on = 0; +} + void MidiNoteTracker::dump (ostream& o) {