mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-12 17:46:34 +01:00
Fix note-offs during playback from model.
git-svn-id: svn://localhost/ardour2/trunk@2262 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
f92be1e34c
commit
c80e9d4ac9
2 changed files with 17 additions and 11 deletions
|
|
@ -21,6 +21,7 @@
|
||||||
#ifndef __ardour_midi_model_h__
|
#ifndef __ardour_midi_model_h__
|
||||||
#define __ardour_midi_model_h__
|
#define __ardour_midi_model_h__
|
||||||
|
|
||||||
|
#include <queue>
|
||||||
#include <boost/utility.hpp>
|
#include <boost/utility.hpp>
|
||||||
#include <pbd/command.h>
|
#include <pbd/command.h>
|
||||||
#include <ardour/types.h>
|
#include <ardour/types.h>
|
||||||
|
|
@ -162,6 +163,13 @@ private:
|
||||||
typedef std::vector<size_t> WriteNotes;
|
typedef std::vector<size_t> WriteNotes;
|
||||||
WriteNotes _write_notes;
|
WriteNotes _write_notes;
|
||||||
bool _writing;
|
bool _writing;
|
||||||
|
|
||||||
|
// note state for read():
|
||||||
|
|
||||||
|
typedef std::priority_queue<const Note*,std::vector<const Note*>,
|
||||||
|
LaterNoteEndComparator> ActiveNotes;
|
||||||
|
|
||||||
|
mutable ActiveNotes _active_notes;
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace ARDOUR */
|
} /* namespace ARDOUR */
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <queue>
|
|
||||||
#include <pbd/enumwriter.h>
|
#include <pbd/enumwriter.h>
|
||||||
#include <ardour/midi_model.h>
|
#include <ardour/midi_model.h>
|
||||||
#include <ardour/midi_events.h>
|
#include <ardour/midi_events.h>
|
||||||
|
|
@ -103,6 +102,7 @@ MidiModel::MidiModel(Session& s, size_t size)
|
||||||
, _notes(size)
|
, _notes(size)
|
||||||
, _note_mode(Sustained)
|
, _note_mode(Sustained)
|
||||||
, _writing(false)
|
, _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 */
|
/* FIXME: cache last lookup value to avoid the search */
|
||||||
|
|
||||||
if (_note_mode == Sustained) {
|
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 */
|
/* FIXME: cache last lookup value to avoid the search */
|
||||||
for (Notes::const_iterator n = _notes.begin(); n != _notes.end(); ++n) {
|
for (Notes::const_iterator n = _notes.begin(); n != _notes.end(); ++n) {
|
||||||
|
|
||||||
//cerr << "MM ON " << n->time() << endl;
|
//cerr << "MM ON " << n->time() << endl;
|
||||||
|
|
||||||
if (n->time() >= start + nframes)
|
while ( ! _active_notes.empty() ) {
|
||||||
break;
|
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();
|
const MidiEvent& ev = earliest_off->off_event();
|
||||||
if (ev.time() < start + nframes && ev.time() <= n->time()) {
|
if (ev.time() < start + nframes && ev.time() <= n->time()) {
|
||||||
dst.write(ev.time() + stamp_offset, ev.size(), ev.buffer());
|
dst.write(ev.time() + stamp_offset, ev.size(), ev.buffer());
|
||||||
active_notes.pop();
|
_active_notes.pop();
|
||||||
++read_events;
|
++read_events;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (n->time() >= start + nframes)
|
||||||
|
break;
|
||||||
|
|
||||||
// Note on
|
// Note on
|
||||||
if (n->time() >= start) {
|
if (n->time() >= start) {
|
||||||
const MidiEvent& ev = n->on_event();
|
const MidiEvent& ev = n->on_event();
|
||||||
dst.write(ev.time() + stamp_offset, ev.size(), ev.buffer());
|
dst.write(ev.time() + stamp_offset, ev.size(), ev.buffer());
|
||||||
active_notes.push(&(*n));
|
_active_notes.push(&(*n));
|
||||||
++read_events;
|
++read_events;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue