Curvature key inside a named control rate breaks SynthDef().writeDefFile

Whats going on here?
Using \lin, \exp, \welsh, whatever curvature key inside a named control rate will fail the writing of definition to file. Integers for curvature is fine though.

SynthDef: could not write def: Wrong type.

(
SynthDef(\a, {
    Env.perc(0.0005, 0.01, curve: \curve.kr(\lin)).ar;
	Silent.ar();
}).writeDefFile;
)
(
SynthDef(\b, {
    Env.perc(0.0005, 0.01, curve: \curve.kr(0)).ar;
	Silent.ar();
}).writeDefFile;
)

And using \lin is okay when not calling .writeDefFile

SynthDef(\c, {
    Env.perc(0.0005, 0.01, curve: \curve.kr(\lin)).ar;
	Silent.ar();
}).add;
)

They must be numbers, hence why integers are fine. I don’t believe you can modulate these arguments.

You can modulate the curve argument:

{ Env(curve:Line.kr(-8, 8, 3)).kr(timeScale: 1/10, gate: Impulse.kr(3)) }.plot(3)

But you cannot use a symbol as a default value for a control. So the problem is this:

{ \foo.kr(\lin) }.play
1 Like

TL;DR the better way to control envelope shapes is by sending the envelope as an array. There are examples in the help: Specifying an envelope for each new synth for one.

Why is that?

Each envelope segment is encoded as four values: target level, duration, shape number and curvature.

Note that this is not a single value for the shape.

All values in the server must be real numbers. If a curvature value can be any real number, and shape must also be a number, then you can’t tell the difference between 1.0 = curvature or 1.0 = exponential curve. It has to be two numbers.

myEnv.asArray automatically looks up the shape numbers for you (Env.shapeNumber) and produces the two values, so it will be much much simpler to follow the model of the link above.

You could write the Env into the synth and override the two values with your own control inputs, but this is a lot trickier (I tried it and got confused) – too much trouble.

hjh

Thanks everybody!
Using symbols like \lin, \exp, \sin, \wel is totally fine right. In Env.new. values arg. And I always tend to use -10 between and 10 for curve :slight_smile: . But through a named control → I expected the curve arg in Env.perc could be set by a named control passing a symbol. Yaaa…
Aand on top of that I hit an error message only when using .writeDefFile on a SynthDef.
Ended up confusing myself indeed.

Also note that the curvature can be an array of values, one for each line segment:

Env.perc(0.01, 0.01, 1, 4).plot

// same as

Env.perc(0.01, 0.01, 1, [4, 4]).plot

// but you can also specify a different curvature for each segment

Env.perc(0.01, 0.01, 1, [-4, 2]).plot

// this is also true for 'custom' envelopes

Env([0, 0.5, 0.3, 1], [0.005, 0.005, 0.01], [-2, 1, 5]).plot

// same envelope with different curvatures

Env([0, 0.5, 0.3, 1], [0.005, 0.005, 0.01], [4, -5, -2]).plot
1 Like