FORUMS: list search recent posts

Randomize, hold value, then randomize again

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Madison Bullard
Randomize, hold value, then randomize again
on Mar 8, 2013 at 11:31:52 pm

I'm working on a project in which most of the expressions in my comp refer back to amplitude keyframes from Sound Keys. (intense bass shakes the screen, a snare drum creates a flash, etc) At one point, I need the tint to change to a random value each time a chord is struck, and remain the same color for the duration of the chord. Each chord is held about 3 seconds.

I have tried writing expressions using seedRandom() that quickly cycle through a bunch of random tints while the chord is silent, and then stops on one random tint while the chord sounds, before returning to a rapid random cycle after the chord decays. I haven't been able to get that to work without using while() statements, but the duration of the comp is long enough so that while() statements aren't an option because they bog down the render speed or crash AE.

Any help pointing me in the right direction would be greatly appreciated. I'm still pretty new to expressions, so pardon me if I'm overlooking a very simple solution.

Thanks!


Return to posts index

Dan Ebberts
Re: Randomize, hold value, then randomize again
on Mar 9, 2013 at 12:56:50 am

This thread discusses something very similar:

http://forums.creativecow.net/readpost/227/23414

except that it uses the keyframes from Convert Audio to Keyframes, but you should be able to make it work with Sound Keys.

Dan



Return to posts index

Madison Bullard
Re: Randomize, hold value, then randomize again
on Mar 9, 2013 at 5:01:16 am

HI Dan, thanks for the reply.

I tried plugging in that expression and adjusting it as needed, but kept getting the same error I was getting when I was attempting to write other expressions with loops:

"timeout while waiting for the engine"

I have 16gb of RAM, so I find it hard to believe that its a memory issue, but maybe there are config settings I haven't taken into account. Any other ideas? I know the expression is a bit complex but aside from that there is barely any render-intensive material in the comp. Really just one layer with a lightweight instance of Particular (never more than 300 particles visible at once).

Really appreciate the help!

The expression I used is below

pulse = (comp("soundkeys").layer("bridge amp").effect("Both Channels")("Slider"));

threshold = 15.0;
above = false;
frame = timeToFrames(time);
while (true){
t = framesToTime(frame);
if (above){
if (pulse.valueAtTime(t) &lt; threshold){
frame++;
break;
}
}else if (pulse.valueAtTime(t) >= threshold){
above = true;
}
if (frame == 0){
break;
}
frame--
}
seedRandom(frame,true);
random([0,0,0,1],[1,1,1,1])


Return to posts index


Dan Ebberts
Re: Randomize, hold value, then randomize again
on Mar 9, 2013 at 5:30:57 am

Is there a long time between beats? Try this small adjustment and see if it makes any difference:


pulse = (comp("soundkeys").layer("bridge amp").effect("Both Channels")("Slider"));
threshold = 15.0;
above = false;
frame = timeToFrames(time);
while (frame >= 0){
t = framesToTime(frame);
if (above){
if (pulse.valueAtTime(t) < threshold){
frame++;
break;
}
}else if (pulse.valueAtTime(t) >= threshold){
above = true;
}
frame--
}
seedRandom(frame,true);
random([0,0,0,1],[1,1,1,1])


Dan



Return to posts index

Madison Bullard
Re: Randomize, hold value, then randomize again
on Mar 10, 2013 at 12:42:55 am

That expression seemed to get me further than before, as the error I got this time was "expression result must be of dimension 1, not 4", which makes since because I'm applying the expression to the Hue on the "Color Balance (HLS)" effect, which is 1 dimension. When I corrected that by changing the last line to random(359), the expression made AE hang for about 1.5 minutes before giving me the "timeout while waiting for the engine" message.

I want to think all of this hanging has to do with the while() function, but perhaps my low disk space has something to do with it (I have <10gb on my AE drive). Do you think moving my media cache to a different drive might help?

Also, to answer your question from your last post, there are approximately 2 seconds between each "beat", which might more accurately be called a trigger point. The color-change trigger should actually fall every 4 beats, but thats kinda irrelevant. I would just time the random color change to align with every 4 beats except that I want this project to be a skeleton that I can use to make other music videos in the future, so an all-sound-reactive project is important.


Return to posts index

Dan Ebberts
Re: Randomize, hold value, then randomize again
on Mar 10, 2013 at 1:04:24 am

The expression goes back in time, from the current frame, frame by frame, until it finds a frame where the value went from below the threshold to above the threshold. If that event doesn't occur for a long time, I suppose the engine would time out. Two seconds between beats shouldn't be a problem though.

I don't think it's a memory issue. Hard to diagnose from a distance...

Dan



Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]