Custom Synthdef not working on Windows

[Edit:] In the initial post the SynthDef segment was forgotten. But this is what my answer referred to.

Hello @Francesco_Corvi, I will answer this question in more detail, and try to describe all possible types of SuperDirt SynthDef variants (as far as I understand). I hope it helps you to solve your problem.

I would also be happy if someone could help me with the terminology.

There are three types of synths:

  1. Standalone SynthDefs
  2. SynthDefs as global effects
  3. Functions

Standalone SynthDefs

If you want to use your own SynthDef, you just need to give it a name (like \sin) and determine the parameters you want to control via TidalCycles. A minimal example could be this:

(
SynthDef(\sin, {|out, freq = 440.0, pan|  
	var sound = SinOsc.ar(freq);
	Out.ar(out, DirtPan.ar(sound, ~dirt.numChannels, pan));
}).add
)

Now you can use it in TidalCycles:

d1 $ n "c a f e" # s "sin"

SynthDefs as global effects

What you practically create with your code above is a responder for a SynthDef, which might not exist.
The addModule function is in my understanding primarily used to add effects. What is generally missing is a SynthDef called 'tanh2' with a parameter param(for demonstration) like:

(
SynthDef('tanh' ++ ~dirt.numChannels, {|param=2|
    var signal;
    signal = In.ar(out, ~dirt.numChannels);
    ...
    ReplaceOut.ar(out, signal)
}).add
)

The 2 in the SynthDef name is the result of adding ~dirt.numChannels using the ++ operator.

The responder should then look something like this:

(
~dirt.addModule('tanh', { |dirtEvent|
dirtEvent.sendSynth('tanh' ++ ~dirt.numChannels,
[
param: ~param,
out: ~out
]
)
}, {~param.notNil})
);

By the way, as effects the SynthDefs are only indirectly controlled when a function is used in TidalCycles. The condition with the notNil determines when the SynthDef is used.

The above example could be used in TidalCycles as

param = pI "param"

d1 $ s "808" # param 4  

Note that I have not used tanh directly.

For a more detailed example you can check the adding-effects file in the SuperDirt hack folder (https://github.com/musikinformatik/SuperDirt/blob/develop/hacks/adding-effects.scd)

Functions

To complete the list: a last variant is the adding of functions.

You can simply add every kind of functions with ~dirt.soundLibrary.addSynth(\name, (play: {}));

A minimal example could be
~dirt.soundLibrary.addSynth(\test, (play: { "Hello World".postln }));
Now you can trigger the function in TidalCycles with

d1 $ s "test"

For a more detailed example you can check the function-hacksfile in the SuperDirt hack folder (https://github.com/musikinformatik/SuperDirt/blob/develop/hacks/function-hacks.scd)

5 Likes