Skip to contentSkip to conversation

MIDI driver for Behringer BCD2000 USB device

PATCH Superseded Mario Kicherer 2 participants 2 messages Feb 10, 2014 – Feb 17, 2014 Sound

v3 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 MIDI driver for Behringer BCD2000 USB device

This patch adds initial support for the Behringer BCD2000 USB DJ controller. At the moment, only the MIDI part of the device is working, i.e. knobs, buttons and LEDs.

I also plan to add support for the audio part, but I assume that this will require more effort than the rather simple MIDI interface. Progress can be tracked at https://github.com/anyc/snd-usb-bcd2000.

Changes since v2:
- applied more changes from Daniel Mack and Clemens Ladisch

Changes since v1:
- fixed the various code style issues, thanks to Daniel Mack and checkpatch.pl.

---
 sound/usb/Kconfig           |  13 ++
 sound/usb/Makefile          |   2 +-
 sound/usb/bcd2000/Makefile  |   3 +
 sound/usb/bcd2000/bcd2000.c | 484 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 501 insertions(+), 1 deletion(-)
 create mode 100644 sound/usb/bcd2000/Makefile
 create mode 100644 sound/usb/bcd2000/bcd2000.c
sound/usb/Kconfig +13 -0
index de9408b..145653a 100644
@@ -146,5 +146,18 @@ config SND_USB_HIFACE
 	  To compile this driver as a module, choose M here: the module
 	  will be called snd-usb-hiface.
 
+config SND_BCD2000
+	tristate "Behringer BCD2000 MIDI driver"
+	select SND_RAWMIDI
+	help
+	  Say Y here to include MIDI support for the Behringer BCD2000 DJ
+	  controller.
+
+	  Audio support is still work-in-progress at
+	  https://github.com/anyc/snd-usb-bcd2000
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called snd-bcd2000.
+
 endif	# SND_USB
 
sound/usb/Makefile +1 -1
index abe668f..2b92f0d 100644
@@ -23,4 +23,4 @@ obj-$(CONFIG_SND_USB_UA101) += snd-usbmidi-lib.o
 obj-$(CONFIG_SND_USB_USX2Y) += snd-usbmidi-lib.o
 obj-$(CONFIG_SND_USB_US122L) += snd-usbmidi-lib.o
 
-obj-$(CONFIG_SND) += misc/ usx2y/ caiaq/ 6fire/ hiface/
+obj-$(CONFIG_SND) += misc/ usx2y/ caiaq/ 6fire/ hiface/ bcd2000/
sound/usb/bcd2000/Makefile new file +3 -0
new file mode 100644
index 0000000..f09ccc0
@@ -0,0 +1,3 @@
+snd-bcd2000-y := bcd2000.o
+
+obj-$(CONFIG_SND_BCD2000) += snd-bcd2000.o
\ No newline at end of file
sound/usb/bcd2000/bcd2000.c new file +484 -0

484 lines not on this page · raw message

Signature · 1 line
1.8.3.2
#1 lore raw

Hi Mario,

Quoted 7 lines · Mario Kicherer

This patch adds initial support for the Behringer BCD2000 USB DJ controller. At the moment, only the MIDI part of the device is working, i.e. knobs, buttons and LEDs.

I also plan to add support for the audio part, but I assume that this will require more effort than the rather simple MIDI interface. Progress can be tracked at https://github.com/anyc/snd-usb-bcd2000.

This looks mostly nice to me now. I just have some minor comments inline.

Quoted 4 lines
 sound/usb/Kconfig           |  13 ++
 sound/usb/Makefile          |   2 +-
 sound/usb/bcd2000/Makefile  |   3 +
 sound/usb/bcd2000/bcd2000.c | 484 ++++++++++++++++++++++++++++++++++++++++++++

As soon as you add more functionality here such as audio, please rename the file so it describes what it's doing, and split functionality into something like card.c, midi.c, pcm.c etc. I think for now, the naming is acceptable.

sound/usb/bcd2000/bcd2000.c line 48

Quoted 8 lines
sound/usb/bcd2000/bcd2000.c new file +8 -0
+static unsigned char bcd2000_init_sequence[] = {
+	0x07, 0x00, 0x00, 0x00, 0x78, 0x48, 0x1c, 0x81,
+	0xc4, 0x00, 0x00, 0x00, 0x5e, 0x53, 0x4a, 0xf7,
+	0x18, 0xfa, 0x11, 0xff, 0x6c, 0xf3, 0x90, 0xff,
+	0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
+	0x18, 0xfa, 0x11, 0xff, 0x14, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0xf2, 0x34, 0x4a, 0xf7,
+	0x18, 0xfa, 0x11, 0xff};

'};' to a new line, please.

sound/usb/bcd2000/bcd2000.c line 108

Quoted 2 lines
sound/usb/bcd2000/bcd2000.c new file +2 -0
+static void bcd2000_midi_handle_input(struct bcd2000 *bcd2k,
+					const unsigned char *buf, int len)

You're passing the 'len' parameter from urb->actual_length, which is unsigned int. For consistency, make the type match here.

Quoted 16 lines
sound/usb/bcd2000/bcd2000.c new file +16 -0
+{
+	unsigned char length, tocopy;
+
+	if (!bcd2k->midi_receive_substream)
+		return;
+
+	bcd2000_dump_buffer(PREFIX "received from device: ", buf, len);
+
+	if (len < 2)
+		return;
+
+	/*
+	 * Packet structure: mm nn oo (pp)
+	 *	mm: payload length
+	 *	nn: MIDI command or note
+	 *	oo: note or velocity

sound/usb/bcd2000/bcd2000.c line 134

Quoted 10 lines
sound/usb/bcd2000/bcd2000.c new file +10 -0
+	 *	pp: velocity
+	 */
+
+	length = buf[0];
+
+	/* ignore packets without payload */
+	if (length == 0)
+		return;
+
+	tocopy = min(length, (unsigned char) (len-1));

I'd rather like it the other way around: make 'length' and 'tocopy' unsigned int, so you can avoid the cast and prevent the statement from overflowing.

Quoted 10 lines
sound/usb/bcd2000/bcd2000.c new file +10 -0
+static void bcd2000_midi_send(struct bcd2000 *bcd2k,
+				struct snd_rawmidi_substream *substream)
+{
+	int len, ret;
+
+	BUILD_BUG_ON(sizeof(device_cmd_prefix) >= BUFSIZE);
+	/* copy the "set LED" command bytes */
+	memcpy(bcd2k->midi_out_buf, device_cmd_prefix,
+		sizeof(device_cmd_prefix));
+

sound/usb/bcd2000/bcd2000.c line 162

Quoted 10 lines
sound/usb/bcd2000/bcd2000.c new file +10 -0
+	/*
+	 * get MIDI packet and leave space for command prefix
+	 * and payload length
+	 */
+	len = snd_rawmidi_transmit(substream,
+				bcd2k->midi_out_buf + 3, BUFSIZE - 3);
+
+	if (len < 0)
+		snd_printk("%s: snd_rawmidi_transmit error %d\n",
+				__func__, len);

Takashi just went through all the drivers and replaced the snd_printk() calls with pr_* and dev_* functions. This driver should also follow that new fashion ...

sound/usb/bcd2000/bcd2000.c line 179

Quoted 4 lines
sound/usb/bcd2000/bcd2000.c new file +4 -0
+	if (ret < 0)
+		dev_err(&bcd2k->dev->dev, PREFIX
+			"%s (%p): usb_submit_urb() failed, ret=%d, len=%d\n",
+			__func__, substream, ret, len);

... like you do here.

Thanks!
Daniel