determine synthDef arguments from other arguments?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

determine synthDef arguments from other arguments?

Peter P.-2
Hi list,

I am trying to determine a default value for the "len" argument in the
following synthdef, which I would like to default to the length of the
buffer passed to the same synthdef as "buf" argument, with a conversion
from sample frames to seconds.

SynthDef(\turntable, {arg buf, rate=1, start=0, len=buf.numFrames/buf.sampleRate, amp=0, fadeIn=0, fadeOut=0, pan=0;
    var fromBuf = PlayBuf.ar(1, buf, rate, startPos:start*BufSampleRate.kr(buf));
    var fromEnv = EnvGen.kr(Env.linen(fadeIn, len-(fadeIn+fadeOut), fadeOut), doneAction:2);
    Out.ar(0, Pan2.ar(fromBuf * fromEnv * amp.dbamp, pos:pan));
    }).add;

If i start one voice of that synth with
        Synth.new(\turntable, [\buf, ~buf1, \start, 15]);
its length seems to be 0 seconds.

Can I execute something like
        arg buf, len=buf.numFrames/buf.sampleRate
in the argument declaration at all? Is there a smarter way to have len
default to the buffer lengths (in seconds)?

No errors are posted upon evaluating the synthdef. Trying to debug this
further I wonder what the best way would be to have the synth post the
value of its len argument to the console window.

Thanks for all ideas!
Peter

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Reply | Threaded
Open this post in threaded view
|

Re: determine synthDef arguments from other arguments?

Eli Fieldsteel
My approach would be to "initialize" len when the Synth is called. I am not sure there is a clean or sensible way to do this within the SynthDef. SynthDefs are built only once when sent to the server, while the Buffer being used is a component that can be changed or chosen dynamically.

I would do this:

Synth.new(\turntable, [\buf, ~buf1, \start, 15, \len, ~buf1.duration]);

And not worry about an initial value being provided at SynthDef load time.

Eli
Reply | Threaded
Open this post in threaded view
|

Re: determine synthDef arguments from other arguments?

Peter P.-2
* Eli Fieldsteel <[hidden email]> [2017-05-09 20:49]:
> My approach would be to "initialize" len when the Synth is called. I am not
> sure there is a clean or sensible way to do this within the SynthDef.
> SynthDefs are built only once when sent to the server, while the Buffer
> being used is a component that can be changed or chosen dynamically.
>
> I would do this:
>
> Synth.new(\turntable, [\buf, ~buf1, \start, 15, \len, ~buf1.duration]);
Which is what I do by now. Thanks for your confirmation.

best, P

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Reply | Threaded
Open this post in threaded view
|

Re: determine synthDef arguments from other arguments?

ddw_music
In reply to this post by Peter P.-2
Peter P.-2 wrote
Can I execute something like
        arg buf, len=buf.numFrames/buf.sampleRate
in the argument declaration at all?
No. Defaults for SynthDef arguments must be literal numbers (Integer or Float) or literal arrays of numbers -- #[0, 1, 2] and you may not omit # here -- only. Expressions will not work.

I've written the technical explanation to the list probably a dozen times over the last few years:

http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/initializing-arguments-in-Synthdef-function-tp4653656p4654877.html

Is there a smarter way to have len
default to the buffer lengths (in seconds)?
I've sometimes done this:

SynthDef(\something, { |bufnum, len =-1|
    var length = Select.kr(len < 0, [len, BufDur.kr(bufnum)]);
    ... as you like...
}).add;

hjh
Reply | Threaded
Open this post in threaded view
|

Re: determine synthDef arguments from other arguments?

Peter P.-2
Hi,

* [hidden email] <[hidden email]> [2017-05-10 01:25]:
> Peter P.-2 wrote
> > Can I execute something like
> > arg buf, len=buf.numFrames/buf.sampleRate
> > in the argument declaration at all?
>
> No. Defaults for SynthDef arguments must be literal numbers (Integer or
> Float) or literal arrays of numbers -- #[0, 1, 2] and you may not omit #
> here -- only. Expressions will not work.
Ok.

