// Script to fade in LoopToGo main volume
// Arguments:
//		1 : Length of the fade in in bar. If not specified, default value is 1.  
//		2 : Step by bar. If not specified, default value is 5
//
// Author: LoopToGo

variable startBar $songBar

variable bar $startBar

variable volumeOri $mainVolume
variable volume $mainVolume

variable nbBarDefaultValue 1
variable nbChangePerBarDefaultValue 5

//print $arg1
//print $arg2

// Setting parameters values from arg or to default values
if $arg1
	variable nbBar $arg1
else
	variable nbBar $nbBarDefaultValue
endIf

if $arg2
	variable nbChangePerBar $arg2
else
	variable nbChangePerBar $nbChangePerBarDefaultValue
endIf

if $nbBar < 1
	print "ERROR: nbBar must be at least 1 bar! nbBar =" $nbBar. Will be set to $nbBarDefaultValue
	variable nbBar $nbBarDefaultValue
endIf
	
if $nbChangePerBar < 1
	print "ERROR: nbChangePerBar must be at least 1 step! nbChangePerBar =" $nbChangePerBar, Will be set to $nbChangePerBarDefaultValue
	variable nbChangePerBar $nbChangePerBarDefaultValue
endIf


//print $arg1 $nbBar
//print $arg2 $nbChangePerBar

//////

variable nbStep $nbBar*$nbChangePerBar

variable step 1/$nbChangePerBar

variable step 1/$nbChangePerBar
variable deltaVolume 1 - $volumeOri
variable deltaVolume $deltaVolume/$nbStep


while $bar < $startBar + $nbBar 
    
	//print songBar : $songBar
	
	variable volume $volume + $deltaVolume 
	
	setMainVolume $volume
	
	//print "Volume set to " $volume
	
	variable bar $bar + $step

	//print Aiming at $bar
 			
	waitTilSongBar $bar

endWhile

setMainVolume 1.0

//print End of script!










						 





