How to Use .NET Math Class Functions in Show Notes

On Show Notes Page (https://www.cantabilesoftware.com/guides/showNotes), there is a reference to the Variables that can be used within Show Notes (https://www.cantabilesoftware.com/guides/variables). That page then mentions the typical Cantabile Functions (https://www.cantabilesoftware.com/guides/functions). This is where it gets a bit confusion, as that page further references the .NET Math Class Functions can be used (https://learn.microsoft.com/en-us/dotnet/api/system.math?redirectedfrom=MSDN&view=net-6.0). This is just for reference as to how I got to these more complicated functions.

There are many functions listed that could be used in Show Notes to modify the display; however, I cannot get any of those .Net Math Class Functions to work.

The specific example I’m trying to do is bind the “Tempo LEDs” to the “Output Port - Onscreen Keyboard” to massage into a blink a dot. If you have worked with a 4/4 output from Tempo LEDs, it outputs and repeates the numeric sequence 32, 33, 34, 35. This numeric sequence can easily be displayed on the Show Notes. If the time signature changes, the numeric sequence changes. My thoughts were to use DivRem (Sequence, 2) == 1, then do X, else do Y.

This is what I believe the format to be, but it doesn’t work:

$(DivRem(cc(127,1),2))

cc(127,1) is the output from the Tempo LEDs and is 32, 33, 34, 35. I would expect the DivRem function to output 0, 1, 0, 1, 0, 1, 0… etc. as the transport is playing. But, the Show Notes displays this:

image

The workaround it to hardcode cc(127,1)==32, 33, etc. and act with nested if/then statements. But, those .NET Math Functions might be useful someday if I could get them working. I fear it may be because of using 7-bit cc constructs and DivRem is expecting formal 8, 16, 32, 64 bit integers.

Tried this out to bounce a square every beat.

$(tempo) BPM $(cc(127,1)==32 ? “:green_square: " : cc(127,1)==33? " :green_square:”:cc(127,1)==34 ? “:green_square: " : " :green_square:”)

Which shows this in Show Notes (the box moves right/left every beat):

image

But still no luck with the .NET Math Functions.

One wrinkle may be that Cantabile has two separate expression engines. See this post by Brad:

I am not sure if this is the issue in this case …

The issue here is the DivRem function has an [out] parameter which makes it incompatible with the expression engine.

To work around this, I’ve added a modulus (remainder) operator for the next build. To get the remainder after division by 2, you’ll be able to use this:

$(cc(127,1) % 2)

I was replying when I saw Brad’s response. Based on this response, I can assume that some, if not all, of the functions listed on the .NET Math Class Functions page are not accessible in the Show Notes. Good to know; I’ll not delve into those functions.

Thank you both for the suggestions and fixes.

Basically anything that takes byval inputs and returns a simple, single value should work fine.

I should update the registration of these functions with the expression engine to not register incompatible ones.