Emute-Lab-Instruments / uSEQ

18 stars 0 forks source link

Function returns number in REPL but throws 'not a number' when passed to a1 #111

Open j0euk opened 2 weeks ago

j0euk commented 2 weeks ago

Hi all,

I was at the workshop in Brighton on Sunday 30th June. I wrote a function that seemed to work OK in the REPL (is this the right word if it's an editor?) but caused an error when sending to one of the analogue outputs.

The function definition is:

(defn steps [numsteps value] (/ (floor (+ 0.5 (* numsteps value))) numsteps))

The function is meant to 'quantise' an input value 0.0-1.0 to a discrete number of 'steps' - e.g. (steps 4 x) can return only 0.0, 0.25, 0.5, 0.75 or 1.0 for any value of x between 0.0 and 1.0. (I know there's a built-in step function - more on that below.)

The function seemed to work fine in the REPL - for example, hitting Ctrl+Enter repeatedly on (steps 20 (ain1)) while slowly turning the ain1 knob returned the expected result - that is, the value of ain1 rounded to the nearest multiple of 0.05.

However, trying to pass this function to a1 by doing (a1 (steps 20 (ain1))) gave an error message along the lines of 'function of a1 does not evaluate to a number'.

Just to be sure - (type (steps 20 (ain1))) returned float, so the function was definitely evaluating to a number when it was being executed in the REPL.

(Using the built-in step function as a workaround seemed to work fine when I tried it, so it seems to be an issue with the function I wrote above in particular - assuming it's not a programmer's error, the same issue could affect other functions for which no workaround is easily available.)

Let me know if any other details needed.