- 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<AsyncMIDIPort> async = boost::dynamic_pointer_cast<AsyncMIDIPort> (p);
+
+ if (!async) {
+
+ 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));
+ mp->set_trace_on (true);
+ traced_port = mp;
+ }
+
+ } else {
+ async->parser()->any.connect_same_thread (_parser_connection, boost::bind (&MidiTracer::tracer, this, _1, _2, _3));