mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-09 20:29:10 +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
|
* Write the reponse back to the data pointer.
|
||||||
* override the return value, this is used in one place to return a pointer
|
|
||||||
* to a `VstTime` object that's contantly being updated.
|
|
||||||
*/
|
*/
|
||||||
virtual std::optional<intptr_t> write(const int /*opcode*/,
|
virtual void write(const int /*opcode*/,
|
||||||
void* data,
|
void* data,
|
||||||
const EventResult& response) {
|
const EventResult& response) {
|
||||||
if (response.data.has_value()) {
|
if (response.data.has_value()) {
|
||||||
char* output = static_cast<char*>(data);
|
char* output = static_cast<char*>(data);
|
||||||
|
|
||||||
@@ -162,8 +160,20 @@ class DefaultDataConverter {
|
|||||||
std::copy(response.data->begin(), response.data->end(), output);
|
std::copy(response.data->begin(), response.data->end(), output);
|
||||||
output[response.data->size()] = 0;
|
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);
|
response.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto return_value_override =
|
data_converter.write(opcode, data, response);
|
||||||
data_converter.write(opcode, data, response);
|
|
||||||
if (return_value_override.has_value()) {
|
|
||||||
return return_value_override.value();
|
|
||||||
}
|
|
||||||
|
|
||||||
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 write(const int opcode, void* data, const EventResult& response) {
|
||||||
void* data,
|
|
||||||
const EventResult& response) {
|
|
||||||
switch (opcode) {
|
switch (opcode) {
|
||||||
case effGetChunk:
|
case effGetChunk:
|
||||||
// Write the chunk data to some publically accessible place in
|
// 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());
|
chunk.assign(response.data->begin(), response.data->end());
|
||||||
|
|
||||||
*static_cast<void**>(data) = chunk.data();
|
*static_cast<void**>(data) = chunk.data();
|
||||||
return std::nullopt;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return DefaultDataConverter::write(opcode, data, response);
|
DefaultDataConverter::write(opcode, data, response);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
intptr_t return_value(const int opcode, const intptr_t original) {
|
||||||
|
return DefaultDataConverter::return_value(opcode, original);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<uint8_t>& chunk;
|
std::vector<uint8_t>& chunk;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -221,22 +221,31 @@ class HostCallbackDataConverter : DefaultDataConverter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<intptr_t> write(const int opcode,
|
void write(const int opcode, void* data, const EventResult& response) {
|
||||||
void* data,
|
|
||||||
const EventResult& response) {
|
|
||||||
switch (opcode) {
|
switch (opcode) {
|
||||||
case audioMasterGetTime:
|
case audioMasterGetTime:
|
||||||
// Write the returned `VstTimeInfo` struct into a field and make
|
// 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
|
// TODO: Start a time to update this on the host bridge once
|
||||||
// it's been requested. Not sure if this is needed though!
|
// it's been requested. Not sure if this is needed though!
|
||||||
time = *static_cast<const VstTimeInfo*>(
|
time = *static_cast<const VstTimeInfo*>(
|
||||||
static_cast<const void*>(response.data->data()));
|
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);
|
return reinterpret_cast<intptr_t>(&time);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return DefaultDataConverter::write(opcode, data, response);
|
return DefaultDataConverter::return_value(opcode, original);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user