incomplete merge of master into windows (requires upcoming changes to master to be...
[ardour.git] / gtk2_ardour / midi_tracer.cc
index c4fe76252b32a1f8b957267d4ec0348d2c9bc0ca..934dffd11c161d88287dca38eea8460e837655d1 100644 (file)
 #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"
@@ -56,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;
@@ -129,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<const Manager::PortList> 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<ARDOUR::Port> p = AudioEngine::instance()->get_port_by_name (_port_combo.get_active_text());
+
+       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<AsyncMIDIPort> async = boost::dynamic_pointer_cast<AsyncMIDIPort> (p);
+
+       if (!async) {
 
-       if (p) {
-               p->parser()->any.connect_same_thread (_parser_connection, boost::bind (&MidiTracer::tracer, this, _1, _2, _3));
+               boost::shared_ptr<ARDOUR::MidiPort> mp = boost::dynamic_pointer_cast<ARDOUR::MidiPort> (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));
        }
 }
 
@@ -369,9 +407,9 @@ MidiTracer::tracer (Parser&, byte* msg, size_t len)
 
        fifo.write (&buf, 1);
 
-       if (g_atomic_int_get (&_update_queued) == 0) {
+       if (g_atomic_int_get (const_cast<gint*> (&_update_queued)) == 0) {
                gui_context()->call_slot (invalidator (*this), boost::bind (&MidiTracer::update, this));
-               g_atomic_int_inc (&_update_queued);
+               g_atomic_int_inc (const_cast<gint*> (&_update_queued));
        }
 }
 
@@ -379,7 +417,7 @@ void
 MidiTracer::update ()
 {
        bool updated = false;
-       g_atomic_int_dec_and_test (&_update_queued);
+       g_atomic_int_dec_and_test (const_cast<gint*> (&_update_queued));
 
        RefPtr<TextBuffer> buf (text.get_buffer());