Old 08-30-2008, 10:10 AM   #1
DarkStar
Human being with feelings
 
DarkStar's Avatar
 
Join Date: May 2006
Location: Surrey, UK
Posts: 19,677
Default JS MIDI Questons

I was just looking at the MIDI functions in the JS programming guide and have a few questions:

a ) In the Guide it says "Offset is offset from current block, in samples."

To me this says that "Offset" is an index runnnig from 1 to "number-of-samples-in-block" starting again at 1 in each new block.
Have I got that right?

b) The block size depends on the ASIO buffer latency, e.g. 10ms at 44100Hz = 441 samples. But does a latency of 5ms produce a block of 220 or 221 samples?

c) Also, how can I determine if a particular MIDI message is, for example, on the beat, or on an eighth?

TIA
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
DarkStar is offline   Reply With Quote
Old 08-30-2008, 11:33 AM   #2
IXix
Human being with feelings
 
Join Date: Jan 2007
Location: mcr:uk
Posts: 3,889
Default

Quote:
Originally Posted by DarkStar View Post
a ) In the Guide it says "Offset is offset from current block, in samples."

To me this says that "Offset" is an index runnnig from 1 to "number-of-samples-in-block" starting again at 1 in each new block.
Have I got that right?
Almost. It starts at 0 and runs to samplesblock-1.

Quote:
b) The block size depends on the ASIO buffer latency, e.g. 10ms at 44100Hz = 441 samples. But does a latency of 5ms produce a block of 220 or 221 samples?
I'd suspect it would vary from block to block. If you do this:
Code:
@block
slider1 != samplesblock ? slider1 = samplesblock; sliderchange(slider1);
You may come closer to an answer. Or Justin might tell you.

Quote:
c) Also, how can I determine if a particular MIDI message is, for example, on the beat, or on an eighth?
Can't answer that 'cos I'm in a rush, but it's definitely possible.
IXix is offline   Reply With Quote
Old 08-30-2008, 12:35 PM   #3
DarkStar
Human being with feelings
 
DarkStar's Avatar
 
Join Date: May 2006
Location: Surrey, UK
Posts: 19,677
Default

thanks IXix,
I'll do some more experiments
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
DarkStar is offline   Reply With Quote
Old 08-30-2008, 02:11 PM   #4
DarkStar
Human being with feelings
 
DarkStar's Avatar
 
Join Date: May 2006
Location: Surrey, UK
Posts: 19,677
Default

Ok, some progress, but I can't get the % operation to work.

With the following code:
Code:
@block
  blockno += 1.7;
  rem100 =  blockno % 100;
  slider10 = rem100;
  sliderchange(2^9);
the slider displays integer values between 0 and 100, not the remainders.

What have I got wrong here?
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
DarkStar is offline   Reply With Quote
Old 08-30-2008, 06:09 PM   #5
IXix
Human being with feelings
 
Join Date: Jan 2007
Location: mcr:uk
Posts: 3,889
Default

Quote:
Originally Posted by DarkStar View Post
the slider displays integer values between 0 and 100, not the remainders.
You're right. I don't know exactly why it doesn't work as you'd expect but I can have a guess. I'm sure one of the Cockos team will correct me if I'm wrong.

JS is, as far as I know, C++ in disguise. I was told in another thread that all JS variables are of the floating point type and if I recall correctly, the % operator in C++ only works for integers. It's been a while since I tried so I might be wrong but at the very least, it doesn't do what you'd expect it to.

So what I think happens is that both operands get converted to integers behind the scenes and everything after the decimal point gets discarded and there's no rounding. So if you do 1.7 % 100, what you get back is the result of 1 % 100.

3 % 2 gives a result of 1.
3.5 % 2 still gives a result of 1, even though you'd expect 1.5.

You could try something like this...

Code:
val1 = 3.5;
val2 = 2;
val1 *= 1000; //3500.0
val2 *= 1000; //2000.0
result = (val1 % val2) / 1000; //1.5
IXix is offline   Reply With Quote
Old 09-16-2008, 02:19 AM   #6
DarkStar
Human being with feelings
 
DarkStar's Avatar
 
Join Date: May 2006
Location: Surrey, UK
Posts: 19,677
Default

oops,

didn't reply to this.

Thank you IXix, I came up with a similar workaround.

----
PS Here's a tip for all JS developers:

I've found it very useful to model the JS scripts in a spreadsheet to make sure that the calculations will do what I want.
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
DarkStar is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 04:00 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.