Quantcast

Two Simple Questions about SC code

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Two Simple Questions about SC code

Marigold Maripol
Hi There, SC-

I had two relatively straight-forward questions that I wanted to ask about..

First:

In a simple SynthDef, being added to the Server, like this:
SynthDef("BasicSine",
{|freq, out|
var sin=SinOsc.ar(freq, 0, 0.4)*EnvGen.kr(Env.perc, doneAction:2);
OffsetOut.ar(out, sin)
}).add

Is there a simple way to have this definition include
grouping/nodal-ordering information?  Within a Synth.new call, it is
very clear what to do, but not so much in this form.


Secondly:
I'd like to modulate two instantiations of the above SynthDef, into
one of these:
SynthDef("RingMod",
{|one, two|
var sig;
one = In.ar(~bussa, 1);
two = In.ar(~bussb, 1);
sig = one*two;
Out.ar(0, sig)
}).add;

I'm a little mixed up on the preferred protocol for doing this. Should
the RingMod be in a new group or just at the Tail?

Sorry for the basic questions,
MM

_______________________________________________
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
|  
Report Content as Inappropriate

Re: Two Simple Questions about SC code

ddw_music
Marigold Maripol wrote
In a simple SynthDef, being added to the Server, like this:
SynthDef("BasicSine",
{|freq, out|
var sin=SinOsc.ar(freq, 0, 0.4)*EnvGen.kr(Env.perc, doneAction:2);
OffsetOut.ar(out, sin)
}).add

Is there a simple way to have this definition include
grouping/nodal-ordering information?  Within a Synth.new call, it is
very clear what to do, but not so much in this form.
A SynthDef *defines* what to do, as an abstract entity. A Synth *executes* the design -- the specific actor.

Grouping and node ordering applies only to the Synth. It doesn't make sense to think of this with respect to a SynthDef.

Secondly:
I'd like to modulate two instantiations of the above SynthDef, into
one of these:
SynthDef("RingMod",
{|one, two|
var sig;
one = In.ar(~bussa, 1);
two = In.ar(~bussb, 1);
sig = one*two;
Out.ar(0, sig)
}).add;

I'm a little mixed up on the preferred protocol for doing this. Should
the RingMod be in a new group or just at the Tail?
I think it's just a matter of preference, whichever works for you -- and if it's working for you, don't overthink it. It's OK to start with a provisional approach, and change it later if the requirement changes.

hjh
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Two Simple Questions about SC code

Marigold Maripol
Sorry, I guess what I meant was that I don't quite understand Node
Priority in a Ring Modulator situation..

For instance, if I do something like the following, I need to
instantiate a second RingMod to hear anything...

(
~bussa=Bus.audio(s, 1);
~bussb=Bus.audio(s, 1);
~group = Group.new;

SynthDef("BasicSine",
{|freq, out|
var sin=SinOsc.ar(freq, 0, 0.9)*EnvGen.kr(Env.perc, doneAction:2);
OffsetOut.ar(out, sin)
}).add;

SynthDef("RingMod",
{|one, two|
var sig;
one = In.ar(~bussa, 1);
two = In.ar(~bussb, 1);
sig = one*two;
Out.ar(0, sig)
}).add;

x=Synth.new('RingMod', target: ~group);

)

g=Pbindef(\a,
\instrument, \BasicSine,
\freq, Pwhite(200, 900, inf),
\out, Prand([~bussa, ~bussb], inf),
\dur, 0.2
);
g.play;

On Sun, Jan 1, 2017 at 10:01 AM, ddw_music <[hidden email]> wrote:

