//-------------------------
//-------- by M0M0 --------
//-------------------------
// for MIDI controller 'Denon HC1000S'
//------------------------------------
function getLanguageVersion()
{
   return 1;
}
function getFileVersion()
{
   return 1;
}
function getControllerUserFriendlyName()
{
   return "DN-HC1000S";
}
function getControllerType()
{
   return 'midi';
}
function getSupportedMidiSysExIdString(osId)
{
   return false;
}
function getSupportedMidiDeviceNameForInput(osId)
{
   return "DN-HC1000S";
}
function getSupportedMidiDeviceNameForOutput(osId)
{
   return false;
}
function getSupportedHidDeviceVID(osId)
{
   return false;
}
function getSupportedHidDevicePID(osId)
{
   return false;
}
function getSupportedHidDeviceName(osId)
{
   return false;
}
function controllerInit(uniqueId)
{
   debug('controllerInit DN-HC1000S ['+uniqueId+']');
}
//-----------------------------------------------------------------------------

function controllerDeinit(uniqueId)
{
   debug('controllerDeinit DN-HC1000S ['+uniqueId+']');
}   

function messageReceived(uniqueId,status,channel,data1,data2)
{
   var messageNotProcessed=false;
   switch(status)
   {
   
   
   case 0xB0:
      switch(data1)
      {
      // global
      case 0x54: call('lbMoveCursor', data2==0x7F ? -1:1); break; //library curser up down      

      case 0x5A: call('setDeckCutoff', data2==0x7F); break; //filter

      default: messageNotProcessed = true;
      }
      break;
      
      
   case 0x80:
   case 0x90:
      if(status==0x90) data2 = 0x40;
      if(status==0x80) data2 = 0;
      switch(channel)
      {
         // program 1
         case 0:
         
         
         
         switch(data1)
         {
         
         //global
         
         case 0x30: call('lbToggleSelect', 0, data2); break;
      
   
         // deck A
         case 0x45: call('deckCue', 0, data2); break;
         case 0x1D: call('deckPlayPause', 0, data2); break;
         case 0x37: call('deckLoopInEnd', 0, data2); break;
         case 0x07: call('deckSync', 0, data2); break;
         case 0x39: call('deckLoopExit', 0, data2); break;
         case 0x0D: call('deckLoopPrev', 0, data2); break;
         case 0x0C: call('deckLoopNext', 0, data2); break;
         case 0x17: call('deckCuePos1', 0, data2); break;
         case 0x18: call('deckCuePos2', 0, data2); break;
         case 0x19: call('deckCuePos3', 0, data2); break;
         case 0x20: call('deckCuePos4', 0, data2); break;
         case 0x21: call('deckCuePos5', 0, data2); break;
         case 0x11: call('deckBendDown', 0, data2); break;
         case 0x10: call('deckBendUp', 0, data2); break;
         case 0x40: call('deckLoopMore', 0, data2); break;
         case 0x62: call('deckLoadNext', 0, data2); break;
         case 0x64: call('deckAnalogIn', 0, data2); break;
         case 0x65: call('deckTimecodeIn', 0, data2); break;
         case 0x61: call('deckEqLowKill', 0, data2); break;
         case 0x06: call('deckKeyLock', 0, data2); break;
         
         // deck B
         case 0x7E: call('deckCue', 1, data2); break;
         case 0x7A: call('deckPlayPause', 1, data2); break;
         case 0x5F: call('deckSync', 1, data2); break;
         case 0x7B: call('deckLoopInEnd', 1, data2); break;
         case 0x7C: call('deckLoopExit', 1, data2); break;
         case 0x71: call('deckLoopPrev', 1, data2); break;
         case 0x70: call('deckLoopNext', 1, data2); break;
         case 0x75: call('deckCuePos1', 1, data2); break;
         case 0x76: call('deckCuePos2', 1, data2); break;
         case 0x77: call('deckCuePos3', 1, data2); break;
         case 0x78: call('deckCuePos4', 1, data2); break;
         case 0x79: call('deckCuePos5', 1, data2); break;         
         case 0x73: call('deckBendDown', 1, data2); break;
         case 0x72: call('deckBendUp', 1, data2); break;
         case 0x7D: call('deckLoopMore', 1, data2); break;
         case 0x63: call('deckLoadNext', 1, data2); break;
         case 0x66: call('deckAnalogIn', 1, data2); break;
         case 0x67: call('deckTimecodeIn', 1, data2); break;
         case 0x7F: call('deckEqLowKill', 1, data2); break;
         case 0x5E: call('deckKeyLock', 1, data2); 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)
{
   
   //Deck a
   
      if(name=='play')         sendMidi(uniqueId,0xB0,deck==1,(param1 ? 0x4A : 0x4B), 0x2B);
      if(name=='onbeat')         sendMidi(uniqueId,0xB0,deck==1,(param1 ? 0x4A : 0x4B), 0x09);
      if(name=='cuepos1')         sendMidi(uniqueId,0xB0,deck==1,(param1 ? 0x4A : 0x4B), 0x11);
      if(name=='cuepos2')         sendMidi(uniqueId,0xB0,deck==1,(param1 ? 0x4A : 0x4B), 0x13);
      if(name=='cuepos3')         sendMidi(uniqueId,0xB0,deck==1,(param1 ? 0x4A : 0x4B), 0x15);
      if(name=='cuepos4')         sendMidi(uniqueId,0xB0,deck==1,(param1 ? 0x4A : 0x4B), 0x17);
      if(name=='cuepos5')         sendMidi(uniqueId,0xB0,deck==1,(param1 ? 0x4A : 0x4B), 0x19);
      if(name=='loopIn')         sendMidi(uniqueId,0xB0,deck==1,(param1 ? 0x4A : 0x4B), 0x24);
      if(name=='looping')         sendMidi(uniqueId,0xB0,deck==1,(param1 ? 0x4A : 0x4B), 0x40);
      
   //Decb b
   
      if(name=='play')         sendMidi(uniqueId,0xB0,deck==0,(param1 ? 0x4A : 0x4B), 0x6F);
      if(name=='onbeat')         sendMidi(uniqueId,0xB0,deck==0,(param1 ? 0x4A : 0x4B), 0x60);
      if(name=='cuepos1')         sendMidi(uniqueId,0xB0,deck==0,(param1 ? 0x4A : 0x4B), 0x61);
      if(name=='cuepos2')         sendMidi(uniqueId,0xB0,deck==0,(param1 ? 0x4A : 0x4B), 0x63);
      if(name=='cuepos3')         sendMidi(uniqueId,0xB0,deck==0,(param1 ? 0x4A : 0x4B), 0x65);
      if(name=='cuepos4')         sendMidi(uniqueId,0xB0,deck==0,(param1 ? 0x4A : 0x4B), 0x67);
      if(name=='cuepos5')         sendMidi(uniqueId,0xB0,deck==0,(param1 ? 0x4A : 0x4B), 0x69);
      if(name=='loopIn')         sendMidi(uniqueId,0xB0,deck==0,(param1 ? 0x4A : 0x4B), 0x6B);
      if(name=='looping')         sendMidi(uniqueId,0xB0,deck==0,(param1 ? 0x4A : 0x4B), 0x6D);
      

}
function timerTick(uniqueId)
{
//for(var i=0; i<2; i++)
   //debug('timerTick ['+uniqueId+']');
}