changeset 1504:150d4e561b07

Only set maximum frequency on FFT model when in a special verticallyFixed mode
author Chris Cannam
date Thu, 12 Sep 2019 13:50:24 +0100
parents 2c7a480f93ca
children 1819978526f9
files layer/SpectrogramLayer.cpp layer/SpectrogramLayer.h
diffstat 2 files changed, 47 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/layer/SpectrogramLayer.cpp	Thu Sep 12 11:53:40 2019 +0100
+++ b/layer/SpectrogramLayer.cpp	Thu Sep 12 13:50:24 2019 +0100
@@ -70,6 +70,7 @@
     m_minFrequency(10),
     m_maxFrequency(8000),
     m_initialMaxFrequency(8000),
+    m_verticallyFixed(false),
     m_colourScale(ColourScaleType::Log),
     m_colourScaleMultiple(1.0),
     m_colourMap(0),
@@ -134,6 +135,14 @@
 }
 
 void
+SpectrogramLayer::setVerticallyFixed()
+{
+    if (m_verticallyFixed) return;
+    m_verticallyFixed = true;
+    recreateFFTModel();
+}
+
+void
 SpectrogramLayer::deleteDerivedModels()
 {
     ModelById::release(m_fftModel);
@@ -845,6 +854,10 @@
 {
     if (m_minFrequency == mf) return;
 
+    if (m_verticallyFixed) {
+        throw std::logic_error("setMinFrequency called with value differing from the default, on SpectrogramLayer with verticallyFixed true");
+    }
+
 //    SVDEBUG << "SpectrogramLayer::setMinFrequency: " << mf << endl;
 
     invalidateRenderers();
@@ -866,16 +879,16 @@
 {
     if (m_maxFrequency == mf) return;
 
+    if (m_verticallyFixed) {
+        throw std::logic_error("setMaxFrequency called with value differing from the default, on SpectrogramLayer with verticallyFixed true");
+    }
+    
 //    SVDEBUG << "SpectrogramLayer::setMaxFrequency: " << mf << endl;
 
     invalidateRenderers();
     invalidateMagnitudes();
     
     m_maxFrequency = mf;
-
-    if (auto fftModel = ModelById::getAs<FFTModel>(m_fftModel)) {
-        fftModel->setMaximumFrequency(m_maxFrequency);
-    }
     
     emit layerParametersChanged();
 }
@@ -1424,7 +1437,9 @@
         return;
     }
 
-    newFFTModel->setMaximumFrequency(getMaxFrequency());
+    if (m_verticallyFixed) {
+        newFFTModel->setMaximumFrequency(getMaxFrequency());
+    }
     
     m_fftModel = ModelById::add(newFFTModel);
 
@@ -1797,12 +1812,13 @@
     invalidateRenderers();
     invalidateMagnitudes();
 
+    if (m_verticallyFixed &&
+        (m_minFrequency != minf || m_maxFrequency != maxf)) {
+        throw std::logic_error("setDisplayExtents called with values differing from the defaults, on SpectrogramLayer with verticallyFixed true");
+    }
+
     m_minFrequency = minf;
     m_maxFrequency = maxf;
-
-    if (auto fftModel = ModelById::getAs<FFTModel>(m_fftModel)) {
-        fftModel->setMaximumFrequency(m_maxFrequency);
-    }
     
     emit layerParametersChanged();
 
--- a/layer/SpectrogramLayer.h	Thu Sep 12 11:53:40 2019 +0100
+++ b/layer/SpectrogramLayer.h	Thu Sep 12 13:50:24 2019 +0100
@@ -55,10 +55,14 @@
 
 public:
     enum Configuration { FullRangeDb, MelodicRange, MelodicPeaks };
-    
+
+    /**
+     * Construct a SpectrogramLayer with default parameters
+     * appropriate for the given configuration.
+     */
     SpectrogramLayer(Configuration = FullRangeDb);
     ~SpectrogramLayer();
-
+    
     const ZoomConstraint *getZoomConstraint() const override { return this; }
     ModelId getModel() const override { return m_model; }
     void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const override;
@@ -89,7 +93,7 @@
     PropertyType getPropertyType(const PropertyName &) const override;
     QString getPropertyGroupName(const PropertyName &) const override;
     int getPropertyRangeAndValue(const PropertyName &,
-                                         int *min, int *max, int *deflt) const override;
+                                 int *min, int *max, int *deflt) const override;
     QString getPropertyValueLabel(const PropertyName &,
                                           int value) const override;
     QString getPropertyValueIconName(const PropertyName &,
@@ -133,6 +137,20 @@
     void setThreshold(float threshold);
     float getThreshold() const;
 
+    /**
+     * Mark the spectrogram layer as having a fixed range in the
+     * vertical axis. This indicates that the visible frequency range
+     * is determined entirely by the configuration requested on
+     * construction, and that setMinFrequency, setMaxFrequency, and
+     * setDisplayExtents will never be called. This may allow some
+     * cache-size-related optimisations. It should be called
+     * immediately after construction, if at all.
+     *
+     * Note that this cannot be reversed on a given object (this call
+     * takes no argument and there is no inverse call).
+     */
+    void setVerticallyFixed();
+
     void setMinFrequency(int);
     int getMinFrequency() const;
 
@@ -259,6 +277,7 @@
     int                 m_minFrequency;
     int                 m_maxFrequency;
     int                 m_initialMaxFrequency;
+    bool                m_verticallyFixed;
     ColourScaleType     m_colourScale;
     double              m_colourScaleMultiple;
     int                 m_colourMap;