Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.56 KB | None | 0 0
  1. Hercules-DJ-Control-MK2-scripts.js
  2. // TODO
  3. // - LED blink functions
  4. // - autosync LED with autosync buttton & pitch
  5. // - test play LED function (buggy)
  6.  
  7. function HerculesMK2 () {}
  8.  
  9. // defaults
  10. HerculesMK2.debug = false;
  11. HerculesMK2.scratchMode = false;
  12. HerculesMK2.decayLast = new Date().getTime();
  13. HerculesMK2.decayInterval = 300;
  14. HerculesMK2.decayRate = 1.5;
  15. HerculesMK2.leds = {};
  16.  
  17. HerculesMK2.joystickValue = false;
  18.  
  19. HerculesMK2.buttons123Modes = ["kill", "fx", "cue", "loop"];
  20. HerculesMK2.buttons123used = {"[Channel1]": false, "[Channel2]": false};
  21.  
  22. // LED controller values
  23. HerculesMK2.ledOn = 0x7F;
  24. HerculesMK2.ledOff = 0x00;
  25.  
  26. HerculesMK2.controls = {
  27. "inputs": {
  28. 0x09: { "channel": 1, "name": "cue", "type": "button" },
  29. 0x03: { "channel": 2, "name": "cue", "type": "button" },
  30. 0x08: { "channel": 1, "name": "play", "type": "button" },
  31. 0x02: { "channel": 2, "name": "play", "type": "button" },
  32. 0x07: { "channel": 1, "name": "fx select", "type": "button","mode": 0 },
  33. 0x01: { "channel": 2, "name": "fx select", "type": "button","mode": 0 },
  34. 0x0F: { "channel": 1, "name": "fx 1", "type": "button", "used": false },
  35. 0x10: { "channel": 2, "name": "fx 1", "type": "button", "used": false },
  36. 0x0E: { "channel": 1, "name": "fx 2", "type": "button", "used": false },
  37. 0x11: { "channel": 2, "name": "fx 2", "type": "button", "used": false },
  38. 0x0D: { "channel": 1, "name": "fx 3", "type": "button", "used": false },
  39. 0x12: { "channel": 2, "name": "fx 3", "type": "button", "used": false },
  40. 0x1B: { "channel": 1, "name": "mouse", "type": "button" },
  41. 0x1C: { "channel": 2, "name": "mouse", "type": "button" },
  42. 0x34: { "channel": 1, "name": "pitch", "type": "pot" },
  43. 0x35: { "channel": 2, "name": "pitch", "type": "pot" },
  44. 0x36: { "channel": 1, "name": "wheel", "type": "pot" },
  45. 0x37: { "channel": 2, "name": "wheel", "type": "pot" },
  46. 0x15: { "channel": 1, "name": "pfl", "type": "button" },
  47. 0x19: { "channel": 2, "name": "pfl", "type": "button" },
  48. 0x16: { "channel": 1, "name": "bpm", "type": "button" },
  49. 0x1A: { "channel": 2, "name": "bpm", "type": "button" },
  50. 0x0A: { "channel": 1, "name": "sync", "type": "button" },
  51. 0x04: { "channel": 2, "name": "sync", "type": "button" }
  52. },
  53. "outputs": {
  54. 0x0F: { "channel": 1, "name": "fx mode", "type": "led" },
  55. 0x10: { "channel": 2, "name": "fx mode", "type": "led" },
  56. 0x0E: { "channel": 1, "name": "cue mode", "type": "led" },
  57. 0x11: { "channel": 2, "name": "cue mode", "type": "led" },
  58. 0x0D: { "channel": 1, "name": "loop mode", "type": "led" },
  59. 0x12: { "channel": 2, "name": "loop mode", "type": "led" },
  60. 0x16: { "channel": 1, "name": "master tempo", "type": "led" },
  61. 0x1A: { "channel": 2, "name": "master tempo", "type": "led" },
  62. 0x0A: { "channel": 1, "name": "sync", "type": "led" },
  63. 0x04: { "channel": 2, "name": "sync", "type": "led" },
  64. 0x09: { "channel": 1, "name": "cue", "type": "led" },
  65. 0x03: { "channel": 2, "name": "cue", "type": "led" },
  66. 0x05: { "channel": 1, "name": "play blink", "type": "led" },
  67. 0x00: { "channel": 2, "name": "play blink", "type": "led" },
  68. 0x08: { "channel": 1, "name": "play", "type": "led" },
  69. 0x02: { "channel": 2, "name": "play", "type": "led" },
  70. 0x7E: { "channel": 1, "name": "pfl", "type": "led" },
  71. 0x7D: { "channel": 2, "name": "pfl", "type": "led" }
  72. }
  73. };
  74.  
  75. // called when the device is opened & set up
  76. HerculesMK2.init = function (id) {
  77. HerculesMK2.initializeControls();
  78.  
  79. engine.connectControl("[Channel1]","playposition","HerculesMK2.wheelDecay");
  80. engine.connectControl("[Channel2]","playposition","HerculesMK2.wheelDecay");
  81.  
  82. print ("HerculesMK2 id: \""+id+"\" initialized.");
  83. };
  84.  
  85. HerculesMK2.initializeControls = function () {
  86. for (control in HerculesMK2.controls.outputs)
  87. {
  88. if (HerculesMK2.controls.outputs[control].type == 'led')
  89. {
  90. key = "[Channel" + HerculesMK2.controls.outputs[control].channel + "] " + HerculesMK2.controls.outputs[control].name;
  91. HerculesMK2.leds[key] = control;
  92. }
  93. }
  94.  
  95. HerculesMK2.setLeds("on");
  96. HerculesMK2.setLeds("off");
  97.  
  98. // Set controls in Mixxx to reflect settings on the device
  99. midi.sendShortMsg(0xB0,0x7F,0x7F);
  100. };
  101.  
  102. HerculesMK2.shutdown = function (id) {
  103. HerculesMK2.setLeds("off");
  104. };
  105.  
  106. HerculesMK2.getGroup = function (control){
  107. // Get the "group" that used to be provided in group, this is not reusable
  108. // across devices and also breaks remapping of these functions to other
  109. // buttons.
  110.  
  111. return "[Channel" + HerculesMK2.controls.inputs[control].channel + "]";
  112. };
  113.  
  114. HerculesMK2.getControl = function (io, channel, name) {
  115. // Accept channel in form 'N' or '[ChannelN]'
  116. channel = channel.replace(/\[Channel(\d)\]/, "$1");
  117.  
  118. for (control in HerculesMK2.controls.inputs)
  119. {
  120. if (HerculesMK2.controls.inputs[control].channel == channel && HerculesMK2.controls.inputs[control].name == name)
  121. return HerculesMK2.controls.inputs[control];
  122. }
  123.  
  124. print ("HerculesMK2.getControl: Control not found: io=" + io + ": channel=" + channel + ": name=" + name);
  125. };
  126.  
  127. HerculesMK2.setLeds = function (onOff) {
  128. for (LED in HerculesMK2.leds)
  129. {
  130. HerculesMK2.setLed(LED,onOff);
  131. // Seems that if midi messages are sent too quickly, leds don't behave as expected. A pause rectifies this.
  132. HerculesMK2.pauseScript(10);
  133. }
  134. };
  135.  
  136. HerculesMK2.setLed = function (led, onOff) {
  137. if (onOff=="on" || onOff==1 )
  138. value = HerculesMK2.ledOn;
  139. else if (onOff=="off" || onOff==0 )
  140. value = HerculesMK2.ledOff;
  141. else return;
  142.  
  143. //if (HerculesMK2.debug) print ("HerculesMK2.setLed: Setting " + led + " led " + onOff);
  144. //if (HerculesMK2.debug) print ("HerculesMK2.setLed: midi.sendShortMsg(0xB0," + HerculesMK2.leds[led].toString(16) + "," + value + ")");
  145.  
  146. midi.sendShortMsg(0xB0,HerculesMK2.leds[led],value);
  147. //HerculesMK2.controls.outputs[HerculesMK2.leds[led]].isOn = onOff=="on" ? true : false;
  148. HerculesMK2.controls.outputs[HerculesMK2.leds[led]].isOn = value;
  149. };
  150.  
  151. ////
  152. //HerculesMK2.blinkStart = function (LED) {
  153. // HerculesMK2.timers[0] = engine.beginTimer(1000, "HerculesMK2.blinkLed("+LED+")",false);
  154. // return;
  155. //}
  156. //
  157. //HerculesMK2.blinkStop = function (LED) {
  158. // engine.stopTimer(HerculesMK2.blinkEnabled);
  159. // HerculesMK2.setLed(LED, "on");
  160. // return;
  161. //}
  162. //
  163. //HerculesMK2.blinkLed = function (LED) {
  164. // print (HerculesMK2.controls.outputs[HerculesMK2.leds[LED]].isOn);
  165. // //if (HerculesMK2.controls.outputs[HerculesMK2.leds[LED]].isOn == "on") HerculesMK2.setLed(LED, "off");
  166. // //else HerculesMK2.setLed(LED, "on");
  167. // return;
  168. //}
  169.  
  170.  
  171. // pause function for delay in script
  172. HerculesMK2.pauseScript = function(ms) {
  173. startDate = new Date();
  174. currentDate = null;
  175. while(currentDate-startDate < ms) currentDate = new Date();
  176. };
  177.  
  178. // increment function to set a value
  179. HerculesMK2.increment = function(group, control, value, min,max,step) {
  180. //if (HerculesMK2.debug) print ("[Debug] HerculesMK2.increment (" + group +", "+ control +", "+value +", "+status +")" );
  181.  
  182. currentValue = engine.getValue(group, control);
  183. increment = (max-min)/step;
  184. increment = (value <= 0x3F) ? increment : increment * -1;
  185.  
  186. newValue = currentValue + increment;
  187. newValue = newValue > max ? max : newValue < min ? min : newValue;
  188.  
  189. if (newValue != currentValue)
  190. engine.setValue(group, control, newValue);
  191.  
  192. print (group + " " + control + " set to " + ((newValue/max)*100) + "%");
  193.  
  194. //if (HerculesMK2.debug) print ("Current value of "+group+" " + control + " is :" + currentValue + ", min: " + min + ", max:" + max + ", step:" + step + ", increment: " + increment );
  195. //if (HerculesMK2.debug) print ("HerculesMK2.pitch: value= " + newValue);
  196.  
  197. return;
  198. };
  199.  
  200. //cue function
  201. HerculesMK2.cue = function (group, control, value, status) {
  202. //if (HerculesMK2.debug) print ("[Debug] HerculesMK2.cue (" + group +", "+ control +", "+value +", "+status +")" );
  203.  
  204. group = HerculesMK2.getGroup(control);
  205.  
  206. if ((engine.getValue(group, "duration") == 0) && (value))
  207. {
  208. print("No song on " + group);
  209. return;
  210. }
  211.  
  212. if (value) // button pressed
  213. {
  214. engine.setValue(group,"cue_default",1);
  215. HerculesMK2.setLed(group + " cue", 1);
  216. }
  217. else
  218. {
  219. engine.setValue(group,"cue_default",0);
  220. }
  221. };
  222.  
  223. // play function
  224. HerculesMK2.play = function (group, control, value, status) {
  225. //if (HerculesMK2.debug) print ("[Debug] HerculesMK2.play (" + group +", "+ control +", "+value +", "+status +")" );
  226.  
  227. if (value) // only when button is pressed, no action on release
  228. {
  229.  
  230. group = HerculesMK2.getGroup(control);
  231. if (engine.getValue(group, "duration") == 0)
  232. {
  233. print("No song on " + group);
  234. return;
  235. }
  236. playvalue = !engine.getValue(group,"play");
  237. engine.setValue(group,"play", playvalue);
  238.  
  239. HerculesMK2.controls.inputs[control].isPlaying = playvalue;
  240.  
  241. // cue off, when simply playing
  242. HerculesMK2.setLed(group + " cue", "off");
  243.  
  244. // play blink LED active, when song is paused
  245. //HerculesMK2.setLed(group + " play blink", !playvalue);
  246.  
  247. // play LED active, when song is playing
  248. HerculesMK2.setLed(group + " play", playvalue);
  249. }
  250. };
  251.  
  252. // pfl toggle function
  253. HerculesMK2.pfl = function (group, control, value, status) {
  254. //if (HerculesMK2.debug) print ("[Debug] HerculesMK2.pfl (" + group +", "+ control +", "+value +", "+status +")" );
  255.  
  256. if (value) // only when button is pressed, no action on release
  257. {
  258. switch (control) {
  259. case 0x23: // Headphones Split
  260. case 0x24: // Headphones Mix
  261. engine.setValue("[Channel1]", "pfl", 1);
  262. engine.setValue("[Channel2]", "pfl", 1);
  263. print("HerculesMk2.pfl: Mix/Split");
  264. break;
  265. case 0x21: // Headphones Deck A
  266. engine.setValue("[Channel1]", "pfl", 1);
  267. engine.setValue("[Channel2]", "pfl", 0);
  268. print("HerculesMk2.pfl: Deck A");
  269. break;
  270. case 0x22: // Headphones Deck B
  271. engine.setValue("[Channel1]", "pfl", 0);
  272. engine.setValue("[Channel2]", "pfl", 1);
  273. print("HerculesMk2.pfl: Deck B");
  274. break;
  275. }
  276. }
  277. };
  278.  
  279.  
  280. // reset bpm (master tempo)
  281. HerculesMK2.resetPitch = function (group, control, value, status) {
  282. //if (HerculesMK2.debug) print ("[Debug] HerculesMK2.resetpitch (" + group +", "+ control +", "+value +", "+status +")" );
  283.  
  284. if (value) // only when button is pressed, no action on release
  285. {
  286. group = HerculesMK2.getGroup(control);
  287. engine.setValue(group,"rate",0);
  288. HerculesMK2.setLed(group + " master tempo", "on");
  289. print ("Resetting pitch on" + group);
  290. }
  291. };
  292.  
  293. HerculesMK2.loadSelectedTrack = function (group, control, value, status) {
  294. //if (HerculesMK2.debug) print ("[Debug] HerculesMK2.loadSelectedTrack (" + group +", "+ control +", "+value +", "+status +")" );
  295.  
  296. if (value) // only when button is pressed, no action on release
  297. {
  298. group = HerculesMK2.getGroup(control);
  299. engine.setValue(group, "LoadSelectedTrack", 1);
  300. HerculesMK2.setLed(group + " cue", 1);
  301. //HerculesMK2.setLed(group + " play blink", 1);
  302. HerculesMK2.resetPitch (group, control, value, status);
  303. print ("Track loaded on group " + group);
  304. }
  305. };
  306.  
  307. // button group changing / button functions
  308. HerculesMK2.buttons123 = function (group, control, value, status) {
  309. //if (HerculesMK2.debug) print ("[Debug] HerculesMK2.buttons123 (" + group +", "+ control +", "+value +", "+status +")" );
  310.  
  311. group = HerculesMK2.getGroup(control);
  312.  
  313. if (value) // Button pressed.
  314. HerculesMK2.controls.inputs[control].isDown = true;
  315. else //Button released.
  316. HerculesMK2.controls.inputs[control].isDown = false;
  317.  
  318. mode = HerculesMK2.getControl("inputs", group, "fx select").mode;
  319. mode = HerculesMK2.buttons123Modes[mode];
  320.  
  321. switch (mode)
  322. {
  323. case "kill": // Kill mode
  324. if (value)
  325. { // Button pressed.
  326. switch (HerculesMK2.controls.inputs[control].name)
  327. {
  328. case "fx 1":
  329. filter = "filterLowKill";
  330. break;
  331. case "fx 2":
  332. filter = "filterMidKill";
  333. break;
  334. case "fx 3":
  335. filter = "filterHighKill";
  336. break;
  337. }
  338. filtervalue = !engine.getValue(group, filter);
  339. engine.setValue(group, filter, filtervalue);
  340. print (group + " "+ filter + " set to "+ filtervalue);
  341. }
  342. break; // End kill mode
  343.  
  344. case "fx": // Fx mode
  345. // because buttons also used together with pitch, we need to map these settings to button release without pitch beeing touched
  346. if (!value) // Button released.
  347. {
  348. // if button was used with pitch
  349. if (HerculesMK2.controls.inputs[control].used)
  350. {
  351. HerculesMK2.controls.inputs[control].used = false;
  352. return;
  353. }
  354. else
  355. {
  356. switch (HerculesMK2.controls.inputs[control].name)
  357. {
  358. case "fx 1":
  359. case "fx 2":
  360. case "fx 3":
  361. filter = "flanger";
  362. break;
  363. }
  364. filtervalue = !engine.getValue(group, filter);
  365. engine.setValue(group, filter, filtervalue);
  366. print (group + " "+ filter + " set to "+ filtervalue);
  367. }
  368. }
  369. break; // End fx mode
  370.  
  371. case "cue": // Cue mode
  372. switch (HerculesMK2.controls.inputs[control].name)
  373. {
  374. case "fx 1":
  375. cue = "hotcue_1_set";
  376. break;
  377. case "fx 2":
  378. cue = "hotcue_1_activate";
  379. break;
  380. case "fx 3":
  381. cue = "hotcue_1_clear";
  382. break;
  383. }
  384. if (value) engine.setValue(group, cue, 1); //button pressed
  385. else engine.setValue(group, cue, 0); //button released
  386. print (group + " "+ cue + " set");
  387. break; // End cue mode
  388.  
  389. case "loop": // loop mode
  390. switch (HerculesMK2.controls.inputs[control].name)
  391. {
  392. case "fx 1":
  393. loop = "loop_in";
  394. break;
  395. case "fx 2":
  396. loop = "loop_out";
  397. break;
  398. case "fx 3":
  399. loop = "reloop_exit";
  400. break;
  401. }
  402. if (value) engine.setValue(group, loop, 1); //button pressed
  403. else engine.setValue(group, loop, 0); //button released
  404. print (loop + "set on " + group );
  405. break; //End loop mode
  406.  
  407. default:
  408. print("HerculesMK2.buttons123: " + mode + " mode unsupported");
  409. }
  410. };
  411.  
  412. // button group mode change function
  413. HerculesMK2.buttons123mode = function (group, control, value, status) {
  414. //if (HerculesMK2.debug) print ("[Debug] HerculesMK2.buttons123mode (" + group +", "+ control +", "+value +", "+status +")" );
  415.  
  416. group = HerculesMK2.getGroup(control);
  417. if (value) // button pressed
  418. {
  419. currentMode = HerculesMK2.controls.inputs[control].mode;
  420. nextMode = currentMode < HerculesMK2.buttons123Modes.length-1 ? currentMode+1 : 0;
  421. currentLed = group + " " + HerculesMK2.buttons123Modes[currentMode] + " mode";
  422. nextLed = group + " " + HerculesMK2.buttons123Modes[nextMode] + " mode";
  423. sNextMode = HerculesMK2.buttons123Modes[nextMode];
  424.  
  425. switch (sNextMode)
  426. {
  427. case "kill":
  428. case "fx":
  429. case "loop":
  430. case "cue":
  431. print("HerculesMK2.buttons123mode: Switching to " + sNextMode + " mode");
  432. break;
  433. default:
  434. print("HerculesMK2.buttons123mode: " + sNextMode + " mode unsupported");
  435. break;
  436. }
  437.  
  438. // Only turn on/off leds for non-zero modes as 0 is kill mode which has no corresponding LED. i.e. all LEDs off for kill mode.
  439. if (currentMode) HerculesMK2.setLed(currentLed, "off");
  440. // Seems that if midi messages are sent too quickly, leds don't behave as expected. A pause rectifies this.
  441. HerculesMK2.pauseScript(10);
  442. if (nextMode) HerculesMK2.setLed(nextLed, "on");
  443.  
  444. HerculesMK2.controls.inputs[control].mode = nextMode;
  445. }
  446. };
  447.  
  448. // pitch function, also the special button + pitch combos
  449. HerculesMK2.pitch = function (group, control, value, status) {
  450. //if (HerculesMK2.debug) print ("[Debug] HerculesMK2.pitch (" + group +", "+ control +", "+value +", "+status +")" );
  451.  
  452. // 7F > 40: CCW Slow > Fast - 127 > 64
  453. // 01 > 3F: CW Slow > Fast - 0 > 63
  454.  
  455. group = HerculesMK2.getGroup(control);
  456. pitchControl = HerculesMK2.getControl("inputs", group, "pitch");
  457. done = false;
  458.  
  459. currentMode = HerculesMK2.getControl("inputs", group, "fx select").mode;
  460. currentMode = HerculesMK2.buttons123Modes[currentMode];
  461.  
  462. joystick = HerculesMK2.joystickValue;
  463.  
  464. // FX mode: buttons + Pitch: effect parameters
  465. if (currentMode == "fx")
  466. {
  467. if (HerculesMK2.getControl("inputs", group, "fx 1").isDown)
  468. {
  469. HerculesMK2.increment("[Flanger]", "lfoDelay", value, 50,10000,30);
  470. HerculesMK2.getControl("inputs", group, "fx 1").used = true;
  471. done = true;
  472. }
  473.  
  474. if (HerculesMK2.getControl("inputs", group, "fx 2").isDown)
  475. {
  476. HerculesMK2.increment("[Flanger]", "lfoDepth", value, 0,1,30);
  477. HerculesMK2.getControl("inputs", group, "fx 2").used = true;
  478. done = true;
  479. }
  480.  
  481. if (HerculesMK2.getControl("inputs", group, "fx 3").isDown)
  482. {
  483. HerculesMK2.increment("[Flanger]", "lfoPeriod", value, 50000, 2000000,30);
  484. HerculesMK2.getControl("inputs", group, "fx 3").used = true;
  485. done = true;
  486. }
  487. }
  488.  
  489. // Cue mode: buttons + Pitch: headphone and channel gain parameters
  490. switch (joystick)
  491. {
  492. case "top":
  493. HerculesMK2.increment("[Master]", "headVolume", value,0,5,30);
  494. done = true;
  495. break;
  496. case "bottom":
  497. HerculesMK2.increment("[Master]", "headMix", value, -1,1,30);
  498. done = true;
  499. break;
  500. case "left":
  501. HerculesMK2.increment("[Channel1]", "pregain", value, 0,4,30);
  502. done = true;
  503. break;
  504. case "right":
  505. HerculesMK2.increment("[Channel2]", "pregain", value, 0,4,30);
  506. done = true;
  507. break;
  508. }
  509.  
  510. // if buttons were used, exit, don't adjust pitch
  511. if (done) return;
  512. //no button was pressed, do normal pitch
  513. else
  514. {
  515. increment = 0.00125;
  516. increment = (value <= 0x3F) ? increment : increment * -1;
  517.  
  518. //if (HerculesMK2.debug) print ("HerculesMK2.pitch: value=" + value);
  519.  
  520. newrate = engine.getValue(group, "rate") + increment;
  521. engine.setValue(group, "rate", newrate);
  522. print ("newrate:" + newrate);
  523.  
  524. //a bit of a range is reasonable
  525. if ((newrate < 0.005) && (newrate > -0.005)) HerculesMK2.setLed(group + " master tempo", "on");
  526. else HerculesMK2.setLed(group + " master tempo", "off");
  527. }
  528. };
  529.  
  530.  
  531. HerculesMK2.jog_wheel = function (group, control, value, status) {
  532. //if (HerculesMK2.debug) print ("[Debug] HerculesMK2.jog_wheel (" + group +", "+ control +", "+value +", "+status +")" );
  533. // 7F > 40: CCW Slow > Fast - 127 > 64
  534. // 01 > 3F: CW Slow > Fast - 0 > 63
  535. group = HerculesMK2.getGroup(control);
  536.  
  537. if (HerculesMK2.controls.outputs[HerculesMK2.leds[group + " cue"]].isOn == true)
  538. HerculesMK2.setLed(group + " cue", "off");
  539.  
  540. jogValue = value >=0x40 ? value - 0x80 : value; // -64 to +63, - = CCW, + = CW
  541.  
  542. // do some scratching
  543. if (HerculesMK2.scratchMode)
  544. {
  545. //if (HerculesMK2.debug) print("Do scratching value:" + value + " jogValue: " + jogValue );
  546. engine.setValue(group,"scratch", (engine.getValue(group,"scratch") + (jogValue/64)).toFixed(2));
  547. }
  548. // do pitch adjustment
  549. else
  550. {
  551. newValue = jogValue;
  552. //if (HerculesMK2.debug) print("do pitching adjust " + jogValue + " new Value: " + newValue);
  553. engine.setValue(group,"jog", newValue);
  554. }
  555. };
  556.  
  557. // needed function to scratch only, not to redefine "vinyl feel" :)
  558. HerculesMK2.wheelDecay = function (value) {
  559. currentDate = new Date().getTime();
  560.  
  561. if (currentDate > HerculesMK2.decayLast + HerculesMK2.decayInterval)
  562. {
  563. HerculesMK2.decayLast = currentDate;
  564.  
  565. //if (HerculesMK2.debug) print(" new playposition: " + value + " decayLast: "+ HerculesMK2.decayLast);
  566.  
  567. // do some scratching
  568. if (HerculesMK2.scratchMode)
  569. {
  570. //if (HerculesMK2.debug) print("Scratch deck1: " + engine.getValue("[Channel1]","scratch") + " deck2: "+ engine.getValue("[Channel2]","scratch"));
  571.  
  572. jog1DecayRate = HerculesMK2.decayRate * (engine.getValue("[Channel1]","play") ? 1 : 5);
  573. jog1 = engine.getValue("[Channel1]","scratch");
  574. if (jog1 != 0)
  575. {
  576. if (Math.abs(jog1) > jog1DecayRate)
  577. engine.setValue("[Channel1]","scratch", (jog1 / jog1DecayRate).toFixed(2));
  578. else
  579. engine.setValue("[Channel1]","scratch", 0);
  580. }
  581. jog2DecayRate = HerculesMK2.decayRate * (engine.getValue("[Channel2]","play") ? 1 : 5);
  582. jog2 = engine.getValue("[Channel2]","scratch");
  583. if (jog2 != 0)
  584. {
  585. if (Math.abs(jog2) > jog2DecayRate)
  586. engine.setValue("[Channel2]","scratch", (jog2 / jog2DecayRate).toFixed(2));
  587. else
  588. engine.setValue("[Channel2]","scratch", 0);
  589. }
  590. }
  591. }
  592. };
  593.  
  594.  
  595.  
  596.  
  597.  
  598. HerculesMK2.joystick = function (group, control, value, status) {
  599. //if (HerculesMK2.debug) print ("[Debug] HerculesMK2.playlist (" + group +", "+ control +", "+value +", "+status +")" );
  600.  
  601. switch (control)
  602. {
  603. case 0x39:
  604. switch (value)
  605. {
  606. case 0x05:
  607. joystick = "top";
  608. break;
  609. case 0x7F:
  610. joystick = "bottom";
  611. break;
  612. default:
  613. joystick = false;
  614. }
  615. break;
  616. case 0x38:
  617. switch (value)
  618. {
  619. case 0x00:
  620. joystick = "left";
  621. break;
  622. case 0x7F:
  623. joystick = "right";
  624. break;
  625. default:
  626. joystick = false;
  627. }
  628. break;
  629. default:
  630. joystick = false;
  631. break;
  632. }
  633.  
  634. HerculesMK2.joystickValue = joystick;
  635. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement