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
+10 -5
View File
@@ -6,20 +6,25 @@ intptr_t send_event(boost::asio::local::stream_protocol::socket& socket,
intptr_t value,
void* data,
float option,
Logger& logger,
bool is_dispatch) {
std::optional<std::pair<Logger&, bool>> logging) {
auto payload =
data == nullptr
? std::nullopt
: std::make_optional(std::string(static_cast<char*>(data)));
logger.log_event(is_dispatch, opcode, index, value, payload, option);
if (logging.has_value()) {
auto [logger, is_dispatch] = *logging;
logger.log_event(is_dispatch, opcode, index, value, payload, option);
}
const Event event{opcode, index, value, option, payload};
write_object(socket, event);
const auto response = read_object<EventResult>(socket);
logger.log_event_response(is_dispatch, response.return_value,
response.data);
if (logging.has_value()) {
auto [logger, is_dispatch] = *logging;
logger.log_event_response(is_dispatch, response.return_value,
response.data);
}
if (response.data.has_value()) {
char* char_data = static_cast<char*>(data);
+21 -17
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
* the parameters and return value of this function.
*
* @param logger The logger to optionally log the event to.
* @param id_dispatch Whether this is for sending `dispatch()` events or host
* callbacks, used for debug logging purposes.
* @param logging A pair containing a logger instance and whether or not this is
* for sending `dispatch()` events or host callbacks. Optional since it
* doesn't have to be done on both sides.
*
* @relates passthrough_event
*/
@@ -317,9 +317,7 @@ intptr_t send_event(boost::asio::local::stream_protocol::socket& socket,
intptr_t value,
void* data,
float option,
Logger& logger,
bool is_dispatch);
std::optional<std::pair<Logger&, bool>> logging);
/**
* 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 ->
@@ -331,9 +329,9 @@ intptr_t send_event(boost::asio::local::stream_protocol::socket& socket,
* function.
* @param callback The function to call with the arguments received from the
* socket.
* @param logger The logger to optionally log the event to.
* @param id_dispatch Whether this is for sending `dispatch()` events or host
* callbacks, used for debug logging purposes.
* @param logging A pair containing a logger instance and whether or not this is
* for sending `dispatch()` events or host callbacks. Optional since it
* doesn't have to be done on both sides.
*
* @relates send_event
*/
@@ -341,11 +339,13 @@ template <typename F>
void passthrough_event(boost::asio::local::stream_protocol::socket& socket,
AEffect* plugin,
F callback,
Logger& logger,
bool is_dispatch) {
std::optional<std::pair<Logger&, bool>> logging) {
auto event = read_object<Event>(socket);
logger.log_event(is_dispatch, event.opcode, event.index, event.value,
event.data, event.option);
if (logging.has_value()) {
auto [logger, is_dispatch] = *logging;
logger.log_event(is_dispatch, event.opcode, event.index, event.value,
event.data, event.option);
}
// The void pointer argument for the dispatch function is used for
// either:
@@ -355,9 +355,9 @@ void passthrough_event(boost::asio::local::stream_protocol::socket& socket,
char* payload = nullptr;
std::array<char, max_string_length> buffer;
if (event.data.has_value()) {
// If the data parameter was an empty string, then we're going to pass a
// larger buffer to the dispatch function instead. Otherwise we'll pass
// the data passed by the host.
// If the data parameter was an empty string, then we're going to
// pass a larger buffer to the dispatch function instead. Otherwise
// we'll pass the data passed by the host.
if (!event.data->empty()) {
payload = const_cast<char*>(event.data->c_str());
} else {
@@ -374,7 +374,11 @@ void passthrough_event(boost::asio::local::stream_protocol::socket& socket,
const auto response_data =
is_updated ? std::make_optional(payload) : std::nullopt;
if (logging.has_value()) {
auto [logger, is_dispatch] = *logging;
logger.log_event_response(is_dispatch, return_value, response_data);
}
EventResult response{return_value, response_data};
logger.log_event_response(is_dispatch, return_value, response_data);
write_object(socket, response);
}
+3 -2
View File
@@ -120,7 +120,8 @@ HostBridge::HostBridge(audioMasterCallback host_callback)
host_callback_handler = std::thread([&]() {
while (true) {
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(); });
@@ -167,7 +168,7 @@ intptr_t HostBridge::dispatch(AEffect* /*plugin*/,
}
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*/,
+10 -46
View File
@@ -31,8 +31,6 @@ using VstEntryPoint = AEffect*(VST_CALL_CONV*)(audioMasterCallback);
*/
PluginBridge* current_bridge_isntance = nullptr;
std::string create_logger_prefix(const fs::path& socket_path);
intptr_t VST_CALL_CONV
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_process_replacing(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>()) {
// Got to love these C APIs
if (plugin_handle == nullptr) {
std::string error =
"Could not load a shared library at '" + plugin_dll_path + "'.";
logger.log("ERROR: " + error);
throw std::runtime_error(error);
throw std::runtime_error("Could not load a shared library at '" +
plugin_dll_path + "'.");
}
// 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) {
std::string error = "Could not find a valid VST entry point for '" +
plugin_dll_path + "'.";
logger.log("ERROR: " + error);
throw std::runtime_error(error);
throw std::runtime_error(
"Could not find a valid VST entry point for '" + plugin_dll_path +
"'.");
}
// 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;
plugin = vst_entry_point(host_callback_proxy);
if (plugin == nullptr) {
std::string error =
"VST plugin at '" + plugin_dll_path + "' failed to initialize.";
logger.log("ERROR: " + error);
throw std::runtime_error(error);
throw std::runtime_error("VST plugin at '" + plugin_dll_path +
"' failed to initialize.");
}
// 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([&]() {
while (true) {
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);
if (request.value.has_value()) {
// `setParameter`
logger.log_set_parameter(request.index, request.value.value());
plugin->setParameter(plugin, request.index,
request.value.value());
ParameterResult response{std::nullopt};
logger.log_set_parameter_response(request.index);
write_object(host_vst_parameters, response);
} else {
// `getParameter`
logger.log_get_parameter(request.index);
float value = plugin->getParameter(plugin, request.index);
ParameterResult response{value};
logger.log_get_parameter_response(request.index, value);
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() {
@@ -214,25 +196,7 @@ intptr_t PluginBridge::host_callback(AEffect* /*plugin*/,
void* data,
float option) {
return send_event(vst_host_callback, opcode, index, value, data, option,
logger, false);
}
/**
* 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();
std::nullopt);
}
intptr_t VST_CALL_CONV host_callback_proxy(AEffect* effect,
-2
View File
@@ -111,8 +111,6 @@ class PluginBridge {
*/
std::thread process_replacing_handler;
Logger logger;
/**
* A scratch buffer for sending and receiving data during `process` and
* `processReplacing` calls.