-
Using sliders to change time of opacity shifts
So I’m currently self learning expressions and a lot of what I’ve been able to pull off is by copy/pasting code and trying to modify it for my needs.
I have a pretty complex problem and have achieved results good enough for this one project but would love to create a template so I could repeat this easier in the future.
What is going on is I have 5 video layers. When triggered using a checkbox the top layer will shift from 100% opacity to 0%. The on and off times are determined with two sliders. I’m needing to change the “flicker” speed during the clip which is why I decided to build this all around sliders. I’ve built a ton of code into this thing and I’m really looking for 1 – a more elegant solution for this workflow and 2 – a code that won’t leave opacity gaps in the composition since the only way I could figure this out is by referencing previous frames which doesn’t always work when you shift the keyframes.
I know I probably haven’t included enough information but any leads/help would be greatly appreciated.Also, a disclaimer, I’m not 100% sure that all of this code is correct or even what a couple parts of it do.
//The code from the Main video layer named "PJ";
A = thisComp.layer("Master Controller").effect("Cycle in Seconds")("Slider");
B = thisComp.layer("Master Controller").effect("Frame Rate Adjusted")("Slider")*thisComp.frameDuration;((time-inPoint)%A <= B) ? 100 : ((thisComp.layer("Master Controller").effect("On / Off")("Checkbox")-1)*-100);
// This is the code from the video layers directly under "PJ";
frameRate = thisComp.layer("Master Controller").effect("Frame Rate")("Slider");
delay = (frameRate*(index-1))*thisComp.frameDuration;thisComp.layer("PJ").transform.opacity.valueAtTime(time-delay);
//This is the code from the main slider driving the rest of the expressions on layer "Master Controller";
cycleRate = effect("Cycle in Seconds")("Slider");
frameRate = effect("Frame Rate")("Slider");
frameDur = frameRate * thisComp.frameDuration;
nearKey = effect("Frame Rate")("Slider").nearestKey(time).index;
lastKey = (frameRate.key(nearKey).time>time) ? ((nearKey>1) ? nearKey-1 : nearKey) : nearKey;
prevKey = frameRate.key(lastKey).index-1;
FG = effect("ForeGround Layers")("Slider");
if
((frameRate.key(lastKey).index == frameRate.key(nearKey).index) && (time - frameRate.key(lastKey).time <= cycleRate) && (frameRate.key(prevKey).value > frameRate.key(lastKey).value)) //if lowering frame rate
{
frameRate.value;
thisComp.layer("PJ").transform.opacity.valueAtTime(time+(index-FG)) = 100;
thisComp.layer("Mike").transform.opacity.valueAtTime(time+(index-FG)) = 100;
thisComp.layer("Cody").transform.opacity.valueAtTime(time+(index-FG)) = 100;
thisComp.layer("Matt").transform.opacity.valueAtTime(time+(index-FG)) = 100;
thisComp.layer("Rob").transform.opacity.valueAtTime(time+(index-FG)) = 100;
}
else if
((frameRate.key(nearKey).time - time <= cycleRate) && (frameRate.key(nearKey).value < frameRate.key(lastKey).value)) // if raising frame rate
{
frameRate.value;thisComp.layer("PJ").transform.opacity.valueAtTime(time) = 100;
thisComp.layer("Mike").transform.opacity.valueAtTime(time+(index-FG)) = 100;
thisComp.layer("Cody").transform.opacity.valueAtTime(time+(index-FG)) = 100;
thisComp.layer("Matt").transform.opacity.valueAtTime(time+(index-FG)) = 100;
thisComp.layer("Rob").transform.opacity.valueAtTime(time+(index-FG)) = 100;
}
else {
frameRate.value;
}// There's a slider for ForeGround elements ( a couple scenes are green screened);
if (thisComp.layer("PJ").index == 1)
{
0;
}
else
{
thisComp.layer("PJ").index - 1;
}
Math.floor(value);//and this is the cycle expression that auto populates this slider based off of the comp;
(effect("Frame Rate")("Slider")*(index-1-effect("ForeGround Layers")("Slider")))*thisComp.frameDuration;