[Alsaplayer-devel][PATCH] specify jack connections on cmd-line

Patrick Shirkey kotau@firstlinux.net
Sat, 9 Feb 2002 23:57:51 -0800 (PST)


Just revisiting the need I have for being able to switch between ports on the fly. ie to switch the signal from headphones to stereo output 1 or stereo output 2. 

I have asked on the jack list and the consensus there is that it will be better to have it available as a seperate gui for all jack aware apps to use. But I don't have the knowledge or time to do that now so I want to get it working in alsaplayer first. 

Any ideas on how I should accomplish this? 

I can easily code a menu box into the gui which allows the user to choose the output but how do I get this to actually work? Obviously it has to be instant and have no dropouts or noise. Possible a better idea would be to provide a fader and a switch. Then it would become a complete cj mixing app.


--
Patrick Shirkey - Boost Hardware Ltd
For the discerning hardware connoisseur
Http://www.boosthardware.com
Http://www.boosthardware.com/LAU/Linux_Audio_Users_Guide/


--- Mark Gibson <mark@markg.co.uk> wrote:
>Part: 1
><pre>Hi, i've been playing arround with AlsaPlayer and Jack.
>I needed to be able to specify the connections that
>AlsaPlayer makes to Jack instead of the default:
>alsa_pcm:out_1&amp;2
>
>so i've made some small changes to Main.cpp and AlsaNode.cpp:
>
>when you start alsaplayer with &quot;-o jack&quot;, you can now
>specify the connections using:
>
>  -d port1[,port2]
>
>eg:  alsaplayer -o jack -d alsa_pcm:out_3,alsa_pcm:out_4
>
>if the port2 is not given, then it is set to port1 -
>essentially producing a mono mix.
>
>ie:  alsaplayer -o jack -d alsa_pcm:out_2
>
>is the same as:
>
>     alsaplayer -o jack -d alsa_pcm:out_2,alsa_pcm:out_2
>
>
>if -d is not given then:
>
>  alsa_pcm:out_1,alsa_pcm:out_2  is assumed.
>
>
>The patch is a bit of a hack, the port names are passed
>to AlsaNode in the &quot;name&quot; arg as:
>
>&quot;jack &lt;port1&gt; &lt;port2&gt;&quot;
>
>and i'm not sure whether port names have a limited length.
>(my C/C++ skills are a bit rusty, too much Java!)
>
>I hope this may be of use to someone, it is to me :)
>
>The patches for the two files are attached.
>
>- Mark.
></pre>Part: 2
><pre>*** AlsaNode.cpp.~1.9.~	Fri Feb  8 14:05:49 2002
>--- AlsaNode.cpp	Fri Feb  8 18:22:06 2002
>***************
>*** 54,61 ****
>  	use_pcm = name;
>  #ifdef USE_JACK	
>  	char client_name[32];
>  	use_jack = 0;
>! #endif	
>  	realtime_sched = realtime;
>  	sample_freq = OUTPUT_RATE;
>  
>--- 54,62 ----
>  	use_pcm = name;
>  #ifdef USE_JACK	
>  	char client_name[32];
>+ 	char dest_port1[32], dest_port2[32];
>  	use_jack = 0;
>! #endif
>  	realtime_sched = realtime;
>  	sample_freq = OUTPUT_RATE;
>  
>***************
>*** 65,71 ****
>  #ifdef USE_JACK
>  	sprintf(client_name, &quot;alsaplayer-%d&quot;, getpid());
>  
>! 	if (strcmp(name, &quot;jack&quot;) == 0) { // Use JACK
>  		if ((client = jack_client_new(client_name)) == 0) {
>  			alsaplayer_error(&quot;jack server not running?&quot;);
>  			return;
>--- 66,72 ----
>  #ifdef USE_JACK
>  	sprintf(client_name, &quot;alsaplayer-%d&quot;, getpid());
>  
>! 	if (strncmp(name, &quot;jack&quot;, 4) == 0) { // Use JACK
>  		if ((client = jack_client_new(client_name)) == 0) {
>  			alsaplayer_error(&quot;jack server not running?&quot;);
>  			return;
>***************
>*** 88,99 ****
>  		}	
>  		printf(&quot;client activated\n&quot;);
>  	
>  		if (jack_connect (client, jack_port_name(my_output_port1),
>! 				&quot;alsa_pcm:out_1&quot;)) {
>  				alsaplayer_error(&quot;cannot connect output port 1&quot;);
>  		}		
>  		if (jack_connect (client, jack_port_name(my_output_port2),
>! 				&quot;alsa_pcm:out_2&quot;)) {
>  				alsaplayer_error(&quot;cannot connect output port 2&quot;);
>  		}		
>  	
>--- 89,108 ----
>  		}	
>  		printf(&quot;client activated\n&quot;);
>  	
>+ 		strcpy(dest_port1, &quot;alsa_pcm:out_1&quot;);
>+ 		strcpy(dest_port2, &quot;alsa_pcm:out_2&quot;);
>+ 		if (sscanf(name, &quot;jack %31s %31s&quot;, dest_port1, dest_port2) == 1) {
>+ 		  strcpy(dest_port2, dest_port1);
>+ 		}
>+ 
>+ 		printf(&quot;connecting to jack ports: %s &amp; %s\n&quot;, dest_port1, dest_port2);
>+ 
>  		if (jack_connect (client, jack_port_name(my_output_port1),
>! 				dest_port1)) {
>  				alsaplayer_error(&quot;cannot connect output port 1&quot;);
>  		}		
>  		if (jack_connect (client, jack_port_name(my_output_port2),
>! 				dest_port2)) {
>  				alsaplayer_error(&quot;cannot connect output port 2&quot;);
>  		}		
>  	
></pre>Part: 3
><pre>*** Main.cpp.~1.16.~	Sat Dec  1 14:31:27 2001
>--- Main.cpp	Fri Feb  8 17:35:18 2002
>***************
>*** 442,448 ****
>  	// Check if we want jack
>  	if (strcmp(argv[0], &quot;jackplayer&quot;) == 0 ||
>  			strcmp(use_output, &quot;jack&quot;) == 0) {
>! 		node = new AlsaNode(&quot;jack&quot;, use_realtime);
>  	} else { // Else do the usual plugin based thing
>  		node = new AlsaNode(use_pcm, use_realtime);
>  		if (use_user) {
>--- 442,457 ----
>  	// Check if we want jack
>  	if (strcmp(argv[0], &quot;jackplayer&quot;) == 0 ||
>  			strcmp(use_output, &quot;jack&quot;) == 0) {
>! 
>! 	  if (use_pcm != default_pcm_device) {
>! 		char *comma;
>! 		snprintf(use_output, 255, &quot;jack %s&quot;, use_pcm);
>! 		if (comma = strchr(use_output, ',')) {
>! 		  *comma = ' ';
>! 		}
>! 	  }
>! 
>! 		node = new AlsaNode(use_output, use_realtime);
>  	} else { // Else do the usual plugin based thing
>  		node = new AlsaNode(use_pcm, use_realtime);
>  		if (use_user) {
></pre>

_____________________________________________________________
Want a new web-based email account ? ---> http://www.firstlinux.net