forked from collexion/wavepool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
midiGuitar1.ck
210 lines (171 loc) · 3.85 KB
/
midiGuitar1.ck
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
// Performed this using a Godin LGXSA and Axon100
// on November 29 at Collexion (opening for Dave Farris and Tatsuya Nakatani)
// The performance was a qualified success -- unique but lacklustre
adc => JCRev r => dac;
Mandolin mando[6];
for (0 => int i; i<6; ++i)
{
0.1 => mando[i].gain;
mando[i] => r;
}
0.001 => r.mix;
0.5 => float legato;
-1 => int octaveShift;
0.125::second => dur qn;
// long running process controls beat
fun void TempoShift()
{
0.25::second => qn;
// accelerando for one minute to 0.125::second
now => time accel_begin;
1::minute + accel_begin => time accel_end;
while (now < accel_end)
{
(accel_end - now) / (accel_end - accel_begin) => float t;
0.25::second * t + 0.125::second * (1-t) => qn;
qn => now;
}
}
fun void ModulateReverb(float start_mix, float end_mix, dur length)
{
// accelerando for one minute to 0.125::second
now => time begin;
length + begin => time end;
while (now < end)
{
(end - now) / (end - begin) => float t;
t*start_mix + (1-t)*end_mix => r.mix;
qn => now;
}
}
fun void OctaveBounces()
{
-2 => octaveShift;
8::qn => now;
-1 => octaveShift;
8::qn => now;
0 => octaveShift;
4::qn => now;
1 => octaveShift;
4::qn => now;
2 => octaveShift;
4::qn => now;
now + 32::qn => time end;
while (now < end)
{
Std.rand2(-2,2) => octaveShift;
qn => now;
}
}
fun void LegatoWarp(float start, float end, dur length)
{
now + length => time end_time;
while (now < end_time)
{
(end_time - now) / length => float t;
t*start + (1-t)*end => legato;
qn => now;
}
}
fun void TenMinutes()
{
now + 10::minute => time performance;
spork ~ LegatoWarp(0.1, 0.7, 30::second);
spork ~ TempoShift();
spork ~ ModulateReverb(0.5, 0, 0.5::minute);
spork ~ OctaveBounces();
while (now < performance)
{
Std.rand2f(0.5,1) * 0.5::minute => now;
Std.rand2(0,4) => int which;
if (which == 0)
{
spork ~ LegatoWarp(Std.rand2f(0.1,0.9), Std.rand2f(0.1,0.9), Std.rand2f(1.0,3.0) * 10::second);
}
0.01 => r.mix;
1::minute => now;
}
}
spork ~ TenMinutes();
float stringVol[6];
int stringPitch[6];
float stringFreq[6];
// run arp on single string
fun void ArpGrid(int channel, int beats[])
{
while (true)
{
for (0 => int beat; beat<beats.cap(); ++beat)
{
if (stringVol[channel] > 0 && beats[beat] == 1)
{
mando[channel].noteOn(stringVol[channel] / 127.0);
legato * 1::qn => now;
mando[channel].noteOff(stringVol[channel] / 127.0);
(1-legato) * 1::qn => now;
}
else
{
1::qn => now;
}
}
}
}
MidiIn min;
MidiMsg msg;
//open midi receiver, exit on fail
if ( !min.open(1) )
{
<<<"Failed to open MIDI input">>>;
me.exit();
}
//MidiGuitarString strings[6];
for (0 => int chan; chan<6; ++chan)
{
int beats[Std.rand2(1,2)*Std.rand2(1,2)*4];
for (0 => int beat; beat<beats.cap(); ++beat)
Std.rand2(0,1) => beats[beat];
spork ~ ArpGrid(chan, beats);
}
while( true )
{
// wait on midi event
min => now;
// receive midimsg(s)
while( min.recv( msg ) )
{
msg.data1 & 15 => int channel;
msg.data1 / 16 => int command;
<<< channel, command, msg.data2, msg.data3 >>>;
if (command == 9)
{
//spork ~ MandoNote(mando, msg.data2 + 12);
//spork ~ PluckString(channel, msg.data2);
msg.data2 => stringPitch[channel];
Std.mtof(12*octaveShift + stringPitch[channel]) => stringFreq[channel];
msg.data3 => stringVol[channel];
//mando[channel].noteOn(msg.data3/127.0);
}
else if (command == 8)
{
//mando[channel].noteOff(msg.data3/127.0);
0 => stringVol[channel];
}
else if (command == 14)
{
// pitch bend
Std.mtof(12*octaveShift + stringPitch[channel] + 12*(msg.data3*128 + msg.data2)/8192.0) => stringFreq[channel] => mando[channel].freq;
}
else if (command == 11)
{
// CC
if (msg.data2 == 7)
{
for (0 => int i; i<6; ++i)
{
0.1 * msg.data3/127.0 => mando[i].gain;
}
}
}
}
}