const correctness.
[ardour.git] / libs / ardour / audioengine.cc
index 903fbb227dcde8cdbd0dfab0fed89a1cc587d134..79aa5d9ff8762ca0cd4fc0130f799a1739ea78fe 100644 (file)
@@ -25,6 +25,9 @@
 #include <sstream>
 
 #include <glibmm/timer.h>
+#include <jack/jack.h>
+#include <jack/thread.h>
+
 #include "pbd/pthread_utils.h"
 #include "pbd/stacktrace.h"
 #include "pbd/unknown_type.h"
@@ -1106,16 +1109,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
@@ -1123,16 +1131,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
@@ -1147,6 +1160,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);
@@ -1165,6 +1181,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);
@@ -1176,6 +1195,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);
@@ -1184,10 +1204,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);
@@ -1480,3 +1504,30 @@ AudioEngine::is_realtime () const
        GET_PRIVATE_JACK_POINTER_RET (_jack,false);
        return jack_is_realtime (_priv_jack);
 }
+
+pthread_t
+AudioEngine::create_process_thread (boost::function<void()> f, size_t stacksize)
+{
+        GET_PRIVATE_JACK_POINTER_RET (_jack, 0);
+        pthread_t thread;
+        ThreadData* td = new ThreadData (this, f, stacksize);
+
+        if (jack_client_create_thread (_priv_jack, &thread, jack_client_real_time_priority (_priv_jack), 
+                                       jack_is_realtime (_priv_jack), _start_process_thread, td)) {
+                return -1;
+        } 
+
+        return thread;
+}
+
+void*
+AudioEngine::_start_process_thread (void* arg)
+{
+        ThreadData* td = reinterpret_cast<ThreadData*> (arg);
+        boost::function<void()> f = td->f;
+        delete td;
+
+        f ();
+
+        return 0;
+}