js-object timing issue

Nov 29, 2011 at 2:40pm

js-object timing issue

hey list,

i just made a js script, wich does a pretty simple thing:
creating a ramp from 0 to n-1 with a delay(ms) after each
increment. (of course something similar is already done as
max externals, but for now i like to understand and recap things with scripting)

when adjusting a very small ms delay value (as argument of the js object)
i get irregular output of js object. it ramps, but not to the
expected value (n-1). in the appended patch i like to ramp to the value 1999. with 20ms everthing working fine, but the smaller the interval gets the bigger the difference between n-1 and the outputs gets. for example:
each time i ramp with 2 ms it stop at different vals. 1976, 1997 etc.

why is it?
is this because the js stuff is executed at low priority at the max sheduler?

i also looked for an alternative to the “task”-way,
but settimeout does not seem to work within the js object…
any workarround within javascript?

here is the patch and i append the javascript file:

– Pasted Max Patch, click to expand. –

BTW. iam on a macbook 10.6.8 with max 5.1.9.

thanks for your help,

greetings.
johannes

Attachments:
  1. jtest1.js
#60339
Nov 29, 2011 at 4:17pm

Hello,

have you tried something like ramp.immediate = 1 to force your function in high priority thread ?

#217163
Nov 29, 2011 at 5:09pm

thanks vanille,

“rep.immediate = 1;” fixed it. i made a test where i count from 0 to 1.000.000 with 2 ms delay and it absolutly matches!

nice,
j

#217164

You must be logged in to reply to this topic.