Advertisement
Guest User

Untitled

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