musikinformatik/SuperDirt

module arguments default to 0 instead of default value given in SynthDef

ahihi opened this issue · 6 comments

ahihi commented

supercollider 3.11.2, superdirt 1.7.3, macos 10.14

i'm trying to write a custom module for superdirt and noticed that all arguments i don't explicitly pass from tidal are defaulting to 0, rather than the default value i specify in the SynthDef. for example:

(
SynthDef("argtest" ++ ~dirt.numChannels, { |out, arg1=1, arg2=2|
	var sig;
	sig = In.ar(out, ~dirt.numChannels);
	[arg1, arg2].poll;
	ReplaceOut.ar(out, sig);
}).add;

~dirt.addModule('argtest', { |dirtEvent|
	dirtEvent.sendSynth('argtest' ++ ~dirt.numChannels,
		[
			arg1: ~arg1,
			arg2: ~arg2,
			out: ~out
		]
	);
}, { ~arg1.notNil || ~arg2.notNil });
)
d1 $ n "<0 1 2 3>*8" # s "amencutup" # pF "arg1" 5

prints:

UGen Array [0]: 5
UGen Array [1]: 0

instead of the expected 5 and 2.

trying to figure out whether my module code is wrong somehow, i also tested with the built-in tremolo effect (defined here and here):

d1 $ n "<0 1 2 3>*8" # s "amencutup" # tremolorate 16

because of the default tremolodepth = 0.5 i would expect to hear some tremolo here, but there is none, suggesting that this argument is also defaulting to 0.

is this intended behavior? can i work around it somehow?

A module doesn't know of the SynthDef args by default. But normally, you don't need to define a module if you just want to play a Synth defined in a SynthDef. Have you tried to just define the SynthDef and play it? You'll have remove the module or rename the SynthDef to make it work.

ahihi commented

i am intentionally defining modules in order to add some effects that i can use with any synth. so there is no way around having to specify in tidal every argument that should have a nonzero value?

No, you should be able to just use the default values if you call the function dirtEvent.sendSynth(~instrument, ~argNames) (see the module ~dirt.addModule('sound',),

(the ~argNames are generated automatically in DirtEvent from the ~instrument name).

ahihi commented

deleted my previous comment because i read too hastily and didn't realize ~argNames is an actual existing variable! 😅

ok, so all i needed to do was

(
~dirt.addModule('argtest', { |dirtEvent|
	dirtEvent.sendSynth('argtest' ++ ~dirt.numChannels, ~argNames);
}, { ~arg1.notNil || ~arg2.notNil });
)

that works, thank you!! :)

Great!

a little more efficient (inlined "or"):

(
~dirt.addModule('argtest', { |dirtEvent|
	dirtEvent.sendSynth('argtest' ++ ~dirt.numChannels, ~argNames);
}, { ~arg1.notNil or: { ~arg2.notNil } });
)