«Molecular music box 2» by grirgz

on 27 Aug'14 20:27 in patterngenerativemolecular

Same algo, but instead of picking the next note in the scale, it take the next event in an event pattern, much more possibilities, I have fun for hours with that =)

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
(
~molecular_box = { arg lenpat, quant=16, keep=3, pattern;

	Prout({ arg ev;
	
		var lenstr = lenpat.asStream;
		var patstr;
		var buf = Array.fill(quant,{List.new});
		var pat, len;
		var i;
		var basepat;

		patstr = pattern.asStream;

		len = lenstr.next;
                if(len.isNil) {
                    nil.yield;
                };

		i = 0;
		inf.do {
			var n;
			buf[i] = buf[i].keep(0-keep);
			n = buf[i];

			if(n.size != 0) {
				// previous note found, change note length
				len = lenstr.next;
                                if(len.isNil) {
                                   nil.yield;
                                };
			};

			basepat = ev;
			basepat[\legato] = len;
			pat = patstr.next(basepat);
                        if(pat.isNil) {
                           nil.yield;
                        };

			n.add(Pn(pat,1));

			len.do {
				var n = buf[i];

				if(n.size != 0) {
					ev = Ppar(n).embedInStream;
				} {
					var myev;
					myev = ev.deepCopy;
					myev[\isRest] = true;
					ev = Pn(myev,1).embedInStream;
				};
				i = (i+1) % quant;
			};
		}
	})
};
);




(
SynthDef(\simple, { arg out=0, amp=0.1, gate=1, pan=0, spread=0.8, freq=200, doneAction=2;
	var sig, sig1, sig2, sig3;
	sig = SinOsc.ar(freq * [1,1.01,2.01,1.02,1/2] * (SinOsc.kr(3)*0.01+1));
	sig = sig + LFTri.ar(freq * [1,1/2,1.01]);
	sig = sig * EnvGen.ar(\adsr.kr(Env.adsr(0.01,0.1,0.8,0.1)),gate,doneAction:doneAction);
	sig = Splay.ar(sig, spread, amp, pan);
	Out.ar(out, sig);
}).add;
SynthDef(\saw, { arg out=0, amp=0.1, gate=1, pan=0, spread=0.8, freq=200, doneAction=2;
	var sig, sig1, sig2, sig3;
	var env;
	sig = LFSaw.ar(freq * [1,1.01,2.01,1.02]);
	sig = Pulse.ar(freq * [1,1.01,2,2.01,1.002]) + sig;
	env = EnvGen.ar(Env.adsr(0.4,0.3,0.31,0.1),gate,doneAction:0);
	sig = RLPF.ar(sig, \ffreq.kr(1000) * (env+0.5));
	sig = sig * EnvGen.ar(\adsr.kr(Env.adsr(0.01,0.1,0.8,0.1)),gate,doneAction:doneAction);
	sig = Splay.ar(sig, spread, amp, pan);
	Out.ar(out, sig);
}).add;
SynthDef(\reverb, {arg out = 0, in=0;
    var sig = In.ar(in, 2);
    sig = FreeVerb.ar(sig,0.5,0.7);
    ReplaceOut.ar(out, sig);
}).add;
);



Synth.tail(1,\reverb); // if you want



(

Pdef(\mol, 

	~molecular_box.(Pseq([4.5,8],inf), 16, 3,
		Pseq([
			Pbind(
				\instrument, Pn(\simple,4),
				\adsr, Pseq([
					[ Env.adsr(0.1,0.1,0.8,0.4) ],
					[ Env.adsr(0.4,0.4,0.6,0.2) ],
				],inf),
				\legato, Pkey(\legato) / 2,
			),
			Pbind(
				\instrument, Pn(\saw,4),
				\ffreq, Pseq([5000,1000,200,2000],inf),
				\adsr, Pseq([
					[ Env.adsr(0.1,0.4,0.4,0.3) ],
				],inf),
				\legato, Pkey(\legato) / 2,
			),
		],inf) 
		<>
		Pbind(
			\degree, Pseq([
				Pseq((0..13)),
				Pseq((0..10)-4),
				Pseq((5..1)),
				Pseq((0..5)*2),
				Pseq((20..10)),
				Pseq((0..10)-10),
			],inf),
		);

	)
	<>
	Pbind(
		\dur, 1/4,
		\scale, Scale.minor,
	)

).play;

)




