diff options
author | David Robillard <d@drobilla.net> | 2007-08-07 00:28:06 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2007-08-07 00:28:06 +0000 |
commit | c80e9d4ac9b8d345f2a03ad802e3ee9fedfddf10 (patch) | |
tree | ba8bb4f8e753193c3bfaae0cc8a3c3a4e905697c /libs | |
parent | f92be1e34c7fa2f25f36c23974045bce22a5049f (diff) |
Fix note-offs during playback from model.
git-svn-id: svn://localhost/ardour2/trunk@2262 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs')
-rw-r--r-- | libs/ardour/ardour/midi_model.h | 8 | ||||
-rw-r--r-- | 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 <queue> #include <boost/utility.hpp> #include <pbd/command.h> #include <ardour/types.h> @@ -162,6 +163,13 @@ private: typedef std::vector<size_t> WriteNotes; WriteNotes _write_notes; bool _writing; + + // note state for read(): + + typedef std::priority_queue<const Note*,std::vector<const Note*>, + 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 <iostream> #include <algorithm> -#include <queue> #include <pbd/enumwriter.h> #include <ardour/midi_model.h> #include <ardour/midi_events.h> @@ -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<const Note*,vector<const Note*>,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; + //cerr << "MM ON " << n->time() << endl; - 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; } |