+void
+MidiStateTracker::resolve_notes (MidiSource& src, const MidiSource::Lock& lock, Evoral::Beats time)
+{
+ DEBUG_TRACE (PBD::DEBUG::MidiTrackers, string_compose ("%1 MS-resolve notes @ %2 on = %3\n", this, time, _on));
+
+ if (!_on) {
+ return;
+ }
+
+ /* NOTE: the src must be locked */
+
+ for (int channel = 0; channel < 16; ++channel) {
+ for (int note = 0; note < 128; ++note) {
+ while (_active_notes[note + 128 * channel]) {
+ Evoral::MIDIEvent<Evoral::Beats> ev ((MIDI_CMD_NOTE_OFF|channel), time, 3, 0, true);
+ ev.set_type (MIDI_CMD_NOTE_OFF);
+ ev.set_channel (channel);
+ ev.set_note (note);
+ ev.set_velocity (0);
+ src.append_event_beats (lock, ev);
+ DEBUG_TRACE (PBD::DEBUG::MidiTrackers, string_compose ("%1: MS-resolved note %2/%3 at %4\n",
+ this, (int) note, (int) channel, time));
+ _active_notes[note + 128 * channel]--;
+ /* don't stack events up at the same time */
+ time += Evoral::Beats::tick();
+ }
+ }
+ }
+ _on = 0;
+}
+
+void
+MidiStateTracker::dump (ostream& o)
+{
+ o << "******\n";
+ for (int c = 0; c < 16; ++c) {
+ for (int x = 0; x < 128; ++x) {
+ if (_active_notes[c * 128 + x]) {
+ o << "Channel " << c+1 << " Note " << x << " is on ("
+ << (int) _active_notes[c*128+x] << "times)\n";
+ }
+ }
+ }
+ o << "+++++\n";
+}