-
Notifications
You must be signed in to change notification settings - Fork 0
/
Music Box.pde
356 lines (310 loc) · 9.82 KB
/
Music Box.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
345
346
347
348
349
350
351
352
353
354
355
356
import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.analysis.*;
import ddf.minim.ugens.*;
import ddf.minim.effects.*;
import controlP5.*;
import processing.serial.*;
Serial myPort;
ControlP5 cp5;
float knobValue;
Knob knob;
float knobFuncValue;
int btnCount=12;
char[] soundonPairs={'A','B','C','D','E','F','G','H','I','J','K','L'};
Minim minim;
int pitch=0;//1オクターブ変えるかどうかの変数
AudioPlayer[] playlist;
AudioOutput out;
int bpm;
int desiredFrameRate=60;
int count=0;
//メトロノーム機能
class MyInstrument implements Instrument{
Oscil osc;
Line ampEnv;
MyInstrument(float frequency){
osc=new Oscil(frequency,0.0,Waves.SINE);//正弦波
ampEnv=new Line();
ampEnv.patch(osc.amplitude);
}
void noteOn(float duration){
ampEnv.activate(duration,0.5,0);
osc.patch(out);
}
void noteOff(){
osc.unpatch(out);
}
}
//キーボードの1の入力でオクターブ変える
void keyPressed(){
if (key=='0'){
pitch++;
}
}
void setup(){
myPort=new Serial(this,"/dev/ttyACM0",9600);
minim=new Minim(this);
playlist=new AudioPlayer[btnCount];
//マリンバの音
/*
playlist[0]=minim.loadFile("Marinba_2si.mp3");
//playlist[0]=minim.loadFile("Marinba_do.mp3");
playlist[1]=minim.loadFile("Marinba_re.mp3");
playlist[2]=minim.loadFile("Marinba_mi.mp3");
playlist[3]=minim.loadFile("Marinba_fa.mp3");
playlist[4]=minim.loadFile("Marinba_so.mp3");
playlist[5]=minim.loadFile("Marinba_ra.mp3");
playlist[6]=minim.loadFile("Marinba_si.mp3");
playlist[7]=minim.loadFile("Marinba_do#.mp3");
playlist[8]=minim.loadFile("Marinba_re#.mp3");
playlist[9]=minim.loadFile("Marinba_fa#.mp3");
playlist[10]=minim.loadFile("Marinba_so#.mp3");
playlist[11]=minim.loadFile("Marinba_ra#.mp3");
playlist[12]=minim.loadFile("Marinba_ddo.mp3");
playlist[13]=minim.loadFile("Marinba_rre.mp3");
playlist[14]=minim.loadFile("Marinba_mmi.mp3");
playlist[15]=minim.loadFile("Marinba_ffa.mp3");
playlist[16]=minim.loadFile("Marinba_sso.mp3");
playlist[17]=minim.loadFile("Marinba_rra.mp3");
playlist[18]=minim.loadFile("Marinba_ssi.mp3");
playlist[19]=minim.loadFile("Marinba_ddoo.mp3");
playlist[20]=minim.loadFile("Marinba_rree.mp3");
playlist[21]=minim.loadFile("Marinba_ffa#.mp3");
playlist[22]=minim.loadFile("Marinba_sso#.mp3");
playlist[23]=minim.loadFile("Marinba_rra#.mp3");
*/
//シンセサイザーの音
/*
playlist[0]=minim.loadFile("synbass_do.mp3");
playlist[1]=minim.loadFile("synbass_re.mp3");
playlist[2]=minim.loadFile("synbass_mi.mp3");
playlist[3]=minim.loadFile("synbass_fa.mp3");
playlist[4]=minim.loadFile("synbass_so.mp3");
playlist[5]=minim.loadFile("synbass_ra.mp3");
playlist[6]=minim.loadFile("synbass_si.mp3");
playlist[7]=minim.loadFile("synbass_do#.mp3");
playlist[8]=minim.loadFile("synbass_re#.mp3");
playlist[9]=minim.loadFile("synbass_fa#.mp3");
playlist[10]=minim.loadFile("synbass_so#.mp3");
playlist[11]=minim.loadFile("synbass_ra#.mp3");
playlist[12]=minim.loadFile("synbass_ddo.mp3");
playlist[13]=minim.loadFile("synbass_rre.mp3");
playlist[14]=minim.loadFile("synbass_mmi.mp3");
playlist[15]=minim.loadFile("synbass_ffa.mp3");
playlist[16]=minim.loadFile("synbass_sso.mp3");
playlist[17]=minim.loadFile("synbass_rra.mp3");
playlist[18]=minim.loadFile("synbass_ssi.mp3");
playlist[19]=minim.loadFile("synbass_ddo#.mp3");
playlist[20]=minim.loadFile("synbass_rre#.mp3");
playlist[21]=minim.loadFile("synbass_ffa#.mp3");
playlist[22]=minim.loadFile("synbass_sso#.mp3");
playlist[23]=minim.loadFile("synbass_rra#.mp3");
*/
//オルゴールの音
/*
playlist[0]=minim.loadFile("musicbox_do.mp3");
playlist[1]=minim.loadFile("musicbox_re.mp3");
playlist[2]=minim.loadFile("musicbox_mi.mp3");
playlist[3]=minim.loadFile("musicbos_fa.mp3");
playlist[4]=minim.loadFile("musicbox_so.mp3");
playlist[5]=minim.loadFile("musicbox_ra.mp3");
playlist[6]=minim.loadFile("musicbox_si.mp3");
playlist[7]=minim.loadFile("musicbox_do#.mp3");
playlist[8]=minim.loadFile("musicbox_re#.mp3");
playlist[9]=minim.loadFile("musicbox_fa#.mp3");
playlist[10]=minim.loadFile("musicbox_so#.mp3");
playlist[11]=minim.loadFile("musicbox_ra#.mp3");
playlist[12]=minim.loadFile("musicbox_ddo.mp3");
playlist[13]=minim.loadFile("musicbox_rre.mp3");
playlist[14]=minim.loadFile("musicbox_mmi.mp3");
playlist[15]=minim.loadFile("musicbox_ffa.mp3");
playlist[16]=minim.loadFile("musicbox_sso.mp3");
playlist[17]=minim.loadFile("musicbox_rra.mp3");
playlist[18]=minim.loadFile("musicbox_ssi.mp3");
playlist[19]=minim.loadFile("musicbox_ddo#.mp3");
playlist[20]=minim.loadFile("musicbox_rre#.mp3");
playlist[21]=minim.loadFile("musicbox_ffa#.mp3");
playlist[22]=minim.loadFile("musicbox_sso#.mp3");
playlist[23]=minim.loadFile("musicbox_rra#.mp3");
*/
playlist[0]=minim.loadFile("music_so1.mp3");
playlist[1]=minim.loadFile("music_si1.mp3");
playlist[2]=minim.loadFile("music_do#.mp3");
playlist[3]=minim.loadFile("music_re.mp3");
playlist[4]=minim.loadFile("music_mi.mp3");
playlist[5]=minim.loadFile("music_fa.mp3");
playlist[6]=minim.loadFile("music_so.mp3");
playlist[7]=minim.loadFile("music_ra.mp3");
playlist[8]=minim.loadFile("music_si.mp3");
playlist[9]=minim.loadFile("music_fa#.mp3");
playlist[10]=minim.loadFile("music_ddo.mp3");
playlist[11]=minim.loadFile("music_rre.mp3");
size (1400,600);//OpenGLの描画ウィンドウの表示サイズ
frameRate(desiredFrameRate);
background(255);//背景は白
//キーボード画面の描画
strokeWeight(6);
for (int i=0;i<15;i++){
line(60+90*i,200,60+90*i,500);
}
line(60,500,1320,500);
line(60,200,1320,200);
strokeWeight(36);
line(150,200,150,370);
line(240,200,240,370);
line(420,200,420,370);
line(510,200,510,370);
line(600,200,600,370);
line(780,200,780,370);
line(870,200,870,370);
line(1050,200,1050,370);
line(1140,200,1140,370);
line(1230,200,1230,370);
//メトロノームダイヤルの描画
out=minim.getLineOut();
cp5=new ControlP5(this);
cp5.addKnob("bpm")
.setRange(0,200)
.setValue(0)
.setPosition(100,50)
.setRadius(50)
.setNumberOfTickMarks(10)
.setTickMarkLength(5);
}
void draw(){
//メトロノーム
if (frameCount % int(desiredFrameRate/(bpm/60.0))==0){
if (count==0){
out.playNote(0.0,0.3,new MyInstrument(440));
}else{
out.playNote(0.0,0.3,new MyInstrument(440));
}
count++;
if (count==4){
count=0;
}
}
//シリアル通信がアルファベットならば音楽再生
for (int a=0;a<12;a++){
if (myPort.read()==soundonPairs[a]){
if (pitch%2==0){
boolean ret=playlist[a].isPlaying();
if (ret!=true){
/*for (int c=0;c<btnCount;c++){
boolean ans=playlist[c].isPlaying();
if (ans==true){
playlist[c].pause();
}
}*/
playlist[a].rewind();
playlist[a].play();
}
}
//赤い円の描画(白鍵盤)
for (int d=0;d<7;d++){
fill(255,255,255);
noStroke();
ellipse(105+90*d,450,60,60);
ellipse(735+90*d,450,60,60);
}
//赤い円の描画(黒鍵盤)
fill(0,0,0);
noStroke();
ellipse(150,350,35,35);
ellipse(240,350,35,35);
ellipse(420,350,35,35);
ellipse(510,350,35,35);
ellipse(600,350,35,35);
ellipse(780,350,35,35);
ellipse(870,350,35,35);
ellipse(1050,350,35,35);
ellipse(1140,350,35,35);
ellipse(1230,350,35,35);
if ((a>=0)&&(a<7)){
fill(255,0,0);
noStroke();
ellipse(105+90*a,450,60,60);
}else if ((a==7)||(a==8)){
fill(255,0,0);
noStroke();
ellipse(150+90*(a-7),350,35,35);
}else{
fill(255,0,0);
noStroke();
ellipse(420+90*(a-9),350,35,35);
}
//1オクターブ変える場合
if (pitch%2==1){
boolean ret=playlist[a+12].isPlaying();
if (ret!=true){
playlist[a+12].rewind();
playlist[a+12].play();
}
for (int d=0;d<7;d++){
fill(255,255,255);
noStroke();
ellipse(105+90*d,450,60,60);
ellipse(735+90*d,450,60,60);
}
//黒鍵盤
fill(0,0,0);
noStroke();
ellipse(150,350,35,35);
ellipse(240,350,35,35);
ellipse(420,350,35,35);
ellipse(510,350,35,35);
ellipse(600,350,35,35);
ellipse(780,350,35,35);
ellipse(870,350,35,35);
ellipse(1050,350,35,35);
ellipse(1140,350,35,35);
ellipse(1230,350,35,35);
if ((a>=0)&&(a<7)){
fill(255,0,0);
noStroke();
ellipse(735+90*a,450,60,60);
}else if ((a==7)||(a==8)){
fill(255,0,0);
noStroke();
ellipse(780+90*(a-7),350,35,35);
}else{
fill(255,0,0);
noStroke();
ellipse(1050+90*(a-9),350,35,35);
}
}
if ((a>=3)&&(a<9)){
fill(255,0,0);
noStroke();
ellipse(195+90*(a-3),450,60,60);
}else if (a==2){
fill(255,0,0);
noStroke();
ellipse(150+90*(a-2),350,35,35);
}else if (a==9){
fill(255,0,0);
noStroke();
ellipse(420+90*(a-9),350,35,35);
}else if ((a==10)||(a==11)){
fill(255,0,0);
noStroke();
ellipse(735+90*(a-10),450,60,60);
}
}
}
if (myPort.read()=='X'){
for (int c=0;c<btnCount;c++){
//playlist[c].pause();
}
}
}
//すべての音楽ファイルを停止
void stop(){
for (int a=0;a<btnCount;a++){
playlist[a].close();
}
minim.stop();
super.stop();
}