27 #include "ardour/debug.h"
36 MidiStateTracker::MidiStateTracker ()
42 MidiStateTracker::reset ()
45 memset (_active_notes, 0,
sizeof (_active_notes));
50 MidiStateTracker::add (uint8_t note, uint8_t chn)
52 if (_active_notes[note+128 * chn] == 0) {
55 ++_active_notes[note + 128 * chn];
57 if (_active_notes[note+128 * chn] > 1) {
58 cerr <<
this <<
" note " << (int) note <<
'/' << (
int) chn <<
" was already on, now at " << (int) _active_notes[note+128*chn] << endl;
62 this, (
int) note, (
int) chn, _on,
63 (
int) _active_notes[note+128 * chn]));
67 MidiStateTracker::remove (uint8_t note, uint8_t chn)
69 switch (_active_notes[note + 128 * chn]) {
74 _active_notes [note + 128 * chn] = 0;
77 --_active_notes [note + 128 * chn];
82 this, (
int) note, (
int) chn, _on,
83 (
int) _active_notes[note+128 * chn]));
95 MidiStateTracker::track (
const uint8_t* evbuf)
97 const uint8_t type = evbuf[0] & 0xF0;
98 const uint8_t chan = evbuf[0] & 0x0F;
107 remove(evbuf[1], chan);
121 for (
int channel = 0; channel < 16; ++channel) {
122 for (
int note = 0; note < 128; ++note) {
123 while (_active_notes[note + 128 * channel]) {
124 uint8_t buffer[3] = { ((uint8_t) (
MIDI_CMD_NOTE_OFF | channel)), uint8_t (note), 0 };
131 _active_notes[note + 128 * channel]--;
133 this, (
int) note, (
int) channel, time));
151 for (
int channel = 0; channel < 16; ++channel) {
152 for (
int note = 0; note < 128; ++note) {
153 while (_active_notes[note + 128 * channel]) {
161 _active_notes[note + 128 * channel]--;
163 this, (
int) note, (
int) channel, time));
181 for (
int channel = 0; channel < 16; ++channel) {
182 for (
int note = 0; note < 128; ++note) {
183 while (_active_notes[note + 128 * channel]) {
191 this, (
int) note, (
int) channel, time));
192 _active_notes[note + 128 * channel]--;
202 MidiStateTracker::dump (ostream& o)
205 for (
int c = 0; c < 16; ++c) {
206 for (
int x = 0; x < 128; ++x) {
207 if (_active_notes[c * 128 + x]) {
208 o <<
"Channel " << c+1 <<
" Note " << x <<
" is on ("
209 << (int) _active_notes[c*128+x] <<
"times)\n";
virtual uint32_t write(Time time, EventType type, uint32_t size, const uint8_t *buf)=0
#define MIDI_CMD_NOTE_OFF
Glib::Threads::Mutex::Lock Lock
void set_type(uint8_t type)
void set_channel(uint8_t channel)
virtual void append_event_beats(const Lock &lock, const Evoral::Event< Evoral::Beats > &ev)=0
#define DEBUG_TRACE(bits, str)
bool push_back(const Evoral::MIDIEvent< TimeType > &event)
LIBARDOUR_API uint64_t MidiTrackers
AutomationType midi_parameter_type(uint8_t status)
#define MIDI_CTL_ALL_NOTES_OFF
std::string string_compose(const std::string &fmt, const T1 &o1)
void set_velocity(uint8_t value)