Commit Graph

442 Commits

Author SHA1 Message Date
Robbert van der Helm 08cd7cf8ab Join Win32Threads on destruct, like std::jthread 2020-10-28 21:11:34 +01:00
Robbert van der Helm dd9957159a Move the sockets after the threads in Vst2Bridge
This way the sockets can be destroyed before the threads, and we can
safely wait for the threads to shut down. I initially had Win32Thread
imitate std::jthread's join-on-destruct, but that was causing group
processes to hang. Now we can safely add that back again, and this will
fix some spurious segfaults during plugin scans when using plugin groups
containing a massive amount of plugins.
2020-10-28 21:05:14 +01:00
Robbert van der Helm d81759c929 Add an explicit wait to our thread wrapper 2020-10-28 20:40:19 +01:00
Robbert van der Helm 93e01dacef Explicitly close all sockets on shutdown
This way we're sure to break out of any blocking loops.
2020-10-28 20:38:01 +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 eb8d4ae1d8 Fix Win32Thread not capturing by move
std::function does not allow non-movable lambdas, so capturing by move
doesn't work there. And the old solution of course has issues with
dangling pointers (but because this is C++ the compiler still thinks
it's A-Ok).
2020-10-27 22:53:59 +01:00
Robbert van der Helm 28886e7073 Replace all threads with Win32Thread in Wine host 2020-10-27 18:29:38 +01:00
Robbert van der Helm bafc36614b Properly forward arguments in Win32Thread 2020-10-27 18:28:23 +01:00
Robbert van der Helm a6b5951d81 Replace std::jthread with Win32Thread everywhere 2020-10-27 17:38:13 +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 1681ec9767 Add support for lambdas to Win32Thread 2020-10-27 17:04:40 +01:00
Robbert van der Helm 058eb9f2ee Fix winedbg warning 2020-10-27 11:56:00 +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 5b00ddb0c4 Fall back to waiting when socket is not yet ready
This can happen with plugin groups.
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 e12a56978d Reintroduce the additional IO contexts
Having these bound to the main context was not a good idea since that
would prevent sockets from being accepted on the Wine side while the
message loop is running.

Partial revert of ac17539ef3
2020-10-26 20:39:16 +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 c95e8aa63c Add a TODO for removing hack_reaper_update_display 2020-10-26 18:00:24 +01:00
Robbert van der Helm e067bbbfbc Don't stop the whole IO context
This would break plugin groups since the different plugins share a
single IO context.
2020-10-26 17:44:34 +01:00
Robbert van der Helm ac17539ef3 Drop all additional IO contexts
Not really needed (since the only other thing happening in the IO
context is processing stdio from the Wine process) and it was causing
some impossible to debug malloc failures in Boost.Asio.
2020-10-26 17:32:37 +01:00
Robbert van der Helm cde7b4ec67 Properly move the sockets to the handler threads
At times like this you really wish you were writing Rust right now.
2020-10-26 15:48:57 +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 81efa6febe Listen for incoming secondary event requests 2020-10-26 12:58:03 +01:00
Robbert van der Helm 523ac64d11 Add a missing lock to reading from active_plugins
I've never seen this cause memory errors, but there exist a rare
situation where it could.
2020-10-26 12:45:38 +01:00
Robbert van der Helm 2f6883977f Create secondary sockets for sending nested events 2020-10-26 12:13:27 +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 a1e7142f17 Mark max_win32_messages as [[maybe_unused]]
ccls/clangd doesn't know that it's being used elsewhere.
2020-10-25 13:00:50 +01:00
Robbert van der Helm db02fa1c43 Fix issue with closing sockets in plugin groups
As per Boost.Asio's manual, an explicit `socket.shutdown()` is needed
before calling `close()`. For some reason this worked fine in almost
every situation, but when hosting both a plugin hosted within a group
host process and a normal individually hosted plugin within a single
process, and then removing those two plugins in order, the
`host_vst_dispatch` socket of the first plugin never got closed. This
would hang the entire shutdown sequence to hang on the
`dispatch_handler` jthread.

First discovered in #45
2020-10-22 14:05:59 +02:00
Robbert van der Helm ce385f39d3 Use vfork() for spawning processes #45 2020-10-21 22:30:50 +02:00
Robbert van der Helm 3facdf532a Fix fake dropdown menus in TDR plugins
These would close immediately when hovering over them with the new focus
grabbing method.
2020-10-19 14:34:52 +02:00
Robbert van der Helm 150845a301 Fix editor_double_embed causing X11 errors
Since the error codes were not before version 1.7.0 we just didn't
notice this, even though everything still appeared to work fine.
2020-10-14 16:36:48 +02:00
Robbert van der Helm a1162c2256 Print invalid and unknown options on startup 2020-10-13 15:04:33 +02:00
Robbert van der Helm 95ad6fc36a Work around reparenting issues in #40
I'm still really curious why this double reparent would be needed
though. Everything works fine on any other i3 config I've tried, and
even the exact same config in a VM works fine for me.
2020-10-12 14:28:29 +02:00
Robbert van der Helm 225d6a000e Add a fallback for non-EWMH compliant WMs
I'm not sure how many people use WMs that don't implement
`_NET_ACTIVE_WINDOW`, but at least this will give those people some way
to grab input focus, even if it's not as good as the new method.
2020-10-09 14:35:43 +02:00
Robbert van der Helm 6ff61b1904 Rewrite how input focus grabbing works #38 2020-10-08 19:34:26 +02:00
Robbert van der Helm 36d39bfca9 Add missing free() calls for xcb 2020-10-08 17:03:03 +02:00
Robbert van der Helm 60c4e64b9b Add xcb error assertions instead of segfaulting
These things should not fail (and I've never seen one of these thing
error out with yabridge), but in the case they do an assertion is at
least a lot trace down than a segfault.
2020-10-08 16:17:00 +02:00
Robbert van der Helm e680f2eddd Made the input focus grabbing even more aggressive
This fixes keyboard focus not returning when closing dialogs in Melda
plugins. I'll have to do some more testing to see if this does not
introduce any unwanted side effects.
2020-10-08 15:51:20 +02:00
Robbert van der Helm e7cbd9e21e Slightly clean up the libSwell message 2020-10-08 14:37:29 +02:00
Robbert van der Helm bfd4553d84 Change punctuation in new libSwell message 2020-10-01 14:23:39 +02:00
Robbert van der Helm 8ae9c4d263 Made input focus grabbing more aggressive #38
This fixes keyboard input in REAPER, and I haven't found any downsides
to this approach yet.
2020-09-30 17:30:38 +02:00
Robbert van der Helm d4787fc120 Clarify libSwell message and mention workaround 2020-09-29 18:13:39 +02:00
Robbert van der Helm 32b3e106b1 Fixed potential use-after-free on detached threads
This could sometimes cause REAPER's plugin scanning to crash when the
stars aligned in the wrong way since the stop token would no longer
exist.
2020-09-28 22:31:53 +02:00
Robbert van der Helm 7fbbb48c54 Fix parsing order of yabridge.toml #37
Since tomlplusplus uses `std::map` instead of `std::unordered_map`
internally the tables were actually being read in lexicographical order.
2020-09-27 19:42:07 +02:00
Robbert van der Helm f1b1f20fdb Update tomlplusplus 2020-09-27 17:48:43 +02:00
Robbert van der Helm ae402aa805 Fix plugin groups outside of Wine prefixes
Boost.Process's `boost::process::environment::at` throws when the
environment variable does not exist, as opposed to `operator[]` which
falls back to an empty value.
2020-09-27 17:26:16 +02:00