obiwanjacobi / vst.net

Virtual Studio Technology (VST) for .NET. Plugins and Host applications.
https://obiwanjacobi.github.io/vst.net/index.html
GNU Lesser General Public License v2.1
420 stars 53 forks source link

Sending several simultaneous events to VST #64

Closed SirLyoshyk closed 1 year ago

SirLyoshyk commented 2 years ago

Describe the bug Hello. I'm trying to create a simple multichannel VST host and found an issue that doesn't allow me to use vst.net properly. When I'm sending several events at once to pluginContext.PluginCommandStub.ProcessEvents some of the events don't reach the VST plugin. These cause missing notes or notes that sound forever as noteoff event wasn't received. This issue especially hurts on pad tracks where we have a lot of simultaneous notes. It looks like ProcessEvents doesn't send events immediately to VST plugin, but sometimes keeps these events in some kind of buffer, because when we are sending next events, sometimes missing events are sent too.

To Reproduce Steps to reproduce the behavior:

  1. Load vst with VstPluginContext.Create(VSTPath, hcs)
  2. Send 4-8 noteon events and after some time the same 4-8 noteoff events using pluginContext.PluginCommandStub.Commands.ProcessEvents(vstEvents)
  3. Sometimes some of notes will stuck

Expected behavior All events must be passed to VST plugin as soon as received so notes will stop playing properly.

Additional info Visual studio communiti 2022 v.17.2.2 VST.NET2-Host 2.0.3 midiMonitor x64 1.3

SirLyoshyk commented 2 years ago

Not important. I've switched to another framework.

fgoulet commented 2 years ago

@SirLyoshyk Out of curiosity, witch framework did you switch to ?

obiwanjacobi commented 2 years ago

I still want to research this.

obiwanjacobi commented 1 year ago

I have tested this by adding a 'Process Midi' button to the Host Sample and loading in an unmanaged midi monitor plugin (not the exact same as described - couldn't find a working download for that one). I send 2 batches of 10 note on/off messages and repeated that test a couple of times. I could not find any problems.

I have examined the code that is responsible for the marshaling of the managed vst events to the unmanaged plugin. I could not find any obvious problems there either. It is true that these events are stored because they (their memory) must remain valid for the entire processing cycle.

The only way that I can imagine the processEvents could go wrong is if you're "sending several events at once" by means of multi-threading: calling the same plugin at the same time from different threads. But I don't think that is what he meant.

If anyone runs into this problem, please let me know.