[RFC] dynamic port name aliases / midi port alias support

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[RFC] dynamic port name aliases / midi port alias support

Pieter Palmers
Nedko informed me that my previous patch conflicts with the one he
posted a while ago. Since there was no response on that one, and I don't
see any problems with it, I'm reposting it here.

If there are no objections within two weeks, I will commit this patch.
Depending on the results of the discussion on my previous patch, I will
merge it into this one. Or not of course.

Greets,

Pieter

Original message:

> In r1051 jack_engine_munge_backend_port_names() is being called during
> startup. ALSA raw midi backend does port discovery in dynamic way and
> thus midi ports appear after call to
> jack_engine_munge_backend_port_names() and thus are not munged.
>
> This patch contains:
>
>  * munge during port registration not during startup. It is done only
>    for internal clients. MIDI ports are midi_capture_N and
>    midi_playback_N in order to not interfere with audio port names.
>  * ALSA backend name is changed from "alsa_pcm" to "ALSA"
>  * engine->driver is initialized before call to driver attach() method
>    to make munge during port registration work during startup.
>
> This is how ports look like in my system (emu10k1) with synth ports
> disabled/ignored:
>
> # jack_lsp -A
> system:capture_1
>    ALSA:capture_1
> system:capture_2
>    ALSA:capture_2
> system:playback_1
>    ALSA:playback_1
> system:playback_2
>    ALSA:playback_2
> system:midi_capture_1
>    ALSA:in-hw-1-0-0-EMU10K1-MPU-401--UART-
> system:midi_playback_1
>    ALSA:out-hw-1-0-0-EMU10K1-MPU-401--UART-
>
> Here is how they look in patchage:
>
> http://nedko.arnaudov.name/tmp/jackmidi_alias.png
> http://triton.atia.com/nedko/tmp/jackmidi_alias.png
>
> This patch may (and should) work for other midi backends (alsa seq,
> firewire) but I don't use them here.
>  


Index: jack/engine.h
===================================================================
--- jack/engine.h (revision 1051)
+++ jack/engine.h (working copy)
@@ -205,6 +205,5 @@
 void jack_port_registration_notify (jack_engine_t *, jack_port_id_t, int);
 void jack_port_release (jack_engine_t *engine, jack_port_internal_t *);
 void jack_sort_graph (jack_engine_t *engine);
-void    jack_engine_munge_backend_port_names (jack_engine_t* engine);
 
 #endif /* __jack_engine_h__ */
Index: jack/port.h
===================================================================
--- jack/port.h (revision 1051)
+++ jack/port.h (working copy)
@@ -53,6 +53,8 @@
 #define JACK_SHM_MAX (MAX_INT32)
 typedef int32_t jack_port_type_id_t;
 
+#define JACK_BACKEND_ALIAS "system"
+
 /* Port type structure.  
  *
  *  (1) One for each port type is part of the engine's jack_control_t
Index: jackd/engine.c
===================================================================
--- jackd/engine.c (revision 1051)
+++ jackd/engine.c (working copy)
@@ -94,7 +94,7 @@
 static int  jack_port_do_disconnect_all (jack_engine_t *engine,
  jack_port_id_t);
 static int  jack_port_do_unregister (jack_engine_t *engine, jack_request_t *);
-static int  jack_port_do_register (jack_engine_t *engine, jack_request_t *);
+static int  jack_port_do_register (jack_engine_t *engine, jack_request_t *, int);
 static int  jack_do_get_port_connections (jack_engine_t *engine,
   jack_request_t *req, int reply_fd);
 static int  jack_port_disconnect_internal (jack_engine_t *engine,
@@ -950,44 +950,6 @@
 }
 #endif /* !JACK_USE_MACH_THREADS */
 
-void
-jack_engine_munge_backend_port_names (jack_engine_t* engine)
-{
- int out_cnt = 1;
- int in_cnt = 1;
- int i;
- char* backend_client_name = (char*) engine->driver->internal_client->control->name;
- size_t len = strlen (backend_client_name);
-
- for (i = 0; i < engine->port_max; i++) {
- jack_port_shared_t* port = &engine->control->ports[i];
-
- if (strncmp (port->name, backend_client_name, len) == 0) {
-
- /* save the backend's own name */
-
- char name[JACK_CLIENT_NAME_SIZE+JACK_PORT_NAME_SIZE];
- snprintf (name, sizeof (name), "%s", engine->control->ports[i].name);
-
- /* replace input port names, and use backend's original as an alias */
-
- if ((port->flags & (JackPortIsPhysical|JackPortIsInput)) == (JackPortIsPhysical|JackPortIsInput)) {
- snprintf (port->name, sizeof (port->name), "system:playback_%d", out_cnt++);
- strcpy (port->alias1, name);
- continue;
- }
-
- /* replace output port names, and use backend's original as an alias */
-
- if ((port->flags & (JackPortIsPhysical|JackPortIsOutput)) == (JackPortIsPhysical|JackPortIsOutput)) {
- snprintf (port->name, sizeof (port->name), "system:capture_%d", in_cnt++);
- strcpy (port->alias1, name);
- continue;
- }
- }
- }
-}
-
 static jack_driver_info_t *
 jack_load_driver (jack_engine_t *engine, jack_driver_desc_t * driver_desc)
 {
@@ -1223,7 +1185,7 @@
 
  switch (req->type) {
  case RegisterPort:
- req->status = jack_port_do_register (engine, req);
+ req->status = jack_port_do_register (engine, req, reply_fd ? FALSE : TRUE);
  break;
 
  case UnRegisterPort:
@@ -3427,6 +3389,8 @@
  engine->driver = 0;
  }
 
+ engine->driver = driver;
+
  if (driver) {
  if (driver->attach (driver, engine))
  return -1;
@@ -3435,7 +3399,6 @@
  jack_rolling_interval (driver->period_usecs);
  }
 
- engine->driver = driver;
  return 0;
 }
 
