diff options
Diffstat (limited to 'sound/usb/usbmidi.c')
-rw-r--r-- | sound/usb/usbmidi.c | 200 |
1 files changed, 130 insertions, 70 deletions
diff --git a/sound/usb/usbmidi.c b/sound/usb/usbmidi.c index 2b9d940c8064..5c53ec8a13bf 100644 --- a/sound/usb/usbmidi.c +++ b/sound/usb/usbmidi.c | |||
@@ -48,6 +48,7 @@ | |||
48 | #include <linux/usb.h> | 48 | #include <linux/usb.h> |
49 | #include <sound/core.h> | 49 | #include <sound/core.h> |
50 | #include <sound/rawmidi.h> | 50 | #include <sound/rawmidi.h> |
51 | #include <sound/asequencer.h> | ||
51 | #include "usbaudio.h" | 52 | #include "usbaudio.h" |
52 | 53 | ||
53 | 54 | ||
@@ -1010,97 +1011,157 @@ static struct snd_rawmidi_substream *snd_usbmidi_find_substream(struct snd_usb_m | |||
1010 | * "(product) MIDI (n)" schema because they aren't external MIDI ports, | 1011 | * "(product) MIDI (n)" schema because they aren't external MIDI ports, |
1011 | * such as internal control or synthesizer ports. | 1012 | * such as internal control or synthesizer ports. |
1012 | */ | 1013 | */ |
1013 | static struct { | 1014 | static struct port_info { |
1014 | u32 id; | 1015 | u32 id; |
1015 | int port; | 1016 | short int port; |
1016 | const char *name_format; | 1017 | short int voices; |
1017 | } snd_usbmidi_port_names[] = { | 1018 | const char *name; |
1019 | unsigned int seq_flags; | ||
1020 | } snd_usbmidi_port_info[] = { | ||
1021 | #define PORT_INFO(vendor, product, num, name_, voices_, flags) \ | ||
1022 | { .id = USB_ID(vendor, product), \ | ||
1023 | .port = num, .voices = voices_, \ | ||
1024 | .name = name_, .seq_flags = flags } | ||
1025 | #define EXTERNAL_PORT(vendor, product, num, name) \ | ||
1026 | PORT_INFO(vendor, product, num, name, 0, \ | ||
1027 | SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC | \ | ||
1028 | SNDRV_SEQ_PORT_TYPE_HARDWARE | \ | ||
1029 | SNDRV_SEQ_PORT_TYPE_PORT) | ||
1030 | #define CONTROL_PORT(vendor, product, num, name) \ | ||
1031 | PORT_INFO(vendor, product, num, name, 0, \ | ||
1032 | SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC | \ | ||
1033 | SNDRV_SEQ_PORT_TYPE_HARDWARE) | ||
1034 | #define ROLAND_SYNTH_PORT(vendor, product, num, name, voices) \ | ||
1035 | PORT_INFO(vendor, product, num, name, voices, \ | ||
1036 | SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC | \ | ||
1037 | SNDRV_SEQ_PORT_TYPE_MIDI_GM | \ | ||
1038 | SNDRV_SEQ_PORT_TYPE_MIDI_GM2 | \ | ||
1039 | SNDRV_SEQ_PORT_TYPE_MIDI_GS | \ | ||
1040 | SNDRV_SEQ_PORT_TYPE_MIDI_XG | \ | ||
1041 | SNDRV_SEQ_PORT_TYPE_HARDWARE | \ | ||
1042 | SNDRV_SEQ_PORT_TYPE_SYNTHESIZER) | ||
1043 | #define SOUNDCANVAS_PORT(vendor, product, num, name, voices) \ | ||
1044 | PORT_INFO(vendor, product, num, name, voices, \ | ||
1045 | SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC | \ | ||
1046 | SNDRV_SEQ_PORT_TYPE_MIDI_GM | \ | ||
1047 | SNDRV_SEQ_PORT_TYPE_MIDI_GM2 | \ | ||
1048 | SNDRV_SEQ_PORT_TYPE_MIDI_GS | \ | ||
1049 | SNDRV_SEQ_PORT_TYPE_MIDI_XG | \ | ||
1050 | SNDRV_SEQ_PORT_TYPE_MIDI_MT32 | \ | ||
1051 | SNDRV_SEQ_PORT_TYPE_HARDWARE | \ | ||
1052 | SNDRV_SEQ_PORT_TYPE_SYNTHESIZER) | ||
1018 | /* Roland UA-100 */ | 1053 | /* Roland UA-100 */ |
1019 | { USB_ID(0x0582, 0x0000), 2, "%s Control" }, | 1054 | CONTROL_PORT(0x0582, 0x0000, 2, "%s Control"), |
1020 | /* Roland SC-8850 */ | 1055 | /* Roland SC-8850 */ |
1021 | { USB_ID(0x0582, 0x0003), 0, "%s Part A" }, | 1056 | SOUNDCANVAS_PORT(0x0582, 0x0003, 0, "%s Part A", 128), |
1022 | { USB_ID(0x0582, 0x0003), 1, "%s Part B" }, | 1057 | SOUNDCANVAS_PORT(0x0582, 0x0003, 1, "%s Part B", 128), |
1023 | { USB_ID(0x0582, 0x0003), 2, "%s Part C" }, | 1058 | SOUNDCANVAS_PORT(0x0582, 0x0003, 2, "%s Part C", 128), |
1024 | { USB_ID(0x0582, 0x0003), 3, "%s Part D" }, | 1059 | SOUNDCANVAS_PORT(0x0582, 0x0003, 3, "%s Part D", 128), |
1025 | { USB_ID(0x0582, 0x0003), 4, "%s MIDI 1" }, | 1060 | EXTERNAL_PORT(0x0582, 0x0003, 4, "%s MIDI 1"), |
1026 | { USB_ID(0x0582, 0x0003), 5, "%s MIDI 2" }, | 1061 | EXTERNAL_PORT(0x0582, 0x0003, 5, "%s MIDI 2"), |
1027 | /* Roland U-8 */ | 1062 | /* Roland U-8 */ |
1028 | { USB_ID(0x0582, 0x0004), 0, "%s MIDI" }, | 1063 | EXTERNAL_PORT(0x0582, 0x0004, 0, "%s MIDI"), |
1029 | { USB_ID(0x0582, 0x0004), 1, "%s Control" }, | 1064 | CONTROL_PORT(0x0582, 0x0004, 1, "%s Control"), |
1030 | /* Roland SC-8820 */ | 1065 | /* Roland SC-8820 */ |
1031 | { USB_ID(0x0582, 0x0007), 0, "%s Part A" }, | 1066 | SOUNDCANVAS_PORT(0x0582, 0x0007, 0, "%s Part A", 64), |
1032 | { USB_ID(0x0582, 0x0007), 1, "%s Part B" }, | 1067 | SOUNDCANVAS_PORT(0x0582, 0x0007, 1, "%s Part B", 64), |
1033 | { USB_ID(0x0582, 0x0007), 2, "%s MIDI" }, | 1068 | EXTERNAL_PORT(0x0582, 0x0007, 2, "%s MIDI"), |
1034 | /* Roland SK-500 */ | 1069 | /* Roland SK-500 */ |
1035 | { USB_ID(0x0582, 0x000b), 0, "%s Part A" }, | 1070 | SOUNDCANVAS_PORT(0x0582, 0x000b, 0, "%s Part A", 64), |
1036 | { USB_ID(0x0582, 0x000b), 1, "%s Part B" }, | 1071 | SOUNDCANVAS_PORT(0x0582, 0x000b, 1, "%s Part B", 64), |
1037 | { USB_ID(0x0582, 0x000b), 2, "%s MIDI" }, | 1072 | EXTERNAL_PORT(0x0582, 0x000b, 2, "%s MIDI"), |
1038 | /* Roland SC-D70 */ | 1073 | /* Roland SC-D70 */ |
1039 | { USB_ID(0x0582, 0x000c), 0, "%s Part A" }, | 1074 | SOUNDCANVAS_PORT(0x0582, 0x000c, 0, "%s Part A", 64), |
1040 | { USB_ID(0x0582, 0x000c), 1, "%s Part B" }, | 1075 | SOUNDCANVAS_PORT(0x0582, 0x000c, 1, "%s Part B", 64), |
1041 | { USB_ID(0x0582, 0x000c), 2, "%s MIDI" }, | 1076 | EXTERNAL_PORT(0x0582, 0x000c, 2, "%s MIDI"), |
1042 | /* Edirol UM-880 */ | 1077 | /* Edirol UM-880 */ |
1043 | { USB_ID(0x0582, 0x0014), 8, "%s Control" }, | 1078 | CONTROL_PORT(0x0582, 0x0014, 8, "%s Control"), |
1044 | /* Edirol SD-90 */ | 1079 | /* Edirol SD-90 */ |
1045 | { USB_ID(0x0582, 0x0016), 0, "%s Part A" }, | 1080 | ROLAND_SYNTH_PORT(0x0582, 0x0016, 0, "%s Part A", 128), |
1046 | { USB_ID(0x0582, 0x0016), 1, "%s Part B" }, | 1081 | ROLAND_SYNTH_PORT(0x0582, 0x0016, 1, "%s Part B", 128), |
1047 | { USB_ID(0x0582, 0x0016), 2, "%s MIDI 1" }, | 1082 | EXTERNAL_PORT(0x0582, 0x0016, 2, "%s MIDI 1"), |
1048 | { USB_ID(0x0582, 0x0016), 3, "%s MIDI 2" }, | 1083 | EXTERNAL_PORT(0x0582, 0x0016, 3, "%s MIDI 2"), |
1049 | /* Edirol UM-550 */ | 1084 | /* Edirol UM-550 */ |
1050 | { USB_ID(0x0582, 0x0023), 5, "%s Control" }, | 1085 | CONTROL_PORT(0x0582, 0x0023, 5, "%s Control"), |
1051 | /* Edirol SD-20 */ | 1086 | /* Edirol SD-20 */ |
1052 | { USB_ID(0x0582, 0x0027), 0, "%s Part A" }, | 1087 | ROLAND_SYNTH_PORT(0x0582, 0x0027, 0, "%s Part A", 64), |
1053 | { USB_ID(0x0582, 0x0027), 1, "%s Part B" }, | 1088 | ROLAND_SYNTH_PORT(0x0582, 0x0027, 1, "%s Part B", 64), |
1054 | { USB_ID(0x0582, 0x0027), 2, "%s MIDI" }, | 1089 | EXTERNAL_PORT(0x0582, 0x0027, 2, "%s MIDI"), |
1055 | /* Edirol SD-80 */ | 1090 | /* Edirol SD-80 */ |
1056 | { USB_ID(0x0582, 0x0029), 0, "%s Part A" }, | 1091 | ROLAND_SYNTH_PORT(0x0582, 0x0029, 0, "%s Part A", 128), |
1057 | { USB_ID(0x0582, 0x0029), 1, "%s Part B" }, | 1092 | ROLAND_SYNTH_PORT(0x0582, 0x0029, 1, "%s Part B", 128), |
1058 | { USB_ID(0x0582, 0x0029), 2, "%s MIDI 1" }, | 1093 | EXTERNAL_PORT(0x0582, 0x0029, 2, "%s MIDI 1"), |
1059 | { USB_ID(0x0582, 0x0029), 3, "%s MIDI 2" }, | 1094 | EXTERNAL_PORT(0x0582, 0x0029, 3, "%s MIDI 2"), |
1060 | /* Edirol UA-700 */ | 1095 | /* Edirol UA-700 */ |
1061 | { USB_ID(0x0582, 0x002b), 0, "%s MIDI" }, | 1096 | EXTERNAL_PORT(0x0582, 0x002b, 0, "%s MIDI"), |
1062 | { USB_ID(0x0582, 0x002b), 1, "%s Control" }, | 1097 | CONTROL_PORT(0x0582, 0x002b, 1, "%s Control"), |
1063 | /* Roland VariOS */ | 1098 | /* Roland VariOS */ |
1064 | { USB_ID(0x0582, 0x002f), 0, "%s MIDI" }, | 1099 | EXTERNAL_PORT(0x0582, 0x002f, 0, "%s MIDI"), |
1065 | { USB_ID(0x0582, 0x002f), 1, "%s External MIDI" }, | 1100 | EXTERNAL_PORT(0x0582, 0x002f, 1, "%s External MIDI"), |
1066 | { USB_ID(0x0582, 0x002f), 2, "%s Sync" }, | 1101 | EXTERNAL_PORT(0x0582, 0x002f, 2, "%s Sync"), |
1067 | /* Edirol PCR */ | 1102 | /* Edirol PCR */ |
1068 | { USB_ID(0x0582, 0x0033), 0, "%s MIDI" }, | 1103 | EXTERNAL_PORT(0x0582, 0x0033, 0, "%s MIDI"), |
1069 | { USB_ID(0x0582, 0x0033), 1, "%s 1" }, | 1104 | EXTERNAL_PORT(0x0582, 0x0033, 1, "%s 1"), |
1070 | { USB_ID(0x0582, 0x0033), 2, "%s 2" }, | 1105 | EXTERNAL_PORT(0x0582, 0x0033, 2, "%s 2"), |
1071 | /* BOSS GS-10 */ | 1106 | /* BOSS GS-10 */ |
1072 | { USB_ID(0x0582, 0x003b), 0, "%s MIDI" }, | 1107 | EXTERNAL_PORT(0x0582, 0x003b, 0, "%s MIDI"), |
1073 | { USB_ID(0x0582, 0x003b), 1, "%s Control" }, | 1108 | CONTROL_PORT(0x0582, 0x003b, 1, "%s Control"), |
1074 | /* Edirol UA-1000 */ | 1109 | /* Edirol UA-1000 */ |
1075 | { USB_ID(0x0582, 0x0044), 0, "%s MIDI" }, | 1110 | EXTERNAL_PORT(0x0582, 0x0044, 0, "%s MIDI"), |
1076 | { USB_ID(0x0582, 0x0044), 1, "%s Control" }, | 1111 | CONTROL_PORT(0x0582, 0x0044, 1, "%s Control"), |
1077 | /* Edirol UR-80 */ | 1112 | /* Edirol UR-80 */ |
1078 | { USB_ID(0x0582, 0x0048), 0, "%s MIDI" }, | 1113 | EXTERNAL_PORT(0x0582, 0x0048, 0, "%s MIDI"), |
1079 | { USB_ID(0x0582, 0x0048), 1, "%s 1" }, | 1114 | EXTERNAL_PORT(0x0582, 0x0048, 1, "%s 1"), |
1080 | { USB_ID(0x0582, 0x0048), 2, "%s 2" }, | 1115 | EXTERNAL_PORT(0x0582, 0x0048, 2, "%s 2"), |
1081 | /* Edirol PCR-A */ | 1116 | /* Edirol PCR-A */ |
1082 | { USB_ID(0x0582, 0x004d), 0, "%s MIDI" }, | 1117 | EXTERNAL_PORT(0x0582, 0x004d, 0, "%s MIDI"), |
1083 | { USB_ID(0x0582, 0x004d), 1, "%s 1" }, | 1118 | EXTERNAL_PORT(0x0582, 0x004d, 1, "%s 1"), |
1084 | { USB_ID(0x0582, 0x004d), 2, "%s 2" }, | 1119 | EXTERNAL_PORT(0x0582, 0x004d, 2, "%s 2"), |
1085 | /* Edirol UM-3EX */ | 1120 | /* Edirol UM-3EX */ |
1086 | { USB_ID(0x0582, 0x009a), 3, "%s Control" }, | 1121 | CONTROL_PORT(0x0582, 0x009a, 3, "%s Control"), |
1087 | /* M-Audio MidiSport 8x8 */ | 1122 | /* M-Audio MidiSport 8x8 */ |
1088 | { USB_ID(0x0763, 0x1031), 8, "%s Control" }, | 1123 | CONTROL_PORT(0x0763, 0x1031, 8, "%s Control"), |
1089 | { USB_ID(0x0763, 0x1033), 8, "%s Control" }, | 1124 | CONTROL_PORT(0x0763, 0x1033, 8, "%s Control"), |
1090 | /* MOTU Fastlane */ | 1125 | /* MOTU Fastlane */ |
1091 | { USB_ID(0x07fd, 0x0001), 0, "%s MIDI A" }, | 1126 | EXTERNAL_PORT(0x07fd, 0x0001, 0, "%s MIDI A"), |
1092 | { USB_ID(0x07fd, 0x0001), 1, "%s MIDI B" }, | 1127 | EXTERNAL_PORT(0x07fd, 0x0001, 1, "%s MIDI B"), |
1093 | /* Emagic Unitor8/AMT8/MT4 */ | 1128 | /* Emagic Unitor8/AMT8/MT4 */ |
1094 | { USB_ID(0x086a, 0x0001), 8, "%s Broadcast" }, | 1129 | EXTERNAL_PORT(0x086a, 0x0001, 8, "%s Broadcast"), |
1095 | { USB_ID(0x086a, 0x0002), 8, "%s Broadcast" }, | 1130 | EXTERNAL_PORT(0x086a, 0x0002, 8, "%s Broadcast"), |
1096 | { USB_ID(0x086a, 0x0003), 4, "%s Broadcast" }, | 1131 | EXTERNAL_PORT(0x086a, 0x0003, 4, "%s Broadcast"), |
1097 | }; | 1132 | }; |
1098 | 1133 | ||
1134 | static struct port_info *find_port_info(struct snd_usb_midi* umidi, int number) | ||
1135 | { | ||
1136 | int i; | ||
1137 | |||
1138 | for (i = 0; i < ARRAY_SIZE(snd_usbmidi_port_info); ++i) { | ||
1139 | if (snd_usbmidi_port_info[i].id == umidi->chip->usb_id && | ||
1140 | snd_usbmidi_port_info[i].port == number) | ||
1141 | return &snd_usbmidi_port_info[i]; | ||
1142 | } | ||
1143 | return NULL; | ||
1144 | } | ||
1145 | |||
1146 | static void snd_usbmidi_get_port_info(struct snd_rawmidi *rmidi, int number, | ||
1147 | struct snd_seq_port_info *seq_port_info) | ||
1148 | { | ||
1149 | struct snd_usb_midi *umidi = rmidi->private_data; | ||
1150 | struct port_info *port_info; | ||
1151 | |||
1152 | /* TODO: read port flags from descriptors */ | ||
1153 | port_info = find_port_info(umidi, number); | ||
1154 | if (port_info) { | ||
1155 | seq_port_info->type = port_info->seq_flags; | ||
1156 | seq_port_info->midi_voices = port_info->voices; | ||
1157 | } | ||
1158 | } | ||
1159 | |||
1099 | static void snd_usbmidi_init_substream(struct snd_usb_midi* umidi, | 1160 | static void snd_usbmidi_init_substream(struct snd_usb_midi* umidi, |
1100 | int stream, int number, | 1161 | int stream, int number, |
1101 | struct snd_rawmidi_substream ** rsubstream) | 1162 | struct snd_rawmidi_substream ** rsubstream) |
1102 | { | 1163 | { |
1103 | int i; | 1164 | struct port_info *port_info; |
1104 | const char *name_format; | 1165 | const char *name_format; |
1105 | 1166 | ||
1106 | struct snd_rawmidi_substream *substream = snd_usbmidi_find_substream(umidi, stream, number); | 1167 | 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 | } | 1171 | } |
1111 | 1172 | ||
1112 | /* TODO: read port name from jack descriptor */ | 1173 | /* TODO: read port name from jack descriptor */ |
1113 | name_format = "%s MIDI %d"; | 1174 | port_info = find_port_info(umidi, number); |
1114 | for (i = 0; i < ARRAY_SIZE(snd_usbmidi_port_names); ++i) { | 1175 | name_format = port_info ? port_info->name : "%s MIDI %d"; |
1115 | if (snd_usbmidi_port_names[i].id == umidi->chip->usb_id && | ||
1116 | snd_usbmidi_port_names[i].port == number) { | ||
1117 | name_format = snd_usbmidi_port_names[i].name_format; | ||
1118 | break; | ||
1119 | } | ||
1120 | } | ||
1121 | snprintf(substream->name, sizeof(substream->name), | 1176 | snprintf(substream->name, sizeof(substream->name), |
1122 | name_format, umidi->chip->card->shortname, number + 1); | 1177 | name_format, umidi->chip->card->shortname, number + 1); |
1123 | 1178 | ||
@@ -1457,6 +1512,10 @@ static int snd_usbmidi_create_endpoints_midiman(struct snd_usb_midi* umidi, | |||
1457 | return 0; | 1512 | return 0; |
1458 | } | 1513 | } |
1459 | 1514 | ||
1515 | static struct snd_rawmidi_global_ops snd_usbmidi_ops = { | ||
1516 | .get_port_info = snd_usbmidi_get_port_info, | ||
1517 | }; | ||
1518 | |||
1460 | static int snd_usbmidi_create_rawmidi(struct snd_usb_midi* umidi, | 1519 | static int snd_usbmidi_create_rawmidi(struct snd_usb_midi* umidi, |
1461 | int out_ports, int in_ports) | 1520 | int out_ports, int in_ports) |
1462 | { | 1521 | { |
@@ -1472,6 +1531,7 @@ static int snd_usbmidi_create_rawmidi(struct snd_usb_midi* umidi, | |||
1472 | rmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT | | 1531 | rmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT | |
1473 | SNDRV_RAWMIDI_INFO_INPUT | | 1532 | SNDRV_RAWMIDI_INFO_INPUT | |
1474 | SNDRV_RAWMIDI_INFO_DUPLEX; | 1533 | SNDRV_RAWMIDI_INFO_DUPLEX; |
1534 | rmidi->ops = &snd_usbmidi_ops; | ||
1475 | rmidi->private_data = umidi; | 1535 | rmidi->private_data = umidi; |
1476 | rmidi->private_free = snd_usbmidi_rawmidi_free; | 1536 | rmidi->private_free = snd_usbmidi_rawmidi_free; |
1477 | snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_usbmidi_output_ops); | 1537 | snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_usbmidi_output_ops); |