Custom Synthdef not working on Windows

Hi everyone I am having a problem with using custom synthdef inside Supercollider on windows and tidalcycles.
Let's say I evaluate this code in SC to create a super simple synthdef:

(

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

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


)

The code is executed correctly but then when I try to use the synthdef I get this message:

*** ERROR: SynthDef tanh2 not found
FAILURE IN SERVER /s_new SynthDef not found

does anyone has a clue of what is going on here?
and why does tanh becomes tanh2?
The same code works on macOs...

[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

hey thanks for your kind and detaild response... I made a mistake when pasting the code in the example before and I missed the actual synthdef... now is correct and still not working

No problem and a pity that it did not solve your problem. I have tested your code under macOS and as you have already written, it works for me too. I don't have a Windows computer at hand so fast, so hopefully someone else here knows more.

1 Like

It seams really werid, anyway your comment will be helpful to others for sure!

1 Like

I cannot solve your problem right now, but I can explain why tanh becomes tanh2.
It's simply because you append ~dirt.numChannels to the "tanh" symbol (and for stereo this is 2 by default).

1 Like

Hi Francesco.

I tried your SynthDef here and it worked when I changed the parameter tanh to another name (xtanh).

My guess is that tanh is already being used and this is confusing either in SC or Tidal sides.

In the tidal side I put p 1 $ "bd" # pF "xtanh" 5

I hope that helps

1 Like

Thanks gli. Yes I already tried this using other names but still not working... tanh stands for hyperbolic tangent so I guessed that could make SuperCollider confused. So on your machine if you call the SynthDef tanh it doesn't work but change does?

Hi.

Yes, that's what is happening here: using tanh as an argument it make the SysnthDef not work and and another name make it work. I can even try changing this while the tidal pattern is running.

I also put a default value in the argument like so | out, xtanh = 1 |, but I don't think this plays any role on making it work.

1 Like

A fresh reistall of everything solved the issue.... We will never know :rofl:

1 Like