> Marigold Maripol wrote
>> In a simple SynthDef, being added to the Server, like this:
>> SynthDef("BasicSine",
>> {|freq, out|
>> var sin=SinOsc.ar(freq, 0, 0.4)*EnvGen.kr(Env.perc, doneAction:2);
>> OffsetOut.ar(out, sin)
>> }).add
>>
>> Is there a simple way to have this definition include
>> grouping/nodal-ordering information?  Within a Synth.new call, it is
>> very clear what to do, but not so much in this form.
>
> A SynthDef *defines* what to do, as an abstract entity. A Synth *executes*
> the design -- the specific actor.
>
> Grouping and node ordering applies only to the Synth. It doesn't make sense
> to think of this with respect to a SynthDef.
>
>
>> Secondly:
>> I'd like to modulate two instantiations of the above SynthDef, into
>> one of these:
>> SynthDef("RingMod",
>> {|one, two|
>> var sig;
>> one = In.ar(~bussa, 1);
>> two = In.ar(~bussb, 1);
>> sig = one*two;
>> Out.ar(0, sig)
>> }).add;
>>
>> I'm a little mixed up on the preferred protocol for doing this. Should
>> the RingMod be in a new group or just at the Tail?
>
> I think it's just a matter of preference, whichever works for you -- and if
> it's working for you, don't overthink it. It's OK to start with a
> provisional approach, and change it later if the requirement changes.
>
> hjh
>
>
>
> --
> View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/Two-Simple-Questions-about-SC-code-tp7629881p7629891.html
> Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.
>
> _______________________________________________
> 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
|  
Report Content as Inappropriate

Re: Two Simple Questions about SC code

Glen Fraser
Hi Marigold.  Be careful about overwriting things like ~bussa and ~group…for example, if you run your code a second time, but don’t redefine your Pbindef ‘g’ with the new variables, you’ll be outputting to the old versions of ~bussa and ~bussb when you call g.play.

Also, when I run your code on a fresh startup of sclang, I get an error because RingMod SynthDef doesn’t yet exist when you try to instantiate your ‘RingMod’ Synth (the def hasn’t yet been received by the Server).  Better to setup the groups and SynthDefs first, then start using them.

You can do this “all at once” (though sequentially) by using a Routine and s.sync to ensure the previous stuff has completed on the Server before moving on to create the Synth.  For example, running the following code works every time from a fresh start of sclang (even without booting the Server).

Note also that s.plotTree or s.queryAllNodes can be very useful for debugging group and Synth/Node ordering issues!

Also, I put the synths generated by your Pbindef into the same group as the RingMod, which I assume is what you wanted to do, by setting the “group” Event key in the Pbindef.

(
s.waitForBoot {
        ~bussa=Bus.audio(s, 1);
        ~bussb=Bus.audio(s, 1);
        ~group = Group.new;
       
        SynthDef("BasicSine",
                {|freq, out|
                        var sin=SinOsc.ar(freq, 0, 0.9)*EnvGen.kr(Env.perc, doneAction:2);
                        OffsetOut.ar(out, sin)
        }).add;
       
        SynthDef("RingMod",
                {|one, two|
                        var sig;
                        one = In.ar(~bussa, 1);
                        two = In.ar(~bussb, 1);
                        sig = one*two;
                        Out.ar(0, sig)
        }).add;
       
        s.sync;
       
        x=Synth.new('RingMod', target: ~group);
        s.plotTree;
}
)


(
g=Pbindef(\a,
        \instrument, \BasicSine,
        \freq, Pwhite(200, 900, inf),
        \out, Prand([~bussa, ~bussb], inf),
        \dur, 0.2,
        \group, ~group
);
z = g.play;
)

z.stop


Again, be careful running the setup code more than once in a row…you’re creating new audio busses each time you run…you might want to add bus cleanup code to CmdPeriod, for example, or else check if ~bussa and ~bussb are already set before initializing them again, e.g.

        ~bussa = ~bussa ?? {Bus.audio(s, 1)};
        ~bussb = ~bussb ?? {Bus.audio(s, 1)};

or the CmdPeriod approach:

        // This will free and set ~bussa and ~bussb to nil whenever command-period is pressed.
        // No need for the Group, they will be deleted automatically when command-period is pressed.
        CmdPeriod.add{ ['bussa', 'bussb'].do{ arg v; topEnvironment[v].free; topEnvironment[v] = nil } };

