From 9a4237ba8377d906c431ea8a7fb00d5a4420228a Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 13 Oct 2020 21:26:26 +0200 Subject: [PATCH] Add debug transmitter This is in preparation to conveniently duplicate debug messages to Window > Log. For cases where stdout/err is not easily accessible. --- libs/pbd/debug.cc | 6 ++++++ libs/pbd/error.cc | 6 +++--- libs/pbd/pbd/debug.h | 1 + libs/pbd/pbd/error.h | 3 ++- libs/pbd/pbd/transmitter.h | 2 ++ libs/pbd/textreceiver.cc | 8 +++++--- libs/pbd/transmitter.cc | 3 +++ 7 files changed, 22 insertions(+), 7 deletions(-) diff --git a/libs/pbd/debug.cc b/libs/pbd/debug.cc index 1104af4dea..e9aa1e5d26 100644 --- a/libs/pbd/debug.cc +++ b/libs/pbd/debug.cc @@ -30,6 +30,7 @@ #include #include "pbd/debug.h" +#include "pbd/error.h" #include "pbd/i18n.h" @@ -62,6 +63,7 @@ DebugBits PBD::DEBUG::Threads = PBD::new_debug_bit ("threads"); DebugBits PBD::DEBUG::Locale = PBD::new_debug_bit ("locale"); DebugBits PBD::DEBUG::StringConvert = PBD::new_debug_bit ("stringconvert"); DebugBits PBD::DEBUG::DebugTimestamps = PBD::new_debug_bit ("debugtimestamps"); +DebugBits PBD::DEBUG::DebugLogToGUI = PBD::new_debug_bit ("debuglogtogui"); /* These are debug bits that are used by backends. Since these are loaded dynamically, after command-line parsing, defining them in code that is part of the backend @@ -105,6 +107,10 @@ PBD::debug_print (const char* prefix, string str) } else { printf ("%s: %s", prefix, str.c_str()); } + if ((PBD::debug_bits & DEBUG::DebugLogToGUI).any()) { + std::replace (str.begin (), str.end (), '\n', ' '); + debug << prefix << ": " << str << endmsg; + } } int diff --git a/libs/pbd/error.cc b/libs/pbd/error.cc index 229c34edf9..b27ebe7fd3 100644 --- a/libs/pbd/error.cc +++ b/libs/pbd/error.cc @@ -18,8 +18,8 @@ #include "pbd/error.h" -Transmitter PBD::error (Transmitter::Error); +Transmitter PBD::debug (Transmitter::Debug); Transmitter PBD::info (Transmitter::Info); -Transmitter PBD::fatal (Transmitter::Fatal); Transmitter PBD::warning (Transmitter::Warning); - +Transmitter PBD::error (Transmitter::Error); +Transmitter PBD::fatal (Transmitter::Fatal); diff --git a/libs/pbd/pbd/debug.h b/libs/pbd/pbd/debug.h index d82e646582..9417eefef8 100644 --- a/libs/pbd/pbd/debug.h +++ b/libs/pbd/pbd/debug.h @@ -63,6 +63,7 @@ namespace PBD { LIBPBD_API extern DebugBits Locale; LIBPBD_API extern DebugBits StringConvert; LIBPBD_API extern DebugBits DebugTimestamps; + LIBPBD_API extern DebugBits DebugLogToGUI; /* See notes in ../debug.cc on why these are defined here */ diff --git a/libs/pbd/pbd/error.h b/libs/pbd/pbd/error.h index e6faf17bd9..ba4b301baf 100644 --- a/libs/pbd/pbd/error.h +++ b/libs/pbd/pbd/error.h @@ -22,9 +22,10 @@ #include "transmitter.h" namespace PBD { - LIBPBD_API extern Transmitter error; + LIBPBD_API extern Transmitter debug; LIBPBD_API extern Transmitter info; LIBPBD_API extern Transmitter warning; + LIBPBD_API extern Transmitter error; LIBPBD_API extern Transmitter fatal; } diff --git a/libs/pbd/pbd/transmitter.h b/libs/pbd/pbd/transmitter.h index 8198d48ec4..7d189914ce 100644 --- a/libs/pbd/pbd/transmitter.h +++ b/libs/pbd/pbd/transmitter.h @@ -31,6 +31,7 @@ class LIBPBD_API Transmitter : public std::stringstream { public: enum Channel { + Debug, Info, Error, Warning, @@ -54,6 +55,7 @@ class LIBPBD_API Transmitter : public std::stringstream Channel channel; PBD::Signal2 *send; + PBD::Signal2 debug; PBD::Signal2 info; PBD::Signal2 warning; PBD::Signal2 error; diff --git a/libs/pbd/textreceiver.cc b/libs/pbd/textreceiver.cc index 30b692e26f..a6d3ee05d1 100644 --- a/libs/pbd/textreceiver.cc +++ b/libs/pbd/textreceiver.cc @@ -36,15 +36,17 @@ TextReceiver::receive (Transmitter::Channel chn, const char *str) const char *prefix = ""; switch (chn) { - case Transmitter::Error: - prefix = ": [ERROR]: "; - break; + case Transmitter::Debug: + return; case Transmitter::Info: prefix = ": [INFO]: "; break; case Transmitter::Warning: prefix = ": [WARNING]: "; break; + case Transmitter::Error: + prefix = ": [ERROR]: "; + break; case Transmitter::Fatal: prefix = ": [FATAL]: "; break; diff --git a/libs/pbd/transmitter.cc b/libs/pbd/transmitter.cc index 719e30a122..38ad1c2198 100644 --- a/libs/pbd/transmitter.cc +++ b/libs/pbd/transmitter.cc @@ -40,6 +40,9 @@ Transmitter::Transmitter (Channel c) case Info: send = &info; break; + case Debug: + send = &debug; + break; case Fatal: send = &fatal; break;