Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

URGENT - AE - Can you limit a range of values within which to apply an expression?

New Here ,
Sep 22, 2018 Sep 22, 2018

I'm trying to link up opacity and audio keyframes - this is where I'm at:

thisComp.layer("Audio Amplitude").effect("Both Channels")("Slider")

(I used pickwhip to connect opacity to the slider for "Both channels")

However, I want to define the audio range, but I have no idea where/how to insert that into the code.

I do know that I want everything within that certain range to be at 100% opacity, and everything outside of the range to be at 0%

Any help is much appreciated!!

8.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Sep 23, 2018 Sep 23, 2018

Let me help you understand the Interpolation methods from the Expression Language menu. You should explore all of the various methods in the menu and become familiar with how they work and the way they are written.

There are linear and ease methods. The method defines what you are going to do. Inside the method, there is the operator (linear), a variable (tMin and tMax) and the output (value1 and value2). Here's the linear method as written automatically from the expression language menu:

linear(t

...
Translate
Community Expert ,
Sep 22, 2018 Sep 22, 2018

You could remap the audio range using linear():

a = thisComp.layer("Audio Amplitude").effect("Both Channels")("Slider");

minAmp = 0; //minimum audio amplititude

maxAmp = 50; //maximum audio amplitude

maxOpacity = 70; //minimum scale

minOpacity = 0; //maximum scale

value + linear (audioLev, minAmp, maxAmp, maxOpacity, minOpacity)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 22, 2018 Sep 22, 2018

Thank you!

when I plug it in like this, I get the error message though! did I do something wrong?

Screen Shot 2018-09-22 at 10.53.45 PM.jpg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 23, 2018 Sep 23, 2018

Rename variable a to audioLev.

Mylenium

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 23, 2018 Sep 23, 2018
LATEST

Let me help you understand the Interpolation methods from the Expression Language menu. You should explore all of the various methods in the menu and become familiar with how they work and the way they are written.

There are linear and ease methods. The method defines what you are going to do. Inside the method, there is the operator (linear), a variable (tMin and tMax) and the output (value1 and value2). Here's the linear method as written automatically from the expression language menu:

linear(t, tmin, tmax, value1, value2)

The Operator is linear and that means that there is a direct ratio established. If the Operator was set to ease or easeIn or easeOut the graph of the function would be a curve.

"t" would be the value you are getting from the Both Channels keyframes that were generated when you used the keyframe assistant to analyze the audio. "tMin" and "tMax" are the minimum and maximum values of the keyframes. These are very easy to see if you just open up the Graph Editor and you look at the value curve. That's how you decide what values to use for the variables.

This is the graph editor of a sample audio file. It is easy to see what values you have to work with by simply hovering over a keyframe. In this example, the audio ranges from a high of 2.5 units:

Screenshot_2018-09-23 03.05.54_3Vmifv.png

to an average low of about .35:

Screenshot_2018-09-23 03.09.19_fwKYaZ.png

I want my new values to start as soon as the audio starts to rise from the average low point and end when I get about 80% of the way to the loudest values so I make note of the high and low values.

It is a good idea to do as little typing as possible writing expressions because it eliminates the possibility of typo's. Start the expression by first defining the variable by typing "t = " and then using the pickwhip to point to the Both Channels parameter. Now the value of for "t" is defined.

An apostrophe and a return end the definition of the variable so all that is left is to load the full linear method from the Interpolation menu;

Screenshot_2018-09-23 03.15.18_Wqoedx.png

and fill in some values.

The final expression looks like this:

t = thisComp.layer("Audio Amplitude").effect("Both Channels")("Slider");

linear(t, .35, 2.2, 0, 100)

There is almost no typing, no errors and when the Both Channels value is below .35 the opacity output from the Linear method will be zero and when the value of t (Both Channels) rises to 2.2 the output value of the linear method will be 100. Since opacity has only a single value I'm done.

That's basically the same thing that Oussk gave you but with a lot less typing and a much lower chance of errors.

If you wanted to apply this to something like the Y scale of a layer and have it change from 25% to 100% you would define a value for y and put it in an array so using the same logic you just do a little more typing and end up with this:

t = thisComp.layer("Audio Amplitude").effect("Both Channels")("Slider");

y = linear(t, .35, 2.2, 25, 100);

[100, y]

Now the scale value for X would always be 100% and the Y value would change from 25% to 100%.

A couple of hours just reading the Expression Language section of the help files and learning how to use the Expression Language Menu with as little retyping as possible is going to save you a lot of time fiddling around with expressions.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines