|
|
|
10-13-2020, 08:00 AM
|
#1
|
Human being with feelings
Join Date: Jun 2007
Location: Berlin, Germany
Posts: 78
|
JSFX: midirecv doesn't provide offset?
Hellosium,
I'm playing around with receiving MIDI messages in JSFX plugins, so I came across the midirecv command, duh.
As I understand it, calling midirecv(offset,msg1,msg2,msg3) in the @block section should put various hex message fragments into the assorted msg* arguments, and the offset argument should contain the offset in samples in the current sample block, at which the currently received MIDI message happened.
But when I call midirecv as directed, the offset argument is always 0, it never changes. I even tested it by storing the max(offset,previousMax) value in a separate variable.
I can hammer the MIDI controller's keys as much as I want, but I just always seem to hit each key at exactly 0 samples block offset... that's definitely way too accurate for my playing skills.
So... is there a particular reason for that? "Anyone else getting this"? Am I doing something wrong? Is the offset value broken? Was it maybe deprecated at some point, and only left in the command to avoid compatibility issues with older JSFX?
Would be grateful for any hints or help.
(Using Reaper 6.14, but also happened in earlier v6 releases.)
Last edited by caleb82; 10-13-2020 at 08:02 AM.
Reason: Added Reaper version
|
|
|
10-13-2020, 12:40 PM
|
#2
|
Human being with feelings
Join Date: Sep 2008
Location: Sweden
Posts: 7,432
|
I am not sure... but it seems to me that his would be related to the buffer size. If you have the buffer size low enough, @block gets called so often that any MIDI event is always at the beginning, at offset zero. Have you tried different buffer sizes?
Maybe try also a MIDI item with the MIDI events carefully positioned (manually) to something that would seem to require an offset different from zero?
Or, it could be just as you surmise, that this was once useful but has been removed. For the MIDI JSFX that I have coded, I have never looked at the offset, I only output with the same offset as I get at the input.
__________________
// MVHMF
I never always did the right thing, but all I did wasn't wrong...
|
|
|
10-13-2020, 01:31 PM
|
#3
|
Human being with feelings
Join Date: May 2006
Location: Surrey, UK
Posts: 19,681
|
I have never used that format of midirecv.
I use:
Code:
midirecv(mpos, msg1, msg23);
msg = (msg1 / 16) | 0;
msg_channel = 1 + msg1 - (msg * 16); // result is 01 .. 16
msg_number = msg23 & 127;
msg_value = (msg23 / 256) | 0;
// .... and so on
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
|
|
|
10-13-2020, 01:44 PM
|
#4
|
Human being with feelings
Join Date: Sep 2008
Location: Sweden
Posts: 7,432
|
Quote:
Originally Posted by DarkStar
I have never used that format of midirecv.
I use:
Code:
midirecv(mpos, msg1, msg23);
msg = (msg1 / 16) | 0;
msg_channel = 1 + msg1 - (msg * 16); // result is 01 .. 16
msg_number = msg23 & 127;
msg_value = (msg23 / 256) | 0;
// .... and so on
|
We're talking about what you call mpos, there. This should be the offset of the MIDI event inside the block, but according to the OP it is always zero.
Code:
midirecv(offset, msg1, msg23)
// ...
midisend(offset, msg1, msg23);
This is the way it looks in all my JSFX where I transform MIDI events. As I mentioned, I never touch the offset, only pass it right through.
__________________
// MVHMF
I never always did the right thing, but all I did wasn't wrong...
|
|
|
10-13-2020, 03:09 PM
|
#5
|
Human being with feelings
Join Date: May 2006
Location: Surrey, UK
Posts: 19,681
|
That's why I suggested using the syntax I posted.
Here it is in (a modified) MIDI_Logger:
As you can see the Offset (named "ts") can be non-zero. But, of course, if the transport is stopped, then the offset will always be zero. Could that be what's happening?
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
|
|
|
10-14-2020, 12:00 AM
|
#6
|
Human being with feelings
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,653
|
Quote:
Originally Posted by DarkStar
But, of course, if the transport is stopped, then the offset will always be zero.
|
I don't think so, because even with transport stopped I can still play live MIDI, so that still has an offset.
|
|
|
10-14-2020, 05:46 AM
|
#7
|
Human being with feelings
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,781
|
I can't believe, the 4 parameter version of midireceive() - which I always used - does not work correctly,.
This would be a very severe bug...
... Tested:
works correctly.
-Michael
|
|
|
10-14-2020, 07:37 AM
|
#8
|
Human being with feelings
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,653
|
Quote:
Originally Posted by mschnell
... Tested:
works correctly.
|
Confirmed for both midirecv(ofs, msg1, msg23) and midirecv(ofs, msg1, msg2, msg3).
This made me wonder if my MIDI controller would use some offsets more than others, so I wrote this:
Code:
desc:MIDI offset test
@block
len = samplesblock;
wrap = (1 << ceil(log(sqrt(len))/log(2))) - 1;
while(midirecv(ofs, msg1, msg2, msg3)) (
max_n = max(buf[ofs] += 1, max_n);
midisend(ofs, msg1, msg2, msg3);
);
@gfx
gfx_x = gfx_y = 8;
scale = 1/(max_n + 1);
i = 0;
loop(len,
(n = buf[i]) > 0 ? (
gfx_set(0, 1, 2/3, (n + 1) * scale);
) : (
gfx_set(1, 0.25, 0.25, 1);
);
gfx_drawchar('*');
!((i += 1) & wrap) ? (
gfx_x = 8;
gfx_y += gfx_texth;
);
);
At my end it seems to favor offsets <= 4, especially exactly 4 (tested at both 64 and 128 buffer). I'm not sure why though...
Last edited by Tale; 10-14-2020 at 07:54 AM.
Reason: Made line wrap dependent on buffer size
|
|
|
10-14-2020, 02:55 PM
|
#9
|
Human being with feelings
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,781
|
I tested by using the stock JSFX CC LFO.
Here - not doing a really decent test - I seem to get all numbers < blocksize equally distributed.
-Michael
|
|
|
10-21-2020, 06:35 AM
|
#10
|
Human being with feelings
Join Date: Jun 2007
Location: Berlin, Germany
Posts: 78
|
Sorry, I totally got distracted by life and forgot about this thread, busy weeks at work.
Quote:
Originally Posted by mschnell
... Tested:
works correctly.
|
How exactly did you test it? Only the CC LFO?
Did you use a MIDI controller? Virtual MIDI keyboard?
I could never get any other offset value than 0, but I never thought about the CC LFO, will give that a spin.
|
|
|
10-21-2020, 07:48 AM
|
#11
|
Human being with feelings
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,653
|
Notes from REAPER's Virtual MIDI Keyboard indeed always have an offset of 0. But if you draw some MIDI notes in MIDI item, and optionally humanize them, then you're bound to see offsets > 0.
|
|
|
10-21-2020, 01:40 PM
|
#12
|
Human being with feelings
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,781
|
Quote:
Originally Posted by Tale
Notes from REAPER's Virtual MIDI Keyboard indeed always have an offset of 0. But if you draw some MIDI notes in MIDI item, and optionally humanize them, then you're bound to see offsets > 0.
|
Supposedly anything derived from activity in the GUI will not feature a decent Midi event offset.
-Michael
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 11:43 AM.
|