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 8.08 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. var CONTROL =
  16. {
  17. REW : 116, // <<
  18. FWD : 117, // >>
  19. STOP : 118, // [ ]
  20. PLAY : 119, // [>]
  21. REC : 114, // [R]
  22. SLIDER_S1_8 : 7, // SLIDERS
  23. KNOB_E1_8 : 10, // ROTARY
  24. FUNC_F1_8 : 16, // SOLO
  25. FUNC_F9_16 : 24 // MUTE
  26. };
  27.  
  28. var isPlay = false;
  29. var callinc = 0;
  30.  
  31. // A function to create an indexed function for the Observers
  32. function getValueObserverFunc(index, varToStore)
  33. {
  34. return function(value)
  35. {
  36. varToStore[index] = value;
  37. }
  38. }
  39.  
  40. function init()
  41. {
  42.  
  43. transport = host.createTransport();
  44.  
  45. transport.addIsPlayingObserver(function(on)
  46. {
  47. isPlay = on;
  48. });
  49.  
  50. // Add an observer which prints the transport PLAY / STOP state to the controller script console
  51. transport.addIsPlayingObserver(function(isPlaying)
  52. {
  53. println(isPlaying ? "PLAY" : "STOP");
  54. });
  55. cursorTrack = host.createCursorTrack(2, 0);
  56.  
  57. host.getMidiInPort(0).setMidiCallback(onMidi);
  58. transport = host.createTransport();
  59. transport.addIsPlayingObserver(function(isPlaying)
  60.  
  61. // Create 16 NoteInputs + Omni.
  62. // Verbose to allow commenting out unneeded channels
  63. // To do so, put "//" in front of the lines containing channels you don't want to use
  64. // Be sure to do it for the "createNoteInput" lines as well as the corresponding
  65. // "setShouldConsumeEvents" and "assignPolyphonicAftertouchToExpression" lines below
  66. MultiBi = host.getMidiInPort(0).createNoteInput("MultiBi - Omni", "??????");
  67. MultiBi1 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 1", "?0????");
  68. MultiBi2 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 2", "?1????");
  69. MultiBi3 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 3", "?2????");
  70. MultiBi4 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 4", "?3????");
  71. MultiBi5 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 5", "?4????");
  72. MultiBi6 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 6", "?5????");
  73. MultiBi7 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 7", "?6????");
  74. MultiBi8 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 8", "?7????");
  75. MultiBi9 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 9", "?8????");
  76. MultiBi10 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 10", "?9????");
  77. MultiBi11 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 11", "?A????");
  78. MultiBi12 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 12", "?B????");
  79. MultiBi13 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 13", "?C????");
  80. MultiBi14 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 14", "?D????");
  81. MultiBi15 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 15", "?E????");
  82. MultiBi16 = host.getMidiInPort(0).createNoteInput("MultiBi - Ch 16", "?F????");
  83.  
  84. // Disable the consuming of events by the NoteInputs, so they are also available for mapping
  85. MultiBi.setShouldConsumeEvents(false);
  86. MultiBi1.setShouldConsumeEvents(false);
  87. MultiBi2.setShouldConsumeEvents(false);
  88. MultiBi3.setShouldConsumeEvents(false);
  89. MultiBi4.setShouldConsumeEvents(false);
  90. MultiBi5.setShouldConsumeEvents(false);
  91. MultiBi6.setShouldConsumeEvents(false);
  92. MultiBi7.setShouldConsumeEvents(false);
  93. MultiBi8.setShouldConsumeEvents(false);
  94. MultiBi9.setShouldConsumeEvents(false);
  95. MultiBi10.setShouldConsumeEvents(false);
  96. MultiBi11.setShouldConsumeEvents(false);
  97. MultiBi12.setShouldConsumeEvents(false);
  98. MultiBi13.setShouldConsumeEvents(false);
  99. MultiBi14.setShouldConsumeEvents(false);
  100. MultiBi15.setShouldConsumeEvents(false);
  101. MultiBi16.setShouldConsumeEvents(false);
  102.  
  103. // Enable Poly AT translation into Timbre for the internal BWS instruments
  104. MultiBi.assignPolyphonicAftertouchToExpression(0, NoteExpression.TIMBRE_UP, 5);
  105. MultiBi1.assignPolyphonicAftertouchToExpression(0, NoteExpression.TIMBRE_UP, 5);
  106. MultiBi2.assignPolyphonicAftertouchToExpression(1, NoteExpression.TIMBRE_UP, 5);
  107. MultiBi3.assignPolyphonicAftertouchToExpression(2, NoteExpression.TIMBRE_UP, 5);
  108. MultiBi4.assignPolyphonicAftertouchToExpression(3, NoteExpression.TIMBRE_UP, 5);
  109. MultiBi5.assignPolyphonicAftertouchToExpression(4, NoteExpression.TIMBRE_UP, 5);
  110. MultiBi6.assignPolyphonicAftertouchToExpression(5, NoteExpression.TIMBRE_UP, 5);
  111. MultiBi7.assignPolyphonicAftertouchToExpression(6, NoteExpression.TIMBRE_UP, 5);
  112. MultiBi8.assignPolyphonicAftertouchToExpression(7, NoteExpression.TIMBRE_UP, 5);
  113. MultiBi9.assignPolyphonicAftertouchToExpression(8, NoteExpression.TIMBRE_UP, 5);
  114. MultiBi10.assignPolyphonicAftertouchToExpression(9, NoteExpression.TIMBRE_UP, 5);
  115. MultiBi11.assignPolyphonicAftertouchToExpression(10, NoteExpression.TIMBRE_UP, 5);
  116. MultiBi12.assignPolyphonicAftertouchToExpression(11, NoteExpression.TIMBRE_UP, 5);
  117. MultiBi13.assignPolyphonicAftertouchToExpression(12, NoteExpression.TIMBRE_UP, 5);
  118. MultiBi14.assignPolyphonicAftertouchToExpression(13, NoteExpression.TIMBRE_UP, 5);
  119. MultiBi15.assignPolyphonicAftertouchToExpression(14, NoteExpression.TIMBRE_UP, 5);
  120. MultiBi16.assignPolyphonicAftertouchToExpression(15, NoteExpression.TIMBRE_UP, 5);
  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. // Updates the controller in an orderly manner when needed
  146. // so that LEDs, Motors etc. react to changes in the Software
  147. // without drowning the Controller with data
  148. function flush()
  149. {
  150. for(var i=LOWEST_CC; i<=HIGHEST_CC; i++)
  151. {
  152. for (var j=1; j<=16; j++) {
  153. var c = i - LOWEST_CC + (j-1) * (HIGHEST_CC-LOWEST_CC+1);
  154. // Check if something has changed
  155. if (ccValue[c] != ccValueOld[c]) {
  156. // If yes, send the updated value
  157. sendChannelController(j-1, i, ccValue[c]);
  158. // And update the value for the next check
  159. ccValueOld[c] = ccValue[c];
  160. }
  161. }
  162. }
  163. }
  164.  
  165. // Update the UserControls when Midi Data is received
  166. function onMidi(status, data1, data2)
  167. {
  168. //printMidi(status, data1, data2);
  169.  
  170. if (isChannelController(status))
  171. {
  172. if (data1 >= LOWEST_CC && data1 <= HIGHEST_CC)
  173. {
  174. var index = data1 - LOWEST_CC + ((HIGHEST_CC-LOWEST_CC+1) * MIDIChannel(status));
  175. userControls.getControl(index).set(data2, 128);
  176. }
  177. }
  178. // handle normal short MIDI messages here
  179. // when we receive a CC #40 with a value bigger than 0 we tell the transport to play
  180. if (isChannelController(status) && data1 == 40 && data2 > 0)
  181. {
  182. transport.play();
  183. }
  184. }
  185.  
  186.  
  187.  
  188.  
  189. function onSysex(data)
  190. {
  191. //printSysex(data);
  192. }
  193.  
  194. function exit()
  195. {
  196. // nothing to do here ;-)
  197. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement