A Look at the Project:
The MIDI Control Node has the following inputs to be set before anything else:
- Use Square Waveform (Boolean)
- Use MIDI Velocity (Boolean)
- Easing (Float)
- Offset (Integer)
Use Square Waveform will move the control empties to 1 when the note is on and 0 when the note is off, turning the note off just before the next Note-Off event – then leaving it off (0) until the next Note-On event. Turning this off means that the waveform forms a Bezier Curve between the Note-On and Note-Off events in the MIDI file. In the image above, square waveform has been used.
Use MIDI Velocity will take the velocity from the MIDI file to proportionally move the empty up to 1, if the velocity is 127, or 0.5 for velocity of 64, etc.
Easing value is in Frames and will slope the F-Curves so the controls don’t “jump” up and down but move smoothly. If you have many small notes close together, use a low easing value.
Offset value is the start frame for the animation and placement of the sound file in the blend file. The value is in Frames, so a value of 21 starts the animation at frame 21.
The process is therefore, after you have chosen the active layer(s) for the controls:
- Set the four inputs above.
- Click “Load MIDI CSV File”.
- Click “Load Sound File for MIDI File”.
- Click “Create MIDI Controls on Active Layer(s)”.
The “Load MIDI CSV File” will prompt you for the MIDI CSV file on your disc. You will then see the controls – a row for each channel of the MIDI file, one for each note played, all labelled appropriately.
The “Load Sound File for MIDI File” button will load the sound file you chose into the VSE at the start frame set by the Offset value.
The last button “Reset Node for New CSV File” will reset all the values on the node and remove all node variables, meaning you can start from scratch with a new setup.
Note: This is a single use node, use it once only to build the controls.
The MIDI Index Node has two inputs:
- Controls Group (String).
- Keys Group (String).
Into the first input should be entered the name of the Controls Group, this is assigned by the previous node and is based upon the MIDI Channel Name. For multi channel projects you must repeat this node for each channel.
Into the second input should be entered the name of the Meshes Group that you want the controls to control. There should be at least as many separate objects as there are notes played in the MIDI channel you are working on, or you get an error.
The groups have to be typed in correctly, rather than using input sockets, owing to some procedural limitations within the AN system.
A Look at the Project:
Here you can see the keys meshes, there are 88 of them and their origins are at the centre of rotation of a piano key. The naming convention is important so the system can assign keys to controls. Each key should be named by its note ident followed by an underscore, then anything else you would like. So in the picture above they are named, for example, c3_key, c3s_key, etc. It is not important what order you made the meshes in, or what order they are in the blend file, the node works out which control relates to which key and gives it an index value displayed in the Viewer Node next to the Index Node.
This Index is then used in your animation to link movements of the controls in Z axis to, for example rotations of the meshes in the X axis. This page will not explain how that is done, but you would use a Loop Sub-Programme Node Set. Once complete, the meshes will react to the note events in the MIDI file, controlled by their empties.
The node has two outputs – a Text List listing the notes played and an Integer List giving the index for each note played against the key to be used. These are to be fed into your animation node tree set.
The MIDI Bake To Curve Node has the following inputs:
- MIDI Channel Number (Integer).
- Use Square Waveform (Boolean).
- Easing (Float).
- Offset (Integer).
- Spacing (Integer).
- Keys Group (String).
MIDI Channel Number is the channel from the MIDI file that you want to process. This node does one channel only so you repeat it for each channel in the MIDI file that you want to animate.
This node tree has 8 MIDI channels fed into 6 Loop Sub-Programmes and some other bits as well! It still runs at under 2.8ms on my Mac.
Use Square Waveform will set the f-curve to 1 when the note is on and 0 when the note is off, turning the note off just before the next Note-Off event – then leaving it off (0) until the next Note-On event. Turning this off means that the waveform forms a Bezier Curve between the Note-On and Note-Off events in the MIDI file. In the image above, square waveform has been used.
Use MIDI Velocity will take the velocity from the MIDI file to proportionally move the empty up to 1, if the velocity is 127, or 0.5 for velocity of 64, etc.
Easing value is in Frames and will slope the F-Curves so the controls don’t “jump” up and down but move smoothly. If you have many small notes close together, use a low easing value.
Offset value is the start frame for the animation and placement of the sound file in the blend file. The value is in Frames, so a value of 21 starts the animation at frame 21.
Spacing value is in frames and denote a minimum separation between consecutive notes played on the same note, so the key will actually move if you pressed your piano key twice without a noticeable gap between note-off and next note-on.
Into the final input should be entered the name of the Key Meshes Group that you want the node to control. There should be at least as many separate objects as there are notes played in the MIDI channel you are working on, or you get an error. The same rules apply to these meshes as to those used in the Index Node above, just to save me repeating myself here 🙂
Once all these inputs are completed simply click the “Select MIDI CSV & Bake Midi” button to complete the process, this will prompt you for the MIDI CSV file on your disc. It is not necessary to have the meshes group assigned, but of course you will need to process the node again by clicking this button, if you add the Keys Group at a later stage. Once complete, the node will display information gathered from the MIDI file, such as the number of unique notes played, total note events, etc.
A Look at the Project:
This shows that the node has just processed “entertainer-new” CSV file.
The node has the following outputs:
- Notes Played (Text List).
- Note Curve Values (Double List).
- Keys Indices (Integer List).
- Beats Per Minute (Integer).
- Time Sig Numerator (Integer).
- Time Sig Denominator (Integer).
- Animation Offset Frame (Integer).
Most are self explanatory (I hope) the most important ones are the Note Curve Values and the Key Indices. The Note Curve Values outputs at each frame the value of each stored curve for all the notes played in the MIDI file’s chosen channel. So as the animation runs the values here will represent whether a note is “on” or “off”, or some way in between the two. So you feed these into a Loop Sub-Programme as the iterator and the Keys Indices as a parameter, using the Loop Index to get the index number of the key to be activated by each note curve.
The “Load Sound File for MIDI File” button will load the sound file you chose into the VSE at the start frame set by the Offset value, the same as the MIDI Control Node.
This node, like all three nodes described here, does not run the MIDI read, evaluate, bake functions unless you click the appropriate button, so is not using compute resources when you run your animation. It does however output the notes’ F-Curve values as you run the timeline. This keeps the compute resources for all these nodes down to an absolute minimum.
Typical Setup For The Bake Node
This image shows a typical node setup to drive meshes from the baked MIDI file:
I simply use a loop sub-programme to get the value from the curves (the Iterator), which I plug into the mesh object. this mesh object is obtained by reading the Index feed to show which note curve corresponds to which mesh. The meshes are obtained by using their group name as the list input. The Rotate value is the amount in degrees that I want the key to rotate. If you look closely you will see that I have set “AV-Sync” at the bottom, so Blender syncs the replay (ALT+A) to the sound file, this is not needed if you render the animation, only for preview Play mode.
Here is a short video made using the MIDI nodes:
This is the node tree:
NOT FINISHED YET 😛