c6652c91b5fe — Chris Cannam 11 months ago
Make this a default implementation of Logger rather than a special case in Log
M rubberband/RubberBandStretcher.h +2 -2
@@ 383,8 383,8 @@ public:
      * Note that although the supplied logger gets to decide what to
      * do with log messages, the separately-set debug level (see
      * setDebugLevel() and setDefaultDebugLevel()) still determines
-     * whether any given debug message is generated and sent to the
-     * logger in the first place.
+     * whether any given debug message is sent to the logger in the
+     * first place.
      */
     RubberBandStretcher(size_t sampleRate,
                         size_t channels,

          
M src/RubberBandStretcher.cpp +24 -1
@@ 24,6 24,8 @@ 
 #include "faster/R2Stretcher.h"
 #include "finer/R3Stretcher.h"
 
+#include <iostream>
+
 namespace RubberBand {
 
 class RubberBandStretcher::Impl

          
@@ 31,6 33,26 @@ class RubberBandStretcher::Impl
     R2Stretcher *m_r2;
     R3Stretcher *m_r3;
 
+    class CerrLogger : public RubberBandStretcher::Logger {
+    public:
+        void log(const char *message) override {
+            std::cerr << "RubberBand: " << message << "\n";
+        }
+        void log(const char *message, double arg0) override {
+            auto prec = std::cerr.precision();
+            std::cerr.precision(10);
+            std::cerr << "RubberBand: " << message << ": " << arg0 << "\n";
+            std::cerr.precision(prec);
+        }
+        void log(const char *message, double arg0, double arg1) override {
+            auto prec = std::cerr.precision();
+            std::cerr.precision(10);
+            std::cerr << "RubberBand: " << message
+                      << ": (" << arg0 << ", " << arg1 << ")" << "\n";
+            std::cerr.precision(prec);
+        }
+    };
+
     Log makeRBLog(std::shared_ptr<RubberBandStretcher::Logger> logger) {
         if (logger) {
             return Log(

          
@@ 45,7 67,8 @@ class RubberBandStretcher::Impl
                 }
                 );
         } else {
-            return Log::makeCoutLog();
+            return makeRBLog(std::shared_ptr<RubberBandStretcher::Logger>
+                             (new CerrLogger()));
         }
     }
 

          
M src/common/Log.cpp +0 -23
@@ 28,27 28,4 @@ namespace RubberBand
 
 int Log::m_defaultDebugLevel = 0;
 
-Log
-Log::makeCoutLog()
-{
-    return Log(
-        [](const char *message) {
-            std::cout << "RubberBand: " << message << "\n";
-        },
-        [](const char *message, double arg0) {
-            auto prec = std::cout.precision();
-            std::cout.precision(10);
-            std::cout << "RubberBand: " << message << ": " << arg0 << "\n";
-            std::cout.precision(prec);
-        },
-        [](const char *message, double arg0, double arg1) {
-            auto prec = std::cout.precision();
-            std::cout.precision(10);
-            std::cout << "RubberBand: " << message
-                      << ": (" << arg0 << ", " << arg1 << ")" << "\n";
-            std::cout.precision(prec);
-        }
-        );
 }
-
-}

          
M src/common/Log.h +4 -15
@@ 39,19 39,10 @@ public:
         m_log2(_log2),
         m_debugLevel(m_defaultDebugLevel) { }
 
-    Log(const Log &other) :
-        m_log0(other.m_log0),
-        m_log1(other.m_log1),
-        m_log2(other.m_log2),
-        m_debugLevel(other.m_debugLevel) { }
-
-    Log &operator=(const Log &other) {
-        m_log0 = other.m_log0;
-        m_log1 = other.m_log1;
-        m_log2 = other.m_log2;
-        m_debugLevel = other.m_debugLevel;
-        return *this;
-    }
+    Log(const Log &other) =default;
+    Log(Log &&other) =default;
+    Log &operator=(const Log &other) =default;
+    Log &operator=(Log &&other) =default;
 
     void setDebugLevel(int level) { m_debugLevel = level; }
     int getDebugLevel() const { return m_debugLevel; }

          
@@ 68,8 59,6 @@ public:
         if (level <= m_debugLevel) m_log2(message, arg0, arg1);
     }
 
-    static Log makeCoutLog();
-    
 private:
     std::function<void(const char *)> m_log0;
     std::function<void(const char *, double)> m_log1;

          
M vamp/RubberBandVampPlugin.cpp +23 -2
@@ 454,6 454,28 @@ RubberBandVampPlugin::Impl::processOffli
     return FeatureSet();
 }
 
+static RubberBand::Log makeCerrLog()
+{
+    auto log0 = [](const char *message) {
+        std::cerr << "RubberBand: " << message << "\n";
+    };
+    auto log1 = [](const char *message, double arg0) {
+        auto prec = std::cerr.precision();
+        std::cerr.precision(10);
+        std::cerr << "RubberBand: " << message << ": " << arg0 << "\n";
+        std::cerr.precision(prec);
+    };
+    auto log2 = [](const char *message, double arg0, double arg1) {
+        auto prec = std::cerr.precision();
+        std::cerr.precision(10);
+        std::cerr << "RubberBand: " << message
+                  << ": (" << arg0 << ", " << arg1 << ")" << "\n";
+        std::cerr.precision(prec);
+    };
+
+    return RubberBand::Log(log0, log1, log2);
+}
+
 RubberBandVampPlugin::FeatureSet
 RubberBandVampPlugin::Impl::getRemainingFeaturesOffline()
 {

          
@@ 464,8 486,7 @@ RubberBandVampPlugin::Impl::getRemaining
     int rate = m_sampleRate;
 
     RubberBand::StretchCalculator sc
-        (rate, m_stretcher->getInputIncrement(), true,
-         RubberBand::Log::makeCoutLog());
+        (rate, m_stretcher->getInputIncrement(), true, makeCerrLog());
 
     size_t inputIncrement = m_stretcher->getInputIncrement();
     std::vector<int> outputIncrements = m_stretcher->getOutputIncrements();