//-----------------------------------------------------------------------------
//-------- Copyright (c)2003-2011. All Rights Reserved. -----------------------
//-----------------------------------------------------------------------------
// file implementing MIDI controller 'Denon DN-MC3000'
//Author: Brandon James
//----------------------------------------------------------------------------- 
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 DN-MC3000";
}
//----------------------------------------------------------------------------- 
// 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 (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 "004003154E5015";
	// F07E??0602004003154E5015????????F7 -- MC3000 (vid 0x154E pid 0x5015)
	// F07E??060200400303006100????????F7 -- MC6000 (vid 0x154E pid 0x5013)
	// F07E7F0602004003154E502131363032F7 -- MC6000 MK2 (vid 0x154E pid 0x5021)
}
//----------------------------------------------------------------------------- 
// 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 "DN-MC3000";// not working
	//return "DENON DJ Controller Midi";// Windows 7
	return false;
}
//----------------------------------------------------------------------------- 
function getSupportedMidiDeviceNameForOutput(osId)
{
	//return "DN-MC3000";// not working
	//return "DENON DJ Controller Midi";// Windows 7
	return false; 
}
//----------------------------------------------------------------------------- 
//----------------------------------------------------------------------------- 
// some variables necessary only for this particular script
var jogWheelsInScratchMode=[0,0,0,0];
var jogWheelsWasDeckPlaying=[0,0,0,0];
//----------------------------------------------------------------------------- 
// 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 MC3000 ['+uniqueId+']');// this outputs a string to DebugView app on Win
	for(var i=0; i<4; i++)
	{
	
		sendMidi(uniqueId,0xB0,0,(getValue('monitor', 0) ? 0x50 : 0x51),0x45);// pfl 1
		sendMidi(uniqueId,0xB0,2,(getValue('monitor', 1) ? 0x50 : 0x51),0x51);// pfl 2
		sendMidi(uniqueId,0xB0,1,(getValue('monitor', 2) ? 0x50 : 0x51),0x4B);// pfl 3
		sendMidi(uniqueId,0xB0,3,(getValue('monitor', 3) ? 0x50 : 0x51),0x57);// pfl 4
		sendMidi(uniqueId,0xB0,0,(getValue('sampler1loaded', 0) ? 0x4A : 0x4B),0x1A);// sampler 1
		sendMidi(uniqueId,0xB0,0,(getValue('sampler2loaded', 0) ? 0x4A : 0x4B),0x1C);// sampler 2
		sendMidi(uniqueId,0xB0,0,(getValue('sampler3loaded', 0) ? 0x4A : 0x4B),0x1F);// sampler 3
		sendMidi(uniqueId,0xB0,0,(getValue('sampler4loaded', 0) ? 0x4A : 0x4B),0x21);// sampler 4
		sendMidi(uniqueId,0xB0,2,(getValue('sampler5loaded', 0) ? 0x4A : 0x4B),0x42);// sampler 5
		sendMidi(uniqueId,0xB0,2,(getValue('sampler6loaded', 0) ? 0x4A : 0x4B),0x44);// sampler 6
		sendMidi(uniqueId,0xB0,2,(getValue('sampler7loaded', 0) ? 0x4A : 0x4B),0x46);// sampler 7
		sendMidi(uniqueId,0xB0,2,(getValue('sampler8loaded', 0) ? 0x4A : 0x4B),0x48);// sampler 8
		//sendMidi(uniqueId,0xB0,0,(getValue('talkOver', 0) ? 0x4A : 0x4B),0x48);// ducking<-causing a crash with updated firmware
		
		
		if(i==2) i = 1;else if(i==1) i = 2;
		{
		
		
		sendMidi(uniqueId,0xB0,i,(getValue('cue', i) ? 0x4A : 0x4B),0x26);// cue
		sendMidi(uniqueId,0xB0,i,(getValue('play', i) ? 0x4C : 0x4B),0x27);// play-pause
		
		sendMidi(uniqueId,0xB0,i,(getValue('cuepos1', i) ? 0x4A : 0x4B),0x11);//cue 1
		sendMidi(uniqueId,0xB0,i,(getValue('cuepos2', i) ? 0x4A : 0x4B),0x13);//cue 2
		sendMidi(uniqueId,0xB0,i,(getValue('cuepos3', i) ? 0x4A : 0x4B),0x15);//cue 3
		sendMidi(uniqueId,0xB0,i,(getValue('cuepos4', i) ? 0x4A : 0x4B),0x17);//cue 4
		sendMidi(uniqueId,0xB0,i,(getValue('cuepos4', i) ? 0x4A : 0x4B),0x30);//cue 5
		sendMidi(uniqueId,0xB0,i,(getValue('cuepos4', i) ? 0x4A : 0x4B),0x32);//cue 6
		sendMidi(uniqueId,0xB0,i,(getValue('cuepos4', i) ? 0x4A : 0x4B),0x34);//cue 7
		sendMidi(uniqueId,0xB0,i,(getValue('cuepos4', i) ? 0x4A : 0x4B),0x36);//cue 8
		sendMidi(uniqueId,0xB0,i,(getValue('keyLock', i) ? 0x4A : 0x4B),0x08);//key lock
		sendMidi(uniqueId,0xB0,i,(getValue('deckSync', i) ? 0x4A : 0x4B),0x09);//sync
		sendMidi(uniqueId,0xB0,i,(getValue('fxFlanger', i) ? 0x4A : 0x4B),0x5C);//flanger 1/3
		sendMidi(uniqueId,0xB0,i,(getValue('fxFlanger', i) ? 0x4A : 0x4B),0x60);//flanger 2/4
		sendMidi(uniqueId,0xB0,i,(getValue('fxPhaser', i) ? 0x4A : 0x4B),0x5D);//Phazer 1/3
		sendMidi(uniqueId,0xB0,i,(getValue('fxPhaser', i) ? 0x4A : 0x4B),0x61);//Phaser 2/4
		sendMidi(uniqueId,0xB0,i,(getValue('fxEcho', i) ? 0x4A : 0x4B),0x5E);//echo 1/3
		sendMidi(uniqueId,0xB0,i,(getValue('fxEcho', i) ? 0x4A : 0x4B),0x62);//echp 2/4
		sendMidi(uniqueId,0xB0,i,(getValue('fxEcho', i) ? 0x4A : 0x4B),0x5F);//echo 1/3
		sendMidi(uniqueId,0xB0,i,(getValue('fxEcho', i) ? 0x4A : 0x4B),0x63);//echp 2/4
		
		sendMidi(uniqueId,0xB0,i,0x4B,0x24);// loop in led
		sendMidi(uniqueId,0xB0,i,0x4B,0x40);//loop out led
		sendMidi(uniqueId,0xB0,i,0x4B,0x2B);// Autoloop  led
		
		}
		
		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 MC3000 ['+uniqueId+']');
	
	for(var i=0; i<4; i++)
	{
		sendMidi(uniqueId,0xB0,0,0x51,0x45); //pfl 1
		sendMidi(uniqueId,0xB0,2,0x51,0x51); //pfl 2
		sendMidi(uniqueId,0xB0,1,0x51,0x4B); //pfl 3
		sendMidi(uniqueId,0xB0,3,0x51,0x57); //pfl 4
		sendMidi(uniqueId,0xB0,0,0x4B,0x1A); //sampler1
		sendMidi(uniqueId,0xB0,0,0x4B,0x1C); //sampler2
		sendMidi(uniqueId,0xB0,0,0x4B,0x1F); //sampler3
		sendMidi(uniqueId,0xB0,2,0x4B,0x21); //sampler4
		sendMidi(uniqueId,0xB0,2,0x4B,0x42); //sampler5
		sendMidi(uniqueId,0xB0,2,0x4B,0x44); //sampler6
		sendMidi(uniqueId,0xB0,2,0x4B,0x46); //sampler7
		sendMidi(uniqueId,0xB0,2,0x4B,0x48); //sampler8
		sendMidi(uniqueId,0xB0,0,0x4B,0x63); //ducking
		
		if(i==2) i = 1;else if(i==1) i = 2;
		{
		sendMidi(uniqueId,0xB0,i,0x4B,0x26);// cue
		sendMidi(uniqueId,0xB0,i,0x4B,0x27);// play-pause
		
		sendMidi(uniqueId,0xB0,i,0x4B,0x11);//cue 1
		sendMidi(uniqueId,0xB0,i,0x4B,0x13);//cue 2
		sendMidi(uniqueId,0xB0,i,0x4B,0x15);//cue 3
		sendMidi(uniqueId,0xB0,i,0x4B,0x17);//cue 4
		sendMidi(uniqueId,0xB0,i,0x4B,0x30);//cue 5
		sendMidi(uniqueId,0xB0,i,0x4B,0x32);//cue 6
		sendMidi(uniqueId,0xB0,i,0x4B,0x34);//cue 7
		sendMidi(uniqueId,0xB0,i,0x4B,0x36);//cue 8
		sendMidi(uniqueId,0xB0,i,0x4B,0x08);//key lock
		sendMidi(uniqueId,0xB0,i,0x4B,0x09);//sync
		sendMidi(uniqueId,0xB0,i,0x4B,0x5C);//flanger 1/3
		sendMidi(uniqueId,0xB0,i,0x4B,0x60);//flanger 2/4
		sendMidi(uniqueId,0xB0,i,0x4B,0x5D);//Phaser 1/3
		sendMidi(uniqueId,0xB0,i,0x4B,0x61);//Phaser 2/4
		sendMidi(uniqueId,0xB0,i,0x4B,0x5E);//echo 1/3
		sendMidi(uniqueId,0xB0,i,0x4B,0x62);//echo 2/4
		sendMidi(uniqueId,0xB0,i,0x4B,0x5F);//beatwaw 1/3
		sendMidi(uniqueId,0xB0,i,0x4B,0x63);//beatwaw 2/4
		
		sendMidi(uniqueId,0xB0,i,0x4B,0x24);// loop in led
		sendMidi(uniqueId,0xB0,i,0x4B,0x40);//loop out led
		sendMidi(uniqueId,0xB0,i,0x4B,0x2B);// Autoloop  led
		}
		
		
		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)
{
	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:  call('setDeckPitch', channel, data2); break; //pitch sliders decks 1-4
	
	case 0xB0:
		switch(data1)
		{
		// global
		case 0x54: if(data2==0) call('lbMoveCursor', 1);else call('lbMoveCursor', -1); break;
			
		case 0x16: call('setCrossfader', data2); break;   // Audio crossfader
		case 0x17: call('setCFVideo', data2); break;   //Video crossfader
		//case 0x19: call('setMasterGain', data2); break;   //master out
		//case 0x44: call('setMonitorGain', data2); break;   //headphone out
		//case 0x1B: call('setPreview', data2); break;   //booth out
		//case 0x43: call('setCuePgmMix', data2); break;   //booth out
		

		// decks
		
		//vol sliders
		case 0x05: call('setDeckVolume', 0, data2); break; // deck 1
		case 0x10: call('setDeckVolume', 1, data2); break; // deck 2
		case 0x0B: call('setDeckVolume', 2, data2); break; // deck 3
		case 0x15: call('setDeckVolume', 3, data2); break; // deck 4
		
		// deck gain
		case 0x01: call('setDeckGain', 0, data2); break; // deck 1
		case 0x0C: call('setDeckGain', 1, data2); break; // deck 2
		case 0x07: call('setDeckGain', 2, data2); break; // deck 3
		case 0x11: call('setDeckGain', 3, data2); break; // deck 4
		
		//eq knob high
		case 0x02: call('setDeckEqHigh', 0, data2); break; // deck 1
		case 0x0D: call('setDeckEqHigh', 1, data2); break; // deck 2
		case 0x08: call('setDeckEqHigh', 2, data2); break; // deck 3
		case 0x12: call('setDeckEqHigh', 3, data2); break; // deck 4
		
		//eq knob mid
		case 0x03: call('setDeckEqMid', 0, data2); break; // deck 1
		case 0x0E: call('setDeckEqMid', 1, data2); break; // deck 2
		case 0x09: call('setDeckEqMid', 2, data2); break; // deck 3
		case 0x13: call('setDeckEqMid', 3, data2); break; // deck 4
		
		//eq knob low
		case 0x04: call('setDeckEqLow', 0, data2); break; // deck 1
		case 0x0F: call('setDeckEqLow', 1, data2); break; // deck 2
		case 0x0A: call('setDeckEqLow', 2, data2); break; // deck 3
		case 0x14: call('setDeckEqLow', 3, data2); break; // deck 4
		
		//HP Filter knob 
		case 0x5D: call('setDeckCutoff', 0, data2); break; // deck 1
		case 0x52: call('setDeckCutoff', 1, data2); break; // deck 2
		case 0x5E: call('setDeckCutoff', 2, data2); break; // deck 3
		case 0x53: call('setDeckCutoff', 3, data2); break; // deck 4
		
		// Deck FX
		case 0x55: call('deckFxFlangerDW', channel, data2); break; // flanger p1 1/3
		case 0x59: call('deckFxFlangerDW', channel, data2); break; // flanger p1 2/4
		case 0x56: call('deckFxPhaserDW', channel, data2); break; // Phaser DW 1/3
		case 0x5A: call('deckFxPhaserDW', channel, data2); break; // Phaser DW 2/4
		case 0x57: call('deckFxEchoDW', channel, data2); break; // echo DW 1/3
		case 0x5B: call('deckFxEchoDW', channel, data2); break; // echo DW 2/4
		case 0x58: call('deckFxBeatwawDW', channel, data2); break; // beatwaw DW 1/3
		case 0x5C: call('deckFxBeatwawDW', channel, data2); break; // beatwaw DW 2/4
		
		//platters
			case 0x51: // params: (deck, increment, total positions per complete revolution) 
			var val1 = data2-0x40;
			if(jogWheelsInScratchMode[channel]) call('scratchDeckJW', channel, val1, 2000);else call('moveDeckJogWheel', channel, val1, 2000);
			break;	
		

		default: messageNotProcessed = true;
		}
		break;
	//-----------------------------------------------
	// note on/off: buttons, switches ('pressing' things)
	case 0x80:
	case 0x90:
		if(data2==0x40) data2 = 0x7F;
		switch(data1)
		{
		// global
		//case 0x47: call('phonesSplit', data2); break; //cue split
		case 0x2A: call('micTalkOver', data2); break; //ducking / talkover
		
		
		// decks
		
		case 0x62: call('deckLBLoad', channel, data2); break; //load deck 1
		case 0x63: call('deckLBLoad', 1, data2); break; //load deck 2
		case 0x01: call('deckMonitor', 0, data2); break; //deck 1 pfl
		case 0x05: call('deckMonitor', 1, data2); break; //deck 2 pfl
		case 0x02: call('deckMonitor', 2, data2); break; //deck 3 pfl
		case 0x07: call('deckMonitor', 3, data2); break; //deck 4 pfl
		
		case 0x43: call('deckPlayPause', channel, data2); break; //play pause decks 1-4
		case 0x42: call('deckCue', channel, data2); break; //cue decks 1-4		   
		case 0x6B: call('deckSync', channel, data2); break; //sync decks 1-4				   
		case 0x0C: call('deckBendUp', channel, data2); break; //bend up decks 1-4				
		case 0x0D: call('deckBendDown', channel, data2); break; //bend down decks 1-4				   
		case 0x11: call('deckSkipBeatPrev', channel, data2); break; //beat skip back decks 1-4				   
		case 0x10: call('deckSkipBeatNext', channel, data2); break; //beat skip back decks 1-4				
		case 0x17: call('deckCuePos1', channel, data2); break; //cue 1 decks 1-4					   
		case 0x18: call('deckCuePos2', channel, data2); break; //cue 2 decks 1-4				   
		case 0x19: call('deckCuePos3', channel, data2); break; //cue 3 decks 1-4						   
		case 0x20: call('deckCuePos4', channel, data2); break; //cue 4 decks 1-4
		case 0x48: call('deckCuePos5', channel, data2); break; //cue 5 decks 1-4
		case 0x49: call('deckCuePos6', channel, data2); break; //cue 6 decks 1-4
		case 0x4A: call('deckCuePos7', channel, data2); break; //cue 7 decks 1-4
		case 0x4B: call('deckCuePos8', channel, data2); break; //cue 8 decks 1-4
		case 0x06: call('deckKeyLock', channel, data2); break; //key lock decks 1-4	
		case 0x37: call('deckLoopInEnd', channel, data2); break; //loop in / end decks 1-4					   
		case 0x39: if(!getValue('looping', channel)) call('deckLoopInEnd', channel, data2);else call('deckLoopExit', channel, data2); break; //loop out or exit
		case 0x1D: call('deckLoop4', channel, data2); break; //auto 4 beat loop / end decks 1-4				   
		case 0x69: call('deckLoopLess', channel, data2); break; //loop less  decks 1-4
		case 0x6A: call('deckLoopMore', channel, data2); break; //loop more decks 1-4					   
		case 0x60: call('deckCuePosClear', channel, data2); break; //clear current cue  decks 1-4
		case 0x15: call('deckFxFlanger', channel, data2); break; //decks flanger 1/3
		case 0x55: call('deckFxFlanger', channel, data2); break; //decks flanger 2/4
		case 0x12: call('deckFxPhaser', channel, data2); break; //decks phazer 1/3
		case 0x52: call('deckFxPhaser', channel, data2); break; //decks phazer 2/4
		case 0x13: call('deckFxEcho', channel, data2); break; //decks echo 1/3
		case 0x53: call('deckFxEcho', channel, data2); break; //decks echo 2/4
		case 0x14: call('deckFxBeatwaw', channel, data2); break; //decks beatwaw 1/3
		case 0x54: call('deckFxBeatwaw', channel, data2); break; //decks beatwaw 2/4
		
		case 0x51: 
			jogWheelsInScratchMode[channel] = (jogWheelsInScratchMode[channel]+1) % 2; // keep the remainder to toggle between scratch mode "0" or jog bend mode "1"
			call('holdDeckJogWheel', channel, jogWheelsInScratchMode[channel]);			

		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);
	

	if(name=='sampler1') sendMidi(uniqueId,0xB0,0,(param1 ? 0x4A : 0x4B),0x1A); //sampler1
	if(name=='sampler2') sendMidi(uniqueId,0xB0,0,(param1 ? 0x4A : 0x4B),0x1C); //sampler2
	if(name=='sampler3') sendMidi(uniqueId,0xB0,0,(param1 ? 0x4A : 0x4B),0x1F); //sampler3
	if(name=='sampler4') sendMidi(uniqueId,0xB0,0,(param1 ? 0x4A : 0x4B),0x21); //sampler4
	if(name=='sampler5') sendMidi(uniqueId,0xB0,2,(param1 ? 0x4A : 0x4B),0x42); //sampler5
	if(name=='sampler6') sendMidi(uniqueId,0xB0,2,(param1 ? 0x4A : 0x4B),0x44); //sampler6
	if(name=='sampler7') sendMidi(uniqueId,0xB0,2,(param1 ? 0x4A : 0x4B),0x46); //sampler7
	if(name=='sampler8') sendMidi(uniqueId,0xB0,2,(param1 ? 0x4A : 0x4B),0x48); //sampler8
	if(name=='talkOver') sendMidi(uniqueId,0xB0,0,(param1 ? 0x4A : 0x4B),0x63); //talk over / ducking

		
		
	if(deck<4)
	{
	
		if(name=='monitor')
				{
					if(deck==0)	sendMidi(uniqueId,0xB0,0,(param1 ? 0x50 : 0x51),0x45);	
					if(deck==1)	sendMidi(uniqueId,0xB0,2,(param1 ? 0x50 : 0x51),0x51);
					if(deck==2)	sendMidi(uniqueId,0xB0,1,(param1 ? 0x50 : 0x51),0x4B);
					if(deck==3)	sendMidi(uniqueId,0xB0,3,(param1 ? 0x50 : 0x51),0x57);
				}
		
		
		if(deck==2) deck = 1;else if(deck==1) deck = 2; // switch to deck specific channels
			{
			if(name=='cue') 		 sendMidi(uniqueId,0xB0,deck,(param1 ? 0x4A : 0x4B),0x26); // cue
			if(name=='play') 		 sendMidi(uniqueId,0xB0,deck,(param1 ? 0x4A : 0x4B),0x27); //play
			if(name=='cuepos1') 	 sendMidi(uniqueId,0xB0,deck,(param1 ? 0x4A : 0x4B),0x11);//cue 1
			if(name=='cuepos2') 	 sendMidi(uniqueId,0xB0,deck,(param1 ? 0x4A : 0x4B),0x13); //cue 2
			if(name=='cuepos3') 	 sendMidi(uniqueId,0xB0,deck,(param1 ? 0x4A : 0x4B),0x15); //cue 3
			if(name=='cuepos4') 	 sendMidi(uniqueId,0xB0,deck,(param1 ? 0x4A : 0x4B),0x17); //cue 4
			if(name=='cuepos5') 	 sendMidi(uniqueId,0xB0,deck,(param1 ? 0x4A : 0x4B),0x30); //cue 5
			if(name=='cuepos6') 	 sendMidi(uniqueId,0xB0,deck,(param1 ? 0x4A : 0x4B),0x32); //cue 6
			if(name=='cuepos7') 	 sendMidi(uniqueId,0xB0,deck,(param1 ? 0x4A : 0x4B),0x34); //cue 7
			if(name=='cuepos8') 	 sendMidi(uniqueId,0xB0,deck,(param1 ? 0x4A : 0x4B),0x36); //cue 8
			if(name=='loopIn') 	 	 sendMidi(uniqueId,0xB0,deck,(param1 ? 0x4A : 0x4B),0x24); //loop in
			if(name=='looping') 	 
				{
				sendMidi(uniqueId,0xB0,deck,(param1 ? 0x4C : 0x4B),0x24);// loop in blink led
				sendMidi(uniqueId,0xB0,deck,(param1 ? 0x4C : 0x4B),0x40);//loop out blink led
				sendMidi(uniqueId,0xB0,deck,(param1 ? 0x4A : 0x4B),0x2B);// auto loop blink led
				}
			if(name=='onbeat') 		sendMidi(uniqueId,0xB0,deck,(param1 ? 0x4A : 0x4B),0x09); //on beat
			if(name=='keyLock') 	sendMidi(uniqueId,0xB0,deck,(param1 ? 0x4A : 0x4B),0x08); //keylock
			if(name=='fxFlanger') 	sendMidi(uniqueId,0xB0,deck,(param1 ? 0x4A : 0x4B),0x5C); //flanger 1/3
			if(name=='fxFlanger') 	sendMidi(uniqueId,0xB0,deck,(param1 ? 0x4A : 0x4B),0x60); //flanger 2/4
			if(name=='fxPhaser') 	sendMidi(uniqueId,0xB0,deck,(param1 ? 0x4A : 0x4B),0x5D); //phazer 1/3
			if(name=='fxPhaser') 	sendMidi(uniqueId,0xB0,deck,(param1 ? 0x4A : 0x4B),0x61); //phazer 2/4
			if(name=='fxEcho') 	sendMidi(uniqueId,0xB0,deck,(param1 ? 0x4A : 0x4B),0x5E); //echo 1/3
			if(name=='fxEcho') 	sendMidi(uniqueId,0xB0,deck,(param1 ? 0x4A : 0x4B),0x62); //echo 2/4
			if(name=='fxBeatwaw') 	sendMidi(uniqueId,0xB0,deck,(param1 ? 0x4A : 0x4B),0x5F); //echo 1/3
			if(name=='fxBeatwaw') 	sendMidi(uniqueId,0xB0,deck,(param1 ? 0x4A : 0x4B),0x63); //echo 2/4
			
			}

	}
	

}
//----------------------------------------------------------------------------- 
function setVUValueForDeck(uniqueId, deck, dbValue)
{

	//var baseLed = 0x0A;// deck 1
	//if(deck==1) baseLed = 0x2A;// deck 2
	//if(deck==2) baseLed = 0x1A;// deck 3
	//if(deck==3) baseLed = 0x3A;// deck 4
	var vuCurrent=[-16,-12,-8,-6,-4,-2,-0];
	var param1=false;
	for(var i=0; i<7; i++)
		{
		if(dbValue>=vuCurrent[i]) param1 = true;else param1 = false;
			{
				if(deck==0)	sendMidi(uniqueId,0xB0,0,(param1 ? 0x50 : 0x51), 0x0A + i);
				if(deck==1)	sendMidi(uniqueId,0xB0,2,(param1 ? 0x50 : 0x51), 0x2A + i);
				//if(deck==2)	sendMidi(uniqueId,0xB0,1,(param1 ? 0x50 : 0x51), 0x1A + i);
				//if(deck==3)	sendMidi(uniqueId,0xB0,3,(param1 ? 0x50 : 0x51), 0x3A + i);
			}		
		}

}
//----------------------------------------------------------------------------- 
// 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)
{
	//debug('timerTick ['+uniqueId+']');


	for(var deck=0; deck<4; deck++)
	{
		var dbValue = getValue('vumeterDeck', deck);// float dB
		setVUValueForDeck(uniqueId, deck, dbValue);	
	}
	
	
}
//----------------------------------------------------------------------------- 
//  		var vuDeck = getValue('vumeterDeck', i);// float dB
	//	sendMidi(uniqueId,0xB0,i+2,17,getMIDIValueForVU(vuDeck));
	// sendMidi(uniqueId,0xB0,0,(getValue('monitor', 0) ? 0x50 : 0x51),0x45);
	
	
	
	