Commit Graph

69 Commits

Author SHA1 Message Date
Robbert van der Helm 6f321649c4 Do small vector optimization for all communication
I once read years ago somewhere on Stack Overflow that `std::vectors`
with that are preinitialized to a default size would allocate the
initial capacity on the stack. This of course doesn't make any
sense (run time sized stack allocations can cause all kinds of issues),
so we were still allocating with our default 64-byte sized buffers, but
just not as often.
2021-05-23 14:43:02 +02:00
Robbert van der Helm 88a45e6178 Prevent unnecessary copies during audio processing
We did a ton of work earlier to make sure we can reuse these objects,
but `auto` implies the type is never a reference type, and we were thus
unnecessarily creating copies every iteration, kind of defeating the
purpose of doing all of this in the first place. We could do some
template trickery here, but it's also safe to just make the persistent
object thread local since the actual objects aren't that large.
2021-05-22 16:07:11 +02:00
Robbert van der Helm 0e3a4f6d54 Move EventResultPayload to Vst2EventResult::Payload 2021-05-20 15:55:39 +02:00
Robbert van der Helm bd0dd63ad2 Rename the EventResult struct to Vst2EventResult 2021-05-20 15:53:16 +02:00
Robbert van der Helm 2bf41c6fe1 Move EventPayload to Vst2Event::Payload 2021-05-20 15:52:40 +02:00
Robbert van der Helm b1c9d75112 Rename the Event struct to Vst2Event 2021-05-20 15:50:09 +02:00
Robbert van der Helm 3e6bf3adfd Allow overriding sending behaviour for VST2 events
Now we can implement mutual recursion for VST2 plugins. Wish we didn't
have to.
2021-05-20 14:49:11 +02:00
Robbert van der Helm ccfda51a69 Clarify the DefaultDataConverter method names 2021-05-20 14:49:11 +02:00
Robbert van der Helm 06bae784a8 Update documentation in passthrough_event()
There were some glaring typos in there. I probably replaced them with
new ones.
2021-05-20 14:31:59 +02:00
Robbert van der Helm c2186fa55b Use the std::derived_from concept when applicable
This probably makes things much clearer at a glance instead of using a
blanked typename.
2021-05-20 14:31:59 +02:00
Robbert van der Helm a194765696 Rename EventHandler to Vst2EventHandler 2021-05-20 13:54:31 +02:00
Robbert van der Helm e4ca520b64 💥 Redo all higher order template functions
This does what we did for a few functions in the last few commits for
every function. We now use either the `std::invocable` concept or our
own `invocable_returning` concept wherever possible to make sure we pass
function types to these template functions, since constraint errors are
a lot more readable than template deduction errors. And instead of
having to specify the return type as a template argument, we now just
use `std::invoke_result_t<F>` instead. The VST3 message handling
functions are still using the good old `typename F` since those are
overloaded polymorphic functions. This was also a good moment to modify
`AdHocSocketHandler::send()` to allow functions returning void (this got
rid of an old fixme where we had to return some dummy value from a
function instead of just not returning anything).
2021-05-20 01:03:58 +02:00
Robbert van der Helm e974d1d2b1 Use perfect forwarding in templates where possible 2021-05-17 01:02:45 +02:00
Robbert van der Helm 448243050a Always serialize in little-endian and skip checks
These checks are not necessary since we can trust ourselves to not try
to cause any buffer overflows.
2021-05-16 13:15:14 +02:00
Robbert van der Helm 4b5cb3e205 Initialize thread locals later
This shouldn't be necessary, but maybe this helps with the issue where
the optional is suddenly a nullopt.
2021-05-16 01:36:17 +02:00
Robbert van der Helm 9696e96564 Forcefully initialize the thread local object
Not sure why the initialization wouldn't work, but apparently in some
cases it doesn't. This will still only be initialized once, hopefully.
2021-05-16 00:46:25 +02:00
Robbert van der Helm fc04e2edcb Properly initialize the thread local objects
Instead of doing assignment. Assignment will probably reinitialize every
cycle, and it also didn't work on one person's computer.
2021-05-16 00:30:46 +02:00
Robbert van der Helm 59ba2aeb5f Add noexcept qualifications in src/common
Apparently this can actually make a difference in some cases, and the
C++ Core Guideliens recommend doing this on all default constructors,
destructors, and all functions that can not throw (and thus also don't
allocate).
2021-05-14 17:12:24 +02:00
Robbert van der Helm 814d3c688c Fix the VST3 audio processing sending buffers
Making these thread local statics makes much more sense for their
purpose. The old approach technically wasn't thread safe (even if it was
never an issue) and this gets rid of a data structure.
2021-05-07 17:41:42 +02:00
Robbert van der Helm 671587f981 Further reduce allocations by reusing responses
On the plugin's side, still need to do a lot of work on the Wine side of
things.
2021-05-07 17:00:43 +02:00
Robbert van der Helm fcaac219a6 💥 Reduce allocations in VST3 audio sockets
We do this by using this new `MessageReference<T>` type to avoid copying
our `YaAudioProcessor::Process` struct and the contained `YaProcessData`
object. This is only part of the work, but this redesign lets us keep
the these objects alive on both the plugin and the host side. On the
plugin side, we'll simply serialize the data from the referred to object
without copying it. On the Wine side, we'll write the data to a
persistent thread local object, and then reassign the
`MessageReference<T>` to point to that object. This lets us serialize
'references', thus avoiding potentially expensive allocations. With
these last few changes alone VST3 plugins are already at the same
performance level as our optimized VST2 plugin groups.
2021-05-07 16:32:08 +02:00
Robbert van der Helm a9a7e3e711 Note that objects in audio sockets doesn't work 2021-05-06 18:05:10 +02:00
Robbert van der Helm 0b173ecba8 Reuse objects in the VST3 audio processor sockets
This means that, we're now receiving into an existing `YaProcessData`
object, which should reduce the number of allocations on the Wine side
considerably. Next we should also reuse the `YaProcessDataResponse`
object.
2021-05-06 16:41:11 +02:00
Robbert van der Helm 0d1cb0bd77 Move special effVendorSpecific handling for REAPER
It's a bit less hacky if we do the effVendorSpecific check where we're
supposed to be checking for those things.
2021-04-24 20:23:23 +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 3ae4bf56cd Fix memory error in remove_audio_processor()
We would close the socket, but the `receive_multi()` call would finish
after the object had already been deallocated using `erase()`. Somehow
this never caused any issues though.
2021-04-07 17:24:00 +02:00
Robbert van der Helm dc7c988623 Fix segfault in REAPER due to new vendor extension
This `effVendorSpecific` call would pass a non-zero non-pointer value to
the pointer argument, which would then of course result in segfaults.
2021-02-15 21:15:22 +01:00
Robbert van der Helm 78a28a679b Prevent nuking socket base dir if not temporary
If `yabridge-host.exe` were somehow to be run with a socket base
directory that's not inside of `$XDG_RUNTIME_DIR`/`/tmp`, then we'll now
warn instead of removing that directory. This should not be necessary,
but in case someone wants to write a wrapper around
`yabridge-host.exe.so` us using a custom `$WINELOADER` then this could
save a lot of headaches.
2021-02-13 18:09:36 +01:00
Robbert van der Helm 4f4f455f13 Add a todo for a failsafe for the socket cleanup 2021-01-22 14:18:21 +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 42b9cf902c Swap read_object arguments to match write_object 2020-12-30 16:38:19 +01:00
Robbert van der Helm 0a05558a8c Make the persistent buffer thread local
Now that we allow ad hoc socket spawning for the audio sockets.
2020-12-29 00:39:23 +01:00
Robbert van der Helm 33806139e9 Revert "Allow disabling ad-hoc socket spawning"
It turns out we can't safely disable this, because in some situations we
still have these mutually recursive function calls. We could optimize
this a bit to have those calls be handled by the general sockets, but
this is much more manageable.

