-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcontrol.pde
202 lines (179 loc) · 4.43 KB
/
control.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
void keyPressed() {
switch(key) {
case ' ': // pause/play toggle
if ( TRACK_LOADED ) {
if ( audio.isPlaying() ) {
sliderProgress.setValueLabel("PAUSED");
audio.pause();
closeMIDINotes();
} else {
sliderProgress.setValueLabel("PLAYING");
audio.play();
}
}
break;
case 'm': // mute audio toggle
if ( audio.isMuted() ) {
audio.unmute();
} else {
audio.mute();
}
break;
case 'n': // mute midi toggle
MIDI_TOGGLE = !MIDI_TOGGLE;
toggleMIDI.setState(MIDI_TOGGLE);
break;
case 'e': // turn equalizer on/off
LINEAR_EQ_TOGGLE = !LINEAR_EQ_TOGGLE;
toggleLinearEQ.setState(LINEAR_EQ_TOGGLE);
break;
case 'p': // turn PCP on/off
PCP_TOGGLE = !PCP_TOGGLE;
togglePCP.setState(PCP_TOGGLE);
break;
case 'h': // turn Harmonic filter on/off
HARMONICS_TOGGLE = !HARMONICS_TOGGLE;
toggleHarmonics.setState(HARMONICS_TOGGLE);
break;
// Octave Toggles
case '0':
OCTAVE_TOGGLE[0] = !OCTAVE_TOGGLE[0];
break;
case '1':
OCTAVE_TOGGLE[1] = !OCTAVE_TOGGLE[1];
break;
case '2':
OCTAVE_TOGGLE[2] = !OCTAVE_TOGGLE[2];
break;
case '3':
OCTAVE_TOGGLE[3] = !OCTAVE_TOGGLE[3];
break;
case '4':
OCTAVE_TOGGLE[4] = !OCTAVE_TOGGLE[4];
break;
case '5':
OCTAVE_TOGGLE[5] = !OCTAVE_TOGGLE[5];
break;
case '6':
OCTAVE_TOGGLE[6] = !OCTAVE_TOGGLE[6];
break;
case '7':
OCTAVE_TOGGLE[7] = !OCTAVE_TOGGLE[7];
break;
}
switch(keyCode) {
case RIGHT:
PEAK_THRESHOLD += 5;
sliderThreshold.setValue(PEAK_THRESHOLD);
break;
case LEFT:
PEAK_THRESHOLD -= 5;
sliderThreshold.setValue(PEAK_THRESHOLD);
break;
}
}
// ControlP5 events
void controlEvent(ControlEvent event) {
if ( event.isController() ) {
switch(event.controller().id()) {
case(1):
PEAK_THRESHOLD = (int)(event.controller().value());
break;
case(2):
break;
case(3): // Progress Slider
// This event is triggered whenever the slider is updated. It is a progress bar updated every buffer iteration.
cuePosition = (int)(event.controller().value());
if ( cuePosition < lastPosition || cuePosition - lastPosition > 2000 ) { // seeked backwards or forwards
audio.pause();
closeMIDINotes();
frameNumber = round((float)cuePosition / 1000f * (float)audio.sampleRate() / (float)bufferSize);
audio.cue(cuePosition);
audio.play();
}
lastPosition = cuePosition;
break;
}
// File List IDs
if ( event.controller().id() >= 100 ) {
openAudioFile(audioFiles[(int)event.controller().value()]);
}
}
}
void radioWeight(int type) {
WEIGHT_TYPE = type;
}
void radioMidiDevice(int device) {
midiOut = RWMidi.getOutputDevices()[device].createOutput();
}
void radioWindow(int mode) {
window.setMode(mode);
}
void radioSmooth(int mode) {
smoother.setMode(mode, SMOOTH_POINTS);
}
void togglePCP(boolean flag) {
PCP_TOGGLE = flag;
}
void toggleMIDI(boolean flag) {
MIDI_TOGGLE = flag;
if ( ! MIDI_TOGGLE ) {
closeMIDINotes();
}
}
void toggleLinearEQ(boolean flag) {
LINEAR_EQ_TOGGLE = flag;
}
void toggleHarmonics(boolean flag) {
HARMONICS_TOGGLE = flag;
}
void oct0(int channel) {
if (channel > 0) {
OCTAVE_CHANNEL[0] = channel -1;
}
}
void oct1(int channel) {
if (channel > 0) {
OCTAVE_CHANNEL[1] = channel -1;
}
}
void oct2(int channel) {
if (channel > 0) {
OCTAVE_CHANNEL[2] = channel -1;
}
}
void oct3(int channel) {
if (channel > 0) {
OCTAVE_CHANNEL[3] = channel -1;
}
}
void oct4(int channel) {
if (channel > 0) {
OCTAVE_CHANNEL[4] = channel -1;
}
}
void oct5(int channel) {
if (channel > 0) {
OCTAVE_CHANNEL[5] = channel -1;
}
}
void oct6(int channel) {
if (channel > 0) {
OCTAVE_CHANNEL[6] = channel -1;
}
}
void oct7(int channel) {
if (channel > 0) {
OCTAVE_CHANNEL[7] = channel -1;
}
}
void balance(int value) {
sliderBalance.setValueLabel(value + "%");
if ( value == 0 ) {
sliderBalance.setValueLabel(" CENTER");
} else if ( value < 0 ) {
sliderBalance.setValueLabel(value * -1 + "% LEFT");
} else if ( value > 0 ) {
sliderBalance.setValueLabel(value + "% RIGHT");
}
}