robbert-vdh / nih-plug

Rust VST3 and CLAP plugin framework and plugins - because everything is better when you do it yourself
ISC License
1.53k stars 137 forks source link

Different SysEx messages in the same block all come through as duplicates (VST3) #78

Open ijijn opened 1 year ago

ijijn commented 1 year ago

Hello NIH-ers!

I've run into a problem case whenever more than one SysEx event is processed during the same block using VST3. Basically, the last event appears duplicated as many times as needed instead of each one having its own data.

In contrast, the CLAP version handles this just fine.

Here's some sample JSON debugging output for comparison, where [xx] is used for unprintable characters...

correct (CLAP):

[f0]{"SysEx":{"bar":0,"beats":2.0,"samples":44100,"tempo":120.0,"timing":243,"channel":0,"note":59}}[f7] (98 bytes)
[f0]{"SysEx":{"bar":0,"beats":2.0,"samples":44100,"tempo":120.0,"timing":289,"channel":0,"note":8}}[f7] (97 bytes)
[f0]{"SysEx":{"bar":0,"beats":2.0,"samples":44100,"tempo":120.0,"timing":312,"channel":0,"note":104}}[f7] (99 bytes)
[f0]{"SysEx":{"bar":0,"beats":2.0,"samples":44100,"tempo":120.0,"timing":496,"channel":0,"note":57}}[f7] (98 bytes)

incorrect (VST3):

[f0]{"SysEx":{"bar":0,"beats":2.0,"samples":44100,"tempo":120.0,"timing":243,"channel":0,"note":57}}[f7] (98 bytes)
[f0]{"SysEx":{"bar":0,"beats":2.0,"samples":44100,"tempo":120.0,"timing":289,"channel":0,"note":57}} (97 bytes)
[f0]{"SysEx":{"bar":0,"beats":2.0,"samples":44100,"tempo":120.0,"timing":312,"channel":0,"note":57}}[f7][00] (99 bytes)
[f0]{"SysEx":{"bar":0,"beats":2.0,"samples":44100,"tempo":120.0,"timing":496,"channel":0,"note":57}}[f7] (98 bytes)

Note the truncated trailing [f7] (line 2) and the extra [00] padding (line 3) where the buffer lengths don't match the repeated event. The reported lengths themselves are accurate, however.

Thanks in advance for any thoughts on this 🚀

Iain

robbert-vdh commented 1 year ago

What host did you try this with? It may be an issue with that host. If you check the code here there's nothing that could cause it to read the same buffer multiple times unless the host used the same pointer for each event: https://github.com/robbert-vdh/nih-plug/blob/b31bafdc4b32d8295100a022b42c99f1d8e8340d/src/wrapper/vst3/wrapper.rs#L1143-L1150

And this works just like you'd expect in REAPER 6.79 with multiple SysEx events sent as part of a single process call.

ijijn commented 1 year ago

Ah, thank you for pointing out exactly where in the code this is all going on. As it happens, I'm experiencing this specifically with REAPER (x64) on Windows 11. Hmm, may have to do some further digging to get to the bottom of it ⛏️