2 Copyright (C) 2008 Paul Davis
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2 of the License, or (at your option)
10 This program is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __ardour_midi_state_tracker_h__
21 #define __ardour_midi_state_tracker_h__
23 #include <glibmm/threads.h>
25 #include "temporal/beats.h"
26 #include "ardour/midi_buffer.h"
29 template <typename T> class EventSink;
36 /** Tracks played notes, so they can be resolved in potential stuck note
37 * situations (e.g. looping, transport stop, etc).
39 class LIBARDOUR_API MidiStateTracker
44 void track (const MidiBuffer::const_iterator& from, const MidiBuffer::const_iterator& to);
45 void track (const uint8_t* evbuf);
46 void add (uint8_t note, uint8_t chn);
47 void remove (uint8_t note, uint8_t chn);
48 void resolve_notes (MidiBuffer& buffer, samplepos_t time);
49 void resolve_notes (Evoral::EventSink<samplepos_t>& buffer, samplepos_t time);
50 void resolve_notes (MidiSource& src, const Glib::Threads::Mutex::Lock& lock, Temporal::Beats time);
51 void dump (std::ostream&);
53 bool empty() const { return _on == 0; }
54 uint16_t on() const { return _on; }
55 bool active (uint8_t note, uint8_t channel) {
56 return _active_notes[(channel*128)+note] > 0;
59 template<typename Time>
60 void track (const Evoral::Event<Time>& ev) {
65 uint8_t _active_notes[128*16];
72 #endif // __ardour_midi_state_tracker_h__