nhielost / obs-midi-mg

Allows MIDI devices to interact with OBS Studio.
GNU General Public License v2.0
155 stars 9 forks source link

[Bug] Issue when sending two of the same event too close to each other #130

Open rwilliam99 opened 6 months ago

rwilliam99 commented 6 months ago

I've encountered an issue when sending two events of the same kind too close together - I'm not sure what "too close" means, but here is some background and I've been able to replicate the behavior consistently.

If I send two of the same events (device, type, channel and program are the same) at the same time, OBS continues display inputs, however it becomes unresponsive and it will no longer respond to Midi events. Something with having two of the same event too close together seems to cause it to become unresponsive.

For background, I use a program called Proclaim (it is kind of like Powerpoint for churches) to display slides during our church services using NDI - Proclaim has the ability to send Midi events when a slide is displayed. It also has what it calls "cues" which can also send Midi events. I was experimenting with using those and had the same Midi event on a slide and a cue right next to each other - when running these slides I can consistently replicate OBS becoming unresponsive when going thru those slides. I also was able to replicate by adding the same event twice to the same slide (meaning it would send the event twice - similar behavior).

My guess would be that if obs-midi-mg has not completed processing event 1 before event 2 comes in, it causes some issue - but that is just a guess. I did confirm that I can send multiple events of different types and it does not cause any issues. The only issue comes when it is the same event.

I hope that is sufficient detail to be able to replicate. I'm happy to provide more details if needed.

rwilliam99 commented 6 months ago

A bit further info - I was able to replicate using the sendmidi command line program and I can send out the same event multiple times and it causes OBS to become unresponsive. This is not completely repeatable but I was able to cause the same behavior with this - either using multiple iterations of the command or adding more events on one command.

This is the command I used which sends the same event twice:

sendmidi dev OBSAndProclaim pc 2 pc 2

OBSAndProclaim is the MIDI device - it sends a program change 2. I confirmed this is the same MIDI command that Proclaim is sending so I believe it replicates the behavior correctly without having Proclaim in the mix.

It seems to be a timing issue of some kind. The events in Proclaim when stacked seem to come out exactly 2ms apart - this is from the log in Bome Midi Translator:

1166744 - MIDI IN [OBSAndProclaim]: C0 02 1166746 - MIDI IN [OBSAndProclaim]: C0 02 1173705 - MIDI IN [OBSAndProclaim]: C0 02 1173707 - MIDI IN [OBSAndProclaim]: C0 02 1179243 - MIDI IN [OBSAndProclaim]: C0 02 1179245 - MIDI IN [OBSAndProclaim]: C0 02

When sent on the same command from sendmidi they are the same time:

1269687 - MIDI IN [OBSAndProclaim]: C0 02 1269687 - MIDI IN [OBSAndProclaim]: C0 02

If I create a batch file to do two invocations, it is longer than 2ms but does not always trigger the behavior: 1283322 - MIDI IN [OBSAndProclaim]: C0 02 1283448 - MIDI IN [OBSAndProclaim]: C0 02

So, the sendmidi is not as repeatable as doing this from Proclaim, but it can be used to (eventually) replicate the behavior.

Hope this information is helpful.

nhielost commented 6 months ago

Hello!

I have managed to replicate this issue enough that it causes issues with OBS as you describe. I have also found a fix, so the next version released will include the change.

rwilliam99 commented 6 months ago

Awesome! Thank you! I look forward to the next version. For now, I've just been careful to make sure there aren't two of the same event being sent. Last Sunday there were no issues (as expected).