> I've written the technical explanation to the list probably a dozen times
> over the last few years:
>
> http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/initializing-arguments-in-Synthdef-function-tp4653656p4654877.html
Thanks for this link and the explanation therein!
 
> > Is there a smarter way to have len
> > default to the buffer lengths (in seconds)?
>
> I've sometimes done this:
>
> SynthDef(\something, { |bufnum, len =-1|
>     var length = Select.kr(len < 0, [len, BufDur.kr(bufnum)]);
>     ... as you like...
> }).add;
Thank you! This looks very good and I will follow that example!

cheers, P

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Reply | Threaded
Open this post in threaded view
|

Re: determine synthDef arguments from other arguments?

Kuivila, Ronald
In reply to this post by ddw_music
Hi James,

This got me thinking....
The underlying problem here is there is no 'nil' on the server so there is no way to recognize uninitialized values.
It would be really great if we could come up with something to do this as simple as the common language expression

        x = x ? defaultValueOfX;

So, this might be worth a little bit of discussion.
For example, using inf as the flag allows your trick to support any finite value
(as opposed to the positive values appropriate to buffer lengths).

SynthDef(\something, { |bufnum, len = inf|
   var length = Select.kr(len >= inf, [len, BufDur.kr(bufnum)]);
   ... as you like...
}).add;

It is tempting to come up with something more streamlined like

x = x.ifInf(y);

Dunno if that is sprawl or useful.

Cheers,

RJK

> On May 9, 2017, at 7:22 PM, [hidden email] wrote:
>
> I've sometimes done this:
>
> SynthDef(\something, { |bufnum, len =-1|
>    var length = Select.kr(len < 0, [len, BufDur.kr(bufnum)]);
>    ... as you like...
> }).add;
>


_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Reply | Threaded
Open this post in threaded view
|

Re: determine synthDef arguments from other arguments?

julian.rohrhuber
in the osc spec, nil exists, so that would be possible, and a good idea.

> On 10.05.2017, at 14:13, Kuivila, Ronald <[hidden email]> wrote:
>
> Hi James,
>
> This got me thinking....
> The underlying problem here is there is no 'nil' on the server so there is no way to recognize uninitialized values.
> It would be really great if we could come up with something to do this as simple as the common language expression
>
> x = x ? defaultValueOfX;
>
> So, this might be worth a little bit of discussion.
> For example, using inf as the flag allows your trick to support any finite value
> (as opposed to the positive values appropriate to buffer lengths).
>
> SynthDef(\something, { |bufnum, len = inf|
>   var length = Select.kr(len >= inf, [len, BufDur.kr(bufnum)]);
>   ... as you like...
> }).add;
>
> It is tempting to come up with something more streamlined like
>
> x = x.ifInf(y);
>
> Dunno if that is sprawl or useful.
>
> Cheers,
>
> RJK
>
>> On May 9, 2017, at 7:22 PM, [hidden email] wrote:
>>
>> I've sometimes done this:
>>
>> SynthDef(\something, { |bufnum, len =-1|
>>   var length = Select.kr(len < 0, [len, BufDur.kr(bufnum)]);
>>   ... as you like...
>> }).add;
>>
>
>
> _______________________________________________
> sc-users mailing list
>
> info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
> archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
> search: http://www.listarc.bham.ac.uk/lists/sc-users/search/


_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Reply | Threaded
Open this post in threaded view
|

Re: determine synthDef arguments from other arguments?

5tefan


Am 2017-05-10 um 15:04 schrieb [hidden email]:
> in the osc spec, nil exists, so that would be possible, and a good idea.

+1, +1, +1

(I've always been convinced nulls or nils aren't possibly because of the
specification... should've read it. Really true?)

Stefan

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/