-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTouchOSC-iPad-scripts.js
270 lines (225 loc) · 8.63 KB
/
TouchOSC-iPad-scripts.js
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
//Please report bugs at https://github.com/rajbot/mixxx_touchosc_mapping
TouchOSC = new function() {
}
TouchOSC.button_state = {"released":0x00, "pressed":0x7F};
TouchOSC.push_buttons = {
0x02: 'beatsync',
0x03: 'cue_default',
0x08: 'cue_default',
0x09: 'beatsync',
0x39: 'filterLowKill',
0x3A: 'filterMidKill',
0x3B: 'filterHighKill',
0x44: 'filterLowKill',
0x45: 'filterMidKill',
0x46: 'filterHighKill',
}
TouchOSC.leds = {
'[Channel1]': {'play': 0x04,
'cue_mode': 0x0C, },
'[Channel2]': {'play': 0x07,
'cue_mode': 0x16, },
}
TouchOSC.global_timer = null;
TouchOSC.cue_mode = {'[Channel1]': 'goto', '[Channel2]': 'goto'};
TouchOSC.jog_mode = {'[Channel1]': 'jog', '[Channel2]': 'jog'};
// init()
//________________________________________________________________________________________
TouchOSC.init = function(id) {
midi.sendShortMsg(0xB1, 0x04, 0x00); //Turn off the Deck 1 Play LED
midi.sendShortMsg(0xB1, 0x07, 0x00); //Turn off the Deck 2 Play LED
midi.sendShortMsg(0xB1, 0x1B, 0x00); //Deck 1 browse led
midi.sendShortMsg(0xB1, 0x24, 0x00); //Deck 2 browse led
['[Channel1]', '[Channel2]'].forEach(function(channel) {
['volume', 'play'].forEach(function(control) {
engine.connectControl(channel, control, 'TouchOSC.'+control+'_status');
engine.trigger(channel, control); //play status led not updating
});
});
engine.connectControl('[Master]', 'crossfader', 'TouchOSC.crossfader_status');
}
// play()
//________________________________________________________________________________________
TouchOSC.play = function(channel, control, value, status, group) {
//play_status will be called to turn/off the LEDs
if (value == TouchOSC.button_state.pressed) {
var currently_playing = engine.getValue(group, 'play');
if (currently_playing ) {
engine.setValue(group, 'play', 0); //stop
} else {
engine.setValue(group, 'play', 1); //play
}
}
};
// play_status()
//________________________________________________________________________________________
TouchOSC.play_status = function(value, group, control) {
var currently_playing = engine.getValue(group, 'play');
if (currently_playing ) {
midi.sendShortMsg(0xB1, TouchOSC.leds[group][control], 0x7F);
} else {
midi.sendShortMsg(0xB1, TouchOSC.leds[group][control], 0x0);
}
}
// volume_status()
//________________________________________________________________________________________
TouchOSC.volume_status = function(value, group, control) {
var num;
if ('[Channel1]' == group) {
num = 0x25;
} else {
num = 0x2A;
}
midi.sendShortMsg(0xB0, num, 127*value);
}
// crossfader_status()
//________________________________________________________________________________________
TouchOSC.crossfader_status = function(value, group, control) {
midi.sendShortMsg(0xB0, 0x11, 64*value+64);
}
// jog()
//________________________________________________________________________________________
TouchOSC.jog = function(channel, control, value, status, group) {
if(TouchOSC.jog_mode[group] == 'browse') {
if (0 == value) {
engine.setValue('[Playlist]', 'SelectPrevTrack', true);
} else {
engine.setValue('[Playlist]', 'SelectNextTrack', true);
}
return;
}
var jog_dir;
var action;
var currently_playing = engine.getValue(group, 'play');
if (currently_playing) {
if (0 == value) {
action = 'rate_temp_down';
} else {
action = 'rate_temp_up';
}
jog_dir = true;
if (null == TouchOSC.global_timer) {
TouchOSC.global_timer = engine.beginTimer(200, "TouchOSC.jog_disable('" + group + "')", true); //one shot
} else {
//print("timer already set, not adjusting rate");
return;
}
} else {
action = 'jog';
if (0 == value) {
jog_dir = -1;
} else {
jog_dir = 1;
}
}
//print(action);
engine.setValue(group, action , jog_dir);
}
// jog_disable()
//________________________________________________________________________________________
TouchOSC.jog_disable = function(group) {
//print("jog_disable: "+group);
TouchOSC.global_timer = null;
engine.setValue(group,'rate_temp_down',false);
engine.setValue(group,'rate_temp_up',false);
}
// toggle_jog_mode()
//________________________________________________________________________________________
TouchOSC.toggle_jog_mode = function(channel, control, value, status, group) {
if (value != TouchOSC.button_state.pressed) return;
var led;
if ('[Channel1]' == group) {
led = 0x1B;
} else {
led = 0x24;
}
//when toggle_jog_mode is called, `this` does not refer to an instance of a TouchOSC object,
//so we can't use `this.jog_mode` to store state.. hmm
if (TouchOSC.jog_mode[group] == 'jog') {
TouchOSC.jog_mode[group] = 'browse';
midi.sendShortMsg(0xB1, led, 0x7F);
} else {
TouchOSC.jog_mode[group] = 'jog';
midi.sendShortMsg(0xB1, led, 0);
}
};
// load_track()
//________________________________________________________________________________________
TouchOSC.load_track = function(channel, control, value, status, group) {
engine.setValue(group, "LoadSelectedTrack", 1);
if (TouchOSC.jog_mode[group] == 'browse') {
TouchOSC.toggle_jog_mode(channel, control, value, status, group);
}
}
// cue()
//________________________________________________________________________________________
TouchOSC.cue = function(channel, control, value, status, group) {
//I couldn't get cue_default to work with a script binding..
if (value == TouchOSC.button_state.pressed) {
engine.setValue(group, "cue_default", 1);
engine.setValue(group, "cue_default", 0); //turn off the cue light in the Mixxx UI
}
};
// push_button()
//________________________________________________________________________________________
TouchOSC.push_button = function(channel, control, value, status, group) {
//I couldn't get cue, beatsync, or filterkill buttons to work without a script binding..
//The button will be lit in the Mixxx UI when the button is held down (value==0x7F)
//and then unlit when the button is released (value==0x00)
var action = TouchOSC.push_buttons[control];
engine.setValue(group, action, (0!=value));
};
// play_position()
//________________________________________________________________________________________
TouchOSC.play_position = function(channel, control, value, status, group) {
//don't scrub the currently-playing track, in order to avoid accidental input
var currently_playing = engine.getValue(group, 'play');
if (currently_playing) {
return;
}
var pos_val = 1.14 / 127 * value;
engine.setValue(group, 'playposition', pos_val);
};
// toggle_cue_mode()
//________________________________________________________________________________________
TouchOSC.toggle_cue_mode = function(channel, control, value, status, group) {
if (value != TouchOSC.button_state.pressed) return;
//when toggle_cue_mode is called, `this` does not refer to an instance of a TouchOSC object,
//so we can't use `this.cue_mode` to store state.. hmm
if (TouchOSC.cue_mode[group] == 'goto') {
TouchOSC.cue_mode[group] = 'set';
midi.sendShortMsg(0xB1, control, 0x7F);
} else {
TouchOSC.cue_mode[group] = 'goto';
midi.sendShortMsg(0xB1, control, 0);
}
};
// hot_cue()
//________________________________________________________________________________________
TouchOSC.hot_cue = function(channel, control, value, status, group) {
if (value != TouchOSC.button_state.pressed) return;
var que_mode = TouchOSC.cue_mode[group];
print (value);
if (control <= 0x10) {
var cue_num = control - 0x0C;
} else {
var cue_num = -(control - 0x16);
}
var enabled = engine.getValue(group, 'hotcue_'+cue_num+'_enabled');
if ('set' == que_mode) {
if (enabled) {
engine.setValue(group, 'hotcue_'+cue_num+'_clear', 1);
midi.sendShortMsg(0xB1, control, 0);
} else {
engine.setValue(group, 'hotcue_'+cue_num+'_set', 1);
midi.sendShortMsg(0xB1, control, 0x7F);
}
} else {
if (enabled) {
engine.setValue(group, 'hotcue_'+cue_num+'_goto', 1);
} else {
engine.setValue(group, 'hotcue_'+cue_num+'_set', 1);
midi.sendShortMsg(0xB1, control, 0x7F);
}
}
};