«poly ndef» by bgola
on 25 Jun'20 14:44 inplaying multiple voices in an Ndef
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
(
Ndef(\polysynth, {|t_gate, midinote=60|
var n_voices = 10, max_voice_time=120;
var times = LocalIn.kr(n_voices);
// Latch returns 0 by default before the first trig, that is why we
// sum 1 to the index and then subtract.
var voice = (Latch.kr(ArrayMax.kr(times)[1] + 1, t_gate) - 1);
var trigs = n_voices.collect {|idx|
BinaryOpUGen('==', voice, idx);
};
var voices = n_voices.collect {|idx|
SinOsc.ar(Latch.kr(midinote.midicps, trigs[idx])) * EnvGen.ar(
Env.perc(0.01,3),
trigs[idx];
);
};
LocalOut.kr(
n_voices.collect {|idx|
EnvGen.kr(Env.new([1,0,1],[0,max_voice_time]), trigs[idx]);
});
Splay.ar(voices);
}).play;
)
(
Tdef(\melody, {
var scale = Scale.choose;
24.rand.do {
Ndef(\polysynth).set(\t_gate, 1, \midinote, 60+scale.degrees.choose);
2.0.rand.wait;
}
}).play;
)
(
Tdef(\chord, {
Ndef(\polysynth).set(\t_gate, 1, \midinote, 50);
0.003.wait;
Ndef(\polysynth).set(\t_gate, 1, \midinote, 60);
0.003.wait;
Ndef(\polysynth).set(\t_gate, 1, \midinote, 70);
}).play;
)
reception
comments