X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fmidi_tracer.cc;h=a92c5a57e349548f19a41264dee340faa8bc366c;hb=9f4a00fa898845ba177955f115fa2f96d62a8643;hp=2515bef08d2ead164e14915b8db040a127ead0c4;hpb=11619a37bff79c050e39e434bc9899b516cbe4a1;p=ardour.git diff --git a/gtk2_ardour/midi_tracer.cc b/gtk2_ardour/midi_tracer.cc index 2515bef08d..a92c5a57e3 100644 --- a/gtk2_ardour/midi_tracer.cc +++ b/gtk2_ardour/midi_tracer.cc @@ -23,8 +23,14 @@ #include #include +#include "pbd/localtime_r.h" +#include "pbd/timersub.h" + #include "midi++/parser.h" -#include "midi++/manager.h" + +#include "ardour/async_midi_port.h" +#include "ardour/midi_port.h" +#include "ardour/audioengine.h" #include "midi_tracer.h" #include "gui_thread.h" @@ -53,7 +59,8 @@ MidiTracer::MidiTracer () , collect_button (_("Enabled")) , delta_time_button (_("Delta times")) { - Manager::instance()->PortsChanged.connect (_manager_connection, invalidator (*this), boost::bind (&MidiTracer::ports_changed, this), gui_context()); + ARDOUR::AudioEngine::instance()->PortRegisteredOrUnregistered.connect + (_manager_connection, invalidator (*this), boost::bind (&MidiTracer::ports_changed, this), gui_context()); _last_receipt.tv_sec = 0; _last_receipt.tv_usec = 0; @@ -126,24 +133,58 @@ MidiTracer::ports_changed () { string const c = _port_combo.get_active_text (); _port_combo.clear (); + + ARDOUR::PortManager::PortList pl; + ARDOUR::AudioEngine::instance()->get_ports (ARDOUR::DataType::MIDI, pl); + + if (pl.empty()) { + _port_combo.set_active_text (""); + return; + } - boost::shared_ptr p = Manager::instance()->get_midi_ports (); - for (Manager::PortList::const_iterator i = p->begin(); i != p->end(); ++i) { + for (ARDOUR::PortManager::PortList::const_iterator i = pl.begin(); i != pl.end(); ++i) { _port_combo.append_text ((*i)->name()); } - _port_combo.set_active_text (c); + if (c.empty()) { + _port_combo.set_active_text (pl.front()->name()); + } else { + _port_combo.set_active_text (c); + } } void MidiTracer::port_changed () { + using namespace ARDOUR; + disconnect (); - Port* p = Manager::instance()->port (_port_combo.get_active_text()); + boost::shared_ptr p = AudioEngine::instance()->get_port_by_name (_port_combo.get_active_text()); - if (p) { - p->parser()->any.connect_same_thread (_parser_connection, boost::bind (&MidiTracer::tracer, this, _1, _2, _3)); + if (!p) { + std::cerr << "port not found\n"; + return; + } + + /* The inheritance heirarchy makes this messy. AsyncMIDIPort has two + * available MIDI::Parsers what we could connect to, ::self_parser() + * (from ARDOUR::MidiPort) and ::parser() from MIDI::Port. One day, + * this mess will all go away ... + */ + + boost::shared_ptr async = boost::dynamic_pointer_cast (p); + + if (!async) { + + boost::shared_ptr mp = boost::dynamic_pointer_cast (p); + + if (mp) { + mp->self_parser().any.connect_same_thread (_parser_connection, boost::bind (&MidiTracer::tracer, this, _1, _2, _3)); + } + + } else { + async->parser()->any.connect_same_thread (_parser_connection, boost::bind (&MidiTracer::tracer, this, _1, _2, _3)); } } @@ -174,7 +215,7 @@ MidiTracer::tracer (Parser&, byte* msg, size_t len) s = snprintf (buf, bufsize, "+%02" PRId64 ":%06" PRId64, (int64_t) delta.tv_sec, (int64_t) delta.tv_usec); bufsize -= s; } else { - localtime_r (&tv.tv_sec, &now); + localtime_r ((const time_t*)&tv.tv_sec, &now); s = strftime (buf, bufsize, "%H:%M:%S", &now); bufsize -= s; s += snprintf (&buf[s], bufsize, ".%06" PRId64, (int64_t) tv.tv_usec); @@ -300,7 +341,11 @@ MidiTracer::tracer (Parser&, byte* msg, size_t len) s += snprintf ( &buf[s], bufsize, " MTC full frame to %02d:%02d:%02d:%02d\n", msg[5] & 0x1f, msg[6], msg[7], msg[8] ); + } else if (len == 3 && msg[0] == MIDI::position) { + /* MIDI Song Position */ + int midi_beats = (msg[2] << 7) | msg[1]; + s += snprintf (&buf[s], bufsize, "%16s %d\n", "Position", (int) midi_beats); } else { /* other sys-ex */ @@ -362,9 +407,9 @@ MidiTracer::tracer (Parser&, byte* msg, size_t len) fifo.write (&buf, 1); - if (g_atomic_int_get (const_cast(&_update_queued)) == 0) { - gui_context()->call_slot (invalidator (*this), boost::bind (&MidiTracer::update, this)); - g_atomic_int_inc (const_cast(&_update_queued)); + if (g_atomic_int_get (const_cast (&_update_queued)) == 0) { + gui_context()->call_slot (invalidator (*this), boost::bind (&MidiTracer::update, this)); + g_atomic_int_inc (const_cast (&_update_queued)); } } @@ -372,7 +417,7 @@ void MidiTracer::update () { bool updated = false; - g_atomic_int_dec_and_test (const_cast(&_update_queued)); + g_atomic_int_dec_and_test (const_cast (&_update_queued)); RefPtr buf (text.get_buffer());