Min/Max value

Moderators: Disciple, zlovatt

Post Reply
hollow man
Posts: 4
Joined: March 8th, 2005, 6:13 am
Location: Switzerland

Hi all,

I've the scale of a layer animated with an audio expression.

I want to specify a minimum and maximum value.

How can I do that with this expression:

Code: Select all

temp = thisComp.layer("Amplitude audio").effect("Les deux couches")("Curseur");
[temp, temp]
Thanks :D
vidpat
Posts: 86
Joined: October 21st, 2004, 12:36 am
Location: Phoenix, AZ
Contact:

To make sure a value is within a certain range, you could use a conditional statement or a combination of the min() and max() functions. Any of the following approaches are equivalent.

Code: Select all

var temp = thisComp.layer("Amplitude audio").effect("Les deux couches")("Curseur");

var min = 0.2;
var max = 0.8;

// conditional statements
if (temp < min) {
    temp = min;
}
else if (temp > max) {
    temp = max;
}

//     or
// ternary operators
temp = ((temp < min) ? min : ((temp > max) ? max : temp));

//     or
// Math functions
temp = Math.min(Math.max(temp, min), max);

[temp, temp];

hollow man
Posts: 4
Joined: March 8th, 2005, 6:13 am
Location: Switzerland

Thanks a lot vidpat!

It works perfectly! :D
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

A couple of other things you might find useful. To clip the values to a certain range you can also use:

Code: Select all

var temp = thisComp.layer("Amplitude audio").effect("Les deux couches")("Curseur");
temp = clamp(temp, 0.2, 0.8);
[temp,temp];
But I usually use this linear expression alongside 'Convert Audio to Keyframes'. It provides a simple way of converting one range of values to another:

Code: Select all

var temp = thisComp.layer("Amplitude audio").effect("Les deux couches")("Curseur");
temp = linear(temp, 0, 10, 50, 100);
[temp,temp];
So that example would convert the audio values between 0 and 10 into scale values of 50 to 100.
Mylenium
Posts: 139
Joined: July 20th, 2005, 12:07 am

Paul Tuersley wrote:A couple of other things you might find useful. To clip the values to a certain range you can also use:

Code: Select all

var temp = thisComp.layer("Amplitude audio").effect("Les deux couches")("Curseur");
temp = clamp(temp, 0.2, 0.8);
[temp,temp];
But I usually use this linear expression alongside 'Convert Audio to Keyframes'. It provides a simple way of converting one range of values to another:

Code: Select all

var temp = thisComp.layer("Amplitude audio").effect("Les deux couches")("Curseur");
temp = linear(temp, 0, 10, 50, 100);
[temp,temp];
So that example would convert the audio values between 0 and 10 into scale values of 50 to 100.
Yepp, I'm definitely with you here. Conditional statemants are so *argh* for this type of stuff.

Mylenium
[Pour Mylène, ange sur terre]
byronnash
Posts: 321
Joined: July 7th, 2004, 2:30 pm
Location: Charlotte, NC
Contact:

Is there a way to scale the values instead of clipping them? Basically the equivalent of linear() but without any manual interaction.
Mylenium
Posts: 139
Joined: July 20th, 2005, 12:07 am

byronnash wrote:Is there a way to scale the values instead of clipping them? Basically the equivalent of linear() but without any manual interaction.
Mmh, not that I know of. But you could cycle thru all keys (while (time >= thisComp.duration){})and find the min/max values and then use them in your linear().

Mylenium
[Pour Mylène, ange sur terre]
Post Reply