mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-09 20:29:10 +02:00
Also add a second payload value to event responses
This will only be used for `effGetSpeakerArrangement`.
This commit is contained in:
+122
-106
@@ -233,121 +233,137 @@ auto passthrough_event(AEffect* plugin, F callback) {
|
|||||||
std::array<char, max_string_length> string_buffer;
|
std::array<char, max_string_length> string_buffer;
|
||||||
string_buffer[0] = 0;
|
string_buffer[0] = 0;
|
||||||
|
|
||||||
void* data = std::visit(
|
auto read_payload_fn = overload{
|
||||||
overload{
|
[&](const std::nullptr_t&) -> void* { return nullptr; },
|
||||||
[&](const std::nullptr_t&) -> void* { return nullptr; },
|
[&](const std::string& s) -> void* {
|
||||||
[&](const std::string& s) -> void* {
|
return const_cast<char*>(s.c_str());
|
||||||
return const_cast<char*>(s.c_str());
|
},
|
||||||
},
|
[&](const std::vector<uint8_t>& buffer) -> void* {
|
||||||
[&](const std::vector<uint8_t>& buffer) -> void* {
|
return const_cast<uint8_t*>(buffer.data());
|
||||||
return const_cast<uint8_t*>(buffer.data());
|
},
|
||||||
},
|
[&](native_size_t& window_handle) -> void* {
|
||||||
[&](native_size_t& window_handle) -> void* {
|
// This is the X11 window handle that the editor should reparent
|
||||||
// This is the X11 window handle that the editor should
|
// itself to. We have a special wrapper around the dispatch
|
||||||
// reparent itself to. We have a special wrapper around the
|
// function that intercepts `effEditOpen` events and creates a
|
||||||
// dispatch function that intercepts `effEditOpen` events
|
// Win32 window and then finally embeds the X11 window Wine
|
||||||
// and creates a Win32 window and then finally embeds the
|
// created into this wnidow handle. Make sure to convert the
|
||||||
// X11 window Wine created into this wnidow handle. Make
|
// window ID first to `size_t` in case this is the 32-bit host.
|
||||||
// sure to convert the window ID first to `size_t` in case
|
return reinterpret_cast<void*>(
|
||||||
// this is the 32-bit host.
|
static_cast<size_t>(window_handle));
|
||||||
return reinterpret_cast<void*>(
|
},
|
||||||
static_cast<size_t>(window_handle));
|
[&](const AEffect&) -> void* { return nullptr; },
|
||||||
},
|
[&](DynamicVstEvents& events) -> void* {
|
||||||
[&](const AEffect&) -> void* { return nullptr; },
|
return &events.as_c_events();
|
||||||
[&](DynamicVstEvents& events) -> void* {
|
},
|
||||||
return &events.as_c_events();
|
[&](DynamicSpeakerArrangement& speaker_arrangement) -> void* {
|
||||||
},
|
return &speaker_arrangement.as_c_speaker_arrangement();
|
||||||
[&](DynamicSpeakerArrangement& speaker_arrangement) -> void* {
|
},
|
||||||
return &speaker_arrangement.as_c_speaker_arrangement();
|
[&](WantsChunkBuffer&) -> void* { return string_buffer.data(); },
|
||||||
},
|
[&](VstIOProperties& props) -> void* { return &props; },
|
||||||
[&](WantsChunkBuffer&) -> void* {
|
[&](VstMidiKeyName& key_name) -> void* { return &key_name; },
|
||||||
return string_buffer.data();
|
[&](VstParameterProperties& props) -> void* { return &props; },
|
||||||
},
|
[&](WantsVstRect&) -> void* { return string_buffer.data(); },
|
||||||
[&](VstIOProperties& props) -> void* { return &props; },
|
[&](const WantsVstTimeInfo&) -> void* { return nullptr; },
|
||||||
[&](VstMidiKeyName& key_name) -> void* { return &key_name; },
|
[&](WantsString&) -> void* { return string_buffer.data(); }};
|
||||||
[&](VstParameterProperties& props) -> void* { return &props; },
|
|
||||||
[&](WantsVstRect&) -> void* { return string_buffer.data(); },
|
// Almost all events pass data through the `data` argument. There are
|
||||||
[&](const WantsVstTimeInfo&) -> void* { return nullptr; },
|
// two events, `effSetParameter` and `effGetParameter` that also pass
|
||||||
[&](WantsString&) -> void* { return string_buffer.data(); }},
|
// data through the value argument.
|
||||||
event.payload);
|
void* data = std::visit(read_payload_fn, event.payload);
|
||||||
|
intptr_t value = event.value;
|
||||||
|
if (event.value_payload.has_value()) {
|
||||||
|
value = reinterpret_cast<intptr_t>(
|
||||||
|
std::visit(read_payload_fn, event.value_payload.value()));
|
||||||
|
}
|
||||||
|
|
||||||
const intptr_t return_value = callback(
|
const intptr_t return_value = callback(
|
||||||
plugin, event.opcode, event.index, event.value, data, event.option);
|
plugin, event.opcode, event.index, value, data, event.option);
|
||||||
|
|
||||||
// Only write back data when needed, this depends on the event payload
|
// Only write back data when needed, this depends on the event payload
|
||||||
// type
|
// type
|
||||||
const auto response_data = std::visit(
|
auto write_payload_fn = overload{
|
||||||
overload{
|
[&](auto) -> EventResposnePayload { return nullptr; },
|
||||||
[&](auto) -> EventResposnePayload { return nullptr; },
|
[&](const AEffect& updated_plugin) -> EventResposnePayload {
|
||||||
[&](const AEffect& updated_plugin) -> EventResposnePayload {
|
// This is a bit of a special case! Instead of writing some
|
||||||
// This is a bit of a special case! Instead of writing some
|
// return value, we will update values on the native VST
|
||||||
// return value, we will update values on the native VST
|
// plugin's `AEffect` object. This is triggered by the
|
||||||
// plugin's `AEffect` object. This is triggered by the
|
// `audioMasterIOChanged` callback from the hsoted VST plugin.
|
||||||
// `audioMasterIOChanged` callback from the hsoted VST
|
|
||||||
// plugin.
|
|
||||||
|
|
||||||
// These are the same fields written by bitsery in the
|
// These are the same fields written by bitsery in the
|
||||||
// initialization of `PluginBridge`. I can't think of a way
|
// initialization of `PluginBridge`. I can't think of a way to
|
||||||
// to reuse the serializer without first having to serialize
|
// reuse the serializer without first having to serialize
|
||||||
// `updated_plugin` first though.
|
// `updated_plugin` first though.
|
||||||
plugin->magic = updated_plugin.magic;
|
plugin->magic = updated_plugin.magic;
|
||||||
plugin->numPrograms = updated_plugin.numPrograms;
|
plugin->numPrograms = updated_plugin.numPrograms;
|
||||||
plugin->numParams = updated_plugin.numParams;
|
plugin->numParams = updated_plugin.numParams;
|
||||||
plugin->numInputs = updated_plugin.numInputs;
|
plugin->numInputs = updated_plugin.numInputs;
|
||||||
plugin->numOutputs = updated_plugin.numOutputs;
|
plugin->numOutputs = updated_plugin.numOutputs;
|
||||||
plugin->flags = updated_plugin.flags;
|
plugin->flags = updated_plugin.flags;
|
||||||
plugin->initialDelay = updated_plugin.initialDelay;
|
plugin->initialDelay = updated_plugin.initialDelay;
|
||||||
plugin->empty3a = updated_plugin.empty3a;
|
plugin->empty3a = updated_plugin.empty3a;
|
||||||
plugin->empty3b = updated_plugin.empty3b;
|
plugin->empty3b = updated_plugin.empty3b;
|
||||||
plugin->unkown_float = updated_plugin.unkown_float;
|
plugin->unkown_float = updated_plugin.unkown_float;
|
||||||
plugin->uniqueID = updated_plugin.uniqueID;
|
plugin->uniqueID = updated_plugin.uniqueID;
|
||||||
plugin->version = updated_plugin.version;
|
plugin->version = updated_plugin.version;
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
},
|
||||||
|
[&](WantsChunkBuffer&) -> EventResposnePayload {
|
||||||
|
// 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 value from the event determines how much data the
|
||||||
|
// plugin has written
|
||||||
|
const uint8_t* chunk_data = *static_cast<uint8_t**>(data);
|
||||||
|
return std::vector<uint8_t>(chunk_data,
|
||||||
|
chunk_data + return_value);
|
||||||
|
},
|
||||||
|
[&](VstIOProperties& props) -> EventResposnePayload {
|
||||||
|
return props;
|
||||||
|
},
|
||||||
|
[&](VstMidiKeyName& key_name) -> EventResposnePayload {
|
||||||
|
return key_name;
|
||||||
|
},
|
||||||
|
[&](VstParameterProperties& props) -> EventResposnePayload {
|
||||||
|
return props;
|
||||||
|
},
|
||||||
|
[&](WantsVstRect&) -> EventResposnePayload {
|
||||||
|
// The plugin has written a pointer to a VstRect struct into the
|
||||||
|
// data poitner
|
||||||
|
return **static_cast<VstRect**>(data);
|
||||||
|
},
|
||||||
|
[&](WantsVstTimeInfo&) -> EventResposnePayload {
|
||||||
|
// Not sure why the VST API has twenty different ways of
|
||||||
|
// returning structs, but in this case the value returned from
|
||||||
|
// the callback function is actually a pointer to a
|
||||||
|
// `VstTimeInfo` struct! It can also be a null pointer if the
|
||||||
|
// host doesn't support this.
|
||||||
|
const auto time_info =
|
||||||
|
reinterpret_cast<const VstTimeInfo*>(return_value);
|
||||||
|
if (time_info == nullptr) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
},
|
} else {
|
||||||
[&](WantsChunkBuffer&) -> EventResposnePayload {
|
return *time_info;
|
||||||
// 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 value from the event determines
|
[&](WantsString&) -> EventResposnePayload {
|
||||||
// how much data the plugin has written
|
return std::string(static_cast<char*>(data));
|
||||||
const uint8_t* chunk_data = *static_cast<uint8_t**>(data);
|
}};
|
||||||
return std::vector<uint8_t>(chunk_data,
|
|
||||||
chunk_data + return_value);
|
|
||||||
},
|
|
||||||
[&](VstIOProperties& props) -> EventResposnePayload {
|
|
||||||
return props;
|
|
||||||
},
|
|
||||||
[&](VstMidiKeyName& key_name) -> EventResposnePayload {
|
|
||||||
return key_name;
|
|
||||||
},
|
|
||||||
[&](VstParameterProperties& props) -> EventResposnePayload {
|
|
||||||
return props;
|
|
||||||
},
|
|
||||||
[&](WantsVstRect&) -> EventResposnePayload {
|
|
||||||
// The plugin has written a pointer to a VstRect struct
|
|
||||||
// into the data poitner
|
|
||||||
return **static_cast<VstRect**>(data);
|
|
||||||
},
|
|
||||||
[&](WantsVstTimeInfo&) -> EventResposnePayload {
|
|
||||||
// Not sure why the VST API has twenty different ways of
|
|
||||||
// returning structs, but in this case the value returned
|
|
||||||
// from the callback function is actually a pointer to a
|
|
||||||
// `VstTimeInfo` struct! It can also be a null pointer if
|
|
||||||
// the host doesn't support this.
|
|
||||||
const auto time_info =
|
|
||||||
reinterpret_cast<const VstTimeInfo*>(return_value);
|
|
||||||
if (time_info == nullptr) {
|
|
||||||
return nullptr;
|
|
||||||
} else {
|
|
||||||
return *time_info;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[&](WantsString&) -> EventResposnePayload {
|
|
||||||
return std::string(static_cast<char*>(data));
|
|
||||||
}},
|
|
||||||
event.payload);
|
|
||||||
|
|
||||||
EventResult response{return_value, response_data};
|
// As mentioned about, the `effSetSpeakerArrangement` and
|
||||||
|
// `effGetSpeakerArrangement` events are the only two events that use
|
||||||
|
// the value argument as a pointer to write data to. Additionally, the
|
||||||
|
// `effGetSpeakerArrangement` expects the plugin to write its own data
|
||||||
|
// to this value. Hence why we need to encode the response here
|
||||||
|
// separately.
|
||||||
|
const EventResposnePayload response_data =
|
||||||
|
std::visit(write_payload_fn, event.payload);
|
||||||
|
std::optional<EventResposnePayload> value_response_data = std::nullopt;
|
||||||
|
if (event.value_payload.has_value()) {
|
||||||
|
value_response_data =
|
||||||
|
std::visit(write_payload_fn, event.value_payload.value());
|
||||||
|
}
|
||||||
|
|
||||||
|
EventResult response{return_value, response_data, value_response_data};
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -161,6 +161,7 @@ void Logger::log_event(bool is_dispatch,
|
|||||||
message << "(index = " << index << ", value = " << value
|
message << "(index = " << index << ", value = " << value
|
||||||
<< ", option = " << option << ", data = ";
|
<< ", option = " << option << ", data = ";
|
||||||
|
|
||||||
|
// TODO: Print value payload
|
||||||
std::visit(
|
std::visit(
|
||||||
overload{
|
overload{
|
||||||
[&](const std::nullptr_t&) { message << "<nullptr>"; },
|
[&](const std::nullptr_t&) { message << "<nullptr>"; },
|
||||||
@@ -185,7 +186,7 @@ void Logger::log_event(bool is_dispatch,
|
|||||||
},
|
},
|
||||||
[&](const DynamicSpeakerArrangement& speaker_arrangement) {
|
[&](const DynamicSpeakerArrangement& speaker_arrangement) {
|
||||||
message << "<" << speaker_arrangement.speakers.size()
|
message << "<" << speaker_arrangement.speakers.size()
|
||||||
<< " speakers>";
|
<< " output_speakers>";
|
||||||
},
|
},
|
||||||
[&](const WantsChunkBuffer&) {
|
[&](const WantsChunkBuffer&) {
|
||||||
message << "<writable_buffer>";
|
message << "<writable_buffer>";
|
||||||
@@ -224,6 +225,7 @@ void Logger::log_event_response(bool is_dispatch,
|
|||||||
|
|
||||||
message << return_value;
|
message << return_value;
|
||||||
|
|
||||||
|
// TODO: Print value payload
|
||||||
std::visit(
|
std::visit(
|
||||||
overload{
|
overload{
|
||||||
[&](const std::nullptr_t&) {},
|
[&](const std::nullptr_t&) {},
|
||||||
@@ -240,6 +242,10 @@ void Logger::log_event_response(bool is_dispatch,
|
|||||||
message << ", <" << buffer.size() << " byte chunk>";
|
message << ", <" << buffer.size() << " byte chunk>";
|
||||||
},
|
},
|
||||||
[&](const AEffect&) { message << ", <AEffect_object>"; },
|
[&](const AEffect&) { message << ", <AEffect_object>"; },
|
||||||
|
[&](const DynamicSpeakerArrangement& speaker_arrangement) {
|
||||||
|
message << ", <" << speaker_arrangement.speakers.size()
|
||||||
|
<< " output_speakers>";
|
||||||
|
},
|
||||||
[&](const VstIOProperties&) { message << ", <io_properties>"; },
|
[&](const VstIOProperties&) { message << ", <io_properties>"; },
|
||||||
[&](const VstMidiKeyName&) { message << ", <key_name>"; },
|
[&](const VstMidiKeyName&) { message << ", <key_name>"; },
|
||||||
[&](const VstParameterProperties& props) {
|
[&](const VstParameterProperties& props) {
|
||||||
|
|||||||
@@ -426,6 +426,7 @@ using EventResposnePayload = std::variant<std::nullptr_t,
|
|||||||
std::string,
|
std::string,
|
||||||
std::vector<uint8_t>,
|
std::vector<uint8_t>,
|
||||||
AEffect,
|
AEffect,
|
||||||
|
DynamicSpeakerArrangement,
|
||||||
VstIOProperties,
|
VstIOProperties,
|
||||||
VstMidiKeyName,
|
VstMidiKeyName,
|
||||||
VstParameterProperties,
|
VstParameterProperties,
|
||||||
@@ -444,6 +445,9 @@ void serialize(S& s, EventResposnePayload& payload) {
|
|||||||
s.container1b(buffer, binary_buffer_size);
|
s.container1b(buffer, binary_buffer_size);
|
||||||
},
|
},
|
||||||
[](S& s, AEffect& effect) { s.object(effect); },
|
[](S& s, AEffect& effect) { s.object(effect); },
|
||||||
|
[&](DynamicSpeakerArrangement& speaker_arrangement) -> void* {
|
||||||
|
return &speaker_arrangement.as_c_speaker_arrangement();
|
||||||
|
},
|
||||||
[](S& s, VstIOProperties& props) { s.object(props); },
|
[](S& s, VstIOProperties& props) { s.object(props); },
|
||||||
[](S& s, VstMidiKeyName& key_name) { s.object(key_name); },
|
[](S& s, VstMidiKeyName& key_name) { s.object(key_name); },
|
||||||
[](S& s, VstParameterProperties& props) { s.object(props); },
|
[](S& s, VstParameterProperties& props) { s.object(props); },
|
||||||
@@ -464,13 +468,22 @@ struct EventResult {
|
|||||||
* into the void pointer, but sometimes an event response should forward
|
* into the void pointer, but sometimes an event response should forward
|
||||||
* some kind of special struct.
|
* some kind of special struct.
|
||||||
*/
|
*/
|
||||||
|
// TODO: Fix typo and rename to `EventResultPayload` for consistency
|
||||||
EventResposnePayload payload;
|
EventResposnePayload 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<EventResposnePayload> value_payload;
|
||||||
|
|
||||||
template <typename S>
|
template <typename S>
|
||||||
void serialize(S& s) {
|
void serialize(S& s) {
|
||||||
s.value8b(return_value);
|
s.value8b(return_value);
|
||||||
|
|
||||||
s.object(payload);
|
s.object(payload);
|
||||||
|
s.ext(value_payload, bitsery::ext::StdOptional(),
|
||||||
|
[](S& s, auto& v) { s.object(v); });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -289,7 +289,7 @@ PluginBridge::PluginBridge(audioMasterCallback host_callback)
|
|||||||
|
|
||||||
incoming_midi_events.push_back(
|
incoming_midi_events.push_back(
|
||||||
std::get<DynamicVstEvents>(event.payload));
|
std::get<DynamicVstEvents>(event.payload));
|
||||||
EventResult response{1, nullptr};
|
EventResult response{1, nullptr, std::nullopt};
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ void WineBridge::handle_dispatch() {
|
|||||||
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, nullptr};
|
EventResult response{return_value, nullptr, std::nullopt};
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user