Commit Graph

76 Commits

Author SHA1 Message Date
Robbert van der Helm 671c6a4c18 Specifically not read data for audioMasterWantMidi
Plugsound Free by UVI will pass random garbage to the data parameter for
this function call for whatever reason, and we'll run into a memory
error if we try to read it. Mentioned in #93.
2021-04-24 20:28:58 +02:00
Robbert van der Helm afefb725b5 Postpone clearing old MIDI events until next event
This fixes Native Instrument's FM7 crashing on MIDI input. The plugin
expects the last received MIDI event to always be alive during audio
processing, even if there have not been any new events in this
processing cycle.
2021-04-23 01:08:21 +02:00
Robbert van der Helm d97e699db1 Run effSetChunk and effGetChunk from main thread 2021-04-14 21:38:15 +02:00
Robbert van der Helm 4937010557 Fix some of the clang-tidy lints 2021-04-14 16:09:54 +02:00
Robbert van der Helm 3fbffa532d Move Win32 event handling to one place
Or technically, two, since the group bridge also does the same loop. We
no longer need special handling for VST2 and VST3 plugins, so we can
simplify things a bit here.
2021-02-09 23:45:33 +01:00
Robbert van der Helm 0adca3e33c Revert "Remove cache_time_info and always cache time info"
This reverts commit cfb171c991.

No idea why, but this cache breaks SPL Transient Designer Plus. Perhaps
it overwrites the time info?
2021-01-30 02:37:27 +01:00
Robbert van der Helm cfb171c991 Remove cache_time_info and always cache time info
It sort of goes against yabridge's principles to not do these
unnecessary `audioMasterGetTime()` calls if the plugin does that, but it
also hurts the user experience to not have this as a default.
2021-01-30 00:20:35 +01:00
Robbert van der Helm 3f7f67fc2d Get rid of no longer used mutex
This was left over from a very early version of yabridge. It's not
needed since we have to initialize all VST2 plugins from the same thread
anyways.
2021-01-28 23:45:44 +01:00
Robbert van der Helm 72e29d044a Add a function for temporarily blocking event loop
This can be used to prevent the Win32 message loop from running while
there are plugins in some partially initialized state.
2021-01-27 19:00:11 +01:00
Robbert van der Helm f03b9b1497 Sync VST2 audio thread scheduling priorities
We'll periodically copy the scheduling priorities from the host's audio
threads to the Wine plugin host's audio threads. The overhead of doing
this is about 1 microsecond on my system, so doing this every cycle
really adds up. But getting the Unix epoch time and comparing some
timestamps has a neglegible overhead, so this should give you the best
of both worlds.

Next we'll do the same thing for VST3 plugins.

As suggested by @jhernberg
2021-01-23 15:14:52 +01:00
Robbert van der Helm 2ca1d5b8ca Greatly increase reliability of deferred closing
It's pretty hard to find a solution that checks all of the boxes. I want
something that:

- Closes instantly when you close the editor, and in REAPER you should
  be able to instantly switch between docked and floating modes
- Where there should not be a delay in user interaction when quickly
  reopening the editor (or doing that switching thing in REAPER since that's
  the same thing)
- Where the window manager should not try to reparent the window during
  the losing process as that can cause some jarring flickering
- And, of course, there should be no weird Wine X11Drv crashes

