//-----------------------------------------------------------------------------
//-------- Copyright (c)2003-2011. All Rights Reserved. -----------------------
//-----------------------------------------------------------------------------
// file implementing MIDI controller ' Pioneer DDJ SB-2
// Date: 2016 01 06
// Author: 
//----------------------------------------------------------------------------- 
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 "G2V Audio";
}
//----------------------------------------------------------------------------- 
// 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 0x23C7;
}
//----------------------------------------------------------------------------- 
function getSupportedMidiDevicePID(osId)
{	
	return 0x0466;	
}
//----------------------------------------------------------------------------- 
//----------------------------------------------------------------------------- 
//----------------------------------------------------------------------------- 
// 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
	//if(osId==1) return false;
	
	return "7D0001000900000000F7";
	
}
//----------------------------------------------------------------------------- 
// 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 "G2V Audio";// !!! 
	
}
//----------------------------------------------------------------------------- 
function getSupportedMidiDeviceNameForOutput(osId)
{
	return "G2V Audio";
	//return false;
}
//----------------------------------------------------------------------------- 
//----------------------------------------------------------------------------- 
// some variables necessary only for this particular script
var jogWheelsInScratchMode	=[0,0];
//var jogWheelsWasDeckPlaying	=[0,0,0,0];
//var shiftButton				=[0,0,0,0];
//var deckMode				=[0,0,0,0]; //0=hot cue 1=roll 2=slicer 3=sampler

var samplerBlinkLedStatus	= [0,0,0,0,0,0,0,0];// 2 decks leds, each with 4 samplers // 0 means off; 1 means on; 2 means blink on; 3 means blink off;
var samplerBlinkState 		= [0,0];
var shiftPressed 			= [0,0];
var bankFxIsOn 				= [[0,0,0], [0,0,0], [0,0,0], [0,0,0]];
var fxLevel                 = [0,0,0,0];

//var padMode 		= [[0,0,0,0],[0,0,0,0]];

var hotCueMode 		= [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]];
var tmphotCueMode 		= [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]];


var autoLoopMode 	= [[0,0,0,0,0],[0,0,0,0,0]];
var tmpautoLoopMode 	= [[0,0,0,0,0],[0,0,0,0,0]];

var sampleMode      = [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]];
var tmpsampleMode   = [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]];

var manualLoopMode  = [[0,0,0,0,0],[0,0,0,0,0]];// in out of/on less more

var holdingJog 		= [0,0];
var loopMovePreviousValue = [-1,-1];

var manualLoop = [0,0];
var tmpmanualLoop = [0,0];



var padmode                 = [0,0];//0=cue;1=autoloop;2=sample;3=manual-loop;

