-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProcessing2SonicPi.pde
146 lines (132 loc) · 3.63 KB
/
Processing2SonicPi.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
//-----------------------------------------------------------------------------
//作成日: 2019/07/13
//修正日: 2019/10/18
//-----------------------------------------------------------------------------
//OSC
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress location;
//ControlP5
import controlP5.*;
ControlP5 cp5;
Println console;
String[] cp5MSG={"MUSICNUM", "VOLUME", "OCTAVE", "TIME"};
ShowInfo info;
void setup() {
size(960, 540, P3D);
frameRate(60);
//osc
oscP5 = new OscP5(this, 8000);
location = new NetAddress("", 4559);
//font
PFont font = createFont("consolas", 32);
PFont fontMsg=createFont("consolas", 24);
textFont(fontMsg);
info=new ShowInfo(24);
//cp5
cp5 = new ControlP5(this);
cp5.setColorBackground(color(0, 102, 0, 160));
cp5.setColorForeground(color(107, 142, 35));
cp5.setColorActive(color(100, 255, 35, 180));
int btnSize=100;
//MUSICNUM,VOLUME,OCTAVE,TIME Buton
for (int y=0; y<cp5MSG.length; y++) {
PVector pos=new PVector(100+btnSize*3*(y%2), 100+btnSize*(y/2));
cp5.addTextlabel(cp5MSG[y])
.setText(cp5MSG[y])
.setPosition(pos.x+btnSize*1.5/2, pos.y-25)
.setColorValue(255)
.setFont(fontMsg)
;
for (int x=0; x<2; x++) {
pos=new PVector(100+btnSize*3*(y%2), 100+btnSize*(y/2));
cp5.addBang(cp5MSG[y]+(x==0?"-":"+"))
.setLabel(x==0?"←":"→")
.setPosition(pos.x+btnSize*x*1.25, pos.y)
.setSize(btnSize, btnSize/2)
.setFont(font)
.align(CENTER, CENTER, CENTER, CENTER);
}
}
//PlayButon
cp5.addToggle("PLAY")
.setPosition(width-250+25, 100)
.setLabel("PLAY")
.setSize(100, 100)
.setFont(font)
.align(CENTER, CENTER, CENTER, CENTER);
//resetButon
cp5.addBang("RESET")
.setPosition(width-250+25, 225)
.setSize(100, 25)
.setFont(fontMsg)
.align(CENTER, CENTER, CENTER, CENTER);
//MessageBox
console=cp5.addConsole(cp5.addTextarea("Message")
.setPosition(50, height/2+50)
.setSize(width-50-250, height/2-100)
.setFont(fontMsg)
.setLineHeight(20)
.setColor(color(222))
.setColorBackground(color(0, 102, 0, 160))
.setColorForeground(color(255, 100))
);
//ClearButon
cp5.addBang("CLEAR")
.setPosition(width-250, height/2+50)
.setSize(200, height/2-100)
.setFont(font)
.align(CENTER, CENTER, CENTER, CENTER);
}
void draw() {
background(0, 50, 0);
info.update();
}
void CLEAR() {
console.clear();
}
void writemsg(String s) {
//year/month/day hour:minute:second
String time=String.format("%d/%02d/%02d %02d:%02d:%02d\t", year(), month(), day(), hour(), minute(), second());
println(time+s);
}
void sendMessage(String... s) {
OscMessage msg = new OscMessage(s[0]);
for (String str : s) {
if (!str.equals(s[0])) {
msg.add(str);
}
}
oscP5.send(msg, location);
writemsg("/osc/"+s[0]+" "+s[1]);
}
void sendMessage(String s, float i) {
OscMessage msg = new OscMessage(s);
msg.add(i);
oscP5.send(msg, location);
writemsg("/osc/"+s+" "+i);
}
void PLAY(boolean state) {
sendMessage("FLAG", state?"START":"STOP");
}
void RESET() {
getController("PLAY").setValue(0);
sendMessage("FLAG", "RESET");
}
void controlEvent(ControlEvent theEvent) {
if (theEvent.isAssignableFrom(Bang.class)) {
for (int i=0; i<cp5MSG.length; i++) {
String m=theEvent.getName();
float n=0;
if (cp5MSG[i].equals(m.substring(0, m.length()-1))) {
n=("-".equals(m.substring(m.length()-1)))?-1:1;
n=("TIME".equals(cp5MSG[i]))?n/4:n;
sendMessage(cp5MSG[i].toString(), n);
}
}
}
}
Controller getController(String name) {
return cp5.getController(name);
}