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-Mk4-scripts.js < prev    next >
Text File  |  2010-12-04  |  11KB  |  347 lines

  1. function HerculesMk4 () {}
  2.  
  3. //Hercules Mk4 scripts from Dj Kork.... enjoy them ;)
  4.  
  5.  
  6.  
  7. // Number of the standard RPM value. Lower values increase de sensitivity as the really records.
  8. HerculesMk4.standardRpm = 33.33;
  9.  
  10. // The HerculesMk4.alpha value for the filter (start with 1/8 (0.125) and tune from there)
  11. HerculesMk4.alpha = 1/8;
  12.  
  13. // The HerculesMk4.beta value for the filter (start with HerculesMk4.alpha/32 and tune from there)
  14. HerculesMk4.beta = HerculesMk4.alpha/20;
  15.  
  16. HerculesMk4.scratchButton = 0;
  17. HerculesMk4.scratchMode =[0,0];
  18. HerculesMk4.antiguoMixCue=1;
  19. HerculesMk4.sensivityPitch=[5,5];
  20. HerculesMk4.jogFastPosition=[0,0];
  21.  
  22.  
  23.  
  24.  
  25. HerculesMk4.init = function (id) { 
  26.     // Switch off all LEDs
  27.     for (var i=1; i<95; i++) midi.sendShortMsg(0x90, i, 0x00);
  28.     // Switch-on the LEDs for improve the usability
  29.     midi.sendShortMsg(0x90, 45, 0x7F);    // Scratch LED
  30.     midi.sendShortMsg(0x90, 14, 0x7F);    // Cue deck A LED
  31.     midi.sendShortMsg(0x90, 34, 0x7F);    // Cue deck B LED
  32. };
  33.  
  34. HerculesMk4.shutdown = function (id) {
  35.     // Switch off all LEDs
  36.     for (var i=1; i<95; i++) midi.sendShortMsg(0x90, i, 0x00);
  37. };
  38.  
  39.  
  40.  
  41. HerculesMk4.loadTrack = function (midino, control, value, status, group) {
  42.     // Load the selected track in the corresponding deck only if the track is 
  43.     // paused
  44.  
  45.     if(value && engine.getValue(group, "play") != 1) {
  46.         engine.setValue(group, "LoadSelectedTrack", 1);
  47.         engine.setValue(group, "rate", 0);
  48.         }
  49.     else engine.setValue(group, "LoadSelectedTrack", 0);
  50. };        
  51.  
  52.  
  53. HerculesMk4.scroll = function (midino, control, value, status, group) {
  54.     // Button "Files": up 10 tracks
  55.     // Button "Folder": down 10 tracks
  56.     // This function scroll up or down 10 tracks on the playlist, like the mouse
  57.     // scroll.
  58.  
  59.     if(control == 0x2C && value == 0x7F) {    
  60.         engine.setValue("[Playlist]", "SelectPrevTrack", "1");
  61.         engine.setValue("[Playlist]", "SelectPrevTrack", "1");
  62.         engine.setValue("[Playlist]", "SelectPrevTrack", "1");
  63.         engine.setValue("[Playlist]", "SelectPrevTrack", "1");
  64.         engine.setValue("[Playlist]", "SelectPrevTrack", "1");
  65.         engine.setValue("[Playlist]", "SelectPrevTrack", "1");
  66.         engine.setValue("[Playlist]", "SelectPrevTrack", "1");
  67.         engine.setValue("[Playlist]", "SelectPrevTrack", "1");
  68.         engine.setValue("[Playlist]", "SelectPrevTrack", "1");
  69.         engine.setValue("[Playlist]", "SelectPrevTrack", "1");
  70.         engine.setValue("[Playlist]", "SelectPrevTrack", "0");
  71.         }
  72.     if (control == 0x2B && value == 0x7F) {    
  73.         engine.setValue("[Playlist]", "SelectNextTrack", "1");
  74.         engine.setValue("[Playlist]", "SelectNextTrack", "1");
  75.         engine.setValue("[Playlist]", "SelectNextTrack", "1");
  76.         engine.setValue("[Playlist]", "SelectNextTrack", "1");
  77.         engine.setValue("[Playlist]", "SelectNextTrack", "1");
  78.         engine.setValue("[Playlist]", "SelectNextTrack", "1");
  79.         engine.setValue("[Playlist]", "SelectNextTrack", "1");
  80.         engine.setValue("[Playlist]", "SelectNextTrack", "1");
  81.         engine.setValue("[Playlist]", "SelectNextTrack", "1");
  82.         engine.setValue("[Playlist]", "SelectNextTrack", "1");
  83.         engine.setValue("[Playlist]", "SelectNextTrack", "0");
  84.         }
  85. };
  86.  
  87.  
  88.  
  89. HerculesMk4.keyButton = function (midino, control, value, status, group) {
  90.     // Loop command for the first 4 Key, Hotcues command for the latest 4
  91.     
  92.     switch (control) {
  93.  
  94.     // Loop buttons
  95.         case 0x01: case 0x15:      // K1, Loop in
  96.             engine.setValue(group, "loop_in", value ? 1 : 0);
  97.             break;
  98.         case 0x02: case 0x16:    // K2, Loop out
  99.             engine.setValue(group, "loop_out", value ? 1 : 0);
  100.             break;
  101.         case 0x03: case 0x17:    // K3, Reloop/Exit
  102.             engine.setValue(group, "reloop_exit", value ? 1 : 0); break;
  103.             break;
  104.         case 0x04: case 0x18:    // K4, Reloop/Exit
  105.             engine.setValue(group, "reloop_exit", value ? 1 : 0);
  106.             break;
  107.  
  108.     // Hotcue buttons:
  109.     // Simple press: go to the hotcue position
  110.     // Shift (hold down "scratch"): clear the hotcue
  111.  
  112.         case 0x05: case 0x19 :    // K5
  113.             if (HerculesMk4.scratchButton == 1) {
  114.                 //HerculesMk4.holdButton(group, value, "hotcue_1_set", "hotcue_1_clear");
  115.                 engine.setValue(group, "hotcue_1_clear", value ? 1 : 0);
  116.             }
  117.             else engine.setValue(group, "hotcue_1_activate", value ? 1 : 0);
  118.             break;
  119.  
  120.         case 0x06: case 0x1A:    // K6
  121.             if (HerculesMk4.scratchButton == 1) {
  122.                 //HerculesMk4.holdButton(group, value, "hotcue_2_set", "hotcue_2_clear");
  123.                 engine.setValue(group, "hotcue_2_clear", value ? 1 : 0);
  124.             }
  125.             else engine.setValue(group, "hotcue_2_activate", value ? 1 : 0);
  126.             break;
  127.  
  128.         case 0x07: case 0x1B:    // K7
  129.             if (HerculesMk4.scratchButton == 1) {
  130.                 //HerculesMk4.holdButton(group, value, "hotcue_3_set", "hotcue_3_clear");
  131.                 engine.setValue(group, "hotcue_3_clear", value ? 1 : 0);
  132.             }
  133.             else engine.setValue(group, "hotcue_3_activate", value ? 1 : 0);
  134.             break;
  135.  
  136.         case 0x08: case 0x1C:    // K8
  137.             if (HerculesMk4.scratchButton == 1) {
  138.                 //HerculesMk4.holdButton(group, value, "hotcue_4_set", "hotcue_4_clear");
  139.                 engine.setValue(group, "hotcue_4_clear", value ? 1 : 0);
  140.             }
  141.             else engine.setValue(group, "hotcue_4_activate", value ? 1 : 0);
  142.             break;
  143.         }
  144. };
  145.  
  146. HerculesMk4.knobIncrement = function (group, action, minValue, maxValue, centralValue, step, sign) {
  147.     // This function allows you to increment a non-linear value like the volume's knob
  148.     // sign must be 1 for positive increment, -1 for negative increment
  149.     var semiStep = step/2;
  150.     var rangeWidthLeft = centralValue-minValue;
  151.     var rangeWidthRight = maxValue-centralValue;
  152.     var actual = engine.getValue(group, action);
  153.     var increment;
  154.     if (actual < 1) increment = ((rangeWidthLeft)/semiStep)*sign;
  155.     if (actual > 1) increment = ((rangeWidthRight)/semiStep)*sign;
  156.     if (actual == 1) {
  157.         increment = (sign == 1) ? rangeWidthRight/semiStep : (rangeWidthLeft/semiStep)*sign;
  158.     }
  159.  
  160.     var newValue;
  161.     
  162.     if (sign == 1 && actual < maxValue)     newValue = actual + increment;
  163.     if (sign == -1 && actual > minValue)    newValue = actual + increment;
  164.     return newValue;
  165. };
  166.  
  167.  
  168. HerculesMk4.deck=function(group){
  169.  //channel 1 -->deck 0
  170.  //channel 2 -->deck 1    
  171.  return (group=="[Channel1]") ? 0 : 1;
  172. }
  173.  
  174. HerculesMk4.selectLed=function(group,led){
  175.  //channel 1 -->led 0
  176.  //channel 2 -->led + 20    
  177.  return (group=="[Channel1]") ? led : led+20;
  178. }
  179.  
  180.  
  181.  
  182. HerculesMk4.pitch = function (midino, control, value, status, group) {
  183.     // Simple: pitch slider
  184.     
  185.         
  186.     if (HerculesMk4.scratchButton == 1) {
  187.         var sign = (value == 0x01) ? 1 : -1;                
  188.         var newValue = HerculesMk4.knobIncrement(group, "pregain", 0, 4, 1, 60, sign);
  189.         engine.setValue(group, "pregain", newValue);
  190.     }
  191.     else {            
  192.                
  193.         var increment = 0.005 * HerculesMk4.sensivityPitch[HerculesMk4.deck(group)];
  194.         increment = (value == 0x01) ? increment : increment * -1;
  195.         engine.setValue(group, "rate", engine.getValue(group, "rate") + increment);
  196.     }
  197. };
  198.  
  199.  
  200. HerculesMk4.pfl = function (midino, control, value, status, group) {
  201.  
  202.     if(value){
  203.     
  204.         engine.setValue(group,"pfl",(engine.getValue(group,"pfl")) ? 0 :1 );
  205.     
  206.         var pfl1=engine.getValue("[Channel1]","pfl");
  207.         var pfl2=engine.getValue("[Channel2]","pfl");
  208.     
  209.         
  210.         var actualMixCue=engine.getValue("[Master]","headMix");
  211.         
  212.         if(pfl1==0 && pfl2==0){
  213.             HerculesMk4.antiguoMixCue=actualMixCue;
  214.             engine.setValue("[Master]","headMix",1);
  215.         }else{            
  216.             if(actualMixCue==1){
  217.                 engine.setValue("[Master]","headMix",antiguoMixCue);
  218.             }            
  219.         };
  220.     };    
  221. };
  222.  
  223.  
  224.  
  225.  
  226. HerculesMk4.pitchbend = function (midino, control, value, status, group) {
  227.     // Pitch - : set pitch sensivity
  228.     // Pitch +:  set jog fast position
  229.     
  230.     //ignore when releasing the button
  231.     if(value==0x00) return;
  232.     
  233.     if (control == 0x0B || control == 0x1F) { // Pitchbend +
  234.         var newValue = (HerculesMk4.jogFastPosition[HerculesMk4.deck(group)]==1)? 0 : 1;
  235.         
  236.         HerculesMk4.jogFastPosition[HerculesMk4.deck(group)]=newValue;
  237.         
  238.         if(newValue==1){
  239.             midi.sendShortMsg(0x90, HerculesMk4.selectLed(group,11), 0x7f);
  240.         }else{
  241.             midi.sendShortMsg(0x90, HerculesMk4.selectLed(group,11), 0x00);
  242.         }        
  243.     }
  244.     else { // Pitchbend -        
  245.         HerculesMk4.sensivityPitch[HerculesMk4.deck(group)]=HerculesMk4.toglePitchSensivity(group,HerculesMk4.sensivityPitch[HerculesMk4.deck(group)]);
  246.         
  247.     }
  248.     
  249. };
  250.  
  251.  
  252. HerculesMk4.toglePitchSensivity=function (group,sensivity) {
  253.     
  254.     sensivity=sensivity+2;
  255.     
  256.     if(sensivity>5){ 
  257.         sensivity=1;
  258.     }
  259.     
  260.     
  261.     
  262.     if(sensivity==1){
  263.         //pitch very fine
  264.         midi.sendShortMsg(0x90, HerculesMk4.selectLed(group,10), 0x00);    // minus led off
  265.         midi.sendShortMsg(0x90, HerculesMk4.selectLed(group,58), 0x7F);    // Blink minus led
  266.         
  267.     } else if (sensivity==3){
  268.         //pitch fine
  269.         midi.sendShortMsg(0x90, HerculesMk4.selectLed(group,58), 0x00);    // Blink minus led off
  270.         midi.sendShortMsg(0x90, HerculesMk4.selectLed(group,10), 0x7F);    // minus led
  271.         
  272.     } else {
  273.         //pitch coarse
  274.         midi.sendShortMsg(0x90, HerculesMk4.selectLed(group,58), 0x00);    // Blink minus led off
  275.         midi.sendShortMsg(0x90, HerculesMk4.selectLed(group,10), 0x00);    // minus led off
  276.     }
  277.     
  278.     return sensivity;
  279.     
  280. }
  281.         
  282. HerculesMk4.cue = function (midino, control, value, status, group) {
  283.     // Don't set Cue accidentaly at the end of the song
  284.     
  285.     if(engine.getValue(group, "playposition") <= 0.97) {
  286.         engine.setValue(group, "cue_default", value ? 1 : 0);
  287.     }
  288.     else     engine.setValue(group, "cue_preview", value ? 1 : 0);
  289. };
  290.  
  291. HerculesMk4.scratch = function (midino, control, value, status, group) {
  292.     // The "scratch" button is used like a shift button only for enable the scratch mode on the 
  293.     // deck A and/or B with the "sync" buttons
  294.     if (value) {
  295.         HerculesMk4.scratchButton = 1;
  296.         //Switch-on the LEDs of Sync buttons while the "scratch" button is hold down
  297.         midi.sendShortMsg(0x90, 18, 0x7F); 
  298.         midi.sendShortMsg(0x90, 38, 0x7F);
  299.         }
  300.     else {
  301.         HerculesMk4.scratchButton = 0;
  302.         midi.sendShortMsg(0x90, 18, 0x00);
  303.         midi.sendShortMsg(0x90, 38, 0x00);
  304.         }
  305. };
  306.  
  307. HerculesMk4.sync = function (midino, control, value, status, group) {
  308.     
  309.     if (HerculesMk4.scratchButton && value) { // If the "scratch" button is hold down
  310.         
  311.         if(HerculesMk4.scratchMode[HerculesMk4.deck(group)]==0) {
  312.             engine.scratchEnable(HerculesMk4.deck(group)+1, 128, HerculesMk4.standardRpm, HerculesMk4.alpha, HerculesMk4.beta); // Enable the scratch mode on Deck A
  313.             HerculesMk4.scratchMode[HerculesMk4.deck(group)] = 1;
  314.             midi.sendShortMsg(0x90, HerculesMk4.selectLed(group,66), 0x7F); // Blinks the sync led
  315.         }
  316.         else {
  317.             engine.scratchDisable(HerculesMk4.deck(group)+1);
  318.             HerculesMk4.scratchMode[HerculesMk4.deck(group)] = 0;
  319.             midi.sendShortMsg(0x90, HerculesMk4.selectLed(group,66), 0x00); // Switch-off the sync led
  320.         }    
  321.         
  322.     }
  323.     else engine.setValue(group, "beatsync", value ? 1 : 0);
  324. };
  325.  
  326. HerculesMk4.jogWheel = function (midino, control, value, status, group) {
  327.     // This function is called everytime the jog is moved
  328.     
  329.     var direction=(value == 0x01)? 1: -1;
  330.     
  331.     engine.scratchTick(HerculesMk4.deck(group)+1, direction);
  332.     
  333.     var turboSeek=engine.getValue(group,"play")==0 && HerculesMk4.jogFastPosition[HerculesMk4.deck(group)]==1 && HerculesMk4.scratchMode[HerculesMk4.deck(group)]==0;
  334.         
  335.     if(turboSeek) {        
  336.         var new_position = engine.getValue(group,"playposition")+ 0.008*direction;
  337.         if(new_position<0) new_position=0;
  338.         if(new_position>1) new_position=1;
  339.         
  340.         engine.setValue(group,"playposition",new_position);
  341.     }
  342.     
  343.     
  344.     if( !turboSeek){
  345.         engine.setValue(group, "jog", direction);
  346.     }
  347. };