-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup1
161 lines (137 loc) · 3.77 KB
/
backup1
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
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=24;
char[] soundonPairs={'A','B','C','D','E','F','G','H','I','J','K','L'};
Minim minim;
int pitch=0;
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);
}
}
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_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");
size (1400,600);
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){
playlist[a].rewind();
playlist[a].play();
}
}
if (pitch%2==1){
boolean ret=playlist[a+12].isPlaying();
if (ret!=true){
playlist[a+12].rewind();
playlist[a+12].play();
}
}
}
}
if (myPort.read()=='X'){
for (int c=0;c<btnCount;c++){
playlist[c].close();
}
}
}