«Yet another molecular music box» by coreyker

on 24 Dec'14 14:13 in algorithmic

An attempt at coding this algorithm: http://www.synthtopia.com/content/2014/12/22/the-molecular-music-box-how-simple-rules-can-lead-to-rich-patterns/

I haven't really checked for errors, but is sounds ok.

There are a few other SC versions as well. See for example:

http://www.kimri.org/blog/?p=487

and

http://sccode.org/1-4Ww

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
( // first run synthdef
SynthDef(\piano, {|midinote, outBus=0|
	Out.ar(outBus, MdaPiano.ar(midinote.midicps, decay:0.5)); // from sc3-plugins
}).add;
)

( // now the rest
~dur = {|len1=4, len2=3|
	Plazy({
		var dur = len1;

		inf.do{|n|
			var overlap = (n % len1 == 0) || (n % len2 == 0);
			if(n>=len1 && dur==len1 && overlap,
				{
					dur=len2;
				},
				{
					if(n>0 && dur==len2 && overlap,
						{
							dur=len1;
					});
				}
			);
			dur.yield;
		};
	}).asStream;
};

~note = { |root=48|
	Plazy({
		var scale = Scale.major.degrees.flat;
		inf.do{|n|
			var oct = (n / scale.size).floor;
			var degree = 12*oct + scale.wrapAt(n) + root;
			degree.yield;
		}
	}).asStream;
};

r = Routine({
	var durStream  = ~dur.value(9, 14.5);
	var noteStream = ~note.value(48);
	inf.do {
		var dur  = durStream.next();
		var note = noteStream.next();
		fork{
			inf.do{
				Synth(\piano, [\midinote, note]);
				4.yield; // loop duration
			};
		};
		dur.yield;
	};
});

r.play(TempoClock(2));
)
raw 1052 chars (focus & ctrl+a+c to copy)
reception
comments