Skip to main content
Inspiring
November 30, 2025
Answered

multiple linear() expressions ?

  • November 30, 2025
  • 1 reply
  • 237 views

 

I'm trying to set multiple linear() ramps (in this case to set opacity) at various points in a song..

my expressions seem to be creating the arrays as expected... but I am not getting the expected results for the resulting post-expression graph... (see ALL CAPS section below)... it seems my if/elseif are just falling through to the else.. thus, setting the opacity to a constant value.

 

 

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
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]
}
else 
{
0
}

 

Correct answer Dan Ebberts

I think that last section needs to be more like this:

if(section_time_cumulative[0]<= time &&  section_time_cumulative[1]>time)
{
	linears[0]
}
else if(section_time_cumulative[1]<= time &&  section_time_cumulative[2]>time)
{
	linears[1]
}
else 
{
0
}

1 reply

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
December 1, 2025

I think that last section needs to be more like this:

if(section_time_cumulative[0]<= time &&  section_time_cumulative[1]>time)
{
	linears[0]
}
else if(section_time_cumulative[1]<= time &&  section_time_cumulative[2]>time)
{
	linears[1]
}
else 
{
0
}
Inspiring
December 1, 2025

Thx, @Dan Ebberts  - ... was so close!  Thx for finding my issue!

nishu_kush
Legend
December 1, 2025

Thanks for updating the thread. Feel free to reach out if there are any other questions.


Thanks,
Nishu