@@ -147,13 +147,13 @@ static port_type_t port_type[2] = {
147
147
{
148
148
SND_SEQ_PORT_CAP_SUBS_READ ,
149
149
JackPortIsOutput ,
150
- "playback " ,
150
+ "capture " ,
151
151
do_jack_input
152
152
},
153
153
{
154
154
SND_SEQ_PORT_CAP_SUBS_WRITE ,
155
155
JackPortIsInput ,
156
- "capture " ,
156
+ "playback " ,
157
157
do_jack_output
158
158
}
159
159
};
@@ -493,15 +493,6 @@ port_t* port_create(alsa_seqmidi_t *self, int type, snd_seq_addr_t addr, const s
493
493
snd_seq_client_info_alloca (& client_info );
494
494
snd_seq_get_any_client_info (self -> seq , addr .client , client_info );
495
495
496
- const char * device_name = snd_seq_client_info_get_name (client_info );
497
- snprintf (port -> name , sizeof (port -> name ), "alsa_pcm:%s/midi_%s_%d" ,
498
- device_name , port_type [type ].name , addr .port + 1 );
499
-
500
- // replace all offending characters by -
501
- for (c = port -> name ; * c ; ++ c )
502
- if (!isalnum (* c ) && * c != '/' && * c != '_' && * c != ':' && * c != '(' && * c != ')' )
503
- * c = '-' ;
504
-
505
496
jack_caps = port_type [type ].jack_caps ;
506
497
507
498
/* mark anything that looks like a hardware port as physical&terminal */
@@ -520,21 +511,61 @@ port_t* port_create(alsa_seqmidi_t *self, int type, snd_seq_addr_t addr, const s
520
511
if (!port -> jack_port )
521
512
goto failed ;
522
513
523
- jack_port_set_alias (port -> jack_port , port -> name );
524
- jack_port_set_default_metadata (port -> jack_port , device_name );
514
+ // First alias: Jack1-compatible port name. -ag
515
+ const char * prefix = "alsa_midi:" ;
516
+ const char * device_name = snd_seq_client_info_get_name (client_info );
517
+ const char * port_name = snd_seq_port_info_get_name (info );
518
+ const char * type_name = jack_caps & JackPortIsOutput ? "out" : "in" ;
519
+ // This code is pilfered from Jack1. -ag
520
+ if (strstr (port_name , device_name ) == port_name ) {
521
+ /* entire client name is part of the port name so don't replicate it */
522
+ snprintf (port -> name ,
523
+ sizeof (port -> name ),
524
+ "%s%s (%s)" ,
525
+ prefix ,
526
+ port_name ,
527
+ type_name );
528
+ } else {
529
+ snprintf (port -> name ,
530
+ sizeof (port -> name ),
531
+ "%s%s %s (%s)" ,
532
+ prefix ,
533
+ device_name ,
534
+ port_name ,
535
+ type_name );
536
+ }
525
537
526
- /* generate an alias */
538
+ // replace all offending characters with ' '
539
+ for (c = port -> name ; * c ; ++ c ) {
540
+ if (!isalnum (* c ) && * c != ' ' && * c != '/' && * c != '_' && * c != ':' && * c != '(' && * c != ')' ) {
541
+ * c = ' ' ;
542
+ }
543
+ }
527
544
528
- snprintf (port -> name , sizeof (port -> name ), "%s:midi/%s_%d" ,
529
- snd_seq_client_info_get_name (client_info ), port_type [type ].name , addr .port + 1 );
545
+ jack_port_set_alias (port -> jack_port , port -> name );
546
+ // Pretty-name metadata is the same as first alias without the prefix.
547
+ jack_port_set_default_metadata (port -> jack_port , port -> name + strlen (prefix ));
548
+
549
+ // Second alias: Strip the alsa_midi prefix, so that devices appear
550
+ // under their ALSA names. Use the ALSA port names (without device
551
+ // prefix) for the individual ports. -ag
552
+ if (strstr (port_name , device_name ) == port_name ) {
553
+ // remove the device name prefix from the port name if present
554
+ port_name += strlen (device_name );
555
+ while (* port_name == ' ' || * port_name == '\t' )
556
+ port_name ++ ;
557
+ }
558
+ snprintf (port -> name , sizeof (port -> name ), "%s:%s (%s)" ,
559
+ device_name , port_name , port_type [type ].name );
530
560
531
- // replace all offending characters by -
532
- for (c = port -> name ; * c ; ++ c )
533
- if (!isalnum (* c ) && * c != '/' && * c != '_' && * c != ':' && * c != '(' && * c != ')' )
534
- * c = '-' ;
561
+ // replace all offending characters with ' '
562
+ for (c = port -> name ; * c ; ++ c ) {
563
+ if (!isalnum (* c ) && * c != ' ' && * c != '/' && * c != '_' && * c != ':' && * c != '(' && * c != ')' ) {
564
+ * c = ' ' ;
565
+ }
566
+ }
535
567
536
568
jack_port_set_alias (port -> jack_port , port -> name );
537
- jack_port_set_default_metadata (port -> jack_port , device_name );
538
569
539
570
if (type == PORT_INPUT )
540
571
err = alsa_connect_from (self , port -> remote .client , port -> remote .port );
0 commit comments