«rand-n-step» by vividsnow

on 14 Nov'11 19:28 in guisequencerrandomstep

simple 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; 
)
descendants
full graph
raw 1084 chars (focus & ctrl+a+c to copy)
reception
comments
beryann.parker user 15 Nov'11 05:32

Great simple (but good sounds) sequencer!! thx

nik user 15 Nov'11 15:46

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.

vividsnow user 17 Nov'11 06:50

thank you for positive feedback - now i'm going to post "rand-n-step+" )

jeryanders user 14 Jun'15 21:01

This is a very elegant script. I love it. Thanks for sharing!

snappizz user 18 Jun'15 16:00

easily a $200 piece of hardware in 37 lines :)

hems.inlet user 07 Jul'15 14:02

super awesome

ivogrig user 25 Oct'16 03:50

I am just starting to learn SC, this is handy and fun. Thanks!