(

Pdef(\mol, 

	~molecular_box.(Pseq([4.5,2,5,1],inf), 16, 3,
		Pbind(
			\legato, Pseq([
				Pfuncn({ arg ev; ev[\legato] },16),
				Pser([0.5],16)
			],inf)
		)
		<>
		Pseq([
			Pbind(
				\instrument, Pn(\simple,4),
				\adsr, Pseq([
					[ Env.adsr(0.1,0.1,0.8,0.4) ],
					[ Env.adsr(0.4,0.4,0.6,0.2) ],
				],inf),
				\legato, Pkey(\legato) * Pseq([0.2,0.8,1.2],inf).stutter(3),
			),
			Pbind(
				\instrument, Pn(\saw,2),
				\ffreq, Pseq([5000,1000,700],inf),
				\adsr, Pseq([
					[ Env.adsr(0.1,0.4,0.4,0.3) ],
				],inf),
			),
			Pbind(
				\instrument, Pn(\saw,2),
				\ffreq, Pkey(\freq) * 4,
				\adsr, Pseq([
					[ Env.adsr(0.1,0.4,0.4,0.3) ],
				],inf),
			),
		],inf) 
		<>
		Pbind(
			\degree, Pseq([
				Pseq((5..1)),
				Pseq((0..3)),
				Pseq((0..10)-4),
				Pseq((0..5)*3),
				Pseq((2..10)),
				Pseq((0..10)-10),
			],inf),
		);

	)
	<>
	Pbind(
		\dur, 1/4,
		\mtranspose, 2,
		\root, 4,
		\scale, Scale.aeolian,
	)

).play;
)
raw 4025 chars (focus & ctrl+a+c to copy)
reception
comments
grirgz user 27 Aug'14 20:41

note it's not a good idea to use floats for the length pattern because it's used in a do. loop, so don't do that at home, kids ;) use multiple and the \dur key instead

Roberto Arletti user 28 Aug'14 09:49

Hi , i am Roberto , on supercollider 3.6.6 with windows 7 64 bit , when evaluate the Pdef istruction i have this error :

Pdef('mol') ERROR: Message 'put' not understood. RECEIVER: nil ARGS: Symbol 'isRest' true CALL STACK: DoesNotUnderstandError:reportError 0x5f65fb0 arg this = <instance of DoesNotUnderstandError> Nil:handleError 0x5f67090 arg this = nil arg error = <instance of DoesNotUnderstandError> Thread:handleError 0x5f64b10 arg this = <instance of Routine> arg error = <instance of DoesNotUnderstandError> Thread:handleError 0x5f64810 arg this = <instance of Routine> arg error = <instance of DoesNotUnderstandError> Thread:handleError 0x5f69010 arg this = <instance of Routine> arg error = <instance of DoesNotUnderstandError> Object:throw 0x5f64ab0 arg this = <instance of DoesNotUnderstandError> Object:doesNotUnderstand 0x5f64cf0 arg this = nil arg selector = 'put' arg args = [*2] < FunctionDef in closed FunctionDef > 0x5f64990 var myev = nil < FunctionDef in closed FunctionDef > 0x5f686b0 var n = <instance of List> Float:do 0x5f67ff0 arg this = 4.5 arg function = <instance of Function> var i = 1 Float:do 0x5f6ca90 arg this = 1.#INF arg function = <instance of Function> var i = 0 Routine:prStart 0x5f99a30 arg this = <instance of Routine> arg inval = <instance of Event> ^^ The preceding error dump is for ERROR: Message 'put' not understood. RECEIVER: nil

grirgz user 01 Sep'14 15:13

Hi, sorry I don't know why it give you this error, i'm on 3.7 ubuntu, no error here :/

Bryan Christophe Green user 15 Feb'15 22:08

Also getting this error.

^^ The preceding error dump is for ERROR: Message 'put' not understood. RECEIVER: nil

grirgz user 19 Feb'15 08:24

I'm trying to find the 3.6 incompatibility. Please try this and tell me if you get an error :

( ~ev = (bla:3, rah:6); ~myev = ~ev.deepCopy; ~myev[\isRest] = true; )

umbescla user 19 Feb'15 11:21

hi , the result is : ( 'isRest': true, 'bla': 3, 'rah': 6 )

....... no error