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-Steel-scripts.js < prev    next >
Text File  |  2010-12-04  |  39KB  |  1,026 lines

  1. /**
  2.  * Hercules DJ Control Steel controller script v1.8.1
  3.  * Copyright (C) 2010  Anders Gunnarsson for DJ Console RMX
  4.  * Copyright (C) 2010  Stephane List for DJ Control Steel adaptation
  5.  *
  6.  * This program is free software; you can redistribute it and/or
  7.  * modify it under the terms of the GNU General Public License
  8.  * as published by the Free Software Foundation; either version 2
  9.  * of the License, or (at your option) any later version.
  10.  * 
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  * 
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  19.  **/
  20.  
  21. /** Changelog
  22.  
  23. v0.2 10/16/2010 invert led light for cueSelect
  24. v0.1 10/09/2010 First public release
  25.  
  26. **/
  27.  
  28. //TODO: Cleanup, create objects from init. 
  29. //Remove led timers when alsa midi is working properly.
  30. HerculesSteel = new function() {
  31.     this.group = "[Master]";
  32.     this.shiftMode = false;
  33.     this.scratchMode = false;
  34.     this.jogPlaylistScrollMode = false;
  35.     this.Controls = [];
  36.     this.Buttons = [];
  37. };
  38.  
  39. HerculesSteel.addButton = function(buttonName, button, eventHandler) {
  40.     if(eventHandler) {
  41.         var executionEnvironment = this;
  42.         function handler(value) {
  43.             button.state = value;
  44.             executionEnvironment[eventHandler](value);
  45.         }
  46.         button.handler = handler;
  47.     }
  48.     this.Buttons[buttonName] = button; 
  49. };
  50.  
  51. HerculesSteel.setControlValue = function(control, value) {
  52.     this.Controls[control].setValue(this.group, value);
  53. };
  54.  
  55.  
  56. HerculesSteel.ButtonState = {"released":0x00, "pressed":0x7F};
  57. HerculesSteel.LedState =  {"off": 0x00, "on": 0x7F, "blink": 0xFF};
  58. HerculesSteel.Button = function (controlId, blinkId) {
  59.     this.controlId = controlId;
  60.     this.blinkId = blinkId;
  61.     this.state = HerculesSteel.ButtonState.released;
  62. };
  63.  
  64.     HerculesSteel.Button.prototype.setLed = function(lightState) {
  65.         if(lightState == HerculesSteel.LedState.on) 
  66.         {
  67.             engine.beginTimer(20, "midi.sendShortMsg(0xB0," + (this.controlId) + ", " + HerculesSteel.LedState.on + ")", true);
  68.         }
  69.         else if(lightState == HerculesSteel.LedState.blink)
  70.         {
  71.             engine.beginTimer(20, "midi.sendShortMsg(0xB0," + (this.controlId + 0x30) + ", " + HerculesSteel.LedState.on + ")", true);
  72.         }
  73.         else
  74.         {
  75.             engine.beginTimer(20, "midi.sendShortMsg(0xB0," + (this.controlId) + ", " + HerculesSteel.LedState.off + ")", true);
  76.             engine.beginTimer(40, "midi.sendShortMsg(0xB0," + (this.controlId + 0x30) + ", " + HerculesSteel.LedState.off + ")", true);
  77.         }
  78.     };
  79.  
  80. HerculesSteel.Button.prototype.handleEvent = function(value) {
  81.     this.handler(value);
  82. };
  83.  
  84. HerculesSteel.Control = function(mappedFunction, softMode) {
  85.     this.minInput = 0;
  86.     this.midInput = 0x3F;
  87.     this.maxInput = 0x7F;
  88.     this.minOutput = -1.0;
  89.     this.midOutput = 0.0;
  90.     this.maxOutput = 1.0;
  91.     this.mappedFunction = mappedFunction;
  92.     this.softMode = softMode;
  93.     this.maxJump = 10;
  94. };
  95.  
  96. HerculesSteel.Control.prototype.setValue = function(group, inputValue){
  97.     var outputValue = 0;
  98.     if(inputValue <= this.midInput){
  99.         outputValue = this.minOutput + ((inputValue - this.minInput) / (this.midInput - this.minInput)) * (this.midOutput - this.minOutput);
  100.     } else {
  101.         outputValue = this.midOutput + ((inputValue - this.midInput) / (this.maxInput - this.midInput)) * (this.maxOutput - this.midOutput);
  102.     }
  103.     if(this.softMode){ 
  104.         var currentValue = engine.getValue(group, this.mappedFunction);
  105.         var currentRelative = 0.0;
  106.         if(currentValue <= this.midOutput){
  107.             currentRelative = this.minInput + ((currentValue - this.minOutput) / (this.midOutput - this.minOutput)) * (this.midInput - this.minInput);
  108.         } else {
  109.             currentRelative = this.midInput + ((currentValue - this.midOutput) / (this.maxOutput - this.midOutput)) * (this.maxInput - this.midInput);
  110.         }
  111.         if(inputValue > currentRelative - this.maxJump && inputValue < currentRelative + this.maxJump) {
  112.             engine.setValue(group, this.mappedFunction, outputValue);
  113.         }
  114.     } else {
  115.         engine.setValue(group, this.mappedFunction, outputValue);
  116.     }
  117. };
  118.  
  119. HerculesSteel.shiftHandler = function(value) {
  120.     if(value == HerculesSteel.ButtonState.pressed) {
  121.  
  122.         print("shiftMode = true");
  123.         this.shiftMode = true;
  124.         if(HerculesSteel.scratchMode) {
  125.             HerculesSteel.scratchMode = false;
  126.             HerculesSteel.Buttons.Scratch.setLed(HerculesSteel.LedState.off);
  127.         } else {
  128.             HerculesSteel.scratchMode = true;
  129.             HerculesSteel.Buttons.Scratch.setLed(HerculesSteel.LedState.on);
  130.         }
  131.     } else {
  132.         print("shiftMode = false");
  133.         this.shiftMode = false;
  134.     }
  135. };
  136.  
  137. HerculesSteel.upHandler = function(value) {
  138.     this.jogPlaylistScrollMode = this.Buttons.Up.state + this.Buttons.Down.state > 0;
  139.     if(value == HerculesSteel.ButtonState.pressed) {
  140.         engine.setValue("[Playlist]", "SelectPrevTrack", 1);
  141.     }
  142. };
  143.  
  144. HerculesSteel.downHandler = function(value) {
  145.     this.jogPlaylistScrollMode = this.Buttons.Up.state + this.Buttons.Down.state > 0;
  146.     if(value == HerculesSteel.ButtonState.pressed) {
  147.         engine.setValue("[Playlist]", "SelectNextTrack", 1);
  148.     }
  149. };
  150.  
  151. HerculesSteel.leftHandler = function(value) {
  152.     if(value == HerculesSteel.ButtonState.pressed) {
  153.         engine.setValue("[Playlist]", "SelectPrevPlaylist", 1);
  154.     }
  155. };
  156.  
  157. HerculesSteel.rightHandler = function(value) {
  158.     if(value == HerculesSteel.ButtonState.pressed) {
  159.         engine.setValue("[Playlist]", "SelectNextPlaylist", 1);
  160.     }
  161. };
  162.  
  163. HerculesSteel.addButton("Scratch", new HerculesSteel.Button(0x29), "shiftHandler");
  164. HerculesSteel.addButton("Up", new HerculesSteel.Button(0x2A), "upHandler");
  165. HerculesSteel.addButton("Down", new HerculesSteel.Button(0x2B), "downHandler");
  166. HerculesSteel.addButton("Left", new HerculesSteel.Button(0x2C), "leftHandler");
  167. HerculesSteel.addButton("Right", new HerculesSteel.Button(0x2D), "rightHandler");
  168.  
  169. HerculesSteel.Controls = {
  170.     "Balance" : new HerculesSteel.Control("balance", false),
  171.     "Volume" : new HerculesSteel.Control("volume", false),
  172.     "CrossFader" : new HerculesSteel.Control("crossfader", false),
  173.     "HeadPhoneMix" : new HerculesSteel.Control("headMix", false),
  174.     "FlangerDepth" : new HerculesSteel.Control("lfoDepth", false),
  175.     "FlangerDelay" : new HerculesSteel.Control("lfoDelay", false),
  176.     "FlangerPeriod" : new HerculesSteel.Control("lfoPeriod", false)
  177. };
  178. HerculesSteel.Controls.Volume.minOutput = 0.0;
  179. HerculesSteel.Controls.Volume.midOutput = 1.0;
  180. HerculesSteel.Controls.Volume.maxOutput = 5.0;
  181. HerculesSteel.Controls.FlangerDepth.minOutput = 0.0;
  182. HerculesSteel.Controls.FlangerDepth.midOutput = 0.5;
  183. HerculesSteel.Controls.FlangerDepth.maxOutput = 1.0;
  184. HerculesSteel.Controls.FlangerDelay.minOutput = 50;
  185. HerculesSteel.Controls.FlangerDelay.midOutput = 5000;
  186. HerculesSteel.Controls.FlangerDelay.maxOutput = 10000;
  187. HerculesSteel.Controls.FlangerPeriod.minOutput = 50000;
  188. HerculesSteel.Controls.FlangerPeriod.midOutput = 1000000;
  189. HerculesSteel.Controls.FlangerPeriod.maxOutput = 2000000;
  190.  
  191. HerculesSteel.balanceHandler = function(value) {
  192.     this.Controls.Balance.setValue(this.group, value);
  193. };
  194.  
  195. HerculesSteel.volumeHandler = function(value) {
  196.     this.Controls.Volume.setValue(this.group, value);
  197. };
  198.  
  199. HerculesSteel.crossFaderHandler = function(value) {
  200.     this.Controls.CrossFader.setValue(this.group, value);
  201. };
  202.  
  203. HerculesSteel.headPhoneMixHandler = function(value) {
  204.     this.Controls.HeadPhoneMix.setValue(this.group, value);
  205. };
  206.  
  207. /**
  208.  * Deck
  209.  * @param deckNumber
  210.  * @param group
  211.  */
  212. HerculesSteel.Deck = function (deckNumber, group) {
  213.     this.deckNumber = deckNumber;
  214.     this.group = group;
  215.     this.shiftMode = false;
  216.     this.scratching = false;
  217.     this.scratchTimer = -1;
  218.     this.cuePlaying = false;
  219.     this.playing = false;
  220.     this.Buttons = [];
  221. };
  222.  
  223. HerculesSteel.Deck.prototype.jogMove = function(jogValue) {
  224.     if(HerculesSteel.jogPlaylistScrollMode) {
  225.         if (jogValue > 0) {
  226.             engine.setValue("[Playlist]","SelectNextTrack", 1);
  227.         } else if (jogValue < 0) {
  228.             engine.setValue("[Playlist]","SelectPrevTrack", 1);
  229.         }
  230.     } else if(HerculesSteel.scratchMode) {
  231.         if(!this.scratching) {
  232.             this.scratching = true;
  233.             engine.scratchEnable(this.deckNumber, 128, 45, 1.0/8, (1.0/8)/32);
  234.         } else {
  235.             engine.stopTimer(this.scratchTimer);
  236.         }
  237.         engine.scratchTick(this.deckNumber, jogValue);
  238.         this.scratchTimer = engine.beginTimer(20, "HerculesSteel.GetDeck('" + this.group + "').stopScratching()", true);
  239.     } else {
  240.         engine.setValue(this.group,"jog", jogValue);
  241.     }
  242. };
  243.  
  244. HerculesSteel.Deck.prototype.stopScratching = function() {
  245.     this.scratching = false;
  246.     engine.scratchDisable(this.deckNumber);
  247.     this.scratchTimer  = -1;
  248. };
  249.  
  250. HerculesSteel.Deck.prototype.setControlValue = HerculesSteel.setControlValue;
  251.  
  252. HerculesSteel.Deck.prototype.pitchResetHandler = function(value) {
  253.     if(value == HerculesSteel.ButtonState.pressed) {
  254.         engine.setValue(this.group,"rate",0);
  255.         this.Buttons.PitchReset.setLed(HerculesSteel.LedState.on);
  256.     }
  257.     else {
  258.         // Button is called Pitch Bend-, so when button is released, turn off the LED
  259.         this.Buttons.PitchReset.setLed(HerculesSteel.LedState.off);
  260.     }
  261. };
  262.  
  263. HerculesSteel.Deck.prototype.syncHandler = function(value) {
  264.     if(value == HerculesSteel.ButtonState.pressed) {
  265.         engine.setValue(this.group,"beatsync",0);
  266.         this.Buttons.Sync.setLed(HerculesSteel.LedState.on);
  267.     }
  268.     else
  269.     {
  270.         this.Buttons.Sync.setLed(HerculesSteel.LedState.off);
  271.     }
  272. };
  273.  
  274. HerculesSteel.Deck.prototype.keypad1Handler = function(value) {
  275.     if(value == HerculesSteel.ButtonState.pressed) {
  276.         if(engine.getValue(this.group,"flanger") == 0) {
  277.             engine.setValue(this.group,"flanger",1);
  278.             this.Buttons.Keypad1.setLed(HerculesSteel.LedState.on);
  279.         } else {
  280.             engine.setValue(this.group,"flanger",0);
  281.             this.Buttons.Keypad1.setLed(HerculesSteel.LedState.off);
  282.         }
  283.     }
  284. };
  285.  
  286. HerculesSteel.Deck.prototype.keypad2Handler = function(value) {
  287.     if(value == HerculesSteel.ButtonState.pressed) {
  288.         this.Buttons.Keypad2.setLed(HerculesSteel.LedState.on);
  289.         engine.setValue(this.group,"hotcue_1_set", 1);
  290.     }
  291.     else {
  292.         this.Buttons.Keypad2.setLed(HerculesSteel.LedState.off);
  293.     }
  294. };
  295.  
  296. HerculesSteel.Deck.prototype.keypad3Handler = function(value) {
  297.     if(value == HerculesSteel.ButtonState.pressed) {
  298.         {
  299.             this.Buttons.Keypad3.setLed(HerculesSteel.LedState.on);
  300.             engine.setValue(this.group,"hotcue_2_set", 1);
  301.         }
  302.     } else {
  303.             this.Buttons.Keypad3.setLed(HerculesSteel.LedState.off);
  304.     }
  305. };
  306.  
  307. HerculesSteel.Deck.prototype.keypad4Handler = function(value) {
  308.     if(value == HerculesSteel.ButtonState.pressed) {
  309.         this.Buttons.Keypad4.setLed(HerculesSteel.LedState.on);
  310.         engine.setValue(this.group,"reverse",1);
  311.     } else {
  312.         this.Buttons.Keypad4.setLed(HerculesSteel.LedState.off);
  313.         engine.setValue(this.group,"reverse",0);
  314.     }
  315. };
  316.  
  317. HerculesSteel.Deck.prototype.keypad5Handler = function(value) {
  318.     if(value == HerculesSteel.ButtonState.pressed) {
  319.         this.Buttons.Keypad5.setLed(HerculesSteel.LedState.on);
  320.         engine.setValue(this.group,"hotcue_1_goto", 1);
  321.     }
  322.     else {
  323.         this.Buttons.Keypad5.setLed(HerculesSteel.LedState.off);
  324.  
  325.     }
  326. };
  327.  
  328. /* HerculesSteel.Deck.prototype.keypad6Handler = function(value) {
  329.     if(value == HerculesSteel.ButtonState.pressed) {
  330.         if(this.shiftMode) {
  331.             var loopIn = engine.getValue(this.group, "loop_start_position");
  332.             var loopOut = engine.getValue(this.group, "loop_end_position");
  333.             var loopLength = loopOut - loopIn;
  334.             if (loopIn != -1 && loopOut != -1 && loopLength >= 2) {
  335.                 engine.setValue(this.group,"loop_end_position",loopIn + loopLength / 2);
  336.             }
  337.         } else {
  338.             engine.setValue(this.group,"reloop_exit",1);
  339.         }
  340.     }
  341. };
  342. engine.setValue(this.group,"loop_in",1);
  343. engine.setValue(this.group,"loop_out",1);
  344. */
  345.  
  346. HerculesSteel.Deck.prototype.keypad6Handler = function(value) {
  347.     if(value == HerculesSteel.ButtonState.pressed) {
  348.         this.Buttons.Keypad6.setLed(HerculesSteel.LedState.on);
  349.         engine.setValue(this.group,"hotcue_2_goto",1);
  350.     }
  351.     else {
  352.         this.Buttons.Keypad6.setLed(HerculesSteel.LedState.off);
  353.     }
  354. };
  355.  
  356. // Loop in
  357. HerculesSteel.Deck.prototype.keypad7Handler = function(value) {
  358.     if(value == HerculesSteel.ButtonState.pressed) {
  359.         this.Buttons.Keypad7.setLed(HerculesSteel.LedState.on);
  360.         engine.setValue(this.group,"loop_in",1);
  361.     }
  362.     else {
  363.         this.Buttons.Keypad7.setLed(HerculesSteel.LedState.off);
  364.     }
  365. };
  366.  
  367. // Loop exit
  368. HerculesSteel.Deck.prototype.keypad8Handler = function(value) {
  369.     if(value == HerculesSteel.ButtonState.pressed) {
  370.         this.Buttons.Keypad8.setLed(HerculesSteel.LedState.on);
  371.         print("reloop_exit");
  372.         engine.setValue(this.group,"reloop_exit",1);
  373.  
  374.         }
  375.     else
  376.     {
  377.         this.Buttons.Keypad8.setLed(HerculesSteel.LedState.off);
  378.     }
  379. };
  380.  
  381. HerculesSteel.Deck.prototype.keypad9Handler = function(value) {};
  382.  
  383. // Loop out
  384. HerculesSteel.Deck.prototype.keypad10Handler = function(value) {
  385.     if(value == HerculesSteel.ButtonState.pressed) {
  386.         this.Buttons.Keypad10.setLed(HerculesSteel.LedState.on);
  387.         engine.setValue(this.group,"loop_out",1);
  388.         this.Buttons.Keypad8.setLed(HerculesSteel.LedState.on);
  389.     }
  390.     else
  391.     {
  392.         this.Buttons.Keypad10.setLed(HerculesSteel.LedState.off);
  393.     }
  394. };
  395.  
  396. HerculesSteel.Deck.prototype.keypad11Handler = function(value) {};
  397. HerculesSteel.Deck.prototype.keypad12Handler = function(value) {};
  398.  
  399. HerculesSteel.Deck.prototype.previousHandler = function(value) {
  400.     if(this.Buttons.Keypad1.state == HerculesSteel.ButtonState.pressed) {
  401.         //Move hotcue 1 backwards
  402.         var hotcue = engine.getValue(this.group, "hotcue_1_position");
  403.         var newPosition = hotcue - 400;
  404.         if(newPosition > 0) {
  405.             engine.setValue(this.group, "hotcue_1_position", newPosition);
  406.         }
  407.     } else if(this.Buttons.Keypad2.state == HerculesSteel.ButtonState.pressed) {
  408.         //Move hotcue 2 backwards
  409.         var hotcue = engine.getValue(this.group, "hotcue_2_position");
  410.         var newPosition = hotcue - 400;
  411.         if(newPosition > 0) {
  412.             engine.setValue(this.group, "hotcue_2_position", newPosition);
  413.         }
  414.     } else if(this.Buttons.Keypad3.state == HerculesSteel.ButtonState.pressed) {
  415.         //Move hotcue 3 backwards
  416.         var hotcue = engine.getValue(this.group, "hotcue_3_position");
  417.         var newPosition = hotcue - 400;
  418.         if(newPosition > 0) {
  419.             engine.setValue(this.group, "hotcue_3_position", newPosition);
  420.         }
  421.     } else if(this.Buttons.Keypad4.state == HerculesSteel.ButtonState.pressed) {
  422.         //Move loop-in backwards
  423.         var loopIn = engine.getValue(this.group, "loop_start_position");
  424.         var newPosition = loopIn - 400;
  425.         if(newPosition > 0) {
  426.             engine.setValue(this.group, "loop_start_position", newPosition);
  427.         }
  428.     } else if(this.Buttons.Keypad5.state == HerculesSteel.ButtonState.pressed) {
  429.         //Move loop-out backwards
  430.         var loopIn = engine.getValue(this.group, "loop_start_position");
  431.         var loopOut = engine.getValue(this.group, "loop_end_position");
  432.         var newPosition = loopOut - 400;
  433.         if(newPosition > loopIn) {
  434.             engine.setValue(this.group, "loop_end_position", newPosition);
  435.         }
  436.     } else {
  437.         engine.setValue(this.group,"back",value);
  438.     }
  439. };
  440.  
  441. HerculesSteel.Deck.prototype.nextHandler = function(value) {
  442.     //TODO: Fix movement of hotcues & loops out of track bounds
  443.     if(this.Buttons.Keypad1.state == HerculesSteel.ButtonState.pressed) {
  444.         //Move hotcue 1 forwards
  445.         var hotcue = engine.getValue(this.group, "hotcue_1_position");
  446.         var newPosition = hotcue + 400;
  447.         if(hotcue != -1) {
  448.             engine.setValue(this.group, "hotcue_1_position", newPosition);
  449.         }
  450.     } else if(this.Buttons.Keypad2.state == HerculesSteel.ButtonState.pressed) {
  451.         //Move hotcue 2 forwards
  452.         var hotcue = engine.getValue(this.group, "hotcue_2_position");
  453.         var newPosition = hotcue + 400;
  454.         if(hotcue != -1) {
  455.             engine.setValue(this.group, "hotcue_2_position", newPosition);
  456.         }
  457.     } else if(this.Buttons.Keypad3.state == HerculesSteel.ButtonState.pressed) {
  458.         //Move hotcue 3 forwards
  459.         var hotcue = engine.getValue(this.group, "hotcue_3_position");
  460.         var newPosition = hotcue + 400;
  461.         if(hotcue != -1 > 0) {
  462.             engine.setValue(this.group, "hotcue_3_position", newPosition);
  463.         }
  464.     } else if(this.Buttons.Keypad4.state == HerculesSteel.ButtonState.pressed) {
  465.         //Move loop-in forwards
  466.         var loopIn = engine.getValue(this.group, "loop_start_position");
  467.         var loopOut = engine.getValue(this.group, "loop_end_position");
  468.         var newPosition = loopIn + 400;
  469.         if(newPosition < loopOut) {
  470.             engine.setValue(this.group, "loop_start_position", newPosition);
  471.         }
  472.     } else if(this.Buttons.Keypad5.state == HerculesSteel.ButtonState.pressed) {
  473.         //Move loop-out forwards
  474.         var loopOut = engine.getValue(this.group, "loop_end_position");
  475.         var newPosition = loopOut + 400;
  476.         engine.setValue(this.group, "loop_end_position", newPosition);
  477.     } else {
  478.         engine.setValue(this.group,"fwd",value);
  479.     }
  480. };
  481.  
  482. HerculesSteel.Deck.prototype.playPauseHandler = function(value) {
  483. };
  484.  
  485. HerculesSteel.Deck.prototype.cueHandler = function(value) {
  486.     if(value == HerculesSteel.ButtonState.pressed) {
  487.         //var position = engine.getValue(this.group,"playposition") * engine.getValue(this.group, "duration") * engine.getValue(this.group, "duration");
  488.         //var atCuePoint = engine.getValue(this.group,"cue_point") == position;
  489.         //print("at cue: " + atCuePoint + ", playposition: " + position);
  490.         engine.setValue(this.group,"cue_default",1);
  491.         this.playing = false;
  492.         this.Buttons.PlayPause.setLed(HerculesSteel.LedState.off);
  493.         //if(atCuePoint) {
  494.         this.cuePlaying = true;
  495.         this.Buttons.Cue.setLed(HerculesSteel.LedState.on);
  496.         //}
  497.     } else {
  498.         engine.setValue(this.group,"cue_default",0);
  499.         if(this.cuePlaying) {
  500.             this.cuePlaying = false;
  501.         }
  502.         this.Buttons.Cue.setLed(HerculesSteel.LedState.off);
  503.     }
  504. };
  505.  
  506. HerculesSteel.Deck.prototype.killHighHandler = function(value) {
  507.     if(value == HerculesSteel.ButtonState.pressed) {
  508.         var filterStatus = engine.getValue(this.group, "filterHighKill");
  509.         if(filterStatus) {
  510.             engine.setValue(this.group, "filterHighKill", 0);
  511.             this.Buttons.KillHigh.setLed(HerculesSteel.LedState.off);
  512.         } else {
  513.             engine.setValue(this.group, "filterHighKill", 1);
  514.             this.Buttons.KillHigh.setLed(HerculesSteel.LedState.on);
  515.         }
  516.     }
  517. };
  518.  
  519. HerculesSteel.Deck.prototype.killMidHandler = function(value) {
  520.     if(value == HerculesSteel.ButtonState.pressed) {
  521.         var filterStatus = engine.getValue(this.group, "filterMidKill");
  522.         if(filterStatus) {
  523.             engine.setValue(this.group, "filterMidKill", 0);
  524.             this.Buttons.KillMid.setLed(HerculesSteel.LedState.off);
  525.         } else {
  526.             engine.setValue(this.group, "filterMidKill", 1);
  527.             this.Buttons.KillMid.setLed(HerculesSteel.LedState.on);
  528.         }
  529.     }
  530. };
  531.  
  532. HerculesSteel.Deck.prototype.killLowHandler = function(value) {
  533.     if(value == HerculesSteel.ButtonState.pressed) {
  534.         var filterStatus = engine.getValue(this.group, "filterLowKill");
  535.         if(filterStatus) {
  536.             engine.setValue(this.group, "filterLowKill", 0);
  537.             this.Buttons.KillLow.setLed(HerculesSteel.LedState.off);
  538.         } else {
  539.             engine.setValue(this.group, "filterLowKill", 1);
  540.             this.Buttons.KillLow.setLed(HerculesSteel.LedState.on);
  541.         }
  542.     }
  543. };
  544.  
  545. HerculesSteel.Deck.prototype.loadHandler = function(value) {
  546.     if(value == HerculesSteel.ButtonState.pressed) {
  547.         engine.setValue(this.group, "LoadSelectedTrack", 1);
  548.     }
  549. };
  550.  
  551. HerculesSteel.Deck.prototype.cueSelectHandler = function(value) {
  552.     if(value == HerculesSteel.ButtonState.pressed) {
  553.         var filterStatus = engine.getValue(this.group, "pfl");
  554.         if(filterStatus) {
  555.             engine.setValue(this.group, "pfl", 0);
  556.             this.Buttons.CueSelect.setLed(HerculesSteel.LedState.off);
  557.         } else {
  558.             engine.setValue(this.group, "pfl", 1);
  559.             this.Buttons.CueSelect.setLed(HerculesSteel.LedState.on);
  560.         }
  561.     }
  562. };
  563.  
  564. HerculesSteel.Deck.prototype.gainHandler = function(value) {
  565.     this.Controls.Gain.setValue(this.group, value);
  566. };
  567.  
  568. HerculesSteel.Deck.prototype.trebleHandler = function(value) {
  569.     if(HerculesSteel.shiftMode) {
  570.         //Flanger
  571.         HerculesSteel.Controls.FlangerDepth.setValue("[Flanger]", value);
  572.     } else if(this.shiftMode) {
  573.         //Soft set
  574.         this.Controls.Treble.softMode = true;
  575.         this.Controls.Treble.setValue(this.group, value);
  576.         this.Controls.Treble.softMode = false;
  577.     } else {
  578.         this.Controls.Treble.setValue(this.group, value);
  579.     }
  580. };
  581.  
  582. HerculesSteel.Deck.prototype.mediumHandler = function(value) {
  583.     if(HerculesSteel.shiftMode) {
  584.         //Flanger
  585.         HerculesSteel.Controls.FlangerDelay.setValue("[Flanger]", value);
  586.     } else if(this.shiftMode) {
  587.         //Soft set
  588.         this.Controls.Medium.softMode = true;
  589.         this.Controls.Medium.setValue(this.group, value);
  590.         this.Controls.Medium.softMode = false;
  591.     } else {
  592.         this.Controls.Medium.setValue(this.group, value);
  593.     }
  594. };
  595.  
  596. HerculesSteel.Deck.prototype.bassHandler = function(value) {
  597.     if(HerculesSteel.shiftMode) {
  598.         //Flanger
  599.         HerculesSteel.Controls.FlangerPeriod.setValue("[Flanger]", value);
  600.     } else if(this.shiftMode) {
  601.         //Soft set
  602.         this.Controls.Bass.softMode = true;
  603.         this.Controls.Bass.setValue(this.group, value);
  604.         this.Controls.Bass.softMode = false;
  605.     } else {
  606.         this.Controls.Bass.setValue(this.group, value);
  607.     }
  608. };
  609.  
  610. HerculesSteel.Deck.prototype.volHandler = function(value) {
  611.     this.Controls.Vol.setValue(this.group, value);
  612. };
  613.  
  614. HerculesSteel.Deck.prototype.pitchHandler = function(value) {
  615.     this.Controls.Pitch.setValue(this.group, value);
  616. };
  617.  
  618. HerculesSteel.Deck.prototype.shiftHandler = function(value) {
  619.     if(value == HerculesSteel.ButtonState.pressed) {
  620.         this.shiftMode = true;
  621.     } else {
  622.         this.shiftMode = false;
  623.     }
  624. };
  625.  
  626. HerculesSteel.Deck.prototype.stopHandler = function(value) {
  627.     if(value == HerculesSteel.ButtonState.pressed) {
  628.         engine.setValue(this.group, "cue_default", 0);
  629.         engine.setValue(this.group, "play", 0);
  630.         engine.setValue(this.group, "start", 0);
  631.     }
  632. };
  633.  
  634. HerculesSteel.Deck.prototype.addButton = HerculesSteel.addButton;
  635.  
  636. HerculesSteel.Decks = {"Left":new HerculesSteel.Deck(1,"[Channel1]"), "Right":new HerculesSteel.Deck(2,"[Channel2]")};
  637. HerculesSteel.GroupToDeck = {"[Channel1]":"Left", "[Channel2]":"Right"};
  638.  
  639. HerculesSteel.GetDeck = function(group) {
  640.     try {
  641.         return HerculesSteel.Decks[HerculesSteel.GroupToDeck[group]];
  642.     } catch(ex) {
  643.         return null;
  644.     }
  645. };
  646.  
  647. HerculesSteel.Decks.Left.addButton("Keypad1", new HerculesSteel.Button(0x01), "keypad1Handler");
  648. HerculesSteel.Decks.Left.addButton("Keypad2", new HerculesSteel.Button(0x02), "keypad2Handler");
  649. HerculesSteel.Decks.Left.addButton("Keypad3", new HerculesSteel.Button(0x03), "keypad3Handler");
  650. HerculesSteel.Decks.Left.addButton("Keypad4", new HerculesSteel.Button(0x04), "keypad4Handler");
  651. HerculesSteel.Decks.Left.addButton("Keypad5", new HerculesSteel.Button(0x05), "keypad5Handler");
  652. HerculesSteel.Decks.Left.addButton("Keypad6", new HerculesSteel.Button(0x06), "keypad6Handler");
  653. HerculesSteel.Decks.Left.addButton("Keypad7", new HerculesSteel.Button(0x64), "keypad7Handler");
  654. HerculesSteel.Decks.Left.addButton("Keypad8", new HerculesSteel.Button(0x65), "keypad8Handler");
  655. HerculesSteel.Decks.Left.addButton("Keypad9", new HerculesSteel.Button(0x66), "keypad9Handler");
  656. HerculesSteel.Decks.Left.addButton("Keypad10", new HerculesSteel.Button(0x67), "keypad10Handler");
  657. HerculesSteel.Decks.Left.addButton("Keypad11", new HerculesSteel.Button(0x68), "keypad11Handler");
  658. HerculesSteel.Decks.Left.addButton("Keypad12", new HerculesSteel.Button(0x69), "keypad12Handler");
  659. HerculesSteel.Decks.Left.addButton("Sync", new HerculesSteel.Button(0x07, 0x37), "syncHandler");
  660. HerculesSteel.Decks.Left.addButton("BeatLock", new HerculesSteel.Button(0x08, 0x38), null);
  661. HerculesSteel.Decks.Left.addButton("Previous", new HerculesSteel.Button(0x09), "previousHandler");
  662. HerculesSteel.Decks.Left.addButton("Next", new HerculesSteel.Button(0x0A), "nextHandler");
  663. HerculesSteel.Decks.Left.addButton("PlayPause", new HerculesSteel.Button(0x0B, 0x3B), "playPauseHandler");
  664. HerculesSteel.Decks.Left.addButton("Cue", new HerculesSteel.Button(0x0C, 0x3C), "cueHandler");
  665. HerculesSteel.Decks.Left.addButton("Shift",  new HerculesSteel.Button(0x0D), "shiftHandler");
  666. HerculesSteel.Decks.Left.addButton("KillHigh", new HerculesSteel.Button(0x0E), "killHighHandler");
  667. HerculesSteel.Decks.Left.addButton("KillMid", new HerculesSteel.Button(0x0F), "killMidHandler");
  668. HerculesSteel.Decks.Left.addButton("KillLow", new HerculesSteel.Button(0x10), "killLowHandler");
  669. HerculesSteel.Decks.Left.addButton("PitchReset", new HerculesSteel.Button(0x11, 0x41), "pitchResetHandler");
  670. HerculesSteel.Decks.Left.addButton("Load", new HerculesSteel.Button(0x12), "loadHandler");
  671. HerculesSteel.Decks.Left.addButton("Source", new HerculesSteel.Button(0x13, 0x43), null);
  672. HerculesSteel.Decks.Left.addButton("CueSelect", new HerculesSteel.Button(0x14, 0x44), "cueSelectHandler");
  673. HerculesSteel.Decks.Left.addButton("Stop",  new HerculesSteel.Button(0x0D), "stopHandler");
  674.  
  675. HerculesSteel.Decks.Left.Controls = {
  676.     "Gain" : new HerculesSteel.Control("pregain", false),
  677.     "Treble" : new HerculesSteel.Control("filterHigh", false),
  678.     "Medium" : new HerculesSteel.Control("filterMid", false),
  679.     "Bass" : new HerculesSteel.Control("filterLow", false),
  680.     "Vol" : new HerculesSteel.Control("volume", false),
  681.     "Pitch" : new HerculesSteel.Control("rate", false)
  682. };
  683. HerculesSteel.Decks.Left.Controls.Gain.minOutput = 0.0;
  684. HerculesSteel.Decks.Left.Controls.Gain.midOutput = 1.0;
  685. HerculesSteel.Decks.Left.Controls.Gain.maxOutput = 4.0;
  686. HerculesSteel.Decks.Left.Controls.Treble.minOutput = 0.0;
  687. HerculesSteel.Decks.Left.Controls.Treble.midOutput = 1.0;
  688. HerculesSteel.Decks.Left.Controls.Treble.maxOutput = 4.0;
  689. HerculesSteel.Decks.Left.Controls.Medium.minOutput = 0.0;
  690. HerculesSteel.Decks.Left.Controls.Medium.midOutput = 1.0;
  691. HerculesSteel.Decks.Left.Controls.Medium.maxOutput = 4.0;
  692. HerculesSteel.Decks.Left.Controls.Bass.minOutput = 0.0;
  693. HerculesSteel.Decks.Left.Controls.Bass.midOutput = 1.0;
  694. HerculesSteel.Decks.Left.Controls.Bass.maxOutput = 4.0;
  695. HerculesSteel.Decks.Left.Controls.Vol.minOutput = 0.0;
  696. HerculesSteel.Decks.Left.Controls.Vol.midOutput = 0.4;
  697. HerculesSteel.Decks.Left.Controls.Vol.maxOutput = 1.0;
  698. HerculesSteel.Decks.Left.Controls.Pitch.midInput = 0x40;
  699.  
  700. HerculesSteel.Decks.Right.addButton("Keypad1",  new HerculesSteel.Button(0x19), "keypad1Handler");
  701. HerculesSteel.Decks.Right.addButton("Keypad2", new HerculesSteel.Button(0x1A), "keypad2Handler");
  702. HerculesSteel.Decks.Right.addButton("Keypad3", new HerculesSteel.Button(0x1B), "keypad3Handler");
  703. HerculesSteel.Decks.Right.addButton("Keypad4", new HerculesSteel.Button(0x1C), "keypad4Handler");
  704. HerculesSteel.Decks.Right.addButton("Keypad5", new HerculesSteel.Button(0x1D), "keypad5Handler");
  705. HerculesSteel.Decks.Right.addButton("Keypad6", new HerculesSteel.Button(0x1E), "keypad6Handler");
  706. HerculesSteel.Decks.Right.addButton("Keypad7", new HerculesSteel.Button(0x6A), "keypad7Handler");
  707. HerculesSteel.Decks.Right.addButton("Keypad8", new HerculesSteel.Button(0x6B), "keypad8Handler");
  708. HerculesSteel.Decks.Right.addButton("Keypad9", new HerculesSteel.Button(0x6C), "keypad9Handler");
  709. HerculesSteel.Decks.Right.addButton("Keypad10", new HerculesSteel.Button(0x6D), "keypad10Handler");
  710. HerculesSteel.Decks.Right.addButton("Keypad11", new HerculesSteel.Button(0x6E), "keypad11Handler");
  711. HerculesSteel.Decks.Right.addButton("Keypad12", new HerculesSteel.Button(0x6F), "keypad12Handler");
  712. HerculesSteel.Decks.Right.addButton("Sync", new HerculesSteel.Button(0x1F, 0x5F), "syncHandler");
  713. HerculesSteel.Decks.Right.addButton("BeatLock", new HerculesSteel.Button(0x15, 0x60), null);
  714. HerculesSteel.Decks.Right.addButton("Previous", new HerculesSteel.Button(0x21), "previousHandler");
  715. HerculesSteel.Decks.Right.addButton("Next", new HerculesSteel.Button(0x22), "nextHandler");
  716. HerculesSteel.Decks.Right.addButton("PlayPause", new HerculesSteel.Button(0x23, 0x53), "playPauseHandler");
  717. HerculesSteel.Decks.Right.addButton("Cue", new HerculesSteel.Button(0x24, 0x54), "cueHandler");
  718. HerculesSteel.Decks.Right.addButton("Shift", new HerculesSteel.Button(0x25), "shiftHandler");
  719. HerculesSteel.Decks.Right.addButton("KillHigh", new HerculesSteel.Button(0x26), "killHighHandler");
  720. HerculesSteel.Decks.Right.addButton("KillMid", new HerculesSteel.Button(0x27), "killMidHandler");
  721. HerculesSteel.Decks.Right.addButton("KillLow", new HerculesSteel.Button(0x28), "killLowHandler");
  722. HerculesSteel.Decks.Right.addButton("PitchReset", new HerculesSteel.Button(0x20, 0x55), "pitchResetHandler");
  723. HerculesSteel.Decks.Right.addButton("Load", new HerculesSteel.Button(0x16), "loadHandler");
  724. HerculesSteel.Decks.Right.addButton("Source", new HerculesSteel.Button(0x17, 0x57), null);
  725. HerculesSteel.Decks.Right.addButton("CueSelect", new HerculesSteel.Button(0x18, 0x58), "cueSelectHandler");
  726. HerculesSteel.Decks.Right.addButton("Stop", new HerculesSteel.Button(0x25), "stopHandler");
  727.  
  728. HerculesSteel.Decks.Right.Controls = {
  729.     "Gain" : new HerculesSteel.Control("pregain", false),
  730.     "Treble" : new HerculesSteel.Control("filterHigh", false),
  731.     "Medium" : new HerculesSteel.Control("filterMid", false),
  732.     "Bass" : new HerculesSteel.Control("filterLow", false),
  733.     "Vol" : new HerculesSteel.Control("volume", false),
  734.     "Pitch" : new HerculesSteel.Control("rate", false)
  735. };
  736. HerculesSteel.Decks.Right.Controls.Gain.minOutput = 0.0;
  737. HerculesSteel.Decks.Right.Controls.Gain.midOutput = 1.0;
  738. HerculesSteel.Decks.Right.Controls.Gain.maxOutput = 4.0;
  739. HerculesSteel.Decks.Right.Controls.Treble.minOutput = 0.0;
  740. HerculesSteel.Decks.Right.Controls.Treble.midOutput = 1.0;
  741. HerculesSteel.Decks.Right.Controls.Treble.maxOutput = 4.0;
  742. HerculesSteel.Decks.Right.Controls.Medium.minOutput = 0.0;
  743. HerculesSteel.Decks.Right.Controls.Medium.midOutput = 1.0;
  744. HerculesSteel.Decks.Right.Controls.Medium.maxOutput = 4.0;
  745. HerculesSteel.Decks.Right.Controls.Bass.minOutput = 0.0;
  746. HerculesSteel.Decks.Right.Controls.Bass.midOutput = 1.0;
  747. HerculesSteel.Decks.Right.Controls.Bass.maxOutput = 4.0;
  748. HerculesSteel.Decks.Right.Controls.Vol.minOutput = 0.0;
  749. HerculesSteel.Decks.Right.Controls.Vol.midOutput = 0.4;
  750. HerculesSteel.Decks.Right.Controls.Vol.maxOutput = 1.0;
  751. HerculesSteel.Decks.Right.Controls.Pitch.midInput = 0x40;
  752.  
  753.  
  754. //Mapping functions
  755. HerculesSteel.volume = function(channel, control, value, status, group) {
  756.     HerculesSteel.volumeHandler(value);
  757. };
  758.  
  759. HerculesSteel.balance = function(channel, control, value, status, group) {
  760.     HerculesSteel.balanceHandler(value);
  761. };
  762.  
  763. HerculesSteel.crossFader = function(channel, control, value, status, group) {
  764.     HerculesSteel.crossFaderHandler(value);
  765. };
  766.  
  767. HerculesSteel.headPhoneMix = function(channel, control, value, status, group) {
  768.     HerculesSteel.headPhoneMixHandler(value);
  769. };
  770.  
  771. HerculesSteel.up = function (channel, control, value, status, group) {
  772.     HerculesSteel.Buttons.Up.handleEvent(value);
  773. };
  774.  
  775. HerculesSteel.down = function (channel, control, value, status, group) {
  776.     HerculesSteel.Buttons.Down.handleEvent(value);
  777. };
  778.  
  779. HerculesSteel.left = function (channel, control, value, status, group) {
  780.     HerculesSteel.Buttons.Left.handleEvent(value);
  781. };
  782.  
  783. HerculesSteel.right = function (channel, control, value, status, group) {
  784.     HerculesSteel.Buttons.Right.handleEvent(value);
  785. };
  786.  
  787. HerculesSteel.scratch = function (channel, control, value, status, group) {
  788.     HerculesSteel.Buttons.Scratch.handleEvent(value);
  789. };
  790.  
  791. HerculesSteel.gain = function(channel, control, value, status, group) {
  792.     var deck = HerculesSteel.GetDeck(group);
  793.     deck.gainHandler(value);
  794. };
  795.  
  796. HerculesSteel.rate = function(channel, control, value, status, group) {
  797.     var deck = HerculesSteel.GetDeck(group);
  798.     deck.pitchHandler(value);
  799. };
  800.  
  801. HerculesSteel.treble = function(channel, control, value, status, group) {
  802.     var deck = HerculesSteel.GetDeck(group);
  803.     deck.trebleHandler(value);
  804. };
  805.  
  806. HerculesSteel.medium = function(channel, control, value, status, group) {
  807.     var deck = HerculesSteel.GetDeck(group);
  808.     deck.mediumHandler(value);
  809. };
  810.  
  811. HerculesSteel.bass = function(channel, control, value, status, group) {
  812.     var deck = HerculesSteel.GetDeck(group);
  813.     deck.bassHandler(value);
  814. };
  815.  
  816. HerculesSteel.deckVolume = function(channel, control, value, status, group) {
  817.     var deck = HerculesSteel.GetDeck(group);
  818.     deck.volHandler(value);
  819. };
  820.  
  821. HerculesSteel.jog_wheel = function (channel, control, value, status, group) {
  822.     // 7F > 40: CCW Slow > Fast - 127 > 64 
  823.     // 01 > 3F: CW Slow > Fast - 0 > 63
  824.     var jogValue = value >=0x40 ? value - 0x80 : value; // -64 to +63, - = CCW, + = CW
  825.     HerculesSteel.GetDeck(group).jogMove(jogValue);
  826. };
  827.  
  828. HerculesSteel.cue = function (channel, control, value, status, group) {
  829.     var deck = HerculesSteel.GetDeck(group);
  830.     deck.Buttons.Cue.handleEvent(value);
  831. };
  832.  
  833. HerculesSteel.beatSync = function (channel, control, value, status, group) {
  834.     var deck = HerculesSteel.GetDeck(group);
  835.     deck.Buttons.Sync.handleEvent(value);
  836. };
  837.  
  838. HerculesSteel.rateReset = function (channel, control, value, status, group) {
  839.     var deck = HerculesSteel.GetDeck(group);
  840.     deck.Buttons.PitchReset.handleEvent(value);
  841. };
  842.  
  843. HerculesSteel.play = function (channel, control, value, status, group) {
  844.     var deck = HerculesSteel.GetDeck(group);
  845.     deck.Buttons.PlayPause.handleEvent(value);
  846. };
  847.  
  848. HerculesSteel.stop = function (channel, control, value, status, group) {
  849.     var deck = HerculesSteel.GetDeck(group);
  850.     deck.Buttons.Stop.handleEvent(value);
  851. };
  852.  
  853. HerculesSteel.shift = function (channel, control, value, status, group) {
  854.     var deck = HerculesSteel.GetDeck(group);
  855.     deck.Buttons.Shift.handleEvent(value);
  856. };
  857.  
  858. HerculesSteel.keypad1 = function (channel, control, value, status, group) {
  859.     var deck = HerculesSteel.GetDeck(group);
  860.     deck.Buttons.Keypad1.handleEvent(value);
  861. };
  862.  
  863. HerculesSteel.keypad2 = function (channel, control, value, status, group) {
  864.     var deck = HerculesSteel.GetDeck(group);
  865.     deck.Buttons.Keypad2.handleEvent(value);
  866. };
  867.  
  868. HerculesSteel.keypad3 = function (channel, control, value, status, group) {
  869.     var deck = HerculesSteel.GetDeck(group);
  870.     deck.Buttons.Keypad3.handleEvent(value);
  871. };
  872.  
  873. HerculesSteel.keypad4 = function (channel, control, value, status, group) {
  874.     var deck = HerculesSteel.GetDeck(group);
  875.     deck.Buttons.Keypad4.handleEvent(value);
  876. };
  877.  
  878. HerculesSteel.keypad5 = function (channel, control, value, status, group) {
  879.     var deck = HerculesSteel.GetDeck(group);
  880.     deck.Buttons.Keypad5.handleEvent(value);
  881. };
  882.  
  883. HerculesSteel.keypad6 = function (channel, control, value, status, group) {
  884.     var deck = HerculesSteel.GetDeck(group);
  885.     deck.Buttons.Keypad6.handleEvent(value);
  886. };
  887.  
  888. HerculesSteel.keypad7 = function (channel, control, value, status, group) {
  889.     var deck = HerculesSteel.GetDeck(group);
  890.     deck.Buttons.Keypad7.handleEvent(value);
  891. };
  892.  
  893. HerculesSteel.keypad8 = function (channel, control, value, status, group) {
  894.     var deck = HerculesSteel.GetDeck(group);
  895.     deck.Buttons.Keypad8.handleEvent(value);
  896. };
  897.  
  898. HerculesSteel.keypad9 = function (channel, control, value, status, group) {
  899.     var deck = HerculesSteel.GetDeck(group);
  900.     deck.Buttons.Keypad9.handleEvent(value);
  901. };
  902.  
  903. HerculesSteel.keypad10 = function (channel, control, value, status, group) {
  904.     var deck = HerculesSteel.GetDeck(group);
  905.     deck.Buttons.Keypad10.handleEvent(value);
  906. };
  907.  
  908. HerculesSteel.keypad11 = function (channel, control, value, status, group) {
  909.     var deck = HerculesSteel.GetDeck(group);
  910.     deck.Buttons.Keypad11.handleEvent(value);
  911. };
  912.  
  913. HerculesSteel.keypad12 = function (channel, control, value, status, group) {
  914.     var deck = HerculesSteel.GetDeck(group);
  915.     deck.Buttons.Keypad12.handleEvent(value);
  916. };
  917.  
  918. HerculesSteel.next = function (channel, control, value, status, group) {
  919.     var deck = HerculesSteel.GetDeck(group);
  920.     deck.Buttons.Next.handleEvent(value);
  921. };
  922.  
  923. HerculesSteel.previous = function (channel, control, value, status, group) {
  924.     var deck = HerculesSteel.GetDeck(group);
  925.     deck.Buttons.Previous.handleEvent(value);
  926. };
  927.  
  928. HerculesSteel.load = function (channel, control, value, status, group) {
  929.     var deck = HerculesSteel.GetDeck(group);
  930.     deck.Buttons.Load.handleEvent(value);
  931. };
  932.  
  933. HerculesSteel.cueSelect = function (channel, control, value, status, group) {
  934.     var deck = HerculesSteel.GetDeck(group);
  935.     deck.Buttons.CueSelect.handleEvent(value);
  936. };
  937.  
  938. HerculesSteel.killLow = function (channel, control, value, status, group) {
  939.     var deck = HerculesSteel.GetDeck(group);
  940.     deck.Buttons.KillLow.handleEvent(value);
  941. };
  942.  
  943.  
  944. HerculesSteel.killMid = function (channel, control, value, status, group) {
  945.     var deck = HerculesSteel.GetDeck(group);
  946.     deck.Buttons.KillMid.handleEvent(value);
  947. };
  948.  
  949.  
  950. HerculesSteel.killHigh = function (channel, control, value, status, group) {
  951.     var deck = HerculesSteel.GetDeck(group);
  952.     deck.Buttons.KillHigh.handleEvent(value);
  953. };
  954.  
  955. HerculesSteel.init = function (id) {    // called when the MIDI device is opened & set up
  956.  
  957.     HerculesSteel.LedsOFF();
  958.     engine.connectControl("[Channel1]","rate","HerculesSteel.rateChange");
  959.     engine.connectControl("[Channel2]","rate","HerculesSteel.rateChange");
  960.     print ("HerculesSteel id: \""+id+"\" initialized.");
  961. };
  962.  
  963. HerculesSteel.shutdown = function() {
  964.     HerculesSteel.LedsOFF();
  965.     print ("HerculesSteel shutdown.");
  966. };
  967.  
  968. HerculesSteel.LedsON = function() {
  969.     var time = 20;
  970.  
  971.     print ("HerculesSteel LEDS ON (1/2).");
  972.     for (i=0;i<0x29;i++)
  973.     {
  974.         //TODO: remove timers when alsa midi work properly.
  975.         //midi.sendShortMsg(0xB0, i, 0x7F);
  976.         engine.beginTimer(time, "midi.sendShortMsg(0xB0, '" + i + "', 0x7F);", true);
  977.         time = time + 5;
  978.     }
  979.  
  980.     // Properly, it would be like this :
  981.     HerculesSteel.Buttons.Scratch.setLed(HerculesSteel.LedState.on);
  982.  
  983.     print ("HerculesSteel LEDS ON (2/2).");
  984.     for (i=0x64;i<0x6f+1;i++)
  985.     {
  986.         //TODO: remove timers when alsa midi work properly.
  987.         //midi.sendShortMsg(0xB0, i, 0x7F);
  988.         engine.beginTimer(time, "midi.sendShortMsg(0xB0, '" + i + "', 0x7F);", true);
  989.         time = time + 5;
  990.     }
  991.     // Some buttons stays OFF : rewind A/B, forward A/B, Load Deck A, Load Deck B, Up, Down, Apply Ctrl. on
  992. }
  993.  
  994. HerculesSteel.LedsOFF = function() {
  995.     HerculesSteel.Buttons.Scratch.setLed(HerculesSteel.LedState.off);
  996.     //TODO: remove timers when alsa midi work properly.
  997.     var button;
  998.     var time = 20;
  999.     print("switch off Left deck LEDs");
  1000.     for (var key in HerculesSteel.Decks.Left.Buttons) {
  1001.         engine.beginTimer(time, "HerculesSteel.Decks.Left.Buttons['" + key + "'].setLed(HerculesSteel.LedState.off)", true);
  1002.         time = time + 5;
  1003.     }
  1004.     print("switch off Right deck LEDs");
  1005.     for (var key in HerculesSteel.Decks.Right.Buttons) {
  1006.         engine.beginTimer(time, "HerculesSteel.Decks.Right.Buttons['" + key + "'].setLed(HerculesSteel.LedState.off)", true);
  1007.         time = time + 5;
  1008.     }
  1009. }
  1010.  
  1011. //Rate change event handler to reset sync and reset leds
  1012. //TODO: Need some way to check sync state here.
  1013. HerculesSteel.rateChange = function (value, group) {
  1014.     if (HerculesSteel.Decks.Left.Buttons.Sync.state != HerculesSteel.ButtonState.pressed) {
  1015.         HerculesSteel.Decks.Left.Buttons.Sync.setLed(HerculesSteel.LedState.off);
  1016.     }
  1017.     if (HerculesSteel.Decks.Right.Buttons.Sync.state != HerculesSteel.ButtonState.pressed) {
  1018.         engine.beginTimer(25, "HerculesSteel.Decks.Right.Buttons.Sync.setLed(HerculesSteel.LedState.off)", true);
  1019.     }
  1020.     if (value != 0.0) {
  1021.         var deck = HerculesSteel.GetDeck(group);
  1022.         engine.beginTimer(30, "HerculesSteel.GetDeck('" + group + "').Buttons.PitchReset.setLed(HerculesSteel.LedState.off)", true);
  1023.     }
  1024. };
  1025.  
  1026.