mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-09 20:29:10 +02:00
Prevent allocations caused by Logger::log_trace
C++ would always construct an `std::string` from the string constant every iteration. Since this also happened when `YABRIDGE_DEBUG_LEVEL` is not set to 2, this ended up causing unnecessary allocations.
This commit is contained in:
@@ -60,6 +60,8 @@ Versioning](https://semver.org/spec/v2.0.0.html).
|
|||||||
visible.
|
visible.
|
||||||
- Fixed _Voxengo_ VST2 plugins in **Renoise** freezing when loading a project or
|
- Fixed _Voxengo_ VST2 plugins in **Renoise** freezing when loading a project or
|
||||||
when otherwise restoring plugin state.
|
when otherwise restoring plugin state.
|
||||||
|
- Fixed logging traces in the VST2 audio processing functions causing
|
||||||
|
allocations even when `YABRIDGE_DEBUG_LEVEL` is not set to 2.
|
||||||
- Fixed builds on Wine 6.8 because of internal changes to Wine's `windows.h`
|
- Fixed builds on Wine 6.8 because of internal changes to Wine's `windows.h`
|
||||||
implementation.
|
implementation.
|
||||||
|
|
||||||
|
|||||||
@@ -125,9 +125,3 @@ void Logger::log(const std::string& message) {
|
|||||||
|
|
||||||
*stream << formatted_message.str() << std::flush;
|
*stream << formatted_message.str() << std::flush;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::log_trace(const std::string& message) {
|
|
||||||
if (verbosity >= Verbosity::all_events) {
|
|
||||||
log(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+16
-10
@@ -28,6 +28,8 @@
|
|||||||
#include <boost/asio/streambuf.hpp>
|
#include <boost/asio/streambuf.hpp>
|
||||||
#include <boost/process/async_pipe.hpp>
|
#include <boost/process/async_pipe.hpp>
|
||||||
|
|
||||||
|
#include "../utils.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Boost 1.72 was released with a known breaking bug caused by a missing
|
* Boost 1.72 was released with a known breaking bug caused by a missing
|
||||||
* typedef: https://github.com/boostorg/process/issues/116.
|
* typedef: https://github.com/boostorg/process/issues/116.
|
||||||
@@ -132,16 +134,6 @@ class Logger {
|
|||||||
*/
|
*/
|
||||||
void log(const std::string& message);
|
void log(const std::string& message);
|
||||||
|
|
||||||
/**
|
|
||||||
* Log a message that should only be printed when the `verbosity` is set to
|
|
||||||
* `all_events`. This should only be used for simple primitive messages
|
|
||||||
* without any formatting since the actual check happens within this
|
|
||||||
* function.
|
|
||||||
*
|
|
||||||
* @param message The message to write.
|
|
||||||
*/
|
|
||||||
void log_trace(const std::string& message);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write output from an async pipe to the log on a line by line basis.
|
* Write output from an async pipe to the log on a line by line basis.
|
||||||
* Useful for logging the Wine process's STDOUT and STDERR streams.
|
* Useful for logging the Wine process's STDOUT and STDERR streams.
|
||||||
@@ -172,6 +164,20 @@ class Logger {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log a message that should only be printed when the `verbosity` is set to
|
||||||
|
* `all_events`. This uses a lambda since producing a string always
|
||||||
|
* allocates.
|
||||||
|
*
|
||||||
|
* @param message A lambda producing a string that should be written.
|
||||||
|
*/
|
||||||
|
template <invocable_returning<std::string> F>
|
||||||
|
void log_trace(F&& fn) {
|
||||||
|
if (verbosity >= Verbosity::all_events) {
|
||||||
|
log(fn());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The verbosity level of this logger instance. Based on this certain
|
* The verbosity level of this logger instance. Based on this certain
|
||||||
* messages may or may not be shown.
|
* messages may or may not be shown.
|
||||||
|
|||||||
@@ -46,13 +46,6 @@ class Vst2Logger {
|
|||||||
*/
|
*/
|
||||||
inline void log(const std::string& message) { logger.log(message); }
|
inline void log(const std::string& message) { logger.log(message); }
|
||||||
|
|
||||||
/**
|
|
||||||
* @see Logger::log_trace
|
|
||||||
*/
|
|
||||||
inline void log_trace(const std::string& message) {
|
|
||||||
logger.log_trace(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
// The following functions are for logging specific events, they are only
|
// The following functions are for logging specific events, they are only
|
||||||
// enabled for verbosity levels higher than 1 (i.e. `Verbosity::events`)
|
// enabled for verbosity levels higher than 1 (i.e. `Verbosity::events`)
|
||||||
void log_get_parameter(int index);
|
void log_get_parameter(int index);
|
||||||
@@ -77,6 +70,14 @@ class Vst2Logger {
|
|||||||
const std::optional<Vst2EventResult::Payload>& value_payload,
|
const std::optional<Vst2EventResult::Payload>& value_payload,
|
||||||
bool from_cache = false);
|
bool from_cache = false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Logger::log_trace
|
||||||
|
*/
|
||||||
|
template <invocable_returning<std::string> F>
|
||||||
|
inline void log_trace(F&& fn) {
|
||||||
|
logger.log_trace(std::forward<F>(fn));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The underlying logger instance we're wrapping.
|
* The underlying logger instance we're wrapping.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -35,13 +35,6 @@ class Vst3Logger {
|
|||||||
*/
|
*/
|
||||||
inline void log(const std::string& message) { logger.log(message); }
|
inline void log(const std::string& message) { logger.log(message); }
|
||||||
|
|
||||||
/**
|
|
||||||
* @see Logger::log_trace
|
|
||||||
*/
|
|
||||||
inline void log_trace(const std::string& message) {
|
|
||||||
logger.log_trace(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log calls to `FUnknown::queryInterface`. This will separately log about
|
* Log calls to `FUnknown::queryInterface`. This will separately log about
|
||||||
* successful queries, queries for interfaces the object did not implement,
|
* successful queries, queries for interfaces the object did not implement,
|
||||||
@@ -340,6 +333,14 @@ class Vst3Logger {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Logger::log_trace
|
||||||
|
*/
|
||||||
|
template <invocable_returning<std::string> F>
|
||||||
|
inline void log_trace(F&& fn) {
|
||||||
|
logger.log_trace(std::forward<F>(fn));
|
||||||
|
}
|
||||||
|
|
||||||
Logger& logger;
|
Logger& logger;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -663,27 +663,27 @@ void Vst2PluginBridge::process(AEffect* /*plugin*/,
|
|||||||
// Technically either `Vst2PluginBridge::process()` or
|
// Technically either `Vst2PluginBridge::process()` or
|
||||||
// `Vst2PluginBridge::process_replacing()` could actually call the other
|
// `Vst2PluginBridge::process_replacing()` could actually call the other
|
||||||
// function on the plugin depending on what the plugin supports.
|
// function on the plugin depending on what the plugin supports.
|
||||||
logger.log_trace(">> process() :: start");
|
logger.log_trace([]() { return ">> process() :: start"; });
|
||||||
do_process<float, false>(inputs, outputs, sample_frames);
|
do_process<float, false>(inputs, outputs, sample_frames);
|
||||||
logger.log_trace(" process() :: end");
|
logger.log_trace([]() { return " process() :: end"; });
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vst2PluginBridge::process_replacing(AEffect* /*plugin*/,
|
void Vst2PluginBridge::process_replacing(AEffect* /*plugin*/,
|
||||||
float** inputs,
|
float** inputs,
|
||||||
float** outputs,
|
float** outputs,
|
||||||
int sample_frames) {
|
int sample_frames) {
|
||||||
logger.log_trace(">> processReplacing() :: start");
|
logger.log_trace([]() { return ">> processReplacing() :: start"; });
|
||||||
do_process<float, true>(inputs, outputs, sample_frames);
|
do_process<float, true>(inputs, outputs, sample_frames);
|
||||||
logger.log_trace(" processReplacing() :: end");
|
logger.log_trace([]() { return " processReplacing() :: end"; });
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vst2PluginBridge::process_double_replacing(AEffect* /*plugin*/,
|
void Vst2PluginBridge::process_double_replacing(AEffect* /*plugin*/,
|
||||||
double** inputs,
|
double** inputs,
|
||||||
double** outputs,
|
double** outputs,
|
||||||
int sample_frames) {
|
int sample_frames) {
|
||||||
logger.log_trace(">> processDoubleReplacing() :: start");
|
logger.log_trace([]() { return ">> processDoubleReplacing() :: start"; });
|
||||||
do_process<double, true>(inputs, outputs, sample_frames);
|
do_process<double, true>(inputs, outputs, sample_frames);
|
||||||
logger.log_trace(" processDoubleReplacing() :: end");
|
logger.log_trace([]() { return " processDoubleReplacing() :: end"; });
|
||||||
}
|
}
|
||||||
|
|
||||||
float Vst2PluginBridge::get_parameter(AEffect* /*plugin*/, int index) {
|
float Vst2PluginBridge::get_parameter(AEffect* /*plugin*/, int index) {
|
||||||
|
|||||||
Reference in New Issue
Block a user