Skip to contentSkip to conversation

g_midi: New USB MIDI Gadget class driver.

RFC In review Ben Williamson 3 participants 6 messages Jul 6, 2006 – Jul 7, 2006 USB

lore
Share & tools
lore
#0 lore raw

RFC 1/1 g_midi: New USB MIDI Gadget class driver.

Hi all,

This patch adds a USB MIDI Gadget driver. This driver is glue between the USB gadget interface and the ALSA MIDI interface. It allows an embedded Linux system to appear as a class-compliant USB-MIDI device to a host system on the other end of a USB cable.

Much of the code is borrowed from zero.c, usbmidi.c and usbaudio.c; my thanks to David, Clemens and Takashi for their work.

Included are usb_audio.h and usb_midi.h containing definitions from the relevant USB specifications for USB audio and USB MIDI devices. The definitions of struct usb_ms_header_descriptor and struct usb_ms_endpoint_descriptor are the same as those that appear in sound/usb/usbmidi.c, with the intention of that file including <linux/usb_midi.h> instead. I have not included that change here.

This patch is against v2.6.17. I have tested using dummy_hcd inside user-mode linux, and using s3c2410_udc. Testing with user-mode linux requires minor changes to a few Kconfig files in order to enable the USB and sound subsystems with ARCH=um.

I have tested playing a midi file with aplaymidi at one end and dumping the events with amidi at the other (in both directions) as well as connecting to a Mac running a synth with Garage Band.

All comments are welcome. If the response is favourable then I'll submit this driver to the USB folks for inclusion.

Cheers,

- Ben.

P.S. My apologies if it's inappropriate to cross-post to linux-usb-devel and alsa-devel, I'm hoping you're both interested. :)

P.P.S. My first attempt at emailing a patch with Thunderbird. Whitespace was munged when inline, so I hope a text/plain attachment is ok.

---
 drivers/usb/gadget/Kconfig  |   13 
 drivers/usb/gadget/Makefile |    2 
 drivers/usb/gadget/gmidi.c  | 1292 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/usb_audio.h   |   52 ++
 include/linux/usb_midi.h    |  110 ++++
 5 files changed, 1469 insertions(+), 0 deletions(-)
drivers/usb/gadget/Kconfig +13 -0
index 363b2ad..6835649 100644
@@ -404,6 +404,19 @@ config USB_G_SERIAL
 	  which includes instructions and a "driver info file" needed to
 	  make MS-Windows work with this driver.
 
+config USB_MIDI_GADGET
+	tristate "MIDI Gadget (EXPERIMENTAL)"
+	depends on EXPERIMENTAL
+	help
+	  The MIDI Gadget acts as a USB Audio device, with one MIDI
+	  input and one MIDI output. These MIDI jacks appear as
+	  a sound "card" in the ALSA sound system. Other MIDI
+	  connections can then be made on the gadget system, using
+	  ALSA's aconnect utility etc.
+
+	  Say "y" to link the driver statically, or "m" to build a
+	  dynamically linked module called "g_midi".
+
 
 # put drivers that need isochronous transfer support (for audio
 # or video class gadget drivers), or specific hardware, here.
drivers/usb/gadget/Makefile +2 -0
index 5a28e61..e71e086 100644
@@ -15,6 +15,7 @@ #
 g_zero-objs			:= zero.o usbstring.o config.o epautoconf.o
 g_ether-objs			:= ether.o usbstring.o config.o epautoconf.o
 g_serial-objs			:= serial.o usbstring.o config.o epautoconf.o
+g_midi-objs			:= gmidi.o usbstring.o config.o epautoconf.o
 gadgetfs-objs			:= inode.o
 g_file_storage-objs		:= file_storage.o usbstring.o config.o \
 					epautoconf.o
@@ -28,4 +29,5 @@ obj-$(CONFIG_USB_ETH)		+= g_ether.o
 obj-$(CONFIG_USB_GADGETFS)	+= gadgetfs.o
 obj-$(CONFIG_USB_FILE_STORAGE)	+= g_file_storage.o
 obj-$(CONFIG_USB_G_SERIAL)	+= g_serial.o
+obj-$(CONFIG_USB_MIDI_GADGET)	+= g_midi.o
 
drivers/usb/gadget/gmidi.c new file +1292 -0

1,292 lines not on this page · raw message

include/linux/usb_audio.h new file +52 -0

52 lines not on this page · raw message

include/linux/usb_midi.h new file +110 -0

110 lines not on this page · raw message

Signature · 1 line
1.4.0

Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

#1 lore raw
Quoted 2 lines · Ben Williamson

This patch adds a USB MIDI Gadget driver. This driver is glue between the USB gadget interface and the ALSA MIDI interface.

Looks good. (Not that I tested it. ;-)

Some remarks below.