(N.B. topEnvironment[‘bussa'] is just like accessing ~bussa, but doing it this way allows me to use an array of symbols representing the variable names.)

Hope that helps,
Glen.

> On 02 Jan 2017, at 11:41, Marigold Maripol <[hidden email]> wrote:
>
> Sorry, I guess what I meant was that I don't quite understand Node
> Priority in a Ring Modulator situation..
>
> For instance, if I do something like the following, I need to
> instantiate a second RingMod to hear anything...
>
> (
> ~bussa=Bus.audio(s, 1);
> ~bussb=Bus.audio(s, 1);
> ~group = Group.new;
>
> SynthDef("BasicSine",
> {|freq, out|
> var sin=SinOsc.ar(freq, 0, 0.9)*EnvGen.kr(Env.perc, doneAction:2);
> OffsetOut.ar(out, sin)
> }).add;
>
> SynthDef("RingMod",
> {|one, two|
> var sig;
> one = In.ar(~bussa, 1);
> two = In.ar(~bussb, 1);
> sig = one*two;
> Out.ar(0, sig)
> }).add;
>
> x=Synth.new('RingMod', target: ~group);
>
> )
>
> g=Pbindef(\a,
> \instrument, \BasicSine,
> \freq, Pwhite(200, 900, inf),
> \out, Prand([~bussa, ~bussb], inf),
> \dur, 0.2
> );
> g.play;
>
> On Sun, Jan 1, 2017 at 10:01 AM, ddw_music <[hidden email]> wrote:
>> Marigold Maripol wrote
>>> In a simple SynthDef, being added to the Server, like this:
>>> SynthDef("BasicSine",
>>> {|freq, out|
>>> var sin=SinOsc.ar(freq, 0, 0.4)*EnvGen.kr(Env.perc, doneAction:2);
>>> OffsetOut.ar(out, sin)
>>> }).add
>>>
>>> Is there a simple way to have this definition include
>>> grouping/nodal-ordering information?  Within a Synth.new call, it is
>>> very clear what to do, but not so much in this form.
>>
>> A SynthDef *defines* what to do, as an abstract entity. A Synth *executes*
>> the design -- the specific actor.
>>
>> Grouping and node ordering applies only to the Synth. It doesn't make sense
>> to think of this with respect to a SynthDef.
>>
>>
>>> Secondly:
>>> I'd like to modulate two instantiations of the above SynthDef, into
>>> one of these:
>>> SynthDef("RingMod",
>>> {|one, two|
>>> var sig;
>>> one = In.ar(~bussa, 1);
>>> two = In.ar(~bussb, 1);
>>> sig = one*two;
>>> Out.ar(0, sig)
>>> }).add;
>>>
>>> I'm a little mixed up on the preferred protocol for doing this. Should
>>> the RingMod be in a new group or just at the Tail?
>>
>> I think it's just a matter of preference, whichever works for you -- and if
>> it's working for you, don't overthink it. It's OK to start with a
>> provisional approach, and change it later if the requirement changes.
>>
>> hjh
>>
>>
>>
>> --
>> View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/Two-Simple-Questions-about-SC-code-tp7629881p7629891.html
>> Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> 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/


_______________________________________________
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
|  
Report Content as Inappropriate

Re: Two Simple Questions about SC code

ddw_music
In reply to this post by Marigold Maripol
Another suggestion: currently, RingMod is hardcoded to use only ~bussa and ~bussb. So you can run only the one RingMod process. It's highly recommended to make arguments for the bus numbers.

Actually, the way you wrote RingMod is a bit weird. 'one' and 'two' are signals that you're reading (In.ar) within the def -- so they should not be synth arguments. They should be 'var's instead.

SynthDef("RingMod", { |bussa, bussb|
                var sig, one, two;
                one = In.ar(bussa, 1);
                two = In.ar(bussb, 1);
                sig = one*two;
                Out.ar(0, sig)
}).add;

x = Synth.new('RingMod', [bussa: ~bussa, bussb: ~bussb], target: ~group);

hjh
Loading...