Disable logging on the Wine side

It was incredibly verbose, and for debugging the networking part you
could still use stdout.
This commit is contained in:
Robbert van der Helm
2020-03-07 23:36:30 +01:00
parent 35b0174b9e
commit 3bfb6cf38b
5 changed files with 44 additions and 72 deletions
+7 -2
View File
@@ -6,20 +6,25 @@ intptr_t send_event(boost::asio::local::stream_protocol::socket& socket,
intptr_t value, intptr_t value,
void* data, void* data,
float option, float option,
Logger& logger, std::optional<std::pair<Logger&, bool>> logging) {
bool is_dispatch) {
auto payload = auto payload =
data == nullptr data == nullptr
? std::nullopt ? std::nullopt
: std::make_optional(std::string(static_cast<char*>(data))); : std::make_optional(std::string(static_cast<char*>(data)));
if (logging.has_value()) {
auto [logger, is_dispatch] = *logging;
logger.log_event(is_dispatch, opcode, index, value, payload, option); logger.log_event(is_dispatch, opcode, index, value, payload, option);
}
const Event event{opcode, index, value, option, payload}; const Event event{opcode, index, value, option, payload};
write_object(socket, event); write_object(socket, event);
const auto response = read_object<EventResult>(socket); const auto response = read_object<EventResult>(socket);
if (logging.has_value()) {
auto [logger, is_dispatch] = *logging;
logger.log_event_response(is_dispatch, response.return_value, logger.log_event_response(is_dispatch, response.return_value,
response.data); response.data);
}
if (response.data.has_value()) { if (response.data.has_value()) {
char* char_data = static_cast<char*>(data); char* char_data = static_cast<char*>(data);
+19 -15
View File
@@ -305,9 +305,9 @@ inline T read_object(Socket& socket) {
* since they follow the same format. See one of those functions for details on * since they follow the same format. See one of those functions for details on
* the parameters and return value of this function. * the parameters and return value of this function.
* *
* @param logger The logger to optionally log the event to. * @param logging A pair containing a logger instance and whether or not this is
* @param id_dispatch Whether this is for sending `dispatch()` events or host * for sending `dispatch()` events or host callbacks. Optional since it
* callbacks, used for debug logging purposes. * doesn't have to be done on both sides.
* *
* @relates passthrough_event * @relates passthrough_event
*/ */
@@ -317,9 +317,7 @@ intptr_t send_event(boost::asio::local::stream_protocol::socket& socket,
intptr_t value, intptr_t value,
void* data, void* data,
float option, float option,
Logger& logger, std::optional<std::pair<Logger&, bool>> logging);
bool is_dispatch);
/** /**
* Receive an event from a socket and pass it through to some callback function. * Receive an event from a socket and pass it through to some callback function.
* This is used for both the host -> plugin 'dispatch' events and the plugin -> * This is used for both the host -> plugin 'dispatch' events and the plugin ->
@@ -331,9 +329,9 @@ intptr_t send_event(boost::asio::local::stream_protocol::socket& socket,
* function. * function.
* @param callback The function to call with the arguments received from the * @param callback The function to call with the arguments received from the
* socket. * socket.
* @param logger The logger to optionally log the event to. * @param logging A pair containing a logger instance and whether or not this is
* @param id_dispatch Whether this is for sending `dispatch()` events or host * for sending `dispatch()` events or host callbacks. Optional since it
* callbacks, used for debug logging purposes. * doesn't have to be done on both sides.
* *
* @relates send_event * @relates send_event
*/ */
@@ -341,11 +339,13 @@ template <typename F>
void passthrough_event(boost::asio::local::stream_protocol::socket& socket, void passthrough_event(boost::asio::local::stream_protocol::socket& socket,
AEffect* plugin, AEffect* plugin,
F callback, F callback,
Logger& logger, std::optional<std::pair<Logger&, bool>> logging) {
bool is_dispatch) {
auto event = read_object<Event>(socket); auto event = read_object<Event>(socket);
if (logging.has_value()) {
auto [logger, is_dispatch] = *logging;
logger.log_event(is_dispatch, event.opcode, event.index, event.value, logger.log_event(is_dispatch, event.opcode, event.index, event.value,
event.data, event.option); event.data, event.option);
}
// The void pointer argument for the dispatch function is used for // The void pointer argument for the dispatch function is used for
// either: // either:
@@ -355,9 +355,9 @@ void passthrough_event(boost::asio::local::stream_protocol::socket& socket,
char* payload = nullptr; char* payload = nullptr;
std::array<char, max_string_length> buffer; std::array<char, max_string_length> buffer;
if (event.data.has_value()) { if (event.data.has_value()) {
// If the data parameter was an empty string, then we're going to pass a // If the data parameter was an empty string, then we're going to
// larger buffer to the dispatch function instead. Otherwise we'll pass // pass a larger buffer to the dispatch function instead. Otherwise
// the data passed by the host. // we'll pass the data passed by the host.
if (!event.data->empty()) { if (!event.data->empty()) {
payload = const_cast<char*>(event.data->c_str()); payload = const_cast<char*>(event.data->c_str());
} else { } else {
@@ -374,7 +374,11 @@ void passthrough_event(boost::asio::local::stream_protocol::socket& socket,
const auto response_data = const auto response_data =
is_updated ? std::make_optional(payload) : std::nullopt; is_updated ? std::make_optional(payload) : std::nullopt;
EventResult response{return_value, response_data}; if (logging.has_value()) {
auto [logger, is_dispatch] = *logging;
logger.log_event_response(is_dispatch, return_value, response_data); logger.log_event_response(is_dispatch, return_value, response_data);
}
EventResult response{return_value, response_data};
write_object(socket, response); write_object(socket, response);
} }
+3 -2
View File
@@ -120,7 +120,8 @@ HostBridge::HostBridge(audioMasterCallback host_callback)
host_callback_handler = std::thread([&]() { host_callback_handler = std::thread([&]() {
while (true) { while (true) {
passthrough_event(vst_host_callback, &plugin, passthrough_event(vst_host_callback, &plugin,
host_callback_function, logger, false); host_callback_function,
std::pair<Logger&, bool>(logger, false));
} }
}); });
wine_io_handler = std::thread([&]() { io_context.run(); }); wine_io_handler = std::thread([&]() { io_context.run(); });
@@ -167,7 +168,7 @@ intptr_t HostBridge::dispatch(AEffect* /*plugin*/,
} }
return send_event(host_vst_dispatch, opcode, index, value, data, option, return send_event(host_vst_dispatch, opcode, index, value, data, option,
logger, true); std::pair<Logger&, bool>(logger, true));
} }
void HostBridge::process_replacing(AEffect* /*plugin*/, void HostBridge::process_replacing(AEffect* /*plugin*/,
+10 -46
View File
@@ -31,8 +31,6 @@ using VstEntryPoint = AEffect*(VST_CALL_CONV*)(audioMasterCallback);
*/ */
PluginBridge* current_bridge_isntance = nullptr; PluginBridge* current_bridge_isntance = nullptr;
std::string create_logger_prefix(const fs::path& socket_path);
intptr_t VST_CALL_CONV intptr_t VST_CALL_CONV
host_callback_proxy(AEffect*, int32_t, int32_t, intptr_t, void*, float); host_callback_proxy(AEffect*, int32_t, int32_t, intptr_t, void*, float);
@@ -64,16 +62,11 @@ PluginBridge::PluginBridge(std::string plugin_dll_path,
host_vst_parameters(io_context), host_vst_parameters(io_context),
host_vst_process_replacing(io_context), host_vst_process_replacing(io_context),
vst_host_aeffect(io_context), vst_host_aeffect(io_context),
logger(Logger::create_from_environment(
create_logger_prefix(socket_endpoint_path))),
process_buffer(std::make_unique<AudioBuffers::buffer_type>()) { process_buffer(std::make_unique<AudioBuffers::buffer_type>()) {
// Got to love these C APIs // Got to love these C APIs
if (plugin_handle == nullptr) { if (plugin_handle == nullptr) {
std::string error = throw std::runtime_error("Could not load a shared library at '" +
"Could not load a shared library at '" + plugin_dll_path + "'."; plugin_dll_path + "'.");
logger.log("ERROR: " + error);
throw std::runtime_error(error);
} }
// VST plugin entry point functions should be called `VSTPluginMain`, but // VST plugin entry point functions should be called `VSTPluginMain`, but
@@ -89,11 +82,9 @@ PluginBridge::PluginBridge(std::string plugin_dll_path,
} }
} }
if (vst_entry_point == nullptr) { if (vst_entry_point == nullptr) {
std::string error = "Could not find a valid VST entry point for '" + throw std::runtime_error(
plugin_dll_path + "'."; "Could not find a valid VST entry point for '" + plugin_dll_path +
"'.");
logger.log("ERROR: " + error);
throw std::runtime_error(error);
} }
// It's very important that these sockets are accepted to in the same order // It's very important that these sockets are accepted to in the same order
@@ -111,11 +102,8 @@ PluginBridge::PluginBridge(std::string plugin_dll_path,
current_bridge_isntance = this; current_bridge_isntance = this;
plugin = vst_entry_point(host_callback_proxy); plugin = vst_entry_point(host_callback_proxy);
if (plugin == nullptr) { if (plugin == nullptr) {
std::string error = throw std::runtime_error("VST plugin at '" + plugin_dll_path +
"VST plugin at '" + plugin_dll_path + "' failed to initialize."; "' failed to initialize.");
logger.log("ERROR: " + error);
throw std::runtime_error(error);
} }
// Send the plugin's information to the Linux VST plugin // Send the plugin's information to the Linux VST plugin
@@ -134,7 +122,7 @@ PluginBridge::PluginBridge(std::string plugin_dll_path,
dispatch_handler = std::thread([&]() { dispatch_handler = std::thread([&]() {
while (true) { while (true) {
passthrough_event(host_vst_dispatch, plugin, plugin->dispatcher, passthrough_event(host_vst_dispatch, plugin, plugin->dispatcher,
logger, true); std::nullopt);
} }
}); });
@@ -147,22 +135,16 @@ PluginBridge::PluginBridge(std::string plugin_dll_path,
auto request = read_object<Parameter>(host_vst_parameters); auto request = read_object<Parameter>(host_vst_parameters);
if (request.value.has_value()) { if (request.value.has_value()) {
// `setParameter` // `setParameter`
logger.log_set_parameter(request.index, request.value.value());
plugin->setParameter(plugin, request.index, plugin->setParameter(plugin, request.index,
request.value.value()); request.value.value());
ParameterResult response{std::nullopt}; ParameterResult response{std::nullopt};
logger.log_set_parameter_response(request.index);
write_object(host_vst_parameters, response); write_object(host_vst_parameters, response);
} else { } else {
// `getParameter` // `getParameter`
logger.log_get_parameter(request.index);
float value = plugin->getParameter(plugin, request.index); float value = plugin->getParameter(plugin, request.index);
ParameterResult response{value}; ParameterResult response{value};
logger.log_get_parameter_response(request.index, value);
write_object(host_vst_parameters, response); write_object(host_vst_parameters, response);
} }
} }
@@ -198,7 +180,7 @@ PluginBridge::PluginBridge(std::string plugin_dll_path,
} }
}); });
logger.log("Finished initializing '" + plugin_dll_path + "'"); std::cout << "Finished initializing '" << plugin_dll_path << "'";
} }
void PluginBridge::wait() { void PluginBridge::wait() {
@@ -214,25 +196,7 @@ intptr_t PluginBridge::host_callback(AEffect* /*plugin*/,
void* data, void* data,
float option) { float option) {
return send_event(vst_host_callback, opcode, index, value, data, option, return send_event(vst_host_callback, opcode, index, value, data, option,
logger, false); std::nullopt);
}
/**
* Create a logger prefix based on the unique socket path for easy
* identification. The socket path contains both the plugin's name and a unique
* identifier.
*
* @param socket_path The path to the socket endpoint in use.
*
* @return A prefix string for log messages.
*/
std::string create_logger_prefix(const fs::path& socket_path) {
std::ostringstream prefix;
prefix << "[" << socket_path.filename().replace_extension().string()
<< "] ";
prefix << "[Wine] ";
return prefix.str();
} }
intptr_t VST_CALL_CONV host_callback_proxy(AEffect* effect, intptr_t VST_CALL_CONV host_callback_proxy(AEffect* effect,
-2
View File
@@ -111,8 +111,6 @@ class PluginBridge {
*/ */
std::thread process_replacing_handler; std::thread process_replacing_handler;
Logger logger;
/** /**
* A scratch buffer for sending and receiving data during `process` and * A scratch buffer for sending and receiving data during `process` and
* `processReplacing` calls. * `processReplacing` calls.