Page 1 of 1

Posted: 03 Dec 2008, 06:59
by woodslanding
I'm trying to write a simple function:

function toDecimal(val : integer) : integer;
begin
val := val * (100/127);
toDecimal := val;
end;

this syntax, as suggested for pascal, isn't working--it wants parentheses, which would make an endless recursive loop, right??

RETURN is also unrecognized.

tips??

thanks!
-eric

Posted: 03 Dec 2008, 14:23
by bsork
I don't quite get this one; it's called toDecimal, but returns integer? Is it supposed to convert MIDI's 0~127 to 0~100? Anyway - here are two varieties, one integer and one single.

Code: Select all

function toDecimal(val : integer) : integer;
begin
   result := val * 100 DIV 127;
end;

Code: Select all

function toDecimal(val : integer) : single;
begin
   result := val * 100 / 127;
end;
I'm not totally sure about this, but I think you have to use "Result :=" and not the function name within Usine scripts. It might depend on something syntatic that has escaped my attention. At least it didn't work with these two examples.

If you like to do it a little bit more "proper", you can typecast val in second example:

Code: Select all

   result := single(val) * 100 / 127;

Posted: 03 Dec 2008, 18:36
by woodslanding
just needed to know the word RESULT.

yes, doDecimal is a misnomer. Just want to show midi values in two digits. I'll actually trunc the result....

Thanks!