For my project, I decided to put together a virtual piano that would be able to read in MIDI files and animate them playing along with sound on a 3D piano.
The plan was to...
1)Get a 3d model of some piano keys
2)Enable clicking on those keys (i.e., click a note and the sound for that note plays while the key animates being pressed)
3)Enable loading in of a MIDI file and performance of said MIDI file on the Virtual Piano.
4)Complete steps 1-3 before the deadline.
I would have to say that this project was a success, since all of those steps were pretty much completed.
My program will do all of those things, the only issues are with the MIDI files. Timing problems arise with MIDI files
with multiple tracks. Also, some MIDI files with multiple tracks will not load.
A bit about how I did it:
Well, the graphics are created using OpenGL. I made all of the keys by drawing polygons for each face of each key.
For picking the notes that are clicked on, I used a technique described on an OpenGL picking tutorial I found online
(all links will come at the end of this paragraph). I render the scene to the back buffer, assigning
each key a unique color. I then get the coordinates of the mouse click and check the color of the pixel at that
spot. That tells me which key is being pressed, if any. For parsing the MIDI files, I used a .dll designed for that purpose.
For playing MIDI I used the windows MIDI stream api. I found both a tutorial I found online and microsoft's msdn helpful.
I needed the MIDI stream api because I needed to be notified whenever a note was played. I tried DirectMusic, but it won't
tell you when a note is played. There are other high-level api's that also lack this, but the MIDI stream api allowed me
to have each note call a callback to let me know when it's played.
Freaking helpful links:
OpenGL picking using Color and the back buffer
MIDI file parsing
MIDI stream api reference
MIDI stream api at msdn