«Hymn #15 - generative melody by array rewriting» by madamdata

on 19 Apr'16 20:22 in algorithmic

This composition uses a task to read an array of durations and pitches. Every certain number of cycles, the functions scrambRand and octRand are called. scrambRand reverses a random sub-segment of the array. octRand randomly transposes a note up or down an octave. Every so often, all pitches are transposed according to the transp array.

Two instances of this process are run simultaneously, one left and one right.

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
(
SynthDef(\ping, {
	arg freq = 440, pan = 0;
	var sig;
	sig = SinOsc.ar(freq, 0, 0.3);
	sig = sig * EnvGen.ar(Env.perc(0.01, 1), doneAction:2);
	sig = Pan2.ar(sig, pan);
	Out.ar(0, sig)
}).add;
)

(
~scramb = {|pan|
var notes = [0,4,7,14,9,12,4,7,9,7];
var dur = [1,1,2,3,6,3,4,5,2,1,13];
var transp = [0, 5, 7, 3, 2];
var scrambRand = {|array|
	var rand = rrand(0, array.size-3);
	var end = rand + rrand(1,2);
	var range = (rand..end);
	var reverseRange = range.reverse;
	var temp = array.copy;
	range.postln;
	range.do({|item, index|
		array[item] = temp[reverseRange[index]];
	});
	array;
};
var octRand = {|array|
		var rand = rrand(0, array.size-1);
		array[rand] = array[rand] + [-12,0,12].choose;
	};
var task = Task {
	var step = 0;
	var transpStep = 0;
	loop {
		var freq = (notes.wrapAt(step) + 60 + transp.wrapAt(transpStep)).midicps;
		Synth(\ping, [\freq, freq, \pan, pan]);
		(dur.wrapAt(step) * 0.15).wait;
		step = step + 1 % (notes.size * 12;);
		if (step%32 == 0, {scrambRand.value(notes)});
		if (step%20 == 0, {scrambRand.value(dur)});
		if (step%66 == 0, {transpStep = transpStep + 1 % (transp.size)});
		if (step%24 == 0, {notes = notes.rotate(rrand(-1, 1))});
		if (step%56 ==0, {octRand.value(notes)});
	}
}.play;
};
)

(
~scramb.value(-0.7);~scramb.value(0.7);
)
raw 1340 chars (focus & ctrl+a+c to copy)
reception
comments