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 / Vestax-Spin-scripts.js < prev    next >
Text File  |  2011-02-04  |  11KB  |  341 lines

  1. // Script file for Mixxx Vestax Spin mapping
  2. // Bill Good, Oct 31, 2010
  3. // Parts of addButton and handleEvent are the work of Anders Gunnarsson
  4.  
  5. // move vu's to script? or fix bug in midi output saving
  6.  
  7. VestaxSpin = new function() {
  8.     this.group = "[Master]";
  9.     this.decks = [];
  10.     this.buttons = [];
  11.     this.controls = [];
  12.     this.lights = [];
  13. }
  14.  
  15. VestaxSpin.DECK_LIGHTS = [0x32, 0x35, 0x33, 0x24, 0x25, 0x46, 0x42, 0x21, 0x20, 0x29, 0x2a, 0x2b,
  16.     0x2c, 0x2d];
  17. VestaxSpin.MISC_LIGHTS = [0x26, 0x29, 0x28, 0x2a];
  18.  
  19. VestaxSpin.init = function(id) {
  20.     VestaxSpin.decks = {
  21.         "L": new VestaxSpin.Deck(1,"[Channel1]"),
  22.         "R": new VestaxSpin.Deck(2,"[Channel2]")
  23.     };
  24.  
  25.     VestaxSpin.addButton("songlist", new VestaxSpin.Button(2, 0x26, true), "handleSongList");
  26.     VestaxSpin.lights["killwheels"] = new VestaxSpin.Light(2, 0x2a);
  27.     VestaxSpin.lights["killwheels"].off();
  28.  
  29.     // clear everything
  30.     for (var light in VestaxSpin.DECK_LIGHTS) {
  31.         new VestaxSpin.Light(0, VestaxSpin.DECK_LIGHTS[light]).off();
  32.         new VestaxSpin.Light(1, VestaxSpin.DECK_LIGHTS[light]).off();
  33.         for (var j = 0; j < 10000000; ++j);
  34.     }
  35.     for (var light in VestaxSpin.MISC_LIGHTS) {
  36.         new VestaxSpin.Light(2, VestaxSpin.MISC_LIGHTS[light]).off();
  37.         for (var j = 0; j < 10000000; ++j);
  38.     }
  39.     // make the eqs do some pretty things
  40. /*    var vu = [0x29, 0x2a, 0x2b, 0x2c, 0x2d];
  41.     for (var light in vu) {
  42.         new VestaxSpin.Light(0, vu[light]).on();
  43.         new VestaxSpin.Light(1, vu[light]).on();
  44.         for (var j = 0; j < 20000000; ++j);
  45.     }
  46.     for (var light in vu) {
  47.         new VestaxSpin.Light(0, vu[light]).off();
  48.         new VestaxSpin.Light(1, vu[light]).off();
  49.         for (var j = 0; j < 20000000; ++j);
  50.     }*/
  51.  
  52. }
  53.  
  54. VestaxSpin.shutdown = function(id) {
  55.     // clear everything
  56.     for (var light in VestaxSpin.DECK_LIGHTS) {
  57.         new VestaxSpin.Light(0, VestaxSpin.DECK_LIGHTS[light]).off();
  58.         new VestaxSpin.Light(1, VestaxSpin.DECK_LIGHTS[light]).off();
  59.         for (var j = 0; j < 10000000; ++j);
  60.     }
  61.     for (var light in VestaxSpin.MISC_LIGHTS) {
  62.         new VestaxSpin.Light(2, VestaxSpin.MISC_LIGHTS[light]).off();
  63.         for (var j = 0; j < 10000000; ++j);
  64.     }
  65. }
  66.  
  67. VestaxSpin.GetDeck = function(group) {
  68.     var groupToDeck = {
  69.         "[Channel1]": "L",
  70.         "[Channel2]": "R",
  71.     };
  72.     try {
  73.         return this.decks[groupToDeck[group]];
  74.     } catch (ex) {
  75.         return null;
  76.     }
  77. }
  78.  
  79. VestaxSpin.addButton = function(buttonName, button, eventHandler) {
  80.     button.group = this.group;
  81.     button.parent = this;
  82.  
  83.     if (eventHandler) {
  84.        var executionEnvironment = button;
  85.        function handler(value) {
  86.           try {
  87.               executionEnvironment[eventHandler]();
  88.           } catch (ex) {
  89.               print("exception in executing handler for button " + buttonName + ": " + ex);
  90.           }
  91.        }
  92.        button.handler = handler;
  93.     }
  94.     this.buttons[buttonName] = button;
  95.     var control_map = this.controls[button.control];
  96.     if (control_map) {
  97.         control_map.push(button);
  98.     } else {
  99.         this.controls[button.control] = [button];
  100.     }
  101. }
  102.  
  103. VestaxSpin.handleEvent = function(channel, control, value, status, group) {
  104.     var deck = VestaxSpin.GetDeck(group);
  105.     if (deck != null) {
  106.         deck.handleEvent(channel, control, value, status, group);
  107.     } 
  108.     try {
  109.         var buttons = VestaxSpin.controls[control];
  110.     } catch (ex) {
  111.         return;
  112.     }
  113.     for (var button in buttons) {
  114.         buttons[button].handleEvent(value);
  115.     }
  116. }
  117.  
  118. VestaxSpin.ButtonState = {"released": 0x00, "pressed": 0x7F};
  119.  
  120. VestaxSpin.Button = function(channel, control, makeLight, lightControl) {
  121.     this.channel = channel;
  122.     this.control = control;
  123.     this.group = null;
  124.     this.state = VestaxSpin.ButtonState.released;
  125.     this.handler = null;
  126.     this.parent = null;
  127.     if (makeLight) {
  128.         if (lightControl) {
  129.             this.light = new VestaxSpin.Light(this.channel, lightControl);
  130.         } else {
  131.             this.light = new VestaxSpin.Light(this.channel, this.control);
  132.         }
  133.     } else {
  134.         this.light = null;
  135.     }
  136. }
  137.  
  138. VestaxSpin.LightState = {"on": 0x7f, "off": 0x00};
  139.  
  140. VestaxSpin.Light = function(channel, control) {
  141.     this.channel = channel;
  142.     this.control = control;
  143.     this.state = VestaxSpin.LightState.off;
  144.     this.on = function() {
  145.         midi.sendShortMsg(0x90 + this.channel, this.control, VestaxSpin.LightState.on);
  146.         this.state = VestaxSpin.LightState.on;
  147.     }
  148.     this.off = function() {
  149.         midi.sendShortMsg(0x90 + this.channel, this.control, VestaxSpin.LightState.off);
  150.         this.state = VestaxSpin.LightState.off;
  151.     }
  152. }
  153.  
  154. VestaxSpin.Button.prototype.handleEvent = function(value) {
  155.     this.state = value;
  156.     this.handler();
  157. }
  158.  
  159. VestaxSpin.Deck = function(deckNum, group) {
  160.     this.deckNum = deckNum;
  161.     this.group = group;
  162.     this.vinylMode = false;
  163.     this.buttons = [];
  164.     this.controls = [];
  165.     this.lights = [];
  166.     this.addButton("loop_open", new VestaxSpin.Button(deckNum-1, 0x21, true), "handleLoopOpen");
  167.     this.addButton("loop_close", new VestaxSpin.Button(deckNum-1, 0x42, true), "handleLoopClose");
  168.     this.addButton("sync", new VestaxSpin.Button(deckNum-1, 0x46, true), "handleSync");
  169.     this.addButton("cue", new VestaxSpin.Button(deckNum-1, 0x35, true), "handleCue");
  170.     this.addButton("cup", new VestaxSpin.Button(deckNum-1, 0x33, true), "handleCup");
  171.     this.addButton("filter", new VestaxSpin.Button(deckNum-1, 0x24, true), "handleFilter");
  172.     this.addButton("back", new VestaxSpin.Button(deckNum-1, 0x36, true, 0x32), "handleBack");
  173.     this.addButton("rw", new VestaxSpin.Button(deckNum-1, 0x37, true, 0x35), "handleRW");
  174.     this.addButton("ff", new VestaxSpin.Button(deckNum-1, 0x38, true, 0x33), "handleFF");
  175.     this.addButton("wheeltouch", new VestaxSpin.Button(deckNum-1, 0x2e), "handleWheelTouch");
  176.     // is this needed on the spin? I don't think we get a different control number
  177.     // from touch if the scratch button light is active like on typhoon
  178.     this.addButton("wheeltouchfilter", new VestaxSpin.Button(deckNum-1, 0x2f), "handleWheelTouchFilter");
  179.     this.addButton("jog", new VestaxSpin.Button(deckNum-1, 0x10), "handleJog");
  180.     // spin doesn't send different control number when the scratch button light
  181.     // is enabled like the typhoon does
  182.     //this.addButton("scratch", new VestaxSpin.Button(deckNum-1, 0x11), "handleScratch");
  183.  
  184.     this.lights["vu1"] = new VestaxSpin.Light(deckNum-1, 0x29);
  185.     this.lights["vu2"] = new VestaxSpin.Light(deckNum-1, 0x2a);
  186.     this.lights["vu3"] = new VestaxSpin.Light(deckNum-1, 0x2b);
  187.     this.lights["vu4"] = new VestaxSpin.Light(deckNum-1, 0x2c);
  188.     this.lights["vu5"] = new VestaxSpin.Light(deckNum-1, 0x2d);
  189. }
  190.  
  191. VestaxSpin.Deck.prototype.addButton = VestaxSpin.addButton;
  192.  
  193. VestaxSpin.Deck.prototype.handleEvent = function(channel, control, value, status, group) {
  194.     try {
  195.         var buttons = this.controls[control];
  196.     } catch (ex) {
  197.         return;
  198.     }
  199.     if (buttons) {
  200.         for (var button in buttons) {
  201.             buttons[button].handleEvent(value);
  202.         }
  203.     }
  204. }
  205.  
  206. VestaxSpin.Button.prototype.handleSongList = function() {
  207.     if (this.state == VestaxSpin.ButtonState.pressed) {
  208.         engine.setValue("[Playlist]", "SelectNextPlaylist", 1);
  209.         this.light.on();
  210.     } else {
  211.         engine.setValue("[Playlist]", "SelectNextPlaylist", 0);
  212.         this.light.off();
  213.     }
  214. }
  215.  
  216. VestaxSpin.Button.prototype.handleLoopOpen = function() {
  217.     if (this.state == VestaxSpin.ButtonState.pressed) {
  218.         engine.setValue(this.group, "loop_in", 1);
  219.         this.light.on();
  220.     } else {
  221.         engine.setValue(this.group, "loop_in", 0);
  222.         this.light.off();
  223.     }
  224. }
  225.  
  226. VestaxSpin.Button.prototype.handleLoopClose = function() {
  227.     if (this.state == VestaxSpin.ButtonState.pressed) {
  228.         engine.setValue(this.group, "loop_out", 1);
  229.         this.light.on();
  230.     } else {
  231.         engine.setValue(this.group, "loop_out", 0);
  232.         this.light.off();
  233.     }
  234. }
  235.  
  236. VestaxSpin.Button.prototype.handleSync = function() {
  237.     if (this.state == VestaxSpin.ButtonState.pressed) {
  238.         engine.setValue(this.group, "beatsync", 1);
  239.         this.light.on();
  240.     } else {
  241.         engine.setValue(this.group, "beatsync", 0);
  242.         this.light.off();
  243.     }
  244. }
  245.  
  246. VestaxSpin.Button.prototype.handleCue = function() {
  247.     if (this.state == VestaxSpin.ButtonState.pressed) {
  248.         engine.setValue(this.group, "cue_default", 1);
  249.         this.light.on();
  250.     } else {
  251.         engine.setValue(this.group, "cue_default", 0);
  252.         // shut off rw so that we don't get stuck in rw if the user lets go
  253.         // of shift before letting go of cue/rw
  254.         engine.setValue(this.group, "back", 0);
  255.         this.light.off();
  256.     }
  257. }
  258.  
  259. VestaxSpin.Button.prototype.handleCup = function() {
  260.     if (this.state == VestaxSpin.ButtonState.pressed) {
  261.         engine.setValue(this.group, "cue_goto", 1);
  262.         this.light.on();
  263.     } else {
  264.         engine.setValue(this.group, "cue_goto", 0);
  265.         // shut off ff so that we don't get stuck in ff if the user lets go
  266.         // of shift before letting go of cup/ff
  267.         engine.setValue(this.group, "fwd", 0);
  268.         this.light.off();
  269.     }
  270. }
  271.  
  272. VestaxSpin.Button.prototype.handleFilter = function() {
  273.     if (this.state == VestaxSpin.ButtonState.released) return;
  274.     if (this.parent.vinylMode == false) {
  275.        this.parent.vinylMode = true;
  276.        this.light.on();
  277.     } else {
  278.        this.parent.vinylMode = false;
  279.        this.light.off();
  280.     }
  281. }
  282.  
  283. VestaxSpin.Button.prototype.handleBack = function() {
  284.     if (this.state == VestaxSpin.ButtonState.pressed) {
  285.         engine.setValue(this.group, "play", 0);
  286.         engine.setValue(this.group, "playposition", 0);
  287.         this.light.on();
  288.     } else {
  289.         this.light.off();
  290.     }
  291. }
  292.  
  293. VestaxSpin.Button.prototype.handleRW = function() {
  294.     if (this.state == VestaxSpin.ButtonState.pressed) {
  295.         engine.setValue(this.group, "back", 1);
  296.         this.light.on();
  297.     } else {
  298.         engine.setValue(this.group, "back", 0);
  299.         this.light.off();
  300.     }
  301. }
  302.  
  303. VestaxSpin.Button.prototype.handleFF = function() {
  304.     if (this.state == VestaxSpin.ButtonState.pressed) {
  305.         engine.setValue(this.group, "fwd", 1);
  306.         this.light.on();
  307.     } else {
  308.         engine.setValue(this.group, "fwd", 0);
  309.         this.light.off();
  310.     }
  311. }
  312.  
  313. VestaxSpin.Button.prototype.handleWheelTouch = function() {
  314.    if (this.parent.vinylMode && this.state == VestaxSpin.ButtonState.pressed) {
  315.        // disable keylock on scratch
  316.        //this.keylock = engine.getValue(this.group, "keylock");
  317.        engine.scratchEnable(this.parent.deckNum, 128*3, 33+(1.0/3), 1.0/8, (1.0/8)/32);
  318.    } else {
  319.        engine.scratchDisable(this.parent.deckNum);
  320.    }
  321. }
  322.  
  323. VestaxSpin.Button.prototype.handleWheelTouchFilter = function() {
  324.     if (this.state == VestaxSpin.ButtonState.pressed) {
  325.         // disable keylock on scratch
  326.         //this.keylock = engine.getValue(this.group, "keylock");
  327.         engine.scratchEnable(this.parent.deckNum, 300, 33+(1.0/3), 1.0/8, (1.0/8)/32);
  328.     } else {
  329.         engine.scratchDisable(this.parent.deckNum);
  330.     }
  331. }
  332.  
  333. VestaxSpin.Button.prototype.handleJog = function() {
  334.     if (engine.getValue(this.group, "scratch2_enable")) {
  335.         engine.scratchTick(this.parent.deckNum, this.state - 0x40);
  336.     } else {
  337.         engine.setValue(this.group, "jog", this.state - 0x40);
  338.     }
  339. }
  340.  
  341.