-
Notifications
You must be signed in to change notification settings - Fork 0
/
cdj_1000_midi_mk3.ino
346 lines (306 loc) · 7.38 KB
/
cdj_1000_midi_mk3.ino
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
#define ENCODER_OPTIMIZE_INTERRUPTS
#include <Encoder.h>
#include <ResponsiveAnalogRead.h>
Encoder wheel(31, 32);
ResponsiveAnalogRead analogpitch(A9, true);
int bttndel=1;
int winc = 63;
int wdec = 65;
long wheelpos = -999;
int wheelmove = 0;
int jogflag = 0;
int speedad = 0;
int avgspeed = 0;
int totspeed = 0;
long vel = 0;
unsigned long newtime;
unsigned long oldtime = 0;
int veldelay = 60;
int channel = 1;
int loopinled=35;
int loopinb=34;
int loopoutb=33;
int loopoutled=15;
int hotcueared=55;
int hotcueagreen=54;
int hotcueayellow=56;
int hcab=57;
int hotcuebred=52;
int hotcuebgreen=51;
int hotcuebyellow=50;
int hcbb=53;
int hotcuecred=45;
int hotcuecgreen=46;
int hotcuecyellow=44;
int hccb=43;
int recb=38;
int cdjmodeled=5;
int vinylmodeled=6;
int modeb=4;
int playled=28;
int playb=29;
int jogpressb=30;
int cueled=26;
int cueb=27;
int temporangeb=8;
int mastertempob=9;
int mastertempoled=7;
int trackbb=11;
int trackfb=10;
int scanbb=24;
int scanfb=12;
int pitch=39;
long pitchval=0;
long oldpitchval=0;
int loopexitb=17;
int loopexitled=16;
int wavbb=19;
int wavfb=18;
int callbb=20;
int callforb=21;
int delbtn=2;
int membtn=3;
int timebtn=37;
int txtbtn=36;
int revled=25;
int revbtn=42;
int ejectbtn=22;
int buttons[30] = {loopinb,loopoutb,hcab,hcbb,hccb,recb,modeb,playb,jogpressb,cueb,temporangeb,mastertempob,trackbb,trackfb,scanbb,scanfb,loopexitb,wavbb,wavfb,callbb,callforb,revbtn,delbtn,membtn,timebtn,txtbtn,loopexitb,modeb,ejectbtn};
int leds[30] = {loopinled,loopoutled,hotcueagreen,hotcuebgreen,hotcuecgreen,0,cdjmodeled,playled,0,cueled,0,mastertempoled,0,0,0,0,0,0,0,0,0,revled,0,0,0,0,loopexitled,0,0};
int buttonstat[57] ={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int jogmode = 10;
int loopint = 22;
int led = 13;
int statOn = 60;
void OnNoteOn(byte channel, byte statOn, byte velocity)
{
switch(statOn){
case 5:
digitalWrite(cdjmodeled, HIGH);
case 6:
digitalWrite(vinylmodeled, HIGH);
case 9:
digitalWrite(mastertempoled, HIGH);
break;
case 17:
digitalWrite(loopexitled, HIGH);
break;
case 27:
digitalWrite(cueled, HIGH);
break;
case 29:
digitalWrite(playled, HIGH);
break;
case 33:
digitalWrite(loopoutled, HIGH);
break;
case 34:
digitalWrite(loopinled, HIGH);
break;
case 42:
digitalWrite(revled, HIGH);
break;
case 43:
if (velocity==21){
digitalWrite(hotcuecgreen,HIGH);
digitalWrite(hotcuecred,LOW);
}
if (velocity==105){
digitalWrite(hotcuecgreen,LOW);
digitalWrite(hotcuecred,HIGH);
}
if (velocity==127){
digitalWrite(hotcuecgreen,HIGH);
digitalWrite(hotcuecred,HIGH);
}
break;
case 53:
if (velocity==21){
digitalWrite(hotcuebgreen,HIGH);
digitalWrite(hotcuebred,LOW);
}
if (velocity==105){
digitalWrite(hotcuebgreen,LOW);
digitalWrite(hotcuebred,HIGH);
}
if (velocity==127){
digitalWrite(hotcuebgreen,HIGH);
digitalWrite(hotcuebred,HIGH);
}
break;
case 57:
if (velocity==21){
digitalWrite(hotcueagreen,HIGH);
digitalWrite(hotcueared,LOW);
}
if (velocity==105){
digitalWrite(hotcueagreen,LOW);
digitalWrite(hotcueared,HIGH);
}
if (velocity==127){
digitalWrite(hotcueagreen,HIGH);
digitalWrite(hotcueared,HIGH);
}
break;
}
}
void OnNoteOff(byte channel, byte statOn, byte velocity)
{
switch(statOn){
case 5:
digitalWrite(cdjmodeled, LOW);
case 6:
digitalWrite(vinylmodeled, LOW);
case 9:
digitalWrite(mastertempoled, LOW);
break;
case 17:
digitalWrite(loopexitled, LOW);
break;
case 27:
digitalWrite(cueled, LOW);
break;
case 29:
digitalWrite(playled, LOW);
break;
case 33:
digitalWrite(loopoutled, LOW);
break;
case 34:
digitalWrite(loopinled, LOW);
break;
case 42:
digitalWrite(revled, LOW);
break;
case 43:
digitalWrite(hotcuecgreen,LOW);
digitalWrite(hotcuecred,LOW);
break;
case 53:
digitalWrite(hotcuebgreen,LOW);
digitalWrite(hotcuebred,LOW);
break;
case 57:
digitalWrite(hotcueagreen,LOW);
digitalWrite(hotcueared,LOW);
break;
}
}
// the setup routine runs once when you press reset:
void setup() {
usbMIDI.setHandleNoteOff(OnNoteOff);
usbMIDI.setHandleNoteOn(OnNoteOn) ;
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
pinMode(13, OUTPUT);
//pinMode(14, OUTPUT);
pinMode(15, OUTPUT);
pinMode(16, OUTPUT);
pinMode(17, INPUT_PULLUP);
pinMode(18, INPUT_PULLUP);
pinMode(19, INPUT_PULLUP);
pinMode(20, INPUT_PULLUP);
pinMode(21, INPUT_PULLUP);
pinMode(22, INPUT_PULLUP);
//pinMode(23, OUTPUT);
pinMode(24, INPUT_PULLUP);
pinMode(25, OUTPUT);
pinMode(26, OUTPUT);
pinMode(27, INPUT_PULLUP);
pinMode(28, OUTPUT);
pinMode(29, INPUT_PULLUP);
pinMode(30, INPUT_PULLUP);
//pinMode(31, OUTPUT);
//pinMode(32, INPUT_PULLUP);
pinMode(33, INPUT_PULLUP);
pinMode(34, INPUT_PULLUP);
pinMode(35, OUTPUT);
pinMode(36, INPUT_PULLUP);
pinMode(37, INPUT_PULLUP);
pinMode(38, INPUT);
//pinMode(39, INPUT_PULLUP);
//pinMode(40, INPUT_PULLUP);
//pinMode(41, INPUT_PULLUP);
pinMode(42, INPUT_PULLUP);
pinMode(43, INPUT_PULLUP);
pinMode(44, OUTPUT);
pinMode(45, OUTPUT);
pinMode(46, OUTPUT);
//pinMode(47, INPUT_PULLUP);
//pinMode(48, INPUT_PULLUP);
//pinMode(49, INPUT_PULLUP);
pinMode(50, OUTPUT);
pinMode(51, OUTPUT);
pinMode(52, OUTPUT);
pinMode(53, INPUT_PULLUP);
pinMode(54, OUTPUT);
pinMode(55, OUTPUT);
pinMode(56, OUTPUT);
pinMode(57, INPUT_PULLUP);
digitalWrite(13, HIGH);
jogmode = 10;
}
// the loop routine runs over and over again forever:
void loop() {
usbMIDI.read();
analogpitch.update();
long newwheel;
newtime = millis();
newwheel = wheel.read();
wheelmove = 0;
vel = 0;
if (newwheel > wheelpos) {
vel = ((newwheel - wheelpos) / (newtime - oldtime)) *2 ;
if (vel>60) vel =60;
if (vel <=0 ) vel = 0;
if (buttonstat[8]==1){
usbMIDI.sendControlChange(0, 127-vel, channel);
} else {
usbMIDI.sendControlChange(0, 127, channel);
}
wheelpos = newwheel;
}
if (newwheel < wheelpos) {
vel = ((wheelpos - newwheel) / (newtime - oldtime)) * 2;
if (vel>60) vel =60;
if (vel <=0 ) vel = 0;
if (buttonstat[8]==1){
usbMIDI.sendControlChange(0, 1+vel, channel);
} else {
usbMIDI.sendControlChange(0, 1, channel);
}
wheelpos = newwheel;
}
oldtime = newtime;
for (int x=0;x<29;x++){
if (digitalRead(buttons[x])==LOW){
if (buttonstat[x]==0){
buttonstat[x]=1;
usbMIDI.sendNoteOn(buttons[x], 99, channel);
delay(bttndel);
}
} else {
if (buttonstat[x]==1){
usbMIDI.sendNoteOff(buttons[x], 0, channel);
buttonstat[x]=0;
delay(bttndel);
}
}
}
if(analogpitch.hasChanged()) {
pitchval=analogpitch.getValue()*16.015;
//Serial.println(pitchval);
usbMIDI.sendPitchBend(pitchval, channel);
}
usbMIDI.send_now();
delay(1);
}