[ardour-dev] [patch] add hacky LASH support

Florian Schmidt mista.tapas at gmx.net
Mon Nov 21 04:31:39 PST 2005


Hi,

below (and attached for your convenience) you find a small patch that
adds LASH support to ardour in a hacky sort of way. Like described in
the previous mail on the subject ardour basically stores the (absolute
path) session filename on the LASH server when LASH asks to store its
config. Ardour will also try to save the session state yo its own
session file when asked by LASH to store its config.

When a LASH session is restored the server sends ardour the name of its
ardour-session file and ardour will proceed rightaway to load it (LASH
users need to know what they are doing). I'm not sure t all about the
order of things. Are there any synchronization issues from the
process_lash_events timeout handler?

One thing left is: maybe ardour should send a LASH Save event, when the
user presses save in ardour, so all other LASH apps in the same session
save their stuff then, too.

But i suppose LASH users will probably use the lash_panel for that
anyways. Need to read more docs though to be certain on this point.

Ardour will also shutdown immediately without any further ado when
receiving a Quit event from the LASH server. This is expected behaviour.

So have at it and let me know what stinks about this patch :)

Regards,
Flo

P.S.: yes, lash lib takes over ownership for these configs and events we
send it. and take ownership for those it sends us.

--- ardour.orig/libs/ardour/audioengine.cc	2005-05-11 04:27:48.000000000 +0200
+++ ardour/libs/ardour/audioengine.cc	2005-11-21 04:20:53.000000000 +0100
@@ -535,7 +535,7 @@
 
 	int ret = jack_connect (_jack, s.c_str(), d.c_str());
 
