[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] variable size array as an argument for Dseq




6 dec. 2018 kl. 10:56 skrev m.piet84@xxxxxxxxx:

dear users,

is there a way to have a variable size list as an argument for Dseq? I know that the array size is set at the definition stage. I have an array of 6 values as a default argument and in some cases, I would like to set it to less than 6 values, e.g., 

this will play 6 consecutive notes
(
Ndef(\dseqTest, {
arg seq = #[1,2,3,4,5,6];
    var a, freq, trig;
    a = Dseq(seq, inf);
    trig = Impulse.kr(MouseX.kr(1, 40, 1));
    freq = Demand.kr(trig, 0, a) * 30 + 340;
    SinOsc.ar(freq) * 0.1

}).play;
)

an I would like to be able to switch to 2 notes only, 

Ndef(\dseqTest).set(\seq, [1,5]);  

but it only replaces the first two elements of the array and the rest remains as in the default. Do I have to redefine the Ndef each time the size changes, even if it is smaller than the default?

yes.
but there are workarounds if you drop Dseq and for example use Dbufrd instead.

s.boot
b.free; b= Buffer.sendCollection(s, [1, 2, 3, 4, 5, 6]);

(
Ndef(\dseqTest, {
arg num = 6;
var a, freq, trig;
a = Dbufrd(b, Dseries(1, 1, inf)%num, 0);  //also try loop=1
trig = Impulse.kr(MouseX.kr(1, 40, 1));
freq = Demand.kr(trig, 0, a).poll * 30 + 340;
SinOsc.ar(freq) * 0.1
}).play;
)


Ndef(\dseqTest).set(\num, 6);
Ndef(\dseqTest).set(\num, 2);
b.set(0, 8)
Ndef(\dseqTest).set(\num, 3);
b.set(1, -5)
Ndef(\dseqTest).set(\num, 5);
//etc

_f

  #|
  |#