Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Multiple linear() in an expression

  • Multiple linear() in an expression

    Posted by Martin Schmid on December 1, 2025 at 10:37 am

    I’m trying to have multiple linear() ramps defining a value at different times…

     

    My arrays seem to be all being defined correctly… however, when I try to conditionally set the ram (see note in all caps below), I’m not getting the expected results… what am I doing wrong?

     

     

     

    beats_per_min = 104

    sec_per_min = 60

    beats_per_bar = 4

    seconds_per_beat = sec_per_min / beats_per_min

    section_bars = [0,2,8,8,4,8,2,8,4,8,2,8,8,9,8];

    // set the bar number at the end of each section

    section_bars_cum = new Array(section_bars.length)

    section_bars_cum[0]=0

    for(arrIndex = 0 ; arrIndex< section_bars.length-1; arrIndex++)

    {

    section_bars_cum[arrIndex+1]= section_bars_cum[arrIndex]+section_bars[arrIndex+1]

    }

    // set the time(in sec) at the end of each section

    section_time_cumulative = new Array(section_bars.length)

    for(arrIndex = 0 ; arrIndex< section_time_cumulative.length; arrIndex++)

    {

    section_time_cumulative[arrIndex]= section_bars_cum[arrIndex] * beats_per_bar * seconds_per_beat

    }

    // compute each linear()

    var linears = new Array(section_bars.length)

    for(arrIndex = 0 ; arrIndex< section_bars.length-1; arrIndex++)

    {

    linears[arrIndex]= linear(time, section_time_cumulative[arrIndex], section_time_cumulative[arrIndex+1],100,0)

    }

     

    /// THIS IS WHERE I AM HAVING ISSUE

    // try to aggregate all the linear()

    if(section_time_cumulative[0]>= time && section_time_cumulative[1]<=time)

    {

    linears[1]

    }

    else if(section_time_cumulative[1]>= time && section_time_cumulative[2]<=time)

    {

    linears[2]

    }

     

    Yoan Boisjoli replied 5 months, 1 week ago 2 Members · 1 Reply
  • 1 Reply
  • Yoan Boisjoli

    December 2, 2025 at 3:47 am

    Hi Martin!
    I might be wrong since I haven’t tested your setup directly, but I think the core issue is that linears[] isn’t a function. When you do:

    linears[i] = linear(time, t0, t1, 100, 0);

    linear() is evaluated immediately, so each linears[i] just stores a number for the current frame. There’s nothing to “call” later.

    Your range checks also look inverted. You probably want:

    if (time >= t0 && time < t1)

    instead of

    t0 >= time && t1 <= time

    A simple pattern that might solve it is to calculate the ramp only for the active section:

    for (i = 0; i < section_time_cumulative.length - 1; i++){
    t0 = section_time_cumulative[i];
    t1 = section_time_cumulative[i+1];
    if (time >= t0 && time < t1){
    value = linear(time, t0, t1, 100, 0);
    break;
    }
    }
    value;

    Hopefully that points you in the right direction.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy