mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-10 04:30:12 +02:00
Fix VstTimeinfo responses and allow null responses
The host is allowed to return a null pointer if it doesn't support the query.
This commit is contained in:
@@ -130,7 +130,9 @@ void Editor::handle_events() {
|
||||
|
||||
// Handle X11 events
|
||||
// TODO: Check if we should forward other events mostly to prevent
|
||||
// unnecessary GUI processing in the background
|
||||
// unnecessary GUI processing in the background. Since
|
||||
// `effEditIdle` should only be called when the plugin's editor is
|
||||
// open this should not cause any different in CPU though.
|
||||
// TODO: Check whether drag and drop works out of the box
|
||||
xcb_generic_event_t* generic_event;
|
||||
while ((generic_event = xcb_poll_for_event(x11_connection.get())) !=
|
||||
|
||||
@@ -272,7 +272,7 @@ class HostCallbackDataConverter : DefaultDataConverter {
|
||||
public:
|
||||
HostCallbackDataConverter(AEffect* plugin,
|
||||
Editor& editor,
|
||||
VstTimeInfo& time_info)
|
||||
std::optional<VstTimeInfo>& time_info)
|
||||
: plugin(plugin), editor(editor), time_info(time_info) {}
|
||||
|
||||
std::optional<EventPayload> read(const int opcode,
|
||||
@@ -314,8 +314,15 @@ class HostCallbackDataConverter : DefaultDataConverter {
|
||||
switch (opcode) {
|
||||
case audioMasterGetTime:
|
||||
// Write the returned `VstTimeInfo` struct into a field and make
|
||||
// the function return a poitner to it in the function below
|
||||
time_info = std::get<VstTimeInfo>(response.payload);
|
||||
// the function return a poitner to it in the function below.
|
||||
// Depending on whether the host supported the requested time
|
||||
// information this operations returns either a null pointer or
|
||||
// a pointer to a `VstTimeInfo` object.
|
||||
if (std::holds_alternative<std::monostate>(response.payload)) {
|
||||
time_info = std::nullopt;
|
||||
} else {
|
||||
time_info = std::get<VstTimeInfo>(response.payload);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
DefaultDataConverter::write(opcode, data, response);
|
||||
@@ -325,12 +332,16 @@ class HostCallbackDataConverter : DefaultDataConverter {
|
||||
|
||||
intptr_t return_value(const int opcode, const intptr_t original) {
|
||||
switch (opcode) {
|
||||
case audioMasterGetTime:
|
||||
case audioMasterGetTime: {
|
||||
// Return a pointer to the `VstTimeInfo` object written in the
|
||||
// function above
|
||||
// TODO: This is incorrect!
|
||||
return reinterpret_cast<intptr_t>(&time);
|
||||
break;
|
||||
VstTimeInfo* time_info_pointer = nullptr;
|
||||
if (time_info.has_value()) {
|
||||
time_info_pointer = &time_info.value();
|
||||
}
|
||||
|
||||
return reinterpret_cast<intptr_t>(time_info_pointer);
|
||||
} break;
|
||||
default:
|
||||
return DefaultDataConverter::return_value(opcode, original);
|
||||
break;
|
||||
@@ -341,7 +352,7 @@ class HostCallbackDataConverter : DefaultDataConverter {
|
||||
AEffect* plugin;
|
||||
// TODO: Clean up
|
||||
Editor& editor;
|
||||
VstTimeInfo& time_info;
|
||||
std::optional<VstTimeInfo>& time_info;
|
||||
};
|
||||
|
||||
intptr_t PluginBridge::host_callback(AEffect* effect,
|
||||
|
||||
@@ -67,9 +67,11 @@ class PluginBridge {
|
||||
|
||||
/**
|
||||
* With the `audioMasterGetTime` host callback the plugin expects the return
|
||||
* value from the calblack to be a pointer to a VstTimeInfo struct.
|
||||
* value from the calblack to be a pointer to a VstTimeInfo struct. If the
|
||||
* host did not support a certain time info query, than we'll store the
|
||||
* returned null pointer as a nullopt.
|
||||
*/
|
||||
VstTimeInfo time_info;
|
||||
std::optional<VstTimeInfo> time_info;
|
||||
|
||||
private:
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user