@@ -3511,14 +3474,19 @@
 }
 
 int
-jack_port_do_register (jack_engine_t *engine, jack_request_t *req)
-
+jack_port_do_register (jack_engine_t *engine, jack_request_t *req, int internal)
 {
  jack_port_id_t port_id;
  jack_port_shared_t *shared;
  jack_port_internal_t *port;
  jack_client_internal_t *client;
  unsigned long i;
+ char *backend_client_name;
+ size_t len;
+ static int audio_out_cnt = 1;
+ static int audio_in_cnt = 1;
+ static int midi_out_cnt = 1;
+ static int midi_in_cnt = 1;
 
  for (i = 0; i < engine->control->n_port_types; ++i) {
  if (strcmp (req->x.port_info.type,
@@ -3556,7 +3524,47 @@
 
  shared = &engine->control->ports[port_id];
 
+ if (!internal || !engine->driver)
+ goto fallback;
+
+ backend_client_name = (char *) engine->driver->internal_client->control->name;
+ len = strlen (backend_client_name);
+
+ if (strncmp (req->x.port_info.name, backend_client_name, len) != 0)
+ goto fallback;
+
+ /* use backend's original as an alias, use predefined names */
+
+ if (strcmp(req->x.port_info.type, JACK_DEFAULT_AUDIO_TYPE) == 0) {
+ if ((req->x.port_info.flags & (JackPortIsPhysical|JackPortIsInput)) == (JackPortIsPhysical|JackPortIsInput)) {
+ snprintf (shared->name, sizeof (shared->name), JACK_BACKEND_ALIAS ":playback_%d", audio_out_cnt++);
+ strcpy (shared->alias1, req->x.port_info.name);
+ goto next;
+ }
+ else if ((req->x.port_info.flags & (JackPortIsPhysical|JackPortIsOutput)) == (JackPortIsPhysical|JackPortIsOutput)) {
+ snprintf (shared->name, sizeof (shared->name), JACK_BACKEND_ALIAS ":capture_%d", audio_in_cnt++);
+ strcpy (shared->alias1, req->x.port_info.name);
+ goto next;
+ }
+ }
+ else if (strcmp(req->x.port_info.type, JACK_DEFAULT_MIDI_TYPE) == 0) {
+ if ((req->x.port_info.flags & (JackPortIsPhysical|JackPortIsInput)) == (JackPortIsPhysical|JackPortIsInput)) {
+ snprintf (shared->name, sizeof (shared->name), JACK_BACKEND_ALIAS ":midi_playback_%d", midi_out_cnt++);
+ strcpy (shared->alias1, req->x.port_info.name);
+ goto next;
+ }
+ else if ((req->x.port_info.flags & (JackPortIsPhysical|JackPortIsOutput)) == (JackPortIsPhysical|JackPortIsOutput)) {
+ snprintf (shared->name, sizeof (shared->name), JACK_BACKEND_ALIAS ":midi_capture_%d", midi_in_cnt++);
+ strcpy (shared->alias1, req->x.port_info.name);
+ goto next;
+ }
+ }
+
+fallback:
  strcpy (shared->name, req->x.port_info.name);
+
+next:
+
  shared->ptype_id = engine->control->port_types[i].ptype_id;
  shared->client_id = req->x.port_info.client_id;
  shared->flags = req->x.port_info.flags;
Index: jackd/jackd.c
===================================================================
--- jackd/jackd.c (revision 1051)
+++ jackd/jackd.c (working copy)
@@ -160,8 +160,6 @@
  goto error;
  }
 
- jack_engine_munge_backend_port_names (engine);
-
  if (engine->driver->start (engine->driver) != 0) {
  jack_error ("cannot start driver");
  goto error;
Index: drivers/alsa/alsa_driver.c
===================================================================
--- drivers/alsa/alsa_driver.c (revision 1051)
+++ drivers/alsa/alsa_driver.c (working copy)
@@ -2347,7 +2347,7 @@
 
 /* DRIVER "PLUGIN" INTERFACE */
 
-const char driver_client_name[] = "alsa_pcm";
+const char driver_client_name[] = "ALSA";
 
 const jack_driver_desc_t *
 driver_get_descriptor ()


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Jackit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jackit-devel