-
Notifications
You must be signed in to change notification settings - Fork 0
/
kagura_midi.pde
344 lines (285 loc) · 7.94 KB
/
kagura_midi.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
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
import themidibus.*; //Import the library
MidiBus myBus; // The MidiBus
// Global Variable
PFont sans;
PImage title;
PImage go;
PImage mamonaku;
PImage result;
// init counter
int counter1 = 0;
int counter2 = 0;
int counter3 = 0;
int counter4 = 0;
// init velocity value
int velo1 = 0;
int velo2 = 0;
int velo3 = 0;
int velo4 = 0;
// init velocity value
int tmpvelo1 = 0;
int tmpvelo2 = 0;
int tmpvelo3 = 0;
int tmpvelo4 = 0;
// init sum
float sum = 0;
// init ratio
float ratio1 = 0.25;
float ratio2 = 0.25;
float ratio3 = 0.25;
float ratio4 = 0.25;
// init rect startpoint
float start = 0;
// init timecounter
int timecounter = 0;
// init midi variable
int channel = 0;
int pitch = 64;
int velocity = 127;
// init winner flag
int winner = 0;
// init scene
int scene = 0;
// init resul tcount
int counter1Result = 0;
int counter2Result = 0;
int counter3Result = 0;
int counter4Result = 0;
// init result ratio
float ratio1Result = 0.25;
float ratio2Result = 0.25;
float ratio3Result = 0.25;
float ratio4Result = 0.25;
//init inplayflag
int inplay =0;
void setup() {
fullScreen();
sans = loadFont("ProcessingSansPro-Regular-48.vlw");
title = loadImage("title.png");
go = loadImage("go.png");
mamonaku = loadImage("mamonaku.png");
result = loadImage("result.png");
MidiBus.list(); // List all available Midi devices on STDOUT. This will show each device's index and name.
myBus = new MidiBus(this, "loopMIDI Port", "loopMIDI Port"); // Create a new MidiBus with no input device and the default Java Sound Synthesizer as the output device.
frameRate(60);
}
void draw() {
// myBus.sendNoteOn(channel, pitch, velocity); // Send a Midi noteOn
// delay(200);
// myBus.sendNoteOff(channel, pitch, velocity); // Send a Midi nodeOff
// int number = 0;
// int value = 90;
// myBus.sendControllerChange(4, 1, 100); // Send a controllerChange
// delay(2000);
background(0,0,0);
// timecounter countup
timecounter++;
// calc wariai
if( counter1 > 0 || counter2 > 0 || counter3 > 0 || counter4 > 0){
sum = counter1 + counter2 + counter3 + counter4;
ratio1 = counter1 / sum;
ratio2 = counter2 / sum;
ratio3 = counter3 / sum;
ratio4 = counter4 / sum;
}
// calc move velocity
if ( timecounter == 0 ){
tmpvelo1 = counter1;
tmpvelo2 = counter2;
tmpvelo3 = counter3;
tmpvelo4 = counter4;
}
if ( timecounter == 60 ) {
velo1 = counter1 - tmpvelo1;
velo2 = counter2 - tmpvelo2;
velo3 = counter3 - tmpvelo3;
velo4 = counter4 - tmpvelo4;
timecounter = 0;
tmpvelo1 = counter1;
tmpvelo2 = counter2;
tmpvelo3 = counter3;
tmpvelo4 = counter4;
}
switch (scene){
case 0:
showWait();
break;
case 1:
showPlay();
inplay = 1;
break;
case 2:
if (inplay==1){
counter1Result = counter1;
counter2Result = counter2;
counter3Result = counter3;
counter4Result = counter4;
sum = counter1Result + counter2Result + counter3Result + counter4Result;
ratio1Result = counter1Result / sum;
ratio2Result = counter2Result / sum;
ratio3Result = counter3Result / sum;
ratio4Result = counter4Result / sum;
inplay = 0;
}
showResultRatio(); //<>//
break;
case 3:
showResult();
break;
default:
showWait();
break;
}
//// change kagura scene
//switch(counterRed){
// case 100:
// myBus.sendControllerChange(3, 1, 100); // Send a controllerChange
// break;
// default:
// break;
//}
//// change kagura scene
//switch(counterBlue){
// case 100:
// myBus.sendControllerChange(4, 1, 100); // Send a controllerChange
// break;
// default:
// break;
//}
// stdout
//println("--------");
//println("ratioRed:"+ratioRed);
//println("rationBlue:"+ratioBlue);
//println("sum:"+sum);
}
void noteOn(int channel, int pitch, int velocity) {
// Receive a noteOn
println();
println("Note On:");
println("--------");
println("Channel:"+channel);
println("Pitch:"+pitch);
println("Velocity:"+velocity);
switch (channel){
case 0:
counter1++;
break;
case 1:
counter2++;
break;
case 2:
counter3++;
break;
case 3:
counter4++;
break;
default:
}
}
void noteOff(int channel, int pitch, int velocity) {
// Receive a noteOff
println();
println("Note Off:");
println("--------");
println("Channel:"+channel);
println("Pitch:"+pitch);
println("Velocity:"+velocity);
}
void controllerChange(int channel, int number, int value) {
// Receive a controllerChange
//println();
//println("Controller Change:");
//println("--------");
//println("Channel:"+channel);
//println("Number:"+number);
//println("Value:"+value);
}
void delay(int time) {
int current = millis();
while (millis () < current+time) Thread.yield();
}
void showPlay() {
fill(83,109,254);
noStroke();
rect(0, 0, ratio1*displayWidth, displayHeight);
fill(0,150,136);
noStroke();
rect(ratio1*displayWidth, 0, ratio2*displayWidth, displayHeight);
fill(123,31,162);
noStroke();
rect((ratio1+ratio2)*displayWidth, 0, ratio3*displayWidth, displayHeight);
fill(211,47,47);
noStroke();
rect((ratio1+ratio2+ratio3)*displayWidth, 0, ratio4*displayWidth, displayHeight);
//imageMode(CENTER); //
//image(go, displayWidth / 2, displayHeight / 2);
}
void showResultRatio(){
//<>//
fill(83,109,254);
noStroke();
rect(0, 0, ratio1Result*displayWidth, displayHeight);
fill(0,150,136);
noStroke();
rect(ratio1Result*displayWidth, 0, ratio2Result*displayWidth, displayHeight);
fill(123,31,162);
noStroke();
rect((ratio1Result+ratio2Result)*displayWidth, 0, ratio3Result*displayWidth, displayHeight);
fill(211,47,47);
noStroke();
rect((ratio1Result+ratio2Result+ratio3Result)*displayWidth, 0, ratio4Result*displayWidth, displayHeight);
imageMode(CENTER); //
image(mamonaku, displayWidth / 2, displayHeight / 2);
}
void showResult() {
// Background
fill(83,109,254);
noStroke();
rect(0, 0, displayWidth/4 , displayHeight);
fill(0,150,136);
noStroke();
rect(displayWidth/4, 0, displayWidth/4 , displayHeight);
fill(123,31,162);
noStroke();
rect(displayWidth/2, 0, displayWidth/4 , displayHeight);
fill(211,47,47);
noStroke();
rect(displayWidth*3/4, 0, displayWidth/4 , displayHeight);
// Result
fill(255,255,255);
textFont(sans,150);
textAlign(CENTER);
text(counter1Result, displayWidth/8, displayHeight*3.3/4);
text(counter2Result, displayWidth*3/8, displayHeight*3.3/4);
text(counter3Result, displayWidth*5/8, displayHeight*3.3/4);
text(counter4Result, displayWidth*7/8, displayHeight*3.3/4); //<>//
imageMode(CENTER); //
image(result, displayWidth / 2, displayHeight / 2);
}
void showWait() {
// Background
fill(83,109,254);
noStroke();
rect(0, 0, displayWidth/4 , displayHeight);
fill(0,150,136);
noStroke();
rect(displayWidth/4, 0, displayWidth/4 , displayHeight);
fill(123,31,162);
noStroke();
rect(displayWidth/2, 0, displayWidth/4 , displayHeight);
fill(211,47,47);
noStroke();
rect(displayWidth*3/4, 0, displayWidth/4 , displayHeight);
imageMode(CENTER); //
image(title, displayWidth / 2, displayHeight / 2);
}
void keyPressed() {
println("Press:");
switch( key ){
case ENTER:
case RETURN:
scene++;
default:
break;
}
}