mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-07 03:50:11 +02:00
Correct reading chunks
They're not actually stored in `data`, but in `*data`.
This commit is contained in:
+16
-21
@@ -225,25 +225,18 @@ void passthrough_event(boost::asio::local::stream_protocol::socket& socket,
|
||||
event.payload, event.option);
|
||||
}
|
||||
|
||||
// Some buffer for the event to write to if needed. We only pass around a
|
||||
// marker struct to indicate that this is indeed the case.
|
||||
std::vector<char> binary_buffer;
|
||||
std::array<char, max_string_length> string_buffer;
|
||||
void* data = std::visit(
|
||||
overload{[&](const std::nullptr_t&) -> void* { return nullptr; },
|
||||
[&](const std::string& s) -> void* {
|
||||
return const_cast<char*>(s.c_str());
|
||||
},
|
||||
[&](DynamicVstEvents& events) -> void* {
|
||||
return &events.as_c_events();
|
||||
},
|
||||
[&](WantsBinaryBuffer&) -> void* {
|
||||
// Only allocate when we actually need this, i.e. when
|
||||
// we're getting a chunk from the plugin
|
||||
binary_buffer.resize(binary_buffer_size);
|
||||
return binary_buffer.data();
|
||||
},
|
||||
[&](WantsString&) -> void* { return string_buffer.data(); }},
|
||||
overload{
|
||||
[&](const std::nullptr_t&) -> void* { return nullptr; },
|
||||
[&](const std::string& s) -> void* {
|
||||
return const_cast<char*>(s.c_str());
|
||||
},
|
||||
[&](DynamicVstEvents& events) -> void* {
|
||||
return &events.as_c_events();
|
||||
},
|
||||
[&](WantsChunkBuffer&) -> void* { return string_buffer.data(); },
|
||||
[&](WantsString&) -> void* { return string_buffer.data(); }},
|
||||
event.payload);
|
||||
|
||||
const intptr_t return_value = callback(plugin, event.opcode, event.index,
|
||||
@@ -255,10 +248,12 @@ void passthrough_event(boost::asio::local::stream_protocol::socket& socket,
|
||||
// report some data back?
|
||||
const auto response_data = std::visit(
|
||||
overload{
|
||||
[&](WantsBinaryBuffer&) -> std::optional<std::string> {
|
||||
// In this case the return value from the event determines how
|
||||
// much data the plugin has written
|
||||
return std::string(static_cast<char*>(data), return_value);
|
||||
[&](WantsChunkBuffer&) -> std::optional<std::string> {
|
||||
// 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
|
||||
return std::string(*static_cast<char**>(data), return_value);
|
||||
},
|
||||
[&](WantsString&) -> std::optional<std::string> {
|
||||
return std::string(static_cast<char*>(data));
|
||||
|
||||
@@ -164,7 +164,7 @@ void Logger::log_event(bool is_dispatch,
|
||||
[&](const DynamicVstEvents& events) {
|
||||
message << "<" << events.events.size() << " midi_events>";
|
||||
},
|
||||
[&](const WantsBinaryBuffer&) {
|
||||
[&](const WantsChunkBuffer&) {
|
||||
message << "<writable_buffer>";
|
||||
},
|
||||
[&](const WantsString&) { message << "<writable_string>"; }},
|
||||
|
||||
@@ -111,11 +111,11 @@ class alignas(16) DynamicVstEvents {
|
||||
};
|
||||
|
||||
/**
|
||||
* Marker struct to indicate that that the event needs to write arbitrary data
|
||||
* to the void pointer, with the return value indicating the amount of data
|
||||
* actually written.
|
||||
* Marker struct to indicate that that the event writes arbitrary data into one
|
||||
* of its own buffers and uses the void pointer to store start of that data,
|
||||
* with the return value indicating the size of the array.
|
||||
*/
|
||||
struct WantsBinaryBuffer {};
|
||||
struct WantsChunkBuffer {};
|
||||
|
||||
/**
|
||||
* Marker struct to indicate that that the event requires some buffer to write
|
||||
@@ -154,7 +154,7 @@ struct WantsString {};
|
||||
using EventPayload = std::variant<std::nullptr_t,
|
||||
std::string,
|
||||
DynamicVstEvents,
|
||||
WantsBinaryBuffer,
|
||||
WantsChunkBuffer,
|
||||
WantsString>;
|
||||
|
||||
template <typename S>
|
||||
@@ -170,7 +170,7 @@ void serialize(S& s, EventPayload& payload) {
|
||||
s.container1b(event.dump);
|
||||
});
|
||||
},
|
||||
[](S&, WantsBinaryBuffer&) {}, [](S&, WantsString&) {}});
|
||||
[](S&, WantsChunkBuffer&) {}, [](S&, WantsString&) {}});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -148,7 +148,7 @@ class DispatchDataConverter : DefaultDataConverter {
|
||||
// TODO: More of these structs
|
||||
switch (opcode) {
|
||||
case effGetChunk:
|
||||
return WantsBinaryBuffer();
|
||||
return WantsChunkBuffer();
|
||||
case effProcessEvents:
|
||||
return DynamicVstEvents(*static_cast<const VstEvents*>(data));
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user