//----------------------------------------------------------------------------- 
// 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)
{

	//debug('controllerInit Gemini G2V ['+uniqueId+']');// this outputs a string to DebugView app on Win
	callSendAllNotifications(uniqueId, true);
	for(var i=0; i<2; i++){	
		clearPads(uniqueId, i);
		sendMidi(uniqueId,0xB0,0x03,0x14+i,0x00);//Deck vu meter
		sendMidi(uniqueId,0xB0,0x03,0x18+i,0x00);//master left and master right
		
		sendMidi(uniqueId,0x90,i,0x01,0x00); //play
		sendMidi(uniqueId,0x90,i,0x02,0x00); //cue
		sendMidi(uniqueId,0x90,i,0x03,0x00); //cup
		sendMidi(uniqueId,0x90,i,0x04,0x00); //sync
		sendMidi(uniqueId,0x90,i,0x05,0x00); //keylock
		sendMidi(uniqueId,0x90,i,0x19,0x00); //slip
		sendMidi(uniqueId,0x90,i,0x1A,0x00); //FX on/off
		sendMidi(uniqueId,0x90,i,0x23,0x00); //scratch
		sendMidi(uniqueId,0x90,i,0x28,0x00); //shift
	}
	enablePadModeLED(uniqueId, 0, -1);
	enablePadModeLED(uniqueId, 1, -1);
	
	sendMidi(uniqueId,0x90,0x03,0x0D,0x00); //mon 1
	sendMidi(uniqueId,0x90,0x03,0x0E,0x00); //mon 2
	sendMidi(uniqueId,0x90,0x03,0x01,0x00); //play
	sendMidi(uniqueId,0x90,0x03,0x02,0x00); //cue

	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)
{
	//debug('controllerDeinit PioneerDDJSX ['+uniqueId+']');
	//callSendAllNotifications(uniqueId, false);
	for(var i=0; i<2; i++){	
		clearPads(uniqueId, i);
		sendMidi(uniqueId,0xB0,0x03,0x14+i,0x00);//Deck vu meter
		sendMidi(uniqueId,0xB0,0x03,0x18+i,0x00);//master left and master right
		
		sendMidi(uniqueId,0x90,i,0x01,0x00); //play
		sendMidi(uniqueId,0x90,i,0x02,0x00); //cue
		sendMidi(uniqueId,0x90,i,0x03,0x00); //cup
		sendMidi(uniqueId,0x90,i,0x04,0x00); //sync
		sendMidi(uniqueId,0x90,i,0x05,0x00); //keylock
		sendMidi(uniqueId,0x90,i,0x19,0x00); //slip
		sendMidi(uniqueId,0x90,i,0x1A,0x00); //FX on/off
		sendMidi(uniqueId,0x90,i,0x23,0x00); //scratch
		sendMidi(uniqueId,0x90,i,0x28,0x00); //shift
	}
	enablePadModeLED(uniqueId, 0, -1);
	enablePadModeLED(uniqueId, 1, -1);
	
	sendMidi(uniqueId,0x90,0x03,0x0D,0x00); //mon 1
	sendMidi(uniqueId,0x90,0x03,0x0E,0x00); //mon 2
	sendMidi(uniqueId,0x90,0x03,0x01,0x00); //play
	sendMidi(uniqueId,0x90,0x03,0x02,0x00); //cue
	
	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 deck = channel;
	if(channel == 4)
		deck = 2;
	if(channel == 5)
		deck = 3;
	
	var messageNotProcessed=false;
	switch(status)
	{
	//-----------------------------------------------
	// controllers: sliders, knobs, jog-wheels, encoders ('moving' things)
	case 0xB0:
		switch(data1)
		{		
		// global
		case 0x01:
		switch(channel){
				case 0:
				case 1:
					call('setDeckPitch', channel, 0x7F-data2);
					
					break;
				case 3:
					call('setDeckGain', 0, data2);
					break;
			}
		break;
		case 0x02:
		switch(channel){
				case 0:
				case 1:
					
					if(loopMovePreviousValue[channel] > data2){
					
					call('deckLoopPrev', channel, data2);
					} else {
					call('deckLoopNext', channel, data2);
					}
					
					loopMovePreviousValue[channel] = data2;
					
					break;
				case 3:
					call('setDeckGain', 1, data2);	
					break;
			}
		break;
		case 0x03:
		switch(channel){
				case 0:
				case 1:
					call('setSamplerMasterVolume', data2);
					break;
				case 3:
					break;
			}
		break;
		case 0x04:
		switch(channel){
				case 0:
				case 1://param1
					call('deckFxFlangerP1', channel, data2);
					break;
				case 3:
					break;
			}
		break;
		case 0x05:
		switch(channel){
				case 0:
				case 1://param2
					call('deckFxFlangerDW', channel, data2);
					break;
				case 3:
					call('setDeckEqMid', 0, data2);
					debug('LED SHOULD CHANGE' + (data2).toString());
					
					//sendMidi(uniqueId,0x90,deck,0x1E,0x00);
					break;
			}
		break;
		case 0x06:
			switch(channel){
				case 0:
				case 1:
					if(jogWheelsInScratchMode[channel] && holdingJog[channel]){
						var val1 = data2-0x40;						
						call('scratchDeckJW', channel, val1, 500);
					
					} else {
						var val1 = data2-0x40;
						call('moveDeckJogWheel', channel, val1, 150);
					}
					break;
				case 3:
					call('setDeckEqMid', 1, data2);
					break;
			}
		break;
		case 0x07:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x08:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x09:
		switch(channel){
				case 0:
				case 1:
					
					break;
				case 3:
					call('setDeckEqHigh', 0, data2);
					break;
			}
		break;
		case 0x0A:
		switch(channel){
				case 0:
				case 1:
					
					
					break;
				case 3:
					call('setDeckEqHigh', 1, data2);
					break;
			}
		break;
		case 0x0B:
		switch(channel){
				case 0:
				case 1:
					
					
					break;
				case 3:
					break;
			}
		break;
		case 0x0C:
		switch(channel){
				case 0:
				case 1:
					
					break;
				case 3:
					break;
			}
		break;
		case 0x0D:
		switch(channel){
				case 0:
				case 1:
					
					
					break;
				case 3:
					call('setDeckEqLow', 0, data2);
					break;
			}
		break;
		case 0x0E:
		switch(channel){
				case 0:
				case 1:
					
					
					break;
				case 3:
					call('setDeckEqLow', 1, data2);
					break;
			}
		break;
		case 0x0F:
		switch(channel){
				case 0:
				case 1:
					
					break;
				case 3:
					break;
			}
		break;
		case 0x10:
		switch(channel){
				case 0:
				case 1:
					
					
					break;
				case 3:
					break;
			}
		break;
		case 0x11:
		switch(channel){
				case 0:
				case 1:
					
					break;
				case 3:
					call('setDeckCutoff', 0, data2);
					break;
			}
		break;
		case 0x12:
		switch(channel){
				case 0:
				case 1:
					
					break;
				case 3:
					call('setDeckCutoff', 1, data2);
					break;
			}
		break;
		case 0x13:
		switch(channel){
				case 0:
				case 1:
					
					break;
				case 3:
					break;
			}
		break;
		case 0x14:
		switch(channel){
				case 0:
				case 1:
					
					break;
				case 3:
					break;
			}
		break;
		case 0x15:
		switch(channel){
				case 0:
				case 1:
					
					break;
				case 3:
					call('setDeckVolume', 0, data2);
					break;
			}
		break;
		case 0x16:
		switch(channel){
				case 0:
				case 1:
					
					break;
				case 3:
					call('setDeckVolume', 1, data2);
					break;
			}
		break;
		case 0x17:
		switch(channel){
				case 0:
				case 1:
					
					break;
				case 3:
					break;
			}
		break;
		case 0x18:
		switch(channel){
				case 0:
				case 1:
					
					break;
				case 3:
					break;
			}
		break;
		case 0x19:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					call('setCrossfader', 0x7F-data2);
					break;
			}
		break;
		case 0x1A:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					call('setCuePgmMix', data2);
					break;
			}
		break;
		case 0x1B:
		switch(channel){
				case 0:
				case 1:
					
					break;
				case 3:
					call('setMasterGain', data2);
					break;
			}
		break;
		case 0x1C:
		switch(channel){
				case 0:
				case 1:
					
					break;
				case 3:
					call('setMonitorVolume', data2);
					break;
			}
		break;
		case 0x1D:
		switch(channel){
				case 0:
				case 1:
					
					break;
				case 3:
					break;
			}
		break;
		case 0x1E:
		switch(channel){
				case 0:
				case 1:
					
					break;
				case 3:
					var val1 = (data2>0x40 ? 1 : -1);
					call('lbMoveCursor', val1);
					break;
			}
		break;
		case 0x1F:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x20:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x20:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x21:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x22:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x23:
		switch(channel){
				case 0:
				case 1:
				
					break;
				case 3:
					break;
			}
		break;
		case 0x24:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x25:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x26:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x27:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x28:
		switch(channel){
				case 0:
				case 1:
					
					break;
				case 3:
					break;
			}
		break;
		case 0x29:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x2A:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x2B:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x2C:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x2D:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x2E:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x2F:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x30:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x31:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x32:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x33:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x34:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x35:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x36:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x37:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x38:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x39:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x3A:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x3B:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x3C:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x3D:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x3E:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x3F:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x40:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x41:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x42:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x43:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x44:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x45:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x46:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x47:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x48:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x49:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x4A:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x4B:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x4C:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x4D:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x4E:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x4F:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x50:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x51:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x52:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x53:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x54:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x55:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x56:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x57:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x58:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x59:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x5A:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x5B:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x5C:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x5D:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x5E:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x5F:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		default: messageNotProcessed = true;
		}
		break;
	//-----------------------------------------------
	// note on/off: buttons, switches ('pressing' things)
	case 0x80:
	case 0x90:		
		switch(data1)
		{
		case 0x01:
		switch(channel){
				case 0:
				case 1:
					if(data2)
						call('deckPlayPause', channel, data2);
					break;
				case 3:
					if(data2){
						call('deckLBLoad', 0, data2);
						if(padmode[0] == 0)
							enablePadModeLED(uniqueId, 0, 0);		
					}
						
					sendMidi(uniqueId,0x90,channel,0x01,data2);
					break;
			}
		break;
		case 0x02:
		switch(channel){
				case 0:
				case 1:
					call('deckCue', channel, data2);
					break;
				case 3:
					if(data2){
						call('deckLBLoad', 1, data2);
						if(padmode[1] == 0)
							enablePadModeLED(uniqueId, 1, 0);
					
					}
						
					sendMidi(uniqueId,0x90,channel,0x02,data2);
					break;
			}
		break;
		case 0x03:
		switch(channel){
				case 0:
				case 1:
					call('deckCuePlay', channel, data2);
				
					break;
				case 3:
					break;
			}
		break;
		case 0x04:
		switch(channel){
				case 0:
				case 1:
					if(data2)
						call('deckSync', channel, data2);
					break;
				case 3:
					break;
			}
		break;
		case 0x05:
		switch(channel){
				case 0:
				case 1:
					if(data2)
						call('deckKeyLock', channel, data2);
					break;
				case 3:
					break;
			}
		break;
		case 0x06:
		switch(channel){
				case 0:
				case 1:
					var currentPitchRange = getValue('pitchRange');
					currentPitchRange = currentPitchRange + 1; if(currentPitchRange>6) currentPitchRange = 1;
					call('setPitchRange', currentPitchRange);
					break;
				case 3:
					break;
			}
		break;
		case 0x07:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x08:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x09:
		//debug((padmode).toString());
		//if(data2){							
				//call('deckCuePos1', channel, data2);
				switch(padmode[channel]){
					case 0:
						if(shiftPressed[channel]){
							call('deckCuePos1Clear', channel, data2);
							//debug();
						} else {
							call('deckCuePos1', channel, data2);
							//debug('setting cue 1');
						}
					break;
					case 1:
						call('deckLoop1_8', channel, data2);
					break;
					case 2:
						call('samplerPlay', 1);
					break;
					case 3:
						call('deckLoopInEnd', channel, data2);
					break;
				}
		//}
		break;
		case 0x0A:
		switch(channel){
				case 0:
				case 1:
					//if(data2){							
							//call('deckCuePos1', channel, data2);
							switch(padmode[channel]){
								case 0:
									if(shiftPressed[channel]){
										call('deckCuePos2Clear', channel, data2);
										//debug();
									} else {
										call('deckCuePos2', channel, data2);										
									}
								break;
								case 1:
									call('deckLoop1_4', channel, data2);
								break;
								case 2:
									call('samplerPlay', 2);
								break;
								case 3:
									call('deckLoopInEnd', channel, data2);
								break;
							}
					//}
					break;
				case 3:
					break;
			}
		break;
		case 0x0B:
		switch(channel){
				case 0:
				case 1:
					//if(data2){							
							//call('deckCuePos1', channel, data2);
							switch(padmode[channel]){
								case 0:
									if(shiftPressed[channel]){
										call('deckCuePos3Clear', channel, data2);										
									} else {
										call('deckCuePos3', channel, data2);
									}
								break;
								case 1:
									call('deckLoop1_2', channel, data2);
								break;
								case 2:
									call('samplerPlay', 3);
								break;
								case 3:
									call('deckLoopExit', channel, data2);
								break;
							}
					//}
					
					break;
				case 3:
					break;
			}
		break;
		case 0x0C:
		switch(channel){
				case 0:
				case 1:
					//if(data2){							
							//call('deckCuePos1', channel, data2);
							switch(padmode[channel]){
								case 0:
									if(shiftPressed[channel]){
										call('deckCuePos4Clear', channel, data2);										
									} else {
										call('deckCuePos4', channel, data2);
									}
								break;
								case 1:
									call('deckLoop1', channel, data2);
								break;
								case 2:
									call('samplerPlay', 4);
								break;
								case 3:
									call('deckLoopLess', channel, data2);
								break;
							}
					//}
					
					break;
				case 3:
					break;
			}
		break;
		case 0x0D:
		switch(channel){
				case 0:
				case 1:
					//if(data2){							
							//call('deckCuePos1', channel, data2);
							switch(padmode[channel]){
								case 0:
									if(shiftPressed[channel]){
										call('deckCuePos5Clear', channel, data2);										
									} else {
										call('deckCuePos5', channel, data2);
									}
								break;
								case 1:
									call('deckLoop2', channel, data2);
								break;
								case 2:
									call('samplerPlay', 5);
								break;
								case 3:
									call('deckLoopMore', channel, data2);
								break;
							}
					//}	
					
					break;
				case 3:
					if(data2)					
						call('deckMonitor', 0, data2);
					break;
			}
		break;
		case 0x0E:
		switch(channel){
				case 0:
				case 1:
					//if(data2){							
							//call('deckCuePos1', channel, data2);
							switch(padmode[channel]){
								case 0:
									if(shiftPressed[channel]){
										call('deckCuePos6Clear', channel, data2);										
									} else {
										call('deckCuePos6', channel, data2);
									}
								break;
								case 1:
									call('deckLoop4', channel, data2);
								break;
								case 2:
									call('samplerPlay', 6);
								break;
								case 3:
									
								break;
							}
					//}
					
					break;
				case 3:
					if(data2)					
						call('deckMonitor', 1, data2);
					break;
			}
		break;
		case 0x0F:
		switch(channel){
				case 0:
				case 1:
					//if(data2){							
							//call('deckCuePos1', channel, data2);
							switch(padmode[channel]){
								case 0:
									if(shiftPressed[channel]){
										call('deckCuePos7Clear', channel, data2);										
									} else {
										call('deckCuePos7', channel, data2);
									}
								break;
								case 1:
									call('deckLoop8', channel, data2);
								break;
								case 2:
									call('samplerPlay', 7);
								break;
								case 3:
									
								break;
							}
					//}	
					
					break;
				case 3:
					break;
			}
		break;
		case 0x10:
		switch(channel){
				case 0:
				case 1:
					//if(data2){							
							//call('deckCuePos1', channel, data2);
							switch(padmode[channel]){
								case 0:
									if(shiftPressed[channel]){
										call('deckCuePos8Clear', channel, data2);										
									} else {
										call('deckCuePos8', channel, data2);
									}
								break;
								case 1:
									call('deckLoop16', channel, data2);
								break;
								case 2:
									call('samplerPlay', 8);
								break;
								case 3:
									
								break;
							}
					//}
					break;
				case 3:
					break;
			}
		break;
		case 0x11:
		switch(channel){
				case 0:
				case 1:
					if(data2)
						call('deckCuePos1Clear', channel, data2);
					break;
				case 3:
					if(data2)
						call('lbToggleSelect', data2);
					break;
			}
		break;
		case 0x12:
		switch(channel){
				case 0:
				case 1:
					if(data2)
						call('deckCuePos2Clear', channel, data2);
					break;
				case 3:
					break;
			}
		break;
		case 0x13:
		switch(channel){
				case 0:
				case 1:
					if(data2)	
						call('deckCuePos3Clear', channel, data2);
					break;
				case 3:
					break;
			}
		break;
		case 0x14:
		switch(channel){
				case 0:
				case 1:
					if(data2)
						call('deckCuePos4Clear', channel, data2);
					break;
				case 3:
					break;
			}
		break;
		case 0x15:
		switch(channel){
				case 0:
				case 1:
					if(data2)
						call('deckCuePos5Clear', channel, data2);
					break;
				case 3:
					break;
			}
		break;
		case 0x16:
		switch(channel){
				case 0:
				case 1:
					if(data2)
						call('deckCuePos6Clear', channel, data2);
					break;
				case 3:
					break;
			}
		break;
		case 0x17:
		switch(channel){
				case 0:
				case 1:
					if(data2)
						call('deckCuePos7Clear', channel, data2);
					break;
				case 3:
					break;
			}
		break;
		case 0x18:
		switch(channel){
				case 0:
				case 1:
					if(data2)
						call('deckCuePos8Clear', channel, data2);
					break;
				case 3:
					break;
			}
		break;
		case 0x19:
		switch(channel){
				case 0:
				case 1:
					call('deckReverse', channel, data2);
				
					break;
				case 3:
					break;
			}
		break;
		case 0x1A:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x1B:
		switch(channel){
				case 0:
				case 1:
					if(data2){
						padmode[channel] = 0;
						clearPads(uniqueId, channel);
						enablePadModeLED(uniqueId, deck, padmode[channel]);
					}
					break;
				case 3:
					break;
			}
		break;
		case 0x1C:
		switch(channel){
				case 0:
				case 1:
					if(data2){
						padmode[channel] = 1;
						clearPads(uniqueId, channel);
						enablePadModeLED(uniqueId, deck, padmode[channel]);
					}
					break;
				case 3:
					break;
			}
		break;
		case 0x1D:
		switch(channel){
				case 0:
				case 1:
					if(data2){
						padmode[channel] = 2;
						clearPads(uniqueId, channel);
						enablePadModeLED(uniqueId, deck, padmode[channel]);
					}
					break;
				case 3:
					break;
			}
		break;
		case 0x1E:
		switch(channel){
				case 0:
				case 1:
					if(data2){
						padmode[channel] = 3;
						clearPads(uniqueId, channel);
						enablePadModeLED(uniqueId, deck, padmode[channel]);
					}
					break;
				case 3:
					break;
			}
		break;
		case 0x1F:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x20:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x20:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x21:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x22:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x23:
		switch(channel){
				case 0:
				case 1:
				if(data2){
					jogWheelsInScratchMode[channel] = (jogWheelsInScratchMode[channel] == 0x00 ? 0x7F : 0x00);
					sendMidi(uniqueId,0x90,channel,0x23,jogWheelsInScratchMode[channel]);
				}
					break;
				case 3:
					break;
			}
		break;
		case 0x24:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x25:
		switch(channel){
				case 0:
				case 1:
					if(jogWheelsInScratchMode[channel]){
						holdingJog[channel] = data2;
						call('holdDeckJogWheel', channel, holdingJog[channel]);
					
					}
					break;
				case 3:
					break;
			}
		break;
		case 0x26:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x27:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x28:
		switch(channel){
				case 0:
				case 1:
					shiftPressed[channel] = data2;
					break;
				case 3:
					break;
			}
		break;
		case 0x29:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x2A:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x2B:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x2C:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x2D:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x2E:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x2F:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x30:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x31:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x32:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x33:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x34:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x35:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x36:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x37:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x38:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x39:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x3A:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x3B:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x3C:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x3D:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x3E:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x3F:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x40:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x41:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x42:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x43:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x44:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x45:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x46:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x47:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x48:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x49:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x4A:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x4B:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x4C:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x4D:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x4E:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x4F:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x50:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x51:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x52:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x53:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x54:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x55:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x56:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x57:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x58:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x59:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x5A:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x5B:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x5C:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x5D:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x5E:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		break;
		case 0x5F:
		switch(channel){
				case 0:
				case 1:
					break;
				case 3:
					break;
			}
		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=='play')
		{
			sendMidi(uniqueId,0x90,deck,0X01,(param1 ? 0x7F : 0x00)); //play button
			sendMidi(uniqueId,0x90,deck,0x03,(param1 ? 0x7F : 0x00)); //cup button
	
		}
	if(name=='cue') 		 
		{
			sendMidi(uniqueId,0x90,deck,0x02,(param1 ? 0x7F : 0x00)); // cue			
		}
	if(name=='onbeat') 	 	 sendMidi(uniqueId,0x90,deck,0x04,(param1 ? 0x7F : 0x00)); //sync
	if(name=='monitor') 	 sendMidi(uniqueId,0x90,0X03,deck + 0x0D,(param1 ? 0x7F : 0x00)); //pfl
    if(name=='keyLock') 	 sendMidi(uniqueId,0x90,deck,0x05,(param1 ? 0x7F : 0x00)); //key lock
	if(name=='reverse') 	 sendMidi(uniqueId,0x90,deck,0x19,(param1 ? 0x7F : 0x00));
	if(name=='looppos1'){
		autoLoopMode[deck][0] = (param1 == -1 ? 0x00 : 0x7F);
					
	}
	if(name=='looppos2'){		
		autoLoopMode[deck][1] = (param1 == -1 ? 0x00 : 0x7F);
	}
	if(name=='looppos3'){	
		autoLoopMode[deck][2] = (param1 == -1 ? 0x00 : 0x7F);		
					
	}
	if(name=='looppos4'){		
		autoLoopMode[deck][3] = (param1 == -1 ? 0x00 : 0x7F);
	}
	if(name=='looppos5'){
		autoLoopMode[deck][4] = (param1 == -1 ? 0x00 : 0x7F);
	}
	
	if(name=='loopSize'){
			
			switch(param1){
				case 8:
					autoLoopMode[deck][0] = 0x7F;
					autoLoopMode[deck][1] = 0;					
					autoLoopMode[deck][2] = 0;
					autoLoopMode[deck][3] = 0;
					autoLoopMode[deck][4] = 0;
					autoLoopMode[deck][5] = 0;
					autoLoopMode[deck][6] = 0;
				    autoLoopMode[deck][7] = 0;
					
					break;
				case 16:
					autoLoopMode[deck][0] = 0;
					autoLoopMode[deck][1] = 0x7F;					
					autoLoopMode[deck][2] = 0;
					autoLoopMode[deck][3] = 0;
					autoLoopMode[deck][4] = 0;
					autoLoopMode[deck][5] = 0;
					autoLoopMode[deck][6] = 0;
				    autoLoopMode[deck][7] = 0;
					
					break;
				case 32:
					autoLoopMode[deck][0] = 0;
					autoLoopMode[deck][1] = 0;					
					autoLoopMode[deck][2] = 0x7F;
					autoLoopMode[deck][3] = 0;
					autoLoopMode[deck][4] = 0;
					autoLoopMode[deck][5] = 0;
					autoLoopMode[deck][6] = 0;
				    autoLoopMode[deck][7] = 0;
					
					break;
				case 64:
					autoLoopMode[deck][0] = 0;
					autoLoopMode[deck][1] = 0;
					autoLoopMode[deck][2] = 0;
					autoLoopMode[deck][3] = 0x7F;
					autoLoopMode[deck][4] = 0;
					autoLoopMode[deck][5] = 0;
					autoLoopMode[deck][6] = 0;
				    autoLoopMode[deck][7] = 0;
					
					break;
				case 128:
					autoLoopMode[deck][0] = 0;
					autoLoopMode[deck][1] = 0;
					autoLoopMode[deck][2] = 0;
					autoLoopMode[deck][3] = 0;
					autoLoopMode[deck][4] = 0x7F;
					autoLoopMode[deck][5] = 0;
					autoLoopMode[deck][6] = 0;
				    autoLoopMode[deck][7] = 0;
					
					break;
				case 256:
					autoLoopMode[deck][0] = 0;	
					autoLoopMode[deck][1] = 0;
					autoLoopMode[deck][2] = 0;
					autoLoopMode[deck][3] = 0;
					autoLoopMode[deck][4] = 0;
					autoLoopMode[deck][5] = 0x7F;
					autoLoopMode[deck][6] = 0;
				    autoLoopMode[deck][7] = 0;
					
					break;
				case 512:
					autoLoopMode[deck][0] = 0;
					autoLoopMode[deck][1] = 0;
					autoLoopMode[deck][2] = 0;
					autoLoopMode[deck][3] = 0;
					autoLoopMode[deck][4] = 0;
					autoLoopMode[deck][5] = 0;
					autoLoopMode[deck][6] = 0x7F;
					autoLoopMode[deck][7] = 0;
					
					break;
				case 1024:
					autoLoopMode[deck][0] = 0;
					autoLoopMode[deck][1] = 0;
					autoLoopMode[deck][2] = 0;
					autoLoopMode[deck][3] = 0;
					autoLoopMode[deck][4] = 0;
					autoLoopMode[deck][5] = 0;
					autoLoopMode[deck][6] = 0;
				    autoLoopMode[deck][7] = 0x7F;
					
					break;
				default:
					autoLoopMode[deck][0] = 0;
					autoLoopMode[deck][1] = 0;
					autoLoopMode[deck][2] = 0;
					autoLoopMode[deck][3] = 0;
					autoLoopMode[deck][4] = 0;
					autoLoopMode[deck][5] = 0;
					autoLoopMode[deck][6] = 0;
					autoLoopMode[deck][7] = 0;
					break;
			}
		}
		
	
	if(name=='cuepos1') {
		hotCueMode[deck][0] = (param1 ? 0x7F : 0x00);
	}//cue 1
	if(name=='cuepos2'){ 	 
		hotCueMode[deck][1] = (param1 ? 0x7F : 0x00);
		
	}
	if(name=='cuepos3'){ 
		hotCueMode[deck][2] = (param1 ? 0x7F : 0x00);	
		
	}
	if(name=='cuepos4'){
		hotCueMode[deck][3] = (param1 ? 0x7F : 0x00);	
		
	}
	if(name=='cuepos5'){ 	 
		hotCueMode[deck][4] = (param1 ? 0x7F : 0x00);
		
	}
	if(name=='cuepos6'){ 
		hotCueMode[deck][5] = (param1 ? 0x7F : 0x00);	
		
	}
	if(name=='cuepos7'){ 
		hotCueMode[deck][6] = (param1 ? 0x7F : 0x00);	
		
	}
	if(name=='cuepos8') {
		hotCueMode[deck][7] = (param1 ? 0x7F : 0x00);	
		
	}
		
		
	
	if(nameLen==8)
	{
		var name1 = name.substr(0, nameLen-1);
		
		if(name1=='sampler')
			{	
				//debug('notif ['+uniqueId+'] name='+name + ' deck='+deck + ' p1(int)='+param1 + ' p2(float)='+param2 + ' p3(str)='+param3);
				var samplerIdx = parseInt(name.charAt(nameLen-1))-1;		
				
				samplerBlinkLedStatus[samplerIdx] = 0;
				if(name=='sampler1'){ 
					sampleMode[0][0] = (param2 ? 0x7F : 0x00);
					sampleMode[1][0] = (param2 ? 0x7F : 0x00);
					
				}
				if(name=='sampler2'){ 
					sampleMode[0][1] = (param2 ? 0x7F : 0x00);
					sampleMode[1][1] = (param2 ? 0x7F : 0x00);
					
				}
				if(name=='sampler3'){ 
					sampleMode[0][2] = (param2 ? 0x7F : 0x00);
					sampleMode[1][2] = (param2 ? 0x7F : 0x00);
					
				}
				if(name=='sampler4'){ 
					sampleMode[0][3] = (param2 ? 0x7F : 0x00);
					sampleMode[1][3] = (param2 ? 0x7F : 0x00);
					
				}
				if(name=='sampler5'){
					sampleMode[0][4] = (param2 ? 0x7F : 0x00);
					sampleMode[1][4] = (param2 ? 0x7F : 0x00);
					
				}
				if(name=='sampler6'){
					sampleMode[0][5] = (param2 ? 0x7F : 0x00);
					sampleMode[1][5] = (param2 ? 0x7F : 0x00);
					
				}
				if(name=='sampler7'){ 
					sampleMode[0][6] = (param2 ? 0x7F : 0x00);
					sampleMode[1][6] = (param2 ? 0x7F : 0x00);
					
				}
				if(name=='sampler8'){ 
					sampleMode[0][7] = (param2 ? 0x7F : 0x00);
					sampleMode[1][7] = (param2 ? 0x7F : 0x00);
					
				}				
							
			}
	}
	
	if(name=='loopIn') 	manualLoop[deck] = (param1 ? 1 : 0); //loop in
		if(name=='looping') 	 
				{
					//debug('notif ['+uniqueId+'] name='+name + ' deck='+deck + ' p1(int)='+param1 + ' p2(float)='+param2 + ' p3(str)='+param3);
					if(param1){
						manualLoop[deck] = 2;
					} else {
						manualLoop[deck] = 0;
					}
				}
	if(name=='fxFlanger') 	 sendMidi(uniqueId,0x90,deck,0x1A,(param1 ? 0x7F : 0x00)); //deck FX flanger
	
	
}
//----------------------------------------------------------------------------- 
function getMIDIValueForVU(vu_val)
{
	// translating VU-meter signal from decibels (dB) to 0..127 MIDI range
	//values are between 1 and 10
	var val = 0;
	var step = 12.7;
	if(vu_val>-44) val =  1;
	if(vu_val>-36) val =  2;
	if(vu_val>-28) val =  3;
	if(vu_val>-20) val =  4;
	if(vu_val>-16) val =  5;
	if(vu_val>-12) val =  6;
	if(vu_val> -8) val =  7;
	if(vu_val> -4) val =  8;
	if(vu_val> -2) val =  9;
	if(vu_val> -1) val = 10;
	return Math.floor(val);
}
function getMIDIValueForDeckVU(vu_val)
{
	// translating VU-meter signal from decibels (dB) to 0..127 MIDI range
	//values are between 1 and 10
	var val = 0;
	var step = 12.7;
	//if(vu_val>-44) val =  1 * step;
	if(vu_val>-36) val =  1;
	//if(vu_val>-28) val =  3 * step;
	if(vu_val>-20) val =  2;
	//if(vu_val>-16) val =  5 * step;
	if(vu_val>-12) val =  3;
	//if(vu_val> -8) val =  7 * step;
	if(vu_val> -4) val =  4;
	//if(vu_val> -2) val =  9 * step;
	if(vu_val> -1) val = 5;
	return Math.floor(val);
}
//----------------------------------------------------------------------------- 
// 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 i=0; i<2; i++)
	{	
		var vuDeck = getValue('vumeterDeck', i);// float dB
		sendMidi(uniqueId,0xB0,0x03,0x14+i,getMIDIValueForDeckVU(vuDeck));
	}
	
	var vuMasterLeft = getValue('vumeterMasterL');
	var vuMasterRight = getValue('vumeterMasterR');
	sendMidi(uniqueId,0xB0,0x03,0x18,getMIDIValueForVU(vuMasterLeft));//master left
	sendMidi(uniqueId,0xB0,0x03,0x19,getMIDIValueForVU(vuMasterRight));//master right
		var s = 0;
		for(var d = 0; d <= 1; d++){
			//cue points
			if(padmode[d] == 3){
				debug((manualLoop).toString());
				
				if(manualLoop[d] == 2 || manualLoop[d] == 3){
					manualLoop[d] = (manualLoop[d] == 2 ? 3 : 2);
				}
				
				switch(manualLoop[d]){
					case 0:
						sendMidi(uniqueId,0x90,d,0x09,0x00);
						sendMidi(uniqueId,0x90,d,0x0A,0x00);
						sendMidi(uniqueId,0x90,d,0x0B,0x00);
					break;
					case 1:
						sendMidi(uniqueId,0x90,d,0x09,0x7F);
						sendMidi(uniqueId,0x90,d,0x0A,0x00);
						sendMidi(uniqueId,0x90,d,0x0B,0x00);
					break;
					case 2:
						sendMidi(uniqueId,0x90,d,0x09,0x7F);
						sendMidi(uniqueId,0x90,d,0x0A,0x7F);
						sendMidi(uniqueId,0x90,d,0x0B,0x7F);
					break;
					case 3:
						sendMidi(uniqueId,0x90,d,0x09,0x7F);
						sendMidi(uniqueId,0x90,d,0x0A,0x7F);
						sendMidi(uniqueId,0x90,d,0x0B,0x00);
					break;					
				}
			}
			for(var c = 0; c <= 7; c++){
				s = c;
				if(padmode[d] == 0){
					if(tmphotCueMode[d][c] != hotCueMode[d][c]){
						switch(c){
							case 0:
							sendMidi(uniqueId,0x90,d,0x09,hotCueMode[d][c]);
							break;
							case 1:
							sendMidi(uniqueId,0x90,d,0x0A,hotCueMode[d][c]);
							break;
							case 2:
							sendMidi(uniqueId,0x90,d,0x0B,hotCueMode[d][c]);
							break;
							case 3:
							sendMidi(uniqueId,0x90,d,0x0C,hotCueMode[d][c]);
							break;
							case 4:
							sendMidi(uniqueId,0x90,d,0x0D,hotCueMode[d][c]);
							break;
							case 5:
							sendMidi(uniqueId,0x90,d,0x0E,hotCueMode[d][c]);
							break;
							case 6:
							sendMidi(uniqueId,0x90,d,0x0F,hotCueMode[d][c]);
							break;
							case 7:
							sendMidi(uniqueId,0x90,d,0x10,hotCueMode[d][c]);
							break;
						}
						
					}
					tmphotCueMode[d][c] = hotCueMode[d][c];
				
				}
			
			
			
				if(padmode[d] == 1){
				debug('padmode autoloop');
					 if(tmpautoLoopMode[d][s] != autoLoopMode[d][s]){
						switch(s){
							case 0: //sample 1	
							debug('AutoLoop 0');
							sendMidi(uniqueId,0x90,d,0x09,autoLoopMode[d][s]);
							break;
							case 1:
							debug('AutoLoop 2');
							sendMidi(uniqueId,0x90,d,0x0A,autoLoopMode[d][s]);
							break;
							case 2:
							debug('AutoLoop 3');
								sendMidi(uniqueId,0x90,d,0x0B,autoLoopMode[d][s]);
							break;
							case 3:
							debug('AutoLoop 4');
								sendMidi(uniqueId,0x90,d,0x0C,autoLoopMode[d][s]);
							break;
							case 4:
							debug('AutoLoop 5');
								sendMidi(uniqueId,0x90,d,0x0D,autoLoopMode[d][s]);
							break;
							case 5:
							debug('AutoLoop 6');
								sendMidi(uniqueId,0x90,d,0x0E,autoLoopMode[d][s]);
							break;
							case 6:
							debug('AutoLoop 7');
								sendMidi(uniqueId,0x90,d,0x0F,autoLoopMode[d][s]);
							break;
							case 7:
							debug('AutoLoop 8');
								sendMidi(uniqueId,0x90,d,0x10,autoLoopMode[d][s]);
							break;
						}
					 }
					 tmpautoLoopMode[d][s] = autoLoopMode[d][s];
				}
			
			
			//samples
				if(padmode[d] == 2){
					if (tmpsampleMode[d][s] != sampleMode[d][s]){
						switch(s){ //switch on sample
							case 0: //sample 1
							debug('Deck: '+(d).toString() +' Sample: '+ (s).toString());
							sendMidi(uniqueId,0x90,d,0x09,sampleMode[d][s]);
							break;
							case 1:
							sendMidi(uniqueId,0x90,d,0x0A,sampleMode[d][s]);
							break;
							case 2:
								sendMidi(uniqueId,0x90,d,0x0B,sampleMode[d][s]);
							break;
							case 3:
								sendMidi(uniqueId,0x90,d,0x0C,sampleMode[d][s]);
							break;
							case 4:
								sendMidi(uniqueId,0x90,d,0x0D,sampleMode[d][s]);
							break;
							case 5:
								sendMidi(uniqueId,0x90,d,0x0E,sampleMode[d][s]);
							break;
							case 6:
								sendMidi(uniqueId,0x90,d,0x0F,sampleMode[d][s]);
							break;
							case 7:
								sendMidi(uniqueId,0x90,d,0x10,sampleMode[d][s]);
							break;
						}
						
					} 
					tmpsampleMode[d][s] = sampleMode[d][s];
				}
				
				
			
			}
			
			
		}

}
function clearPads(uniqueId, deck){
	for(var i = 0x09; i <= 0x10; i++){
		sendMidi(uniqueId,0x90,deck,i,0x00);
	}
	tmpsampleMode[deck][0] = 0x00;
	tmpsampleMode[deck][1] = 0x00;
	tmpsampleMode[deck][2] = 0x00;
	tmpsampleMode[deck][3] = 0x00;
	tmpsampleMode[deck][4] = 0x00;
	tmpsampleMode[deck][5] = 0x00;
	tmpsampleMode[deck][6] = 0x00;
	tmpsampleMode[deck][7] = 0x00;
	
	tmpautoLoopMode[deck][0] = 0x00;
	tmpautoLoopMode[deck][1] = 0x00;
	tmpautoLoopMode[deck][2] = 0x00;
	tmpautoLoopMode[deck][3] = 0x00;
	tmpautoLoopMode[deck][4] = 0x00;
	tmpautoLoopMode[deck][5] = 0x00;
	tmpautoLoopMode[deck][6] = 0x00;
	tmpautoLoopMode[deck][7] = 0x00;
	
	tmphotCueMode[deck][0] = 0x00;
	tmphotCueMode[deck][1] = 0x00;
	tmphotCueMode[deck][2] = 0x00;
	tmphotCueMode[deck][3] = 0x00;
	tmphotCueMode[deck][4] = 0x00;
	tmphotCueMode[deck][5] = 0x00;
	tmphotCueMode[deck][6] = 0x00;
	tmphotCueMode[deck][7] = 0x00;
	
	
}

