// Set Of Utilities Functions for Arturia Keylab mkII  		
//
// Author: LoopToGo
//
// To use: include the following in your script:
//		loadScript LoopToGo\libs\arturiaKeylabMKIIUtilities.ltgl

skipIfAlreadyLoaded // This command will make sure this script (library) is only loaded once when a child script try to load it after its parent script loaded it

// Function to set pad color, note : arguments must be specified as decimal values
function setPadColor // device [in] padNumber [in] red [in] green [in] blue [in] 

	if $nbArgs = 5
		variable device $arg1
		variable padNumber $arg2 - 1
		variable red $arg3
		variable green $arg4
		variable blue $arg5		
		
		convertDecimalsToHex hexPadNumber $padNumber + 112 // 112 = 0xF0
		convertDecimalsToHex hexColor $red & " " & $green & " " & $blue
		
		//print hexPadNumber : $hexPadNumber [ $padNumber + 112 ]
		//print hexColor : $hexColor [ $red & " " & $green & " " & $blue ]
		
		sendMidiRawBytes $device "F0 00 20 6B 7F 42 02 00 16 " & $hexPadNumber & " " & $hexColor & " F7"
		
	else
		print "setPadColor: wrong number of args!"
	endIf

endFunction