From e94e373c429ba770bdc8c2bd2b02dc56939e52d0 Mon Sep 17 00:00:00 2001
From: David Robillard <d@drobilla.net>
Date: Tue, 10 Jun 2008 19:41:31 +0000
Subject: Fix handling of clients with duplex alsa ports and jack ports (force
 split). Fixes ticket #140.

git-svn-id: http://svn.drobilla.net/lad/patchage@1267 a436a847-0d15-0410-975c-d299462d15a1
---
 src/AlsaDriver.cpp | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/src/AlsaDriver.cpp b/src/AlsaDriver.cpp
index b0981f0..8794386 100644
--- a/src/AlsaDriver.cpp
+++ b/src/AlsaDriver.cpp
@@ -142,6 +142,7 @@ AlsaDriver::refresh_ports()
 	bool is_input       = false;
 	bool is_duplex      = false;
 	bool is_application = true;
+	bool need_refresh   = false;
 
 	set< boost::shared_ptr<PatchageModule> > to_resize;
 
@@ -183,13 +184,24 @@ AlsaDriver::refresh_ports()
 			port_name = snd_seq_port_info_get_name(pinfo);
 			boost::shared_ptr<PatchageModule> m;
 
-			bool split = _app->state_manager()->get_module_split(client_name, !is_application)
-				|| is_duplex;
+			bool split = false;
+
+			// Because there would be name conflicts, we must force a split if (stupid)
+			// alsa duplex ports are present on the client
+			if (is_duplex) {
+				split = true;
+				if (!_app->state_manager()->get_module_split(client_name, !is_application)) {
+					need_refresh = true;
+					_app->state_manager()->set_module_split(client_name, true);
+				}
+			} else {
+				split = _app->state_manager()->get_module_split(client_name, !is_application);
+			}
 			
-			//cout << "SHOW: " << client_name << " : " << port_name
-				//<< " is_application = " << is_application
-				//<< " is_duplex = " << is_duplex
-				//<< ", split = " << split << endl;
+			/*cout << "SHOW: " << client_name << " : " << port_name
+				<< " is_application = " << is_application
+				<< " is_duplex = " << is_duplex
+				<< ", split = " << split << endl;*/
 			
 			// Application input/output ports go on the same module
 			if (!split) {
@@ -274,9 +286,13 @@ AlsaDriver::refresh_ports()
 		}
 	}
 
-	for (set< boost::shared_ptr<PatchageModule> >::iterator i = to_resize.begin();
-			i != to_resize.end(); ++i) {
-		(*i)->resize();
+	if (need_refresh) {
+		_app->refresh();
+	} else {
+		for (set< boost::shared_ptr<PatchageModule> >::iterator i = to_resize.begin();
+				i != to_resize.end(); ++i) {
+			(*i)->resize();
+		}
 	}
 }
 
-- 
cgit v1.2.1