«rand-n-step» by vividsnow
on 15 Nov'11 01:28 insimple gui step sequencer of PMOsc-based random instruments
note: modify variables "dims" and "resolution" to change number of instruments/steps and time resolution
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
(
var w, buttons, data, synths, dims = [16,16], resolution = 4;
w = Window("rand-n-step", Rect(50,250,dims[0]*22 + 10,dims[1]*22+10));
synths = Array.fill(dims[1], { |i|
SynthDef('rstp'++i, {
var sig = Pan2.ar(
PMOsc.ar(80.exprand(10000), 1.exprand(200), 1.exprand(20)),
-1.0.rand2,
EnvGen.kr(Env(Array.rand(4, 0, 0.1.rrand(0.5)).add(0), Array.rand(3, 0.1, 0.3).add(0.1), -5.rrand(5)), doneAction: 2)
);
Out.ar(0, sig);
}).add.name;
});
data = Array2D(dims[1],dims[0]);
buttons = Array.fill(dims[1], { |l|
Array.fill(dims[0], { |i|
Button( w, Rect( 5 + (22*i), 5 + (22*l), 20, 20) ).states_([ ['-'], ['+'], ['%'] ]).action_({ |b| data[l,i] = b.value });
})
});
AppClock.play({
inf.do({|i|
dims[1].do({ |l|
(buttons[l] @@ i).font_(Font("sans", 20));
(buttons[l] @@ (i-1)).font_(Font("sans", 14));
switch( data[l,i.mod(dims[0])],
1, { Synth(synths[l]) },
2, { 0.5.coin.if({ Synth(synths[l]) }) }
);
});
(TempoClock.default.tempo.reciprocal / resolution).yield;
});
}.asRoutine);
w.front;
)
reception
Great simple (but good sounds) sequencer!! thx
wow. a 16x16 PM step sequencer in less than 40 lines of code.
Should be at the top of everybody's "Why use Supercollider?" examples.
thank you for positive feedback - now i'm going to post "rand-n-step+" )
This is a very elegant script. I love it. Thanks for sharing!
easily a $200 piece of hardware in 37 lines :)
super awesome
I am just starting to learn SC, this is handy and fun. Thanks!
I love the simplicity and utility of this code. It was super easy to manipulate to make a drum sequencer with a buffer as the Synth variable and "-", "+", "^", "()" as the button states for amplitude. It might be my favorite new toy.