Merge lp:~zestoi/mixxx/controller_scripts into lp:~mixxxdevelopers/mixxx/trunk
- controller_scripts
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 3226 |
Proposed branch: | lp:~zestoi/mixxx/controller_scripts |
Merge into: | lp:~mixxxdevelopers/mixxx/trunk |
Diff against target: |
429 lines (+80/-166) 3 files modified
mixxx/res/controllers/Hercules-DJ-Console-Mk2-hid-scripts.js (+5/-2) mixxx/res/controllers/Novation-Launchpad-scripts.js (+63/-69) mixxx/res/controllers/common-controller-scripts.js (+12/-95) |
To merge this branch: | bzr merge lp:~zestoi/mixxx/controller_scripts |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Mixxx Development Team | Pending | ||
Review via email: mp+107559@code.launchpad.net |
Commit message
Description of the change
* use engine.spinback() and engine.brake() in launchpad and mk2 mappings and the common-
* add in missing led feedback for channel2 eq kills in the herc mapping
* fix for the led feedback in the launchpad mapping - cause by the different runtime environment after the merge of madjester's code last night (i think) where 'this' is now in the engine as opposed to the controller instance
- 3218. By Zestoi
-
remove debug
- 3219. By Zestoi
-
removed javascript implementation of spinback/brake and renamed script.
spinbackDefault to script.spinback and script.brakeDefault to script.brake - 3220. By Zestoi
-
whitespace
- 3221. By Zestoi
-
fixed new context for incomingData() and used new lambda style calling of engine.
connectControl( )
Preview Diff
1 | === modified file 'mixxx/res/controllers/Hercules-DJ-Console-Mk2-hid-scripts.js' | |||
2 | --- mixxx/res/controllers/Hercules-DJ-Console-Mk2-hid-scripts.js 2012-05-26 14:22:39 +0000 | |||
3 | +++ mixxx/res/controllers/Hercules-DJ-Console-Mk2-hid-scripts.js 2012-05-29 18:21:20 +0000 | |||
4 | @@ -231,6 +231,9 @@ | |||
5 | 231 | c.feedback("[Channel1]", "filterHighKill", c.kill_status); | 231 | c.feedback("[Channel1]", "filterHighKill", c.kill_status); |
6 | 232 | c.feedback("[Channel1]", "filterMidKill", c.kill_status); | 232 | c.feedback("[Channel1]", "filterMidKill", c.kill_status); |
7 | 233 | c.feedback("[Channel1]", "filterLowKill", c.kill_status); | 233 | c.feedback("[Channel1]", "filterLowKill", c.kill_status); |
8 | 234 | c.feedback("[Channel2]", "filterHighKill", c.kill_status); | ||
9 | 235 | c.feedback("[Channel2]", "filterMidKill", c.kill_status); | ||
10 | 236 | c.feedback("[Channel2]", "filterLowKill", c.kill_status); | ||
11 | 234 | 237 | ||
12 | 235 | // | 238 | // |
13 | 236 | // clear/setup any initial leds | 239 | // clear/setup any initial leds |
14 | @@ -261,10 +264,10 @@ | |||
15 | 261 | engine.setValue(g, "flanger", v > 0); | 264 | engine.setValue(g, "flanger", v > 0); |
16 | 262 | break; | 265 | break; |
17 | 263 | case 2: | 266 | case 2: |
19 | 264 | script.spinback(g, v > 0); | 267 | engine.spinback(parseInt(g.substring(8,9)), v > 0); |
20 | 265 | break; | 268 | break; |
21 | 266 | case 3: | 269 | case 3: |
23 | 267 | script.brake(g, v > 0); | 270 | engine.brake(parseInt(g.substring(8,9)), v > 0); |
24 | 268 | } | 271 | } |
25 | 269 | break; | 272 | break; |
26 | 270 | case "hotcue": | 273 | case "hotcue": |
27 | 271 | 274 | ||
28 | === modified file 'mixxx/res/controllers/Novation-Launchpad-scripts.js' | |||
29 | --- mixxx/res/controllers/Novation-Launchpad-scripts.js 2012-05-26 14:22:39 +0000 | |||
30 | +++ mixxx/res/controllers/Novation-Launchpad-scripts.js 2012-05-29 18:21:20 +0000 | |||
31 | @@ -25,6 +25,8 @@ | |||
32 | 25 | this.vumeters = []; | 25 | this.vumeters = []; |
33 | 26 | 26 | ||
34 | 27 | var self = NovationLaunchpad; | 27 | var self = NovationLaunchpad; |
35 | 28 | self.instance = this; // needed for incoming data from the launchpad | ||
36 | 29 | |||
37 | 28 | this.colors = self.colors(); | 30 | this.colors = self.colors(); |
38 | 29 | this.capture = self.capture; | 31 | this.capture = self.capture; |
39 | 30 | this.feedback = self.feedback; | 32 | this.feedback = self.feedback; |
40 | @@ -153,10 +155,11 @@ | |||
41 | 153 | 155 | ||
42 | 154 | // led feedback for loop in/out buttons to show loop status | 156 | // led feedback for loop in/out buttons to show loop status |
43 | 155 | 157 | ||
48 | 156 | this.feedback(group, "loop_enabled", function(self, g, e, value) { | 158 | engine.connectControl(group, "loop_enabled", function(value, g, e) { |
49 | 157 | var offset = g == "[Channel1]" ? 0 : 4; // ???? | 159 | var offset = g == "[Channel1]" ? 0 : 4; // value not closed |
50 | 158 | self.send("3," + (offset + 0), self.colors[value > 0 ? 'hi_green' : 'lo_green'], page); | 160 | this.send("3," + (offset + 0), this.colors[value > 0 ? 'hi_green' : 'lo_green'], 1); |
51 | 159 | self.send("3," + (offset + 1), self.colors[value > 0 ? 'hi_green' : 'lo_green'], page); | 161 | this.send("3," + (offset + 1), this.colors[value > 0 ? 'hi_green' : 'lo_green'], 1); |
52 | 162 | this.feedback_cache[g + e] = value; | ||
53 | 160 | }); | 163 | }); |
54 | 161 | 164 | ||
55 | 162 | // hotcues or needle drop with shift2 pressed | 165 | // hotcues or needle drop with shift2 pressed |
56 | @@ -185,10 +188,11 @@ | |||
57 | 185 | this.toggle("7," + (offset + 0), "press", 1, 'hi_yellow', 'lo_red', group, "play"); | 188 | this.toggle("7," + (offset + 0), "press", 1, 'hi_yellow', 'lo_red', group, "play"); |
58 | 186 | 189 | ||
59 | 187 | // flash play button when near end of track | 190 | // flash play button when near end of track |
61 | 188 | this.feedback(group, "playposition", function(self, g, e, value) { | 191 | engine.connectControl(group, "playposition", function(value, g, e) { |
62 | 189 | if (value > 0.9 && engine.getValue(g, "play") > 0) { | 192 | if (value > 0.9 && engine.getValue(g, "play") > 0) { |
64 | 190 | self.send(g == "[Channel1]" ? "7,0" : "7,4", self.colors['flash_hi_red'], 1); | 193 | this.send(g == "[Channel1]" ? "7,0" : "7,4", this.colors['flash_hi_red'], 1); |
65 | 191 | } | 194 | } |
66 | 195 | this.feedback_cache[g + e] = value; | ||
67 | 192 | }); | 196 | }); |
68 | 193 | 197 | ||
69 | 194 | // sync or move beatgrid when shift is pressed | 198 | // sync or move beatgrid when shift is pressed |
70 | @@ -233,15 +237,23 @@ | |||
71 | 233 | }, | 237 | }, |
72 | 234 | 238 | ||
73 | 235 | // | 239 | // |
74 | 240 | // empty shutdown method | ||
75 | 241 | // | ||
76 | 242 | |||
77 | 243 | shutdown: function() { | ||
78 | 244 | }, | ||
79 | 245 | |||
80 | 246 | // | ||
81 | 236 | // convert incoming midi to a 'name' and call callbacks (if any) | 247 | // convert incoming midi to a 'name' and call callbacks (if any) |
82 | 237 | // | 248 | // |
83 | 238 | 249 | ||
84 | 239 | incomingData: function(channel, control, value, status, group) { | 250 | incomingData: function(channel, control, value, status, group) { |
88 | 240 | if ((name = this.control2name["" + status + control]) != undefined) { | 251 | var me = NovationLaunchpad.instance; |
89 | 241 | if (this.callbacks[name] != undefined) { | 252 | if ((name = me.control2name["" + status + control]) != undefined) { |
90 | 242 | var callbacks = this.callbacks[name]; | 253 | if (me.callbacks[name] != undefined) { |
91 | 254 | var callbacks = me.callbacks[name]; | ||
92 | 243 | for (var i=0; i<callbacks.length; i++) { | 255 | for (var i=0; i<callbacks.length; i++) { |
94 | 244 | if ((callbacks[i][1] == 0 || callbacks[i][1] == this.page) && typeof(callbacks[i][2]) == 'function') { | 256 | if ((callbacks[i][1] == 0 || callbacks[i][1] == me.page) && typeof(callbacks[i][2]) == 'function') { |
95 | 245 | 257 | ||
96 | 246 | // | 258 | // |
97 | 247 | // check we need to call for this value change: all, press, release | 259 | // check we need to call for this value change: all, press, release |
98 | @@ -255,7 +267,7 @@ | |||
99 | 255 | // call a callback function for this control | 267 | // call a callback function for this control |
100 | 256 | // | 268 | // |
101 | 257 | 269 | ||
103 | 258 | callbacks[i][2](this, group, name, value); | 270 | callbacks[i][2].call(me, group, name, value); |
104 | 259 | } | 271 | } |
105 | 260 | } | 272 | } |
106 | 261 | } | 273 | } |
107 | @@ -351,35 +363,6 @@ | |||
108 | 351 | }, | 363 | }, |
109 | 352 | 364 | ||
110 | 353 | // | 365 | // |
111 | 354 | // map a callback to an event from mixxx | ||
112 | 355 | // | ||
113 | 356 | |||
114 | 357 | feedback: function(g, e, f) { | ||
115 | 358 | if (g != "" && e != "") { | ||
116 | 359 | engine.connectControl(g, e, "NovationLaunchpad.feedbackData"); | ||
117 | 360 | if (this.feedbacks[g + e] == undefined) { | ||
118 | 361 | this.feedbacks[g + e] = []; | ||
119 | 362 | } | ||
120 | 363 | this.feedbacks[g + e].push(f); | ||
121 | 364 | } | ||
122 | 365 | }, | ||
123 | 366 | |||
124 | 367 | // | ||
125 | 368 | // call callbacks from mixxx events | ||
126 | 369 | // | ||
127 | 370 | |||
128 | 371 | feedbackData: function(v, g, e) { | ||
129 | 372 | this.feedback_cache[g + e] = v; | ||
130 | 373 | if (this.feedbacks[g + e] != undefined) { | ||
131 | 374 | for (func in this.feedbacks[g + e]) { | ||
132 | 375 | if (typeof(this.feedbacks[g + e][func]) == "function") { | ||
133 | 376 | this.feedbacks[g + e][func](this, g, e, v); | ||
134 | 377 | } | ||
135 | 378 | } | ||
136 | 379 | } | ||
137 | 380 | }, | ||
138 | 381 | |||
139 | 382 | // | ||
140 | 383 | // map a callback to a launchpad button name | 366 | // map a callback to a launchpad button name |
141 | 384 | // | 367 | // |
142 | 385 | 368 | ||
143 | @@ -414,25 +397,27 @@ | |||
144 | 414 | 397 | ||
145 | 415 | // launchpad => mixxx | 398 | // launchpad => mixxx |
146 | 416 | 399 | ||
148 | 417 | this.capture(name, "all", page, function(self, g, name, value) { | 400 | this.capture(name, "all", page, function(g, name, value) { |
149 | 401 | |||
150 | 418 | if (callback == undefined) { | 402 | if (callback == undefined) { |
151 | 419 | engine.setValue(group, event, value); | 403 | engine.setValue(group, event, value); |
152 | 420 | } | 404 | } |
153 | 421 | else if (typeof(callback) == "function") { | 405 | else if (typeof(callback) == "function") { |
154 | 422 | if (values == "all" || (values == "press" && value > 0) || (values == "release" && value == 0)) { | 406 | if (values == "all" || (values == "press" && value > 0) || (values == "release" && value == 0)) { |
156 | 423 | callback(group, event, value); | 407 | callback.call(this, group, event, value); |
157 | 424 | } | 408 | } |
158 | 425 | } | 409 | } |
159 | 426 | 410 | ||
160 | 427 | if (values == "all" || (values == "press" && value > 0) || (values == "release" && value == 0)) { | 411 | if (values == "all" || (values == "press" && value > 0) || (values == "release" && value == 0)) { |
162 | 428 | self.send(name, self.colors[value > 0 ? on_color : off_color], page); | 412 | this.send(name, this.colors[value > 0 ? on_color : off_color], page); |
163 | 429 | } | 413 | } |
164 | 430 | }); | 414 | }); |
165 | 431 | 415 | ||
166 | 432 | // mixxx => launchpad | 416 | // mixxx => launchpad |
167 | 433 | 417 | ||
170 | 434 | this.feedback(group, event, function(self, g, e, value) { | 418 | engine.connectControl(group, event, function(value, g, e) { |
171 | 435 | self.send(name, self.colors[value > 0 ? on_color : off_color], page); | 419 | this.send(name, this.colors[value > 0 ? on_color : off_color], page); |
172 | 420 | this.feedback_cache[g + e] = value; | ||
173 | 436 | }); | 421 | }); |
174 | 437 | 422 | ||
175 | 438 | // init led | 423 | // init led |
176 | @@ -445,27 +430,28 @@ | |||
177 | 445 | // | 430 | // |
178 | 446 | 431 | ||
179 | 447 | toggle: function(name, values, page, on_color, off_color, group, event, callback) { | 432 | toggle: function(name, values, page, on_color, off_color, group, event, callback) { |
183 | 448 | this.capture(name, "press", page, function(self, g, name, value) { | 433 | this.capture(name, "press", page, function(g, name, value) { |
184 | 449 | if (typeof(self.toggle_cache[page][name]) == "undefined") { | 434 | if (typeof(this.toggle_cache[page][name]) == "undefined") { |
185 | 450 | self.toggle_cache[page][name] = 0; | 435 | this.toggle_cache[page][name] = 0; |
186 | 451 | } | 436 | } |
188 | 452 | self.toggle_cache[page][name] = self.toggle_cache[page][name] == 0 ? 1 : 0; | 437 | this.toggle_cache[page][name] = this.toggle_cache[page][name] == 0 ? 1 : 0; |
189 | 453 | 438 | ||
190 | 454 | if (callback == undefined) { | 439 | if (callback == undefined) { |
192 | 455 | engine.setValue(group, event, self.toggle_cache[page][name]); | 440 | engine.setValue(group, event, this.toggle_cache[page][name]); |
193 | 456 | } | 441 | } |
194 | 457 | else if (typeof(callback) == "function") { | 442 | else if (typeof(callback) == "function") { |
196 | 458 | callback(group, event, self.toggle_cache[page][name]); | 443 | callback.call(this, group, event, this.toggle_cache[page][name]); |
197 | 459 | } | 444 | } |
198 | 460 | 445 | ||
200 | 461 | self.send(name, self.colors[self.toggle_cache[page][name] > 0 ? on_color : off_color], page); | 446 | this.send(name, this.colors[this.toggle_cache[page][name] > 0 ? on_color : off_color], page); |
201 | 462 | }); | 447 | }); |
202 | 463 | 448 | ||
203 | 464 | // mixxx => launchpad | 449 | // mixxx => launchpad |
204 | 465 | 450 | ||
208 | 466 | this.feedback(group, event, function(self, g, e, value) { | 451 | engine.connectControl(group, event, function(value, g, e) { |
209 | 467 | self.send(name, self.colors[value > 0 ? on_color : off_color], page); | 452 | this.send(name, this.colors[value > 0 ? on_color : off_color], page); |
210 | 468 | self.toggle_cache[page][name] = value > 0 ? 1 : 0; | 453 | this.toggle_cache[page][name] = value > 0 ? 1 : 0; |
211 | 454 | this.feedback_cache[g + e] = value; | ||
212 | 469 | }); | 455 | }); |
213 | 470 | 456 | ||
214 | 471 | // init led | 457 | // init led |
215 | @@ -478,11 +464,14 @@ | |||
216 | 478 | // | 464 | // |
217 | 479 | 465 | ||
218 | 480 | hotcue: function(name, page, group, num) { | 466 | hotcue: function(name, page, group, num) { |
221 | 481 | this.capture(name, "press", page, function(self, g, name, value) { | 467 | |
222 | 482 | if (self.shift2) { | 468 | // launchpad => mixxx |
223 | 469 | |||
224 | 470 | this.capture(name, "press", page, function(g, name, value) { | ||
225 | 471 | if (this.shift2) { | ||
226 | 483 | engine.setValue(group, "playposition", (num-1)/8); | 472 | engine.setValue(group, "playposition", (num-1)/8); |
227 | 484 | } | 473 | } |
229 | 485 | else if (self.shift) { | 474 | else if (this.shift) { |
230 | 486 | engine.setValue(group, "hotcue_" + num + "_clear", 1); | 475 | engine.setValue(group, "hotcue_" + num + "_clear", 1); |
231 | 487 | } | 476 | } |
232 | 488 | else { | 477 | else { |
233 | @@ -490,8 +479,11 @@ | |||
234 | 490 | } | 479 | } |
235 | 491 | }); | 480 | }); |
236 | 492 | 481 | ||
239 | 493 | this.feedback(group, "hotcue_" + num + "_enabled", function(self, g, e, value) { | 482 | // mixxx => launchpad |
240 | 494 | self.send(name, self.colors[value > 0 ? 'hi_red' : 'black'], page); | 483 | |
241 | 484 | engine.connectControl(group, "hotcue_" + num + "_enabled", function(value, g, e) { | ||
242 | 485 | this.send(name, this.colors[value > 0 ? 'hi_red' : 'black'], page); | ||
243 | 486 | this.feedback_cache[g + e] = value; | ||
244 | 495 | }); | 487 | }); |
245 | 496 | }, | 488 | }, |
246 | 497 | 489 | ||
247 | @@ -538,8 +530,8 @@ | |||
248 | 538 | // launchpad => mixxx | 530 | // launchpad => mixxx |
249 | 539 | 531 | ||
250 | 540 | for (var btn=0; btn<nbtns; btn++) { | 532 | for (var btn=0; btn<nbtns; btn++) { |
253 | 541 | this.capture((y-btn)+","+x, "press", page, function(self, g, name, value) { | 533 | this.capture((y-btn)+","+x, "press", page, function(g, name, value) { |
254 | 542 | var cap = name.match(/^(\d+),\d+/); | 534 | var cap = name.match(/^(\d+),\d+/); // value not closed |
255 | 543 | var num = y - cap[1] + 1; | 535 | var num = y - cap[1] + 1; |
256 | 544 | engine.setValue(group, action, incr * num); | 536 | engine.setValue(group, action, incr * num); |
257 | 545 | }); | 537 | }); |
258 | @@ -548,15 +540,16 @@ | |||
259 | 548 | 540 | ||
260 | 549 | // mixxx => launchpad | 541 | // mixxx => launchpad |
261 | 550 | 542 | ||
263 | 551 | this.feedback(group, action, function(self, g, e, value) { | 543 | engine.connectControl(group, action, function(value, g, e) { |
264 | 552 | for (btn=0; btn<nbtns; btn++) { | 544 | for (btn=0; btn<nbtns; btn++) { |
265 | 553 | if (value > btn*incr) { | 545 | if (value > btn*incr) { |
267 | 554 | self.send((y-btn)+","+x, self.colors[on_color], page); | 546 | this.send((y-btn)+","+x, this.colors[on_color], page); |
268 | 555 | } | 547 | } |
269 | 556 | else { | 548 | else { |
271 | 557 | self.send((y-btn)+","+x, self.colors[off_color], page); | 549 | this.send((y-btn)+","+x, this.colors[off_color], page); |
272 | 558 | } | 550 | } |
273 | 559 | } | 551 | } |
274 | 552 | this.feedback_cache[g + e] = value; | ||
275 | 560 | }); | 553 | }); |
276 | 561 | }, | 554 | }, |
277 | 562 | 555 | ||
278 | @@ -567,17 +560,18 @@ | |||
279 | 567 | vumeter: function(y, x, page, nbtns, on_color, off_color, group, action) { | 560 | vumeter: function(y, x, page, nbtns, on_color, off_color, group, action) { |
280 | 568 | var incr = 1 / nbtns; | 561 | var incr = 1 / nbtns; |
281 | 569 | this.vumeters.push([ y, x, page, nbtns, on_color, off_color, group, action ]); | 562 | this.vumeters.push([ y, x, page, nbtns, on_color, off_color, group, action ]); |
284 | 570 | this.feedback(group, action, function(self, g, e, value) { | 563 | engine.connectControl(group, action, function(value, g, e) { |
285 | 571 | if (self.vumeter_shift > 0) { | 564 | if (this.vumeter_shift > 0) { |
286 | 572 | for (btn=0; btn<nbtns; btn++) { | 565 | for (btn=0; btn<nbtns; btn++) { |
287 | 573 | if (value > btn*incr) { | 566 | if (value > btn*incr) { |
289 | 574 | self.send((y-btn)+","+x, self.colors[on_color], page); | 567 | this.send((y-btn)+","+x, this.colors[on_color], page); |
290 | 575 | } | 568 | } |
291 | 576 | else { | 569 | else { |
293 | 577 | self.send((y-btn)+","+x, self.colors[off_color], page); | 570 | this.send((y-btn)+","+x, this.colors[off_color], page); |
294 | 578 | } | 571 | } |
295 | 579 | } | 572 | } |
296 | 580 | } | 573 | } |
297 | 574 | this.feedback_cache[g + e] = value; | ||
298 | 581 | }); | 575 | }); |
299 | 582 | }, | 576 | }, |
300 | 583 | 577 | ||
301 | 584 | 578 | ||
302 | === modified file 'mixxx/res/controllers/common-controller-scripts.js' | |||
303 | --- mixxx/res/controllers/common-controller-scripts.js 2012-05-27 12:48:11 +0000 | |||
304 | +++ mixxx/res/controllers/common-controller-scripts.js 2012-05-29 18:21:20 +0000 | |||
305 | @@ -123,112 +123,29 @@ | |||
306 | 123 | } | 123 | } |
307 | 124 | 124 | ||
308 | 125 | /* -------- ------------------------------------------------------ | 125 | /* -------- ------------------------------------------------------ |
311 | 126 | script.spinbackDefault | 126 | script.spinback |
312 | 127 | Purpose: wrapper around spinback() that can be directly mapped | 127 | Purpose: wrapper around engine.spinback() that can be directly mapped |
313 | 128 | from xml for a spinback effect | 128 | from xml for a spinback effect |
314 | 129 | e.g: <key>script.spinback</key> | ||
315 | 129 | Input: channel, control, value, status, group | 130 | Input: channel, control, value, status, group |
316 | 130 | Output: none | 131 | Output: none |
317 | 131 | -------- ------------------------------------------------------ */ | 132 | -------- ------------------------------------------------------ */ |
321 | 132 | script.spinbackDefault = function(channel, control, value, status, group) { | 133 | script.spinback = function(channel, control, value, status, group) { |
322 | 133 | // disable on note-off or zero value note/cc | 134 | // disable on note-off or zero value note/cc |
323 | 134 | script.spinback(group, ((status & 0xF0) != 0x80 && value > 0)); | 135 | engine.spinback(parseInt(group.substring(8,9)), ((status & 0xF0) != 0x80 && value > 0)); |
324 | 135 | } | 136 | } |
325 | 136 | 137 | ||
326 | 137 | /* -------- ------------------------------------------------------ | 138 | /* -------- ------------------------------------------------------ |
329 | 138 | script.brakeDefault | 139 | script.brake |
330 | 139 | Purpose: wrapper around brake() that can be directly mapped | 140 | Purpose: wrapper around engine.brake() that can be directly mapped |
331 | 140 | from xml for a brake effect | 141 | from xml for a brake effect |
332 | 142 | e.g: <key>script.brake</key> | ||
333 | 141 | Input: channel, control, value, status, group | 143 | Input: channel, control, value, status, group |
334 | 142 | Output: none | 144 | Output: none |
335 | 143 | -------- ------------------------------------------------------ */ | 145 | -------- ------------------------------------------------------ */ |
424 | 144 | script.brakeDefault = function(channel, control, value, status, group) { | 146 | script.brake = function(channel, control, value, status, group) { |
425 | 145 | // disable on note-off or zero value note/cc | 147 | // disable on note-off or zero value note/cc |
426 | 146 | script.brake(group, ((status & 0xF0) != 0x80 && value > 0)); | 148 | engine.brake(parseInt(group.substring(8,9)), ((status & 0xF0) != 0x80 && value > 0)); |
339 | 147 | } | ||
340 | 148 | |||
341 | 149 | /* -------- ------------------------------------------------------ | ||
342 | 150 | script.spinback | ||
343 | 151 | Purpose: Activate or disable a spinback effect on the chosen deck | ||
344 | 152 | Input: group, enable/disable, [delay], [factor], [inital rate] | ||
345 | 153 | Output: None | ||
346 | 154 | -------- ------------------------------------------------------ */ | ||
347 | 155 | script.spinback = function(group, activate, factor, rate, delay) { | ||
348 | 156 | if (factor == undefined) factor = 0.8; | ||
349 | 157 | if (rate == undefined) rate = -10; | ||
350 | 158 | if (delay == undefined) delay = 5; | ||
351 | 159 | script.deckSpinbackBrake(group, activate, factor, rate, delay); | ||
352 | 160 | } | ||
353 | 161 | |||
354 | 162 | /* -------- ------------------------------------------------------ | ||
355 | 163 | script.brake | ||
356 | 164 | Purpose: Activate or disable a brake effect on the chosen deck | ||
357 | 165 | Input: group, enable/disable, [delay], [factor], [inital rate] | ||
358 | 166 | Output: None | ||
359 | 167 | -------- ------------------------------------------------------ */ | ||
360 | 168 | script.brake = function(group, activate, factor, rate, delay) { | ||
361 | 169 | if (factor == undefined) factor = 0.95; | ||
362 | 170 | if (rate == undefined) rate = 1; | ||
363 | 171 | if (delay == undefined) delay = 0; | ||
364 | 172 | script.deckSpinbackBrake(group, activate, factor, rate, delay); | ||
365 | 173 | } | ||
366 | 174 | |||
367 | 175 | script.deckSpinbackBrakeData = {}; | ||
368 | 176 | |||
369 | 177 | script.deckSpinbackBrake = function(group, activate, factor, rate, delay) { | ||
370 | 178 | |||
371 | 179 | if (activate != undefined) { | ||
372 | 180 | |||
373 | 181 | // store the current settings | ||
374 | 182 | |||
375 | 183 | if (script.deckSpinbackBrakeData[group] == undefined) { | ||
376 | 184 | script.deckSpinbackBrakeData[group] = { timer: null, delay: delay, factor: factor, rate: rate }; | ||
377 | 185 | } | ||
378 | 186 | else { | ||
379 | 187 | script.deckSpinbackBrakeData[group].delay = delay; | ||
380 | 188 | script.deckSpinbackBrakeData[group].factor = factor; | ||
381 | 189 | script.deckSpinbackBrakeData[group].rate = rate; | ||
382 | 190 | } | ||
383 | 191 | |||
384 | 192 | // kill timer when both enabling or disabling | ||
385 | 193 | |||
386 | 194 | if (script.deckSpinbackBrakeData[group].timer != null) { | ||
387 | 195 | engine.stopTimer(script.deckSpinbackBrakeData[group].timer); | ||
388 | 196 | script.deckSpinbackBrakeData[group].timer = null; | ||
389 | 197 | } | ||
390 | 198 | |||
391 | 199 | // enable/disable scratch2 mode | ||
392 | 200 | |||
393 | 201 | engine.setValue(group, 'scratch2_enable', activate ? 1 : 0); | ||
394 | 202 | |||
395 | 203 | if (activate) { | ||
396 | 204 | // save keylock status and disable it | ||
397 | 205 | if ((script.deckSpinbackBrakeData[group].keylock = engine.getValue(group, "keylock")) > 0) { | ||
398 | 206 | engine.setValue(group, "keylock", 0); | ||
399 | 207 | } | ||
400 | 208 | |||
401 | 209 | // setup timer and send first scratch2 'tick' if activating | ||
402 | 210 | script.deckSpinbackBrakeData[group].timer = engine.beginTimer(50, 'script.deckSpinbackBrake("' + group + '")'); | ||
403 | 211 | engine.setValue(group, 'scratch2', script.deckSpinbackBrakeData[group].rate); | ||
404 | 212 | } | ||
405 | 213 | |||
406 | 214 | // re-enable keylock if needed | ||
407 | 215 | |||
408 | 216 | else if (script.deckSpinbackBrakeData[group].keylock) { | ||
409 | 217 | engine.setValue(group, "keylock", 1); | ||
410 | 218 | } | ||
411 | 219 | } | ||
412 | 220 | else { | ||
413 | 221 | // being called from a timer | ||
414 | 222 | |||
415 | 223 | engine.setValue(group, 'scratch2', script.deckSpinbackBrakeData[group].rate); | ||
416 | 224 | |||
417 | 225 | if (script.deckSpinbackBrakeData[group].delay > 0) { | ||
418 | 226 | script.deckSpinbackBrakeData[group].delay--; | ||
419 | 227 | } | ||
420 | 228 | else { | ||
421 | 229 | script.deckSpinbackBrakeData[group].rate *= script.deckSpinbackBrakeData[group].factor; | ||
422 | 230 | } | ||
423 | 231 | } | ||
427 | 232 | } | 149 | } |
428 | 233 | 150 | ||
429 | 234 | // bpm - Used for tapping the desired BPM for a deck | 151 | // bpm - Used for tapping the desired BPM for a deck |