Augast 31 2024
USB MIDI is a standard for treating Arduino as a MIDI device by connecting it to a computer with a USB cable. Using this standard, you can exchange MIDI messages between Arduino and a PC. It was standardized by the USB standards organization USB-IF in 1999. The specification can be downloaded from USB MIDI Devices 1.0. The USB MIDI library is a library that is installed on Arduino.
By the way, a new version of USB MIDI was released in 2020: USB Class Definition for MIDI Devices v2.0. However, it seems that there are currently no devices or Arduino libraries that are compatible with this version. (August 31 2024)
When you search for MIDIUSB in the Library Manager of the Arduino IDE, you will find three libraries: one called 1)MIDIUSB, one called 2)USB-MIDI, and one called 3)USBMIDI. Very confusing.
For Arduino IDE 2.3.2, it will be found them as follows. (August 31 2024)
I will describe the features of three similarly named libraries.
MIDIUSB is a library provided by arduino.LCC for atmega32u4 or ARM boards. It is based on PluggableUSB, a general USB library for Arduino.
MIDI messages are handled by the midiEventPacket_t structure.
Send MIDI: midiEventPacket_t message = MidiUSB.read() Receive MIDI: MidiUSB.send(midiEventPacket_t event)
The source code is available on Github here.
USB-MIDI has a "- " between USB and MIDI. The source code is available on Github here. And this is a library to make using MIDIUSB more convenient.
When you try to install this library, you will be prompted to install two libraries, MIDI Library and MIDIUSB as shown below.
For Arduino ID 2.3.2, it will be found them as follows. (August 31 2024)
This library allows you to set a callback function for each MIDI event. Below is an example of setting a callback function for the Note On and Note Off messages.
void setHandleNoteOn(NoteOnCallback fptr) void setHandleNoteOff(NoteOffCallback fptr) etc.
For details, see Arduino\libraries\MIDI_Library\src\MIDI.h installed. Thanks to this callback function, you don't need to parse each message in your program when you receive MIDI.
Source code of USBMIDI is available on Github here. The arduino.cc page is here. This is a library developed by BlokasLab.
The differences from MIDIUSB are described in the Arduino\libraries\Readme.md. The following is a quote.
Arduino has its own similar library called MIDIUSB, it was being developed relatively at the same time as USBMIDI. The biggest difference is that the MIDIUSB library introduced new APIs with difficult interfaces while USBMIDI library exposes a familiar interface, similar to the Serial objects, by inheriting and implementing the Stream base class. Therefore, as many existing projects and examples for MIDI are using Serial to send and receive MIDI data through the DIN-5 ports using TX/RX UART pins, the exact same code can be adapted simply by using USBMIDI global object instead of Serial, or generalized by refactoring the code generating and interpreting messages to use Stream pointers or references, and passing in USBMIDI as a reference, that makes it straightforward to extend existing projects with MIDI over USB support.The advantage of USBMIDI is that you can use programs for serial communication as is, and another advantage is that a wide variety of microcontrollers are available. The serial communication means send and receive MIDI message via TX and RX port.
USBMIDI uses a common library called V-USB Library as the USB interface. When you install this library, V-USB is automatically added to USBMIDI library.
For more detailed information on using USBMIDI and MIDIUSB, please refer to the Arduino Micro USB-MIDI page.
// Stream interface. virtual int available(); virtual int read(); virtual int peek(); virtual void flush(); // Print interface. virtual size_t write(uint8_t c);