mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-07 03:50:11 +02:00
Add basic communication with a child process
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
#include "bridge.h"
|
||||
|
||||
#include <boost/dll/runtime_symbol_info.hpp>
|
||||
#include <boost/process/io.hpp>
|
||||
#include <boost/process/search_path.hpp>
|
||||
#include <iostream>
|
||||
#include <msgpack.hpp>
|
||||
|
||||
@@ -9,6 +12,22 @@
|
||||
// implementation details, such as the use of intptr_t isntead of void*
|
||||
// here.
|
||||
|
||||
namespace bp = boost::process;
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
constexpr auto yabridge_wine_host_name = "yabridge-host.exeTODO";
|
||||
|
||||
fs::path find_wine_vst_host();
|
||||
|
||||
Bridge::Bridge()
|
||||
: vst_stdin(),
|
||||
vst_stdout(),
|
||||
vst_host(find_wine_vst_host(),
|
||||
bp::std_in = vst_stdin,
|
||||
bp::std_out = vst_stdout) {
|
||||
// TODO: Wineprefix detection
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an event sent by the VST host. Most of these opcodes will be passed
|
||||
* through to the winelib VST host.
|
||||
@@ -36,6 +55,8 @@ intptr_t Bridge::dispatch(AEffect* /*plugin*/,
|
||||
switch (opcode) {
|
||||
case effClose:
|
||||
// TODO: Gracefully close the editor?
|
||||
// XXX: Boost.Process will send SIGKILL to the process for us, is
|
||||
// there a way to manually send a SIGTERM signal instead?
|
||||
|
||||
// The VST API does not have an explicit function for releasing
|
||||
// resources, so we'll have to do it here. The actual plugin
|
||||
@@ -67,3 +88,34 @@ float Bridge::get_parameter(AEffect* /*plugin*/, int32_t /*index*/
|
||||
// TODO: Unimplmemented
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the Wine VST hsot (named `yabridge-host.exe`). For this we will search
|
||||
* in two places:
|
||||
*
|
||||
* 1. Alongside libyabridge.so if the file got symlinked. This is useful
|
||||
* when developing, as you can simply symlink the the libyabridge.so
|
||||
* file in the build directory without having to install anything to
|
||||
* /usr.
|
||||
* 2. In the regular search path.
|
||||
*
|
||||
* @return The a path to the VST host, if found.
|
||||
* @throw std::runtime_error If the Wine VST host could not be found.
|
||||
*/
|
||||
fs::path find_wine_vst_host() {
|
||||
fs::path host_path = fs::canonical(boost::dll::this_line_location());
|
||||
host_path.remove_filename().append(yabridge_wine_host_name);
|
||||
if (fs::exists(host_path)) {
|
||||
return host_path;
|
||||
}
|
||||
|
||||
// Bosot will return an empty path if the file could not be found in the
|
||||
// search path
|
||||
fs::path vst_host_path = bp::search_path(yabridge_wine_host_name);
|
||||
if (fs::is_empty(vst_host_path)) {
|
||||
throw std::runtime_error("Could not locate '" +
|
||||
std::string(yabridge_wine_host_name) + "'");
|
||||
}
|
||||
|
||||
return vst_host_path;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user