//-----------------------------------------------------------------------------
//-------- Copyright (c)2003-2016. All Rights Reserved. -----------------------
//-----------------------------------------------------------------------------
// file implementing MIDI controller 'DENON DJ MCX8000'
// last revision: 2019-01-10
//Author: Tollen Francisco
//
//----------------------------------------------------------------------------- 
function getLanguageVersion()
{
	return 1;// do not modify this, this should be 1 for all scripts
}
//----------------------------------------------------------------------------- 
function getFileVersion()
{
	return 1;// update this as needed
}
//----------------------------------------------------------------------------- 
// return a user friendly name for the controller supported
function getControllerUserFriendlyName()
{
	return "Denon MCX8000";
}
//----------------------------------------------------------------------------- 
// return the communication type that the controller supports 
// this can be either 'midi' or 'hid' (please return only one of them in case the controller supports both)
function getControllerType()
{
	return 'midi';
}
//----------------------------------------------------------------------------- 
//----------------------------------------------------------------------------- 
//----------------------------------------------------------------------------- 
// preferred way to identify the controller (using the USB device VID and PID -- vendor and product id)
// return false if the controller does not support this kind of identification
// osId -- 0 Windows; 1 MacOSX; 2 Linux; -1 unknown
function getSupportedHidDeviceVID(osId)
{
	return false;
}
//----------------------------------------------------------------------------- 
function getSupportedHidDevicePID(osId)
{
	return false;
}
//----------------------------------------------------------------------------- 
// this is NOT the preferred way to identify the controller but you should use
// it if the controller does not support standard USB VID and PID identification
// return false if the controller does not support this kind of identification
// osId -- 0 Windows; 1 MacOSX; 2 Linux; -1 unknown
function getSupportedHidDeviceName(osId)
{
	return false;
}
//----------------------------------------------------------------------------- 
//----------------------------------------------------------------------------- 
//----------------------------------------------------------------------------- 
// preferred way to identify the controller (using the USB device VID and PID -- vendor and product id)
// return false if the controller does not support this kind of identification
// osId -- 0 Windows; 1 MacOSX; 2 Linux; -1 unknown
function getSupportedMidiDeviceVID(osId)
{	
	return 0x15E4;
}
//----------------------------------------------------------------------------- 
function getSupportedMidiDevicePID(osId)
{	
	return 0x8002;	
}
//----------------------------------------------------------------------------- 
// preferred way to identify the controller (if it supports MIDI SysEx)
// return false if the controller does not support this kind of identification
function getSupportedMidiSysExIdString(osId)
{
	// sysex response to 'F0 7E 7F 06 01 F7' (identification request sysex)
	// please note that the response contains 5 bytes in hex format containing
	// the Manufacturer ID (3 bytes) and Model Number (2 bytes)
	// ATTN: the returned value should omit the standard 'F0 7E 00 06 02' message start
	//return '00 01 3F 37 00 19 00 01 00 04 00 7F 7F 7F 7F 4E 31 31 38 30 36 31 38 36 39 30 38 39 34 30 00 F7'; //very long sysex id
	return '00013F37001900010004007F7F7F7F4E313138303631383639303839343000F7'; //very long sysex id
	
}
//----------------------------------------------------------------------------- 
// this is NOT the preferred way to identify the controller but you should use
// it if the controller does not support standard MIDI SysEx identification
// return false if the controller does not support this kind of identification
// osId -- 0 Windows; 1 MacOSX; 2 Linux; -1 unknown
function getSupportedMidiDeviceNameForInput(osId)
{
	return "DENON DJ MCX8000";
	//return false;
}
//----------------------------------------------------------------------------- 
function getSupportedMidiDeviceNameForOutput(osId)
{
	return "DENON DJ MCX8000";
	//return false;
}
//----------------------------------------------------------------------------- 
//----------------------------------------------------------------------------- 
// some variables necessary only for this particular script
var color_pad_cuepoint_on 	= 0x04;
var color_pad_cuepoint_off 	= 0x02;

var color_pad_looppoint_on 	= 0x0D;
var color_pad_looppoint_off = 0x02;

var color_pad_autoloop_on 	= 0x3D;
var color_pad_autoloop_off	= 0x02;

var color_pad_sample_on 	= 0x35;
var color_pad_sample_off 	= 0x02;



var shiftButton				=[0,0,0,0];
var samplerBlinkLedStatus   =[0,0,0,0];
var jogWheelsInScratchMode	=[0,0,0,0];
var vuLED                   =[0,0,0,0];

var fxEcho = [0,0,0,0];
var fxFlanger = [0,0,0,0];
var fxBeatwaw = [0,0,0,0];

var fxKnobCurrentValue = 0;

var autoLoopLEDState = [0,0,0,0];

var padMode = [0,0,0,0];
// 1 = cue points, 2 = loop points, 3 = auto loop, 4 = sampler

var deckState = [1,1,0,0];

var deckChaseCurrentLED = 0x00;

var padLEDState = [
					[
						[0,0,0,0,0,0,0,0], //cue points 	i=0
						[0,0,0,0,0,0,0,0], //loop points 	i=1
						[0,0,0,0,0,0,0,0], //auto loop 		i=2
						[0,0,0,0,0,0,0,0]  //sampler 		i=3
					],//channel 1 i=0
					[
						[0,0,0,0,0,0,0,0], //cue points 	i=0
						[0,0,0,0,0,0,0,0], //loop points 	i=1
						[0,0,0,0,0,0,0,0], //auto loop 		i=2
						[0,0,0,0,0,0,0,0]  //sampler 		i=3
					],//channel 2 i=1
					[
						[0,0,0,0,0,0,0,0], //cue points 	i=0
						[0,0,0,0,0,0,0,0], //loop points 	i=1
						[0,0,0,0,0,0,0,0], //auto loop 		i=2
						[0,0,0,0,0,0,0,0]  //sampler 		i=3
					],//channel 3 i=2
					[
						[0,0,0,0,0,0,0,0], //cue points 	i=0
						[0,0,0,0,0,0,0,0], //loop points 	i=1
						[0,0,0,0,0,0,0,0], //auto loop 		i=2
						[0,0,0,0,0,0,0,0]  //sampler 		i=3
					]//channel 4 i=3
				   ];

