Commit a7b928ac authored by Clemens Ladisch's avatar Clemens Ladisch Committed by Jaroslav Kysela

[ALSA] rawmidi: add get_port_info callback for sequencer information flags

Add a get_port_info callback to the snd_rawmidi_global_ops structure to
allow the USB MIDI driver to supply information flags for the sequencer
ports created by seq_midi.
Signed-off-by: default avatarClemens Ladisch <clemens@ladisch.de>
parent 450047a7
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
struct snd_rawmidi; struct snd_rawmidi;
struct snd_rawmidi_substream; struct snd_rawmidi_substream;
struct snd_seq_port_info;
struct snd_rawmidi_ops { struct snd_rawmidi_ops {
int (*open) (struct snd_rawmidi_substream * substream); int (*open) (struct snd_rawmidi_substream * substream);
...@@ -57,6 +58,8 @@ struct snd_rawmidi_ops { ...@@ -57,6 +58,8 @@ struct snd_rawmidi_ops {
struct snd_rawmidi_global_ops { struct snd_rawmidi_global_ops {
int (*dev_register) (struct snd_rawmidi * rmidi); int (*dev_register) (struct snd_rawmidi * rmidi);
int (*dev_unregister) (struct snd_rawmidi * rmidi); int (*dev_unregister) (struct snd_rawmidi * rmidi);
void (*get_port_info)(struct snd_rawmidi *rmidi, int number,
struct snd_seq_port_info *info);
}; };
struct snd_rawmidi_runtime { struct snd_rawmidi_runtime {
......
...@@ -278,6 +278,7 @@ snd_seq_midisynth_register_port(struct snd_seq_device *dev) ...@@ -278,6 +278,7 @@ snd_seq_midisynth_register_port(struct snd_seq_device *dev)
struct seq_midisynth *msynth, *ms; struct seq_midisynth *msynth, *ms;
struct snd_seq_port_info *port; struct snd_seq_port_info *port;
struct snd_rawmidi_info *info; struct snd_rawmidi_info *info;
struct snd_rawmidi *rmidi = dev->private_data;
int newclient = 0; int newclient = 0;
unsigned int p, ports; unsigned int p, ports;
struct snd_seq_port_callback pcallbacks; struct snd_seq_port_callback pcallbacks;
...@@ -389,6 +390,8 @@ snd_seq_midisynth_register_port(struct snd_seq_device *dev) ...@@ -389,6 +390,8 @@ snd_seq_midisynth_register_port(struct snd_seq_device *dev)
pcallbacks.unuse = midisynth_unuse; pcallbacks.unuse = midisynth_unuse;
pcallbacks.event_input = event_process_midi; pcallbacks.event_input = event_process_midi;
port->kernel = &pcallbacks; port->kernel = &pcallbacks;
if (rmidi->ops && rmidi->ops->get_port_info)
rmidi->ops->get_port_info(rmidi, p, port);
if (snd_seq_kernel_client_ctl(client->seq_client, SNDRV_SEQ_IOCTL_CREATE_PORT, port)<0) if (snd_seq_kernel_client_ctl(client->seq_client, SNDRV_SEQ_IOCTL_CREATE_PORT, port)<0)
goto __nomem; goto __nomem;
ms->seq_client = client->seq_client; ms->seq_client = client->seq_client;
......
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
#include <linux/usb.h> #include <linux/usb.h>
#include <sound/core.h> #include <sound/core.h>
#include <sound/rawmidi.h> #include <sound/rawmidi.h>
#include <sound/asequencer.h>
#include "usbaudio.h" #include "usbaudio.h"
...@@ -1010,97 +1011,157 @@ static struct snd_rawmidi_substream *snd_usbmidi_find_substream(struct snd_usb_m ...@@ -1010,97 +1011,157 @@ static struct snd_rawmidi_substream *snd_usbmidi_find_substream(struct snd_usb_m
* "(product) MIDI (n)" schema because they aren't external MIDI ports, * "(product) MIDI (n)" schema because they aren't external MIDI ports,
* such as internal control or synthesizer ports. * such as internal control or synthesizer ports.
*/ */
static struct { static struct port_info {
u32 id; u32 id;
int port; short int port;
const char *name_format; short int voices;
} snd_usbmidi_port_names[] = { const char *name;
unsigned int seq_flags;
} snd_usbmidi_port_info[] = {
#define PORT_INFO(vendor, product, num, name_, voices_, flags) \
{ .id = USB_ID(vendor, product), \
.port = num, .voices = voices_, \
.name = name_, .seq_flags = flags }
#define EXTERNAL_PORT(vendor, product, num, name) \
PORT_INFO(vendor, product, num, name, 0, \
SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC | \
SNDRV_SEQ_PORT_TYPE_HARDWARE | \
SNDRV_SEQ_PORT_TYPE_PORT)
#define CONTROL_PORT(vendor, product, num, name) \
PORT_INFO(vendor, product, num, name, 0, \
SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC | \
SNDRV_SEQ_PORT_TYPE_HARDWARE)
#define ROLAND_SYNTH_PORT(vendor, product, num, name, voices) \
PORT_INFO(vendor, product, num, name, voices, \
SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC | \
SNDRV_SEQ_PORT_TYPE_MIDI_GM | \
SNDRV_SEQ_PORT_TYPE_MIDI_GM2 | \
SNDRV_SEQ_PORT_TYPE_MIDI_GS | \
SNDRV_SEQ_PORT_TYPE_MIDI_XG | \
SNDRV_SEQ_PORT_TYPE_HARDWARE | \
SNDRV_SEQ_PORT_TYPE_SYNTHESIZER)
#define SOUNDCANVAS_PORT(vendor, product, num, name, voices) \
PORT_INFO(vendor, product, num, name, voices, \
SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC | \
SNDRV_SEQ_PORT_TYPE_MIDI_GM | \
SNDRV_SEQ_PORT_TYPE_MIDI_GM2 | \
SNDRV_SEQ_PORT_TYPE_MIDI_GS | \
SNDRV_SEQ_PORT_TYPE_MIDI_XG | \
SNDRV_SEQ_PORT_TYPE_MIDI_MT32 | \
SNDRV_SEQ_PORT_TYPE_HARDWARE | \
SNDRV_SEQ_PORT_TYPE_SYNTHESIZER)
/* Roland UA-100 */ /* Roland UA-100 */
{ USB_ID(0x0582, 0x0000), 2, "%s Control" }, CONTROL_PORT(0x0582, 0x0000, 2, "%s Control"),
/* Roland SC-8850 */ /* Roland SC-8850 */
{ USB_ID(0x0582, 0x0003), 0, "%s Part A" }, SOUNDCANVAS_PORT(0x0582, 0x0003, 0, "%s Part A", 128),
{ USB_ID(0x0582, 0x0003), 1, "%s Part B" }, SOUNDCANVAS_PORT(0x0582, 0x0003, 1, "%s Part B", 128),
{ USB_ID(0x0582, 0x0003), 2, "%s Part C" }, SOUNDCANVAS_PORT(0x0582, 0x0003, 2, "%s Part C", 128),
{ USB_ID(0x0582, 0x0003), 3, "%s Part D" }, SOUNDCANVAS_PORT(0x0582, 0x0003, 3, "%s Part D", 128),
{ USB_ID(0x0582, 0x0003), 4, "%s MIDI 1" }, EXTERNAL_PORT(0x0582, 0x0003, 4, "%s MIDI 1"),
{ USB_ID(0x0582, 0x0003), 5, "%s MIDI 2" }, EXTERNAL_PORT(0x0582, 0x0003, 5, "%s MIDI 2"),
/* Roland U-8 */ /* Roland U-8 */
{ USB_ID(0x0582, 0x0004), 0, "%s MIDI" }, EXTERNAL_PORT(0x0582, 0x0004, 0, "%s MIDI"),
{ USB_ID(0x0582, 0x0004), 1, "%s Control" }, CONTROL_PORT(0x0582, 0x0004, 1, "%s Control"),
/* Roland SC-8820 */ /* Roland SC-8820 */
{ USB_ID(0x0582, 0x0007), 0, "%s Part A" }, SOUNDCANVAS_PORT(0x0582, 0x0007, 0, "%s Part A", 64),
{ USB_ID(0x0582, 0x0007), 1, "%s Part B" }, SOUNDCANVAS_PORT(0x0582, 0x0007, 1, "%s Part B", 64),
{ USB_ID(0x0582, 0x0007), 2, "%s MIDI" }, EXTERNAL_PORT(0x0582, 0x0007, 2, "%s MIDI"),
/* Roland SK-500 */ /* Roland SK-500 */
{ USB_ID(0x0582, 0x000b), 0, "%s Part A" }, SOUNDCANVAS_PORT(0x0582, 0x000b, 0, "%s Part A", 64),
{ USB_ID(0x0582, 0x000b), 1, "%s Part B" }, SOUNDCANVAS_PORT(0x0582, 0x000b, 1, "%s Part B", 64),
{ USB_ID(0x0582, 0x000b), 2, "%s MIDI" }, EXTERNAL_PORT(0x0582, 0x000b, 2, "%s MIDI"),
/* Roland SC-D70 */ /* Roland SC-D70 */
{ USB_ID(0x0582, 0x000c), 0, "%s Part A" }, SOUNDCANVAS_PORT(0x0582, 0x000c, 0, "%s Part A", 64),
{ USB_ID(0x0582, 0x000c), 1, "%s Part B" }, SOUNDCANVAS_PORT(0x0582, 0x000c, 1, "%s Part B", 64),
{ USB_ID(0x0582, 0x000c), 2, "%s MIDI" }, EXTERNAL_PORT(0x0582, 0x000c, 2, "%s MIDI"),
/* Edirol UM-880 */ /* Edirol UM-880 */
{ USB_ID(0x0582, 0x0014), 8, "%s Control" }, CONTROL_PORT(0x0582, 0x0014, 8, "%s Control"),
/* Edirol SD-90 */ /* Edirol SD-90 */
{ USB_ID(0x0582, 0x0016), 0, "%s Part A" }, ROLAND_SYNTH_PORT(0x0582, 0x0016, 0, "%s Part A", 128),
{ USB_ID(0x0582, 0x0016), 1, "%s Part B" }, ROLAND_SYNTH_PORT(0x0582, 0x0016, 1, "%s Part B", 128),
{ USB_ID(0x0582, 0x0016), 2, "%s MIDI 1" }, EXTERNAL_PORT(0x0582, 0x0016, 2, "%s MIDI 1"),
{ USB_ID(0x0582, 0x0016), 3, "%s MIDI 2" }, EXTERNAL_PORT(0x0582, 0x0016, 3, "%s MIDI 2"),
/* Edirol UM-550 */ /* Edirol UM-550 */
{ USB_ID(0x0582, 0x0023), 5, "%s Control" }, CONTROL_PORT(0x0582, 0x0023, 5, "%s Control"),
/* Edirol SD-20 */ /* Edirol SD-20 */
{ USB_ID(0x0582, 0x0027), 0, "%s Part A" }, ROLAND_SYNTH_PORT(0x0582, 0x0027, 0, "%s Part A", 64),
{ USB_ID(0x0582, 0x0027), 1, "%s Part B" }, ROLAND_SYNTH_PORT(0x0582, 0x0027, 1, "%s Part B", 64),
{ USB_ID(0x0582, 0x0027), 2, "%s MIDI" }, EXTERNAL_PORT(0x0582, 0x0027, 2, "%s MIDI"),
/* Edirol SD-80 */ /* Edirol SD-80 */
{ USB_ID(0x0582, 0x0029), 0, "%s Part A" }, ROLAND_SYNTH_PORT(0x0582, 0x0029, 0, "%s Part A", 128),
{ USB_ID(0x0582, 0x0029), 1, "%s Part B" }, ROLAND_SYNTH_PORT(0x0582, 0x0029, 1, "%s Part B", 128),
{ USB_ID(0x0582, 0x0029), 2, "%s MIDI 1" }, EXTERNAL_PORT(0x0582, 0x0029, 2, "%s MIDI 1"),
{ USB_ID(0x0582, 0x0029), 3, "%s MIDI 2" }, EXTERNAL_PORT(0x0582, 0x0029, 3, "%s MIDI 2"),
/* Edirol UA-700 */ /* Edirol UA-700 */
{ USB_ID(0x0582, 0x002b), 0, "%s MIDI" }, EXTERNAL_PORT(0x0582, 0x002b, 0, "%s MIDI"),
{ USB_ID(0x0582, 0x002b), 1, "%s Control" }, CONTROL_PORT(0x0582, 0x002b, 1, "%s Control"),
/* Roland VariOS */ /* Roland VariOS */
{ USB_ID(0x0582, 0x002f), 0, "%s MIDI" }, EXTERNAL_PORT(0x0582, 0x002f, 0, "%s MIDI"),
{ USB_ID(0x0582, 0x002f), 1, "%s External MIDI" }, EXTERNAL_PORT(0x0582, 0x002f, 1, "%s External MIDI"),
{ USB_ID(0x0582, 0x002f), 2, "%s Sync" }, EXTERNAL_PORT(0x0582, 0x002f, 2, "%s Sync"),
/* Edirol PCR */ /* Edirol PCR */
{ USB_ID(0x0582, 0x0033), 0, "%s MIDI" }, EXTERNAL_PORT(0x0582, 0x0033, 0, "%s MIDI"),
{ USB_ID(0x0582, 0x0033), 1, "%s 1" }, EXTERNAL_PORT(0x0582, 0x0033, 1, "%s 1"),
{ USB_ID(0x0582, 0x0033), 2, "%s 2" }, EXTERNAL_PORT(0x0582, 0x0033, 2, "%s 2"),
/* BOSS GS-10 */ /* BOSS GS-10 */
{ USB_ID(0x0582, 0x003b), 0, "%s MIDI" }, EXTERNAL_PORT(0x0582, 0x003b, 0, "%s MIDI"),
{ USB_ID(0x0582, 0x003b), 1, "%s Control" }, CONTROL_PORT(0x0582, 0x003b, 1, "%s Control"),
/* Edirol UA-1000 */ /* Edirol UA-1000 */
{ USB_ID(0x0582, 0x0044), 0, "%s MIDI" }, EXTERNAL_PORT(0x0582, 0x0044, 0, "%s MIDI"),
{ USB_ID(0x0582, 0x0044), 1, "%s Control" }, CONTROL_PORT(0x0582, 0x0044, 1, "%s Control"),
/* Edirol UR-80 */ /* Edirol UR-80 */
{ USB_ID(0x0582, 0x0048), 0, "%s MIDI" }, EXTERNAL_PORT(0x0582, 0x0048, 0, "%s MIDI"),
{ USB_ID(0x0582, 0x0048), 1, "%s 1" }, EXTERNAL_PORT(0x0582, 0x0048, 1, "%s 1"),
{ USB_ID(0x0582, 0x0048), 2, "%s 2" }, EXTERNAL_PORT(0x0582, 0x0048, 2, "%s 2"),
/* Edirol PCR-A */ /* Edirol PCR-A */
{ USB_ID(0x0582, 0x004d), 0, "%s MIDI" }, EXTERNAL_PORT(0x0582, 0x004d, 0, "%s MIDI"),
{ USB_ID(0x0582, 0x004d), 1, "%s 1" }, EXTERNAL_PORT(0x0582, 0x004d, 1, "%s 1"),
{ USB_ID(0x0582, 0x004d), 2, "%s 2" }, EXTERNAL_PORT(0x0582, 0x004d, 2, "%s 2"),
/* Edirol UM-3EX */ /* Edirol UM-3EX */
{ USB_ID(0x0582, 0x009a), 3, "%s Control" }, CONTROL_PORT(0x0582, 0x009a, 3, "%s Control"),
/* M-Audio MidiSport 8x8 */ /* M-Audio MidiSport 8x8 */
{ USB_ID(0x0763, 0x1031), 8, "%s Control" }, CONTROL_PORT(0x0763, 0x1031, 8, "%s Control"),
{ USB_ID(0x0763, 0x1033), 8, "%s Control" }, CONTROL_PORT(0x0763, 0x1033, 8, "%s Control"),
/* MOTU Fastlane */ /* MOTU Fastlane */
{ USB_ID(0x07fd, 0x0001), 0, "%s MIDI A" }, EXTERNAL_PORT(0x07fd, 0x0001, 0, "%s MIDI A"),
{ USB_ID(0x07fd, 0x0001), 1, "%s MIDI B" }, EXTERNAL_PORT(0x07fd, 0x0001, 1, "%s MIDI B"),
/* Emagic Unitor8/AMT8/MT4 */ /* Emagic Unitor8/AMT8/MT4 */
{ USB_ID(0x086a, 0x0001), 8, "%s Broadcast" }, EXTERNAL_PORT(0x086a, 0x0001, 8, "%s Broadcast"),
{ USB_ID(0x086a, 0x0002), 8, "%s Broadcast" }, EXTERNAL_PORT(0x086a, 0x0002, 8, "%s Broadcast"),
{ USB_ID(0x086a, 0x0003), 4, "%s Broadcast" }, EXTERNAL_PORT(0x086a, 0x0003, 4, "%s Broadcast"),
}; };
static struct port_info *find_port_info(struct snd_usb_midi* umidi, int number)
{
int i;
for (i = 0; i < ARRAY_SIZE(snd_usbmidi_port_info); ++i) {
if (snd_usbmidi_port_info[i].id == umidi->chip->usb_id &&
snd_usbmidi_port_info[i].port == number)
return &snd_usbmidi_port_info[i];
}
return NULL;
}
static void snd_usbmidi_get_port_info(struct snd_rawmidi *rmidi, int number,
struct snd_seq_port_info *seq_port_info)
{
struct snd_usb_midi *umidi = rmidi->private_data;
struct port_info *port_info;
/* TODO: read port flags from descriptors */
port_info = find_port_info(umidi, number);
if (port_info) {
seq_port_info->type = port_info->seq_flags;
seq_port_info->midi_voices = port_info->voices;
}
}
static void snd_usbmidi_init_substream(struct snd_usb_midi* umidi, static void snd_usbmidi_init_substream(struct snd_usb_midi* umidi,
int stream, int number, int stream, int number,
struct snd_rawmidi_substream ** rsubstream) struct snd_rawmidi_substream ** rsubstream)
{ {
int i; struct port_info *port_info;
const char *name_format; const char *name_format;
struct snd_rawmidi_substream *substream = snd_usbmidi_find_substream(umidi, stream, number); struct snd_rawmidi_substream *substream = snd_usbmidi_find_substream(umidi, stream, number);
...@@ -1110,14 +1171,8 @@ static void snd_usbmidi_init_substream(struct snd_usb_midi* umidi, ...@@ -1110,14 +1171,8 @@ static void snd_usbmidi_init_substream(struct snd_usb_midi* umidi,
} }
/* TODO: read port name from jack descriptor */ /* TODO: read port name from jack descriptor */
name_format = "%s MIDI %d"; port_info = find_port_info(umidi, number);
for (i = 0; i < ARRAY_SIZE(snd_usbmidi_port_names); ++i) { name_format = port_info ? port_info->name : "%s MIDI %d";
if (snd_usbmidi_port_names[i].id == umidi->chip->usb_id &&
snd_usbmidi_port_names[i].port == number) {
name_format = snd_usbmidi_port_names[i].name_format;
break;
}
}
snprintf(substream->name, sizeof(substream->name), snprintf(substream->name, sizeof(substream->name),
name_format, umidi->chip->card->shortname, number + 1); name_format, umidi->chip->card->shortname, number + 1);
...@@ -1457,6 +1512,10 @@ static int snd_usbmidi_create_endpoints_midiman(struct snd_usb_midi* umidi, ...@@ -1457,6 +1512,10 @@ static int snd_usbmidi_create_endpoints_midiman(struct snd_usb_midi* umidi,
return 0; return 0;
} }
static struct snd_rawmidi_global_ops snd_usbmidi_ops = {
.get_port_info = snd_usbmidi_get_port_info,
};
static int snd_usbmidi_create_rawmidi(struct snd_usb_midi* umidi, static int snd_usbmidi_create_rawmidi(struct snd_usb_midi* umidi,
int out_ports, int in_ports) int out_ports, int in_ports)
{ {
...@@ -1472,6 +1531,7 @@ static int snd_usbmidi_create_rawmidi(struct snd_usb_midi* umidi, ...@@ -1472,6 +1531,7 @@ static int snd_usbmidi_create_rawmidi(struct snd_usb_midi* umidi,
rmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT | rmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT |
SNDRV_RAWMIDI_INFO_INPUT | SNDRV_RAWMIDI_INFO_INPUT |
SNDRV_RAWMIDI_INFO_DUPLEX; SNDRV_RAWMIDI_INFO_DUPLEX;
rmidi->ops = &snd_usbmidi_ops;
rmidi->private_data = umidi; rmidi->private_data = umidi;
rmidi->private_free = snd_usbmidi_rawmidi_free; rmidi->private_free = snd_usbmidi_rawmidi_free;
snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_usbmidi_output_ops); snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_usbmidi_output_ops);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment