Handle effGetChunk correctly

This commit is contained in:
Robbert van der Helm
2020-03-09 23:53:36 +01:00
parent 7e75f913fa
commit 7fcf5abaf2
3 changed files with 38 additions and 3 deletions
+2 -1
View File
@@ -114,7 +114,8 @@ inline T read_object(Socket& socket) {
* (`audioMaster()`). The `dispatch()` function will require some more specific
* structs.
*/
struct DefaultDataConverter {
class DefaultDataConverter {
public:
EventPayload read(const int /*opcode*/, const void* data) {
if (data == nullptr) {
return nullptr;
+28 -2
View File
@@ -137,12 +137,18 @@ HostBridge::HostBridge(audioMasterCallback host_callback)
plugin = read_object(vst_host_aeffect, plugin);
}
struct DispatchDataConverter : DefaultDataConverter {
class DispatchDataConverter : DefaultDataConverter {
public:
DispatchDataConverter(std::vector<uint8_t>& chunk_data)
: chunk(chunk_data) {}
EventPayload read(const int opcode, const void* data) {
// There are some events that need specific structs that we can't simply
// serialize as a string because they might contain null bytes
// TODO: More of these structs
switch (opcode) {
case effGetChunk:
return WantsBinaryBuffer();
case effProcessEvents:
return DynamicVstEvents(*static_cast<const VstEvents*>(data));
break;
@@ -151,6 +157,26 @@ struct DispatchDataConverter : DefaultDataConverter {
break;
}
}
void write(const int opcode, void* data, const EventResult& response) {
switch (opcode) {
case effGetChunk:
// Write the chunk data to some publically accessible place in
// `HostBridge` and write a pointer to that struct to the data
// pointer
assert(response.data.has_value());
chunk.assign(response.data->begin(), response.data->end());
*static_cast<void**>(data) = chunk.data();
break;
default:
DefaultDataConverter::write(opcode, data, response);
break;
}
}
private:
std::vector<uint8_t>& chunk;
};
/**
@@ -183,7 +209,7 @@ intptr_t HostBridge::dispatch(AEffect* /*plugin*/,
}
// TODO: Maybe reuse buffers here when dealing with chunk data
DispatchDataConverter converter;
DispatchDataConverter converter(chunk_data);
return send_event(host_vst_dispatch, converter, opcode, index, value, data,
option, std::pair<Logger&, bool>(logger, true));
}
+8
View File
@@ -87,6 +87,14 @@ class HostBridge {
*/
AEffect plugin;
/**
* The VST hsot can query a plugin for arbitrary binary data such as
* presets. It will expect the plugin to write back a pointer that points to
* that data. This vector is where we store the chunk data for the last
* `effGetChunk` event.
*/
std::vector<uint8_t> chunk_data;
private:
/**
* Write output from an async pipe to the log on a line by line basis.