Move EventResultPayload to Vst2EventResult::Payload

This commit is contained in:
Robbert van der Helm
2021-05-20 15:55:39 +02:00
parent bd0dd63ad2
commit 0e3a4f6d54
4 changed files with 77 additions and 73 deletions
+18 -14
View File
@@ -230,7 +230,7 @@ class Vst2EventHandler : public AdHocSocketHandler<Thread> {
* an `Vst2Event`. This is almost always uses `passthrough_event()`, which * an `Vst2Event`. This is almost always uses `passthrough_event()`, which
* converts a `Vst2Event::Payload` into the format used by VST2, calls * converts a `Vst2Event::Payload` into the format used by VST2, calls
* either `dispatch()` or `audioMaster()` depending on the context, and then * either `dispatch()` or `audioMaster()` depending on the context, and then
* serializes the result back into an `EventResultPayload`. * serializes the result back into an `Vst2EventResult::Payload`.
* *
* @param logging A pair containing a logger instance and whether or not * @param logging A pair containing a logger instance and whether or not
* this is for sending `dispatch()` events or host callbacks. Optional * this is for sending `dispatch()` events or host callbacks. Optional
@@ -478,8 +478,8 @@ Vst2EventResult passthrough_event(AEffect* plugin,
// For some payload types we need to write back a value to the data pointer // For some payload types we need to write back a value to the data pointer
auto write_payload_fn = overload{ auto write_payload_fn = overload{
[&](auto) -> EventResultPayload { return nullptr; }, [&](auto) -> Vst2EventResult::Payload { return nullptr; },
[&](const AEffect& updated_plugin) -> EventResultPayload { [&](const AEffect& updated_plugin) -> Vst2EventResult::Payload {
// This is a bit of a special case! Instead of writing some return // This is a bit of a special case! Instead of writing some return
// value, we will update values on the native VST plugin's `AEffect` // value, we will update values on the native VST plugin's `AEffect`
// object. This is triggered by the `audioMasterIOChanged` callback // object. This is triggered by the `audioMasterIOChanged` callback
@@ -489,9 +489,11 @@ Vst2EventResult passthrough_event(AEffect* plugin,
return nullptr; return nullptr;
}, },
[&](DynamicSpeakerArrangement& speaker_arrangement) [&](DynamicSpeakerArrangement& speaker_arrangement)
-> EventResultPayload { return speaker_arrangement; }, -> Vst2EventResult::Payload { return speaker_arrangement; },
[&](WantsAEffectUpdate&) -> EventResultPayload { return *plugin; }, [&](WantsAEffectUpdate&) -> Vst2EventResult::Payload {
[&](WantsChunkBuffer&) -> EventResultPayload { return *plugin;
},
[&](WantsChunkBuffer&) -> Vst2EventResult::Payload {
// In this case the plugin will have written its data stored in an // In this case the plugin will have written its data stored in an
// array to which a pointer is stored in `data`, with the return // array to which a pointer is stored in `data`, with the return
// value from the event determines how much data the plugin has // value from the event determines how much data the plugin has
@@ -500,7 +502,7 @@ Vst2EventResult passthrough_event(AEffect* plugin,
return ChunkData{ return ChunkData{
std::vector<uint8_t>(chunk_data, chunk_data + return_value)}; std::vector<uint8_t>(chunk_data, chunk_data + return_value)};
}, },
[&](WantsVstRect&) -> EventResultPayload { [&](WantsVstRect&) -> Vst2EventResult::Payload {
// The plugin should have written a pointer to a VstRect struct into // The plugin should have written a pointer to a VstRect struct into
// the data pointer. I haven't seen this fail yet, but since some // the data pointer. I haven't seen this fail yet, but since some
// hosts will call `effEditGetRect()` before `effEditOpen()` I can // hosts will call `effEditGetRect()` before `effEditOpen()` I can
@@ -512,7 +514,7 @@ Vst2EventResult passthrough_event(AEffect* plugin,
return *editor_rect; return *editor_rect;
}, },
[&](WantsVstTimeInfo&) -> EventResultPayload { [&](WantsVstTimeInfo&) -> Vst2EventResult::Payload {
// Not sure why the VST API has twenty different ways of // Not sure why the VST API has twenty different ways of
// returning structs, but in this case the value returned from // returning structs, but in this case the value returned from
// the callback function is actually a pointer to a // the callback function is actually a pointer to a
@@ -526,14 +528,16 @@ Vst2EventResult passthrough_event(AEffect* plugin,
return *time_info; return *time_info;
} }
}, },
[&](WantsString&) -> EventResultPayload { [&](WantsString&) -> Vst2EventResult::Payload {
return std::string(static_cast<char*>(data)); return std::string(static_cast<char*>(data));
}, },
[&](VstIOProperties& props) -> EventResultPayload { return props; }, [&](VstIOProperties& props) -> Vst2EventResult::Payload {
[&](VstMidiKeyName& key_name) -> EventResultPayload { return props;
},
[&](VstMidiKeyName& key_name) -> Vst2EventResult::Payload {
return key_name; return key_name;
}, },
[&](VstParameterProperties& props) -> EventResultPayload { [&](VstParameterProperties& props) -> Vst2EventResult::Payload {
return props; return props;
}}; }};
@@ -541,9 +545,9 @@ Vst2EventResult passthrough_event(AEffect* plugin,
// And as mentioned above, `effGetSpeakerArrangement()` wants the plugin's // And as mentioned above, `effGetSpeakerArrangement()` wants the plugin's
// speaker arrangement to be the data pointer, so we need to do this same // speaker arrangement to be the data pointer, so we need to do this same
// serialization step just for that function. // serialization step just for that function.
const EventResultPayload response_data = const Vst2EventResult::Payload response_data =
std::visit(write_payload_fn, event.payload); std::visit(write_payload_fn, event.payload);
std::optional<EventResultPayload> value_response_data = std::nullopt; std::optional<Vst2EventResult::Payload> value_response_data = std::nullopt;
if (event.value_payload) { if (event.value_payload) {
value_response_data = value_response_data =
std::visit(write_payload_fn, *event.value_payload); std::visit(write_payload_fn, *event.value_payload);
+2 -2
View File
@@ -448,8 +448,8 @@ void Vst2Logger::log_event_response(
bool is_dispatch, bool is_dispatch,
int opcode, int opcode,
intptr_t return_value, intptr_t return_value,
const EventResultPayload& payload, const Vst2EventResult::Payload& payload,
const std::optional<EventResultPayload>& value_payload, const std::optional<Vst2EventResult::Payload>& value_payload,
bool from_cache) { bool from_cache) {
if (BOOST_UNLIKELY(logger.verbosity >= Logger::Verbosity::most_events)) { if (BOOST_UNLIKELY(logger.verbosity >= Logger::Verbosity::most_events)) {
if (should_filter_event(is_dispatch, opcode)) { if (should_filter_event(is_dispatch, opcode)) {
+2 -2
View File
@@ -73,8 +73,8 @@ class Vst2Logger {
bool is_dispatch, bool is_dispatch,
int opcode, int opcode,
intptr_t return_value, intptr_t return_value,
const EventResultPayload& payload, const Vst2EventResult::Payload& payload,
const std::optional<EventResultPayload>& value_payload, const std::optional<Vst2EventResult::Payload>& value_payload,
bool from_cache = false); bool from_cache = false);
/** /**
+37 -37
View File
@@ -427,21 +427,25 @@ void serialize(S& s, Vst2Event::Payload& payload) {
} }
/** /**
* AN instance of this should be sent back as a response to an incoming event.
*/
struct Vst2EventResult {
/**
* The response for an event. This is usually either: * The response for an event. This is usually either:
* *
* - Nothing, on which case only the return value from the callback function * - Nothing, on which case only the return value from the callback function
* gets passed along. * gets passed along.
* - A (short) string. * - A (short) string.
* - Some binary blob stored as a byte vector. During `effGetChunk` this will * - Some binary blob stored as a byte vector. During `effGetChunk` this
* contain some chunk data that should be written to * will contain some chunk data that should be written to
* `Vst2PluginBridge::chunk_data`. * `Vst2PluginBridge::chunk_data`.
* - A specific struct in response to an event such as `audioMasterGetTime` or * - A specific struct in response to an event such as `audioMasterGetTime`
* `audioMasterIOChanged`. * or `audioMasterIOChanged`.
* - An X11 window pointer for the editor window. * - An X11 window pointer for the editor window.
* *
* @relates passthrough_event * @relates passthrough_event
*/ */
using EventResultPayload = std::variant<std::nullptr_t, using Payload = std::variant<std::nullptr_t,
std::string, std::string,
AEffect, AEffect,
ChunkData, ChunkData,
@@ -452,8 +456,35 @@ using EventResultPayload = std::variant<std::nullptr_t,
VstRect, VstRect,
VstTimeInfo>; VstTimeInfo>;
/**
* The result that should be returned from the dispatch function.
*/
native_intptr_t return_value;
/**
* Events typically either just return their return value or write a string
* into the void pointer, but sometimes an event response should forward
* some kind of special struct.
*/
Payload payload;
/**
* The same as the above value, but for returning values written to the
* `intptr_t` value parameter. This is only used during
* `effGetSpeakerArrangement`.
*/
std::optional<Payload> value_payload;
template <typename S>
void serialize(S& s) {
s.value8b(return_value);
s.object(payload);
s.ext(value_payload, bitsery::ext::StdOptional(),
[](S& s, auto& v) { s.object(v); });
}
};
template <typename S> template <typename S>
void serialize(S& s, EventResultPayload& payload) { void serialize(S& s, Vst2EventResult::Payload& payload) {
s.ext(payload, s.ext(payload,
bitsery::ext::StdVariant{ bitsery::ext::StdVariant{
[](S&, std::nullptr_t&) {}, [](S&, std::nullptr_t&) {},
@@ -474,37 +505,6 @@ void serialize(S& s, EventResultPayload& payload) {
[](S& s, VstTimeInfo& time_info) { s.object(time_info); }}); [](S& s, VstTimeInfo& time_info) { s.object(time_info); }});
} }
/**
* AN instance of this should be sent back as a response to an incoming event.
*/
struct Vst2EventResult {
/**
* The result that should be returned from the dispatch function.
*/
native_intptr_t return_value;
/**
* Events typically either just return their return value or write a string
* into the void pointer, but sometimes an event response should forward
* some kind of special struct.
*/
EventResultPayload payload;
/**
* The same as the above value, but for returning values written to the
* `intptr_t` value parameter. This is only used during
* `effGetSpeakerArrangement`.
*/
std::optional<EventResultPayload> value_payload;
template <typename S>
void serialize(S& s) {
s.value8b(return_value);
s.object(payload);
s.ext(value_payload, bitsery::ext::StdOptional(),
[](S& s, auto& v) { s.object(v); });
}
};
/** /**
* Represents a call to either `getParameter` or `setParameter`, depending on * Represents a call to either `getParameter` or `setParameter`, depending on
* whether `value` contains a value or not. * whether `value` contains a value or not.