drivers/usb/gadget/Kconfig config USB_G_SERIAL · line 409

Quoted 3 lines
drivers/usb/gadget/Kconfig +3 -0
+config USB_MIDI_GADGET
+	tristate "MIDI Gadget (EXPERIMENTAL)"
+	depends on EXPERIMENTAL

You need something like this:
depends on SND
select SND_RAWMIDI

Quoted 1 line

+#include <sound/asequencer.h>

This header isn't needed.

drivers/usb/gadget/gmidi.c line 1084

Quoted 1 line
drivers/usb/gadget/gmidi.c new file +1 -0
+	card = snd_card_new(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, THIS_MODULE, 0);

Other ALSA drivers have module options for index and id.

I could imagine that a synthesizer has another sound card for PCM output; it would make sense for at least the index to be configurable.

drivers/usb/gadget/gmidi.c line 1139

Quoted 3 lines
drivers/usb/gadget/gmidi.c new file +3 -0
+enomem:
+	...
+	return -ENOMEM;

These error handlers could return err instead.

Regards,
Clemens

Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

#2 lore raw
Quoted 3 lines · Clemens Ladisch

You need something like this:
depends on SND
select SND_RAWMIDI

Thanks, will do.

Quoted 3 lines

drivers/usb/gadget/gmidi.c line 1084

Quoted 1 line
drivers/usb/gadget/gmidi.c new file +1 -0
+	card = snd_card_new(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, THIS_MODULE, 0);

Other ALSA drivers have module options for index and id.

How's this?

static int index = SNDRV_DEFAULT_IDX1;
static char *id = SNDRV_DEFAULT_STR1;

module_param(index, int, 0444);
MODULE_PARM_DESC(index, "Index value for the USB MIDI Gadget adapter."); module_param(id, charp, 0444);
MODULE_PARM_DESC(id, "ID string for the USB MIDI Gadget adapter.");

	card = snd_card_new(index, id, THIS_MODULE, 0);

I see lots of drivers with arrays for those, but I think I can use the excuse that there is at most once instance of gmidi. As far as I can tell, the gadget subsystem only handles one udc interface, at least for now.

Thanks for the feedback, I'll post another version when I can incorporating all the suggestions.

Cheers,

- Ben.

Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

#3 lore raw
Quoted 4 lines

I see lots of drivers with arrays for those, but I think I can use the excuse that there is at most once instance of gmidi. As far as I can tell, the gadget subsystem only handles one udc interface, at least for now.

One UDC, yes -- that's a very basic USB definition thing. But surely one MIDI gadget can support multiple channels, one interface each?

- Dave

Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

#4 lore raw
Quoted 2 lines · David Brownell

One UDC, yes -- that's a very basic USB definition thing. But surely one MIDI gadget can support multiple channels, one interface each?

Actually I was wondering if you plan to support plugging in multiple NetChip UDC cards, but I can't imagine it would be all that useful.

At this stage g_midi only support one MIDI in jack and one MIDI out jack, because that's all I need for now. In order to support more than that one would need to add more jack descriptors and corresponding rawmidi substreams, none of which should be too tough. But I think it would make the most sense for all that to still appear under the one ALSA "card", with a single index and id as Clemens suggested, at least as I understand it.

- Ben.

Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

#5 lore raw
In reply to Ben Williamson
Quoted 6 lines · Ben Williamson

Included are usb_audio.h and usb_midi.h containing definitions from the relevant USB specifications for USB audio and USB MIDI devices. The definitions of struct usb_ms_header_descriptor and struct usb_ms_endpoint_descriptor are the same as those that appear in sound/usb/usbmidi.c, with the intention of that file including <linux/usb_midi.h> instead. I have not included that change here.

Make that <linux/usb/midi.h> or maybe <linux/usb/audio.h> ... in fact, several pending patches move <linux/usb_*.h> files into that subdirectory, so watch out when this is ready to submit.

Glad to see such a driver. I won't comment on the MIDI bits, but quick comments on other parts are below.

- Dave

This still have some debris left over from gadget zero, like mentions of having two configurations, using endpoint names rather than just the endpoints, and even comments describing itself as being gadget zero. Best to clean that stuff up more; gadget zero did a bunch of stuff mostly to make sure that APIs get tested, or to work with earlier versions of the gadget framework, and your driver can be smaller.

I don't think this is a case where usb_ep_alloc_buffer() and friends are desired ... such buffers are normally not cacheable.

You should have driver code to support high speed controllers, e.g. the high speed descriptors including the device qualifier.

Quoted 1 line

+static const struct USB_MIDI_OUT_JACK_DESCRIPTOR(1) jack_out_emb_desc = {

What's with the SHOUTING in a struct name? Those are nasty macros. All the struct names should be lowercase.

Note that this attachment got mangled a bit too (STATE_SYSEX_2 line wrapped).

Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel