-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmidibus.pde
68 lines (61 loc) · 1.96 KB
/
midibus.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
import themidibus.*; MidiBus myBus;
int[] knob = {63 ,0 ,0 ,0 ,0 ,0 ,50 ,50};
int[] slider = {63 ,63 ,63 ,63 ,63 ,63 ,63 ,63};
int[] button = {0 ,0 ,0 ,0 ,0 ,0 ,0 ,0};
float valueMin;
float valueMax;
void midibusSetup(int min,int max){
myBus = new MidiBus(this, 0,1);
try { loadMidibus("midibus.txt"); }catch(Exception e){
saveMidibus("data/midibus.txt"); println("the file \"midibus.txt\" CREATED");
}
valueMin = min;
valueMax = max;
}
void controllerChange(int channel, int number, int value) {
if(number<=7) slider[number] = int(map(value,0,127,valueMin, valueMax));
if(number>=16 && number<=23) knob[number-16] = int(map(value,0,127,valueMin, valueMax)) ;
if(number>=32 && number<=39){ button[number-32] = 1 ; println("1"); }
if(number>=48 && number<=55){ button[number-48] = 0 ; println("0"); }
if(number>=64 && number<=71){ button[number-64] = -1 ; println("-1"); }
saveMidibus("data/midibus.txt");
println("___ "+value);
redraw();
}
void importMidibus(){
selectInput("Select a midibus file :", "import_midibusSelected");
}
void import_midibusSelected(File selection) {
if (selection != null)
loadMidibus( selection.getAbsolutePath() );
}
void exportMidibus(){
selectOutput("Name the midibus file :", "export_midibusSelected");
}
void export_midibusSelected(File selection) {
if (selection != null)
fileName = selection.getAbsolutePath();
saveMidibus( selection.getAbsolutePath()+".txt" );
isRecording = true;
redraw();
}
void saveMidibus(String name){
String str[] = new String[8];
for (int i = 0; i < 8; ++i) {
str[i] = knob[i] + " " ;
str[i] += slider[i] + " " ;
str[i] += button[i] + "" ;
}
saveStrings(name, str);
}
void loadMidibus(String name){
String str[] = loadStrings(name);
for (int i = 0; i < 8; ++i) {
println("str[i]: "+str[i]);
String tmp[] = split(str[i]," ");
knob[i] = int(tmp[0]) ;
slider[i] = int(tmp[1]) ;
button[i] = int(tmp[2]) ;
}
redraw();
}