This reverts commit 415c1b5683.
2020-12-29 00:25:44 +01:00
Robbert van der Helm 6b4df4d274 Explicitly include <mutex>
This is an indirect dependency in Boost 1.72/1.73, but not in older
versions.
2020-12-25 21:55:00 +01:00
Robbert van der Helm 7da5ec113c Reuse buffers in VST3 audio processing 2020-12-25 16:22:53 +01:00
Robbert van der Helm 51877796fa Add dedicated IAudioProcessor/IComponent sockets
This way every relevant object instance will get its own thread for
handling these calls. The alternative would be creating a full fat
Vst3MessageHandler pair for all object instances, but that would be a
huge waste.
2020-12-21 17:26:30 +01:00
Robbert van der Helm 415c1b5683 Allow disabling ad-hoc socket spawning
We'll need this for handling `IAudioProcessor` method calls in VST3. We
basically want a `Vst3MessageHandler` per `IAudioProcessor` instance,
but without the additional socket spawning or extra thread.
2020-12-21 15:45:47 +01:00
Robbert van der Helm 38c37f2721 Don't log responses for filtered out requests 2020-12-19 13:07:58 +01:00
Robbert van der Helm 481975860c Use the new simple supports flags for the factory
This is both more type safe and as it turns out much more manageable.
2020-12-17 13:20:16 +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 7c5f7a2e0e Fully implement IPluginBase::initialize()
We can now pass host contexts around.
2020-12-13 15:16:11 +01:00
Robbert van der Helm 41b79720ca Merge branch 'master' into feature/vst3 2020-12-11 00:50:43 +01:00
Robbert van der Helm e5cd777713 Fix the templated visitor in Vst3MessageHandler
Now it works as expected, since auto can't be initialized to multiple
different values.
2020-12-07 23:49:25 +01:00
Robbert van der Helm f1fe0fa8a4 Log a warning when encountering unknown interfaces 2020-12-07 22:21:01 +01:00
Robbert van der Helm 8ea40cd9f9 Rework Vst3MessageHandler::receive_messages
This now takes a regular overloaded function and the visiting is done in
`receive_messages()` itself. This way we can use templates to ensure
that the return type is correct. Otherwise auto will cause issues in the
future when we want to return multiple concrete types from a function
that takes a single variant. The alternative would be both receiving a
variant as a parameter and then returning another variant as a result,
but that is much less type safe.
2020-12-07 18:28:16 +01:00
Robbert van der Helm c2503f8aaa Send the factory from the Wine host to the plugin 2020-12-07 18:28:16 +01:00
Robbert van der Helm 887a856e58 Rename Vst3MessageHandler::send_message overload
`receive_into()` looks much clearer in typical usage.
2020-12-07 18:28:16 +01:00
Robbert van der Helm a16cf3015f Fix deserializing into existing objects
`read_object()` was trying to create copies.
2020-12-07 18:28:16 +01:00
Robbert van der Helm d5374e4540 💥 Rework Vst3MessageHandler
- Now allows direct deserialization into existing objects. This will be
  necessary for our VST3 implementations since the interface instances
  we'll deserialize into will not be trivially constructable because
  they have to be able to do callbacks.
- `ControlResponse` and `CallbackResponse` were dropped. These response
  enums are not necessary because of the `T::Response` associated type
  and returning the types directly makes the direct deserialization
  possible.
2020-12-07 18:28:16 +01:00
Robbert van der Helm 5423950a8a Allow receiving VST3 messages into existing object 2020-12-07 18:28:16 +01:00