// Example on how to generate a Led effects on a Launchpad Mini MkIII from LoopToGo (from script button, script marker, etc)
//			It should be seen as a demo, not a perfect solution. 
//			The led effects are from the library LoopToGo\Libs\Novation\novationLaunchPadMiniLedEffects.ltgl
//			For now, this library is quite limited but will eventually grow. If you are interested to add your own effects to this library, please contact us
//			You should adapt it to your own needs and modify and/or cerate other Led Effects
//
// Arguments:  
//		arg1: step (quantization in bar)
//
// Author: LoopToGo
//
// Description: The script will run until it is manually stopped
//				Its an example on how to synchronize a led fx with the tempo.
//				The effect will be call once when the script is started and then, it will be called at each "step" bar
//


// We enable script concurrency because event can occur again even if the script has not completed!!!!
// Note the concurency mode is taken into account for Script marker and midi or keyboard triggered events. Not for Script button or running it manually from the Script manager.
setScriptConcurrencyMode 2			// ConcurrentScript = 0, DoNotStartScriptIfAlreadyRunning = 1, StopOtherScriptAndRun = 2 

alias aDevice LaunchPadMini		// Should be set to your own LaunchPad Mini MkIII mapped name (Preferences/MIDI)

loadScript LoopToGo\Libs\Novation\novationLaunchPadMiniLedEffects.ltgl


// $arg1 is the discreet bar at which we will start an action

if $arg1 > .01
	variable step $arg1
else
	variable step 1
endIf

//print Starts $scriptFileName step : $step

variable firstTime 1

variable color 34 + $songBar 1

while 1

	if $gCurrentMode = 0
		
		if $gLaunchPadCurrentPage = 3

			variable nextActionBar $songBar + $step $step
			
			print Waiting for $nextActionBar
			
			ifNot $firstTime			// We always do it the first time we call the script!
				waitTilSongBar $nextActionBar
			else
				variable firstTime 0
			endIf			
			
			//print Action $songBar $nextActionBar $songBar - $nextActionBar
			
			
			variable color $color + 1
			if $color > 127
				variable color 1
			endIf
			
			callFunction ledFxGrowFromCenter aDevice $step/$topNumber/8 $color 
			callFunction ledFxGrowFromContour aDevice $step/$topNumber/8 $color + 10
		else
		
			waitDelta .02
		 
		endIf
	else

		waitDelta .02
			
	endIf

endWhile


	

