tldr: I need an expression that plays a sequence of images on a layer (and leave it on the last image) when the value of a key (keyframe?) in another layer of the same comp equals a specific value.
I am fairly new to AE and trying to port a project I made exclusively using Processing. Wrapping my head around how Expressions work is proving difficult, and I learn best by example, and am even finding it hard to piece together how to do this from what I've found online.
The situation and what I need:
I have imported key frames from a midi file (using this script) into a layer called "midi" and a layer that is an animation of frames . The idea is that if midi's effect ch_0_pitch has a value of, in this case, 36, that the frames in layer "ds_bass" animate when they come across one of these keys.
This is basically a "bass drum" animating on a "bass note" pitch. The midi file contains references to the entirety of drum midi needs (ie hi hat, snare, bass), each having a different pitch value. While I could simply render each individual "pitch" midi sequence to a midi file and import it as keys and then use a time remap expression to unpause and pause the animation on markers, which has worked, I need the capability to specify pitches for other instruments and run specific animations based on what pitch is being hit. As well, going through and adding a marker for each midi note is tedius and inaccurate (as there are very small differences visually between two keys with different values played synchronously, ie a bass hit and a hi hat hit).
I found something online that accomplished this at first, with markers, placed in TimeRemap of the ds_bass layer. I would go note by note in the midi and add markers to the ds_bass layer for this to work, and it perfectly paused and ran the animation when I needed it:
try {
m = thisLayer.marker.nearestKey(time);
linear(time, m.time, outPoint, 0, outPoint - m.time);
} catch (e) {
value
}
But seeing as I needed more to automate this process (this is a four minute piece with a lot of instrumentation and I'd like to be able to use this as a template for another project), I looked at the reference and other resources and the best I could come up with was something like this, which doesn't cause errors but also doesn't do anything (as well on TimeRemap of ds_bass layer in the same comp as midi):
try {
if (thisComp.layer("midi").effect("ch_0_pitch").nearestKey(value) == 36) {
m = thisComp.layer("midi").nearestKey(time);
linear(time, m.time, outPoint, 0, outPoint - m.time);
}
} catch (e) {
value
}
In Processing this was all handled with a switch in a method that brought in midi info on noteOn signals, and that checked for pitch values and ran methods based on pitch which ran sequences of images. Maybe I am going about this the wrong way, admittedly, as I am terribly new to AE, but this seems like it should be completely possible to automate all of this for very solid and automated timing mechanisms based directly off of the midi data.
Many of the other animations will be dependent on running a sequence based on pitch, in the sense of having a puppet that can animate ArmL to ArmLPlaySnare OR ArmLPlayHat - having a single "resting" frame that executes different animations (these are sets of 1-5 .pngs) dependent on midi pitch. Again, how it was managed in Processing.
If anyone can give some insight I would greatly appreciate it. I moved to AE as I found I'd need to render visuals in non-realtime (from midi data), and it seemed superior to learn AE as it has render capabilities that are more inline and intuitive with this project. At the moment I am stuck. Thanks for your time.
Edit - If I could simply copy the key frames I need to the ds_bass layer and then use the marker script (first above) with nearest key instead I figure it would work fine, though that's merely a more satisfactory convenience, not a proper fix. I'd still have to easily render dozens of midi files and do this for each. Best case scenario would be that I have one keyframed midi file with all channels in it (in my "master comp?") that can be referenced by the individual compositions. At the moment I'm putting instrument specific midi-keyed layers into each instrument specific comp.
Message was edited by: cheerbot: added references online to resources used