changeset 1203:932487fe515a 3.0-integration

Introduce labels in RangeMapper and use them in AudioDial, though only for tooltip at present. Make use of this for spectrogram magic -81dB/-Inf threshold. Also introduce static strings for inf/pi and use where appropriate.
author Chris Cannam
date Fri, 05 Aug 2016 17:48:52 +0100
parents 3b84f9bd0048
children 35387a99c236
files base/RangeMapper.cpp base/RangeMapper.h base/Strings.cpp base/Strings.h svcore.pro
diffstat 5 files changed, 89 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/base/RangeMapper.cpp	Fri Aug 05 15:05:02 2016 +0100
+++ b/base/RangeMapper.cpp	Fri Aug 05 17:48:52 2016 +0100
@@ -23,13 +23,15 @@
 
 LinearRangeMapper::LinearRangeMapper(int minpos, int maxpos,
 				     double minval, double maxval,
-                                     QString unit, bool inverted) :
+                                     QString unit, bool inverted,
+                                     std::map<int, QString> labels) :
     m_minpos(minpos),
     m_maxpos(maxpos),
     m_minval(minval),
     m_maxval(maxval),
     m_unit(unit),
-    m_inverted(inverted)
+    m_inverted(inverted),
+    m_labels(labels)
 {
     assert(m_maxval != m_minval);
     assert(m_maxpos != m_minpos);
@@ -74,6 +76,16 @@
     return value;
 }
 
+QString
+LinearRangeMapper::getLabel(int position) const
+{
+    if (m_labels.find(position) != m_labels.end()) {
+        return m_labels.at(position);
+    } else {
+        return "";
+    }
+}
+
 LogRangeMapper::LogRangeMapper(int minpos, int maxpos,
                                double minval, double maxval,
                                QString unit, bool inverted) :
--- a/base/RangeMapper.h	Fri Aug 05 15:05:02 2016 +0100
+++ b/base/RangeMapper.h	Fri Aug 05 17:48:52 2016 +0100
@@ -50,7 +50,7 @@
     virtual double getValueForPosition(int position) const = 0;
 
     /**
-     * Return the value mapped from the given positionq, without
+     * Return the value mapped from the given position, without
      * clamping. That is, whatever mapping function is in use will be
      * projected even outside the minimum and maximum extents of the
      * mapper's value range. (The mapping outside that range is not
@@ -62,6 +62,16 @@
      * Get the unit of the mapper's value range.
      */
     virtual QString getUnit() const { return ""; }
+
+    /**
+     * The mapper may optionally provide special labels for one or
+     * more individual positions (such as the minimum position, the
+     * default, or indeed all positions). These should be used in any
+     * display context in preference to just showing the numerical
+     * value for the position. If a position has such a label, return
+     * it here.
+     */
+    virtual QString getLabel(int position) const { return ""; }
 };
 
 
@@ -76,7 +86,8 @@
      */
     LinearRangeMapper(int minpos, int maxpos,
                       double minval, double maxval,
-                      QString unit = "", bool inverted = false);
+                      QString unit = "", bool inverted = false,
+                      std::map<int, QString> labels = {});
     
     virtual int getPositionForValue(double value) const;
     virtual int getPositionForValueUnclamped(double value) const;
@@ -85,6 +96,7 @@
     virtual double getValueForPositionUnclamped(int position) const;
 
     virtual QString getUnit() const { return m_unit; }
+    virtual QString getLabel(int position) const;
 
 protected:
     int m_minpos;
@@ -93,6 +105,7 @@
     double m_maxval;
     QString m_unit;
     bool m_inverted;
+    std::map<int, QString> m_labels;
 };
 
 class LogRangeMapper : public RangeMapper
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/base/Strings.cpp	Fri Aug 05 17:48:52 2016 +0100
@@ -0,0 +1,28 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    Sonic Visualiser
+    An audio file viewer and annotation editor.
+    Centre for Digital Music, Queen Mary, University of London.
+    
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.  See the file
+    COPYING included with this distribution for more information.
+*/
+
+#include "Strings.h"
+
+QString
+Strings::pi = QChar(0x3c0);
+
+QString
+Strings::minus_pi = "-" + pi;
+
+QString
+Strings::infinity = QChar(0x221e);
+
+QString
+Strings::minus_infinity = "-" + infinity;
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/base/Strings.h	Fri Aug 05 17:48:52 2016 +0100
@@ -0,0 +1,30 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    Sonic Visualiser
+    An audio file viewer and annotation editor.
+    Centre for Digital Music, Queen Mary, University of London.
+    
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.  See the file
+    COPYING included with this distribution for more information.
+*/
+
+#ifndef SV_STRINGS_H
+#define SV_STRINGS_H
+
+#include <QString>
+
+class Strings
+{
+public:
+    static QString pi;
+    static QString minus_pi;
+
+    static QString infinity;
+    static QString minus_infinity;
+};
+
+#endif
--- a/svcore.pro	Fri Aug 05 15:05:02 2016 +0100
+++ b/svcore.pro	Fri Aug 05 17:48:52 2016 +0100
@@ -82,6 +82,7 @@
            base/Serialiser.h \
            base/StorageAdviser.h \
            base/StringBits.h \
+           base/Strings.h \
            base/TempDirectory.h \
            base/TempWriteFile.h \
            base/TextMatcher.h \
@@ -114,6 +115,7 @@
            base/Serialiser.cpp \
            base/StorageAdviser.cpp \
            base/StringBits.cpp \
+           base/Strings.cpp \
            base/TempDirectory.cpp \
            base/TempWriteFile.cpp \
            base/TextMatcher.cpp \