extern uint64_t AudioUnits;
extern uint64_t ControlProtocols;
extern uint64_t CycleTimers;
+ extern uint64_t MidiTrackers;
}
}
void resize(size_t);
- bool merge(const MidiBuffer& a, const MidiBuffer& b);
bool merge_in_place(const MidiBuffer &other);
template<typename BufferType, typename EventType>
#include <iostream>
#include <algorithm>
+#include <sstream>
#include "pbd/compose.h"
ebuf->reset();
if (input) {
+ DEBUG_TRACE (PBD::DEBUG::LV2, string_compose ("%1 bytes of MIDI waiting @ %2\n", mbuf.size(), (void*) mbuf.data()));
for (MidiBuffer::iterator e = mbuf.begin(); e != mbuf.end(); ++e) {
const Evoral::MIDIEvent<framepos_t> ev(*e, false);
uint32_t type = LV2Plugin::midi_event_type();
#ifndef NDEBUG
- DEBUG_TRACE (PBD::DEBUG::LV2, string_compose ("(FLUSH) MIDI event of size %1\n", ev.size()));
+ DEBUG_TRACE (PBD::DEBUG::LV2, string_compose ("\tMIDI event of size %1 @ %2\n", ev.size(), ev.time()));
for (uint16_t x = 0; x < ev.size(); ++x) {
- DEBUG_TRACE (PBD::DEBUG::LV2, string_compose ("\tByte[%1] = %2\n", x, (int) ev.buffer()[x]));
+ std::stringstream ss;
+ ss << "\t\tByte[" << x << "] = " << std::hex << (int) ev.buffer()[x] << std::dec << std::endl;
+ DEBUG_TRACE (PBD::DEBUG::LV2, ss.str());
}
#endif
ebuf->append(ev.time(), 0, type, ev.size(), ev.buffer());
uint64_t PBD::DEBUG::AudioUnits = PBD::new_debug_bit ("audiounits");
uint64_t PBD::DEBUG::ControlProtocols = PBD::new_debug_bit ("controlprotocols");
uint64_t PBD::DEBUG::CycleTimers = PBD::new_debug_bit ("cycletimers");
+uint64_t PBD::DEBUG::MidiTrackers = PBD::new_debug_bit ("miditrackers");
MidiBuffer::push_back(const Evoral::MIDIEvent<TimeType>& ev)
{
const size_t stamp_size = sizeof(TimeType);
- /*cerr << "MidiBuffer: pushing event @ " << ev.time()
- << " size = " << ev.size() << endl;*/
if (_size + stamp_size + ev.size() >= _capacity) {
cerr << "MidiBuffer::push_back failed (buffer is full)" << endl;
MidiBuffer::push_back(const jack_midi_event_t& ev)
{
const size_t stamp_size = sizeof(TimeType);
+
if (_size + stamp_size + ev.size >= _capacity) {
cerr << "MidiBuffer::push_back failed (buffer is full)" << endl;
return false;
return false;
}
+#ifndef NDEBUG
+ if (DEBUG::MidiIO & PBD::debug_bits) {
+ DEBUG_STR_DECL(a);
+ DEBUG_STR_APPEND(a, string_compose ("midibuffer %1 push jack event @ %2 sz %3 ", this, ev.time, ev.size));
+ for (size_t i=0; i < ev.size; ++i) {
+ DEBUG_STR_APPEND(a,hex);
+ DEBUG_STR_APPEND(a,"0x");
+ DEBUG_STR_APPEND(a,(int)ev.buffer[i]);
+ DEBUG_STR_APPEND(a,' ');
+ }
+ DEBUG_STR_APPEND(a,'\n');
+ DEBUG_TRACE (DEBUG::MidiIO, DEBUG_STR(a).str());
+ }
+#endif
+
uint8_t* const write_loc = _data + _size;
*((TimeType*)write_loc) = ev.time;
memcpy(write_loc + stamp_size, ev.buffer, ev.size);
/** Merge \a other into this buffer. Realtime safe. */
bool
-MidiBuffer::merge_in_place(const MidiBuffer &other)
+MidiBuffer::merge_in_place (const MidiBuffer &other)
{
- if (other.size() || size()) {
+ if (other.size() && size()) {
DEBUG_TRACE (DEBUG::MidiIO, string_compose ("merge in place, sizes %1/%2\n", size(), other.size()));
}
return true;
}
-/** Clear, and merge \a a and \a b into this buffer.
- *
- * \return true if complete merge was successful
- */
-bool
-MidiBuffer::merge(const MidiBuffer& a, const MidiBuffer& b)
-{
- _size = 0;
-
- if (this == &a) {
- return merge_in_place(b);
- } else if (this == &b) {
- return merge_in_place(a);
- }
-
- const_iterator ai = a.begin();
- const_iterator bi = b.begin();
-
- resize(a.size() + b.size());
- while (ai != a.end() && bi != b.end()) {
- if ((*ai).time() < (*bi).time()) {
- memcpy(_data + _size, (*ai).buffer(), (*ai).size());
- _size += (*ai).size();
- ++ai;
- } else {
- memcpy(_data + _size, (*bi).buffer(), (*bi).size());
- _size += (*bi).size();
- ++bi;
- }
- }
-
- while (ai != a.end()) {
- memcpy(_data + _size, (*ai).buffer(), (*ai).size());
- _size += (*ai).size();
- ++ai;
- }
-
- while (bi != b.end()) {
- memcpy(_data + _size, (*bi).buffer(), (*bi).size());
- _size += (*bi).size();
- ++bi;
- }
-
- return true;
-}
-
Glib::Mutex::Lock lm (capture_info_lock);
if (capture_info.empty()) {
- return;
+ goto no_capture_stuff_to_do;
}
if (abort_capture) {
delete *ci;
}
+ capture_info.clear ();
+ capture_start_frame = 0;
+
+ no_capture_stuff_to_do:
+
if (_playlist) {
midi_playlist()->clear_note_trackers ();
}
-
- capture_info.clear ();
- capture_start_frame = 0;
}
void
for (NoteTrackers::iterator n = _note_trackers.begin(); n != _note_trackers.end(); ++n) {
delete n->second;
}
+ DEBUG_TRACE (DEBUG::MidiTrackers, string_compose ("%1 clears all note trackers\n", name()));
_note_trackers.clear ();
}
src->set_note_mode(mode);
/*
- cerr << "MR read @ " << position << " * " << to_read
+ cerr << "MR " << name () << " read @ " << position << " * " << to_read
<< " _position = " << _position
<< " _start = " << _start
<< " intoffset = " << internal_offset
BeatsFramesConverter converter(_session.tempo_map(), source_start);
- DEBUG_TRACE (DEBUG::MidiSourceIO, string_compose ("MidiSource::midi-read() sstart %1 start %2 cnt %3 tracker %4\n",
- source_start, start, cnt, tracker));
+ DEBUG_TRACE (DEBUG::MidiSourceIO, string_compose ("MidiSource::midi-read() %5 sstart %1 start %2 cnt %3 tracker %4\n",
+ source_start, start, cnt, tracker, name()));
if (_model) {
Evoral::Sequence<double>::const_iterator& i = _model_iter;
DEBUG_TRACE (DEBUG::MidiSourceIO, string_compose ("*** %1 search for relevant iterator for %1 / %2\n", _name, source_start, start));
for (i = _model->begin(0, false, filtered); i != _model->end(); ++i) {
if (converter.to(i->time()) >= start) {
+ DEBUG_TRACE (DEBUG::MidiSourceIO, string_compose ("***\tstop iterator search @ %1\n", i->time()));
break;
}
}
*/
#include <iostream>
+
+#include "pbd/compose.h"
+
+#include "ardour/debug.h"
#include "ardour/event_type_map.h"
#include "ardour/midi_ring_buffer.h"
#include "ardour/midi_source.h"
void
MidiStateTracker::reset ()
{
+ DEBUG_TRACE (PBD::DEBUG::MidiTrackers, string_compose ("%1: reset\n", this));
memset (_active_notes, 0, sizeof (_active_notes));
_on = 0;
}
{
++_active_notes[note + 128 * chn];
++_on;
+ DEBUG_TRACE (PBD::DEBUG::MidiTrackers, string_compose ("MST @ %1 ON %2/%3 total on %4\n",
+ this, (int) note, (int) chn, _on));
}
void
break;
}
+ DEBUG_TRACE (PBD::DEBUG::MidiTrackers, string_compose ("MST @ %1 OFF %2/%3 total on %4\n",
+ this, (int) note, (int) chn, _on));
}
void
{
looped = false;
+ DEBUG_TRACE (PBD::DEBUG::MidiTrackers, string_compose ("%1 track notes, looped = %2\n", this, looped));
+
for (MidiBuffer::iterator i = from; i != to; ++i) {
const Evoral::MIDIEvent<MidiBuffer::TimeType> ev(*i, false);
if (ev.event_type() == LoopEventType) {
void
MidiStateTracker::resolve_notes (MidiBuffer &dst, framepos_t time)
{
+ DEBUG_TRACE (PBD::DEBUG::MidiTrackers, string_compose ("%1 MB-resolve notes @ %2 on = %3\n", this, time, _on));
+
if (!_on) {
return;
}
(MIDI_CMD_NOTE_OFF, time, 3, buffer, false);
dst.push_back (noteoff);
_active_notes[note + 128 * channel]--;
+ DEBUG_TRACE (PBD::DEBUG::MidiTrackers, string_compose ("%1: MB-resolved note %2/%3 at %4\n",
+ this, (int) note, (int) channel, time));
}
}
}
{
uint8_t buf[3];
+ DEBUG_TRACE (PBD::DEBUG::MidiTrackers, string_compose ("%1 EVS-resolve notes @ %2 on = %3\n", this, time, _on));
+
if (!_on) {
return;
}
buf[2] = 0;
dst.write (time, EventTypeMap::instance().midi_event_type (buf[0]), 3, buf);
_active_notes[note + 128 * channel]--;
+ DEBUG_TRACE (PBD::DEBUG::MidiTrackers, string_compose ("%1: EVS-resolved note %2/%3 at %4\n",
+ this, (int) note, (int) channel, time));
}
}
}
void
MidiStateTracker::resolve_notes (MidiSource& src, Evoral::MusicalTime time)
{
+ DEBUG_TRACE (PBD::DEBUG::MidiTrackers, string_compose ("%1 MS-resolve notes @ %2 on = %3\n", this, time, _on));
+
if (!_on) {
return;
}
ev.set_note (note);
ev.set_velocity (0);
src.append_event_unlocked_beats (ev);
+ DEBUG_TRACE (PBD::DEBUG::MidiTrackers, string_compose ("%1: MS-resolved note %2/%3 at %4\n",
+ this, (int) note, (int) channel, time));
_active_notes[note + 128 * channel]--;
/* don't stack events up at the same time */
time += 1.0/128.0;
MidiTrack::realtime_handle_transport_stopped ()
{
Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
+
if (!lm.locked ()) {
return;
}