Leaving (control) busses unassigned?

Hi list,

I am wanting to use In.kr or In.ar in a SynthDef as an optional control
inlet. Here is an example:
SynthDef(\mwe, {arg inBus; Out.ar(0, SinOsc.ar(440 + In.ar(inBus)))}).add

Here, if I don’t specify the inBus argument, it will default to 0 and
lead to unexpected behavior.

Now is there a way to use a In.kr or In.ar in a SynthDef without having to
assign it to a Bus number, so its use can remain fully optional?

I am aware of the .asMap method to plug a bus into a Synth argument.
Here, the disadvantage is, that I have to specify it every time a synth
node is started.

Is there yet another way?

Oh, and besides: How can I quickly turn MouseX.kr into audio rate?

Thanks!
Peter

You can just:

    Out.ar(0, SinOsc.ar(440 + (In.ar(inBus) * useInput)))

where userInput is 0 or 1

Or SelectX

    var input = SelectX.ar(useInput, [0, In.ar(inBus)]);
    Out.ar(0, SinOsc.ar(440 + input))

Remember that when you evaluate SynthDef, its internal structure will no longer change. This is a classic separation between language and server. Check the documentation on that.

My preferred trick, if you prefer to specify a bus number:

var inBus = \inBus.kr(-1);

var busValue = Select.kr(inBus < 0, [In.kr(inBus, 1), 0]);

I think this isn’t true… You would need to specify it only when using it. If unspecified, the control input would take the default value that it’s given in the SynthDef.

hjh

1 Like

I think asMap is very functional to control groups of synths. I think it is just another option. I use it.

Bernardo, James, thanks for both of your suggestions!

James, how does your trick work with regard to putting the string
\inBus.kr(-1)
into the variable?

If someone can furthermore recommend a nice way to render MouseX.kr into
an .ar signal it would be very welcome!

And I am currently looking for documentation on a way to address (.set
or .release) specific nodes in a Group.

Thanks to you all!
P

\inBus.kr(-1) creates a control input named inBus whose default is -1. In that sense it isn’t any different from writing inBus = -1 in the SynthDef argument list. So, if you don’t specify a value, it will be negative and use the 0 branch of the Select instead of the In value.

Actually I don’t use \name.kr syntax generally for simple controls – figures that the one time I do on the forum, it raises confusion :laughing:

hjh

See K2A.ar - K2A | SuperCollider 3.13.0 Help

I like to use .midiratio with these types of inputs as the default value will be 0 and 0.midiratio = 1. This works well if you multiply instead of add, so I try to construct my synthdefs in this way. A way to ensure that you do not feed the control bus a wrong values is to reserve the first control bus for default inputs with a value of 0 and never set this bus to anything other than 0. This way all synthdefs will work with and without control bus inputs.