From c80e9d4ac9b8d345f2a03ad802e3ee9fedfddf10 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 7 Aug 2007 00:28:06 +0000 Subject: [PATCH] Fix note-offs during playback from model. git-svn-id: svn://localhost/ardour2/trunk@2262 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/ardour/midi_model.h | 8 ++++++++ libs/ardour/midi_model.cc | 20 +++++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/libs/ardour/ardour/midi_model.h b/libs/ardour/ardour/midi_model.h index 5a253c1033..2879514d5a 100644 --- a/libs/ardour/ardour/midi_model.h +++ b/libs/ardour/ardour/midi_model.h @@ -21,6 +21,7 @@ #ifndef __ardour_midi_model_h__ #define __ardour_midi_model_h__ +#include #include #include #include @@ -162,6 +163,13 @@ private: typedef std::vector WriteNotes; WriteNotes _write_notes; bool _writing; + + // note state for read(): + + typedef std::priority_queue, + LaterNoteEndComparator> ActiveNotes; + + mutable ActiveNotes _active_notes; }; } /* namespace ARDOUR */ diff --git a/libs/ardour/midi_model.cc b/libs/ardour/midi_model.cc index 7a09804aef..a10a663780 100644 --- a/libs/ardour/midi_model.cc +++ b/libs/ardour/midi_model.cc @@ -20,7 +20,6 @@ #include #include -#include #include #include #include @@ -103,6 +102,7 @@ MidiModel::MidiModel(Session& s, size_t size) , _notes(size) , _note_mode(Sustained) , _writing(false) + , _active_notes(LaterNoteEndComparator()) { } @@ -121,34 +121,32 @@ MidiModel::read (MidiRingBuffer& dst, nframes_t start, nframes_t nframes, nframe /* FIXME: cache last lookup value to avoid the search */ if (_note_mode == Sustained) { - LaterNoteEndComparator cmp; - priority_queue,LaterNoteEndComparator> active_notes(cmp); /* FIXME: cache last lookup value to avoid the search */ for (Notes::const_iterator n = _notes.begin(); n != _notes.end(); ++n) { - + //cerr << "MM ON " << n->time() << endl; - if (n->time() >= start + nframes) - break; - - while ( ! active_notes.empty() ) { - const Note* const earliest_off = active_notes.top(); + while ( ! _active_notes.empty() ) { + const Note* const earliest_off = _active_notes.top(); const MidiEvent& ev = earliest_off->off_event(); if (ev.time() < start + nframes && ev.time() <= n->time()) { dst.write(ev.time() + stamp_offset, ev.size(), ev.buffer()); - active_notes.pop(); + _active_notes.pop(); ++read_events; } else { break; } } + if (n->time() >= start + nframes) + break; + // Note on if (n->time() >= start) { const MidiEvent& ev = n->on_event(); dst.write(ev.time() + stamp_offset, ev.size(), ev.buffer()); - active_notes.push(&(*n)); + _active_notes.push(&(*n)); ++read_events; }