Guest User

A-300-Pro.control.js

a guest
Nov 3rd, 2014
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.39 KB | None | 0 0
  1. /**
  2. * Created by Suloo on 29.10.2014.
  3. */
  4. loadAPI(1);
  5.  
  6. host.defineController("Cakewalk", "A-300 PRO", "1.1", "e504e660-2b27-11e4-8c21-0800200c9a66");
  7. host.defineMidiPorts(1, 1);
  8. host.addDeviceNameBasedDiscoveryPair(["A-PRO 1"], ["A-PRO"]);
  9.  
  10.  
  11. // CC 0 and CCs 120+ are reserved
  12. var LOWEST_CC = 1;
  13. var HIGHEST_CC = 119;
  14.  
  15. // Two array-variables to hold the values of all the CCs and to check if they have changed
  16. var ccValue = initArray(0, ((HIGHEST_CC - LOWEST_CC + 1)*16));
  17. var ccValueOld = initArray(0, ((HIGHEST_CC - LOWEST_CC + 1)*16));
  18.  
  19.  
  20. /*Load the A-300 Bitwig.mid file in your A-300 Editor and transmit it to the Hardware device. Then select
  21. the controller Map.*/
  22.  
  23. var _down = 22;
  24. var _up = 23;
  25. var _ff = 24;
  26. var _stop = 25;
  27. var _play = 26;
  28. var _loop = 27;
  29. var _record = 28;
  30. var _b1 = 29;
  31. var _b2 = 30;
  32. var _b3 = 3;
  33. var _b4 = 4;
  34.  
  35. var _knob1 = 102;
  36. var _knob2 = 103;
  37. var _knob3 = 104;
  38. var _knob4 = 105;
  39. var _knob5 = 106;
  40. var _knob6 = 107;
  41. var _knob7 = 108;
  42. var _knob8 = 109;
  43. var _mastervolume = 118;
  44.  
  45. // Macros:
  46. deviceMacro = [];
  47. deviceMacroHasChanged = [];
  48.  
  49. //var lockOnMacro[0] = false;
  50.  
  51. // A function to create an indexed function for the Observers
  52. function getValueObserverFunc(index, varToStore)
  53. {
  54. return function(value)
  55. {
  56. varToStore[index] = value;
  57. }
  58. }
  59.  
  60. // A function to create an indexed function for the Observers with an added state variable:
  61. function getTrackValueFunc(index, varToStore, varToSet)
  62. {
  63. return function(value)
  64. {
  65. varToStore[index] = value;
  66. varToSet[index] = true;
  67. }
  68. }
  69.  
  70. function init()
  71. {
  72. transport = host.createTransport();
  73. cursorTrack = host.createCursorTrack(0,0);
  74. primaryDevice = cursorTrack.getPrimaryDevice();
  75. masterTrack = host.createMasterTrack(0);
  76. application = host.createApplication();
  77.  
  78. for (var i = 0; i < 8; i++) {
  79. primaryDevice.getMacro(i).getAmount().setIndication(true);
  80. }
  81.  
  82. for (var i=0; i<8; i++) {
  83. // macros
  84. primaryDevice.getMacro(i).getAmount().addValueObserver(127, getTrackValueFunc(i, deviceMacro, deviceMacroHasChanged));
  85. }
  86.  
  87.  
  88.  
  89.  
  90.  
  91. // Create 16 NoteInputs + Omni.
  92. // Verbose to allow commenting out unneeded channels
  93. // To do so, put "//" in front of the lines containing channels you don't want to use
  94. // Be sure to do it for the "createNoteInput" lines as well as the corresponding
  95. // "setShouldConsumeEvents" and "assignPolyphonicAftertouchToExpression" lines below
  96. MultiBi = host.getMidiInPort(0).createNoteInput("MultiBi - Omni", "??????");
  97. MultiBi1 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 1", "?0????");
  98. MultiBi2 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 2", "?1????");
  99.  
  100.  
  101. // Disable the consuming of events by the NoteInputs, so they are also available for mapping
  102. MultiBi.setShouldConsumeEvents(false);
  103. MultiBi1.setShouldConsumeEvents(false);
  104.  
  105.  
  106. // Enable Poly AT translation into Timbre for the internal BWS instruments
  107. MultiBi.assignPolyphonicAftertouchToExpression(0, NoteExpression.TIMBRE_UP, 5);
  108. MultiBi1.assignPolyphonicAftertouchToExpression(0, NoteExpression.TIMBRE_UP, 5);
  109. MultiBi2.assignPolyphonicAftertouchToExpression(1, NoteExpression.TIMBRE_UP, 5);
  110.  
  111.  
  112.  
  113.  
  114.  
  115. // Enable Midi Beat Clock. Comment out if you don't want that
  116. host.getMidiOutPort(0).setShouldSendMidiBeatClock;
  117.  
  118. // Setting Callbacks for Midi and Sysex
  119. host.getMidiInPort(0).setMidiCallback(onMidi);
  120. host.getMidiInPort(0).setSysexCallback(onSysex);
  121.  
  122. // Make CCs 1-119 freely mappable for all 16 Channels
  123. userControls = host.createUserControls((HIGHEST_CC - LOWEST_CC + 1)*16);
  124.  
  125. for(var i=LOWEST_CC; i<=HIGHEST_CC; i++)
  126. {
  127. for (var j=1; j<=16; j++) {
  128. // Create the index variable c
  129. var c = i - LOWEST_CC + (j-1) * (HIGHEST_CC-LOWEST_CC+1);
  130. // Set a label/name for each userControl
  131. userControls.getControl(c).setLabel("CC " + i + " - Channel " + j);
  132. // Add a ValueObserver for each userControl
  133. userControls.getControl(c).addValueObserver(127, getValueObserverFunc(c, ccValue));
  134. }
  135. }
  136. }
  137.  
  138.  
  139.  
  140.  
  141. function exit()
  142. {
  143. // nothing to do here ;-)
  144. }
  145.  
  146.  
  147. // Update the UserControls when Midi Data is received
  148. function onMidi(status, data1, data2)
  149. {
  150.  
  151. printMidi(status, data1, data2);
  152.  
  153. if (isChannelController(status))
  154. {
  155. switch (data1)
  156. {
  157.  
  158. case _stop:
  159. transport.stop();
  160. break;
  161.  
  162. case _play:
  163. transport.play();
  164. break;
  165.  
  166. case _record:
  167. transport.record();
  168. break;
  169. case _loop:
  170. transport.toggleLoop();
  171. break;
  172. case _up:
  173. cursorTrack.selectNext();
  174. break;
  175. case _down:
  176. cursorTrack.selectPrevious();
  177. break;
  178. case _mastervolume:
  179. masterTrack.getVolume().set(data2, 128);
  180. masterTrack.getVolume().setIndication(true);
  181. break;
  182. case _b1:
  183. application.toggleNoteEditor();
  184. break;
  185. case _b2:
  186. application.toggleAutomationEditor();
  187. break;
  188. case _b3:
  189. application.toggleMixer();
  190. break;
  191. case _b4:
  192. application.toggleDevices();
  193. break;
  194. case _ff:
  195. cursorTrack.returnToArrangement();
  196. break;
  197.  
  198. case _knob1:
  199. primaryDevice.getMacro(0).getAmount().set(data2, 128);
  200. break;
  201. case _knob2:
  202. primaryDevice.getMacro(1).getAmount().set(data2, 128);
  203. break;
  204. case _knob3:
  205. primaryDevice.getMacro(2).getAmount().set(data2, 128);
  206. break;
  207. case _knob4:
  208. primaryDevice.getMacro(3).getAmount().set(data2, 128);
  209. break;
  210. case _knob5:
  211. primaryDevice.getMacro(4).getAmount().set(data2, 128);
  212. break;
  213. case _knob6:
  214. primaryDevice.getMacro(5).getAmount().set(data2, 128);
  215. break;
  216. case _knob7:
  217. primaryDevice.getMacro(6).getAmount().set(data2, 128);
  218. break;
  219. case _knob8:
  220. primaryDevice.getMacro(7).getAmount().set(data2, 128);
  221. break;
  222. }
  223. if (data1 >= LOWEST_CC && data1 <= HIGHEST_CC)
  224. {
  225. var index = data1 - LOWEST_CC + ((HIGHEST_CC-LOWEST_CC+1) * MIDIChannel(status));
  226. userControls.getControl(index).set(data2, 128);
  227. }
  228.  
  229. }
  230. var threshold = 5; // you need to experiment what works here.
  231. if (data1 === _knob1[0]) {
  232. if (lockOnMacro[0] === true) {
  233. primaryDevice.getMacro(0).getAmount().set(data2, 128);
  234. }
  235. else if (data2 >= (deviceMacro[0] - threshold) && data2 <= (deviceMacro[0] + threshold) ) {
  236. lockOnMacro[0] = true;
  237. primaryDevice.getMacro(0).getAmount().set(data2, 128);
  238. }
  239.  
  240. }
  241. }
  242.  
  243.  
  244. function onSysex(data)
  245. {
  246. //printSysex(data);
  247. }
Advertisement
Add Comment
Please, Sign In to add comment