add tim's jack_utils code to rationalize setup of JACK config
[ardour.git] / libs / ardour / jack_connection.cc
index d2b69c31fb029fc0717857a905359d28f4641c83..57950b0e17086004dfcdd8cd6453e3ab5ae4b918 100644 (file)
 #include "pbd/epa.h"
 
 #include "ardour/jack_connection.h"
+#include "ardour/jack_utils.h"
 
 #define GET_PRIVATE_JACK_POINTER(j)  jack_client_t* _priv_jack = (jack_client_t*) (j); if (!_priv_jack) { return; }
 #define GET_PRIVATE_JACK_POINTER_RET(j,r) jack_client_t* _priv_jack = (jack_client_t*) (j); if (!_priv_jack) { return r; }
 
 using namespace ARDOUR;
 using namespace PBD;
+using std::string;
+using std::vector;
 
 static void jack_halted_callback (void* arg)
 {
@@ -55,6 +58,33 @@ JackConnection::~JackConnection ()
        close ();
 }
 
+bool
+JackConnection::server_running ()
+{
+        EnvironmentalProtectionAgency* global_epa = EnvironmentalProtectionAgency::get_global_epa ();
+        boost::scoped_ptr<EnvironmentalProtectionAgency> current_epa;
+
+        /* revert all environment settings back to whatever they were when
+        * ardour started, because ardour's startup script may have reset
+        * something in ways that interfere with finding/starting JACK.
+         */
+
+        if (global_epa) {
+                current_epa.reset (new EnvironmentalProtectionAgency(true)); /* will restore settings when we leave scope */
+                global_epa->restore ();
+        }
+
+       jack_status_t status;
+       jack_client_t* c = jack_client_open ("ardourprobe", JackNoStartServer, &status);
+
+       if (status == 0) {
+               jack_client_close (c);
+               return true;
+       }
+
+       return false;
+}
+
 int
 JackConnection::open ()
 {
@@ -72,6 +102,14 @@ JackConnection::open ()
                 global_epa->restore ();
         }
 
+       /* ensure that PATH or equivalent includes likely locations of the JACK
+        * server, in case the user's default does not.
+        */
+
+       vector<string> dirs;
+       get_jack_server_dir_paths (dirs);
+       set_path_env_for_jack_autostart (dirs);
+
        if ((_jack = jack_client_open (_client_name.c_str(), JackSessionID, &status, session_uuid.c_str())) == 0) {
                return -1;
        }