forked from cjkcjk01/GiantSpaceRobotVisualiser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Midi.pde
329 lines (286 loc) · 8.2 KB
/
Midi.pde
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
// Handles midi messages, currently we are only using CC values, but the methods are here for //<>//
// note on and off in case they are needed at some stage.
// It then uses Java's reflection techniques (https://www.oracle.com/technical-resources/articles/java/javareflection.html)
// to call a method for each individual message that is received
void noteOn(int channel, int pitch, int velocity, long timestamp, String busName) {
//println("Note On : Channel = " + channel + " Pitch = " + pitch + " Vel = "+ velocity + " bus name = " + busName);
}
void noteOff(int channel, int pitch, int velocity, long timestamp, String busName) {
//println("Note Off : Channel = " + channel + " Pitch = " + pitch + " Vel = "+ velocity + " bus name = " + busName);
}
void controllerChange(int channel, int number, int value, long timestamp, String busName) {
int functionKey;
String functionName;
MidiControl midiControl;
//println("Control Change: Channel = " + channel + " CC" + number + " Value = "+value + " bus name = " + busName);
if (!midiControls.exists(busName, channel, number)) {
MidiControl c = new MidiControl(busName, channel, number, value);
midiControls.addControl(c);
}
midiControl = midiControls.get(busName, channel, number);
midiControl.value = value;
// make the key to retrive the midi function name from the hashmap
functionKey = (channel * 100) + number;
// Retrive the function name from the HashMap of midi functions
functionName = midiFunctions.get(functionKey);
if (functionName == null) {
println("Function for Midi Value " + functionKey + " not found");
return;
}
// use Java Reflection technique to call the required function
// https://www.baeldung.com/java-reflection has a good explanation of this approach
try {
Class[] cls = new Class[1];
cls[0] = int.class;
Method handler = this.getClass().getMethod( functionName, cls );
handler.invoke(this, value);
}
catch (Exception e) {
println("Midi error in control change : number = " + number + ", value = " + value );
e.printStackTrace();
}
}
// *****************************************
// * Hotcues & deck specific settings
// *****************************************
// Deck volume faders
void setVolumeDeckA(int value) {
deckA.setVolume(value);
}
void setVolumeDeckB(int value) {
deckB.setVolume(value);
}
void setVolumeDeckC(int value) {
deckC.setVolume(value);
}
void setVolumeDeckD(int value) {
deckD.setVolume(value);
}
// Deck play status
void setIsPlayingDeckA(int value) {
if (value == 127) {
deckA.setIsPlaying(true);
} else {
deckA.setIsPlaying(false);
}
}
void setIsPlayingDeckB(int value) {
if (value == 127) {
deckB.setIsPlaying(true);
} else {
deckB.setIsPlaying(false);
}
}
void setIsPlayingDeckC(int value) {
if (value == 127) {
deckC.setIsPlaying(true);
} else {
deckC.setIsPlaying(false);
}
}
void setIsPlayingDeckD(int value) {
if (value == 127) {
deckD.setIsPlaying(true);
} else {
deckD.setIsPlaying(false);
}
}
// Hotcues for Decks
void readyHotCueDeckA(int value) {
if (value > 0) {
deckA.readyHotcue(value);
}
}
void readyHotCueDeckB(int value) {
if (value > 0) {
deckA.readyHotcue(value);
}
}
void readyHotCueDeckC(int value) {
if (value > 0) {
deckA.readyHotcue(value);
}
}
void readyHotCueDeckD(int value) {
if (value > 0) {
deckA.readyHotcue(value);
}
}
//select hotcue packs
void setHotCuePackA(int value) {
if (value > 0) {
deckA.setPack(value);
}
}
void setHotCuePackB(int value) {
if (value > 0) {
deckB.setPack(value);
}
}
void setHotCuePackC(int value) {
if (value > 0) {
deckC.setPack(value);
}
}
void setHotCuePackD(int value) {
if (value > 0) {
deckD.setPack(value);
}
}
void hotCueClearCueInfo(int Value) {
cueInfo.clearText();
}
// ********************************************
// * respond to effects being used in Traktor *
// ********************************************
// Set the degree of blur based on the Traktor filter knob
void setFilterA(int value) {
deckA.setFilter(value);
}
void setFilterB(int value) {
deckB.setFilter(value);
}
void setFilterC(int value) {
deckC.setFilter(value);
}
void setFilterD(int value) {
deckD.setFilter(value);
}
// Shader to visualise the delay(echo) effect
void setDelayStatus(int value) {
if (value > 100) {
delayOn = true;
} else if (value == 0) {
delayOn = false;
}
}
// Shader to visualise the gate/slice/mash effect
void setGlitchStatus(int value) {
if (value > 100) {
sliceOn = true;
} else if (value == 0) {
sliceOn = false;
}
}
// ********************************************
// * Visualiser settings *
// ********************************************
// Cue up the next main visualiser
void cueVisualiser(int value) {
visualisers.cueVisualiserByMidi(value);
}
// Select the main visualiser
void selectVisualiser(int value) {
visualisers.setVisualiser(value);
}
// Sends a value from the browse knob to the current visualiser
void setVisualiserKnobValue(int value) {
visualisers.setKnob1(value);
}
// set the scaling for the fft analysis, which is it's sensitivity to volume
void setVisualiserScalingValue(int value) {
visualisers.setScaling(value);
}
// Button1 for visualiser
void toggleVisualiserButton1(int value) {
if (value > 100) {
visualisers.toggleButton1();
}
}
// Button2 for visualiser
void toggleVisualiserButton2(int value) {
if (value > 100) {
visualisers.toggleButton2();
}
}
// Fader1 for visualiser
void setVisualiserFader1(int value) {
visualisers.setFader1(value);
}
// Fader2 for visualiser
void setVisualiserFader2(int value) {
visualisers.setFader2(value);
}
// Toggle the waveform visualiser
void toggleWaveform(int value) {
waveformOn = !waveformOn;
}
// set the scaling for the waveform visualiser, which is it's sensitivity to volume
void setWaveformScale(int value) {
visWaveform.scale(value);
}
// Toggle the kaleidoscope shader
void toggleKaleidoscope(int value) {
kaleidoscopeOn = !kaleidoscopeOn;
}
void setKaleidoscopeRotation(int value) {
shaderKaleidoscope.setRotation(value);
}
void setKaleidoscopeViewAngle(int value) {
shaderKaleidoscope.setViewAngle(value);
}
// set the alpha value for the beat text
void setBeatTextAlpha(int value) {
beatWords.setAlpha(value);
}
//************************************************
// Background colour and word display settings
//************************************************
// carry out any actions that happen when a beat is detected
void triggerBeatActions(int value) {
if (value > 120) {
myBgPalette.incColor(); // Increments the background color on each beat,
beatWords.nextWord(); // Draws the next word in the wordlist
visualisers.onBeatAction(); // Triggers any beat related actins in the current visualiser
// Calculate the duration between beats
float currentTime = millis();
beatTimes[currentIndex] = currentTime;
currentIndex = (currentIndex + 1) % beatTimes.length;
int sum = 0;
int count = 0;
for (int i = 0; i < beatTimes.length; i++) {
if (beatTimes[i] > 0) {
sum += currentTime - beatTimes[i];
count++;
}
}
if (count > 0) {
beatDuration = sum / count;
}
}
}
// Toggle the beat sync (change background color on each beat)
void toggleBackgroundBeatSync(int value) {
if (value > 100) {
myBgPalette.toggle();
}
}
// Toggle black or white background
void toggleBlackOrWhiteBackground(int value) {
if (value > 100) {
myBgPalette.toggleBlackOrWhite();
}
}
// toggle the word display and set the list of words to use
void toggleWordDisplay(int value) {
beatWords.setCurrentPack(value);
}
//*************************************
// Post processing shader selection
//*************************************
// select the shader to use
void selectPostShader(int value) {
VisShaders.setShader(value);
}
// toggle the post processing shaders
void togglePostShader(int value) {
VisShaders.toggleVisShaders();
}
// change the first parameter of the post processing shader
void setPostShaderValue1(int value) {
VisShaders.setX(value);
}
// change the second parameter of the post processing shader
void setPostShaderValue2(int value) {
VisShaders.setY(value);
}