home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / Aplikacje_64-bitowe / Mixxx / mixxx-1.9.0-win64.exe / midi / Hercules-DJ-Control-MP3-scripts.js < prev    next >
Text File  |  2010-12-04  |  22KB  |  686 lines

  1. function HerculesMp3 () {}
  2.  
  3. //wheel sensitivity is changing between different versions of Mixxx.
  4. //Change this accordingly.
  5.  
  6. jog_sens = 1;
  7.  
  8. //Warning! setting enable_beats to true, will enable Autobeat lights to flash near a beat. 
  9. //Unfortunately I had to use a buffer to avoid sending signal to the controller too close each other.
  10. //If you enable this feature, leds could not properly work.
  11. //In the future, a function midi.sendShortMsgBuffered() will be implemented in Mixxx code and I will try to fix this.
  12. //Until there, I recommend to not change this setting.
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20. //If you do not know what you are doing, do not change any variable under this comment.
  21.  
  22. HerculesMp3.buttons123Modes = ["kill", "fx", "cue", "loop"];
  23.  
  24.  
  25. HerculesMp3.controls = {
  26. "inputs": {
  27.     0x09: { "channel": 1, "name": "cue", "type": "button" },
  28.     0x03: { "channel": 2, "name": "cue", "type": "button" },
  29.     0x08: { "channel": 1, "name": "play", "type": "button" },
  30.     0x02: { "channel": 2, "name": "play", "type": "button" },
  31.     0x07: { "channel": 1, "name": "fx select", "type": "button", "mode": 0 },
  32.     0x01: { "channel": 2, "name": "fx select", "type": "button", "mode": 0 },
  33.     0x0F: { "channel": 1, "name": "fx 1", "type": "button", "used": false },
  34.     0x10: { "channel": 2, "name": "fx 1", "type": "button", "used": false },
  35.     0x0E: { "channel": 1, "name": "fx 2", "type": "button", "used": false },
  36.     0x11: { "channel": 2, "name": "fx 2", "type": "button", "used": false },
  37.     0x0D: { "channel": 1, "name": "fx 3", "type": "button", "used": false },
  38.     0x12: { "channel": 2, "name": "fx 3", "type": "button", "used": false },
  39.     0x1B: { "channel": 1, "name": "mouse", "type": "button" },
  40.     0x1C: { "channel": 2, "name": "mouse", "type": "button" },
  41.     0x16: { "channel": 1, "name": "master tempo", "type": "button" },
  42.     0x1A: { "channel": 2, "name": "master tempo", "type": "button" },
  43.     0x34: { "channel": 1, "name": "pitch", "type": "pot", "mode": 0 },
  44.     0x35: { "channel": 2, "name": "pitch", "type": "pot", "mode": 0 },
  45.     0x36: { "channel": 1, "name": "wheel", "type": "pot" },
  46.     0x37: { "channel": 2, "name": "wheel", "type": "pot" },
  47.     0x0B: { "channel": 1, "name": "prevtrack", "type": "button" },
  48.     0x0C: { "channel": 1, "name": "nexttrack", "type": "button" },
  49.     0x05: { "channel": 2, "name": "prevtrack", "type": "button" },
  50.     0x06: { "channel": 2, "name": "nexttrack", "type": "button" }
  51. },
  52. "outputs": {
  53.     0x0F: { "channel": 1, "name": "fx mode", "type": "led" , "status": 0x00 , "isblinking": false },
  54.     0x10: { "channel": 2, "name": "fx mode", "type": "led" , "status": 0x00 , "isblinking": false },
  55.     0x0E: { "channel": 1, "name": "cue mode", "type": "led" , "status": 0x00 },
  56.     0x11: { "channel": 2, "name": "cue mode", "type": "led" , "status": 0x00 },
  57.     0x0D: { "channel": 1, "name": "loop mode", "type": "led" , "status": 0x00 },
  58.     0x12: { "channel": 2, "name": "loop mode", "type": "led" , "status": 0x00 },
  59.     0x16: { "channel": 1, "name": "master tempo", "type": "led" , "status": 0x00 },
  60.     0x1A: { "channel": 2, "name": "master tempo", "type": "led" , "status": 0x00 },
  61.     0x0A: { "channel": 1, "name": "auto beat", "type": "led" , "status": 0x00 , "beatlen": 0 },
  62.     0x04: { "channel": 2, "name": "auto beat", "type": "led" , "status": 0x00 , "beatlen": 0 },
  63.     0x09: { "channel": 1, "name": "cue_set", "type": "led" , "status": 0x00 },
  64.     0x03: { "channel": 2, "name": "cue_set", "type": "led" , "status": 0x00 },
  65.     0x00: { "channel": 1, "name": "play blink", "type": "led" , "status": 0x00 },
  66.     0x05: { "channel": 2, "name": "play blink", "type": "led" , "status": 0x00 },
  67.     0x08: { "channel": 1, "name": "play", "type": "led" , "status": 0x00 },
  68.     0x02: { "channel": 2, "name": "play", "type": "led" , "status": 0x00 },
  69.     0x7E: { "channel": 1, "name": "pfl", "type": "led" , "status": 0x00 },
  70.     0x7D: { "channel": 2, "name": "pfl", "type": "led" , "status": 0x00 }
  71. }
  72. };
  73.  
  74.  
  75.  
  76. //Init controller
  77.  
  78. HerculesMp3.init = function (id) { // called when the device is opened & set up
  79.  
  80. //  variables and arrays
  81.     led_lock = false;
  82.     enable_beats = false;
  83.     ledmsg = 0x00;
  84.  
  85.     loopc = [];
  86.     timerloopID = [];
  87.     is_hold_loop=[];
  88.     reloopon = [];
  89.     is_hold_hotcue = [];
  90.     timerhotcueID = [];
  91.     loop_control=[];
  92.     Deck = [];
  93.     scratch = [];
  94.     led_array = [];
  95.     scratch_timer_on = [];
  96.     scratch_timer = [];
  97.     returnblink = [];
  98.     blinktimer = [];
  99.  
  100.     bshot = [];
  101.  
  102.     VLset = [];
  103.     
  104.     for(decks=1;  decks<=2; decks++){
  105.         Deck[decks] = "[Channel"+decks+"]";
  106.         loopc[decks] = 0;
  107.         VLset[decks] = false;
  108.         timerloopID[decks] = 0;
  109.         is_hold_loop[decks] = true;
  110.         reloopon[decks] = false;
  111.         scratch[decks] = false;
  112.         VLset[decks] = false;
  113.         scratch_timer_on[decks]=false;
  114.     }
  115.  
  116.  
  117.  
  118.  
  119.  
  120. //  Messages to the console cannot be sent too close ( < 10ms)
  121. //  So that in other scripts a pause function is used
  122. //  afaik it is not allowed.
  123. //  a timer and a buffer will rectify this.
  124. //  Setting it to 20ms instead of 11ms as this first is the lowest value accepted for a timer.
  125.  
  126.     engine.beginTimer(20, "HerculesMp3.ledhelper()");
  127.  
  128.  
  129. //  Be the leds!
  130.  
  131.     HerculesMp3.leds(true);
  132.     engine.beginTimer(500, "HerculesMp3.leds(false)",true);
  133.  
  134. //  Connect leds here and not in xml. This is to avoid an annoying bug (maybe) in controller drivers.
  135.  
  136.     engine.connectControl("[Channel1]", "pfl", "HerculesMp3.pfl_left");
  137.     engine.connectControl("[Channel2]", "pfl", "HerculesMp3.pfl_right");
  138.     engine.connectControl("[Channel1]", "play", "HerculesMp3.play_left");
  139.     engine.connectControl("[Channel2]", "play", "HerculesMp3.play_right");
  140.     engine.connectControl("[Channel1]", "cue_default", "HerculesMp3.cue_left");
  141.     engine.connectControl("[Channel2]", "cue_default", "HerculesMp3.cue_right");
  142.     //engine.connectControl("[Channel1]", "keylock", "HerculesMp3.master_tempoA");
  143.     //engine.connectControl("[Channel2]", "keylock", "HerculesMp3.master_tempoB");
  144.  
  145.     print ("HerculesMp3 id: \""+id+"\" initialized.");
  146. };
  147.  
  148. //Shutdown the controller.
  149.  
  150. HerculesMp3.shutdown = function (id) {
  151.     HerculesMp3.leds(false);
  152.     print ("HerculesMp3 id: \""+id+"\" shut down.");
  153. };
  154.  
  155.  
  156. //Messages to the console cannot be sent too close ( < 10ms)
  157.  
  158. HerculesMp3.ledhelper = function () {
  159.  
  160. //  What does this function do? It is just an apostrophe between the words "I'll-do".
  161.  
  162.     if(typeof led_array == "undefined"){
  163.         led_array = [];
  164.     }
  165.     if (led_array.length > 0){
  166.         var nowled = led_array[0];
  167.         var nowstatus = HerculesMp3.controls.outputs[nowled].status;
  168.         led_array.shift();
  169.         midi.sendShortMsg(0xB0,nowled,nowstatus);
  170.         //clear buffer if there are too messages
  171.     }
  172. //  beat leds
  173.  
  174.     if(enable_beats){
  175.         var beatA = HerculesMp3.controls.outputs[0x0A].beatlen;
  176.         var beatB = HerculesMp3.controls.outputs[0x04].beatlen;
  177.         if(beatA) HerculesMp3.bblinkA(beatA);
  178.         if(beatB) HerculesMp3.bblinkB(beatB);
  179.     }
  180.  
  181.  
  182. };
  183.  
  184. HerculesMp3.leds = function (onoff) {
  185.     for (control in HerculesMp3.controls.outputs) {
  186.         if (HerculesMp3.controls.outputs[control].type == 'led') {
  187.             HerculesMp3.led(control,onoff);
  188.         }
  189.     }
  190.  
  191. };
  192.  
  193. HerculesMp3.ledblink = function (control,onoff){
  194.     if(onoff) {
  195.         actual_status = HerculesMp3.controls.outputs[control].status;
  196.         blinktimer[control] = engine.beginTimer(300,"HerculesMp3.ledblinkhelper("+control+")");
  197.         HerculesMp3.controls.outputs[control].isblinking = true;
  198.     }
  199.     else
  200.     {
  201.         if (HerculesMp3.controls.outputs[control].isblinking) {
  202.             HerculesMp3.controls.outputs[control].isblinking = false;
  203.             engine.stopTimer(blinktimer[control]);
  204.             HerculesMp3.led(control,actual_status);
  205.         }
  206.     }
  207. };
  208.  
  209. HerculesMp3.ledblinkhelper = function (control){
  210.     var ledval = true;
  211.     if (HerculesMp3.controls.outputs[control].status)
  212.         {
  213.         ledval = false;
  214.         }
  215.     HerculesMp3.led(control,ledval);
  216. };
  217.  
  218. HerculesMp3.pfl_left = function(value) {
  219.     HerculesMp3.led(0x7E, value);
  220. };
  221. HerculesMp3.pfl_right = function(value) {
  222.     HerculesMp3.led(0x7D, value);
  223. };
  224. HerculesMp3.play_left = function(value) {
  225.     HerculesMp3.led(0x08, value);
  226. };
  227. HerculesMp3.play_right = function(value) {
  228.     HerculesMp3.led(0x02, value);
  229. };
  230. HerculesMp3.cue_left = function(value) {
  231.     HerculesMp3.led(0x09, value);
  232. };
  233. HerculesMp3.cue_right = function (value) {
  234.     HerculesMp3.led(0x03, value);
  235.  
  236. };
  237. HerculesMp3.master_tempoA = function (value){
  238.     HerculesMp3.led(0x16, value);
  239. };
  240.  
  241. HerculesMp3.master_tempoB = function (value){
  242.     HerculesMp3.led(0x1A, value);
  243. };
  244.  
  245. HerculesMp3.led = function (control, isOn) {
  246.     ledmsg = 0x00;
  247.     if (isOn){
  248.         ledmsg = 0x7F;
  249.       //Clear buffer when there are too messages
  250.         if(led_array.length > 10) {
  251.             led_array = [];
  252.         }
  253.     }
  254.     if(HerculesMp3.controls.outputs[control].status != ledmsg) {
  255.         led_array.push(control);
  256.         HerculesMp3.controls.outputs[control].status = ledmsg;
  257.     }
  258. };
  259.  
  260.  
  261.  
  262. //loop control
  263.  
  264.  
  265. HerculesMp3.loophold = function (deck) {
  266.  
  267.     is_hold_loop[deck] = true;
  268.     if(engine.getValue("[Channel"+deck+"]","loop_enabled"))
  269.     {
  270.         //problem with skins
  271.         engine.setValue("[Channel"+deck+"]","reloop_exit",1);
  272.         engine.setValue("[Channel"+deck+"]","reloop_exit",0);
  273.     }
  274.     else {
  275.         engine.setValue("[Channel"+deck+"]","reloop_exit",0);
  276.     }
  277.     engine.setValue("[Channel"+deck+"]", "loop_in", 0);
  278.     engine.setValue("[Channel"+deck+"]", "loop_start_position",-1);
  279.     engine.setValue("[Channel"+deck+"]", "loop_out", 0);
  280.     engine.setValue("[Channel"+deck+"]", "loop_end_position",-1);
  281.     loopc[deck] = 0;
  282. };
  283.  
  284.  
  285.  
  286.  
  287. HerculesMp3.loop = function (deck, control, value) {
  288.     if(value) {
  289.         is_hold_loop[deck] = false;
  290.         timerloopID[deck] = engine.beginTimer(700,"HerculesMp3.loophold("+deck+")",true);
  291.     } 
  292.     else {
  293.         engine.stopTimer(timerloopID[deck]);
  294.         if(!is_hold_loop[deck]) {
  295.             loopc[deck]++;
  296.             if(loopc[deck]==1)engine.setValue("[Channel"+deck+"]", "loop_in", 1);
  297.             if(loopc[deck]==2)engine.setValue("[Channel"+deck+"]", "loop_out", 1);
  298.             if(loopc[deck]>2) {
  299.                 engine.setValue("[Channel"+deck+"]", "reloop_exit", 1);
  300.                 loopc[deck]=2;
  301.             }
  302.         }
  303.     }
  304. };
  305.  
  306.  
  307.  
  308. //hotcue control
  309.  
  310. HerculesMp3.fxbutton = function (fxnumber) {
  311.     switch(fxnumber)
  312.     {
  313.         case "fx 1":
  314.             return "hotcue_1_";
  315.             break;
  316.  
  317.         case "fx 2" :
  318.             return "hotcue_2_";
  319.             break;
  320.  
  321.         case "fx 3" :
  322.             return "hotcue_3_";
  323.             break;    
  324.     }
  325.  
  326. };
  327.  
  328. HerculesMp3.hotcue = function (deck, control, value) {
  329.     hotcue_string = HerculesMp3.fxbutton(HerculesMp3.controls.inputs[control].name);
  330.     if(value){
  331.         is_hold_hotcue[control] = false;
  332.         timerhotcueID[control] = engine.beginTimer(500,"HerculesMp3.hchold("+deck+","+control+","+"\""+hotcue_string+"\")",true);
  333.     }
  334.     else {
  335.         engine.stopTimer(timerhotcueID[control]);
  336.         if(!is_hold_hotcue[control]){
  337.             if(!engine.getValue("[Channel"+deck+"]",hotcue_string+"enabled")) {engine.setValue("[Channel"+deck+"]",hotcue_string+"activate",1);}
  338.             else{engine.setValue("[Channel"+deck+"]",hotcue_string+"goto",1);}
  339.         }
  340.     }
  341. };
  342.  
  343.  
  344. HerculesMp3.hchold = function (deck,control,hotcuestr){
  345.     is_hold_hotcue[control]=true;
  346.     engine.setValue("[Channel"+deck+"]",hotcuestr+"clear",1);
  347. };
  348.  
  349.  
  350. //Cycle between kill,cue,loop,fx
  351.  
  352. HerculesMp3.mode = function (group, control, value, status) {
  353.  
  354.  
  355.     var n = HerculesMp3.controls.inputs[control].channel;
  356.  
  357.     var group = Deck[n];
  358.  
  359. //  took from other Hercules scripts
  360.  
  361.     if (value) { // Only do stuff when pushed, not released.
  362.         currentMode = HerculesMp3.controls.inputs[control].mode;
  363.         nextMode = currentMode < HerculesMp3.buttons123Modes.length-1 ? currentMode+1 : 0;
  364.         HerculesMp3.controls.inputs[control].mode = nextMode;
  365.         sNextMode = HerculesMp3.buttons123Modes[nextMode];
  366.         sCurrentMode = HerculesMp3.buttons123Modes[currentMode];
  367.         for ( fxcontrol in HerculesMp3.controls.outputs){
  368.             if(HerculesMp3.controls.outputs[fxcontrol].channel == n && 
  369.                     HerculesMp3.controls.outputs[fxcontrol].name == sCurrentMode+" mode")
  370.             {
  371.                 currentLed = fxcontrol;
  372.             }
  373.             if(HerculesMp3.controls.outputs[fxcontrol].channel == n && 
  374.                     HerculesMp3.controls.outputs[fxcontrol].name == sNextMode+" mode")
  375.             {
  376.                 nextLed = fxcontrol;
  377.             }
  378.         }
  379.         switch (sNextMode) {
  380.             case "kill":
  381.                 HerculesMp3.led(currentLed, false);
  382.                 break;
  383.             case "fx":
  384.                 returnblink[n] = false;
  385.                 if(HerculesMp3.controls.outputs[nextLed].isblinking){
  386.                     HerculesMp3.ledblink(nextLed, false);
  387.                     returnblink[n] = true;
  388.                 }
  389.                 HerculesMp3.led(nextLed, true); 
  390.                 //print("HerculesMp3.buttons123mode: Switching to " + sNextMode + " mode");
  391.                 break;
  392.             case "cue":
  393.                 if(returnblink[n]){
  394.                     HerculesMp3.ledblink(currentLed, true);
  395.                 }
  396.                 HerculesMp3.led(currentLed, false); 
  397.                 HerculesMp3.led(nextLed, true); 
  398.                 //print("HerculesMp3.buttons123mode: Switching to " + sNextMode + " mode");
  399.                 break; 
  400.             case "loop":
  401.                 HerculesMp3.led(currentLed, false); 
  402.                 HerculesMp3.led(nextLed, true); 
  403.                 //print("HerculesMp3.buttons123mode: " + sNextMode + " mode");
  404.                 break;
  405.         }
  406.  
  407.  
  408.     }
  409. };
  410.  
  411. //fx buttons
  412.  
  413.  
  414. HerculesMp3.fx = function (group, control, value, status) {
  415.  
  416.     var n = HerculesMp3.controls.inputs[control].channel;
  417.  
  418.     var fxdeck = n==1 ? 0x07 : 0x01;
  419.  
  420.     var currentMode = HerculesMp3.controls.inputs[fxdeck].mode;
  421.  
  422.     switch (HerculesMp3.buttons123Modes[currentMode]){
  423.         case "kill" :
  424.             if (value){
  425.                 HerculesMp3.controls.inputs[control].used = true;
  426.             }
  427.             else { HerculesMp3.controls.inputs[control].used = false; 
  428.             }
  429.             break;
  430.  
  431.         case "loop" :
  432.  
  433.             HerculesMp3.loop(n, control, value);
  434.  
  435.             break;
  436.  
  437.         case "cue" :
  438.  
  439.             HerculesMp3.hotcue(n, control, value);
  440.  
  441.             break;
  442.  
  443.         case "fx" :
  444.  
  445.             if (HerculesMp3.controls.inputs[control].name == "fx 1"){
  446.                 if(value)
  447.                     {
  448.                     scratch[n]=!scratch[n];
  449.                     HerculesMp3.controls.outputs[nextLed].isblinking = scratch[n];
  450.                     returnblink[n] = scratch[n];
  451.                     }
  452.                 
  453.             }
  454.             if (HerculesMp3.controls.inputs[control].name == "fx 2"){
  455.                 if(value){bpm.tapButton(n);}
  456.             }
  457.             if (HerculesMp3.controls.inputs[control].name == "fx 3"){
  458.                 if(value){
  459.                 enable_beats = !enable_beats;
  460.                 if(enable_beats){
  461.                     engine.connectControl("[Channel1]", "playposition", "HerculesMp3.playpositionA");
  462.                     engine.connectControl("[Channel1]","file_bpm","HerculesMp3.bpconnectA");
  463.                     engine.connectControl("[Channel2]", "playposition", "HerculesMp3.playpositionB");
  464.                     engine.connectControl("[Channel2]","file_bpm","HerculesMp3.bpconnectB");
  465.                 }
  466.                 else
  467.                     {
  468.                     engine.connectControl("[Channel1]", "playposition", "HerculesMp3.playpositionA",true);
  469.                     engine.connectControl("[Channel1]","file_bpm","HerculesMp3.bpconnectA",true);
  470.                     engine.connectControl("[Channel2]", "playposition", "HerculesMp3.playpositionB",true);
  471.                     engine.connectControl("[Channel2]","file_bpm","HerculesMp3.bpconnectB",true);
  472.                     }
  473.                 }
  474.             }
  475.  
  476.             break;
  477.  
  478.     }
  479.  
  480. };
  481.  
  482.  
  483.  
  484. HerculesMp3.pitchpot = function (group, control, value, status) {
  485.  
  486.     var n = HerculesMp3.controls.inputs[control].channel;
  487.     var fxdeck = n ==1 ? 0x07 : 0x01;
  488.  
  489.     var currentMode = HerculesMp3.controls.inputs[fxdeck].mode;
  490.  
  491.     var name = "none";
  492.  
  493.     if (currentMode == 0){
  494.         for ( fxcontrol in HerculesMp3.controls.inputs){
  495.             if(HerculesMp3.controls.inputs[fxcontrol].channel == n && HerculesMp3.controls.inputs[fxcontrol].used)
  496.             {
  497.                 name = HerculesMp3.controls.inputs[fxcontrol].name;
  498.             }
  499.         }
  500.     }
  501.  
  502.     if (name == "fx 1"){ 
  503.         chan = Deck[n];
  504.         action = "pregain";
  505.         min = -4;
  506.         max = 4;
  507.     }
  508.     else if (name == "fx 2"){
  509.         chan = "[Master]";
  510.         action="headVolume";
  511.         min=0;
  512.         max=5;
  513.     }
  514.     else if (name == "fx 3"){
  515.         chan = "[Master]";
  516.         action="headMix";
  517.         min=-1;
  518.         max=1;
  519.     }
  520.     else {
  521.         chan = Deck[n];
  522.         action = "rate";
  523.         min = -1;
  524.         max = 1;
  525.     }
  526.  
  527.  
  528.     if(value){
  529.         var increment = (max-min)/50;
  530.         increment = (value <= 0x3F) ? increment : increment * -1;
  531.         var newValue = engine.getValue(chan,action) + increment;
  532.         newValue = newValue > max ? max : newValue < min ? min : newValue;
  533.         engine.setValue(chan,action,newValue);
  534.     }
  535. };
  536.  
  537.  
  538. HerculesMp3.jog_wheel = function (group, control, value, status) {
  539.     var n = HerculesMp3.controls.inputs[control].channel;
  540.     if(scratch[n]){
  541.         if(value){
  542.             if (scratch_timer_on[n])
  543.             {
  544.                 engine.stopTimer(scratch_timer[n]);
  545.                 scratch_timer_on[n] = false;
  546.             }
  547.             if (!engine.getValue(Deck[n],"scratch2_enable")){
  548.                 engine.scratchEnable(n, 128, 33+1/3, 1.0/8*(0.500), (1.0/8)*(0.500)/32);
  549.             }
  550.             else {
  551.             var newValue=(value-0x40);
  552.             engine.scratchTick(n,-newValue);
  553.             }
  554.         }
  555.  
  556.         if(engine.getValue(Deck[n],"scratch2_enable"))
  557.         {
  558.             //when not moved for 200 msecs, probably we are not touching the wheel anymore
  559.             scratch_timer[n] = engine.beginTimer(200,"HerculesMp3.jog_wheelhelper("+n+")",true);
  560.             scratch_timer_on[n] = true;
  561.         }
  562.     }
  563.     else {
  564.         if(value){
  565.             if (!engine.getValue(Deck[n],"play")) {
  566.                 var jogValue = value >=0x40 ? value - 0x80 : value;
  567.                 jogValue = jogValue*jog_sens;
  568.                 engine.setValue(Deck[n],"jog", jogValue);
  569.                 
  570.             }
  571.         }
  572.     }
  573. };
  574.  
  575.  
  576. HerculesMp3.jog_wheelhelper = function(n) {
  577.     engine.scratchDisable(n);
  578.     scratch_timer_on[n] = false;
  579. }
  580.  
  581. HerculesMp3.joystick = function (group, control, value, status) {
  582.     if(!value) 
  583.         engine.setValue("[Playlist]","SelectPrevTrack", 1);
  584.     if(value == 0x7F) 
  585.         engine.setValue("[Playlist]","SelectNextTrack",1);
  586. };
  587.  
  588.  
  589.  
  590. HerculesMp3.loadSelectedTrack = function (group, control, value, status) {
  591.     if (value) { // Only do stuff when pushed, not released.
  592.         var deck = HerculesMp3.controls.inputs[control].channel;
  593.         engine.setValue(Deck[deck] , "LoadSelectedTrack", 1);
  594.     }
  595. };
  596.  
  597.  
  598. //This is called when bpm is calculated.
  599. //Reusing one function for both decks caused a strange behavior and I am too lazy to fix it.
  600.  
  601. HerculesMp3.bpconnectA = function (valueA) {
  602.        if(valueA){
  603.         HerculesMp3.controls.outputs[0x0A].beatlen = 6000/valueA;
  604.     }
  605.     else    {
  606.         HerculesMp3.controls.outputs[0x0A].beatlen=0;
  607.     }
  608. };
  609.  
  610. HerculesMp3.bpconnectB = function (valueB) {
  611.     if(valueB){
  612.         HerculesMp3.controls.outputs[0x04].beatlen = 6000/valueB;
  613.     }
  614.     else    {
  615.         HerculesMp3.controls.outputs[0x04].beatlen=0;
  616.     }
  617. };
  618.  
  619. //These are for beat blink.
  620.  
  621. HerculesMp3.bblinkA = function (csecA) {
  622.     var actposA = engine.getValue(Deck[1], "duration")*engine.getValue(Deck[1], "playposition")*100;
  623.     if(engine.getValue(Deck[1],"play")){
  624.  
  625.         if(actposA) {
  626.             if( (actposA-csecA/6)<bshot[1]*csecA && actposA>((bshot[1]-1)*csecA) ) {
  627.                 if(!HerculesMp3.controls.outputs[0x0A].status)
  628.                     {HerculesMp3.led(0x0A, true);
  629.                     }
  630.             } 
  631.             if((actposA+csecA/3)>(bshot[1]-1)*csecA && (actposA+csecA/6)<bshot[1]*csecA) {
  632.                 if(HerculesMp3.controls.outputs[0x0A].status) HerculesMp3.led(0x0A, false);
  633.             }
  634.  
  635.         }
  636.     }
  637.     else
  638.     {
  639.         if(HerculesMp3.controls.outputs[0x0A].status)
  640.         {
  641.             HerculesMp3.led(0x0A, false);
  642.         }
  643.     }
  644. };
  645.  
  646. HerculesMp3.bblinkB = function (csecB) {
  647.     var actposB = engine.getValue(Deck[2], "duration")*engine.getValue(Deck[2], "playposition")*100;
  648.     if(engine.getValue(Deck[2],"play")){
  649.  
  650.         if(actposB) {
  651.             if( (actposB-csecB/6)<bshot[2]*csecB && actposB>((bshot[2]-1)*csecB) ) {
  652.                 if(!HerculesMp3.controls.outputs[0x04].status)
  653.                 {HerculesMp3.led(0x04, true);
  654.                 }
  655.             }
  656.             else {
  657.                 if((actposB+csecB/3)>(bshot[2]-1)*csecB && (actposB+csecB/6)<bshot[2]*csecB) {
  658.                     if(HerculesMp3.controls.outputs[0x04].status) HerculesMp3.led(0x04, false);
  659.                 }
  660.             }
  661.  
  662.         }
  663.     }
  664.     else
  665.     {
  666.         if(HerculesMp3.controls.outputs[0x04].status)
  667.         {
  668.             HerculesMp3.led(0x04, false);
  669.         }
  670.     }
  671. };
  672.  
  673. //Find out where the next beat is.
  674.  
  675. HerculesMp3.playpositionA = function (value) {
  676.     actposA = engine.getValue(Deck[1], "duration")*value*100;
  677.     csecA =  HerculesMp3.controls.outputs[0x0A].beatlen;
  678.     if(csecA) bshot[1] = Math.ceil(actposA/csecA);
  679. };
  680.  
  681. HerculesMp3.playpositionB = function (value) {
  682.     actposB = engine.getValue(Deck[2], "duration")*value*100;
  683.     csecB =  HerculesMp3.controls.outputs[0x04].beatlen;
  684.     if(csecB) bshot[2] = Math.ceil(actposB/csecB);
  685. };
  686.