Selecting predesigned ENVs within a synthdef

I wrapped a GrainBuf based synthdef to make it usable inside an ofxSuperCollider driven application.
Everything works flawlessly, but i can’t figure out how to make a user-selectable predesigned Env.
I thought Select would make it, but it looks it doesn’t…

Can you help me finding a correct approach?
Here’s my code so far. Everything works good, but the envelope selection (it will just play the default hanning window):

(///// GranularSampler
		arg out=0;
		var t, signal, spd, buf,bucle, start, gain,dur,envtyp,selenv;

		envtyp=[ //can be envs selected like this?
			Env([0, 1,0], [0.5, 0.5], \sine),
			Env([0,1,1,0], [0.01,1, 0.01], [0,0,0])
		//using z as an envelope for grainbuf
		z = Buffer.sendCollection(s, selenv, 1);, t, dur, buf, spd, start,2,0,z,512)*gain;, signal);

Select will only select signals (not Objects) - so you need to give Select an array of EnvGens not an array of Env !

I’m away from my machine but try:

			Env([0, 1,0], [0.5, 0.5], \sine),
			Env([0,1,1,0], [0.01,1, 0.01], [0,0,0])
		].collect{|env|, /* any other appropriate args here */);
1 Like

Thanks for the tip!

unfortunately, it looks like that is not working. As far as i could discover, buffers cannot be defined within a synthdef and localBuf has to be used instead. But even like that, i’m not managing to make it work.

I’ll go on with the research and post my findings, even if those may be too obvious for most of the people here!

Even if you removed the envelope-type selection, there still isn’t a way to generate the envelope in real-time and instantaneously populate a buffer with it, on the server side.

So the problem really has nothing to do with choosing the envelope – it’s that the whole approach of trying to set up the envelope in the server is not right for GrainBuf.

GrainBuf expects grain envelopes to be provided in buffers.

So, you can make n buffers, one for each envelope, in advance, using language-side operations.

Then just pass the buffer number as an argument to the synth, and you’re done, all of that complexity is gone.


1 Like