mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-09 20:29:10 +02:00
Answer event queries within the Wine VST host
This commit is contained in:
+1
-1
@@ -44,6 +44,6 @@ executable(
|
|||||||
],
|
],
|
||||||
native : false,
|
native : false,
|
||||||
include_directories : include_dir,
|
include_directories : include_dir,
|
||||||
dependencies : [],
|
|
||||||
link_args : []
|
link_args : []
|
||||||
|
dependencies : [msgpack_dep],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
|
#include <iostream>
|
||||||
#include <msgpack.hpp>
|
#include <msgpack.hpp>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
@@ -49,14 +50,14 @@ struct EventResult {
|
|||||||
*
|
*
|
||||||
* @relates read_object
|
* @relates read_object
|
||||||
*/
|
*/
|
||||||
template <typename Stream, typename T>
|
template <typename T, typename Stream>
|
||||||
inline void write_object(Stream& stream, const T& object) {
|
inline void write_object(Stream& stream, const T& object) {
|
||||||
// TODO: Reuse buffers
|
// TODO: Reuse buffers
|
||||||
msgpack::sbuffer buffer;
|
msgpack::sbuffer buffer;
|
||||||
msgpack::pack(buffer, object);
|
msgpack::pack(buffer, object);
|
||||||
|
|
||||||
stream << buffer.size();
|
stream << buffer.size();
|
||||||
stream << buffer.data();
|
stream.write(buffer.data(), buffer.size());
|
||||||
stream.flush();
|
stream.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,11 +67,12 @@ inline void write_object(Stream& stream, const T& object) {
|
|||||||
available.
|
available.
|
||||||
*
|
*
|
||||||
* @param stream The stream to read from.
|
* @param stream The stream to read from.
|
||||||
|
* @throw msgpack::type_error If the conversion to an object was not successful.
|
||||||
*
|
*
|
||||||
* @relates write_object
|
* @relates write_object
|
||||||
*/
|
*/
|
||||||
template <typename Stream>
|
template <typename T, typename Stream>
|
||||||
inline EventResult read_object(Stream& stream) {
|
inline T read_object(Stream& stream) {
|
||||||
size_t message_length;
|
size_t message_length;
|
||||||
stream >> message_length;
|
stream >> message_length;
|
||||||
|
|
||||||
|
|||||||
+11
-11
@@ -15,7 +15,7 @@
|
|||||||
namespace bp = boost::process;
|
namespace bp = boost::process;
|
||||||
namespace fs = boost::filesystem;
|
namespace fs = boost::filesystem;
|
||||||
|
|
||||||
constexpr auto yabridge_wine_host_name = "yabridge-host.exeTODO";
|
constexpr auto yabridge_wine_host_name = "yabridge-host.exe";
|
||||||
|
|
||||||
fs::path find_wine_vst_host();
|
fs::path find_wine_vst_host();
|
||||||
|
|
||||||
@@ -38,15 +38,6 @@ intptr_t Bridge::dispatch(AEffect* /*plugin*/,
|
|||||||
intptr_t value,
|
intptr_t value,
|
||||||
void* result,
|
void* result,
|
||||||
float option) {
|
float option) {
|
||||||
Event event{opcode, parameter, value, option};
|
|
||||||
write_object(vst_stdin, event);
|
|
||||||
|
|
||||||
EventResult response = read_object(vst_stdout);
|
|
||||||
if (response.result) {
|
|
||||||
std::copy(response.result->begin(), response.result->end(),
|
|
||||||
static_cast<char*>(result));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Some events need some extra handling
|
// Some events need some extra handling
|
||||||
// TODO: Handle other things such as GUI itneraction
|
// TODO: Handle other things such as GUI itneraction
|
||||||
switch (opcode) {
|
switch (opcode) {
|
||||||
@@ -64,6 +55,15 @@ intptr_t Bridge::dispatch(AEffect* /*plugin*/,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Event event{opcode, parameter, value, option};
|
||||||
|
write_object(vst_stdin, event);
|
||||||
|
|
||||||
|
auto response = read_object<EventResult>(vst_stdout);
|
||||||
|
if (response.result) {
|
||||||
|
std::copy(response.result->begin(), response.result->end(),
|
||||||
|
static_cast<char*>(result));
|
||||||
|
}
|
||||||
|
|
||||||
return response.return_value;
|
return response.return_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ fs::path find_wine_vst_host() {
|
|||||||
// Bosot will return an empty path if the file could not be found in the
|
// Bosot will return an empty path if the file could not be found in the
|
||||||
// search path
|
// search path
|
||||||
fs::path vst_host_path = bp::search_path(yabridge_wine_host_name);
|
fs::path vst_host_path = bp::search_path(yabridge_wine_host_name);
|
||||||
if (fs::is_empty(vst_host_path)) {
|
if (vst_host_path == "") {
|
||||||
throw std::runtime_error("Could not locate '" +
|
throw std::runtime_error("Could not locate '" +
|
||||||
std::string(yabridge_wine_host_name) + "'");
|
std::string(yabridge_wine_host_name) + "'");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// Libraries like Boost and msgpack think we're compiling on Windows or using a
|
||||||
|
// MSVC toolchain. This will cause them to make assumptions about the way
|
||||||
|
// certain types are defined, which headers are available and which features to
|
||||||
|
// disable (i.e. POSIX specific features). The only way around this I could
|
||||||
|
// think of was to just temporarily undefine the macros these libraries use to
|
||||||
|
// detect it's running under a WIN32 environment. If anyone knows a better way
|
||||||
|
// to do this, please let me know!
|
||||||
|
|
||||||
|
#pragma push_macro("WIN32")
|
||||||
|
#pragma push_macro("_WIN32")
|
||||||
|
#pragma push_macro("__WIN32__")
|
||||||
|
#pragma push_macro("_WIN64")
|
||||||
|
|
||||||
|
#undef WIN32
|
||||||
|
#undef _WIN32
|
||||||
|
#undef __WIN32__
|
||||||
|
#undef _WIN64
|
||||||
|
|
||||||
|
#include <msgpack.hpp>
|
||||||
|
|
||||||
|
#pragma pop_macro("WIN32")
|
||||||
|
#pragma pop_macro("_WIN32")
|
||||||
|
#pragma pop_macro("__WIN32__")
|
||||||
|
#pragma pop_macro("_WIN64")
|
||||||
@@ -1,7 +1,28 @@
|
|||||||
// TODO: Do something useful here!
|
#include <vestige/aeffect.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "native-includes.h"
|
||||||
|
|
||||||
|
// `native-includes.h` has to be included before any other files as otherwise we
|
||||||
|
// might get the wrong version of certain libraries
|
||||||
|
#include "../common/communication.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
std::cout << "Hello, world!" << std::endl;
|
// TODO: The program should terminate automatically when stdin gets closed
|
||||||
|
|
||||||
|
// TODO: Remove debug
|
||||||
|
while (true) {
|
||||||
|
auto event = read_object<Event>(std::cin);
|
||||||
|
|
||||||
|
EventResult response;
|
||||||
|
if (event.opcode == effGetEffectName) {
|
||||||
|
response.return_value = 1;
|
||||||
|
response.result = "Hello, world!";
|
||||||
|
} else {
|
||||||
|
response.return_value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
write_object(std::cout, response);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user