Example on Youtube
Scripts: midi_piano.py & midi.py
Blender 2.49 file: midi_piano_test001.blend
Here is what I did.
Steps for the blender file:
- Create a new object for the white piano keys
- Edit the object until it looks like a piano key
- Duplicate the piano key object six times and align the objects
- Create a new object for the black piano keys
- Duplicate it four times and place the keys in the right position
- Edit the white keys so that the black & white keys don't overlap
- Make an armature with twelve bones and name the bones. Place the bones just behind the piano keys.
- Make the bones the parent of the corresponding piano key.
- Copy the armature and the piano keys to make a new octave
Steps for the scripts:
- Get midi.py (by Will Ware) for reading the midi file from:
- http://code.google.com/p/meaws/source/browse/trunk/data/midi.py?spec=svn2&r=2 - Midi tempo change added (detect a SET_TEMPO event while reading) to midi.py for calculating the frame
- New script file midi_piano with the class Piano
- The class uses an array that contains all the armatures for the octaves
- This class changes the bone rotation for the piano keys on the calculated frames.
midiBeat = float(midiTime) / float(ticksPerQuarterNote)
midiBeatTime = float(self.tempo) / 1000000.00 * midiBeat
frame = (midiBeatTime * self.fps) + 1 - The pitch is used to determine the right armature and bone
- Create a MidiFile object for reading a file
- Create a Piano object
- Pass the register_note method results to the Piano object
- Select, open, read & close the file
Update (2010-11-22):
I just found a very useful Blender script that can do all this and more.
You can find it at http://blenderartists.org/forum/showthread.php?t=195434 and http://blendit.xaa.pl/?p=middrv&l=eng. The creator of this script is working on a version for Blender 2.5.