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* data,
const EventResult& response) const {
const Vst2EventResult& response) const {
// The default behavior is to handle this as a null terminated C-style
// string
std::visit(overload{[&](const auto&) {},
@@ -62,18 +62,19 @@ void DefaultDataConverter::write_data(const int /*opcode*/,
response.payload);
}
void DefaultDataConverter::write_value(const int /*opcode*/,
intptr_t /*value*/,
const EventResult& /*response*/) const {}
void DefaultDataConverter::write_value(
const int /*opcode*/,
intptr_t /*value*/,
const Vst2EventResult& /*response*/) const {}
intptr_t DefaultDataConverter::return_value(const int /*opcode*/,
const intptr_t original) const {
return original;
}
EventResult DefaultDataConverter::send_event(
Vst2EventResult DefaultDataConverter::send_event(
boost::asio::local::stream_protocol::socket& socket,
const Vst2Event& event) const {
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,
void* data,
const EventResult& response) const;
const Vst2EventResult& response) const;
/**
* 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,
intptr_t value,
const EventResult& response) const;
const Vst2EventResult& response) const;
/**
* 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
* specific opcodes to allow mutually recursive calling sequences.
*/
virtual EventResult send_event(
virtual Vst2EventResult send_event(
boost::asio::local::stream_protocol::socket& socket,
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
// that potentially need to have their responses handled on the same
// calling thread (i.e. mutual recursion).
const EventResult response = this->send(
const Vst2EventResult response = this->send(
[&](boost::asio::local::stream_protocol::socket& socket) {
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
* then start a blocking loop that handles events from the primary `socket`.
*
* The specified function will be used to create an `EventResult` from an
* `Vst2Event`. This is almost always uses `passthrough_event()`, which
* The specified function will be used to create an `Vst2EventResult` from
* an `Vst2Event`. This is almost always uses `passthrough_event()`, which
* converts a `Vst2Event::Payload` into the format used by VST2, calls
* either `dispatch()` or `audioMaster()` depending on the context, and then
* serializes the result back into an `EventResultPayload`.
@@ -241,7 +241,7 @@ class Vst2EventHandler : public AdHocSocketHandler<Thread> {
* @relates Vst2EventHandler::send_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,
F&& callback) {
// Reading, processing, and writing back event data from the sockets
@@ -257,7 +257,7 @@ class Vst2EventHandler : public AdHocSocketHandler<Thread> {
event.value_payload);
}
EventResult response = callback(event, on_main_thread);
Vst2EventResult response = callback(event, on_main_thread);
if (logging) {
auto [logger, is_dispatch] = *logging;
logger.log_event_response(
@@ -388,7 +388,7 @@ class Vst2Sockets : public Sockets {
* Unmarshall an `Vst2Event::Payload` back to the representation used by VST2,
* pass that value to a callback function (either `AEffect::dispatcher()` for
* 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.
*
@@ -410,7 +410,9 @@ class Vst2Sockets : public Sockets {
*/
template <
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
// initialize the beginning with null values to both prevent it from being
// 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);
}
return EventResult{.return_value = return_value,
.payload = response_data,
.value_payload = value_response_data};
return Vst2EventResult{.return_value = return_value,
.payload = 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.
*/
struct EventResult {
struct Vst2EventResult {
/**
* 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(
std::get<DynamicVstEvents>(event.payload));
return EventResult{.return_value = 1,
.payload = nullptr,
.value_payload = std::nullopt};
return Vst2EventResult{.return_value = 1,
.payload = nullptr,
.value_payload = std::nullopt};
} break;
// REAPER requires that `audioMasterSizeWindow()` calls are
// 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);
return EventResult{.return_value = 1,
.payload = nullptr,
.value_payload = std::nullopt};
return Vst2EventResult{.return_value = 1,
.payload = nullptr,
.value_payload = std::nullopt};
} break;
// HACK: Certain plugins may have undesirable DAW-specific
// behaviour. Chromaphone 3 for instance has broken
@@ -125,9 +125,10 @@ Vst2PluginBridge::Vst2PluginBridge(audioMasterCallback host_callback)
std::string(product_name_override) +
"\" instead of the actual host's name.");
return EventResult{.return_value = 1,
.payload = product_name_override,
.value_payload = std::nullopt};
return Vst2EventResult{
.return_value = 1,
.payload = product_name_override,
.value_payload = std::nullopt};
}
} break;
case audioMasterGetVendorString: {
@@ -139,9 +140,10 @@ Vst2PluginBridge::Vst2PluginBridge(audioMasterCallback host_callback)
std::string(vendor_name_override) +
"\" instead of the actual host's vendor.");
return EventResult{.return_value = 1,
.payload = vendor_name_override,
.value_payload = std::nullopt};
return Vst2EventResult{
.return_value = 1,
.payload = vendor_name_override,
.value_payload = std::nullopt};
}
} break;
}
@@ -157,7 +159,7 @@ Vst2PluginBridge::Vst2PluginBridge(audioMasterCallback host_callback)
// over the `dispatcher()` socket. This would happen whenever the plugin
// calls `audioMasterIOChanged()` and after the host calls `effOpen()`.
const auto initialization_data =
sockets.host_vst_control.receive_single<EventResult>();
sockets.host_vst_control.receive_single<Vst2EventResult>();
const auto initialized_plugin =
std::get<AEffect>(initialization_data.payload);
@@ -330,7 +332,7 @@ class DispatchDataConverter : public DefaultDataConverter {
void write_data(const int opcode,
void* data,
const EventResult& response) const override {
const Vst2EventResult& response) const override {
switch (opcode) {
case effOpen: {
// Update our `AEffect` object one last time for improperly
@@ -418,7 +420,7 @@ class DispatchDataConverter : public DefaultDataConverter {
void write_value(const int opcode,
intptr_t value,
const EventResult& response) const override {
const Vst2EventResult& response) const override {
switch (opcode) {
case effGetSpeakerArrangement: {
// 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
// done after the host calls `effOpen()`, and when the plugin calls
// `audioMasterIOChanged()`.
sockets.host_vst_control.send(EventResult{
sockets.host_vst_control.send(Vst2EventResult{
.return_value = 0, .payload = *plugin, .value_payload = std::nullopt});
// 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,
&events.as_c_events(), event.option);
EventResult response{.return_value = return_value,
.payload = nullptr,
.value_payload = std::nullopt};
Vst2EventResult response{.return_value = return_value,
.payload = nullptr,
.value_payload = std::nullopt};
return response;
} else {
@@ -588,7 +588,7 @@ class HostCallbackDataConverter : public DefaultDataConverter {
void write_data(const int opcode,
void* data,
const EventResult& response) const override {
const Vst2EventResult& response) const override {
switch (opcode) {
case audioMasterGetTime:
// 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,
intptr_t value,
const EventResult& response) const override {
const Vst2EventResult& response) const override {
return DefaultDataConverter::write_value(opcode, value, response);
}
EventResult send_event(boost::asio::local::stream_protocol::socket& socket,
const Vst2Event& event) const override {
Vst2EventResult send_event(
boost::asio::local::stream_protocol::socket& socket,
const Vst2Event& event) const override {
if (mutually_recursive_callbacks.contains(event.opcode)) {
return mutual_recursion.fork([&]() {
return DefaultDataConverter::send_event(socket, event);