From: Paul Davis Date: Fri, 2 Apr 2010 18:54:33 +0000 (+0000) Subject: (FULL) not-yet-complete JACK session management patch (TODO: get program name, vary... X-Git-Tag: 3.0-alpha5~2257 X-Git-Url: https://git.carlh.net/gitweb/?a=commitdiff_plain;h=7ed95f7c37c17d9d13fa1126d5117a17f1906637;p=ardour.git (FULL) not-yet-complete JACK session management patch (TODO: get program name, vary snapshot name, arrange quit when necessary) git-svn-id: svn://localhost/ardour2/branches/3.0@6841 d708f5d6-7413-0410-9779-e7cbd77b26cf --- diff --git a/Makefile b/Makefile index 4b80bc8285..4e0908e4cd 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,7 @@ +all: waf + +waf: + ./waf cscope: cscope.out cscope.out: cscope.files @@ -6,4 +10,4 @@ cscope.out: cscope.files cscope.files: find . -name '*.[ch]' -o -name '*.cc' > $@ -.PHONY: all cscope.files sconsi cscope +.PHONY: all cscope.files sconsi cscope waf diff --git a/libs/ardour/ardour/audioengine.h b/libs/ardour/ardour/audioengine.h index e3fcb58fa1..d9f6fa4662 100644 --- a/libs/ardour/ardour/audioengine.h +++ b/libs/ardour/ardour/audioengine.h @@ -40,6 +40,10 @@ #include "ardour/session_handle.h" #include "ardour/types.h" +#ifdef HAVE_JACK_SESSION +#include +#endif + namespace ARDOUR { class InternalPort; @@ -52,7 +56,7 @@ class AudioEngine : public SessionHandlePtr public: typedef std::set Ports; - AudioEngine (std::string client_name); + AudioEngine (std::string client_name, std::string session_uuid); virtual ~AudioEngine (); jack_client_t* jack() const; @@ -201,6 +205,11 @@ _ the regular process() call to session->process() is not made. PBD::Signal0 GraphReordered; +#ifdef HAVE_JACK_SESSION + PBD::Signal1 JackSessionEvent; +#endif + + /* this signal is emitted if the sample rate changes */ PBD::Signal1 SampleRateChanged; @@ -263,6 +272,9 @@ _ the regular process() call to session->process() is not made. void port_registration_failure (const std::string& portname); static int _xrun_callback (void *arg); +#ifdef HAVE_JACK_SESSION + static void _session_callback (jack_session_event_t *event, void *arg); +#endif static int _graph_order_callback (void *arg); static int _process_callback (nframes_t nframes, void *arg); static int _sample_rate_callback (nframes_t nframes, void *arg); @@ -277,7 +289,7 @@ _ the regular process() call to session->process() is not made. int jack_bufsize_callback (nframes_t); int jack_sample_rate_callback (nframes_t); - int connect_to_jack (std::string client_name); + int connect_to_jack (std::string client_name, std::string session_uuid); static void halted (void *); diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index bd59e83824..2b51e3f8ec 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -54,6 +54,10 @@ #include "ardour/timecode.h" #include "ardour/interpolation.h" +#ifdef HAVE_JACK_SESSION +#include +#endif + class XMLTree; class XMLNode; class AEffect; @@ -348,6 +352,9 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi nframes_t worst_input_latency () const { return _worst_input_latency; } nframes_t worst_track_latency () const { return _worst_track_latency; } +#ifdef HAVE_JACK_SESSION + void jack_session_event (jack_session_event_t* event); +#endif int save_state (std::string snapshot_name, bool pending = false); int restore_state (std::string snapshot_name); int save_template (std::string template_name); diff --git a/libs/ardour/audioengine.cc b/libs/ardour/audioengine.cc index 398a4936cc..6ffe0f6048 100644 --- a/libs/ardour/audioengine.cc +++ b/libs/ardour/audioengine.cc @@ -61,7 +61,7 @@ AudioEngine* AudioEngine::_instance = 0; #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; } -AudioEngine::AudioEngine (string client_name) +AudioEngine::AudioEngine (string client_name, string session_uuid) : ports (new Ports) { _instance = this; /* singleton */ @@ -81,7 +81,7 @@ AudioEngine::AudioEngine (string client_name) m_meter_thread = 0; g_atomic_int_set (&m_meter_exit, 0); - if (connect_to_jack (client_name)) { + if (connect_to_jack (client_name, session_uuid)) { throw NoBackendAvailable (); } @@ -188,6 +188,10 @@ AudioEngine::start () jack_set_sample_rate_callback (_priv_jack, _sample_rate_callback, this); jack_set_buffer_size_callback (_priv_jack, _bufsize_callback, this); jack_set_xrun_callback (_priv_jack, _xrun_callback, this); +#ifdef HAVE_JACK_SESSION + if( jack_set_session_callback ) + jack_set_session_callback (_priv_jack, _session_callback, this); +#endif jack_set_sync_callback (_priv_jack, _jack_sync_callback, this); jack_set_freewheel_callback (_priv_jack, _freewheel_callback, this); jack_set_port_registration_callback (_priv_jack, _registration_callback, this); @@ -299,6 +303,17 @@ AudioEngine::_xrun_callback (void *arg) return 0; } +#ifdef HAVE_JACK_SESSION +void +AudioEngine::_session_callback (jack_session_event_t *event, void *arg) +{ + printf( "helo.... " ); + AudioEngine* ae = static_cast (arg); + if (ae->connected()) { + ae->JackSessionEvent ( event ); /* EMIT SIGNAL */ + } +} +#endif int AudioEngine::_graph_order_callback (void *arg) { @@ -1133,14 +1148,19 @@ AudioEngine::remove_all_ports () } int -AudioEngine::connect_to_jack (string client_name) +AudioEngine::connect_to_jack (string client_name, string session_uuid) { jack_options_t options = JackNullOption; jack_status_t status; const char *server_name = NULL; jack_client_name = client_name; /* might be reset below */ - _jack = jack_client_open (jack_client_name.c_str(), options, &status, server_name); +#ifdef HAVE_JACK_SESSION + if (! session_uuid.empty()) + _jack = jack_client_open (jack_client_name.c_str(), JackSessionID, &status, session_uuid.c_str()); + else +#endif + _jack = jack_client_open (jack_client_name.c_str(), options, &status, server_name); if (_jack == NULL) { // error message is not useful here @@ -1193,7 +1213,7 @@ AudioEngine::reconnect_to_jack () Glib::usleep (250000); } - if (connect_to_jack (jack_client_name)) { + if (connect_to_jack (jack_client_name, "")) { error << _("failed to connect to JACK") << endmsg; return -1; } @@ -1236,6 +1256,10 @@ AudioEngine::reconnect_to_jack () jack_set_sample_rate_callback (_priv_jack, _sample_rate_callback, this); jack_set_buffer_size_callback (_priv_jack, _bufsize_callback, this); jack_set_xrun_callback (_priv_jack, _xrun_callback, this); +#ifdef HAVE_JACK_SESSION + if( jack_set_session_callback ) + jack_set_session_callback (_priv_jack, _session_callback, this); +#endif jack_set_sync_callback (_priv_jack, _jack_sync_callback, this); jack_set_freewheel_callback (_priv_jack, _freewheel_callback, this); diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 504eadcc92..22a9100b31 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -725,6 +725,35 @@ Session::remove_state (string snapshot_name) sys::remove (xml_path); } +#ifdef HAVE_JACK_SESSION +void +Session::jack_session_event( jack_session_event_t * event ) +{ + if (save_state ("jacksession_snap")) { + event->flags = JackSessionSaveError; + } else { + sys::path xml_path (_session_dir->root_path()); + xml_path /= legalize_for_path ("jacksession_snap") + statefile_suffix; + + string cmd ("PROG_NAME -U "); + cmd += event->client_uuid; + cmd += ' \"'; + cmd += xml_path.to_string(); + cmd += '\"'; + + event->command_line = strdup (cmd.c_str()); + } + + jack_session_reply (_engine.jack(), event); + + if (event->type == JackSessionSaveAndQuit) { + // TODO: make ardour quit. + } + + jack_session_event_free( event ); +} +#endif + int Session::save_state (string snapshot_name, bool pending) { diff --git a/libs/ardour/wscript b/libs/ardour/wscript index dd0138968c..54fe07199f 100644 --- a/libs/ardour/wscript +++ b/libs/ardour/wscript @@ -239,6 +239,8 @@ def configure(conf): conf.check(header_name='sys/vfs.h', define_name='HAVE_SYS_VFS_H') conf.check(header_name='wordexp.h', define_name='HAVE_WORDEXP') + + conf.check(header_name='jack/session.h', define_name='HAVE_JACK_SESSION') if flac_supported(): conf.define ('HAVE_FLAC', 1) diff --git a/wscript b/wscript index 75cf78ce7f..371f214691 100644 --- a/wscript +++ b/wscript @@ -461,6 +461,8 @@ def configure(conf): autowaf.check_header(conf, 'boost/signals2.hpp', mandatory = True) + autowaf.check_header(conf, 'jack/session.h', define="JACK_SESSION") + conf.check_cc(fragment = "#include \nint main(void) { return (BOOST_VERSION >= 103900 ? 0 : 1); }\n", execute = "1", mandatory = True, @@ -524,6 +526,8 @@ def configure(conf): autowaf.display_msg(conf, 'VST Support', opts.vst) if opts.vst: conf.define('VST_SUPPORT', 1) + if bool(conf.env['JACK_SESSION']): + conf.define ('HAVE_JACK_SESSION', 1) autowaf.display_msg(conf, 'Wiimote Support', opts.wiimote) if opts.wiimote: conf.define('WIIMOTE',1)