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-Console-RMX-scripts.js < prev    next >
Text File  |  2011-02-04  |  32KB  |  843 lines

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