summaryrefslogtreecommitdiffstats
path: root/res/controllers/Hercules-DJ-Console-Mk4-scripts.js
blob: 7f12a22fd74054d05979762987b6a5f4dfb9c6ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
function HerculesMk4 () {}

//Hercules Mk4 scripts from Dj Kork.... enjoy them ;)



// Number of the standard RPM value. Lower values increase de sensitivity as the really records.
HerculesMk4.standardRpm = 33.33;

// The HerculesMk4.alpha value for the filter (start with 1/8 (0.125) and tune from there)
HerculesMk4.alpha = 1/8;

// The HerculesMk4.beta value for the filter (start with HerculesMk4.alpha/32 and tune from there)
HerculesMk4.beta = HerculesMk4.alpha/20;

HerculesMk4.scratchButton = 0;
HerculesMk4.scratchMode =[0,0];
HerculesMk4.antiguoMixCue=1;
HerculesMk4.sensivityPitch=[5,5];
HerculesMk4.jogFastPosition=[0,0];




HerculesMk4.init = function (id) {
	// Switch off all LEDs
	for (var i=1; i<95; i++) midi.sendShortMsg(0x90, i, 0x00);
	// Switch-on the LEDs for improve the usability
	midi.sendShortMsg(0x90, 45, 0x7F);	// Scratch LED
	midi.sendShortMsg(0x90, 14, 0x7F);	// Cue deck A LED
	midi.sendShortMsg(0x90, 34, 0x7F);	// Cue deck B LED
};

HerculesMk4.shutdown = function (id) {
	// Switch off all LEDs
	for (var i=1; i<95; i++) midi.sendShortMsg(0x90, i, 0x00);
};



HerculesMk4.loadTrack = function (midino, control, value, status, group) {
	// Load the selected track in the corresponding deck only if the track is
	// paused

	if(value && engine.getValue(group, "play") != 1) {
		engine.setValue(group, "LoadSelectedTrack", 1);
		engine.setValue(group, "rate", 0);
		}
	else engine.setValue(group, "LoadSelectedTrack", 0);
};


HerculesMk4.scroll = function (midino, control, value, status, group) {
	// Button "Files": up 10 tracks
	// Button "Folder": down 10 tracks
	// This function scroll up or down 10 tracks on the playlist, like the mouse
	// scroll.

	if(control == 0x2C && value == 0x7F) {
		engine.setValue("[Playlist]", "SelectPrevTrack", "1");
		engine.setValue("[Playlist]", "SelectPrevTrack", "1");
		engine.setValue("[Playlist]", "SelectPrevTrack", "1");
		engine.setValue("[Playlist]", "SelectPrevTrack", "1");
		engine.setValue("[Playlist]", "SelectPrevTrack", "1");
		engine.setValue("[Playlist]", "SelectPrevTrack", "1");
		engine.setValue("[Playlist]", "SelectPrevTrack", "1");
		engine.setValue("[Playlist]", "SelectPrevTrack", "1");
		engine.setValue("[Playlist]", "SelectPrevTrack", "1");
		engine.setValue("[Playlist]", "SelectPrevTrack", "1");
		engine.setValue("[Playlist]", "SelectPrevTrack", "0");
		}
	if (control == 0x2B && value == 0x7F) {
		engine.setValue("[Playlist]", "SelectNextTrack", "1");
		engine.setValue("[Playlist]", "SelectNextTrack", "1");
		engine.setValue("[Playlist]", "SelectNextTrack", "1");
		engine.setValue("[Playlist]", "SelectNextTrack", "1");
		engine.setValue("[Playlist]", "SelectNextTrack", "1");
		engine.setValue("[Playlist]", "SelectNextTrack", "1");
		engine.setValue("[Playlist]", "SelectNextTrack", "1");
		engine.setValue("[Playlist]", "SelectNextTrack", "1");
		engine.setValue("[Playlist]", "SelectNextTrack", "1");
		engine.setValue("[Playlist]", "SelectNextTrack", "1");
		engine.setValue("[Playlist]", "SelectNextTrack", "0");
		}
};