//----------------------------------------------------------------------------- 
// this is called when the controller is initialized and the control is passed to this script
// use this to initialize any variables you might need, the controller' leds, etc
// uniqueId is a unique integer between 0..15 that is guaranteed not to change for 
// a certain opened controller -- please note that there can be many controllers
// of the same type in use at the same time ! Use uniqueId to identify between them
function controllerInit(uniqueId)
{
	callSendAllNotifications(uniqueId, true);// send all notifications to the controller (so that we don't have to manually init all leds/lcd screens)
	sendMidi(uniqueId,0x90,0,0x08,0x7F); //set deck to 1
	sendMidi(uniqueId,0x90,1,0x08,0x7F); //set deck to 2
	
	//disable fx 2 and 3 on/off and select. These are not supported.
	sendMidi(uniqueId,0x90,8,0x01,0x00); 
	sendMidi(uniqueId,0x90,9,0x01,0x00);
	
	sendMidi(uniqueId,0x90,8,0x02,0x00);
	sendMidi(uniqueId,0x90,9,0x02,0x00);
	
	sendMidi(uniqueId,0x90,8,0x0C,0x00); 
	sendMidi(uniqueId,0x90,9,0x0C,0x00);
	
	sendMidi(uniqueId,0x90,8,0x0D,0x00);
	sendMidi(uniqueId,0x90,9,0x0D,0x00);
	
	for (var x = 4; x<=7; x++){
		sendMidi(uniqueId,0x90,x,0x00,0x7F); //set each deck to cuepoint pad mode.
		sendMidi(uniqueId,0x90,x - 4,0x07,0x01); //vinyl led
		updatePadModeLEDs(uniqueId, x - 4, 0);
	}
	
	
	
		
	call('sleep', 10);// delay for 10ms to allow the MIDI out buffer to flush
	
}
//----------------------------------------------------------------------------- 
// called just before the controller will be deinitialized and the control will go away from the script
// use to power off any powered leds, etc
function controllerDeinit(uniqueId)
{
	callSendAllNotifications(uniqueId, false);// send all notifications to the controller (so that we don't have to manually init all leds/lcd screens)
	sendMidi(uniqueId,0x90,0,0x08,0x7F); //set deck to 1
	sendMidi(uniqueId,0x90,1,0x08,0x7F); //set deck to 2
	
	//disable fx 2 and 3 on/off and select. These are not supported.
	sendMidi(uniqueId,0x90,8,0x01,0x00); 
	sendMidi(uniqueId,0x90,9,0x01,0x00);
	
	sendMidi(uniqueId,0x90,8,0x02,0x00);
	sendMidi(uniqueId,0x90,9,0x02,0x00);
	
	for (var x = 4; x<=7; x++){
		sendMidi(uniqueId,0x90,x,0x00,0x7F); //set each deck to cuepoint pad mode.
		sendMidi(uniqueId,0x90,x - 4,0x07,0x01); //vinyl led
		updatePadModeLEDs(uniqueId, x - 4, 0);
	}
	
	call('sleep', 10);// delay for 10ms to allow the MIDI out buffer to flush

}
//----------------------------------------------------------------------------- 
// this is your main target function to implement the controller -- this is called 
// for each and every MIDI message that comes from the controller itself
// return true if the message was processed by the script and false to let it 
// pass thru the software (eg. so it can be assigned by the user using the LEARN function)
function messageReceived(uniqueId,status,channel,data1,data2)
{
	//debug('messageReceived ['+uniqueId+'] - status:'+status+' channel:'+channel+' data1:'+data1+' data2:'+data2);
	var messageNotProcessed=false;
	
    //if(channel==2) channel = 1;else if(channel==1) channel = 2; // use this to switch channel; 2 and 3 instead of multiple if's
	switch(status)
	{
	//-----------------------------------------------
	// controllers: sliders, knobs, jog-wheels, encoders ('moving' things)
	case 0xE0:
		break;
	
	case 0xB0:
		switch(data1)
		{
		case 0x00:
			if(channel >= 8 && channel <= 9){
				call('deckFx1DryWet', channel - 8, data2);
			} else {
				var val1 = (data2 < 0x40 ? 1 : -1);
				call('lbMoveCursor', val1);
			}
			break;
		case 0x01: 
			if(channel >= 8 && channel <= 9){
				call('deckFx2DryWet', channel - 8, data2);
			}
		break;
		case 0x02: 
			if(channel >= 8 && channel <= 9){
				call('deckFxBeatwawDW', channel - 8, data2);
			}
		break;
		case 0x03: 
			
		break;
		case 0x04: 
			
		break;
		case 0x05:
		break;
		case 0x06: 
			var val1 = (data2 - 0x40) * -1;
			if(jogWheelsInScratchMode[channel] > 0){
				call('scratchDeckJW', channel, val1, 7200);
			} else {
				call('moveDeckJogWheel', channel, val1, 7200);
			}
		break;
		case 0x07: 
			
		break;
		case 0x08: 
			call('setCrossfader', data2);
		break;
		case 0x09: 
			if(channel == 15){
				call('setCFCurve', data2);
			} else {
				call('setDeckPitch', channel, 0x7F-data2);
			}
		break;
		case 0x0A: 
			
		break;
		case 0x0B: 
			
		break;
		case 0x0C: 
			
		break;
		case 0x0D: 
			
		break;
		case 0x0E: 
		break;
		case 0x0F: 
		
		break;
		case 0x10: 
		break;
		case 0x11: 
		break;
		case 0x12: 
		break;
		case 0x13: 
			
		break;
		case 0x14: 
		break;
		case 0x15: 
		break;
		case 0x16: 
			call('setDeckGain', channel, data2);
		break;
		case 0x17: 
			call('setDeckEqHigh', channel, data2);
		break;
		case 0x18:
			call('setDeckEqMid', channel, data2);
		break;
		case 0x19: 
			call('setDeckEqLow', channel, data2);
		break;
		case 0x1A: 
			if(channel < 4){
				call('setDeckCutoff', channel, data2);
			} else {
				if(data2)
					call('setSamplerMasterVolume',data2);
			}
		break;
		case 0x1B: 
		break;
		case 0x1C: 
			call('setDeckVolume', channel, data2);
		break;
		case 0x1D: 
		break;
		case 0x1E: 
		break;
		case 0x1F: 
			
		break;
		case 0x20: 
		break;
		case 0x21: 
			
		break;
		case 0x22:
		case 0x23:		

		break;
		
		case 0x24: 
		break;
		case 0x25: 
		break;
		case 0x26: 
		break;
		case 0x27: 

		break;
		case 0x28: 
		break;
		case 0x29: 
		break;
		case 0x2A: 
		break;
		case 0x2B:
			call('setDeckPos', channel, data2);
		break;
		case 0x2C: 
		break;
		case 0x2D: 
		break;
		case 0x2E: 
		break;
		case 0x2F: 
		break;
		case 0x30: 
		break;
		case 0x31: 
		break;
		case 0x32: 
		break;
		case 0x33: 
			
		break;
		case 0x34: 
			
		break;
		case 0x35: 
			
		break;
		case 0x36: 
		break;
		case 0x37: 
		break;
		case 0x38: 
			
		break;
		case 0x39: 
			
		break;
		case 0x3A: 
		break;
		case 0x3B: 
		break;
		case 0x3C: 
		break;
		case 0x3D: 
		break;
		case 0x3E: 
		break;
		case 0x3F: 
			
		break;
		case 0x40:
			
		break;
		case 0x43:			
		break;
		case 0x44:
			var val1 = (data2 < 0x40 ? 1 : -1);
			call('lbMoveCursor', val1);
			break;
		default: messageNotProcessed = true;
		}
	break;
	//-----------------------------------------------
	// note on/off: buttons, switches ('pressing' things)
	case 0x80:
	case 0x90:
		switch(data1)
		{
		case 0x00:	
			if(channel >= 8 && channel <= 9){
				//turn fx on or off.
				call('deckFx1ToggleOn', channel - 8, data2);
			} else {
				if(channel < 4){
				call('deckPlayPause', channel, data2);
				} else {
					//cue mode
					if(padMode[channel-4] != 0){
						padMode[channel-4] = 0;
						updatePadModeLEDs(uniqueId, channel-4, padMode[channel-4], padLEDState); //update pad mode leds.
					}
				}
			}
			break;
		case 0x01:
			if(channel >= 8 && channel <= 9){
				//turn fx on or off.
				call('deckFx2ToggleOn', channel - 8, data2); //not working
			} else {
				if(channel < 4){
					call('deckCue', channel, data2);
				}
			}
			
			break;
		case 0x02: 			
			if(channel < 4){
				call('deckSync', channel, data2);
			} else if(channel == 15 && data2) {
				call('deckLBLoad', 0, data2);
			
			}
			break;
		case 0x03: 		
					
			if(channel == 15 && data2) {
				call('deckLBLoad', 1, data2);			
			} else {
				if(!data2){
					sendMidi(uniqueId,0x90,channel,0x00,0x7F);
				}
			}
			break;
		case 0x04: 			
			if(channel == 15 && data2) {
				call('deckLBLoad', 2, data2);
			} else {
				call('deckTapBpm', channel-8, data2);
			}
			break;
		case 0x05: 			
			if(channel == 15 && data2) {
				call('deckLBLoad', 3, data2);
			
			}
			break;
		case 0x06: 			
				if(jogWheelsInScratchMode[channel]){
					call('holdDeckJogWheel', channel, data2);
				}	
			break;
		case 0x07:
			if(channel < 4){
				if(data2){
					jogWheelsInScratchMode[channel] = (jogWheelsInScratchMode[channel] ? 0 : 127);
					sendMidi(uniqueId,0x90,channel,0x07,(jogWheelsInScratchMode[channel] ? 0x7F : 0x01));
				}
			} else {
				//loop point mode
				if(padMode[channel-4] != 1){
					padMode[channel-4] = 1; //set pad mode
					updatePadModeLEDs(uniqueId, channel-4, padMode[channel-4]); //update pad mode leds.
				} //if change
				
			}
			
			
			break;
		case 0x08: //deck selector
			if(data2){
				switch(channel){
					case 0: //deck 1 selected, disable deck 3
						deckState[0] = 1;
						deckState[2] = 0;
						updatePadModeLEDs(uniqueId, channel, padMode[channel]);
						break;
					case 1: //deck 2 selected, disable deck 4
						deckState[1] = 1;
						deckState[3] = 0;
						updatePadModeLEDs(uniqueId, channel, padMode[channel]);
						break;
					case 2: //deck 3 selected, disable deck 1
						deckState[0] = 0;
						deckState[2] = 1;
						updatePadModeLEDs(uniqueId, channel, padMode[channel]);
						break;
					case 3: //deck 4 selected, disable deck 1
						deckState[1] = 0;
						deckState[3] = 1;
						updatePadModeLEDs(uniqueId, channel, padMode[channel]);
						break;
				}	
			}
			break;
		case 0x09:	
			//auto loop mode
			if(padMode[channel-4] != 2){
				padMode[channel-4] = 2;
				updatePadModeLEDs(uniqueId, channel-4, padMode[channel-4]); //update pad mode leds.
			}
			
			break;
		case 0x0A:
			if(!data2){
				sendMidi(uniqueId,0x90,channel,0x09,0x7F);
			}
			break;
		case 0x0B:			
			if(channel >= 8 && channel <= 9){
				call('deckFx1Next', channel - 8, data2);
			} else {
				if(channel < 4){
				call('deckBendUp', channel, data2);
				} else {
					//sampler mode
					if(padMode[channel-4] != 3){
						padMode[channel-4] = 3;
						updatePadModeLEDs(uniqueId, channel-4, padMode[channel-4]); //update pad mode leds.
					}
					
				}
			}
			
			break;
		case 0x0C:	
			if(channel >= 8 && channel <= 9){
				call('deckFx2Next', channel - 8, data2); //not working; only echo is enabled.
				//sendMidi(uniqueId,0x90,channel,0x0C,0x00);
			} else {
				if(channel < 4){
					call('deckBendDown', channel, data2);
				} else {
					if(!data2){
						sendMidi(uniqueId,0x90,channel,0x0B,0x7F);
					}
				}
			}
			
			break;
		case 0x0D:	
			if(channel >= 8 && channel <= 9){
				//sendMidi(uniqueId,0x90,channel,0x0D,0x00);
			} else {
				if(channel < 4){
					call('deckKeyLock', channel, data2);
				} else {
					if(!data2){
						
						sendMidi(uniqueId,0x90,channel,0x07,0x7F);
					}
				}
			}
			
			break;
		case 0x0E:			
			break;
		case 0x0F: 
			break;
		case 0x10:
			if(channel < 4){
				call('deckReverse', channel, data2);
			}
			break;
		case 0x11:
			if(data2)
				call('lbToggleSelect', data2);
			break;
		case 0x12: 
			
			break;
		case 0x13: 
			
			break;
		case 0x14: 
			//sendMidi(uniqueId,0x90,channel,0x14, (data2 ? 0x0D : 0x03));
			if(padMode[channel - 4] == 0){
				call('deckCuePos1', channel-4, data2);
			} else if(padMode[channel - 4] == 1){
				call('deckLoopPoint1', channel-4, data2);
			} else if(padMode[channel - 4] == 2){
				call('deckLoop1_16', channel - 4, data2);
			} else if(padMode[channel - 4] == 3){
				if(data2)
					call('samplerPlay', 1);
			}
			
			break;
		case 0x15: 
			if(padMode[channel - 4] == 0){
				call('deckCuePos2', channel-4, data2);
			} else if(padMode[channel - 4] == 1){
				call('deckLoopPoint2', channel-4, data2);
			} else if(padMode[channel - 4] == 2){
				call('deckLoop1_8', channel - 4, data2);
			} else if(padMode[channel - 4] == 3){
				if(data2)
					call('samplerPlay', 2);
			}
			break;
		case 0x16: 
			if(padMode[channel - 4] == 0){
				call('deckCuePos3', channel-4, data2);
			} else if(padMode[channel - 4] == 1){
				call('deckLoopPoint3', channel-4, data2);
			} else if(padMode[channel - 4] == 2){
				call('deckLoop1_4', channel - 4, data2);
			} else if(padMode[channel - 4] == 3){
				if(data2)
					call('samplerPlay', 3);
			}
			break;
		case 0x17: 
			if(padMode[channel - 4] == 0){
				call('deckCuePos4', channel-4, data2);
			} else if(padMode[channel - 4] == 1){
				call('deckLoopPoint4', channel-4, data2);
			} else if(padMode[channel - 4] == 2){
				call('deckLoop1_2', channel - 4, data2);
			} else if(padMode[channel - 4] == 3){
				if(data2)
					call('samplerPlay', 4);
			}
			break;
		case 0x18:	
			if(padMode[channel - 4] == 0){
				call('deckCuePos5', channel-4, data2);
			} else if(padMode[channel - 4] == 1){
				call('deckLoopPoint5', channel-4, data2);
			} else if(padMode[channel - 4] == 2){
				call('deckLoop1', channel - 4, data2);
			} else if(padMode[channel - 4] == 3){
				if(data2)
					call('samplerPlay', 5);
			}
			break;
		case 0x19:		
			if(padMode[channel - 4] == 0){
				call('deckCuePos6', channel-4, data2);
			} else if(padMode[channel - 4] == 1){
				
			} else if(padMode[channel - 4] == 2){
				call('deckLoop2', channel - 4, data2);
			} else if(padMode[channel - 4] == 3){
				if(data2)
					call('samplerPlay', 6);
			}
			break;
		case 0x1A:	
			if(padMode[channel - 4] == 0){
				call('deckCuePos7', channel-4, data2);
			} else if(padMode[channel - 4] == 1){
				
			} else if(padMode[channel - 4] == 2){
				call('deckLoop4', channel - 4, data2);
			} else if(padMode[channel - 4] == 3){
				if(data2)
					call('samplerPlay', 7);
			}
			break;
		case 0x1B:
			if(channel > 3){
				if(padMode[channel - 4] == 0){
					call('deckCuePos8', channel-4, data2);
				} else if(padMode[channel - 4] == 1){
				
				} else if(padMode[channel - 4] == 2){
					call('deckLoop8', channel - 4, data2);
				} else if(padMode[channel - 4] == 3){
					if(data2)
						call('samplerPlay', 8);
				}
			} else {
				call('deckMonitor', channel, data2);
			}
			break;
		case 0x1C:
			
			break;
		case 0x1D: 
			break;
		case 0x1E: 
			break;
		case 0x1F: 
			break;
		case 0x20: 
			break;
		case 0x21: 
			break;
		case 0x22: 
			break;
		case 0x23: 
			break;
		case 0x24: 
			break;
		case 0x25: 
			break;
		case 0x26: 
			break;
		case 0x27: 
			break;
		case 0x28: 	 		
			call('deckLoopPrev', channel - 4, data2);
			sendMidi(uniqueId,0x90,channel,0x28,(data2 ? 0x7F : 0x01));
			break;
		case 0x29: 		 	
			call('deckLoopNext', channel - 4, data2);
			sendMidi(uniqueId,0x90,channel,0x29,(data2 ? 0x7F : 0x01));
			break;
		case 0x2A: 
			break;
		case 0x2B:
			if(data2){
				var currentPitchRange = getValue('pitchRange');
				currentPitchRange = currentPitchRange + 1; if(currentPitchRange>6) currentPitchRange = 1;
				call('setPitchRange', currentPitchRange);
			}
			break;
		case 0x2C:
			if(data2){
				var currentPitchRange = getValue('pitchRange');
				currentPitchRange = currentPitchRange - 1; if(currentPitchRange<0) currentPitchRange = 6;
				call('setPitchRange', currentPitchRange);
			}
			break;
		case 0x2D: 
			break;
		case 0x2E: 			
			break;
		case 0x2F: 
			break;
		case 0x30: 
			
			break;
		case 0x31: 
			
			break;
		case 0x32: 
			if(!getValue('looping', channel - 4)) {
				call('deckLoop4', channel - 4, data2); 				
			} else { 
				call('deckLoopExit', channel - 4, data2);				
			}
			break;
		case 0x33: 
			call('deckLoopExitOrReloop', channel - 4, data2);
			sendMidi(uniqueId,0x90,channel,0x33,(data2 ? 0x7F : 0x01));
			break;
		case 0x34: 
			call('deckLoopLess', channel - 4, (data2 ? 0x7F : 0x01));
			sendMidi(uniqueId,0x90,channel,0x34,(data2 ? 0x7F : 0x01));
			break;
		case 0x35: 
			call('deckLoopMore', channel - 4, data2);
			sendMidi(uniqueId,0x90,channel,0x35, (data2 ? 0x7F : 0x01));
			break;
		case 0x36: 
			break;
		case 0x37: 
			break;
		case 0x38: 
			call('deckLoopInEnd', channel - 4, data2); //loopin
			
			break;
		case 0x39: 
			if(!getValue('looping', channel - 4)) call('deckLoopInEnd', channel - 4, data2); else call('deckLoopExit', channel - 4, data2); //loopout
			break;
		case 0x3A: 
			break;
		case 0x3B: 
			break;
		case 0x3C: 
			break;
		case 0x3D: 
			break;
		case 0x3E: 
			break;
		case 0x3F: 
			break;
		case 0x40:
			
			break;
		case 0x41:
			
			break;
		case 0x42:
			
			break;
		case 0x43:
		
			break;
		case 0x44:
			
			break;
		case 0x45:
			
			break;
		case 0x46:
			
			break;
		case 0x47:
			
			break;
		case 0x48:
			
			break;
		case 0x49:
			
			
			break;
		case 0x4D:
			
			break;
		case 0x50:
			
			break;
		case 0x51:
			
			break;
		case 0x52:
			
			break;
		case 0x53:
			
			break;
		case 0x54:
			
			break;
		case 0x55:
			
			break;
		case 0x56:
			
			break;
		case  0x67:
			
			break;
		case 0x58:
			
			break;
		case 0x5F:
			break;
		case 0x60:
			
			break;
		case 0x61:
			break;
		case 0x62:
			break;
		case 0x72:
			
			break;
		case 0x77: 
			break;
		
		default: messageNotProcessed = true;
		}
		break;
	//-----------------------------------------------
	default: messageNotProcessed = true;
	}
	//if(messageNotProcessed) debug('messageReceived ['+uniqueId+'] - status:'+status+' channel:'+channel+' data1:'+data1+' data2:'+data2);
	return !messageNotProcessed;
}
//----------------------------------------------------------------------------- 
// this is called by the software whenever something important changes (eg. play status, song changed, etc)
// depending on the notification type it may refer to a global event (deck is -1) or a specific deck (deck >= 0)
// and can contain any/all of the parameters: param 1 is an integer, param 2 is a float, param 3 is a string
function notificationReceived(uniqueId,name,deck,param1,param2,param3)
{
	//debug('notif ['+uniqueId+'] name='+name + ' deck='+deck + ' p1(int)='+param1 + ' p2(float)='+param2 + ' p3(str)='+param3);
	var nameLen = name.length;
	
	if(name=='cue') 		 sendMidi(uniqueId,0x90,deck,0x01,(param1 ? 0x7F : 0x01)); // cue
	if(name=='play') 		 sendMidi(uniqueId,0x90,deck,0x00,(param1 ? 0x7F : 0x01)); //play
	
	if(name=='cuepos1') {	 
		if((padLEDState[deck][0][0] && !param1) || (!padLEDState[deck][0][0] && param1)){ //these are the only conditions where LED changes			
			padLEDState[deck][0][0] = param1 ? 1 : 0; //set the new value			
			if(padMode[deck] == 0){ //update the switch on/off led if and only if user is in correct pad mode.				
				sendMidi(uniqueId,0x90,deck + 4,0x14, (padLEDState[deck][0][0] ? color_pad_cuepoint_on : color_pad_cuepoint_off)); //change LED
			}
		}//if change
	}//cue 1
	if(name=='cuepos2') {	 
		if((padLEDState[deck][0][1] && !param1) || (!padLEDState[deck][0][1] && param1)){ //these are the only conditions where LED changes			
			padLEDState[deck][0][1] = param1 ? 1 : 0; //set the new value			
			if(padMode[deck] == 0){ //update the switch on/off led if and only if user is in correct pad mode.				
				sendMidi(uniqueId,0x90,deck + 4,0x15, (padLEDState[deck][0][1] ? color_pad_cuepoint_on : color_pad_cuepoint_off)); //change LED
			}
		}//if change
	}//cue 2
	if(name=='cuepos3') {	 
		if((padLEDState[deck][0][2] && !param1) || (!padLEDState[deck][0][2] && param1)){ //these are the only conditions where LED changes			
			padLEDState[deck][0][2] = param1 ? 1 : 0; //set the new value			
			if(padMode[deck] == 0){ //update the switch on/off led if and only if user is in correct pad mode.				
				sendMidi(uniqueId,0x90,deck + 4,0x16, (padLEDState[deck][0][2] ? color_pad_cuepoint_on : color_pad_cuepoint_off)); //change LED
			} //if cue point pad mode
		}//if change
	}//cue 3
	if(name=='cuepos4') {	 
		if((padLEDState[deck][0][3] && !param1) || (!padLEDState[deck][0][3] && param1)){ //these are the only conditions where LED changes			
			padLEDState[deck][0][3] = param1 ? 1 : 0; //set the new value			
			if(padMode[deck] == 0){ //update the switch on/off led if and only if user is in correct pad mode.				
				sendMidi(uniqueId,0x90,deck + 4,0x17, (padLEDState[deck][0][3] ? color_pad_cuepoint_on : color_pad_cuepoint_off)); //change LED
			} //if cue point pad mode
		}//if change
	}//cue 4
	if(name=='cuepos5') {	 
		if((padLEDState[deck][0][4] && !param1) || (!padLEDState[deck][0][4] && param1)){ //these are the only conditions where LED changes			
			padLEDState[deck][0][4] = param1 ? 1 : 0; //set the new value			
			if(padMode[deck] == 0){ //update the switch on/off led if and only if user is in correct pad mode.				
				sendMidi(uniqueId,0x90,deck + 4,0x18, (padLEDState[deck][0][4] ? color_pad_cuepoint_on : color_pad_cuepoint_off)); //change LED
			} //if cue point pad mode
		}//if change
	}//cue 5
	if(name=='cuepos6') {	 
		if((padLEDState[deck][0][5] && !param1) || (!padLEDState[deck][0][5] && param1)){ //these are the only conditions where LED changes			
			padLEDState[deck][0][5] = param1 ? 1 : 0; //set the new value			
			if(padMode[deck] == 0){ //update the switch on/off led if and only if user is in correct pad mode.				
				sendMidi(uniqueId,0x90,deck + 4,0x19, (padLEDState[deck][0][5] ? color_pad_cuepoint_on : color_pad_cuepoint_off)); //change LED
			} //if cue point pad mode
		}//if change
	}//cue 6	
	if(name=='cuepos7') {	 
		if((padLEDState[deck][0][6] && !param1) || (!padLEDState[deck][0][6] && param1)){ //these are the only conditions where LED changes			
			padLEDState[deck][0][6] = param1 ? 1 : 0; //set the new value			
			if(padMode[deck] == 0){ //update the switch on/off led if and only if user is in correct pad mode.				
				sendMidi(uniqueId,0x90,deck + 4,0x1A, (padLEDState[deck][0][6] ? color_pad_cuepoint_on : color_pad_cuepoint_off)); //change LED
			} //if cue point pad mode
		}//if change
	}//cue 7
	if(name=='cuepos8') {	 
		if((padLEDState[deck][0][7] && !param1) || (!padLEDState[deck][0][7] && param1)){ //these are the only conditions where LED changes			
			padLEDState[deck][0][7] = param1 ? 1 : 0; //set the new value			
			if(padMode[deck] == 0){ //update the switch on/off led if and only if user is in correct pad mode.				
				sendMidi(uniqueId,0x90,deck + 4,0x1B, (padLEDState[deck][0][7] ? color_pad_cuepoint_on : color_pad_cuepoint_off)); //change LED
			} //if cue point pad mode
		}//if change
	}//cue 8
	
	if(name=='looppos1'){
		
		if((padLEDState[deck][1][0] && !param1) || (!padLEDState[deck][1][0] && param1)){ //these are the only conditions where LED changes			
			padLEDState[deck][1][0] = param1 ? 1 : 0; //set the new value			
			if(padMode[deck] == 1){ //update the switch on/off led if and only if user is in correct pad mode.				
				sendMidi(uniqueId,0x90,deck + 4,0x14, (padLEDState[deck][1][0] ? color_pad_looppoint_on : color_pad_looppoint_off)); //change LED
			} //if cue point pad mode
		}//if change
					
	}//loop point 1
	
	if(name=='looppos2'){
		
		if((padLEDState[deck][1][1] && !param1) || (!padLEDState[deck][1][1] && param1)){ //these are the only conditions where LED changes			
			padLEDState[deck][1][1] = param1 ? 1 : 0; //set the new value			
			if(padMode[deck] == 1){ //update the switch on/off led if and only if user is in correct pad mode.				
				sendMidi(uniqueId,0x90,deck + 4,0x15, (padLEDState[deck][1][1] ? color_pad_looppoint_on : color_pad_looppoint_off)); //change LED
			} //if cue point pad mode
		}//if change
					
	}//loop point 2
	
	if(name=='looppos3'){
		
		if((padLEDState[deck][1][2] && !param1) || (!padLEDState[deck][1][2] && param1)){ //these are the only conditions where LED changes			
			padLEDState[deck][1][2] = param1 ? 1 : 0; //set the new value			
			if(padMode[deck] == 1){ //update the switch on/off led if and only if user is in correct pad mode.				
				sendMidi(uniqueId,0x90,deck + 4,0x16, (padLEDState[deck][1][2] ? color_pad_looppoint_on : color_pad_looppoint_off)); //change LED
			} //if cue point pad mode
		}//if change
					
	}//loop point 3
	
	if(name=='looppos4'){
		
		if((padLEDState[deck][1][3] && !param1) || (!padLEDState[deck][1][3] && param1)){ //these are the only conditions where LED changes			
			padLEDState[deck][1][3] = param1 ? 1 : 0; //set the new value			
			if(padMode[deck] == 1){ //update the switch on/off led if and only if user is in correct pad mode.				
				sendMidi(uniqueId,0x90,deck + 4,0x17, (padLEDState[deck][1][3] ? color_pad_looppoint_on : color_pad_looppoint_off)); //change LED
			} //if cue point pad mode
		}//if change
					
	}//loop point 4
	
	if(name=='looppos5'){
		
		if((padLEDState[deck][1][4] && !param1) || (!padLEDState[deck][1][4] && param1)){ //these are the only conditions where LED changes			
			padLEDState[deck][1][4] = param1 ? 1 : 0; //set the new value			
			if(padMode[deck] == 1){ //update the switch on/off led if and only if user is in correct pad mode.				
				sendMidi(uniqueId,0x90,deck + 4,0x18, (padLEDState[deck][1][4] ? color_pad_looppoint_on : color_pad_looppoint_off)); //change LED
			} //if cue point pad mode
		}//if change
					
	}//loop point 5
	
	
	
	
	
	if(name=='loopIn') 	 	 sendMidi(uniqueId,0x90,deck + 4,0x38,(param1 ? 0x7F : 0x01)); //loop in
	if(name=='looping') 	 
			{
				sendMidi(uniqueId,0x90,deck + 4,0x38,(param1 ? 0x7F : 0x01));// loop in led
				sendMidi(uniqueId,0x90,deck + 4,0x39,(param1 ? 0x7F : 0x01));//loop out led
				sendMidi(uniqueId,0x90,deck + 4,0x32,(param1 ? 0x7F : 0x01));//loop out led
			}
	if(name=='onbeat') 		sendMidi(uniqueId,0x90,deck,0x02,(param1 ? 0x7F : 0x01));
	if(name=='keyLock') 	sendMidi(uniqueId,0x90,deck,0x0D,(param1 ? 0x7F : 0x01));
	if(name=='monitor') 	sendMidi(uniqueId, 0x90,deck,0x1B,(param1 ? 0x7F : 0x00));//monitor
	if(name=='reverse')		sendMidi(uniqueId,0x90,deck,0x10,(param1 ? 0x7F : 0x01));//reverse
	
	if(name=='loopSize'){
		//debug((param1).toString());
		
		switch(param1){
			case 4:
				
				if((padLEDState[deck][2][0] && !param1) || (!padLEDState[deck][2][0] && param1)){ //these are the only conditions where LED changes			
					padLEDState[deck][2][0] = 1; //set the new value
					padLEDState[deck][2][1] = 0//make sure the rest are off.
					padLEDState[deck][2][2] = 0;
					padLEDState[deck][2][3] = 0;
					padLEDState[deck][2][4] = 0;
					padLEDState[deck][2][5] = 0;
					padLEDState[deck][2][6] = 0;
					padLEDState[deck][2][7] = 0;
					
					if(padMode[deck] == 2){ //update the switch on/off led if and only if user is in correct pad mode.				
						//sendMidi(uniqueId,0x90,deck + 4,0x14, (padLEDState[deck][2][0] ? color_pad_autoloop_on : color_pad_autoloop_off)); //change LED
						updatePadModeLEDs(uniqueId, deck, padMode[deck]);
					} //if cue point pad mode
				}//if change
				break;
			case 8:
				if((padLEDState[deck][2][1] && !param1) || (!padLEDState[deck][2][1] && param1)){ //these are the only conditions where LED changes			
					padLEDState[deck][2][0] = 0;
					padLEDState[deck][2][1] = 1; //set the new value
					padLEDState[deck][2][2] = 0;
					padLEDState[deck][2][3] = 0;
					padLEDState[deck][2][4] = 0;
					padLEDState[deck][2][5] = 0;
					padLEDState[deck][2][6] = 0;
					padLEDState[deck][2][7] = 0;
					
					if(padMode[deck] == 2){ //update the switch on/off led if and only if user is in correct pad mode.				
						//sendMidi(uniqueId,0x90,deck + 4,0x14, (padLEDState[deck][2][0] ? color_pad_autoloop_on : color_pad_autoloop_off)); //change LED
						updatePadModeLEDs(uniqueId, deck, padMode[deck]);
					} //if cue point pad mode
				}//if change
				
				break;
			case 16:
				if((padLEDState[deck][2][2] && !param1) || (!padLEDState[deck][2][2] && param1)){ //these are the only conditions where LED changes			
					padLEDState[deck][2][0] = 0;
					padLEDState[deck][2][1] = 0; //set the new value
					padLEDState[deck][2][2] = 1;
					padLEDState[deck][2][3] = 0;
					padLEDState[deck][2][4] = 0;
					padLEDState[deck][2][5] = 0;
					padLEDState[deck][2][6] = 0;
					padLEDState[deck][2][7] = 0;
					
					if(padMode[deck] == 2){ //update the switch on/off led if and only if user is in correct pad mode.				
						//sendMidi(uniqueId,0x90,deck + 4,0x14, (padLEDState[deck][2][0] ? color_pad_autoloop_on : color_pad_autoloop_off)); //change LED
						updatePadModeLEDs(uniqueId, deck, padMode[deck]);
					} //if cue point pad mode
				}//if change
				break;
			case 32:
				if((padLEDState[deck][2][3] && !param1) || (!padLEDState[deck][2][3] && param1)){ //these are the only conditions where LED changes			
					padLEDState[deck][2][0] = 0;
					padLEDState[deck][2][1] = 0; //set the new value
					padLEDState[deck][2][2] = 0;
					padLEDState[deck][2][3] = 1;
					padLEDState[deck][2][4] = 0;
					padLEDState[deck][2][5] = 0;
					padLEDState[deck][2][6] = 0;
					padLEDState[deck][2][7] = 0;
					
					if(padMode[deck] == 2){ //update the switch on/off led if and only if user is in correct pad mode.				
						//sendMidi(uniqueId,0x90,deck + 4,0x14, (padLEDState[deck][2][0] ? color_pad_autoloop_on : color_pad_autoloop_off)); //change LED
						updatePadModeLEDs(uniqueId, deck, padMode[deck]);
					} //if cue point pad mode
				}//if change
				break;
			case 64:
				if((padLEDState[deck][2][4] && !param1) || (!padLEDState[deck][2][4] && param1)){ //these are the only conditions where LED changes			
					padLEDState[deck][2][0] = 0;
					padLEDState[deck][2][1] = 0; //set the new value
					padLEDState[deck][2][2] = 0;
					padLEDState[deck][2][3] = 0;
					padLEDState[deck][2][4] = 1;
					padLEDState[deck][2][5] = 0;
					padLEDState[deck][2][6] = 0;
					padLEDState[deck][2][7] = 0;
					
					if(padMode[deck] == 2){ //update the switch on/off led if and only if user is in correct pad mode.				
						//sendMidi(uniqueId,0x90,deck + 4,0x14, (padLEDState[deck][2][0] ? color_pad_autoloop_on : color_pad_autoloop_off)); //change LED
						updatePadModeLEDs(uniqueId, deck, padMode[deck]);
					} //if cue point pad mode
				}//if change
				break;
			case 128:
				if((padLEDState[deck][2][5] && !param1) || (!padLEDState[deck][2][5] && param1)){ //these are the only conditions where LED changes			
					padLEDState[deck][2][0] = 0;
					padLEDState[deck][2][1] = 0; //set the new value
					padLEDState[deck][2][2] = 0;
					padLEDState[deck][2][3] = 0;
					padLEDState[deck][2][4] = 0;
					padLEDState[deck][2][5] = 1;
					padLEDState[deck][2][6] = 0;
					padLEDState[deck][2][7] = 0;
					
					if(padMode[deck] == 2){ //update the switch on/off led if and only if user is in correct pad mode.				
						//sendMidi(uniqueId,0x90,deck + 4,0x14, (padLEDState[deck][2][0] ? color_pad_autoloop_on : color_pad_autoloop_off)); //change LED
						updatePadModeLEDs(uniqueId, deck, padMode[deck]);
					} //if cue point pad mode
				}//if change
				break;
			case 256:
				if((padLEDState[deck][2][6] && !param1) || (!padLEDState[deck][2][6] && param1)){ //these are the only conditions where LED changes			
					padLEDState[deck][2][0] = 0;
					padLEDState[deck][2][1] = 0; //set the new value
					padLEDState[deck][2][2] = 0;
					padLEDState[deck][2][3] = 0;
					padLEDState[deck][2][4] = 0;
					padLEDState[deck][2][5] = 0;
					padLEDState[deck][2][6] = 1;
					padLEDState[deck][2][7] = 0;
					
					if(padMode[deck] == 2){ //update the switch on/off led if and only if user is in correct pad mode.				
						//sendMidi(uniqueId,0x90,deck + 4,0x14, (padLEDState[deck][2][0] ? color_pad_autoloop_on : color_pad_autoloop_off)); //change LED
						updatePadModeLEDs(uniqueId, deck, padMode[deck]);
					} //if cue point pad mode
				}//if change
				break;
			case 512:
				if((padLEDState[deck][2][7] && !param1) || (!padLEDState[deck][2][7] && param1)){ //these are the only conditions where LED changes			
					padLEDState[deck][2][0] = 0;
					padLEDState[deck][2][1] = 0; //set the new value
					padLEDState[deck][2][2] = 0;
					padLEDState[deck][2][3] = 0;
					padLEDState[deck][2][4] = 0;
					padLEDState[deck][2][5] = 0;
					padLEDState[deck][2][6] = 0;
					padLEDState[deck][2][7] = 1;
					
					if(padMode[deck] == 2){ //update the switch on/off led if and only if user is in correct pad mode.				
						//sendMidi(uniqueId,0x90,deck + 4,0x14, (padLEDState[deck][2][0] ? color_pad_autoloop_on : color_pad_autoloop_off)); //change LED
						updatePadModeLEDs(uniqueId, deck, padMode[deck]);
					} //if cue point pad mode
				}//if change
				break;
			case 0:
				//if((padLEDState[deck][2][7] && !param1) || (!padLEDState[deck][2][7] && param1)){ //these are the only conditions where LED changes			
					padLEDState[deck][2][0] = 0;
					padLEDState[deck][2][1] = 0; //set the new value
					padLEDState[deck][2][2] = 0;
					padLEDState[deck][2][3] = 0;
					padLEDState[deck][2][4] = 0;
					padLEDState[deck][2][5] = 0;
					padLEDState[deck][2][6] = 0;
					padLEDState[deck][2][7] = 0;
					
					if(padMode[deck] == 2){ //update the switch on/off led if and only if user is in correct pad mode.				
						//sendMidi(uniqueId,0x90,deck + 4,0x14, (padLEDState[deck][2][0] ? color_pad_autoloop_on : color_pad_autoloop_off)); //change LED
						updatePadModeLEDs(uniqueId, deck, padMode[deck]);
					} //if cue point pad mode
				//}//if change
				break;
		}
		
	}
	
	if(nameLen==8)
	{
		var name1 = name.substr(0, nameLen-1);
		if(name1=='sampler'){
			if(name=='sampler1') {
				if((padLEDState[0][3][0] && !param1) || (!padLEDState[0][3][0] && param1)){ //these are the only conditions where LED changes			
					padLEDState[0][3][0] = param1 ? 1 : 0; //set the new value (do this for all channels.
					padLEDState[1][3][0] = param1 ? 1 : 0; //set the new value (do this for all channels.
					padLEDState[2][3][0] = param1 ? 1 : 0; //set the new value (do this for all channels.
					padLEDState[3][3][0] = param1 ? 1 : 0; //set the new value (do this for all channels.
											
					if(deckState[0] == 1)
						if(padMode[0] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,4,0x14, (padLEDState[0][3][0] ? color_pad_sample_on : color_pad_sample_off)); //change LED
						} //if sampler pad mode
					
					if(deckState[1] == 1)
						if(padMode[1] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,5,0x14, (padLEDState[0][3][0] ? color_pad_sample_on : color_pad_sample_off)); //change LED
						} //if sampler pad mode
					
					if(deckState[2] == 1)
						if(padMode[2] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,4,0x14, (padLEDState[0][3][0] ? color_pad_sample_on : color_pad_sample_off)); //change LED
						} //if sampler pad mode
					
					if(deckState[3] == 1)
						if(padMode[3] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,5,0x14, (padLEDState[0][3][0] ? color_pad_sample_on : color_pad_sample_off)); //change LED
					} //if sampler pad mode
					
					
				}//if change
			}
			
			if(name=='sampler2') {
				if((padLEDState[0][3][1] && !param1) || (!padLEDState[0][3][1] && param1)){ //these are the only conditions where LED changes			
					padLEDState[0][3][1] = param1 ? 1 : 0; //set the new value (do this for all channels.
					padLEDState[1][3][1] = param1 ? 1 : 0; //set the new value (do this for all channels.
					padLEDState[2][3][1] = param1 ? 1 : 0; //set the new value (do this for all channels.
					padLEDState[3][3][1] = param1 ? 1 : 0; //set the new value (do this for all channels.
					
					if(deckState[0] == 1)
						if(padMode[0] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,4,0x15, (padLEDState[0][3][1] ? color_pad_sample_on : color_pad_sample_off)); //change LED
						} //if sampler pad mode
					
					if(deckState[1] == 1)
						if(padMode[1] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,5,0x15, (padLEDState[0][3][1] ? color_pad_sample_on : color_pad_sample_off)); //change LED
						} //if sampler pad mode
					
					if(deckState[2] == 1)
						if(padMode[2] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,4,0x15, (padLEDState[0][3][1] ? color_pad_sample_on : color_pad_sample_off)); //change LED
						} //if sampler pad mode
					
					if(deckState[3] == 1)
						if(padMode[3] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,5,0x15, (padLEDState[0][3][1] ? color_pad_sample_on : color_pad_sample_off)); //change LED
					} //if sampler pad mode
					
				}//if change
			}
			
			if(name=='sampler3') {
				if((padLEDState[0][3][2] && !param1) || (!padLEDState[0][3][2] && param1)){ //these are the only conditions where LED changes			
					padLEDState[0][3][2] = param1 ? 1 : 0; //set the new value (do this for all channels.
					padLEDState[1][3][2] = param1 ? 1 : 0; //set the new value (do this for all channels.
					padLEDState[2][3][2] = param1 ? 1 : 0; //set the new value (do this for all channels.
					padLEDState[3][3][2] = param1 ? 1 : 0; //set the new value (do this for all channels.
											
					if(deckState[0] == 1)
						if(padMode[0] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,4,0x16, (padLEDState[0][3][2] ? color_pad_sample_on : color_pad_sample_off)); //change LED
						} //if sampler pad mode
					
					if(deckState[1] == 1)
						if(padMode[1] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,5,0x16, (padLEDState[0][3][2] ? color_pad_sample_on : color_pad_sample_off)); //change LED
						} //if sampler pad mode
					
					if(deckState[2] == 1)
						if(padMode[2] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,4,0x16, (padLEDState[0][3][2] ? color_pad_sample_on : color_pad_sample_off)); //change LED
						} //if sampler pad mode
					
					if(deckState[3] == 1)
						if(padMode[3] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,5,0x16, (padLEDState[0][3][2] ? color_pad_sample_on : color_pad_sample_off)); //change LED
					} //if sampler pad mode
					
				}//if change
			}
			
			if(name=='sampler4') {
				if((padLEDState[0][3][3] && !param1) || (!padLEDState[0][3][3] && param1)){ //these are the only conditions where LED changes			
					padLEDState[0][3][3] = param1 ? 1 : 0; //set the new value (do this for all channels.
					padLEDState[1][3][3] = param1 ? 1 : 0; //set the new value (do this for all channels.
					padLEDState[2][3][3] = param1 ? 1 : 0; //set the new value (do this for all channels.
					padLEDState[3][3][3] = param1 ? 1 : 0; //set the new value (do this for all channels.
					
					if(deckState[0] == 1)
						if(padMode[0] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,4,0x17, (padLEDState[0][3][3] ? color_pad_sample_on : color_pad_sample_off)); //change LED
						} //if sampler pad mode
					
					if(deckState[1] == 1)
						if(padMode[1] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,5,0x17, (padLEDState[0][3][3] ? color_pad_sample_on : color_pad_sample_off)); //change LED
						} //if sampler pad mode
					
					if(deckState[2] == 1)
						if(padMode[2] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,4,0x17, (padLEDState[0][3][3] ? color_pad_sample_on : color_pad_sample_off)); //change LED
						} //if sampler pad mode
					
					if(deckState[3] == 1)
						if(padMode[3] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,5,0x17, (padLEDState[0][3][3] ? color_pad_sample_on : color_pad_sample_off)); //change LED
					} //if sampler pad mode
				}//if change
			}
			
			if(name=='sampler5') {
				if((padLEDState[0][3][4] && !param1) || (!padLEDState[0][3][4] && param1)){ //these are the only conditions where LED changes			
					padLEDState[0][3][4] = param1 ? 1 : 0; //set the new value (do this for all channels.
					padLEDState[1][3][4] = param1 ? 1 : 0; //set the new value (do this for all channels.
					padLEDState[2][3][4] = param1 ? 1 : 0; //set the new value (do this for all channels.
					padLEDState[3][3][4] = param1 ? 1 : 0; //set the new value (do this for all channels.
					
					
					if(deckState[0] == 1)
						if(padMode[0] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,4,0x18, (padLEDState[0][3][4] ? color_pad_sample_on : color_pad_sample_off)); //change LED
						} //if sampler pad mode
					
					if(deckState[1] == 1)
						if(padMode[1] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,5,0x18, (padLEDState[0][3][4] ? color_pad_sample_on : color_pad_sample_off)); //change LED
						} //if sampler pad mode
					
					if(deckState[2] == 1)
						if(padMode[2] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,4,0x18, (padLEDState[0][3][4] ? color_pad_sample_on : color_pad_sample_off)); //change LED
						} //if sampler pad mode
					
					if(deckState[3] == 1)
						if(padMode[3] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,5,0x18, (padLEDState[0][3][4] ? color_pad_sample_on : color_pad_sample_off)); //change LED
					} //if sampler pad mode
				}//if change
			}
			
			if(name=='sampler6') {
				if((padLEDState[0][3][5] && !param1) || (!padLEDState[0][3][5] && param1)){ //these are the only conditions where LED changes			
					padLEDState[0][3][5] = param1 ? 1 : 0; //set the new value (do this for all channels.
					padLEDState[1][3][5] = param1 ? 1 : 0; //set the new value (do this for all channels.
					padLEDState[2][3][5] = param1 ? 1 : 0; //set the new value (do this for all channels.
					padLEDState[3][3][5] = param1 ? 1 : 0; //set the new value (do this for all channels.
											
					if(deckState[0] == 1)
						if(padMode[0] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,4,0x19, (padLEDState[0][3][5] ? color_pad_sample_on : color_pad_sample_off)); //change LED
						} //if sampler pad mode
					
					if(deckState[1] == 1)
						if(padMode[1] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,55,0x19, (padLEDState[0][3][5] ? color_pad_sample_on : color_pad_sample_off)); //change LED
						} //if sampler pad mode
					
					if(deckState[2] == 1)
						if(padMode[2] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,4,0x19, (padLEDState[0][3][5] ? color_pad_sample_on : color_pad_sample_off)); //change LED
						} //if sampler pad mode
					
					if(deckState[3] == 1)
						if(padMode[3] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,5,0x19, (padLEDState[0][3][5] ? color_pad_sample_on : color_pad_sample_off)); //change LED
					} //if sampler pad mode
				}//if change
			}
			
			if(name=='sampler7') {
				if((padLEDState[0][3][6] && !param1) || (!padLEDState[0][3][6] && param1)){ //these are the only conditions where LED changes			
					padLEDState[0][3][6] = param1 ? 1 : 0; //set the new value (do this for all channels.
					padLEDState[1][3][6] = param1 ? 1 : 0; //set the new value (do this for all channels.
					padLEDState[2][3][6] = param1 ? 1 : 0; //set the new value (do this for all channels.
					padLEDState[3][3][6] = param1 ? 1 : 0; //set the new value (do this for all channels.
					
					if(deckState[0] == 1)
						if(padMode[0] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,4,0x1A, (padLEDState[0][3][6] ? color_pad_sample_on : color_pad_sample_off)); //change LED
						} //if sampler pad mode
					
					if(deckState[1] == 1)
						if(padMode[1] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,5,0x1A, (padLEDState[0][3][6] ? color_pad_sample_on : color_pad_sample_off)); //change LED
						} //if sampler pad mode
					
					if(deckState[2] == 1)
						if(padMode[2] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,4,0x1A, (padLEDState[0][3][6] ? color_pad_sample_on : color_pad_sample_off)); //change LED
						} //if sampler pad mode
					
					if(deckState[3] == 1)
						if(padMode[3] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,5,0x1A, (padLEDState[0][3][6] ? color_pad_sample_on : color_pad_sample_off)); //change LED
					} //if sampler pad mode
				}//if change
			}
			
			if(name=='sampler8') {
				if((padLEDState[0][3][7] && !param1) || (!padLEDState[0][3][7] && param1)){ //these are the only conditions where LED changes			
					padLEDState[0][3][7] = param1 ? 1 : 0; //set the new value (do this for all channels.
					padLEDState[1][3][7] = param1 ? 1 : 0; //set the new value (do this for all channels.
					padLEDState[2][3][7] = param1 ? 1 : 0; //set the new value (do this for all channels.
					padLEDState[3][3][7] = param1 ? 1 : 0; //set the new value (do this for all channels.
					
					if(deckState[0] == 1)
						if(padMode[0] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,4,0x1B, (padLEDState[0][3][7] ? color_pad_sample_on : color_pad_sample_off)); //change LED
						} //if sampler pad mode
					
					if(deckState[1] == 1)
						if(padMode[1] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,5,0x1B, (padLEDState[0][3][7] ? color_pad_sample_on : color_pad_sample_off)); //change LED
						} //if sampler pad mode
					
					if(deckState[2] == 1)
						if(padMode[2] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,4,0x1B, (padLEDState[0][3][7] ? color_pad_sample_on : color_pad_sample_off)); //change LED
						} //if sampler pad mode
					
					if(deckState[3] == 1)
						if(padMode[3] == 3){ //update the switch on/off led if and only if user is in correct pad mode.
							sendMidi(uniqueId,0x90,5,0x1B, (padLEDState[0][3][7] ? color_pad_sample_on : color_pad_sample_off)); //change LED
						} //if sampler pad mode
				}//if change
			}
		}
	}
	if(nameLen > 2){
		var name1 = name.substr(0, 2);
		//debug((getValue('fx1', deck)).toString());
		if(name1 == 'fx' && name != 'fxEcho' && name != 'fxBeatwaw') {
			
			sendMidi(uniqueId,0x90,deck + 8,0x00,(param1 ? 0x7F : 0x01));
		}
	}
}


