From a6cbb48222bfb6d374b11ebd0d308af2d3cf0284 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Thu, 26 Mar 2020 23:15:50 +0100 Subject: [PATCH] Add the ability to set a log filename (non abi breaking change) --- src/sfizz.h | 8 ++++++++ src/sfizz.hpp | 14 ++++++++++++++ src/sfizz/Logger.cpp | 8 ++++---- src/sfizz/Logger.h | 4 ++-- src/sfizz/Synth.cpp | 10 +++++++--- src/sfizz/Synth.h | 8 +++++++- src/sfizz/sfizz.cpp | 10 ++++++++++ src/sfizz/sfizz_wrapper.cpp | 6 ++++++ 8 files changed, 58 insertions(+), 10 deletions(-) diff --git a/src/sfizz.h b/src/sfizz.h index fbe5520f..5e5c6af8 100644 --- a/src/sfizz.h +++ b/src/sfizz.h @@ -379,6 +379,14 @@ SFIZZ_EXPORTED_API void sfizz_enable_logging(sfizz_synth_t* synth); */ SFIZZ_EXPORTED_API void sfizz_disable_logging(sfizz_synth_t* synth); +/** + * @brief Enable logging of timings to sidecar CSV files. This can produce + * many outputs so use with caution. + * + * @param synth + */ +SFIZZ_EXPORTED_API void sfizz_set_logging_prefix(sfizz_synth_t* synth, const char* prefix); + /** * @brief Shuts down the current processing, clear buffers and reset the voices. * diff --git a/src/sfizz.hpp b/src/sfizz.hpp index 8cb87ab1..d0e62e37 100644 --- a/src/sfizz.hpp +++ b/src/sfizz.hpp @@ -258,8 +258,22 @@ public: * @brief Enable logging of timings to sidecar CSV files. This can produce * many outputs so use with caution. * + * @param prefix the file prefix to use for logging */ void enableLogging() noexcept; + /** + * @brief Enable logging of timings to sidecar CSV files. This can produce + * many outputs so use with caution. + * + * @param prefix the file prefix to use for logging + */ + void enableLogging(const std::string& prefix) noexcept; + /** + * @brief Set the logging prefix + * + * @param prefix + */ + void setLoggingPrefix(const std::string& prefix) noexcept; /** * @brief Disable logging; * diff --git a/src/sfizz/Logger.cpp b/src/sfizz/Logger.cpp index fa1defd7..d69671c1 100644 --- a/src/sfizz/Logger.cpp +++ b/src/sfizz/Logger.cpp @@ -112,15 +112,14 @@ void sfz::Logger::logFileTime(std::chrono::duration waitDuration, std::c fileTimeQueue.try_push({ waitDuration, loadDuration, fileSize, filename }); } -void sfz::Logger::setPrefix(const std::string& prefix) +void sfz::Logger::setPrefix(absl::string_view prefix) { - this->prefix = prefix; + this->prefix = std::string(prefix); } void sfz::Logger::clear() { clearFlag.clear(); - prefix.clear(); } void sfz::Logger::moveEvents() noexcept @@ -143,8 +142,9 @@ void sfz::Logger::moveEvents() noexcept } } -void sfz::Logger::enableLogging() +void sfz::Logger::enableLogging(absl::string_view prefix) { + setPrefix(prefix); loggingEnabled = true; } diff --git a/src/sfizz/Logger.h b/src/sfizz/Logger.h index 04bea8fc..de7e8beb 100644 --- a/src/sfizz/Logger.h +++ b/src/sfizz/Logger.h @@ -99,7 +99,7 @@ public: * * @param prefix */ - void setPrefix(const std::string& prefix); + void setPrefix(absl::string_view prefix); /** * @brief Removes all logged data @@ -111,7 +111,7 @@ public: * @brief Enables logging and writing to log files on destruction * */ - void enableLogging(); + void enableLogging(absl::string_view prefix); /** * @brief Disables logging and writing to log files on destruction diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index 56c5126c..997a3869 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -291,7 +291,6 @@ bool sfz::Synth::loadSfzFile(const fs::path& file) return false; resources.filePool.setRootDirectory(this->originalDirectory); - resources.logger.setPrefix(file.filename().string()); auto currentRegion = regions.begin(); auto lastRegion = regions.rbegin(); @@ -953,9 +952,14 @@ bool sfz::Synth::shouldReloadFile() return (checkModificationTime() > modificationTime); } -void sfz::Synth::enableLogging() noexcept +void sfz::Synth::enableLogging(absl::string_view prefix) noexcept { - resources.logger.enableLogging(); + resources.logger.enableLogging(prefix); +} + +void sfz::Synth::setLoggingPrefix(absl::string_view prefix) noexcept +{ + resources.logger.setPrefix(prefix); } void sfz::Synth::disableLogging() noexcept diff --git a/src/sfizz/Synth.h b/src/sfizz/Synth.h index 2fb1eb16..fb755574 100644 --- a/src/sfizz/Synth.h +++ b/src/sfizz/Synth.h @@ -355,7 +355,13 @@ public: * many outputs so use with caution. * */ - void enableLogging() noexcept; + void enableLogging(absl::string_view prefix = "") noexcept; + /** + * @brief Enable logging of timings to sidecar CSV files. This can produce + * many outputs so use with caution. + * + */ + void setLoggingPrefix(absl::string_view prefix) noexcept; /** * @brief Disable logging; * diff --git a/src/sfizz/sfizz.cpp b/src/sfizz/sfizz.cpp index ee4ef4f1..08f88c1a 100644 --- a/src/sfizz/sfizz.cpp +++ b/src/sfizz/sfizz.cpp @@ -191,6 +191,16 @@ void sfz::Sfizz::enableLogging() noexcept synth->enableLogging(); } +void sfz::Sfizz::enableLogging(const std::string& prefix) noexcept +{ + synth->enableLogging(prefix); +} + +void sfz::Sfizz::setLoggingPrefix(const std::string& prefix) noexcept +{ + synth->setLoggingPrefix(prefix); +} + void sfz::Sfizz::disableLogging() noexcept { synth->disableLogging(); diff --git a/src/sfizz/sfizz_wrapper.cpp b/src/sfizz/sfizz_wrapper.cpp index 7e18d2f6..bc62c4c7 100644 --- a/src/sfizz/sfizz_wrapper.cpp +++ b/src/sfizz/sfizz_wrapper.cpp @@ -238,6 +238,12 @@ void sfizz_enable_logging(sfizz_synth_t* synth) return self->enableLogging(); } +void sfizz_set_logging_prefix(sfizz_synth_t* synth, const char* prefix) +{ + auto self = reinterpret_cast(synth); + return self->setLoggingPrefix(prefix); +} + void sfizz_disable_logging(sfizz_synth_t* synth) { auto self = reinterpret_cast(synth);