2 Copyright (C) 2013 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <boost/scoped_ptr.hpp>
21 #include <jack/session.h>
25 #include "ardour/jack_connection.h"
27 #define GET_PRIVATE_JACK_POINTER(j) jack_client_t* _priv_jack = (jack_client_t*) (j); if (!_priv_jack) { return; }
28 #define GET_PRIVATE_JACK_POINTER_RET(j,r) jack_client_t* _priv_jack = (jack_client_t*) (j); if (!_priv_jack) { return r; }
30 using namespace ARDOUR;
33 static void jack_halted_callback (void* arg)
35 JackConnection* jc = static_cast<JackConnection*> (arg);
36 jc->halted_callback ();
39 static void jack_halted_info_callback (jack_status_t code, const char* reason, void* arg)
41 JackConnection* jc = static_cast<JackConnection*> (arg);
42 jc->halted_info_callback (code, reason);
46 JackConnection::JackConnection (const std::string& arg1, const std::string& arg2)
53 JackConnection::~JackConnection ()
59 JackConnection::server_running ()
61 EnvironmentalProtectionAgency* global_epa = EnvironmentalProtectionAgency::get_global_epa ();
62 boost::scoped_ptr<EnvironmentalProtectionAgency> current_epa;
64 /* revert all environment settings back to whatever they were when
65 * ardour started, because ardour's startup script may have reset
66 * something in ways that interfere with finding/starting JACK.
70 current_epa.reset (new EnvironmentalProtectionAgency(true)); /* will restore settings when we leave scope */
71 global_epa->restore ();
75 jack_client_t* c = jack_client_open ("ardourprobe", JackNoStartServer, &status);
78 jack_client_close (c);
86 JackConnection::open ()
88 EnvironmentalProtectionAgency* global_epa = EnvironmentalProtectionAgency::get_global_epa ();
89 boost::scoped_ptr<EnvironmentalProtectionAgency> current_epa;
94 /* revert all environment settings back to whatever they were when ardour started
98 current_epa.reset (new EnvironmentalProtectionAgency(true)); /* will restore settings when we leave scope */
99 global_epa->restore ();
102 if ((_jack = jack_client_open (_client_name.c_str(), JackSessionID, &status, session_uuid.c_str())) == 0) {
106 if (status & JackNameNotUnique) {
107 _client_name = jack_get_client_name (_jack);
110 /* attach halted handler */
112 if (jack_on_info_shutdown) {
113 jack_on_info_shutdown (_jack, jack_halted_info_callback, this);
115 jack_on_shutdown (_jack, jack_halted_callback, this);
122 JackConnection::close ()
124 GET_PRIVATE_JACK_POINTER_RET (_jack, -1);
127 return jack_client_close (_priv_jack);
134 JackConnection::halted_callback ()
141 JackConnection::halted_info_callback (jack_status_t /*status*/, const char* reason)
144 Disconnected (reason);