Author Topic: Keep your MIDI simple  (Read 198 times)

Renate

  • Frequent Contributor
  • ****
  • Posts: 56
Keep your MIDI simple
« on: December 09, 2020, 06:39:33 pm »
Everybody has read the USB MIDI spec: https://www.usb.org/sites/default/files/midi10.pdf
It gives one example in Appendix B (page 37) of a descriptor block for a "Simple MIDI Adapter".
It seems that everyone scratches their head over this complicated standard and just copies the example verbatim.
I've done that too.
So, I'd like to mention a few points.

You only need "Jacks" for input or output if you actually need it.
USB HID must always have an input endpoint, but this isn't like that.

If you are making a keyboard, you need "external" MIDI IN jack -> "embedded"  MIDI OUT jack -> USB IN endpoint.
If you are making a synthesizer you need  USB OUT endpoint -> "embedded" MIDI IN jack -> "external" MIDI OUT jack.

You probably don't need ANY "external jacks".
Keep your MIDI OUT JACK descriptor simple, you probably don't need any of the external routing stuff.


And finally, double check the wTotalLength in the class-specific MIDI interface descriptor as including that and up to the last class-specific MIDI endpoint descriptor.
« Last Edit: December 13, 2020, 11:41:08 am by Renate »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 2959
    • Lakeview Research
Re: Keep your MIDI simple
« Reply #1 on: December 10, 2020, 10:41:23 pm »
Thanks for the tips, Renate!

Renate

  • Frequent Contributor
  • ****
  • Posts: 56
Re: Keep your MIDI simple
« Reply #2 on: December 12, 2020, 03:10:13 pm »
Well, apparently, I don't know what I'm talking about.
Using the previously stated approach, things just work hunky-dorky until you reboot.
Then they don't.
I don't know what's going on, but I will investigate.

Edit: This works fine on Linux on a RPi.
Code: [Select]
[   50.947112] usb 1-1.2: new full-speed USB device number 4 using dwc_otg
...
[   51.188766] usbcore: registered new interface driver snd-usb-audio

~ $ amidi -d -p hw:1
90 3D 7F
80 3D 00
...

Unfortunately under Windows it loads fine (with no error code) but it doesn't enumerate under midiInGetNumDevs();
A synthesizer-only works fine in Windows, a keyboard-only is problematic.

I have another two commercial keyboards, I looked at their descriptors and they are pretty much like the example in the MIDI spec.
I don't think that they actually do anything with the USB OUT/MIDI IN.

It's funny because the MIDI spec says explicitly that external jacks are not required.
« Last Edit: December 13, 2020, 08:50:28 am by Renate »

Renate

  • Frequent Contributor
  • ****
  • Posts: 56
Re: Keep your MIDI simple
« Reply #3 on: December 13, 2020, 12:36:00 pm »
So, final notes:

I've fixed the original post so as not to confuse anyone.

The thing that got me started on this was the amount of MIDI devices I've seen that present as both input and output despite not having both capabilities.
For instance, I can use Audacity and select my Korg nanoKey 2 keyboard as the MIDI playback device.
When I play a MIDI file not a peep comes out of the keyboard!

So the only thing we learned from this excursion is that you can chop out two jack descriptors, one endpoint descriptor and one MIDI endpoint descriptor for the direction you are not using.
We always have to have an "external" jack and an "embedded" jack for each direction we are using.
Moreover, "external" doesn't mean external to anything really.

So, are you ready to deal with MIDI 2.0? :P

Unrelated warning
I was working on another HID device and had left it in a beat up shape.
The next time I tried to boot my PC it would not boot at all, no splash screen, no error beeps, it just stalled.
After much experimentation I figure it out (and unplugged the offending device).
The Asus BIOS tries to enumerate the USB for keyboards before splashing the screen.
If it get something that looks like a keyboard but has serious moral flaws it freezes without a peep.

bpaddock

  • Frequent Contributor
  • ****
  • Posts: 54
Re: Keep your MIDI simple
« Reply #4 on: December 14, 2020, 08:05:00 am »
"I was working on another HID device and had left it in a beat up shape.
The next time I tried to boot my PC it would not boot at all, "

Having a hub full of embedded development boards will do the same.
I have to unplug the hub anytime I do a hard reset of the PC.