fbpx
Skip to main content

Building a USB MIDI 2.0 Device – Part 3

This is the third part in this series on how developers go about building a USB MIDI 2.0 Device. Please read Part 1 and Part 2 before reading Part 3.

In Part 2 we looked at handling Function Blocks and Group Terminal Blocks, UMP Discovery. 

In this third guide we will cover:

  • Using a USB Descriptor Builder to avoid mistakes
  • Interfaces and Interface Association Descriptors in USB
  • Why having separate MIDI 1.0 mode may be useful
  • OS Caching and Firmware updates that affect your USB Descriptors

Using a USB Descriptor Builder to avoid mistakes

Creating correct USB Descriptors can be difficult to get right. Issues can occur such as

  • Incorrect lengths of descriptors
  • Difficulties when creating USB Endpoint with multi MIDI 1.0 Ports
  • Confusion between USB Endpoint In/Out to Embedded Out/IN to External In/Out Descriptors
  • IAD creation

To make this much easier, members of the MIDI Association and MIDI2.dev have created a MIDI USB Descriptor Builder. It allows you to create the Descriptors needed to create a MIDI 1.0/2.0 USB Device. Although the Descriptor Builder is catered to output descriptor for use with tinyUSB tusb_ump driver (https://github.com/midi2-dev/tusb_ump) or the Linux Gadget interface, the generated code should be easily adaptable to other USB stack implementations.

The USB Descriptor Builder is located at https://midi2-dev.github.io/usbMIDI2DescriptorBuilder/ 

The GitHub repository is located here

Parts 1 and 2 of this article include several examples of descriptors. Those examples are based on the default settings of the Descriptor Builder. The USB Descriptor sets many parameters and properties used by the device. It is also recommended that you consider the association of these parameters in relation to other UMP features, selecting values that are consistently formatted. In developing your USB device, be sure to reference the Property Names and Mapping article (https://midi.org/midi-2-0-device-design-property-names-and-mapping).

Interfaces and Interface Association Descriptors (IAD)

If a device supports both USB MIDI and USB Audio, the device should be configured as a Composite device with Audio Interfaces separated from MIDI Interfaces. This mechanism is particularly useful in devices which combine Audio Class version 2, 3, or 4 with a MIDI Class function. This is because the MIDI Class Function, defined as a subclass of Audio Class, has an Audio Control Interface.

An IAD is used to show the relationship between the Audio Interfaces, particularly to associate an Audio Control Interface with an Audio Streaming Interface(s).

A separate IAD is used to show the relationship between the Interfaces for the MIDI Function. This IAD associates a 2nd Audio Control Interface with a MIDI Streaming Interface.

USB Hosts may use the IADs to better determine which drivers will be used to support the device.

Two Alternate Settings: To Enable Backward Compatibility

The USB Device Class Definition for MIDI Devices, Version 2.0 defines how the use of 2 Alternate Settings on the Class Specific MIDI Streaming Interface provides the widest compatibility of Devices and Hosts.

Using this mechanism, a Device can operate as a MIDI 1.0 Device when necessary, but can switch to operating as a MIDI 2.0 Device on any Host which can support MIDI 2.0.

Alternate Setting 0 of the MIDI Streaming Interface is compliant with USB Device Class Specification for MIDI Devices Version 1.0.

Alternate Setting 1 of the MIDI Streaming Interface has descriptors for the MIDI 2.0 function.

The bcdMSC field in Alternate Setting 0 is set to 0x0100. (MIDI 1.0)

The bcdMSC field in Alternate Setting 1 is set to 0x0200. (MIDI 2.0)

USB MIDI Hosts which do not support USB MIDI 2.0 use the descriptors found on Alternate Setting 0 and install the Device as a MIDI 1.0 Device.

USB MIDI Hosts capable of supporting a USB MIDI 2.0 Device instead start by looking for an Alternate Setting 1 with bcdMSC set to 0x0200. If such an Alternate Setting is found in the device, the Host installs the Device as a MIDI 2.0 Device using those descriptors. If the Host does not find the Alternate Setting 1, then the Host will use the descriptors found on Alternate Setting 0 and install the Device as a MIDI 1.0 Device.

Why having separate MIDI 1.0 USB Only mode may be useful in some cases at this time

This may be done to be more compatible with and avoid unexpected behavior when used with some early beta versions of Host USB MIDI 2.0 drivers in 2023 and 2024. 

Initial USB MIDI 2.0 Devices, such as the Native Instruments Komplete Kontrol MK3 and the Roland A-88 MK2, store 2 sets of USB Descriptors :

  • Legacy MIDI 1.0 only
  • USB MIDI 2.0 (with alt 0 = MIDI 1.0, alt 1 = MIDI 2.0)

The user decides which to enable on the device. On the A-88MK2 this is a button combination on start up, on the Kontrol it is a menu option (which causes a reboot).

It is expected that with a short timeframe this will not be a concern and this suggestion will change. Ultimately, all Devices should simply have a single mode of operation which has an Alternate Setting 0 for MIDI 1.0 and an Alternate Setting 1 for MIDI 2.0.

OS Caching and Firmware updates that affect your USB Descriptors

When Devices connect to a Host, an OS may cache the USB Descriptors. For example CoreMIDI uses caching to build a database of MIDI Devices and to handle reconnects.

A Host might not be able to recognize when a device makes these kinds of changes::

  • USB Descriptors including string name changes
  • Group Terminal Block updates
  • Switching between a USB MIDI 1.0 only mode and USB MIDI 2.0 mode

If the Host OS does not recognize that a change has occurred, the user may experience errors and unknown behaviors. 

One method to avoid errors, the user needs to clear the cache and remove the prior device entry. However, this is not always possible and explaining the steps to users can be a challenge. This can be confusing and may still result in further technical support issues.

If the device can change the iSerial string value or the PID every time these notable configuration changes occur, then the OS will see a new device with a new set of features.

The End…

This set of articles would not have been possible without the input and support of the MIDI Association OSAPI Working Group members who provided much of the content.

Writing this series has helped me to clarify and organize my own understanding of  USB MIDI. The MIDI Association intends to continue publishing these kinds of articles to support developers.

Thank you to everyone else who provided information, asked probing questions, and read this series.

Basics of USB-MIDI

USB MIDI 2.0 ADOPTED

MIDI 2.0 Progress Continues with Updated USB Specification –  

As computers have become central components in many MIDI systems, USB has become the most widely used protocol for transporting MIDI data. With the introduction of MIDI 2.0, the USB Implementers Forum’s USB MIDI 2.0 working group, headed by members o

 

 

 

USB and MIDI

 

MIDI has stayed relevant for over 30 years by adapting to the different ways that computers send information to and from external devices. MIDI can now be sent over 5 Pin DIN, Serial Ports, USB, Firewire, Ethernet, Bluetooth and more. But currently the most prevalent way to connect to computers, tablets and smartphones is USB. This article will cover the basics of USB-MIDI.

 

Why USB came about

 

In the early 1990’s, there were far too many types of connectors on computers. There were separate serial ports, parallel ports, keyboard and mouse connections, and joystick ports, It was hard for people to tell whether the peripheral they were buying would actually work with their computer.  So Compaq, Intel, Microsoft and NEC ( joined later by Hewlett-Packard, Lucent and Philips) formed the USB Implementers Forum, Inc, a non-profit corporation to publish the specifications and organise further development in USB. Similar to the MIDI Manufacturers Association, the USB-IF makes sure that there is interoperability between USB devices.

 

Goals of USB

 

The USB-IF had some clear goals when first developing the USB specification

  • Standardize connector types: There are now several different types of USB connectors, but they are all standardized by the USB-IF
  • Hot-swappable: USB devices can be safely plugged and unplugged as needed while the computer is running. So there is no need to reboot.
  • Plug and Play: USB devices are divided into functional types (Audio, Image, Human User Interface, Mass Storage) and then operating system software can automatically identify, configure, and load the appropriate device driver when a user connects a USB device.
  • High performance: USB offers low speed (1.5 Mbit/s), full speed (12 Mbit/s) and high speed (up to 480 Mbit/s) transfer rates that can support a variety of USB peripherals. USB 3.0 (SuperSpeed USB) achieves the throughput up to 5.0 Gbit/s.
  • Expandability: Up to 127 different peripheral devices may theoretically be connected to a single bus at one time

 

USB System Architecture

 

The basic USB system architecture is actually pretty simple and consists of the following main components:

  • A Host Computer, Smartphone or Tablet
  • One or more USB Devices
  • A physical bus represented by the USB Cable that links the devices with the host 

The Universal Serial Bus is a host controlled bus. All data transfers are initiated and controlled by the host and USB peripherals are slaves responding to host commands. So for  USB MIDI peripheral devices you need a computer, smartphone or tablet in the system to control and initiate USB communication.

 

USB Device Classes

 

USB devices are defined into specific functional classes, for example image, human interface devices (keyboard, mouse, joystick), mass storage, and audio. The operating system can then know what the devices is designed to do and automatically load what is called a class compliant driver for that type of devices. In 1999, the MIDI specification was developed by the USB-IF in cooperation with the MIDI Manufacturers Association and included in the Audio class of devices.  That is why sometimes when you connect a USB-MIDI peripheral, the OS will display a message that says USB-Audio devices connected.  As far as USB is concerned MIDI is an Audio Class Compliant device.

 

Class Compliant Drivers versus Manufacturer Specific Drivers

 

Class compliant drivers are convenient because you don’t have to download any external software.  But often manufacturer specific drivers provide added functionality. Let’s use Yamaha has an example.  Because data transfer on USb is much faster than 5 pin DIN it is possible to have multiple ports of MIDI (a port is a group of 16 MIDI channels) on a single USB cable. The dedicated Yamaha USB Driver provides for 8 ports of high speed USB, includes the names of all the devices that are compatible with the driver and has some routing capabilities. These features are only available if you download the driver from Yamaha’s website.  Also many audio interfaces are also MIDI interfaces and audio and MIDI travel over the USb cable.  So if you purchase a MIDI or Audio interface you should always check the product manual and manufacturer’s website to see if there is a dedicated USB driver for your product that provides added functionality. Often even if the manufacturer specific driver is available when connected to a device which don’t allow driver downloads into the operating system (for example iOS devices), the product will still work as a class compliant USB device.

 

Types of USB MIDI connectors

 

Over the years, USB has developed and there are now a number of different cable types and USB specifications. Let’s take a look at the different connectors.

 

 

 

 

Originally most desktop and laptops computers had the standard sized Type A USB connector. A standard USB cable has a Type A connector on one end to connect to the host and a Type B connector on the other end to connect to the peripheral device. This is still the most common cable to connect a MIDI instrument to a computer.

 

 

 

 

USB Type A host connector

 

 

 

 

Type B USB peripheral connector

 

 

The Type A connector has a pin that supplies power to external peripherals so you need to be carefully about trying to connect two hosts via a Type A to Type A cable. This can cause serious damage to your gear so consult the manufacturer and manual before attempting this.

 

The Type A connector is for host controllers (computers, smartphones, tablets and some digital musical instruments that act as hosts) and USB hubs. A USB hub is a device that expands a single (USB) port into several so that there are more ports available to connect devices to a host system.USB hubs are often built into equipment such as computers, computer keyboards, monitors, or printers. When a device has many USB ports, they all usually stem from one or two internal USB hubs rather than each port having independent USB circuitry. If you need more USB ports, there are also external hubs that you can buy. You need to check to see if your USB peripherals need to be powered by USB and if they do you may need a powered USB hub.

 

 

 

 

On many digital musical instruments you find two USB connectors – one Type A connector labeled To Device and one Type B labeled To Host .  The To Host is usually used to send MIDI, Audio or both Audio and MIDI to a computer, smartphone or tablet. If your digital music product sends both MIDI and Audio over USB, you will almost certainly need a manufacturer specific driver.

The To Device is usually used for USB Storage devices like Flash Thumb drives, but it can be used for other things depending on what the Host music product supports for device classes.

 

 

 

 

USB A-Type

 

Considered the standard and most common type of connector, A-style connectors are found on the PC or charger side of most cables. This flat, rectangular interface is held in place through friction. Durable enough for continuous connection but easy enough for users to connect and disconnect, this connector type is also available in micro variations.

 

USB B-Type

 

Type-B USBs were traditionally used with printer cables but, they’re now found on many popular models of Android smartphones and external hard drives. These USBs feature a square interface and are available as a Micro-USB B, USB Mini-b (5-pin), and USB Mini-b (4-pin).

 

USB C-Type

 

The newest type of connector on the market, Type-C is a one-size-fits-all solution. Developed to support devices with a smaller, thinner and lighter form factor. Type-C is slim enough for a smartphone or tablet, yet robust enough for a desktop computer. It also has the advantage of a reversible plug orientation and cable direction, eliminating the guesswork about which direction the connection goes.

 

The future of USB Connectivity

 

USB Type-C is designed as a one-size-fits-all solution for data transfer and power supply on any device. Featuring a smaller connector, Type-C fits into one multi-use port to simultaneously charge devices and transfer data and also offers backward compatibility to support previous USB standards (2.0, 3.0, and 3.1).

Type-C is quickly becoming the new standard for operating systems and hardware providers; Intel’s Thunderbolt recently switched to USB Type-C ports while enabling cross compatibility with USB 3.1. The new Apple MacBooks feature a Type-C port.

The USB-IF predicts that by 2019, all laptops, tablets, mobile phones, and other consumer electronics will be equipped with USB Type-C.

In the meantime, if you have a newer computer, you may need an adapter to connect your MIDI gear to your computer.