Here is an issue posted by mantsar: SuperDirt does not recognize SynthDef variants · Issue #279 · musikinformatik/SuperDirt · GitHub
SynthDef variants are a bit of a rarely used feauture in SuperCollider, so we never supported them in SuperDirt.
It would impose extra complexity, so I think we won't ...
But, here is how you can add them yourself:
(
SynthDef(\vartest, { |out, freq = 440, amp = 0.2, a = 0.01, r = 1|
// the EnvGen with doneAction: Done.freeSelf frees the synth automatically when done
Out.ar(out, SinOsc.ar(freq!2, 0, EnvGen.kr(Env.perc(a, r, amp), doneAction: Done.freeSelf)));
}, variants: (alpha: [a: 0.5, r: 0.5], beta: [a: 3, r: 0.01], gamma: [a: 0.01, r: 4])
).add;
)
Synth('vartest.alpha'); // works.
// some tests from within sclang
SuperDirt.default = ~dirt;
(type:\dirt, orbit:0, s: 'vartest').play; // works
(type:\dirt, orbit:0, s: 'vartest.alpha').play; // doesn't work.
(type:\dirt, orbit:0, instrument: 'vartest.alpha').play;
// this is how you can do it:
(
~dirt.soundLibrary.addSynth(\vartest,
(playInside: { |e|
var name = if(~variant.notNil) { 'vartest.' ++ ~variant } { 'vartest' };
// make sure that you play it in the ~synthGroup and to the out
(instrument: name, out: ~out, freq: ~freq, amp: ~amp, group: ~synthGroup).play
})
)
)
SuperDirt.default = ~dirt;
(type:\dirt, orbit:0, s: 'vartest').play;
(type:\dirt, orbit:0, s: 'vartest', variant: \alpha).play;
(type:\dirt, orbit:0, s: 'vartest', variant: \beta).play;
// or more general, if you wan to add more variants:
(
~addVariantSynth = { |name|
~dirt.soundLibrary.addSynth(name,
(playInside: { |e|
var instrument = if(~variant.notNil) { format("%.%", name, ~variant) } { 'vartest' };
// make sure that you play it in the ~synthGroup and to the out
(instrument: instrument, out: ~out, freq: ~freq, amp: ~amp, group: ~synthGroup).play
})
)
};
)
(
SynthDef(\vartest_2, { |out, freq = 440, amp = 0.2, a = 0.01, r = 1|
// the EnvGen with doneAction: Done.freeSelf frees the synth automatically when done
Out.ar(out, SinOsc.ar(freq!2, 0, EnvGen.kr(Env.perc(a, r, amp), doneAction: Done.freeSelf)));
}, variants: (alpha: [a: 0.5, r: 0.5], beta: [a: 3, r: 0.01], gamma: [a: 0.01, r: 4])
).add;
)
~addVariantSynth.(\vartest_2);
(type:\dirt, orbit:0, s: 'vartest_2', variant: \alpha).play;
For playing in tidal, you just need to add the variant
variable:
SuperDirt.postTidalParameters([\vartest_2])
-- | parameters for the SynthDefs: vartest_2
let (a, a_p) = pF "a" (Nothing)
(freq, freq_p) = pF "freq" (Nothing)
(r, r_p) = pF "r" (Nothing)