mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-09 20:29:10 +02:00
Add log messages everywhere
This commit is contained in:
@@ -5,16 +5,21 @@ intptr_t send_event(boost::asio::local::stream_protocol::socket& socket,
|
|||||||
int32_t index,
|
int32_t index,
|
||||||
intptr_t value,
|
intptr_t value,
|
||||||
void* data,
|
void* data,
|
||||||
float option) {
|
float option,
|
||||||
|
Logger& logger,
|
||||||
|
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)));
|
||||||
|
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);
|
||||||
|
logger.log_event_response(is_dispatch, response.return_value,
|
||||||
|
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);
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,8 @@
|
|||||||
#endif
|
#endif
|
||||||
#include <boost/asio/local/stream_protocol.hpp>
|
#include <boost/asio/local/stream_protocol.hpp>
|
||||||
|
|
||||||
|
#include "logging.h"
|
||||||
|
|
||||||
// These are for the serialization done by bitsery
|
// These are for the serialization done by bitsery
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -303,6 +305,10 @@ 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 id_dispatch Whether this is for sending `dispatch()` events or host
|
||||||
|
* callbacks, used for debug logging purposes.
|
||||||
|
*
|
||||||
* @relates passthrough_event
|
* @relates passthrough_event
|
||||||
*/
|
*/
|
||||||
intptr_t send_event(boost::asio::local::stream_protocol::socket& socket,
|
intptr_t send_event(boost::asio::local::stream_protocol::socket& socket,
|
||||||
@@ -310,7 +316,9 @@ intptr_t send_event(boost::asio::local::stream_protocol::socket& socket,
|
|||||||
int32_t index,
|
int32_t index,
|
||||||
intptr_t value,
|
intptr_t value,
|
||||||
void* data,
|
void* data,
|
||||||
float option);
|
float option,
|
||||||
|
Logger& logger,
|
||||||
|
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.
|
||||||
@@ -323,14 +331,21 @@ 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 id_dispatch Whether this is for sending `dispatch()` events or host
|
||||||
|
* callbacks, used for debug logging purposes.
|
||||||
*
|
*
|
||||||
* @relates send_event
|
* @relates send_event
|
||||||
*/
|
*/
|
||||||
template <typename F>
|
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,
|
||||||
|
bool is_dispatch) {
|
||||||
auto event = read_object<Event>(socket);
|
auto event = read_object<Event>(socket);
|
||||||
|
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
|
// The void pointer argument for the dispatch function is used for
|
||||||
// either:
|
// either:
|
||||||
@@ -356,12 +371,10 @@ void passthrough_event(boost::asio::local::stream_protocol::socket& socket,
|
|||||||
// Only write back the value from `payload` if we were passed an empty
|
// Only write back the value from `payload` if we were passed an empty
|
||||||
// buffer to write into
|
// buffer to write into
|
||||||
bool is_updated = event.data.has_value() && event.data->empty();
|
bool is_updated = event.data.has_value() && event.data->empty();
|
||||||
|
const auto response_data =
|
||||||
|
is_updated ? std::make_optional(payload) : std::nullopt;
|
||||||
|
|
||||||
if (is_updated) {
|
EventResult response{return_value, response_data};
|
||||||
EventResult response{return_value, payload};
|
logger.log_event_response(is_dispatch, return_value, response_data);
|
||||||
write_object(socket, response);
|
write_object(socket, response);
|
||||||
} else {
|
|
||||||
EventResult response{return_value, std::nullopt};
|
|
||||||
write_object(socket, response);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ 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);
|
host_callback_function, logger, false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
wine_io_handler = std::thread([&]() { io_context.run(); });
|
wine_io_handler = std::thread([&]() { io_context.run(); });
|
||||||
@@ -166,7 +166,8 @@ intptr_t HostBridge::dispatch(AEffect* /*plugin*/,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return send_event(host_vst_dispatch, opcode, index, value, data, option);
|
return send_event(host_vst_dispatch, opcode, index, value, data, option,
|
||||||
|
logger, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HostBridge::process_replacing(AEffect* /*plugin*/,
|
void HostBridge::process_replacing(AEffect* /*plugin*/,
|
||||||
@@ -199,21 +200,29 @@ void HostBridge::process_replacing(AEffect* /*plugin*/,
|
|||||||
}
|
}
|
||||||
|
|
||||||
float HostBridge::get_parameter(AEffect* /*plugin*/, int32_t index) {
|
float HostBridge::get_parameter(AEffect* /*plugin*/, int32_t index) {
|
||||||
|
logger.log_get_parameter(index);
|
||||||
|
|
||||||
const Parameter request{index, std::nullopt};
|
const Parameter request{index, std::nullopt};
|
||||||
write_object(host_vst_parameters, request);
|
write_object(host_vst_parameters, request);
|
||||||
|
|
||||||
const auto response = read_object<ParameterResult>(host_vst_parameters);
|
const auto response = read_object<ParameterResult>(host_vst_parameters);
|
||||||
|
logger.log_get_parameter_response(index, response.value.value());
|
||||||
|
|
||||||
return response.value.value();
|
return response.value.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HostBridge::set_parameter(AEffect* /*plugin*/,
|
void HostBridge::set_parameter(AEffect* /*plugin*/,
|
||||||
int32_t index,
|
int32_t index,
|
||||||
float value) {
|
float value) {
|
||||||
|
logger.log_set_parameter(index, value);
|
||||||
|
|
||||||
const Parameter request{index, value};
|
const Parameter request{index, value};
|
||||||
write_object(host_vst_parameters, request);
|
write_object(host_vst_parameters, request);
|
||||||
|
|
||||||
// This should not contain any values and just serve as an acknowledgement
|
// This should not contain any values and just serve as an acknowledgement
|
||||||
const auto response = read_object<ParameterResult>(host_vst_parameters);
|
const auto response = read_object<ParameterResult>(host_vst_parameters);
|
||||||
|
logger.log_set_parameter_response(index);
|
||||||
|
|
||||||
assert(!response.value.has_value());
|
assert(!response.value.has_value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -133,7 +133,8 @@ PluginBridge::PluginBridge(std::string plugin_dll_path,
|
|||||||
// lockstep anyway
|
// lockstep anyway
|
||||||
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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -146,16 +147,22 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -206,7 +213,8 @@ intptr_t PluginBridge::host_callback(AEffect* /*plugin*/,
|
|||||||
intptr_t value,
|
intptr_t value,
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user