1 of 12

MIDI for OpenFrameworks

Workshop by David Stein, July 25, 2020

2 of 12

What is MIDI?

Source: https://www.musicrepo.com/how-to-connect-midi-keyboard-to-computer/

Old method of connecting MIDI devices

Communication Protocol originally intended to connect musical instruments together (based on a published paper in 1981)

Originally limited to sets of unique cables connected between input and output ports. Today it is most commonly over USB cables.

Version 2.0 was just released (almost 40 years later!)

3 of 12

What is MIDI?

Source: https://www.musicrepo.com/how-to-connect-midi-keyboard-to-computer/

Old method of connecting MIDI devices.

Modern method is usually just a USB from a keyboard/controller to the computer

4 of 12

Limits of MIDI 1.0

  • 16 channels per Interface, one-way interfaces
  • 31250 bits per second SLOW!
  • Messages are generally very simply constructed 3-byte commands
  • Messages do not have time stamps and notes and activities are recorded at the time they arrive to a recording device.

Midi 2.0 was first researched in 2005 and was just released this year in 2020!

  • Bi-Directional, software can ask the devices what they are doing
  • More detailed data to allow instruments to be more expressive
  • Higher Speed
  • Prepares for instruments that have not been invented

5 of 12

Why MIDI for Creative Technology?

Create Music / Sounds

Create Visuals that interact with musical instruments

Take advantage of MIDI Controllers for interactive visuals

6 of 12

Midi Messages

Messages we will use today

Note On, pitch, velocity

Note Off, pitch

Control Change, control, value

7 of 12

Midi Interfaces

Windows & Mac have a concept of Midi Busses. Each Midi Bus can handle 16 seperate channels of Midi, generally each channel comes from a single hardware interface.

Music Software has the ability to connect into multiple busses

May need to setup a Midi Interface / Bus on your computer

Mac: Audio Midi Setup -> Window Menu -> Show Midi Studio

PC: Midi Setup in Control Panel?

8 of 12

Opening a connection to Midi Interface with Open Frameworks

  • List Output Interfaces: midiOut.listOutPorts();
  • Open port for Output: midiOut.openPort(1);

Similar for Input

  • List Input Interfaces: midiIn.listInPorts();
  • Open port for Input: midiIn.openPort(1);

9 of 12

Sending Midi Messages

  • If you don’t have a hardware synth to play music, you can open https://websynths.com/
  • Include ofxMidi.h in ofApp.cpp and ofApp.h
  • Open Output Port
  • Send note on, note off message:
    • midiOut.sendNoteOn(channelID,noteID, velocity);
    • midiOut.sendNoteOff(channelID,noteID);

10 of 12

Receiving Midi Messages

  • ofApp needs to inherit ofxMidiListener
    • class ofApp : public ofBaseApp, public ofxMidiListener {
  • Create message handler to receive messages
    • void ofApp::newMidiMessage(ofxMidiMessage& msg) {}
  • Write message to Error Output
    • Tips on Debugging different controllers
  • Data Structure to contain controller values
    • int knobs[8];
    • Note that in my demo, I did a Midi Out within the MidiMessage listener. This is not recommended. The MidiMessage listener should do simple quick routines, like copying data to variables or pushing message on stack to be processed later. More detailed routines should be called in the Update method to process the data.

11 of 12

Resources

12 of 12

Resources

If you want your code to play sound

  • Web based synth that uses Web Midi: http://websynths.com
  • To use OpenFrameworks to play Audio Samples:
  • To use OpenFrameworks for Audio Synthesis