Commit Graph

760 Commits

Author SHA1 Message Date
Robbert van der Helm e700678a11 Also preallocate small buffers for VST2 events 2021-05-23 00:10:03 +02:00
Robbert van der Helm 095ca11535 Add alignment hints to types stored in containers 2021-05-22 23:45:52 +02:00
Robbert van der Helm da8f4aae19 Preallocate small vectors for VST3 queues
Events, parameter changes, and the individual queues contained within
the parameter changes all use dynamic memory allocation. Preallocating
some memory for those things inside of the objects may prevent latency
spikes when they those objects are first filled. This is especially
useful for the parameter changes since there's no way to reserve memory
in a vector of vectors.
2021-05-22 23:38:31 +02:00
Robbert van der Helm 90338abe6d Add bitsery trait for Boost.Container small_vector
I was going to implement these myself since we don't need them to be
contiguous like Boost's implementation is, but this is much easier of
course.
2021-05-22 23:25:36 +02:00
Robbert van der Helm 7c49fe739d Use our new custom std::variant bitsery extension
This prevents reinitializing `std::variant`s when the variant we want to
deserialize is already active. We store audio buffers in variants, so
reinitializing them results in a lot of unnecessary memory frees,
allocations and writes during every processing cycle.
2021-05-22 17:51:01 +02:00
Robbert van der Helm 6ee905c79f Add a realtime-safe bitsery extension for variants
I blindly assumed the original implementation also did this, but this
version `std::variant<Ts...>` objects from being reinitialized if we're
deserializing a variant that's also currently active in the object we're
deserializing into. For simple structs this won't make any difference,
but in yabridge we often use variants to differentiate between things
like single precision and double precision audio buffers. Those buffers
are allocated on the heap, so recreating the objects every time we
deserialize them adds a lot of unnecessary overhead.
2021-05-22 17:27:54 +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 549306b295 Include effString2Parameter in opcode list
We don't need any special handling for this since our default argument
detection will handle strings, but it might be useful for log output if
a host ever uses this. At the moment there don't seem to be any hosts on
Linux that use this.
2021-05-21 02:03:27 +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 808cca3cb2 Always use static const instead of const static 2021-05-20 15:12:44 +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 8bfaade2a6 Change wording in the MessageReference bitsery ext
I had to reread the docstrings to remember what `deseerialization_store`
was, so it probably needed a better name.
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 6c58f4e305 Fix the return type constraint
Apparently T is only convertible to T if it can be copy constructed.
2021-05-20 00:10:00 +02:00
Robbert van der Helm 35cc47d021 Add a concept for invocables with a return type
Because for some reason this is not part of the standard library.
2021-05-19 23:30:42 +02:00
Robbert van der Helm 53794f94bf Encapsulate the mutual recursion behaviour
As it turns out, we'll sadly also need this for VST2 plugins on the Wine
side, so we should probably finally encapsulate this instead of
duplicating it a third time.
2021-05-19 19:36:44 +02:00
Robbert van der Helm 95badeb1bc Add a way to disable pipes for the Wine host
For some reason ujam plugins (and other plugins made with the Gorilla
Engine, like the LoopCloud plugins) will throw a `JS_EXEC_FAILED` error
when trying to load the plugin while either of the STDOUT or STDERR
streams is pointing to a pipe. Simply redirecting the output to a file
fixes this. By default we'll write the output to
`<temporary_directory>/yabridge-plugin-output.log`, but you can also set
the new `disable_pipes` option to `"/dev/null"` to completely throw away
all output.

This addresses #47.
2021-05-18 17:59:43 +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 f1d7b7bf57 Avoid allocations in VST3 process response
This is very ugly so hopefully I can think of a neater way, but now the
response object is just a set of pointers, so we can avoid all copies
and moves on the Wine side.
2021-05-07 19:24:28 +02:00
Robbert van der Helm 93b8643cba Avoid allocations when reconstructing process data 2021-05-07 18:21:30 +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 d08ec70f2c Add a bitsery adapter for MessageReference<T>
This lets us deserialize into an actual persistent object and then
reassign the reference to point to that object.
2021-05-07 16:23:04 +02:00
Robbert van der Helm c6fc24f210 Add a reference wrapper for VST3 message objects
This is kind of equivalent to `std::reference_wrapper`, but with default
initialization support (which is UB, but is required for serialization)
and a forward for `T::Response` as used by your sockets API.
2021-05-07 16:21:48 +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 9f5066a293 Avoid allocations when reading VST3 process data
On the plugin side. We still need to do a lot of optimizations
elsewhere.
2021-05-06 17:50:41 +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 9424c36993 Temporarily memoize IPlugView::canResize()
This makes VST3 plugin resizing more responsive, because this function
would otherwise be constantly running in lockstep from the GUI thread.
2021-05-05 19:44:44 +02:00
Robbert van der Helm 75006a537b Split up VST3 logging for UniversalTResult
I was wondering why I couldn't find the overload for `UniversalTResult`,
and as it turns out we would always use this variant (which
unsurprisingly was the very first overload added). We should of course
have separate overloads for this.
2021-05-05 19:38:46 +02:00
Robbert van der Helm 22d74e8b70 Add a helper for temporarily caching a value 2021-05-05 19:38:46 +02:00
Robbert van der Helm ce668ec022 Clean up style 2021-05-05 19:38:46 +02:00
Robbert van der Helm a9f9691b42 Don't copy any VST3 state preamble
Bitwig prepends some data when passing an `IBStream*` to the plugin, and
when we do copy it iZotope Rx7 plugins cannot load their state (even if
we also copy over the same seek position). Not copying that preamble
fixes the issue, and it seems like it doesn't break anything.
2021-05-02 22:00:53 +02:00
Robbert van der Helm 757fb6d372 Pass the PID of the native host to the Wine hosts
We need this for our watchdog.
2021-05-01 17:13:16 +02:00
Robbert van der Helm 071bb157ad Move the pid_running() function to common utils
We're going to need this for our watchdog.
2021-05-01 17:08:47 +02:00
Robbert van der Helm 167784f93b Prevent unnecessary copies in ScopedValueCache 2021-05-01 16:28:14 +02:00
Robbert van der Helm 89d6c1b2e0 Fix assertion failure when reading end of stream
Getting the address of the end of a vector apparently raises an
assertion failure now, even if we didn't do anything with it.
2021-04-30 17:00:04 +02:00
Robbert van der Helm 0536256217 Add clamping to IBStream implementation seek 2021-04-29 23:40:42 +02:00