Welcome to %s forums

BrainModular Users Forum

Login Register

script function syntax??

I need help on a Patch
Post Reply
woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 03 Dec 2008, 06:59

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
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

bsork
Site Admin
Posts: 1334
Location: Asker, Norway
Contact:

Unread post by bsork » 03 Dec 2008, 14:23

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;
Bjørn S

woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 03 Dec 2008, 18:36

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!
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

Post Reply

Who is online

Users browsing this forum: No registered users and 69 guests