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 / American-Audio-VMS4-scripts.js < prev    next >
Text File  |  2011-02-04  |  5KB  |  165 lines

  1. /**
  2.  * American Audio VMS4 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. VMS4 = new Controller();
  20. VMS4.RateRanges = [0.08, 0.10, 0.30, 1.00];
  21.  
  22. VMS4.Button = Button;
  23.  
  24. VMS4.Button.prototype.setLed = function(ledState) {
  25.    if(ledState == LedState.on) {
  26.       midi.sendShortMsg(0x90,this.controlId,LedState.on);
  27.    } else {
  28.       midi.sendShortMsg(0x80,this.controlId,LedState.off);  
  29.    }
  30. }
  31.  
  32. VMS4.Deck = Deck;
  33. VMS4.Deck.scratchMode = false;
  34. VMS4.Deck.jogMsb = 0x00;
  35. VMS4.Deck.rateRange = VMS4.RateRanges[1];
  36.  
  37. VMS4.Deck.prototype.rateRangeHandler = function(value) {
  38.    if(value == ButtonState.pressed) {
  39.       var i;
  40.       for(i=0; i < VMS4.RateRanges.length; i++) {
  41.          if(VMS4.RateRanges[i] == this.rateRange) {
  42.             break;
  43.          }
  44.       }
  45.       
  46.       //Found correct value increment by one
  47.       i++;
  48.       
  49.       //Wrap if needed
  50.       if(i == VMS4.RateRanges.length) {
  51.          i = 0;
  52.       }
  53.       
  54.       this.rateRange = VMS4.RateRanges[i];
  55.    }
  56. }
  57.  
  58. VMS4.Deck.prototype.playHandler = function(value) {
  59.    engine.setValue(this.group, "play", 1);
  60. }
  61.  
  62. VMS4.Deck.prototype.pauseHandler = function(value) {
  63.    engine.setValue(this.group, "play", 0);
  64. }
  65.  
  66. VMS4.Deck.prototype.scratchHandler = function(value) {
  67.    if(value == ButtonState.pressed) {
  68.       if(this.scratchMode) {
  69.          this.scratchMode = false;
  70.          this.Buttons.Scratch.setLed(LedState.off);
  71.       } else {
  72.          this.scratchMode = true;
  73.          this.Buttons.Scratch.setLed(LedState.on);
  74.       }
  75.    }
  76.    print("scratchMode: " + this.scratchMode);
  77. }
  78.  
  79. VMS4.Deck.prototype.jogTouchHandler = function(value) {
  80.    if(value == ButtonState.pressed && this.scratchMode) {
  81.       engine.scratchEnable(this.deckNumber, 3000, 45, 1.0/8, (1.0/8)/32);
  82.    } else {
  83.       engine.scratchDisable(this.deckNumber);
  84.    }
  85. }
  86.  
  87. VMS4.Deck.prototype.jogMove = function(lsbValue) {
  88.    var jogValue = (this.jogMsb << 7) + lsbValue;
  89.  
  90.    if(!isNaN(this.previousJogValue)) {
  91.       var offset = jogValue - this.previousJogValue;
  92.  
  93.       if(offset > 8192) {
  94.          offset = offset - 16384;
  95.       } else if(offset < -8192) {
  96.          offset = offset + 16384;
  97.       }
  98.  
  99.       if(this.scratchMode) {
  100.          engine.scratchTick(this.deckNumber, offset);
  101.       } else {
  102.          engine.setValue(this.group,"jog", offset / 40.0);
  103.       }
  104.    }
  105.    this.previousJogValue = jogValue;
  106. }
  107.  
  108. VMS4.Decks = {"Left":new VMS4.Deck(1,"[Channel1]"), "Right":new VMS4.Deck(2,"[Channel2]")};
  109. VMS4.GroupToDeck = {"[Channel1]":"Left", "[Channel2]":"Right"};
  110.  
  111. VMS4.GetDeck = function(group) {
  112.    try {
  113.       return VMS4.Decks[VMS4.GroupToDeck[group]];
  114.    } catch(ex) {
  115.       return null;
  116.    }
  117. }
  118.  
  119. VMS4.Decks.Left.addButton("RateRange", new VMS4.Button(), "rateRangeHandler");
  120. VMS4.Decks.Left.addButton("Play", new VMS4.Button(), "playHandler");
  121. VMS4.Decks.Left.addButton("Pause", new VMS4.Button(), "pauseHandler");
  122. VMS4.Decks.Left.addButton("Scratch", new VMS4.Button(0x27), "scratchHandler");
  123. VMS4.Decks.Left.addButton("JogTouch", new VMS4.Button(), "jogTouchHandler");
  124.  
  125. VMS4.Decks.Right.addButton("RateRange", new VMS4.Button(), "rateRangeHandler");
  126. VMS4.Decks.Right.addButton("Play", new VMS4.Button(), "playHandler");
  127. VMS4.Decks.Right.addButton("Pause", new VMS4.Button(), "pauseHandler");
  128. VMS4.Decks.Right.addButton("Scratch", new VMS4.Button(0x49), "scratchHandler");
  129. VMS4.Decks.Right.addButton("JogTouch", new VMS4.Button(), "jogTouchHandler");
  130.  
  131. //Mapping functions
  132. VMS4.rate_range = function(channel, control, value, status, group) {
  133.    var deck = VMS4.GetDeck(group);
  134.    deck.Buttons.RateRange.handleEvent(value);
  135. }
  136.  
  137. VMS4.play = function(channel, control, value, status, group) {
  138.    var deck = VMS4.GetDeck(group);
  139.    deck.Buttons.Play.handleEvent(value);
  140. }
  141.  
  142. VMS4.pause = function(channel, control, value, status, group) {
  143.    var deck = VMS4.GetDeck(group);
  144.    deck.Buttons.Pause.handleEvent(value);
  145. }
  146.  
  147. VMS4.scratch = function(channel, control, value, status, group) {
  148.    var deck = VMS4.GetDeck(group);
  149.    deck.Buttons.Scratch.handleEvent(value);
  150. }
  151.  
  152. VMS4.jog_touch = function(channel, control, value, status, group) {
  153.    var deck = VMS4.GetDeck(group);
  154.    deck.Buttons.JogTouch.handleEvent(value);
  155. }
  156.  
  157. VMS4.jog_move_lsb = function(channel, control, value, status, group) {
  158.    var deck = VMS4.GetDeck(group);
  159.    deck.jogMove(value);
  160. }
  161.  
  162. VMS4.jog_move_msb = function(channel, control, value, status, group) {
  163.    var deck = VMS4.GetDeck(group);
  164.    deck.jogMsb = value;
  165. }