And it should do all of that in Bitwig, REAPER, Carla, Ardour and
Renoise. Apparently it's quite the task to find an approach that checks
all the boxes there.
2021-01-21 16:47:35 +01:00
Robbert van der Helm bf3a4e7296 Allow changing the event loop tick rate
This also changes the refresh rate for most plugins. You can now lower
this setting if your computer is struggling to keep up with rendering a
certain heavy plugin.
2021-01-11 23:38:21 +01:00
Robbert van der Helm 8f15578d8c Also disable realtime priority during effEditGetRect
Since on some hosts this is called before effEditOpen.
2021-01-11 18:53:36 +01:00
Robbert van der Helm f015739942 Open and close editors without realtime priority 2021-01-11 18:50:53 +01:00
Robbert van der Helm 2f5d22ca17 Handle effMainsChanged on the main UI thread #75
This fixes EZdrummer not producing any sound, as the plugin presumably
schedules some task on the Win32 message loop to load its resources,
which won't happen if this is run from any other thread.
2021-01-05 23:04:18 +01:00
Robbert van der Helm 4ec8b01bcc Completely run effEditIdle from a timer
Although it hasn't shown up, this will get rid of the possibility of
off-thread effEditIdle calls causing issues. And since we need some way
to run call this function while the event loop is running anyways, doing
it entirely from a timer similar to how hosts on Windows would do it
seems like the best solution.
2021-01-04 15:50:17 +01:00
Robbert van der Helm 34f8d3b1d2 Update the copyright notices for 2021 2021-01-01 18:54:02 +01:00
Robbert van der Helm fa0753f520 Use atomic fetch-and-add for unique window classes 2020-12-31 14:12:14 +01:00
Robbert van der Helm 7e34cf69fe Remove Editor::handle_win32_events
This apparently isn't needed anymore.
2020-12-21 18:24:07 +01:00
Robbert van der Helm 703b6d9285 Add functions to schedule tasks in main IO context 2020-12-20 12:18:51 +01:00
Robbert van der Helm 49fc896d62 Remove Win32 effEditIdle() timer
Now Editor is completely decoupled from VST2.
2020-12-19 23:30:47 +01:00
Robbert van der Helm a724b378fe Move the editor handling back to Vst2Bridge
Since we can have multiple editors in Vst3Bridge.
2020-12-19 19:56:49 +01:00
Robbert van der Helm 816d1c1501 Implement IComponent::setState() 2020-12-14 12:09:47 +01:00
Robbert van der Helm 32c1028736 Implement IPluginFactory3::setHostContext()
Now the plugin factories are fully implemented (at least, functionality
wise, we still can't create most kinds of objects).
2020-12-13 15:53:39 +01:00
Robbert van der Helm 3db099e0fc Also make the GroupHost plugin type agnostic 2020-12-07 18:28:16 +01:00
Robbert van der Helm 0eb80fe866 Add a general entry point to HostBridge
Since for all plugin types we would need to start listening for incoming
events this way.
2020-12-07 18:28:16 +01:00
Robbert van der Helm eeb6acf8dd Move event handling to a common HostBridge 2020-12-07 18:28:16 +01:00
Robbert van der Helm 46bc0301af Move communication.h to communication/vst2.h 2020-12-07 18:28:16 +01:00
Robbert van der Helm 23d5567e72 Add a time info caching compatibility option #62
This is needed to get good performance out of SWAM Cello until this
issue is fixed by the plugin.
2020-11-30 14:49:02 +01:00
Robbert van der Helm 49900e4753 Fix typo 2020-11-20 17:45:21 +01:00
Robbert van der Helm 28013cb6a7 Note that the effEditIdle issue is fixed in Ardour
For the upcoming Ardour 6.4 release:

https://github.com/Ardour/ardour/commit/f7cb1b0b481eeda755bdf8eb9fc5f90a81d2aa01
2020-11-20 15:59:40 +01:00
Robbert van der Helm ff021d0581 Work around editor opening bug in Ardour 6.3 2020-11-13 17:08:41 +01:00
Robbert van der Helm 9300648067 Fix typo in vst2.cpp 2020-11-08 16:07:57 +01:00
Robbert van der Helm d2500ff31d Get rid of message loop skipping and EditorOpening
This special behaviour is no longer needed now that event handling is
fully concurrent and the Win32 message loop no longer blocks
`dispatch()` calls.
2020-11-07 22:06:58 +01:00
Robbert van der Helm a0c0a86e2c Drop the separate effProcessEvents socket
Now that event handling is fully concurrent and thus no longer gets
blocked by the Win32 message loop.
2020-11-07 20:54:33 +01:00
Robbert van der Helm 1c7e866609 No longer return a lambda in passthrough_event()
Now that it's no longer used directly this is no longer needed, and it's
much clearer without the lambda.
2020-11-06 17:17:36 +01:00
Robbert van der Helm ba6381e3ae Rename EventHandler::{send,receive} to *_event(s?)
Since it does something way more involved than
`SocketHandler::{send,receive_multi}`, and that makes it a bit confusing
if you don't already know about that (and even if you do).
2020-11-01 12:01:50 +01:00
Robbert van der Helm fa01ac843b Replace all non-group sockets with SocketHandler
This greatly reduces the amount of boilerplate and potential for error.
2020-10-30 13:30:08 +01:00
Robbert van der Helm bece654c2d Rename PluginContext to MainContext for clarity 2020-10-28 01:02:56 +01:00
Robbert van der Helm fac820c25a Execute all non-unsafe opcodes on calling thread
This will require more testing of course, but I think it should be safe.
This would increase the potential maximal throughput in group hosts
significantly.
2020-10-27 23:18:59 +01:00
Robbert van der Helm 4038e198fe Replace the Win32Thread proxy functions
Now that we can use lambdas instead.
2020-10-27 17:16:20 +01:00
Robbert van der Helm e51c7f7ae3 Get rid of hack_reaper_update_display
It is now no longer necessary.
2020-10-27 11:13:39 +01:00
Robbert van der Helm 016ceccc18 Mark several opcodes as unsafe
These potentially perform GUI operations and should always be handled on
the main thread.
2020-10-27 11:13:39 +01:00
Robbert van der Helm ca2b95e7aa Handle dispatch() directly during event handling
When the message loop is active and we get an incoming dispatch() event,
we'll just handle it directly. In practice this would only be needed
when the event is a response to an `audioMaster()` call made during the
event loop, but we can't know that. This allows the `getProgram()`
during `audioMasterUpdateDisplay()` in REAPER and Renoise to work
correctly. Hopefully this doesn't cause random rare breakage.
2020-10-26 20:03:54 +01:00
Robbert van der Helm 8d7826f1df Handle incoming events from off-threads separately
On the Wine side we want to handle most events on the main UI thread.
We'll assume any events coming in from a secondary socket are safe and
can be handled directly.
2020-10-26 13:45:37 +01:00
Robbert van der Helm d82f8463d9 Use simple numerical IDs for plugins in groups
We'll be using a similar approach to identify threads for event
handlers.
2020-10-26 11:51:13 +01:00
Robbert van der Helm 74c3cab046 Move event handling logic to a dedicated class
Now all pieces are in place to allow handling events over multiple
socket connections.
2020-10-26 11:40:38 +01:00
Robbert van der Helm 54ed69c408 Merge events.h into communication.h 2020-10-25 21:37:04 +01:00
Robbert van der Helm 4b53342514 💥 Encapsulate and rework all socket logic
This is a pretty huge change that will be important for being able to
handle nested or mutually recursive `dispatch()` and `audioMaster()`
calls. This sadly all had to be done in a single commit, so here's a
summary:

- `src/common/sockets.h:Sockets` contains all sockets on both the plugin
  and the Wine host side, and is used to both listen on and connect to
  the sockets.
- Sockets and other temporary files respect `$XDG_RUNTIME_DIR` instead
  of being dumped in `/tmp`.
- All sockets now have a unique endpoint in
  `/run/user/<uid>/yabridge-<plugin_name>-<random_id>/`. This is
  important for when we want to have multiple socket connections for
  handling `dispatch()` and `audioMaster()`.
- Because of the above, we no longer clean up the socket endpoint files
  after the connection gets established during initialization. Instead
  we'll remove the socket base directory when shutting down.
2020-10-25 21:24:56 +01:00
Robbert van der Helm 8198a73742 Add support for double precision audio #34
So far I've only seen REAPER running iZotope Rx plugins utilize this.
2020-08-24 16:13:29 +02:00