Introduction
{photo href=’http://www.flickr.com/photos/chancesend/353444194/’ title=’The touch of a hand’ src=’http://farm1.static.flickr.com/133/353444194_6b4b2a5972_m.jpg’ width=’240′ caption=’Screenshot of Midi2OpenGL’}This program was designed as a demonstration of how to integrate {extlink href=”http://www-2.cs.cmu.edu/%7emusic/portmusic/” linktext=”PortMIDI”} with {extlink href=”http://www.opengl.org/” linktext=”OpenGL”} 3D visualizations. It takes MIDI input from the default MIDI Input port, outputs that data to the default MIDI output, and translates the note and controller data into various OpenGL parameters. It serves as an example for implementing PortMIDI, and basic OpenGL concepts such as GLU Quadrics and lighting. The OpenGL code is heavily referenced from the great tutorials at {extlink href=”http://nehe.gamedev.net/” linktext=”NeHe Productions”}.
The APIs implemented are as follows:
- {extlink href=”http://www-2.cs.cmu.edu/%7emusic/portmusic/” linktext=”PortMIDI”}
- {extlink href=”http://www.opengl.org/” linktext=”OpenGL”}
Parameter Implementation
The program was designed to be used with an Oxygen8 keyboard controller, so the notes and parameters used are as follows:
Note C2 .. C4 | Individual size of corresponding sphere |
Controller | |
1
|
X-coord of spotlight |
7
|
Y-coord of spotlight |
11
|
Diffuse light: Red value |
12
|
Diffuse light: Green value |
13
|
Diffuse light: Blue value |
15
|
Ambient light: Red value |
16
|
Ambient light: Green value |
17
|
Ambient light: Blue value |
For Oxygen8 users, these parameters correspond to the Modulation wheel, the data slider, and the 3 right-most rotary knobs in both rows.
To Use
{photo href=’http://www.flickr.com/photos/chancesend/353444209/’ title=’The touch of a hand’ src=’http://farm1.static.flickr.com/128/353444209_5e1b081af2_m.jpg’ width=’240′ caption=’Screenshot of Midi2OpenGL’}Run midi2opengl.exe . The program relies on your default MIDI input and output ports being the ones you intend for input and output, so other setups will require re-coding in the openMidi function. To trigger the spheres, press C2 .. C4 on your MIDI input controller. The lighting characteristics are modified by the controller parameters listed above.
As this is only a quick technology/interfacing demo, some re-coding might be necessary for this to run on your machine. As every MIDI I/O situation is different, you MAY need to change the IN and OUT parameters in openMidi to suit your specific setup. Run the test application packaged with PortMidi to determine the proper parameters to use with your system.
IMPORTANT NOTE! This program does not use threads for video and MIDI updates, and instead runs in an endless loop. Though this makes the code easy to read, it has the side effect of maxing your CPU at 100% usage. Take note of this fact when running the program – it won't harm your computer, but it will heat up the processor quickly!
Requirements
A PC running Windows 98+, a sound card or external audio device with MIDI inputs and outputs
Download
- midi2opengl (application + source)
Links
- {extlink href=”http://www-2.cs.cmu.edu/%7emusic/portmusic/” linktext=”PortMIDI”}
- {extlink href=”http://www.opengl.org/” linktext=”OpenGL”}
- {extlink href=”http://nehe.gamedev.net/” linktext=”NeHe Productions” title=”OpenGL Tutorials”}
To Do
- Change OpenGL and MIDI polling to thread-based, to prevent maxing out the processor
- Add support for non-default MIDI devices
- Add support for more MIDI parameters: OpenGL rotation control, others(?)
- Change graphics to a time-based 3D "piano roll" that handles all note values