Rename the EventResult struct to Vst2EventResult

This commit is contained in:
Robbert van der Helm
2021-05-20 15:53:16 +02:00
parent 2bf41c6fe1
commit bd0dd63ad2
5 changed files with 49 additions and 43 deletions
+7 -6
View File
@@ -46,7 +46,7 @@ std::optional<Vst2Event::Payload> DefaultDataConverter::read_value(
void DefaultDataConverter::write_data(const int /*opcode*/, void DefaultDataConverter::write_data(const int /*opcode*/,
void* data, void* data,
const EventResult& response) const { const Vst2EventResult& response) const {
// The default behavior is to handle this as a null terminated C-style // The default behavior is to handle this as a null terminated C-style
// string // string
std::visit(overload{[&](const auto&) {}, std::visit(overload{[&](const auto&) {},
@@ -62,18 +62,19 @@ void DefaultDataConverter::write_data(const int /*opcode*/,
response.payload); response.payload);
} }
void DefaultDataConverter::write_value(const int /*opcode*/, void DefaultDataConverter::write_value(
intptr_t /*value*/, const int /*opcode*/,
const EventResult& /*response*/) const {} intptr_t /*value*/,
const Vst2EventResult& /*response*/) const {}
intptr_t DefaultDataConverter::return_value(const int /*opcode*/, intptr_t DefaultDataConverter::return_value(const int /*opcode*/,
const intptr_t original) const { const intptr_t original) const {
return original; return original;
} }
EventResult DefaultDataConverter::send_event( Vst2EventResult DefaultDataConverter::send_event(
boost::asio::local::stream_protocol::socket& socket, boost::asio::local::stream_protocol::socket& socket,
const Vst2Event& event) const { const Vst2Event& event) const {
write_object(socket, event); write_object(socket, event);
return read_object<EventResult>(socket); return read_object<Vst2EventResult>(socket);
} }
+15 -13
View File
@@ -57,7 +57,7 @@ class DefaultDataConverter {
*/ */
virtual void write_data(const int opcode, virtual void write_data(const int opcode,
void* data, void* data,
const EventResult& response) const; const Vst2EventResult& response) const;
/** /**
* Write the response back to the `value` pointer. This is only used during * Write the response back to the `value` pointer. This is only used during
@@ -65,7 +65,7 @@ class DefaultDataConverter {
*/ */
virtual void write_value(const int opcode, virtual void write_value(const int opcode,
intptr_t value, intptr_t value,
const EventResult& response) const; const Vst2EventResult& response) const;
/** /**
* This function can override a callback's return value based on the opcode. * This function can override a callback's return value based on the opcode.
@@ -85,7 +85,7 @@ class DefaultDataConverter {
* back. This can be overridden to use `MutualRecursionHelper::fork()` for * back. This can be overridden to use `MutualRecursionHelper::fork()` for
* specific opcodes to allow mutually recursive calling sequences. * specific opcodes to allow mutually recursive calling sequences.
*/ */
virtual EventResult send_event( virtual Vst2EventResult send_event(
boost::asio::local::stream_protocol::socket& socket, boost::asio::local::stream_protocol::socket& socket,
const Vst2Event& event) const; const Vst2Event& event) const;
}; };
@@ -204,7 +204,7 @@ class Vst2EventHandler : public AdHocSocketHandler<Thread> {
// from the socket, so we can override this for specific function calls // from the socket, so we can override this for specific function calls
// that potentially need to have their responses handled on the same // that potentially need to have their responses handled on the same
// calling thread (i.e. mutual recursion). // calling thread (i.e. mutual recursion).
const EventResult response = this->send( const Vst2EventResult response = this->send(
[&](boost::asio::local::stream_protocol::socket& socket) { [&](boost::asio::local::stream_protocol::socket& socket) {
return data_converter.send_event(socket, event); return data_converter.send_event(socket, event);
}); });
@@ -226,8 +226,8 @@ class Vst2EventHandler : public AdHocSocketHandler<Thread> {
* Spawn a new thread to listen for extra connections to `endpoint`, and * Spawn a new thread to listen for extra connections to `endpoint`, and
* then start a blocking loop that handles events from the primary `socket`. * then start a blocking loop that handles events from the primary `socket`.
* *
* The specified function will be used to create an `EventResult` from an * The specified function will be used to create an `Vst2EventResult` from
* `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 `EventResultPayload`.
@@ -241,7 +241,7 @@ class Vst2EventHandler : public AdHocSocketHandler<Thread> {
* @relates Vst2EventHandler::send_event * @relates Vst2EventHandler::send_event
* @relates passthrough_event * @relates passthrough_event
*/ */
template <invocable_returning<EventResult, Vst2Event&, bool> F> template <invocable_returning<Vst2EventResult, Vst2Event&, bool> F>
void receive_events(std::optional<std::pair<Vst2Logger&, bool>> logging, void receive_events(std::optional<std::pair<Vst2Logger&, bool>> logging,
F&& callback) { F&& callback) {
// Reading, processing, and writing back event data from the sockets // Reading, processing, and writing back event data from the sockets
@@ -257,7 +257,7 @@ class Vst2EventHandler : public AdHocSocketHandler<Thread> {
event.value_payload); event.value_payload);
} }
EventResult response = callback(event, on_main_thread); Vst2EventResult response = callback(event, on_main_thread);
if (logging) { if (logging) {
auto [logger, is_dispatch] = *logging; auto [logger, is_dispatch] = *logging;
logger.log_event_response( logger.log_event_response(
@@ -388,7 +388,7 @@ class Vst2Sockets : public Sockets {
* Unmarshall an `Vst2Event::Payload` back to the representation used by VST2, * Unmarshall an `Vst2Event::Payload` back to the representation used by VST2,
* pass that value to a callback function (either `AEffect::dispatcher()` for * pass that value to a callback function (either `AEffect::dispatcher()` for
* host -> plugin events or `audioMaster()` for plugin -> host events), and then * host -> plugin events or `audioMaster()` for plugin -> host events), and then
* serialize the results back into an `EventResult`. * serialize the results back into an `Vst2EventResult`.
* *
* This is the receiving analogue of the `*DataCovnerter` objects. * This is the receiving analogue of the `*DataCovnerter` objects.
* *
@@ -410,7 +410,9 @@ class Vst2Sockets : public Sockets {
*/ */
template < template <
invocable_returning<intptr_t, AEffect*, int, int, intptr_t, void*, float> F> invocable_returning<intptr_t, AEffect*, int, int, intptr_t, void*, float> F>
EventResult passthrough_event(AEffect* plugin, F&& callback, Vst2Event& event) { Vst2EventResult passthrough_event(AEffect* plugin,
F&& callback,
Vst2Event& event) {
// This buffer is used to write strings and small objects to. We'll // This buffer is used to write strings and small objects to. We'll
// initialize the beginning with null values to both prevent it from being // initialize the beginning with null values to both prevent it from being
// read as some arbitrary C-style string, and to make sure that // read as some arbitrary C-style string, and to make sure that
@@ -547,7 +549,7 @@ EventResult passthrough_event(AEffect* plugin, F&& callback, Vst2Event& event) {
std::visit(write_payload_fn, *event.value_payload); std::visit(write_payload_fn, *event.value_payload);
} }
return EventResult{.return_value = return_value, return Vst2EventResult{.return_value = return_value,
.payload = response_data, .payload = response_data,
.value_payload = value_response_data}; .value_payload = value_response_data};
} }
+1 -1
View File
@@ -477,7 +477,7 @@ void serialize(S& s, EventResultPayload& payload) {
/** /**
* AN instance of this should be sent back as a response to an incoming event. * AN instance of this should be sent back as a response to an incoming event.
*/ */
struct EventResult { struct Vst2EventResult {
/** /**
* The result that should be returned from the dispatch function. * The result that should be returned from the dispatch function.
*/ */
+17 -15
View File
@@ -91,9 +91,9 @@ Vst2PluginBridge::Vst2PluginBridge(audioMasterCallback host_callback)
incoming_midi_events.push_back( incoming_midi_events.push_back(
std::get<DynamicVstEvents>(event.payload)); std::get<DynamicVstEvents>(event.payload));
return EventResult{.return_value = 1, return Vst2EventResult{.return_value = 1,
.payload = nullptr, .payload = nullptr,
.value_payload = std::nullopt}; .value_payload = std::nullopt};
} break; } break;
// REAPER requires that `audioMasterSizeWindow()` calls are // REAPER requires that `audioMasterSizeWindow()` calls are
// handled from the GUI thread, which is the thread that // handled from the GUI thread, which is the thread that
@@ -105,9 +105,9 @@ Vst2PluginBridge::Vst2PluginBridge(audioMasterCallback host_callback)
incoming_resize = std::pair(event.index, event.value); incoming_resize = std::pair(event.index, event.value);
return EventResult{.return_value = 1, return Vst2EventResult{.return_value = 1,
.payload = nullptr, .payload = nullptr,
.value_payload = std::nullopt}; .value_payload = std::nullopt};
} break; } break;
// HACK: Certain plugins may have undesirable DAW-specific // HACK: Certain plugins may have undesirable DAW-specific
// behaviour. Chromaphone 3 for instance has broken // behaviour. Chromaphone 3 for instance has broken
@@ -125,9 +125,10 @@ Vst2PluginBridge::Vst2PluginBridge(audioMasterCallback host_callback)
std::string(product_name_override) + std::string(product_name_override) +
"\" instead of the actual host's name."); "\" instead of the actual host's name.");
return EventResult{.return_value = 1, return Vst2EventResult{
.payload = product_name_override, .return_value = 1,
.value_payload = std::nullopt}; .payload = product_name_override,
.value_payload = std::nullopt};
} }
} break; } break;
case audioMasterGetVendorString: { case audioMasterGetVendorString: {
@@ -139,9 +140,10 @@ Vst2PluginBridge::Vst2PluginBridge(audioMasterCallback host_callback)
std::string(vendor_name_override) + std::string(vendor_name_override) +
"\" instead of the actual host's vendor."); "\" instead of the actual host's vendor.");
return EventResult{.return_value = 1, return Vst2EventResult{
.payload = vendor_name_override, .return_value = 1,
.value_payload = std::nullopt}; .payload = vendor_name_override,
.value_payload = std::nullopt};
} }
} break; } break;
} }
@@ -157,7 +159,7 @@ Vst2PluginBridge::Vst2PluginBridge(audioMasterCallback host_callback)
// over the `dispatcher()` socket. This would happen whenever the plugin // over the `dispatcher()` socket. This would happen whenever the plugin
// calls `audioMasterIOChanged()` and after the host calls `effOpen()`. // calls `audioMasterIOChanged()` and after the host calls `effOpen()`.
const auto initialization_data = const auto initialization_data =
sockets.host_vst_control.receive_single<EventResult>(); sockets.host_vst_control.receive_single<Vst2EventResult>();
const auto initialized_plugin = const auto initialized_plugin =
std::get<AEffect>(initialization_data.payload); std::get<AEffect>(initialization_data.payload);
@@ -330,7 +332,7 @@ class DispatchDataConverter : public DefaultDataConverter {
void write_data(const int opcode, void write_data(const int opcode,
void* data, void* data,
const EventResult& response) const override { const Vst2EventResult& response) const override {
switch (opcode) { switch (opcode) {
case effOpen: { case effOpen: {
// Update our `AEffect` object one last time for improperly // Update our `AEffect` object one last time for improperly
@@ -418,7 +420,7 @@ class DispatchDataConverter : public DefaultDataConverter {
void write_value(const int opcode, void write_value(const int opcode,
intptr_t value, intptr_t value,
const EventResult& response) const override { const Vst2EventResult& response) const override {
switch (opcode) { switch (opcode) {
case effGetSpeakerArrangement: { case effGetSpeakerArrangement: {
// Same as the above, but now for the input speaker // Same as the above, but now for the input speaker
+9 -8
View File
@@ -167,7 +167,7 @@ Vst2Bridge::Vst2Bridge(MainContext& main_context,
// of this object will be sent over the `dispatcher()` socket. This would be // of this object will be sent over the `dispatcher()` socket. This would be
// done after the host calls `effOpen()`, and when the plugin calls // done after the host calls `effOpen()`, and when the plugin calls
// `audioMasterIOChanged()`. // `audioMasterIOChanged()`.
sockets.host_vst_control.send(EventResult{ sockets.host_vst_control.send(Vst2EventResult{
.return_value = 0, .payload = *plugin, .value_payload = std::nullopt}); .return_value = 0, .payload = *plugin, .value_payload = std::nullopt});
// After sending the AEffect struct we'll receive this instance's // After sending the AEffect struct we'll receive this instance's
@@ -385,9 +385,9 @@ void Vst2Bridge::run() {
plugin, event.opcode, event.index, event.value, plugin, event.opcode, event.index, event.value,
&events.as_c_events(), event.option); &events.as_c_events(), event.option);
EventResult response{.return_value = return_value, Vst2EventResult response{.return_value = return_value,
.payload = nullptr, .payload = nullptr,
.value_payload = std::nullopt}; .value_payload = std::nullopt};
return response; return response;
} else { } else {
@@ -588,7 +588,7 @@ class HostCallbackDataConverter : public DefaultDataConverter {
void write_data(const int opcode, void write_data(const int opcode,
void* data, void* data,
const EventResult& response) const override { const Vst2EventResult& response) const override {
switch (opcode) { switch (opcode) {
case audioMasterGetTime: case audioMasterGetTime:
// If the host returned a valid `VstTimeInfo` object, then we'll // If the host returned a valid `VstTimeInfo` object, then we'll
@@ -624,12 +624,13 @@ class HostCallbackDataConverter : public DefaultDataConverter {
void write_value(const int opcode, void write_value(const int opcode,
intptr_t value, intptr_t value,
const EventResult& response) const override { const Vst2EventResult& response) const override {
return DefaultDataConverter::write_value(opcode, value, response); return DefaultDataConverter::write_value(opcode, value, response);
} }
EventResult send_event(boost::asio::local::stream_protocol::socket& socket, Vst2EventResult send_event(
const Vst2Event& event) const override { boost::asio::local::stream_protocol::socket& socket,
const Vst2Event& event) const override {
if (mutually_recursive_callbacks.contains(event.opcode)) { if (mutually_recursive_callbacks.contains(event.opcode)) {
return mutual_recursion.fork([&]() { return mutual_recursion.fork([&]() {
return DefaultDataConverter::send_event(socket, event); return DefaultDataConverter::send_event(socket, event);