fix missing symbol on OS X
[ardour.git] / libs / backends / jack / jack_connection.cc
index d5d25c747f2106c7b944f0f38808a50906dab73e..2747832ec004911d4e3aecf107cf533c3f2a84d7 100644 (file)
@@ -19,7 +19,8 @@
 #include <iostream>
 
 #include <boost/scoped_ptr.hpp>
-#include <jack/session.h>
+
+#include <glibmm/timer.h>
 
 #include "pbd/epa.h"
 
@@ -36,6 +37,8 @@ using std::vector;
 using std::cerr;
 using std::endl;
 
+bool JackConnection::_in_control = false;
+
 static void jack_halted_callback (void* arg)
 {
        JackConnection* jc = static_cast<JackConnection*> (arg);
@@ -53,18 +56,12 @@ JackConnection::JackConnection (const std::string& arg1, const std::string& arg2
        : _jack (0)
        , _client_name (arg1)
        , session_uuid (arg2)
+       , _probed_buffer_size (0)
+       , _probed_sample_rate (0)
 {
-       _in_control = !server_running();
-}
-
-JackConnection::~JackConnection ()
-{
-       close ();
-}
+       /* See if the server is already up
+        */
 
-bool
-JackConnection::server_running ()
-{
         EnvironmentalProtectionAgency* global_epa = EnvironmentalProtectionAgency::get_global_epa ();
         boost::scoped_ptr<EnvironmentalProtectionAgency> current_epa;
 
@@ -82,11 +79,18 @@ JackConnection::server_running ()
        jack_client_t* c = jack_client_open ("ardourprobe", JackNoStartServer, &status);
 
        if (status == 0) {
+               _probed_buffer_size = jack_get_buffer_size(c);
+               _probed_sample_rate = jack_get_sample_rate(c);
                jack_client_close (c);
-               return true;
+               _in_control = false;
+       } else {
+               _in_control = true;
        }
+}
 
-       return false;
+JackConnection::~JackConnection ()
+{
+       close ();
 }
 
 int
@@ -106,19 +110,6 @@ JackConnection::open ()
                 global_epa->restore ();
         }
 
-       /* check to see if the server is already running so that we know if we
-        * are starting it.
-        */
-
-       jack_client_t* c = jack_client_open ("ardourprobe", JackNoStartServer, &status);
-
-       if (status == 0) {
-               _in_control = false;
-               jack_client_close (c);
-       } else {
-               _in_control = true;
-       }
-
        /* ensure that PATH or equivalent includes likely locations of the JACK
         * server, in case the user's default does not.
         */
@@ -154,10 +145,15 @@ JackConnection::close ()
 {
        GET_PRIVATE_JACK_POINTER_RET (_jack, -1);
 
-       if (_priv_jack) {       
+       if (_priv_jack) {
                int ret = jack_client_close (_priv_jack);
                _jack = 0;
+
+               /* If we started JACK, it will be closing down */
+               Glib::usleep (500000);
+
                Disconnected (""); /* EMIT SIGNAL */
+
                return ret;
        }