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 / Ion-Discover-DJ-scripts.js < prev    next >
Text File  |  2010-12-02  |  8KB  |  212 lines

  1. function IonDiscoverDJ () {}
  2. IonDiscoverDJ.leds = {
  3. "scratch":0x48,
  4. "[Channel1] sync":0x40,
  5. "[Channel1] rev":0x33,
  6. "[Channel1] cue":0x3B,
  7. "[Channel1] play":0x4A,
  8. "[Channel2] sync":0x47,
  9. "[Channel2] rev":0x3C,
  10. "[Channel2] cue":0x42,
  11. "[Channel2] play":0x4C
  12. };
  13.  
  14. IonDiscoverDJ.debug = true;
  15. IonDiscoverDJ.ledOn = 0x7F;
  16. IonDiscoverDJ.ledOff = 0x00;
  17. IonDiscoverDJ.scratchMode = false;
  18. IonDiscoverDJ.pitchDial1 = false;
  19. IonDiscoverDJ.pitchDial2 = false;
  20.  
  21. IonDiscoverDJ.init = function (id) {    // called when the MIDI device is opened & set up
  22.     print ("Ion Discover DJ id: \""+id+"\" initialized.");
  23.  
  24.     var timeToWait = 20;
  25.     for (var LED in IonDiscoverDJ.leds ) {
  26.         IonDiscoverDJ.sendMidi(0x80, IonDiscoverDJ.leds[LED], IonDiscoverDJ.ledOff, timeToWait);
  27.         timeToWait += 5;
  28.     }
  29.     
  30.     for (var LED in IonDiscoverDJ.leds ) {
  31.         IonDiscoverDJ.sendMidi(0x90, IonDiscoverDJ.leds[LED], IonDiscoverDJ.ledOn, timeToWait);
  32.         timeToWait += 5;
  33.     }
  34.     
  35.     timeToWait += 1000;
  36.     for (var LED in IonDiscoverDJ.leds ) {
  37.         IonDiscoverDJ.sendMidi(0x80, IonDiscoverDJ.leds[LED], IonDiscoverDJ.ledOff, timeToWait);
  38.         timeToWait += 5;
  39.     }
  40. };
  41.  
  42. IonDiscoverDJ.sendMidi = function(status, control, value, timeToWait) {
  43.    if(timeToWait == 0) {
  44.       midi.sendShortMsg(status, control, value);
  45.    } else {
  46.       engine.beginTimer(timeToWait, "midi.sendShortMsg(" + status + ", " + control + ", " + value + ")", true);
  47.    }
  48. };
  49.  
  50. //Decks
  51. IonDiscoverDJ.Deck = function (deckNumber, group) {
  52.    this.deckNumber = deckNumber;
  53.    this.group = group;
  54.    this.shiftMode = false;
  55.    this.scratching = false;
  56.    this.Buttons = [];
  57. };
  58.  
  59. IonDiscoverDJ.Deck.prototype.jogMove = function(jogValue) {
  60.    if(this.shiftMode) {
  61.       var newRate = engine.getValue(this.group, "rate") + (jogValue/3000);
  62.       engine.setValue(this.group, "rate", newRate);
  63.    } else if(this.scratching) {
  64.       engine.scratchTick(this.deckNumber, jogValue);
  65.    } else {
  66.       jogValue = jogValue * 10;
  67.       engine.setValue(this.group,"jog", jogValue);
  68.    }
  69. };
  70.  
  71. IonDiscoverDJ.Decks = {"Left":new IonDiscoverDJ.Deck(1,"[Channel1]"), "Right":new IonDiscoverDJ.Deck(2,"[Channel2]")};
  72. IonDiscoverDJ.GroupToDeck = {"[Channel1]":"Left", "[Channel2]":"Right"};
  73.  
  74. IonDiscoverDJ.GetDeck = function(group) {
  75.    try {
  76.       return IonDiscoverDJ.Decks[IonDiscoverDJ.GroupToDeck[group]];
  77.    } catch(ex) {
  78.       return null;
  79.    }
  80. };
  81.  
  82.  
  83. IonDiscoverDJ.getControl = function (io, channel, name) { 
  84.     // Accept channel in form 'N' or '[ChannelN]'
  85.     channel = channel.replace(/\[Channel(\d)\]/, "$1");
  86.  
  87.     for (control in IonDiscoverDJ.controls.inputs) {
  88.     if (IonDiscoverDJ.controls.inputs[control].channel == channel && 
  89.         IonDiscoverDJ.controls.inputs[control].name == name
  90.         ) return IonDiscoverDJ.controls.inputs[control];
  91.     }
  92.  
  93.     print ("IonDiscoverDJ.getControl: Control not found: io=" + io + ": channel=" + channel + ": name=" + name);
  94. }
  95.  
  96. IonDiscoverDJ.shutdown = function() {
  97. }
  98.  
  99. IonDiscoverDJ.toggle_scratch_mode_on = function (control, value, status) {
  100.     IonDiscoverDJ.scratchMode = true;
  101.     midi.sendShortMsg(0x90, IonDiscoverDJ.leds["scratch"] , IonDiscoverDJ.ledOn);
  102. }
  103.  
  104. IonDiscoverDJ.toggle_scratch_mode_off = function (control, value, status) {
  105.     IonDiscoverDJ.scratchMode = false;
  106.     midi.sendShortMsg(0x80, IonDiscoverDJ.leds["scratch"] , IonDiscoverDJ.ledOff);
  107. }
  108.  
  109. IonDiscoverDJ.play = function (control, value, status) {
  110.    // Only send events when play is pushed, not when it comes back up.
  111.    // group = IonDiscoverDJ.getGroup(control);
  112.    // if (engine.getValue(group, "duration") == 0) { if (value) print("No song on " + group); return; }; 
  113.    //midi.sendShortMsg(0x90, IonDiscoverDJ.leds[IonDiscoverDJ.getGroup(control) + " play"], IonDiscoverDJ.ledOn);
  114.   // midi.sendShortMsg(0x90, IonDiscoverDJ.leds["[Channel1] play"], IonDiscoverDJ.ledOn);
  115.    // engine.setValue(group,"play", !engine.getValue(group,"play"));
  116.    // if (engine.getValue(group, "play") == 0) midi.sendShortMsg(0x80, IonDiscoverDJ.leds[group + " play"], IonDiscoverDJ.ledOFF); 
  117. }   
  118.  
  119. IonDiscoverDJ.jog_touch = function (channel, control, value, status, group) {
  120.    var deck = IonDiscoverDJ.GetDeck(group);
  121.    if(value) {
  122.       if(IonDiscoverDJ.scratchMode) {
  123.          engine.scratchEnable(deck.deckNumber, 128, 45, 1.0/8, (1.0/8)/32);
  124.          deck.scratching = true;
  125.       }
  126.    } else {
  127.       deck.scratching = false;
  128.       engine.scratchDisable(deck.deckNumber);
  129.    }
  130. };
  131.  
  132. IonDiscoverDJ.jog_wheel = function (channel, control, value, status, group) {
  133.    // 7F > 40: CCW Slow > Fast - 127 > 64 
  134.    // 01 > 3F: CW Slow > Fast - 0 > 63
  135.    var jogValue = value >=0x40 ? value - 0x80 : value; // -64 to +63, - = CCW, + = CW
  136.    IonDiscoverDJ.GetDeck(group).jogMove(jogValue);
  137. };
  138.  
  139. IonDiscoverDJ.reversek = function (channel, control, value, status, group) {
  140.    var deck = IonDiscoverDJ.GetDeck(group);
  141.    
  142.    deck.shiftMode = (value == 0x7F); //If button down on, else off
  143. }
  144.  
  145. IonDiscoverDJ.volCh1Up = function (group, control, value, status) {
  146. engine.setValue("[Channel1]","pregain", engine.getValue("[Channel1]", "pregain") + 0.1);
  147. }
  148. IonDiscoverDJ.volCh1Down = function (group, control, value, status) {
  149. engine.setValue("[Channel1]","pregain", engine.getValue("[Channel1]", "pregain") - 0.1);
  150. }
  151. IonDiscoverDJ.volCh2Up = function (group, control, value, status) {
  152. engine.setValue("[Channel2]","pregain", engine.getValue("[Channel2]", "pregain") + 0.1);
  153. }
  154. IonDiscoverDJ.volCh2Down = function (group, control, value, status) {
  155. engine.setValue("[Channel2]","pregain", engine.getValue("[Channel2]", "pregain") - 0.1);
  156. }
  157.  
  158. IonDiscoverDJ.pflCh1On = function (group, control, value, status) {
  159.    if(engine.getValue("[Channel1]", "pfl")){
  160.       engine.setValue("[Channel1]","pfl", false);
  161.       midi.sendShortMsg(0x90, IonDiscoverDJ.leds["[Channel1] cue"], IonDiscoverDJ.ledOff);}
  162.    else {
  163.       engine.setValue("[Channel1]","pfl", true);
  164.       midi.sendShortMsg(0x90, IonDiscoverDJ.leds["[Channel1] cue"], IonDiscoverDJ.ledOn);}
  165.    }
  166. IonDiscoverDJ.pflCh1Off = function (group, control, value, status) {}
  167.  
  168. IonDiscoverDJ.pflCh2On = function (group, control, value, status) {
  169.    if(engine.getValue("[Channel2]", "pfl")){
  170.       engine.setValue("[Channel2]","pfl", false);
  171.       midi.sendShortMsg(0x90, IonDiscoverDJ.leds["[Channel2] cue"], IonDiscoverDJ.ledOff);}
  172.    else {
  173.       engine.setValue("[Channel2]","pfl", true);
  174.       midi.sendShortMsg(0x90, IonDiscoverDJ.leds["[Channel2] cue"], IonDiscoverDJ.ledOn);}
  175.    }
  176. IonDiscoverDJ.pflCh2Off = function (group, control, value, status) {}
  177.  
  178.  
  179.  
  180. IonDiscoverDJ.LoadSelectedTrackCh1 = function (group, control, value, status) 
  181. {
  182.    //midi.sendShortMsg(0x90, IonDiscoverDJ.leds["[Channel1] play"], IonDiscoverDJ.ledOn);
  183.    engine.setValue("[Channel1]","LoadSelectedTrack", true);
  184.    
  185.    //IonDiscoverDJ.pauseScript(5000);
  186.    //engine.setValue("[Channel1]","play", true);
  187.    //midi.sendShortMsg(0x90, IonDiscoverDJ.leds["[Channel1] play"], IonDiscoverDJ.ledOff);
  188.    
  189.    //IonDiscoverDJ.pauseScript(5000);
  190.    //midi.sendShortMsg(0x90, IonDiscoverDJ.leds["[Channel1] sync"], IonDiscoverDJ.ledOn);
  191.    //IonDiscoverDJ.pauseScript(200);
  192.    //engine.setValue("[Channel1]","beatsync", true);
  193.    //midi.sendShortMsg(0x90, IonDiscoverDJ.leds["[Channel1] sync"], IonDiscoverDJ.ledOff);
  194. }
  195.  
  196. IonDiscoverDJ.LoadSelectedTrackCh2 = function (group, control, value, status) 
  197. {
  198.    //midi.sendShortMsg(0x90, IonDiscoverDJ.leds["[Channel2] play"], IonDiscoverDJ.ledOn);
  199.    engine.setValue("[Channel2]","LoadSelectedTrack", true);
  200.    
  201.    //IonDiscoverDJ.pauseScript(5000);
  202.    //engine.setValue("[Channel2]","play", true);
  203.    //midi.sendShortMsg(0x90, IonDiscoverDJ.leds["[Channel2] play"], IonDiscoverDJ.ledOff);
  204.    
  205.    //IonDiscoverDJ.pauseScript(5000);
  206.    //midi.sendShortMsg(0x90, IonDiscoverDJ.leds["[Channel2] sync"], IonDiscoverDJ.ledOn);
  207.    //IonDiscoverDJ.pauseScript(200);
  208.    //engine.setValue("[Channel2]","beatsync", true);
  209.    //midi.sendShortMsg(0x90, IonDiscoverDJ.leds["[Channel2] sync"], IonDiscoverDJ.ledOff);
  210. }
  211.  
  212.