Skip to content

Commit ff166a9

Browse files
committed
ALSA: seq: Add port direction to snd_seq_port_info
Add a new field "direction" to snd_seq_port_info for allowing a client to tell the expected direction of the port access. A port might still allow subscriptions for read/write (e.g. for MIDI-CI) even if the primary usage of the port is a single direction (either input or output only). This new "direction" field can help to indicate such cases. When the direction is unspecified at creating a port and the port has either read or write capability, the corresponding direction bits are set automatically as default. Reviewed-by: Jaroslav Kysela <perex@perex.cz> Link: https://lore.kernel.org/r/20230523075358.9672-29-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 177ccf8 commit ff166a9

7 files changed

Lines changed: 43 additions & 3 deletions

File tree

include/uapi/sound/asequencer.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,12 @@ struct snd_seq_remove_events {
455455
#define SNDRV_SEQ_PORT_FLG_TIMESTAMP (1<<1)
456456
#define SNDRV_SEQ_PORT_FLG_TIME_REAL (1<<2)
457457

458+
/* port direction */
459+
#define SNDRV_SEQ_PORT_DIR_UNKNOWN 0
460+
#define SNDRV_SEQ_PORT_DIR_INPUT 1
461+
#define SNDRV_SEQ_PORT_DIR_OUTPUT 2
462+
#define SNDRV_SEQ_PORT_DIR_BIDIRECTION 3
463+
458464
struct snd_seq_port_info {
459465
struct snd_seq_addr addr; /* client/port numbers */
460466
char name[64]; /* port name */
@@ -471,7 +477,8 @@ struct snd_seq_port_info {
471477
void *kernel; /* reserved for kernel use (must be NULL) */
472478
unsigned int flags; /* misc. conditioning */
473479
unsigned char time_queue; /* queue # for timestamping */
474-
char reserved[59]; /* for future use */
480+
unsigned char direction; /* port usage direction (r/w/bidir) */
481+
char reserved[58]; /* for future use */
475482
};
476483

477484

sound/core/seq/seq_clientmgr.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2440,6 +2440,17 @@ static void snd_seq_info_dump_subscribers(struct snd_info_buffer *buffer,
24402440

24412441
#define FLAG_PERM_DUPLEX(perm) ((perm) & SNDRV_SEQ_PORT_CAP_DUPLEX ? 'X' : '-')
24422442

2443+
static const char *port_direction_name(unsigned char dir)
2444+
{
2445+
static const char *names[4] = {
2446+
"-", "In", "Out", "In/Out"
2447+
};
2448+
2449+
if (dir > SNDRV_SEQ_PORT_DIR_BIDIRECTION)
2450+
return "Invalid";
2451+
return names[dir];
2452+
}
2453+
24432454
static void snd_seq_info_dump_ports(struct snd_info_buffer *buffer,
24442455
struct snd_seq_client *client)
24452456
{
@@ -2449,12 +2460,13 @@ static void snd_seq_info_dump_ports(struct snd_info_buffer *buffer,
24492460
list_for_each_entry(p, &client->ports_list_head, list) {
24502461
if (p->capability & SNDRV_SEQ_PORT_CAP_INACTIVE)
24512462
continue;
2452-
snd_iprintf(buffer, " Port %3d : \"%s\" (%c%c%c%c)\n",
2463+
snd_iprintf(buffer, " Port %3d : \"%s\" (%c%c%c%c) [%s]\n",
24532464
p->addr.port, p->name,
24542465
FLAG_PERM_RD(p->capability),
24552466
FLAG_PERM_WR(p->capability),
24562467
FLAG_PERM_EX(p->capability),
2457-
FLAG_PERM_DUPLEX(p->capability));
2468+
FLAG_PERM_DUPLEX(p->capability),
2469+
port_direction_name(p->direction));
24582470
snd_seq_info_dump_subscribers(buffer, &p->c_src, 1, " Connecting To: ");
24592471
snd_seq_info_dump_subscribers(buffer, &p->c_dest, 0, " Connected From: ");
24602472
}

sound/core/seq/seq_dummy.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ create_port(int idx, int type)
127127
pinfo.capability |= SNDRV_SEQ_PORT_CAP_WRITE | SNDRV_SEQ_PORT_CAP_SUBS_WRITE;
128128
if (duplex)
129129
pinfo.capability |= SNDRV_SEQ_PORT_CAP_DUPLEX;
130+
pinfo.direction = SNDRV_SEQ_PORT_DIR_BIDIRECTION;
130131
pinfo.type = SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC
131132
| SNDRV_SEQ_PORT_TYPE_SOFTWARE
132133
| SNDRV_SEQ_PORT_TYPE_PORT;

sound/core/seq/seq_midi.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,10 @@ snd_seq_midisynth_probe(struct device *_dev)
367367
if ((port->capability & (SNDRV_SEQ_PORT_CAP_WRITE|SNDRV_SEQ_PORT_CAP_READ)) == (SNDRV_SEQ_PORT_CAP_WRITE|SNDRV_SEQ_PORT_CAP_READ) &&
368368
info->flags & SNDRV_RAWMIDI_INFO_DUPLEX)
369369
port->capability |= SNDRV_SEQ_PORT_CAP_DUPLEX;
370+
if (port->capability & SNDRV_SEQ_PORT_CAP_READ)
371+
port->direction |= SNDRV_SEQ_PORT_DIR_INPUT;
372+
if (port->capability & SNDRV_SEQ_PORT_CAP_WRITE)
373+
port->direction |= SNDRV_SEQ_PORT_DIR_OUTPUT;
370374
port->type = SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC
371375
| SNDRV_SEQ_PORT_TYPE_HARDWARE
372376
| SNDRV_SEQ_PORT_TYPE_PORT;

sound/core/seq/seq_ports.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,16 @@ int snd_seq_set_port_info(struct snd_seq_client_port * port,
356356
port->time_real = (info->flags & SNDRV_SEQ_PORT_FLG_TIME_REAL) ? 1 : 0;
357357
port->time_queue = info->time_queue;
358358

359+
/* direction */
360+
port->direction = info->direction;
361+
/* fill default port direction */
362+
if (!port->direction) {
363+
if (info->capability & SNDRV_SEQ_PORT_CAP_READ)
364+
port->direction |= SNDRV_SEQ_PORT_DIR_INPUT;
365+
if (info->capability & SNDRV_SEQ_PORT_CAP_WRITE)
366+
port->direction |= SNDRV_SEQ_PORT_DIR_OUTPUT;
367+
}
368+
359369
return 0;
360370
}
361371

@@ -393,6 +403,9 @@ int snd_seq_get_port_info(struct snd_seq_client_port * port,
393403
info->time_queue = port->time_queue;
394404
}
395405

406+
/* direction */
407+
info->direction = port->direction;
408+
396409
return 0;
397410
}
398411

sound/core/seq/seq_ports.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ struct snd_seq_client_port {
7272
int midi_voices;
7373
int synth_voices;
7474

75+
/* direction */
76+
unsigned char direction;
7577
};
7678

7779
struct snd_seq_client;

sound/core/seq/seq_virmidi.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ static int snd_virmidi_dev_attach_seq(struct snd_virmidi_dev *rdev)
385385
pinfo->capability |= SNDRV_SEQ_PORT_CAP_WRITE | SNDRV_SEQ_PORT_CAP_SYNC_WRITE | SNDRV_SEQ_PORT_CAP_SUBS_WRITE;
386386
pinfo->capability |= SNDRV_SEQ_PORT_CAP_READ | SNDRV_SEQ_PORT_CAP_SYNC_READ | SNDRV_SEQ_PORT_CAP_SUBS_READ;
387387
pinfo->capability |= SNDRV_SEQ_PORT_CAP_DUPLEX;
388+
pinfo->direction = SNDRV_SEQ_PORT_DIR_BIDIRECTION;
388389
pinfo->type = SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC
389390
| SNDRV_SEQ_PORT_TYPE_SOFTWARE
390391
| SNDRV_SEQ_PORT_TYPE_PORT;

0 commit comments

Comments
 (0)