Advertisement
Guest User

Untitled

a guest
Aug 24th, 2014
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.50 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.  
  20.  
  21.  
  22. // A function to create an indexed function for the Observers
  23. function getValueObserverFunc(index, varToStore)
  24. {
  25. return function(value)
  26. {
  27. varToStore[index] = value;
  28. }
  29. }
  30.  
  31. function init()
  32. {
  33. transport = host.createTransport();
  34.  
  35. // Create 16 NoteInputs + Omni.
  36. // Verbose to allow commenting out unneeded channels
  37. // To do so, put "//" in front of the lines containing channels you don't want to use
  38. // Be sure to do it for the "createNoteInput" lines as well as the corresponding
  39. // "setShouldConsumeEvents" and "assignPolyphonicAftertouchToExpression" lines below
  40. MultiBi = host.getMidiInPort(0).createNoteInput("MultiBi - Omni", "??????");
  41. MultiBi1 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 1", "?0????");
  42. MultiBi2 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 2", "?1????");
  43. MultiBi3 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 3", "?2????");
  44. MultiBi4 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 4", "?3????");
  45. MultiBi5 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 5", "?4????");
  46. MultiBi6 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 6", "?5????");
  47. MultiBi7 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 7", "?6????");
  48. MultiBi8 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 8", "?7????");
  49. MultiBi9 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 9", "?8????");
  50. MultiBi10 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 10", "?9????");
  51. MultiBi11 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 11", "?A????");
  52. MultiBi12 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 12", "?B????");
  53. MultiBi13 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 13", "?C????");
  54. MultiBi14 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 14", "?D????");
  55. MultiBi15 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 15", "?E????");
  56. MultiBi16 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 16", "?F????");
  57.  
  58. // Disable the consuming of events by the NoteInputs, so they are also available for mapping
  59. MultiBi.setShouldConsumeEvents(false);
  60. MultiBi1.setShouldConsumeEvents(false);
  61. MultiBi2.setShouldConsumeEvents(false);
  62. MultiBi3.setShouldConsumeEvents(false);
  63. MultiBi4.setShouldConsumeEvents(false);
  64. MultiBi5.setShouldConsumeEvents(false);
  65. MultiBi6.setShouldConsumeEvents(false);
  66. MultiBi7.setShouldConsumeEvents(false);
  67. MultiBi8.setShouldConsumeEvents(false);
  68. MultiBi9.setShouldConsumeEvents(false);
  69. MultiBi10.setShouldConsumeEvents(false);
  70. MultiBi11.setShouldConsumeEvents(false);
  71. MultiBi12.setShouldConsumeEvents(false);
  72. MultiBi13.setShouldConsumeEvents(false);
  73. MultiBi14.setShouldConsumeEvents(false);
  74. MultiBi15.setShouldConsumeEvents(false);
  75. MultiBi16.setShouldConsumeEvents(false);
  76.  
  77. // Enable Poly AT translation into Timbre for the internal BWS instruments
  78. MultiBi.assignPolyphonicAftertouchToExpression(0, NoteExpression.TIMBRE_UP, 5);
  79. MultiBi1.assignPolyphonicAftertouchToExpression(0, NoteExpression.TIMBRE_UP, 5);
  80. MultiBi2.assignPolyphonicAftertouchToExpression(1, NoteExpression.TIMBRE_UP, 5);
  81. MultiBi3.assignPolyphonicAftertouchToExpression(2, NoteExpression.TIMBRE_UP, 5);
  82. MultiBi4.assignPolyphonicAftertouchToExpression(3, NoteExpression.TIMBRE_UP, 5);
  83. MultiBi5.assignPolyphonicAftertouchToExpression(4, NoteExpression.TIMBRE_UP, 5);
  84. MultiBi6.assignPolyphonicAftertouchToExpression(5, NoteExpression.TIMBRE_UP, 5);
  85. MultiBi7.assignPolyphonicAftertouchToExpression(6, NoteExpression.TIMBRE_UP, 5);
  86. MultiBi8.assignPolyphonicAftertouchToExpression(7, NoteExpression.TIMBRE_UP, 5);
  87. MultiBi9.assignPolyphonicAftertouchToExpression(8, NoteExpression.TIMBRE_UP, 5);
  88. MultiBi10.assignPolyphonicAftertouchToExpression(9, NoteExpression.TIMBRE_UP, 5);
  89. MultiBi11.assignPolyphonicAftertouchToExpression(10, NoteExpression.TIMBRE_UP, 5);
  90. MultiBi12.assignPolyphonicAftertouchToExpression(11, NoteExpression.TIMBRE_UP, 5);
  91. MultiBi13.assignPolyphonicAftertouchToExpression(12, NoteExpression.TIMBRE_UP, 5);
  92. MultiBi14.assignPolyphonicAftertouchToExpression(13, NoteExpression.TIMBRE_UP, 5);
  93. MultiBi15.assignPolyphonicAftertouchToExpression(14, NoteExpression.TIMBRE_UP, 5);
  94. MultiBi16.assignPolyphonicAftertouchToExpression(15, NoteExpression.TIMBRE_UP, 5);
  95.  
  96. // Enable Midi Beat Clock. Comment out if you don't want that
  97. host.getMidiOutPort(0).setShouldSendMidiBeatClock;
  98.  
  99. // Setting Callbacks for Midi and Sysex
  100. host.getMidiInPort(0).setMidiCallback(onMidi);
  101. host.getMidiInPort(0).setSysexCallback(onSysex);
  102.  
  103. // Make CCs 1-119 freely mappable for all 16 Channels
  104. userControls = host.createUserControls((HIGHEST_CC - LOWEST_CC + 1)*16);
  105.  
  106. for(var i=LOWEST_CC; i<=HIGHEST_CC; i++)
  107. {
  108. for (var j=1; j<=16; j++) {
  109. // Create the index variable c
  110. var c = i - LOWEST_CC + (j-1) * (HIGHEST_CC-LOWEST_CC+1);
  111. // Set a label/name for each userControl
  112. userControls.getControl(c).setLabel("CC " + i + " - Channel " + j);
  113. // Add a ValueObserver for each userControl
  114. userControls.getControl(c).addValueObserver(127, getValueObserverFunc(c, ccValue));
  115. }
  116. }
  117. }
  118.  
  119. // Updates the controller in an orderly manner when needed
  120. // so that LEDs, Motors etc. react to changes in the Software
  121. // without drowning the Controller with data
  122. function flush()
  123. {
  124. for(var i=LOWEST_CC; i<=HIGHEST_CC; i++)
  125. {
  126. for (var j=1; j<=16; j++) {
  127. var c = i - LOWEST_CC + (j-1) * (HIGHEST_CC-LOWEST_CC+1);
  128. // Check if something has changed
  129. if (ccValue[c] != ccValueOld[c]) {
  130. // If yes, send the updated value
  131. sendChannelController(j-1, i, ccValue[c]);
  132. // And update the value for the next check
  133. ccValueOld[c] = ccValue[c];
  134. }
  135. }
  136. }
  137. }
  138.  
  139.  
  140. function exit()
  141. {
  142. // nothing to do here ;-)
  143. }
  144.  
  145.  
  146. // Update the UserControls when Midi Data is received
  147. function onMidi(status, data1, data2)
  148. {
  149. var pressed = (value>=64);
  150. printMidi(status, data1, data2);
  151.  
  152. if (isChannelController(status))
  153. {var control = find_control(ctrl,chan);
  154. switch (control) {
  155.  
  156. case _stop:
  157. if (pressed) transport.stop();
  158. break;
  159.  
  160. case _play:
  161. if (pressed) transport.play();
  162. break;
  163.  
  164. case _record:
  165. if (pressed) transport.record();
  166. break;
  167. }
  168. if (data1 >= LOWEST_CC && data1 <= HIGHEST_CC)
  169. {
  170. var index = data1 - LOWEST_CC + ((HIGHEST_CC-LOWEST_CC+1) * MIDIChannel(status));
  171. userControls.getControl(index).set(data2, 128);
  172. }
  173.  
  174. }
  175.  
  176. }
  177. function onSysex(data)
  178. {
  179. //printSysex(data);
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement