- if (event.is_note_on()) {
- _active_notes [event.note() + 128 * event.channel()]++;
- } else if (event.is_note_off()){
- if (_active_notes[event.note() + 128 * event.channel()]) {
- _active_notes [event.note() + 128 * event.channel()]--;
- }
+ if (_active_notes[note+128 * chn] == 0) {
+ ++_on;
+ }
+ ++_active_notes[note + 128 * chn];
+
+ if (_active_notes[note+128 * chn] > 1) {
+ //cerr << this << " note " << (int) note << '/' << (int) chn << " was already on, now at " << (int) _active_notes[note+128*chn] << endl;
+ }
+
+ DEBUG_TRACE (PBD::DEBUG::MidiTrackers, string_compose ("%1 ON %2/%3 voices %5 total on %4\n",
+ this, (int) note, (int) chn, _on,
+ (int) _active_notes[note+128 * chn]));
+}
+
+void
+MidiStateTracker::remove (uint8_t note, uint8_t chn)
+{
+ switch (_active_notes[note + 128 * chn]) {
+ case 0:
+ break;
+ case 1:
+ --_on;
+ _active_notes [note + 128 * chn] = 0;
+ break;
+ default:
+ --_active_notes [note + 128 * chn];
+ break;
+
+ }
+ DEBUG_TRACE (PBD::DEBUG::MidiTrackers, string_compose ("%1 OFF %2/%3 current voices = %5 total on %4\n",
+ this, (int) note, (int) chn, _on,
+ (int) _active_notes[note+128 * chn]));
+}
+
+void
+MidiStateTracker::track (const MidiBuffer::const_iterator &from, const MidiBuffer::const_iterator &to)
+{
+ for (MidiBuffer::const_iterator i = from; i != to; ++i) {
+ track(*i);