Remove MMC thread protection which is pointless now that only JACK MIDI ports are...
[ardour.git] / libs / ardour / audioengine.cc
index 2282a20809c3c5767a028a132366feb77d9ce437..fb81ccd144e62c814feaa5be89276fdd28c3f224 100644 (file)
@@ -32,7 +32,9 @@
 #include "pbd/stacktrace.h"
 #include "pbd/unknown_type.h"
 
-#include "midi++/jack.h"
+#include "midi++/port.h"
+#include "midi++/mmc.h"
+#include "midi++/manager.h"
 
 #include "ardour/amp.h"
 #include "ardour/audio_port.h"
@@ -145,7 +147,7 @@ _thread_init_callback (void * /*arg*/)
 
        SessionEvent::create_per_thread_pool (X_("Audioengine"), 512);
 
-       MIDI::JACK_MidiPort::set_process_thread (pthread_self());
+       MIDI::Port::set_process_thread (pthread_self());
 }
 
 typedef void (*_JackInfoShutdownCallback)(jack_status_t code, const char* reason, void *arg);
@@ -260,7 +262,7 @@ AudioEngine::stop (bool forever)
                } else {
                        jack_deactivate (_priv_jack);
                        Stopped(); /* EMIT SIGNAL */
-                       MIDI::JACK_MidiPort::JackHalted (); /* EMIT SIGNAL */
+                       MIDI::Port::JackHalted (); /* EMIT SIGNAL */
                }
        }
 
@@ -1071,7 +1073,7 @@ AudioEngine::halted (void *arg)
 
        if (was_running) {
                ae->Halted(""); /* EMIT SIGNAL */
-               MIDI::JACK_MidiPort::JackHalted (); /* EMIT SIGNAL */
+               MIDI::Port::JackHalted (); /* EMIT SIGNAL */
        }
 }
 
@@ -1109,16 +1111,21 @@ AudioEngine::n_physical_outputs (DataType type) const
 {
        GET_PRIVATE_JACK_POINTER_RET (_jack,0);
        const char ** ports;
-       uint32_t i = 0;
+       uint32_t cnt = 0;
 
        if ((ports = jack_get_ports (_priv_jack, NULL, type.to_jack_type(), JackPortIsPhysical|JackPortIsInput)) == 0) {
                return 0;
        }
 
-       for (i = 0; ports[i]; ++i) {}
+       for (uint32_t i = 0; ports[i]; ++i) {
+                if (!strstr (ports[i], "Midi-Through")) {
+                        cnt++;
+                }
+        }
+
        free (ports);
 
-       return i;
+       return cnt;
 }
 
 uint32_t
@@ -1126,16 +1133,21 @@ AudioEngine::n_physical_inputs (DataType type) const
 {
        GET_PRIVATE_JACK_POINTER_RET (_jack,0);
        const char ** ports;
-       uint32_t i = 0;
-
+       uint32_t cnt = 0;
+        
        if ((ports = jack_get_ports (_priv_jack, NULL, type.to_jack_type(), JackPortIsPhysical|JackPortIsOutput)) == 0) {
                return 0;
        }
 
-       for (i = 0; ports[i]; ++i) {}
+       for (uint32_t i = 0; ports[i]; ++i) {
+                if (!strstr (ports[i], "Midi-Through")) {
+                        cnt++;
+                }
+        }
+
        free (ports);
 
-       return i;
+       return cnt;
 }
 
 void
@@ -1150,6 +1162,9 @@ AudioEngine::get_physical_inputs (DataType type, vector<string>& ins)
 
        if (ports) {
                for (uint32_t i = 0; ports[i]; ++i) {
+                        if (strstr (ports[i], "Midi-Through")) {
+                                continue;
+                        }
                        ins.push_back (ports[i]);
                }
                free (ports);
@@ -1168,6 +1183,9 @@ AudioEngine::get_physical_outputs (DataType type, vector<string>& outs)
        }
 
        for (i = 0; ports[i]; ++i) {
+                if (strstr (ports[i], "Midi-Through")) {
+                        continue;
+                }
                outs.push_back (ports[i]);
        }
        free (ports);
@@ -1179,6 +1197,7 @@ AudioEngine::get_nth_physical (DataType type, uint32_t n, int flag)
        GET_PRIVATE_JACK_POINTER_RET (_jack,"");
        const char ** ports;
        uint32_t i;
+       uint32_t idx;
        string ret;
 
        assert(type != DataType::NIL);
@@ -1187,10 +1206,14 @@ AudioEngine::get_nth_physical (DataType type, uint32_t n, int flag)
                return ret;
        }
 
-       for (i = 0; i < n && ports[i]; ++i) {}
+       for (i = 0, idx = 0; idx < n && ports[i]; ++i) {
+                if (!strstr (ports[i], "Midi-Through")) {
+                        ++idx;
+                }
+        }
 
-       if (ports[i]) {
-               ret = ports[i];
+       if (ports[idx]) {
+               ret = ports[idx];
        }
 
        free ((const char **) ports);
@@ -1334,7 +1357,7 @@ AudioEngine::disconnect_from_jack ()
        if (_running) {
                _running = false;
                Stopped(); /* EMIT SIGNAL */
-               MIDI::JACK_MidiPort::JackHalted (); /* EMIT SIGNAL */
+               MIDI::Port::JackHalted (); /* EMIT SIGNAL */
        }
 
        return 0;
@@ -1372,6 +1395,8 @@ AudioEngine::reconnect_to_jack ()
 
        GET_PRIVATE_JACK_POINTER_RET (_jack,-1);
 
+       MIDI::Manager::instance()->reestablish (_priv_jack);
+       
        if (_session) {
                _session->reset_jack_connection (_priv_jack);
                 jack_bufsize_callback (jack_get_buffer_size (_priv_jack));
@@ -1412,6 +1437,8 @@ AudioEngine::reconnect_to_jack ()
                (*i)->reconnect ();
        }
 
+       MIDI::Manager::instance()->reconnect ();
+
        Running (); /* EMIT SIGNAL*/
 
        start_metering_thread ();