Skip to content

Introduction to MIDI

Sara Adkins edited this page Oct 23, 2017 · 9 revisions

What is MIDI?

MIDI(Music Instrument Digital Interface) is a technical standard used to quickly communicate musical data. The MIDI protocol is commonly used in electronic instruments such as synthesizers. MIDI works by sending a piece of data called a MIDI message to a computer or digital instrument that then interprets the message and (usually) outputs sound based on the message it receives. By sending MIDI messages to our robotic instruments, we can easily control the music RobOrchestra plays.

Types of MIDI Messages

There are several different types of MIDI messages, which are all commonly used to control synthesizers. For the purposes of RobOrchestra we care about primarily about two types of messages: the NoteOn message and the NoteOff message. Details about how messages are encoded can be found in Dave's MIDI Spec.

NoteOn Message

A noteOn message is composed of 3 components: channel, pitch and velocity. By sending a noteOn message, we are telling the robot receiving the message to immediately play the note specified.

  • Channel: When sending a noteOn message, we use the channel parameter to specify which robot we want to play the note. Each robotic instrument is programmed to accept MIDI messages from its specific channel. The channel parameter must be an integer 0-15
  • Pitch: This parameter is used to tell the robot which pitch to play. This parameter is represented as an integer. Use the MIDI Pitch Table to translate a note name(C4, E3 etc.) to its corresponding MIDI pitch value. For percussion robots, each type of drum has a corresponding "pitch" value as defined in the Percussion Pitch Table
  • Velocity: The velocity value corresponds to volume, and is represented by an integer 0-127. This parameter specifies how loud to play a note, but most RobOrchestra instruments ignore this parameter.

NoteOff Message

A noteOff message specifies that a previously sent noteOn message should stop playing. Without this message type, all notes would play forever! A noteOff message has the same 3 parameters as a noteOn message, but the velocity value MUST be set to 0. When "turning off" a note, be sure to use the same channel the note was turned on with.

RobOrchestra MIDI Setup

All RobOrchestra instruments are controlled by Arduinos with MIDI shields that are programmed to listen for MIDI messages. The robots are connected to each other via MIDI cables in a daisy chain. Each robot listens for MIDI messages on a specific channel. Because the robots are connected in a daisy chain, each robot receives all MIDI messages that are sent to the orchestra, but only interprets messages sent to their specific channel.

The orchestra receives MIDI messages from a laptop through a USB-to-MIDI cable. Since MIDI is a universal standard, any program that outputs MIDI via USB can be used to control RobOrchestra. However, our software team usually uses the Java MIDI Library and Processing to program and send MIDI messages to the orchestra.

A Note on Timing

One of the most important aspects of music is WHEN to play notes, but standard MIDI protocol does not have a way specify when a noteOn or noteOff message should fire. All MIDI messages are interpreted as soon as they are received. Because of this, MIDI messages must be sent at the time they are to be played. This can be accomplished in Java by using the delay() function, or by using the built in Timer/TimerTask classes to create a scheduler. Examples of both of these solutions can be found in the GitHub Repo under the MIDI_Interface_Test folder. More information on sending MIDI messages to the orchestra can be found on the Software Basics page.

Arduino MIDI Documentation

https://github.com/FortySevenEffects/arduino_midi_library/