mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-07 03:50:11 +02:00
Clarify the return value override
This commit is contained in:
+19
-13
@@ -145,13 +145,11 @@ class DefaultDataConverter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the reponse back to the data pointer. It's also possible to
|
||||
* override the return value, this is used in one place to return a pointer
|
||||
* to a `VstTime` object that's contantly being updated.
|
||||
* Write the reponse back to the data pointer.
|
||||
*/
|
||||
virtual std::optional<intptr_t> write(const int /*opcode*/,
|
||||
void* data,
|
||||
const EventResult& response) {
|
||||
virtual void write(const int /*opcode*/,
|
||||
void* data,
|
||||
const EventResult& response) {
|
||||
if (response.data.has_value()) {
|
||||
char* output = static_cast<char*>(data);
|
||||
|
||||
@@ -162,8 +160,20 @@ class DefaultDataConverter {
|
||||
std::copy(response.data->begin(), response.data->end(), output);
|
||||
output[response.data->size()] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
/**
|
||||
* This function can override a callback's return value based on the opcode.
|
||||
* This is used in one place to return a pointer to a `VstTime` object
|
||||
* that's contantly being updated.
|
||||
*
|
||||
* @param opcode The opcode for the current event.
|
||||
* @param original The original return value as returned by the callback
|
||||
* function.
|
||||
*/
|
||||
virtual intptr_t return_value(const int /*opcode*/,
|
||||
const intptr_t original) {
|
||||
return original;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -221,13 +231,9 @@ intptr_t send_event(boost::asio::local::stream_protocol::socket& socket,
|
||||
response.data);
|
||||
}
|
||||
|
||||
const auto return_value_override =
|
||||
data_converter.write(opcode, data, response);
|
||||
if (return_value_override.has_value()) {
|
||||
return return_value_override.value();
|
||||
}
|
||||
data_converter.write(opcode, data, response);
|
||||
|
||||
return response.return_value;
|
||||
return data_converter.return_value(opcode, response.return_value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -182,9 +182,7 @@ class DispatchDataConverter : DefaultDataConverter {
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<intptr_t> write(const int opcode,
|
||||
void* data,
|
||||
const EventResult& response) {
|
||||
void write(const int opcode, void* data, const EventResult& response) {
|
||||
switch (opcode) {
|
||||
case effGetChunk:
|
||||
// Write the chunk data to some publically accessible place in
|
||||
@@ -194,14 +192,17 @@ class DispatchDataConverter : DefaultDataConverter {
|
||||
chunk.assign(response.data->begin(), response.data->end());
|
||||
|
||||
*static_cast<void**>(data) = chunk.data();
|
||||
return std::nullopt;
|
||||
break;
|
||||
default:
|
||||
return DefaultDataConverter::write(opcode, data, response);
|
||||
DefaultDataConverter::write(opcode, data, response);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
intptr_t return_value(const int opcode, const intptr_t original) {
|
||||
return DefaultDataConverter::return_value(opcode, original);
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<uint8_t>& chunk;
|
||||
};
|
||||
|
||||
@@ -221,22 +221,31 @@ class HostCallbackDataConverter : DefaultDataConverter {
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<intptr_t> write(const int opcode,
|
||||
void* data,
|
||||
const EventResult& response) {
|
||||
void write(const int opcode, void* data, const EventResult& response) {
|
||||
switch (opcode) {
|
||||
case audioMasterGetTime:
|
||||
// Write the returned `VstTimeInfo` struct into a field and make
|
||||
// the function return a poitner to it
|
||||
// the function return a poitner to it in the function below
|
||||
// TODO: Start a time to update this on the host bridge once
|
||||
// it's been requested. Not sure if this is needed though!
|
||||
time = *static_cast<const VstTimeInfo*>(
|
||||
static_cast<const void*>(response.data->data()));
|
||||
break;
|
||||
default:
|
||||
DefaultDataConverter::write(opcode, data, response);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
intptr_t return_value(const int opcode, const intptr_t original) {
|
||||
switch (opcode) {
|
||||
case audioMasterGetTime:
|
||||
// Return a pointer to the `VstTimeInfo` object written in the
|
||||
// function above
|
||||
return reinterpret_cast<intptr_t>(&time);
|
||||
break;
|
||||
default:
|
||||
return DefaultDataConverter::write(opcode, data, response);
|
||||
return DefaultDataConverter::return_value(opcode, original);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user