summaryrefslogtreecommitdiff
path: root/libs/ardour/midi_state_tracker.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2009-09-11 13:25:31 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2009-09-11 13:25:31 +0000
commitd98302ae2c9040dd61573739b3bbdc708d1dd54e (patch)
tree21081910c79cccea718bf2f07d630f9242f5b359 /libs/ardour/midi_state_tracker.cc
parent65c5e7ae47fca8a38c35def99a28e99dc18fa52d (diff)
track note on/off and send appropriate note offs at transport stop
git-svn-id: svn://localhost/ardour2/branches/3.0@5655 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/midi_state_tracker.cc')
-rw-r--r--libs/ardour/midi_state_tracker.cc35
1 files changed, 16 insertions, 19 deletions
diff --git a/libs/ardour/midi_state_tracker.cc b/libs/ardour/midi_state_tracker.cc
index 66d356f9a6..e25dbdd094 100644
--- a/libs/ardour/midi_state_tracker.cc
+++ b/libs/ardour/midi_state_tracker.cc
@@ -27,59 +27,55 @@ using namespace ARDOUR;
MidiStateTracker::MidiStateTracker ()
{
- _active_notes.reset();
+ reset ();
}
void
MidiStateTracker::reset ()
{
- _active_notes.reset ();
+ memset (_active_notes, 0, sizeof (_active_notes));
}
void
MidiStateTracker::track_note_onoffs (const Evoral::MIDIEvent<MidiBuffer::TimeType>& event)
{
if (event.is_note_on()) {
- _active_notes [event.note() + 128 * event.channel()] = true;
+ _active_notes [event.note() + 128 * event.channel()]++;
} else if (event.is_note_off()){
- _active_notes [event.note() + 128 * event.channel()] = false;
+ if (_active_notes[event.note() + 128 * event.channel()]) {
+ _active_notes [event.note() + 128 * event.channel()]--;
+ }
}
}
-bool
-MidiStateTracker::track (const MidiBuffer::iterator &from, const MidiBuffer::iterator &to)
+void
+MidiStateTracker::track (const MidiBuffer::iterator &from, const MidiBuffer::iterator &to, bool& looped)
{
- bool ret = false;
+ looped = false;
for (MidiBuffer::iterator i = from; i != to; ++i) {
const Evoral::MIDIEvent<MidiBuffer::TimeType> ev(*i, false);
if (ev.event_type() == LoopEventType) {
- ret = true;
+ looped = true;
continue;
}
track_note_onoffs (ev);
}
- return ret;
}
void
MidiStateTracker::resolve_notes (MidiBuffer &dst, nframes_t time)
{
- // Dunno if this is actually faster but at least it fills our cacheline.
- if (_active_notes.none ())
- return;
-
for (int channel = 0; channel < 16; ++channel) {
for (int note = 0; note < 128; ++note) {
- if (_active_notes[channel * 128 + note]) {
+ while (_active_notes[channel * 128 + note]) {
uint8_t buffer[3] = { MIDI_CMD_NOTE_OFF | channel, note, 0 };
Evoral::MIDIEvent<MidiBuffer::TimeType> noteoff
- (time, MIDI_CMD_NOTE_OFF, 3, buffer, false);
-
+ (time, MIDI_CMD_NOTE_OFF, 3, buffer, false);
+
dst.push_back (noteoff);
-
- _active_notes [channel * 128 + note] = false;
+ _active_notes[channel * 128 + note]--;
}
}
}
@@ -92,7 +88,8 @@ MidiStateTracker::dump (ostream& o)
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\n";
+ o << "Channel " << c+1 << " Note " << x << " is on ("
+ << (int) _active_notes[c*128+x] << "times)\n";
}
}
}