// Library of Led Effects. This library will eventually includes more effects
/		
//
// Author: LoopToGo
//
// Contains the following functions  : 
//
//		ledFxOn //device [in] row [in] column [in] color [in]
//		ledFxOff // device [in] row [in] column [in] 
//		ledFxColumn // device [in] onOff [in] note [in] color [in]
//		ledFxRow // device [in] onOff [in] note [in] color [in]
//		ledFxRowColumn // device [in] onOff [in] note [in] color [in]
//		ledFxGrow2 // device [in] onOff [in] note [in] color  [in]
//		ledFxGrow3 // device [in] onOff [in] note [in] color  [in]
//		ledFxGrowFromCenter // device [in]  delay [in] color [in]
//		ledFxGrowFromContour // device [in]  delay [in] color [in]
//		ledFXCenteredSquare // device [in] onOff [in] squareNo [in] color  [in]



function ledFxOn //device [in] row [in] column [in] color [in]
	
	if $arg2 < 1
		exitFunction
	endIf
	if $arg3 < 1
		exitFunction
	endIf
	
	sendMidiNoteOn $arg1  $arg2*10 + $arg3 $arg4
endFunction

function ledFxOff // device [in] row [in] column [in] 

	if $arg2 < 1
		exitFunction
	endIf
	if $arg3 < 1
		exitFunction
	endIf

	sendMidiNoteOff $arg1  $arg2*10 + $arg3 
endFunction		

function ledFxColumn // device [in] onOff [in] note [in] color [in]
	variable note $arg3
	variable row $note/10 1
	variable column $note - $row*10
	
	//print ledFxColumn $arg1 $arg2 $arg3 $arg4
	
	if $arg2
		for row 1 8
			callFunction ledFxOn $arg1 $row $column $arg4
		endFor
		exitFunction
	else
		for row 1 8
			callFunction ledFxOff $arg1 $row $column  
		endFor
	endIf

endFunction

function ledFxRow // device [in] onOff [in] note [in] color [in]
	
	variable note $arg3
	variable row $note/10 1
	
	if $arg2
		for column 1 8
			callFunction ledFxOn  $arg1 $row $column $arg4
		endFor
		exitFunction
	else
		for column 1 8
			callFunction ledFxOff $arg1 $row $column  
		endFor
	endIf

endFunction
 
function ledFxRowColumn // device [in] onOff [in] note [in] color [in]
	callFunction ledFxRow $arg1 $arg2 $arg3 $arg4
	callFunction ledFxColumn $arg1 $arg2 $arg3 $arg4
endFunction

function ledFxGrow // device [in] onOff [in] note [in] color  [in]
	variable note $arg3
	variable row $note/10 1
	variable column $note - $row*10
	
	if $arg2
		for i 0 3
			callFunction ledFxOn $arg1 $row - $i $column - $i $arg4
			callFunction ledFxOn $arg1 $row - $i $column + $i $arg4
			callFunction ledFxOn $arg1 $row + $i $column + $i $arg4
			callFunction ledFxOn $arg1 $row + $i $column - $i $arg4
			waitDelta .015
		endFor
		exitFunction
	else
		for i 0 3
			callFunction ledFxOff $arg1 $row - $i $column - $i 
			callFunction ledFxOff $arg1 $row - $i $column + $i 
			callFunction ledFxOff $arg1 $row + $i $column + $i 
			callFunction ledFxOff $arg1 $row + $i $column - $i 
			waitDelta .015
		endFor
	endIf

endFunction

function ledFxGrow2 // device [in] onOff [in] note [in] color  [in]
	variable note $arg3
	variable row $note/10 1
	variable column $note - $row*10
	
	if $arg2
		for i 0 3
			variable color $arg4 + $i*10
			callFunction ledFxOn $arg1 $row - $i $column - $i $color
			callFunction ledFxOn $arg1 $row - $i $column + $i $color
			callFunction ledFxOn $arg1 $row + $i $column + $i $color
			callFunction ledFxOn $arg1 $row + $i $column - $i $color
			waitDelta .015
		endFor
		exitFunction
	else
		for i 0 3
			callFunction ledFxOff $arg1 $row - $i $column - $i 
			callFunction ledFxOff $arg1 $row - $i $column + $i 
			callFunction ledFxOff $arg1 $row + $i $column + $i 
			callFunction ledFxOff $arg1 $row + $i $column - $i 
			waitDelta .015
		endFor
	endIf

endFunction

function ledFxGrow3 // device [in] onOff [in] note [in] color  [in]
	variable note $arg3
	variable row $note/10 1
	variable column $note - $row*10
	
	if $arg2
		
		for i 0 2
			variable color $arg4 + $i*10
			
			for j 0-$i $i
				callFunction ledFxOn $arg1 $row - $i $column + $j $color
				callFunction ledFxOn $arg1 $row + $i $column + $j $color
			endFor	
			
			for j 1 - $i $i - 1
				callFunction ledFxOn $arg1 $row + $j $column - $i $color
				callFunction ledFxOn $arg1 $row + $j $column + $i $color
			endFor	
			
			
			waitDelta .015
		endFor
		exitFunction
	else
		for i 0 2
			for j 0-$i $i
				callFunction ledFxOff $arg1 $row - $i $column + $j 
				callFunction ledFxOff $arg1 $row + $i $column + $j 
			endFor	
			
			for j 1 - $i $i - 1
				callFunction ledFxOff $arg1 $row + $j $column - $i 
				callFunction ledFxOff $arg1 $row + $j $column + $i 
			endFor	
			waitDelta .015
		endFor
	endIf

endFunction

function ledFxGrowFromCenter // device [in]  delay [in] color [in]
		
	for sq 1 4
		callFunction ledFXCenteredSquare $arg1 1 $sq $arg3
		waitDelta $arg2
		callFunction ledFXCenteredSquare $arg1 0 $sq $arg3
		waitDelta $arg2
	endFor

endFunction

function ledFxGrowFromContour // device [in]  delay [in] color [in]
	
	for sq 1 4
		callFunction ledFXCenteredSquare $arg1 1 5 - $sq $arg3
		waitDelta $arg2
		callFunction ledFXCenteredSquare $arg1 0 5 - $sq $arg3
		waitDelta $arg2
	endFor

endFunction


function ledFXCenteredSquare // device [in] onOff [in] squareNo [in] color  [in]

	// squareNo must be 1, 2, 3 or 4. 1 is center, 4 is biggest square (contour)

	if $arg2
		
		for i 0 - $arg3 $arg3 -1
			for j 0 - $arg3 $arg3 -1
				callFunction ledFxOn $arg1 5 + $i 5 + $j $arg4
			endFor
		endFor
	
	else
	
		for i 0 - $arg3 $arg3 - 1
			for j 0 - $arg3 $arg3 -1
				callFunction ledFxOff $arg1 5 + $i 5 + $j 
			endFor
		endFor
	
	endIf

endFunction




