Advertisement
Guest User

Bitwig Arturia Minilab Mk2 by Netsu (TEST by nojoe)

a guest
Sep 19th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.97 KB | None | 0 0
  1. loadAPI(6);
  2.  
  3. host.defineController("Arturia", "MiniLab MKII", "1.0", "9c891939-9cb5-488d-a447-266f543516f3", "Netsu (TEST by nojoe)");
  4. host.defineMidiPorts(1, 1);
  5. host.addDeviceNameBasedDiscoveryPair(["Arturia MINILAB MKII"], ["Arturia MINILAB MKII"]);
  6.  
  7. STATUS_PAD_ON = 153;
  8. STATUS_PAD_OFF = 137;
  9. STATUS_KNOB = 176;
  10. FIRST_PAD_MIDI = 36;
  11.  
  12. var MACRO_NAMES = [
  13. "Macro 1",
  14. "Macro 2",
  15. "Macro 3",
  16. "Macro 4",
  17. "Macro 5",
  18. "Macro 6",
  19. "Macro 7",
  20. "Macro 8"
  21. ];
  22.  
  23. var MACRO_MAP =
  24. {
  25. "Macro 1":0,
  26. "Macro 2":1,
  27. "Macro 3":2,
  28. "Macro 4":3,
  29. "Macro 5":4,
  30. "Macro 6":5,
  31. "Macro 7":6,
  32. "Macro 8":7
  33. };
  34.  
  35. var COLOR =
  36. {
  37. BLACK :"00",
  38. RED :"01",
  39. BLUE :"10",
  40. GREEN :"04",
  41. CYAN :"14",
  42. PURPLE :"11",
  43. YELLOW :"05",
  44. WHITE :"7F"
  45. };
  46.  
  47. var PAD_COLORS =
  48. [
  49. COLOR.YELLOW,
  50. COLOR.YELLOW,
  51. COLOR.PURPLE,
  52. COLOR.PURPLE,
  53. COLOR.BLACK,
  54. COLOR.GREEN,
  55. COLOR.BLUE,
  56. COLOR.RED,
  57. COLOR.YELLOW,
  58. COLOR.YELLOW,
  59. COLOR.PURPLE,
  60. COLOR.PURPLE,
  61. COLOR.BLACK,
  62. COLOR.GREEN,
  63. COLOR.BLUE,
  64. COLOR.RED,
  65. ];
  66.  
  67. var BOTTOM_FUNC =
  68. {
  69. CURRENT:0,
  70. MASTER:1
  71. };
  72.  
  73. var PAD_FUNCTION =
  74. {
  75. NOTES:0,
  76. CONTROL:1
  77. };
  78.  
  79. var KnobsLeft = [112, 74, 71, 76, 114, 18, 19, 16];
  80. var KnobsRight = [77, 93, 73, 17, 91, 79];
  81.  
  82. var Knob1click = 113;
  83. var Knob9click = 115;
  84.  
  85. var Knob8 = 75;
  86. var Knob16 = 72;
  87.  
  88. var modWheel = 1;
  89. var modWheelMacro = 7;
  90. var macroKnobSpeed = 1.0;
  91. var rainbowColors = true;
  92. var padFunction = PAD_FUNCTION.NOTES;
  93.  
  94. var identityMap = makeArray(128, -1);
  95. var emptyMap = makeArray(128, -1);
  96.  
  97. function makeArray(x, init)
  98. {
  99. var table = new Array(x);
  100. for (var i = 0; i < x; i++)
  101. {
  102. table[i] = init;
  103. }
  104. return table;
  105. }
  106.  
  107. function init()
  108. {
  109. for (var i = 0; i < 128; i++)
  110. identityMap[i] = i;
  111.  
  112. // Create the Note Inputs and their Settings
  113. MiniLabKeys = host.getMidiInPort(0).createNoteInput("MiniLab Keys", "80????", "90????", "B001??", "B002??", "B007??", "B00B??", "B040??", "C0????", "D0????", "E0????");
  114. MiniLabKeys.setShouldConsumeEvents(false);
  115. MiniLabPads = host.getMidiInPort(0).createNoteInput("MiniLab Pads", "?9????");
  116. MiniLabPads.setShouldConsumeEvents(false);
  117. MiniLabPads.assignPolyphonicAftertouchToExpression(0, NoteExpression.TIMBRE_UP, 2);
  118.  
  119. host.getMidiInPort(0).setMidiCallback(onMidi);
  120.  
  121. transport = host.createTransport();
  122. cTrack = host.createCursorTrack(3, 0);
  123. uControl = host.createUserControls(8);
  124. prefs = host.getPreferences();
  125.  
  126. primaryDevice = cTrack.getPrimaryDevice();
  127.  
  128. deviceCursor = cTrack.createCursorDevice();
  129. controlPageCursor = deviceCursor.createCursorRemoteControlsPage(8);
  130.  
  131. for (var i = 0; i < 8; i++)
  132. {
  133. uControl.getControl(i).setLabel("CC " + KnobsRight[i])
  134. }
  135.  
  136. var modWheelSetting = prefs.getEnumSetting("Modwheel macro", "Modwheel", MACRO_NAMES, "Macro 1");
  137. modWheelSetting.addValueObserver(function (value)
  138. {
  139. modWheelMacro = MACRO_MAP[value];
  140. });
  141.  
  142. var macroSpeedSetting = prefs.getNumberSetting("Macro knob speed", "Knobs", -10, 10, 0.1, "", 2.0);
  143. macroSpeedSetting.addRawValueObserver(function(value)
  144. {
  145. macroKnobSpeed = value;
  146. });
  147.  
  148. var rainbowSetting = prefs.getEnumSetting("Rainbow colors", "Pads", ["ON", "OFF"], "ON");
  149. rainbowSetting.addValueObserver(function (value)
  150. {
  151. rainbowColors = (value == "ON");
  152. if (rainbowColors == true)
  153. {
  154. makeRainbow();
  155. }
  156. });
  157.  
  158. var padSetting = prefs.getEnumSetting("Pad function", "Pads", ["Notes", "Control"], "Control");
  159. padSetting.addValueObserver(function (value)
  160. {
  161. if (value == "Notes")
  162. {
  163. padFunction = PAD_FUNCTION.NOTES;
  164. MiniLabPads.setKeyTranslationTable(identityMap);
  165. }
  166. else
  167. {
  168. padFunction = PAD_FUNCTION.CONTROL;
  169. MiniLabPads.setKeyTranslationTable(emptyMap);
  170. }
  171. });
  172.  
  173. setIndications();
  174. }
  175.  
  176. function makeRainbow()
  177. {
  178. for (var i = 0; i < 16; i++)
  179. {
  180. setPadColor(i, PAD_COLORS[i]);
  181. }
  182. }
  183.  
  184. function MidiData(status, data1, data2)
  185. {
  186. this.status = status;
  187. this.data1 = data1;
  188. this.data2 = data2;
  189. }
  190.  
  191. function onPad(midi)
  192. {
  193. if (midi.status == STATUS_PAD_ON)
  194. {
  195. var padNum = midi.data1 - FIRST_PAD_MIDI;
  196.  
  197. if (padFunction == PAD_FUNCTION.CONTROL)
  198. {
  199. if (padNum == 0)
  200. {
  201. deviceCursor.selectPrevious();
  202. }
  203. else if (padNum == 1)
  204. {
  205. deviceCursor.selectNext();
  206. }
  207. else if (padNum == 2)
  208. {
  209. controlPageCursor.selectPreviousPage(true);
  210. }
  211. else if (padNum == 3)
  212. {
  213. controlPageCursor.selectNextPage(true);
  214. }
  215. else if (padNum == 5)
  216. {
  217. transport.togglePlay();
  218. }
  219. else if (padNum == 6)
  220. {
  221. transport.stop();
  222. }
  223. else if (padNum == 7)
  224. {
  225. transport.record();
  226. }
  227. }
  228.  
  229. if (rainbowColors == true)
  230. {
  231. setPadColor(padNum, COLOR.WHITE);
  232. }
  233. }
  234. else if (midi.status == STATUS_PAD_OFF)
  235. {
  236. var padNum = midi.data1 - FIRST_PAD_MIDI;
  237.  
  238. if (rainbowColors == true)
  239. {
  240. setPadColor(padNum, PAD_COLORS[padNum]);
  241. }
  242. }
  243. }
  244.  
  245. function onMidi(status, data1, data2)
  246. {
  247. // Instantiate the MidiData Object for convenience:
  248. var midi = new MidiData(status, data1, data2);
  249.  
  250. //println(midi.status + ":" + midi.data1 + ":" + midi.data2);
  251. if (midi.status == STATUS_PAD_ON || midi.status == STATUS_PAD_OFF)
  252. {
  253. onPad(midi);
  254. }
  255.  
  256. if (midi.status == STATUS_KNOB)
  257. {
  258. var inc = (midi.data2 - 64) * macroKnobSpeed;
  259.  
  260. for (var i = 0; i < 8; i++)
  261. {
  262. if (midi.data1 === KnobsLeft[i])
  263. {
  264. controlPageCursor.getParameter(i).inc(inc, 128);
  265. }
  266. else if (midi.data1 === KnobsRight[i])
  267. {
  268. uControl.getControl(i).inc(inc, 128);
  269. }
  270. }
  271.  
  272. if (midi.data1 == Knob1click)
  273. {
  274. resetMacros();
  275. }
  276. else if (midi.data1 == Knob8)
  277. {
  278. cTrack.pan();
  279. }
  280. else if (midi.data1 == Knob16)
  281. {
  282. cTrack.volume();
  283. }
  284. else if (midi.data1 == modWheel)
  285. {
  286. modWheelFunc(midi);
  287. }
  288. }
  289. }
  290.  
  291. function resetMacros()
  292. {
  293. for (var i = 0; i < 8; i++)
  294. {
  295. controlPageCursor.getParameter(i).reset();
  296. }
  297. }
  298.  
  299. function modWheelFunc(midi)
  300. {
  301. controlPageCursor.getParameter(modWheelMacro).set(midi.data2, 128);
  302. }
  303.  
  304. function setPadColor(pad, color)
  305. {
  306. var padHex = (112 + pad).toString(16);
  307. sendSysex("F0 00 20 6B 7F 42 02 00 10 " + padHex + " " + color + " F7");
  308. }
  309.  
  310. function setIndications()
  311. {
  312. for (var i = 0; i < 8; i++)
  313. {
  314. controlPageCursor.getParameter(i).setIndication(true);
  315. uControl.getControl(i).setIndication(true);
  316. }
  317. }
  318.  
  319. function getSign(x)
  320. {
  321. return typeof x === 'number' ? x ? x < 0 ? -1 : 1 : x === x ? 0 : NaN : NaN;
  322. }
  323.  
  324. function exit()
  325. {
  326. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement