Possible bug: Unrecognized function clamp()

I am getting an “unknown name” semantic error on the clamp() function in the .cantabileControlCurve file I am developing. The expression is:

"scalarToPosition(x)": "clamp( ((log(x,10)*20 >= -6) ? ((log(x,10)*20 + 26.8235294118) * 31.1666666641) : (826 - Sqrt(-34869 - 220660*log(x,10)))) / 1023, 0, 1)",

(This relates to my development of control curves that match TotalMix.)

The error occurs when I start up Cantabile (which apparently parses all available .cantabileControlCurve files in the Resources directory on launch):


I’m looking at the function reference at Functions - Cantabile - Software for Performing Musicians.

When I remove the clamp() call the expression parses and Cantabile implements the new control curves as expected.

Not sure if this is an @brad question, or whether I’ve misunderstood control expressions.

Hi @ClintGoss,

I always confuse even myself a little with this math expression stuff.

Cantabile has two expression engines:

  • The main one for general purpose use in sysex and string variable expressions and,
  • a more highly optimized, numeric only one used control curves.

The numeric only one is more highly optimized (and limited) because it needs to be fast for high update rate of level meters.

All that’s to say there’s two expression engines that are similar, but different and the numeric one doesn’t have the clamp function.

But you can probably add it yourself with another definition entry similar to this:

"clamp(x,a,b)": "x < a ? a : (x > b ? b : x)"

(I haven’t tested this, let me know if it works or not)

Or, if you can wait to the next build I can add it?

1 Like

This works … Thanks!!

The declaration of clamp() can appear before or after it is used, so it must be a multi-pass parser.

I’ve done minimal testing on

"clamp(x,a,b)": "x < a ? a : (x > b ? b : x)"

… and it seems to work as expected.

Hi Client,

Thanks for the update, glad that worked.

Not really, it’s just that the expression variables are resolved at eval time - which is always after everything has been parsed.

btw: I’ve added a clamp function for the next build - so you should be able to get rid of your custom declaration once that’s released. Not sure if you’ll get an error - possibly not.

1 Like