(FULL) not-yet-complete JACK session management patch (TODO: get program name, vary...
authorPaul Davis <paul@linuxaudiosystems.com>
Fri, 2 Apr 2010 18:54:33 +0000 (18:54 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Fri, 2 Apr 2010 18:54:33 +0000 (18:54 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@6841 d708f5d6-7413-0410-9779-e7cbd77b26cf

Makefile
libs/ardour/ardour/audioengine.h
libs/ardour/ardour/session.h
libs/ardour/audioengine.cc
libs/ardour/session_state.cc
libs/ardour/wscript
wscript

index 4b80bc8285399327999c814dfce048f57ab6dddb..4e0908e4cdeefe2ff459647eff2e9db9f63ffb10 100644 (file)
--- 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
index e3fcb58fa1f9fefba6e688b9d1dadd8ecbfb57f5..d9f6fa466225e0d06a42ddc87b3fe7e548c6181a 100644 (file)
 #include "ardour/session_handle.h"
 #include "ardour/types.h"
 
+#ifdef HAVE_JACK_SESSION
+#include <jack/session.h>
+#endif
+
 namespace ARDOUR {
 
 class InternalPort;
@@ -52,7 +56,7 @@ class AudioEngine : public SessionHandlePtr
    public:
        typedef std::set<Port*> 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<void> GraphReordered;
 
+#ifdef HAVE_JACK_SESSION
+       PBD::Signal1<void,jack_session_event_t *> JackSessionEvent;
+#endif
+
+
        /* this signal is emitted if the sample rate changes */
 
        PBD::Signal1<void,nframes_t> 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 *);
 
index bd59e83824170aa320251ad39d355661919aa664..2b51e3f8ecb700cc96f2e8872f84f068b1979fdc 100644 (file)
 #include "ardour/timecode.h"
 #include "ardour/interpolation.h"
 
+#ifdef HAVE_JACK_SESSION
+#include <jack/session.h>
+#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);
index 398a4936cc283481fe4e8dea0f41fe3d5865f428..6ffe0f604815ec81d3ae33778c32772e1b50a463 100644 (file)
@@ -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<AudioEngine*> (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);
 
index 504eadcc924516d014f2482f7c034cd401a4ab80..22a9100b319e602d65e27010bf02d51ea7fcad30 100644 (file)
@@ -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)
 {
index dd0138968c41a4e0819be393929fc7c51fee8faf..54fe07199fe67206a70bda2008b373fbe074e551 100644 (file)
@@ -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 75cf78ce7f4c96885c5ac1209601f25683aca15a..371f2146912de02fd389df8b85145fab3ef3b9b8 100644 (file)
--- 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 <boost/version.hpp>\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)