-	if (ret == 0) {
+	if (ret == 0 || ret == EEXIST) {
 		pair<string,string> c (s, d);
 		port_connections.push_back (c);
 	} else {
--- ardour.orig/gtk_ardour/ardour_ui.cc	2005-09-22 06:30:34.000000000 +0200
+++ ardour/gtk_ardour/ardour_ui.cc	2005-11-21 13:14:07.000000000 +0100
@@ -25,12 +25,14 @@
 #include <unistd.h>
 #include <cerrno>
 #include <fstream>
+#include <cstdlib>
 
 #include <iostream>
 
 #include <gtk--.h>
 #include <pbd/error.h>
 #include <pbd/basename.h>
+#include <pbd/dirname.h>
 #include <pbd/pathscanner.h>
 #include <pbd/failed_constructor.h>
 #include <gtkmmext/gtk_ui.h>
@@ -784,6 +786,7 @@
 
 	: Gtkmmext::UI ("ardour", argcp, argvp, rcfile),
 
+
 	  primary_clock (X_("TransportClockDisplay"), true, false, true),
 	  secondary_clock (X_("SecondaryClockDisplay"), true, false, true),
 	  preroll_clock (X_("PreRollClock"), true, true),
@@ -819,6 +822,10 @@
 
 	  session_selector (1, 0),
 
+#ifdef LASH_SUPPORT
+	  lash_client(0),
+#endif
+
 	  shown_flag (false)
 
 {
@@ -826,6 +833,21 @@
 
 	Gtkmmext::init();
 
+#ifdef LASH_SUPPORT
+	/* not sure whether i can really use these argcp and argvp pointers
+	   here */
+	lash_client = lash_init(lash_extract_args(argcp, argvp), "ardour",
+		LASH_Config_Data_Set, LASH_PROTOCOL(2, 0));
+
+	lash_event_t *lash_event;
+	if (lash_client) {
+		cerr << "Successfully connected to LASH server" << endl;
+		lash_event = lash_event_new_with_type(LASH_Client_Name);
+		lash_event_set_string(lash_event, "Ardour");
+		lash_send_event(lash_client, lash_event);
+	}
+#endif
+
 	/* actually, its already loaded, but ... */
 
 	cerr << "Loading UI configuration file " << rcfile << endl;
@@ -955,6 +977,11 @@
 	update_wall_clock ();
 	Main::timeout.connect (slot (*this, &ARDOUR_UI::update_wall_clock), 60000);
 
+#ifdef LASH_SUPPORT
+	process_lash_events();
+	Main::timeout.connect (slot (*this, &ARDOUR_UI::process_lash_events), 1000);
+#endif
+
 	update_disk_space ();
 	update_cpu_load ();
 	update_sample_rate (engine->frame_rate());
@@ -1343,6 +1370,74 @@
 	return TRUE;
 }
 
+#ifdef LASH_SUPPORT
+gint
+ARDOUR_UI::process_lash_events() {
+	lash_event_t *lash_event;
+	lash_config_t *lash_config;
+	if (lash_client) {
+		while ((lash_event = lash_get_event(lash_client))) {
+			char *lash_config_key;
+			char *lash_config_value;
+			switch (lash_event_get_type(lash_event)) {
+			    case LASH_Quit:
+						Main::quit();
+					break;
+
+				case LASH_Save_Data_Set:
+					/* send LASH our filename */
+
+					if (session) {
+						cerr << "LASH asked us to save state" << endl;
+						save_ardour_state();
+						cerr << "Sending session filename to LASH" << endl;
+
+						lash_config = lash_config_new();
+
+						lash_config_key = (char*) malloc(strlen("session_filename") + 1);
+						/* 1024 is arbitrarily chosen */
+						lash_config_value = (char*) malloc(1024);
+
+						strcpy(lash_config_key, "session_filename");
+						strcpy(lash_config_value, 
+							(session->path() + session->name()).c_str());
+
+						lash_config_set_key(lash_config, lash_config_key);
+						lash_config_set_value(lash_config, lash_config_value, 
+							strlen((session->path() + session->name()).c_str())+1);
+
+						lash_send_config(lash_client, lash_config);
+						
+						lash_event_t *ack = lash_event_new_with_type(LASH_Save_Data_Set);
+						lash_send_event(lash_client, ack);
+
+					}
+					break;
+
+				case LASH_Restore_Data_Set:
+					cerr << "LASH wants us to restore a session" << endl;
+					while ((lash_config = lash_get_config(lash_client))) {
+						if (string(lash_config_get_key(lash_config)) == "session_filename") {
+							string value = lash_config_get_value_string(lash_config);
+							load_session(PBD::dirname(value), PBD::basename(value));
+							lash_jack_client_name(lash_client, engine->client_name().c_str());
+						}
+						lash_config_destroy(lash_config);
+						lash_event_t *ack = lash_event_new_with_type(LASH_Restore_Data_Set);
+						lash_send_event(lash_client, ack);
+					}
+					break;
+
+			    default:
+					cerr << "Got unhandled LASH event" << endl;
+			}
+			lash_event_destroy(lash_event);
+		}
+	}
+	return 1;
+}
+#endif
+
 void
 ARDOUR_UI::toggle_recording_plugins ()
 {
--- ardour.orig/gtk_ardour/ardour_ui.h	2005-09-22 06:30:34.000000000 +0200
+++ ardour/gtk_ardour/ardour_ui.h	2005-11-20 22:59:01.000000000 +0100
@@ -37,6 +37,10 @@
 
 #include <gtk-canvas.h>
 
+#ifdef LASH_SUPPORT
+#include <lash/lash.h>
+#endif
+
 #include <pbd/xml++.h>
 #include <gtkmmext/gtk_ui.h>
 #include <gtkmmext/pix.h>
@@ -500,7 +504,6 @@
 	Gtk::MenuItem *image_compositor_item ;
 	/* </CMT Additions> */
 
-
 	Gtk::Label   wall_clock_label;
 	Gtk::EventBox wall_clock_box;
 	gint update_wall_clock ();
@@ -681,8 +684,15 @@
 	uint32_t rec_enabled_diskstreams;
 	void count_recenabled_diskstreams (ARDOUR::DiskStream&);
 
+#ifdef LASH_SUPPORT
+	lash_client_t *lash_client;
+
+	gint process_lash_events();
+#endif
+
 	About* about;
 	bool shown_flag;
+
 	/* cleanup */
 
 	Gtk::MenuItem *cleanup_item;
--- ardour.orig/gtk_ardour/SConscript	2005-11-17 22:57:02.000000000 +0100
+++ ardour/gtk_ardour/SConscript	2005-11-20 20:55:35.000000000 +0100
@@ -40,6 +40,10 @@
 if gtkardour['VST']:
     gtkardour.Merge ([ libraries['fst']])
 
+if gtkardour['LASH']:
+    gtkardour.Merge ([ libraries['lash']])
+
+
 gtkardour_files=Split("""
 about.cc
 add_route_dialog.cc
--- ardour.orig/SConstruct	2005-11-17 23:00:46.000000000 +0100
+++ ardour/SConstruct	2005-11-20 20:51:19.000000000 +0100
@@ -34,6 +34,7 @@
     BoolOption('NOARCH', 'Do not use architecture-specific compilation flags', 0),
     PathOption('PREFIX', 'Set the install "prefix"', '/usr/local'),
     BoolOption('VST', 'Compile with support for VST', 0),
+    BoolOption('LASH', 'Compile with support for LASH session handling', 0),
     BoolOption('VERSIONED', 'Add version information to ardour/gtk executable name inside the build directory', 0),
     BoolOption('USE_SSE_EVERYWHERE', 'Ask the compiler to use x86/SSE instructions and also our hand-written x86/SSE optimizations when possible (off by default)', 0),
     BoolOption('BUILD_SSE_OPTIMIZATIONS', 'Use our hand-written x86/SSE optimizations when possible (off by default)', 0),
@@ -364,6 +365,9 @@
 libraries['jack'] = LibraryInfo()
 libraries['jack'].ParseConfig('pkg-config --cflags --libs jack')
 
+libraries['lash'] = LibraryInfo()
+libraries['lash'].ParseConfig('pkg-config --cflags --libs lash-1.0')
+
 libraries['xml'] = LibraryInfo()
 libraries['xml'].ParseConfig('pkg-config --cflags --libs libxml-2.0')
 
@@ -611,6 +615,10 @@
     env.Append(CCFLAGS="-DVST_SUPPORT")
 
 
+if env['LASH']:
+    env.Append(CCFLAGS="-DLASH_SUPPORT")
+
+
 #
 # everybody needs this
 #


-- 
Palimm Palimm!
http://tapas.affenbande.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ardour_lash.patch
Type: application/octet-stream
Size: 6926 bytes
Desc: not available
URL: <http://lists.ardour.org/pipermail/ardour-dev-ardour.org/attachments/20051121/5c128c93/attachment.obj>


More information about the Ardour-Dev mailing list