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

Florian Schmidt mista.tapas at gmx.net
Wed Nov 23 17:04:26 PST 2005


On Mon, 21 Nov 2005 13:31:39 +0100
Florian Schmidt <mista.tapas at gmx.net> wrote:

> 
> 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.

Hi,

this is an updated version of the hacky LASH support. It's still hacky,
but maybe a bit less than before ;)

I'm still not sure about the audioengine.cc thing. Is there a cleaner
way to make ardour not complain about creating connections that were
already made by LASH?

All potential users should be aware, that they should _not_ close their
session from LASH when ardour still has a dialog open. This will make
ardour crash and potentially produce an XRUN. Besides that crashing is
an OK way to "quit" ;)

Have fun,
Flo


Index: gtk_ardour/ardour_ui.cc
===================================================================
RCS file: /home/las/cvsroot/ardour/ardour/gtk_ardour/ardour_ui.cc,v
retrieving revision 1.260
diff -u -r1.260 ardour_ui.cc
--- gtk_ardour/ardour_ui.cc	22 Sep 2005 04:30:34 -0000	1.260
+++ gtk_ardour/ardour_ui.cc	24 Nov 2005 00:59:17 -0000
@@ -21,16 +21,19 @@
 #include <algorithm>
 #include <cmath>
 #include <fcntl.h>
+#include <sys/types.h>
 #include <signal.h>
 #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>
@@ -909,6 +912,29 @@
 	ArdourMessage message (editor, X_("cannotrecord"), msg);
 }
 
+#ifdef LASH_SUPPORT
+bool
+ARDOUR_UI::got_lash() {
+	if (lash_client)
+		return true;
+	else 
+		return false;
+}
+
+void
+ARDOUR_UI::do_init_lash(int *argcp, char **argvp[]) {
+	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) {
+		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
+
 void
 ARDOUR_UI::set_engine (AudioEngine& e)
 {
@@ -955,6 +981,13 @@
 	update_wall_clock ();
 	Main::timeout.connect (slot (*this, &ARDOUR_UI::update_wall_clock), 60000);
 
+#ifdef LASH_SUPPORT
+	if (lash_client) {
+		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 +1376,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) {
+						save_ardour_state();
+
+						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);
+
+						/* need to send an acknowledge to LASH */
+						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:
+					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);
+
+						/* need to send an acknowledge to LASH */
+						lash_event_t *ack = lash_event_new_with_type(LASH_Restore_Data_Set);
+						lash_send_event(lash_client, ack);
+					}
+					break;
+
+				default:
+					/* ignore everything else */
+					;
+			}
+			lash_event_destroy(lash_event);
+		}
+	}
+	return 1;
+}
+#endif
+
 void
 ARDOUR_UI::toggle_recording_plugins ()
 {
@@ -3383,3 +3484,8 @@
 	_will_create_new_session_automatically = false; /* done it */
 	return FALSE; /* don't call it again */
 }
+
+#ifdef LASH_SUPPORT
+lash_client_t *ARDOUR_UI::lash_client = 0;
+#endif
+
Index: gtk_ardour/ardour_ui.h
===================================================================
RCS file: /home/las/cvsroot/ardour/ardour/gtk_ardour/ardour_ui.h,v
retrieving revision 1.159
diff -u -r1.159 ardour_ui.h
--- gtk_ardour/ardour_ui.h	22 Sep 2005 04:30:34 -0000	1.159
+++ gtk_ardour/ardour_ui.h	24 Nov 2005 00:59:17 -0000
@@ -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>
@@ -94,7 +98,12 @@
 	
 	void show_splash ();
 	void hide_splash ();
-	
+
+#ifdef LASH_SUPPORT	
+	static void do_init_lash(int *argcp, char **argvp[]);
+	static bool got_lash();
+#endif
+
 	int load_session (string path, string snapshot, string* mix_template = 0);
 	bool session_loaded;
 	int build_session (string path, string snapshot, 
@@ -127,7 +136,7 @@
 	void restore_state (string state_name = "");
 
 	static double gain_to_slider_position (ARDOUR::gain_t g);
-        static ARDOUR::gain_t slider_position_to_gain (double pos);
+	static ARDOUR::gain_t slider_position_to_gain (double pos);
 
 	static ARDOUR_UI *instance () { return theArdourUI; }
 
@@ -500,7 +509,6 @@
 	Gtk::MenuItem *image_compositor_item ;
 	/* </CMT Additions> */
 
-
 	Gtk::Label   wall_clock_label;
 	Gtk::EventBox wall_clock_box;
 	gint update_wall_clock ();
@@ -681,8 +689,15 @@
 	uint32_t rec_enabled_diskstreams;
 	void count_recenabled_diskstreams (ARDOUR::DiskStream&);
 
+
+#ifdef LASH_SUPPORT
+	static lash_client_t *lash_client;
+	gint process_lash_events();
+#endif
+
 	About* about;
 	bool shown_flag;
+
 	/* cleanup */
 
 	Gtk::MenuItem *cleanup_item;
Index: gtk_ardour/main.cc
===================================================================
RCS file: /home/las/cvsroot/ardour/ardour/gtk_ardour/main.cc,v
retrieving revision 1.101
diff -u -r1.101 main.cc
--- gtk_ardour/main.cc	22 Sep 2005 03:26:04 -0000	1.101
+++ gtk_ardour/main.cc	24 Nov 2005 00:59:17 -0000
@@ -325,6 +325,10 @@
 	ARDOUR::AudioEngine *engine;
 	char *null_file_list[] = { 0 };
 
+#ifdef LASH_SUPPORT
+	ARDOUR_UI::do_init_lash(&argc, &argv);
+#endif
+
 	gtk_set_locale ();
 
 	(void)   bindtextdomain (PACKAGE, LOCALEDIR);
@@ -428,7 +432,11 @@
 	/* load session, if given */
 	string name, path;
 
+#ifdef LASH_SUPPORT
+	if (session_name.length() && !ARDOUR_UI::got_lash()){
+#else
 	if (session_name.length()){
+#endif
 		bool isnew;
 
 		if (Session::find_session (session_name, path, name, isnew)) {
Index: gtk_ardour/SConscript
===================================================================
RCS file: /home/las/cvsroot/ardour/ardour/gtk_ardour/SConscript,v
retrieving revision 1.111
diff -u -r1.111 SConscript
--- gtk_ardour/SConscript	17 Nov 2005 21:57:02 -0000	1.111
+++ gtk_ardour/SConscript	24 Nov 2005 00:59:17 -0000
@@ -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
Index: libs/ardour/audioengine.cc
===================================================================
RCS file: /home/las/cvsroot/ardour/ardour/libs/ardour/audioengine.cc,v
retrieving revision 1.77
diff -u -r1.77 audioengine.cc
--- libs/ardour/audioengine.cc	11 May 2005 02:27:48 -0000	1.77
+++ libs/ardour/audioengine.cc	24 Nov 2005 00:59:17 -0000
@@ -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 {
Index: SConstruct
===================================================================
RCS file: /home/las/cvsroot/ardour/ardour/SConstruct,v
retrieving revision 1.73
diff -u -r1.73 SConstruct
--- SConstruct	17 Nov 2005 22:00:46 -0000	1.73
+++ SConstruct	24 Nov 2005 00:59:17 -0000
@@ -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: 9181 bytes
Desc: not available
URL: <http://lists.ardour.org/pipermail/ardour-dev-ardour.org/attachments/20051124/0de9e0d8/attachment.obj>


More information about the Ardour-Dev mailing list