# What is tidal doing with SynthDef envelopes?

**URL:** <https://uzu.lurk.org/t/what-is-tidal-doing-with-synthdef-envelopes/2904>\
**Category:** TidalCycles\
**Tags:** questions\
**Created:** [15 February 2021 15:05 UTC](https://uzu.lurk.org/t/what-is-tidal-doing-with-synthdef-envelopes/2904 "2021-02-15T15:05:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![C-o](https://uzu.lurk.org/user_avatar/uzu.lurk.org/c-o/32/1692_2.png) [@C-o](https://uzu.lurk.org/u/C-o)\
**Post date:** [15 February 2021 15:05 UTC](https://uzu.lurk.org/t/what-is-tidal-doing-with-synthdef-envelopes/2904/1 "2021-02-15T15:05:29Z")

</div>

Hi! I'm having some trouble wrapping my head around why tidal is behaving like it is.

Consider this simple example:

```haskell
(
SynthDef.new(\SinTest, {
	|out, pan, rell=1|
	var sig, env;
	env = EnvGen.kr(Env.new([0, 1, 0], [0.1, rell]), doneAction: 2);
	sig = SinOsc.ar;
	sig = sig*env;
	OffsetOut.ar(out, DirtPan.ar (sig, ~dirt.numChannels,pan));
}) .add;
)

```

When I run this SynthDef in SC via `x = Synth.new(\SinTest);` I get a tone with a gain dropoff from 1 to 0 over 1 second. If I run this in quick succession I get multiple tones running independent of one another as expected.

I would expect this (in tidal):

```haskell
d1 
$ struct "1*4"
$ s "SinTest"
# rell 1

```

To result in the same result as manually running `x = Synth.new(\SinTest);` four times over one cycle but this is not the case.  
It's like tidal is sending a doneAction message to the SynthDef making it kill the previous SynthDef resulting in a click effectively making the SynthDef monophonic.  
I can get around this to some extent with this:

```haskell
(
SynthDef.new(\SinTest, {
	|out, pan, sustain=1, decvol=0.5, atk=0.1, dect=0.5, rell=0.1|
	var sig, env, line, vol;
	line = Line.ar(0, 1, sustain, doneAction:2);
	env = Env.new(
		levels:[0, 1, decvol, 0], 
		times: [atk, dect, rell], 
		curve: [-5, 0, -5]);
	vol = IEnvGen.ar(env, line);
	
	sig = SinOsc.ar;
	sig = sig*vol;
	OffsetOut.ar(out, DirtPan.ar (sig, ~dirt.numChannels,pan));
}) .add;
)

```

But this ^ adds some other issues. Like making the envelope duration dependent on the length of the event triggering it.  
Is there a way to make tidal interact with SC in a way that doesn't effect the env? Ie removing the magical doneAction message maybe?

---

<div class="post-metadata">

**Author:** ![C-o](https://uzu.lurk.org/user_avatar/uzu.lurk.org/c-o/32/1692_2.png) [@C-o](https://uzu.lurk.org/u/C-o)\
**Post date:** [15 February 2021 16:03 UTC](https://uzu.lurk.org/t/what-is-tidal-doing-with-synthdef-envelopes/2904/2 "2021-02-15T16:03:49Z")

</div>

I just realized I could just set the sustain way up and bypass the "Tidal-doneAction" that way. So, solved I guess!

---

<div class="post-metadata">

**Author:** ![polymorphic.engine](https://uzu.lurk.org/user_avatar/uzu.lurk.org/polymorphic.engine/32/30_2.png) [@polymorphic.engine](https://uzu.lurk.org/u/polymorphic.engine)\
**Post date:** [15 February 2021 17:34 UTC](https://uzu.lurk.org/t/what-is-tidal-doing-with-synthdef-envelopes/2904/3 "2021-02-15T17:34:54Z")

</div>

Yes, I usually use #legato to avoid this clipping. And yes I think you're right that this happens because SuperDirt frees the synths after playing a note. Not 100% sure though since I didn't read through all of SuperDirts code.
