Repository navigation
Expand file tree
/
Copy pathseco6.sc
More file actions
294 lines (247 loc) · 5.41 KB
/
Copy pathseco6.sc
File metadata and controls
294 lines (247 loc) · 5.41 KB
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
s.boot
(
SynthDef("channel", {
arg out, in, amp, bal;
Out.ar(out, In.ar(in)*amp);
}).send(s);
SynthDef("sin1", {
arg out, t_trig;
Out.ar(out, In.ar(in)*amp);
}).send(s);
)
(
SynthDef(\bubblebub, { |out=0, t_trig=1, attack=0.01, decay=0.08, pitchcurvelen=0.1, freq=1000, doneAction=0, amp=0.1|
var pitch, son;
amp = amp * EnvGen.ar(Env.perc(attack, decay).delay(0.003), t_trig, doneAction: doneAction);
pitch = freq * EnvGen.ar(Env.new([0,0,1],[0,1]).exprange(1, 2.718), t_trig, timeScale: pitchcurvelen);
son = SinOsc.ar(pitch);
// high-pass to remove any lowpitched artifacts, scale amplitude
son = HPF.ar(son, 500) * amp * 10;
Out.ar(out, son);
}).send(s);
)
(
~keyboard = "azertyuiqsdfghjkwxcvbn,;";
buttons = [];
handlers = (0..(~numSteps*3)).collect ({ arg i;
{
buttons[i].value = ((buttons[i].value+1) % 2).postln;
buttons[i].doAction.value;
};
});
window.keyDownAction = { arg view, char, modifiers, u, k;
var f = ~keyboard.find(char.asString);
f.postln;
f.dump;
handlers.postln;
~keyboard.postln;
buttons.postln;
if ( f.isNil, {"plop".postln;}, {handlers[f].value});
} ;
)
(
var width = 1110, height = 500;
// ============= helpers
~toggle_button = { arg button;
button.value = ((button.value+1) % 2);
button.doAction.value;
};
~toggle_value = { arg value;
((value+1) % 2);
};
~mkdico = { arg col, f;
var dico = Dictionary.new;
var ret;
col.collect { arg row, r;
row.collect{ arg cell, c;
ret = f.(row, r, cell, c);
dico[ret[0]] = ret[1];
};
dico;
};
};
// ============= raw inputs definitions
~kbpad8x4 = [
[ 38, 233, 34, 39, 40, 45, 232, 95 ],
[97, 122, 101, 114, 116, 121, 117, 105 ],
[113, 115, 100, 102, 103, 104, 106, 107 ],
[119, 120, 99, 118, 98, 110, 44, 59 ]
];
~cakewalk = (
\knot: [
74, 71, 65, 2, 5, 76, 77, 78, 10
],
\button: [
21, 22, 23, 24, 25, 26, 27, 28
],
\toggle: [
80,81,82,83
],
\slider: [
73, 75, 72, 91, 92, 93, 94, 95, 7
]
);
// ============= input symbol mapping
~midi = {
var dico = Dictionary.new;
~cakewalk.collect { arg v, k;
"v:".postln;
v.postln;
"k:".postln;
k.postln;
v.do { arg raw, i;
dico[raw] = (k.asString++i).asSymbol;
};
};
dico;
}.value;
~cakewalk_bend2 = 1;
~cakewalk_master_knot = 0;
~numstep = 8;
~keyboard = {
var dico = Dictionary.new;
~kbpad8x4.do { arg row, r;
row.do {arg cell, c;
dico[cell] = ("line"++r++"_step"++c).asSymbol
};
};
dico
}.value;
~keyboard.value.postln;
// ============= gui
~make_window = {
var window, buttons, handlers;
var ul = [];
window = GUI.window.new("seq", Rect(50, 50, width, height)).front;
window.view.decorator = FlowLayout(window.view.bounds); // notice that FlowView refers to w.view, not w
window;
};
~add_channel = {
arg parent, name;
var hl, b, txt, blist = [];
hl = GUI.hLayoutView.new(parent, Rect(0,0,width+10,60));
hl.background = Color.rand;
txt = GUI.staticText.new(hl, Rect(0,0,100, 50)); // no text, just a vertical spacer
txt.string = " " ++ name;
~numstep.do { arg i;
b = GUI.button.new(hl, Rect(50,50,50,50));
i = i;
b.states = [
[ " " ++ i ++ " ", Color.black, Color.red],
[ "=" ++ i ++ "=", Color.white, Color.black ]
];
blist = blist.add(b);
};
blist;
};
~stepsbut = [];
~win = ~make_window.value;
~stepsbut = ~stepsbut.add( ~add_channel.(~win, "chan1"));
~stepsbut = ~stepsbut.add( ~add_channel.(~win, "chan2"));
// ============= spec
~freqspec = ControlSpec(20,20000,\exp,1,440,"Hz");
// ============= data struct
~stepsamp = ~stepsbut.collect { arg row, r;
row.collect{ arg cell, c;
0
}
};
~stepsfreq = ~stepsbut.collect { arg row, r;
//row.collect{ arg cell, c;
300
//}
};
~currentline = 0;
// ============= handlers
~handlers = {
var dico = Dictionary.new;
~stepsbut.do { arg row, r;
row.do { arg cell, c;
dico[("line"++r++"_step"++c).asSymbol] = {
//"==>>>".postln;
//~stepsbut[r][c].postln;
~toggle_button.(~stepsbut[r][c]);
~stepsamp[r][c] = ~toggle_value.(~stepsamp[r][c]);
}
}
};
dico;
}.value;
~handlers.postln;
~midihandlers = {
var dico = Dictionary.new;
dico[\knot0] = { arg value;
~stepsfreq[~currentline] = ~freqspec.map(value/127);
};
dico;
}.value;
// ============= main handlers
~win.view.keyDownAction = { arg view, char, modifiers, u, k;
//"{ ============".postln;
~stepsbut.postln;
~handlers.postln;
if (~keyboard.at(u).notNil, {
//~keyboard[u].postln;
//~handlers[~keyboard[u]].postln;
~handlers[~keyboard[u]].value;
});
//"============ }".postln;
};
~ccresp = CCResponder({ |src,chan,num,value|
"####============".postln;
[src,chan,num,value].postln;
~midi[num].postln;
~midihandlers[~midi[num]].(value)
},
nil, // any source
nil, // any channel
nil, // any CC number
nil // any value
);
~stepsamp.postln;
// ============= patterns connectors
~steps = { arg line;
Prout({
~stepsamp[line].do { arg a, i;
//"NOW:".postln;
//i.postln;
//a.postln;
//"-END".postln;
a.yield;
}
});
};
~freqs = { arg line;
Prout({
"NOW:".postln;
~stepsfreq[line].postln;
"-END".postln;
~stepsfreq[line].yield
});
};
~legato = 0.1;
// ============= patterns
~p1 = Pbind(
//\degree, Pwhite(-7, 12, inf),
\freq, Pn(~freqs.(0),inf),
\dur, 0.5,
\amp, Pn(~steps.(0),inf)*0.1,
\legato, Pfunc({
~stepsamp.postln;
~legato;
})
);
~p2 = Pbind(
\instrument, \bubblebub,
\degree, Pwhite(-7, 12, inf),
\dur, 0.5,
\amp, Pn(~steps.(1),inf)*0.1,
\legato, Pfunc({~legato})
);
~whole = Ppar([
~p2,
~p1
]);
//~whole = ~p1;
~whole.play;
)