function enablePadModeLED(uniqueId, deck, padmode){
	//debug('Padmode =============================' + (padmode.toString()));
	switch(padmode){
		case -1:
		sendMidi(uniqueId,0x90,deck,0x1B,0x00);
		sendMidi(uniqueId,0x90,deck,0x1C,0x00);
		sendMidi(uniqueId,0x90,deck,0x1D,0x00);
		sendMidi(uniqueId,0x90,deck,0x1E,0x00);
		break;
		case 0:
		sendMidi(uniqueId,0x90,deck,0x1B,0x7F);
		sendMidi(uniqueId,0x90,deck,0x1C,0x00);
		sendMidi(uniqueId,0x90,deck,0x1D,0x00);
		sendMidi(uniqueId,0x90,deck,0x1E,0x00);
		break;
		case 1:
		sendMidi(uniqueId,0x90,deck,0x1B,0x00);
		sendMidi(uniqueId,0x90,deck,0x1C,0x7F);
		sendMidi(uniqueId,0x90,deck,0x1D,0x00);
		sendMidi(uniqueId,0x90,deck,0x1E,0x00);
		break;
		case 2:
		sendMidi(uniqueId,0x90,deck,0x1B,0x00);
		sendMidi(uniqueId,0x90,deck,0x1C,0x00);
		sendMidi(uniqueId,0x90,deck,0x1D,0x7F);
		sendMidi(uniqueId,0x90,deck,0x1E,0x00);
		break;
		case 3:
		sendMidi(uniqueId,0x90,deck,0x1B,0x00);
		sendMidi(uniqueId,0x90,deck,0x1C,0x00);
		sendMidi(uniqueId,0x90,deck,0x1D,0x00);
		sendMidi(uniqueId,0x90,deck,0x1E,0x7F);
		break;
	}
}
//----------------------------------------------------------------------------- 