//----------------------------------------------------------------------------- 
// this is called from time to time by the software (several times per second)
// (it is guaranteed that 'timerTick' will get executed ALWAYS right after notificationReceived)
function timerTick(uniqueId)
{
	for(var deck=0; deck<4; deck++)
	{
		var dbValue = getValue('vumeterDeck', deck);// float dB
		setVUValueForDeck(uniqueId, deck, dbValue);
	}
}

var vuStatus=[[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]];
var vuCurrent=[-44,-36,-28,-20,-16,-12,-8,-4,-2,-1];
function setVUValueForDeck(uniqueId, deck, dbValue)
{	
	var param1=0;
	for(var i=0; i<10; i++)
	{
		if(dbValue>=vuCurrent[i]) param1 = 1;else param1 = 0;
		if(param1 != vuStatus[deck][i])
		{
			vuStatus[deck][i] = param1;
			sendMidi(uniqueId,0xB0,deck,0x1F, i * 14);// VU Led			
		}
	}
}

function updatePadModeLEDs(uniqueId, deck, padmode){
	var ledcolor_on  = 0x00;
	var ledcolor_off = 0x00;
	switch(padmode){
		case 0:
			ledcolor_on = color_pad_cuepoint_on;
			ledcolor_off = color_pad_cuepoint_off;
			break;
		case 1:
			ledcolor_on = color_pad_looppoint_on;
			ledcolor_off = color_pad_looppoint_off;
			break;
		case 2:
			ledcolor_on = color_pad_autoloop_on;
			ledcolor_off = color_pad_autoloop_off;
			break;
		case 3:
			ledcolor_on = color_pad_sample_on;
			ledcolor_off = color_pad_sample_off;
			break;
	}
	
	
	
	for(var x = 0; x < 8; x++){
		sendMidi(uniqueId,0x90,deck + 4,0x14 + x, (padLEDState[deck][padmode][x] ? ledcolor_on : ledcolor_off));//change LED
		
	}
}
	


//----------------------------------------------------------------------------- 
