mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-10 04:30:12 +02:00
Get rid of the VST3 logging boilerplate
This commit is contained in:
+18
-43
@@ -16,79 +16,54 @@
|
|||||||
|
|
||||||
#include "vst3.h"
|
#include "vst3.h"
|
||||||
|
|
||||||
#include <sstream>
|
|
||||||
#include "src/common/serialization/vst3.h"
|
#include "src/common/serialization/vst3.h"
|
||||||
|
|
||||||
// TODO: Reconsider the output format
|
// TODO: Reconsider the output format
|
||||||
// TODO: Maybe think of an alterantive that's a little less boilerplaty
|
|
||||||
|
|
||||||
Vst3Logger::Vst3Logger(Logger& generic_logger) : logger(generic_logger) {}
|
Vst3Logger::Vst3Logger(Logger& generic_logger) : logger(generic_logger) {}
|
||||||
|
|
||||||
void Vst3Logger::log_request(bool is_host_vst, const YaComponent::Create&) {
|
void Vst3Logger::log_request(bool is_host_vst, const YaComponent::Create&) {
|
||||||
if (BOOST_UNLIKELY(logger.verbosity >= Logger::Verbosity::most_events)) {
|
log_request_base(is_host_vst, [](auto& message) {
|
||||||
std::ostringstream message;
|
|
||||||
// TODO: Log the cid in some readable way, if possible
|
// TODO: Log the cid in some readable way, if possible
|
||||||
message << get_log_prefix(is_host_vst)
|
message << "IPluginFactory::createComponent(cid, IComponent::iid, "
|
||||||
<< " >> IPluginFactory::createComponent(cid, IComponent::iid, "
|
|
||||||
"&obj)";
|
"&obj)";
|
||||||
|
});
|
||||||
log(message.str());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vst3Logger::log_request(bool is_host_vst, const WantsConfiguration&) {
|
void Vst3Logger::log_request(bool is_host_vst, const WantsConfiguration&) {
|
||||||
if (BOOST_UNLIKELY(logger.verbosity >= Logger::Verbosity::most_events)) {
|
log_request_base(is_host_vst, [](auto& message) {
|
||||||
std::ostringstream message;
|
message << "Requesting <Configuration>";
|
||||||
message << get_log_prefix(is_host_vst)
|
});
|
||||||
<< " >> Requesting <Configuration>";
|
|
||||||
|
|
||||||
log(message.str());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vst3Logger::log_request(bool is_host_vst, const WantsPluginFactory&) {
|
void Vst3Logger::log_request(bool is_host_vst, const WantsPluginFactory&) {
|
||||||
if (BOOST_UNLIKELY(logger.verbosity >= Logger::Verbosity::most_events)) {
|
log_request_base(is_host_vst, [](auto& message) {
|
||||||
std::ostringstream message;
|
message << "Requesting <IPluginFactory*>";
|
||||||
message << get_log_prefix(is_host_vst)
|
});
|
||||||
<< " >> Requesting <IPluginFactory*>";
|
|
||||||
|
|
||||||
log(message.str());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vst3Logger::log_response(
|
void Vst3Logger::log_response(
|
||||||
bool is_host_vst,
|
bool is_host_vst,
|
||||||
const std::optional<YaComponent::Arguments>& args) {
|
const std::optional<YaComponent::Arguments>& args) {
|
||||||
if (BOOST_UNLIKELY(logger.verbosity >= Logger::Verbosity::most_events)) {
|
log_response_base(is_host_vst, [&](auto& message) {
|
||||||
std::ostringstream message;
|
|
||||||
if (args) {
|
if (args) {
|
||||||
message << get_log_prefix(is_host_vst) << " <IComponent* #"
|
message << "<IComponent* #" << args->instance_id << ">";
|
||||||
<< args->instance_id << ">";
|
|
||||||
} else {
|
} else {
|
||||||
message << get_log_prefix(is_host_vst) << " <nullptr>";
|
message << "<nullptr>";
|
||||||
}
|
}
|
||||||
|
});
|
||||||
log(message.str());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vst3Logger::log_response(bool is_host_vst, const Configuration&) {
|
void Vst3Logger::log_response(bool is_host_vst, const Configuration&) {
|
||||||
if (BOOST_UNLIKELY(logger.verbosity >= Logger::Verbosity::most_events)) {
|
log_response_base(is_host_vst,
|
||||||
std::ostringstream message;
|
[](auto& message) { message << "<Configuration"; });
|
||||||
message << get_log_prefix(is_host_vst) << " <Configuration>";
|
|
||||||
|
|
||||||
log(message.str());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vst3Logger::log_response(bool is_host_vst,
|
void Vst3Logger::log_response(bool is_host_vst,
|
||||||
const YaPluginFactory& factory) {
|
const YaPluginFactory& factory) {
|
||||||
if (BOOST_UNLIKELY(logger.verbosity >= Logger::Verbosity::most_events)) {
|
log_response_base(is_host_vst, [&](auto& message) {
|
||||||
std::ostringstream message;
|
message << "<IPluginFactory*> with "
|
||||||
message << get_log_prefix(is_host_vst) << " <IPluginFactory*> with "
|
|
||||||
<< const_cast<YaPluginFactory&>(factory).countClasses()
|
<< const_cast<YaPluginFactory&>(factory).countClasses()
|
||||||
<< " registered classes";
|
<< " registered classes";
|
||||||
|
});
|
||||||
log(message.str());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include "../serialization/vst3.h"
|
#include "../serialization/vst3.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
@@ -58,11 +60,42 @@ class Vst3Logger {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* Get the `host -> vst` or `vst -> host` prefix based on the boolean flag
|
* Log a request with a standard prefix based on the boolean flag we pass to
|
||||||
* we pass to every logging function so we don't have to repeat it
|
* every logging function so we don't have to repeat it everywhere.
|
||||||
* everywhere.
|
|
||||||
*/
|
*/
|
||||||
inline std::string get_log_prefix(bool is_host_vst) {
|
template <std::invocable<std::ostringstream&> F>
|
||||||
return is_host_vst ? "[host -> vst]" : "[vst -> host]";
|
void log_request_base(bool is_host_vst, F callback) {
|
||||||
|
if (BOOST_UNLIKELY(logger.verbosity >=
|
||||||
|
Logger::Verbosity::most_events)) {
|
||||||
|
std::ostringstream message;
|
||||||
|
if (is_host_vst) {
|
||||||
|
message << "[host -> vst] >> ";
|
||||||
|
} else {
|
||||||
|
message << "[vst -> host] >> ";
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(message);
|
||||||
|
log(message.str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log a response with a standard prefix based on the boolean flag we pass
|
||||||
|
* to every logging function so we don't have to repeat it everywhere.
|
||||||
|
*/
|
||||||
|
template <std::invocable<std::ostringstream&> F>
|
||||||
|
void log_response_base(bool is_host_vst, F callback) {
|
||||||
|
if (BOOST_UNLIKELY(logger.verbosity >=
|
||||||
|
Logger::Verbosity::most_events)) {
|
||||||
|
std::ostringstream message;
|
||||||
|
if (is_host_vst) {
|
||||||
|
message << "[host -> vst] ";
|
||||||
|
} else {
|
||||||
|
message << "[vst -> host] ";
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(message);
|
||||||
|
log(message.str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user