-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMidiFunctions.pde
77 lines (65 loc) · 1.89 KB
/
MidiFunctions.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
import themidibus.*;
MidiBus controller;
String midiName = "Launch Control";
final Knob[] knobs = new Knob[16];
final boolean[] pads = new boolean[8];
void midiSetup(){
for(String s : MidiBus.availableInputs()){
if(s.equals(midiName)){
controller = new MidiBus(this, midiName, midiName);
break;
}else{
println("Please connect Launchpad.");
}
}
for(int i = 0; i < knobs.length; i++){
knobs[i] = new Knob();
//knobs[i].softValue(int(random(1.0) * 127));
}
for(int i = 0; i < pads.length; i++){
pads[i] = true;
}
// set the knobs' default values-- this code should ideally go with the Envelope logic...
knobs[0].softValue(126); // gain 1
knobs[1].softValue(20); // cutoff 1
knobs[2].softValue(100); // gain 2
knobs[3].softValue(70); // cutoff 2
knobs[4].softValue(112); // gain 3
knobs[5].softValue(70); // cutoff 3
knobs[6].softValue(105); // spring constant
knobs[7].softValue(3); // damping constant
knobs[8].softValue(35); // width 1
knobs[9].softValue(50); // center 1
knobs[10].softValue(3); // width 2
knobs[11].softValue(3); // center 2
knobs[12].softValue(15); // width 3
knobs[13].softValue(20); // center 3
}
void controllerChange(int chan, int num, int val){
//everything should be coming in on channel 1
int index = num & 0x7;
switch(num >> 3 & 0x3){
case 1: pads[index] = !pads[index]; break;
case 2: knobs[index + 8].hardValue(val); break;
case 3: knobs[index].hardValue(val); break;
default: println("unknown cc"); break;
}
}
class Knob{
boolean restored = true;
int value;
void softValue(int val){
value = val;
//restored = false;
}
void hardValue(int val){
if(!restored){
if(val == value){
restored = true;
}else{
return;
}
}
value = val;
}
}