[sc-users] Triggering a function with Impulse: wrong approach?

Batuhan Bozkurt batuhan at batuhanbozkurt.com
Thu Oct 25 01:26:23 PDT 2007


Hello,

This is my first message in list and I'm new at SuperCollider too. I'm 
trying to get the knack of the approach SC introduces, and it is giving 
me hard time. I'm trying to "unlearn" some stuff as I'm a pretty 
experienced PD user, and I'm  slowly learning that "bang" 
driven(triggered) structures jsut don't cut it in SC. It's a new 
approach for me and I'm asking for your help.

What I'm trying to do is essentially building a loop slicer and 
randomiser mostly to get used to SC. The basic structure should be: Load 
a sound into buffer(which should be a loop), give the number of slices 
to the program and let the code play the slices randomly(logic will be 
applied later) as a start. My approach for this is: Get the length of 
sound in buffer, divide that number with number of slices to get the 
length of one slice, then drive a BufRd with some sort of Line so if I 
want to play the 5th slice, "Line" would ramp through (5 * slicelength) 
to (6 * slicelength). And when the ramp "ends" I want to retrigger the 
synth to get a new random number and play that slice. Easy as that. I've 
actually built it and it is working as is but I don't think I'm 
approaching the issue in a right way. Here is the code:
///////////////////////////////////////////////////////////////////////
~thisPath = PathName.new( Document.current.path ).pathOnly;
s.sendMsg("/b_allocRead", 0, ~thisPath ++ "loop.wav");

(
SynthDef("masher",{
    var bufPlay, sliceLen = BufFrames.kr(0)/128, sliceDur = 
sliceLen/BufSampleRate.kr(0), randSlice = Rand(0,128).round(1);
    bufPlay = BufRd.ar(1,0,Line.ar(randSlice*sliceLen, 
(randSlice*sliceLen)+sliceLen, sliceLen/BufSampleRate.kr(0), 1, 0, 2));
    Out.ar([0,1], bufPlay);
}).send(s);

)


r = Routine { loop {
    m = Synth.new("masher");
    (0.13).yield } //0.13 is hardcoded here but should be equal to sliceLen
}.play;

////////////////////////////////////////////////////////////////////////

This way seems to work fine but a new synth is created for each 
slice(but they are freed by doneAction) but I want to have a one synth 
running, so I want to retrigger the function inside synthdef with that 
instance staying on server as it looks more convenient for this case but 
maybe I'm heading the wrong way. The other problem is; I'm not sure if 
Routine-loop combos are meant for this kind of control. Controlling 
iterations with "wait x seconds" way seemed a bit awkward to me. And 
this approach is unsyncable to outside sources, even to other runing synths.

I'm not really asking help about my code as I'm using it to demonstrate 
my humble approch in my first steps in SC(it's been 3 full days of work 
now). But I think experienced people can see what I am going through so 
they may lead me to the right direction.

I think I should dig for TempoClock for sync issues and retriggering 
stuff right? What about using them in SynthDefs? Is this the wrong 
approach for doing things?

Any help is appreciated.

BB.


More information about the sc-users mailing list