HerculesMk4.keyButton = function (midino, control, value, status, group) {
	// Loop command for the first 4 Key, Hotcues command for the latest 4

	switch (control) {

	// Loop buttons
		case 0x01: case 0x15:  	// K1, Loop in
			engine.setValue(group, "loop_in", value ? 1 : 0);
			break;
		case 0x02: case 0x16:	// K2, Loop out
			engine.setValue(group, "loop_out", value ? 1 : 0);
			break;
		case 0x03: case 0x17:	// K3, Reloop/Exit
			engine.setValue(group, "reloop_exit", value ? 1 : 0); break;
			break;
		case 0x04: case 0x18:	// K4, Reloop/Exit
			engine.setValue(group, "reloop_exit", value ? 1 : 0);
			break;

	// Hotcue buttons:
	// Simple press: go to the hotcue position
	// Shift (hold down "scratch"): clear the hotcue

		case 0x05: case 0x19 :	// K5
			if (HerculesMk4.scratchButton == 1) {
				//HerculesMk4.holdButton(group, value, "hotcue_1_set", "hotcue_1_clear");
				engine.setValue(group, "hotcue_1_clear", value ? 1 : 0);
			}
			else engine.setValue(group, "hotcue_1_activate", value ? 1 : 0);
			break;

		case 0x06: case 0x1A:	// K6
			if (HerculesMk4.scratchButton == 1) {
				//HerculesMk4.holdButton(group, value, "hotcue_2_set", "hotcue_2_clear");
				engine.setValue(group, "hotcue_2_clear", value ? 1 : 0);
			}
			else engine.setValue(group, "hotcue_2_activate", value ? 1 : 0);
			break;

		case 0x07: case 0x1B:	// K7
			if (HerculesMk4.scratchButton == 1) {
				//HerculesMk4.holdButton(group, value, "hotcue_3_set", "hotcue_3_clear");
				engine.setValue(group, "hotcue_3_clear", value ? 1 : 0);
			}
			else engine.setValue(group, "hotcue_3_activate", value ? 1 : 0);
			break;

		case 0x08: case 0x1C:	// K8
			if (HerculesMk4.scratchButton == 1) {
				//HerculesMk4.holdButton(group, value, "hotcue_4_set", "hotcue_4_clear");
				engine.setValue(group, "hotcue_4_clear", value ? 1 : 0);
			}
			else engine.setValue(group, "hotcue_4_activate", value ? 1 : 0);
			break;
		}
};

HerculesMk4.knobIncrement = function (group, action, minValue, maxValue, centralValue, step, sign) {
	// This function allows you to increment a non-linear value like the volume's knob
	// sign must be 1 for positive increment, -1 for negative increment
	var semiStep = step/2;
	var rangeWidthLeft = centralValue-minValue;
	var rangeWidthRight = maxValue-centralValue;
	var actual = engine.getValue(group, action);
	var increment;
	if (actual < 1) increment = ((rangeWidthLeft)/semiStep)*sign;
	if (actual > 1) increment = ((rangeWidthRight)/semiStep)*sign;
	if (actual == 1) {
		increment = (sign == 1) ? rangeWidthRight/semiStep : (rangeWidthLeft/semiStep)*sign;
	}

	var newValue;

	if (sign == 1 && actual < maxValue) 	newValue = actual + increment;
	if (sign == -1 && actual > minValue)	newValue = actual + increment;
	return newValue;
};


HerculesMk4.deck=function(group){
 //channel 1 -->deck 0
 //channel 2 -->deck 1
 return (group=="[Channel1]") ? 0 : 1;
}

HerculesMk4.selectLed=function(group,led){
 //channel 1 -->led 0
 //channel 2 -->led + 20
 return (group=="[Channel1]") ? led : led+20;
}



HerculesMk4.pitch = function (midino, control, value, status, group) {
	// Simple: pitch slider


	if (HerculesMk4.scratchButton == 1) {
		var sign = (value == 0x01) ? 1 : -1;
		var newValue = HerculesMk4.knobIncrement(group, "pregain", 0