changeset 772:986f1670a502 tonioni

Merge from default branch
author Chris Cannam
date Wed, 14 May 2014 09:58:16 +0100
parents 6388ddae6ce3 (current diff) a964151832a7 (diff)
children 6da4897a11d3
files
diffstat 8 files changed, 157 insertions(+), 78 deletions(-) [+]
line wrap: on
line diff
--- a/layer/Colour3DPlotLayer.cpp	Fri Apr 11 16:34:12 2014 +0100
+++ b/layer/Colour3DPlotLayer.cpp	Wed May 14 09:58:16 2014 +0100
@@ -579,6 +579,13 @@
     return true;
 }
 
+bool
+Colour3DPlotLayer::getYScaleValue(const View *v, int y,
+                                  float &value, QString &unit) const
+{
+    return false;//!!!
+}
+
 int
 Colour3DPlotLayer::getVerticalZoomSteps(int &defaultStep) const
 {
@@ -952,6 +959,7 @@
     size_t cacheHeight = m_model->getHeight();
 
     if (m_cache && (m_cache->height() != int(cacheHeight))) {
+        // height has changed: delete everything rather than resizing
         delete m_cache;
         delete m_peaksCache;
         m_cache = 0;
@@ -959,6 +967,7 @@
     } 
 
     if (m_cache && (m_cache->width() != int(cacheWidth))) {
+        // width has changed and we have an existing cache: resize it
         QImage *newCache =
             new QImage(m_cache->copy(0, 0, cacheWidth, cacheHeight));
         delete m_cache;
@@ -966,7 +975,7 @@
         if (m_peaksCache) {
             QImage *newPeaksCache =
                 new QImage(m_peaksCache->copy
-                           (0, 0, cacheWidth / m_peakResolution, cacheHeight));
+                           (0, 0, cacheWidth / m_peakResolution + 1, cacheHeight));
             delete m_peaksCache;
             m_peaksCache = newPeaksCache;
         }
@@ -991,6 +1000,9 @@
         m_cacheValidEnd = 0;
     }
 
+//    cerr << "cache size = " << m_cache->width() << "x" << m_cache->height()
+//         << " peaks cache size = " << m_peaksCache->width() << "x" << m_peaksCache->height() << endl;
+
     if (m_cacheValidStart <= firstBin && m_cacheValidEnd >= lastBin) {
 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
         cerr << "Cache is valid in this region already" << endl;
@@ -1117,6 +1129,12 @@
 	
         values = getColumn(c);
 
+        if (c >= m_cache->width()) {
+            cerr << "ERROR: column " << c << " >= cache width "
+                 << m_cache->width() << endl;
+            continue;
+        }
+
         for (size_t y = 0; y < cacheHeight; ++y) {
 
             float value = min;
@@ -1145,7 +1163,11 @@
             if (m_invertVertical) {
                 m_cache->setPixel(c, cacheHeight - y - 1, pixel);
             } else {
-                m_cache->setPixel(c, y, pixel);
+                if (y >= m_cache->height()) {
+                    cerr << "ERROR: row " << y << " >= cache height " << m_cache->height() << endl;
+                } else {
+                    m_cache->setPixel(c, y, pixel);
+                }
             }
         }
 
@@ -1153,11 +1175,23 @@
             size_t notch = (c % m_peakResolution);
             if (notch == m_peakResolution-1 || c == fillEnd) {
                 size_t pc = c / m_peakResolution;
+                if (pc >= m_peaksCache->width()) {
+                    cerr << "ERROR: peak column " << pc
+                         << " (from col " << c << ") >= peaks cache width "
+                         << m_peaksCache->width() << endl;
+                    continue;
+                }
                 for (size_t y = 0; y < cacheHeight; ++y) {
                     if (m_invertVertical) {
                         m_peaksCache->setPixel(pc, cacheHeight - y - 1, peaks[y]);
                     } else {
-                        m_peaksCache->setPixel(pc, y, peaks[y]);
+                        if (y >= m_peaksCache->height()) {
+                            cerr << "ERROR: row " << y
+                                 << " >= peaks cache height "
+                                 << m_peaksCache->height() << endl;
+                        } else {
+                            m_peaksCache->setPixel(pc, y, peaks[y]);
+                        }
                     }
                 }
                 for (int y = 0; y < cacheHeight; ++y) {
--- a/layer/Colour3DPlotLayer.h	Fri Apr 11 16:34:12 2014 +0100
+++ b/layer/Colour3DPlotLayer.h	Wed May 14 09:58:16 2014 +0100
@@ -151,6 +151,9 @@
     virtual bool getDisplayExtents(float &min, float &max) const;
     virtual bool setDisplayExtents(float min, float max);
 
+    virtual bool getYScaleValue(const View *, int /* y */,
+                                float &/* value */, QString &/* unit */) const;
+
     virtual int getVerticalZoomSteps(int &defaultStep) const;
     virtual int getCurrentVerticalZoomStep() const;
     virtual void setVerticalZoomStep(int);
@@ -188,17 +191,32 @@
     bool        m_smooth;
     size_t      m_peakResolution;
 
+    // Minimum and maximum bin numbers visible within the view. We
+    // always snap to whole bins at view edges.
     int         m_miny;
     int         m_maxy;
+
+    /**
+     * Return the y coordinate at which the given bin "starts"
+     * (i.e. at the bottom of the bin, if the given bin is an integer
+     * and the vertical scale is the usual way up). Bin number may be
+     * fractional, to obtain a position part-way through a bin.
+     */
+    float getYForBin(View *, float bin) const;
+
+    /**
+     * Return the bin number, possibly fractional, at the given y
+     * coordinate. Note that the whole numbers occur at the positions
+     * at which the bins "start" (i.e. the bottom of the visible bin,
+     * if the vertical scale is the usual way up).
+     */
+    float getBinForY(View *, float y) const;
     
     DenseThreeDimensionalModel::Column getColumn(size_t col) const;
 
     int getColourScaleWidth(QPainter &) const;
     void fillCache(size_t firstBin, size_t lastBin) const;
     void paintDense(View *v, QPainter &paint, QRect rect) const;
-
-    float getYForBin(View *, float bin) const;
-    float getBinForY(View *, float y) const;
 };
 
 #endif
--- a/layer/SingleColourLayer.cpp	Fri Apr 11 16:34:12 2014 +0100
+++ b/layer/SingleColourLayer.cpp	Wed May 14 09:58:16 2014 +0100
@@ -32,9 +32,17 @@
     m_colourExplicitlySet(false),
     m_defaultColourSet(false)
 {
+    // Reference current colour because setDefaulColourFor
+    // will unreference it before (possibly) changing it.
+    refColor();
     setDefaultColourFor(0);
 }
 
+SingleColourLayer::~SingleColourLayer()
+{
+    unrefColor();
+}
+
 QPixmap
 SingleColourLayer::getLayerPresentationPixmap(QSize size) const
 {
@@ -152,10 +160,6 @@
     int hint = -1;
     bool impose = false;
     if (v) {
-        if (m_colourRefCount.find(m_colour) != m_colourRefCount.end() &&
-            m_colourRefCount[m_colour] > 0) {
-            m_colourRefCount[m_colour]--;
-        }
         // We don't want to call this if !v because that probably
         // means we're being called from the constructor, and this is
         // a virtual function
@@ -174,6 +178,8 @@
         return;
     }
 
+    unrefColor();
+
     int bestCount = 0, bestColour = -1;
     
     for (int i = 0; i < cdb->getColourCount(); ++i) {
@@ -203,15 +209,11 @@
         cerr << endl;
 #endif
     }
-    
+
     if (bestColour < 0) m_colour = 0;
     else m_colour = bestColour;
 
-    if (m_colourRefCount.find(m_colour) == m_colourRefCount.end()) {
-        m_colourRefCount[m_colour] = 1;
-    } else {
-        m_colourRefCount[m_colour]++;
-    }
+    refColor();
 }
 
 void
@@ -221,18 +223,9 @@
 
     if (m_colour == colour) return;
 
-    if (m_colourRefCount.find(m_colour) != m_colourRefCount.end() &&
-        m_colourRefCount[m_colour] > 0) {
-        m_colourRefCount[m_colour]--;
-    }
-
+    refColor();
     m_colour = colour;
-
-    if (m_colourRefCount.find(m_colour) == m_colourRefCount.end()) {
-        m_colourRefCount[m_colour] = 1;
-    } else {
-        m_colourRefCount[m_colour]++;
-    }
+    unrefColor();
 
     flagBaseColourChanged();
     emit layerParametersChanged();
@@ -307,6 +300,9 @@
     int colour = ColourDatabase::getInstance()->putStringValues
         (colourName, colourSpec, darkbg);
 
+    if (colour == -1)
+      return;
+
     m_colourExplicitlySet = true;
 
     if (m_colour != colour) {
@@ -315,20 +311,27 @@
         SVDEBUG << "SingleColourLayer::setProperties: changing colour from " << m_colour << " to " << colour << endl;
 #endif
 
-        if (m_colourRefCount.find(m_colour) != m_colourRefCount.end() &&
-            m_colourRefCount[m_colour] > 0) {
-            m_colourRefCount[m_colour]--;
-        }
-
+        unrefColor();
         m_colour = colour;
-
-        if (m_colourRefCount.find(m_colour) == m_colourRefCount.end()) {
-            m_colourRefCount[m_colour] = 1;
-        } else {
-            m_colourRefCount[m_colour]++;
-        }
+        refColor();
 
         flagBaseColourChanged();
     }
 }
 
+void SingleColourLayer::refColor()
+{
+    if (m_colourRefCount.find(m_colour) == m_colourRefCount.end()) {
+        m_colourRefCount[m_colour] = 1;
+    } else {
+        m_colourRefCount[m_colour]++;
+    }
+}
+
+void SingleColourLayer::unrefColor()
+{
+    if (m_colourRefCount.find(m_colour) != m_colourRefCount.end() &&
+        m_colourRefCount[m_colour] > 0) {
+        m_colourRefCount[m_colour]--;
+    }
+}
--- a/layer/SingleColourLayer.h	Fri Apr 11 16:34:12 2014 +0100
+++ b/layer/SingleColourLayer.h	Wed May 14 09:58:16 2014 +0100
@@ -75,6 +75,7 @@
 
 protected:
     SingleColourLayer();
+    virtual ~SingleColourLayer();
 
     virtual QColor getBaseQColor() const;
     virtual QColor getBackgroundQColor(View *v) const;
@@ -91,6 +92,10 @@
     int m_colour;
     bool m_colourExplicitlySet;
     bool m_defaultColourSet;
+
+private:
+    void refColor();
+    void unrefColor();
 };
 
 #endif
--- a/layer/SpectrogramLayer.cpp	Fri Apr 11 16:34:12 2014 +0100
+++ b/layer/SpectrogramLayer.cpp	Wed May 14 09:58:16 2014 +0100
@@ -3459,6 +3459,11 @@
 
         return n;
     }
+    
+    virtual int getPositionForValueUnclamped(float value) const {
+        // We don't really support this
+        return getPositionForValue(value);
+    }
 
     virtual float getValueForPosition(int position) const {
 
@@ -3478,6 +3483,11 @@
         return dist;
     }
     
+    virtual float getValueForPositionUnclamped(int position) const {
+        // We don't really support this
+        return getValueForPosition(position);
+    }
+
     virtual QString getUnit() const { return "Hz"; }
 
 protected:
--- a/widgets/CSVFormatDialog.cpp	Fri Apr 11 16:34:12 2014 +0100
+++ b/widgets/CSVFormatDialog.cpp	Wed May 14 09:58:16 2014 +0100
@@ -94,6 +94,7 @@
         cpc->addItem(tr("End time")); // ColumnEndTime
         cpc->addItem(tr("Duration")); // ColumnDuration
         cpc->addItem(tr("Value"));    // ColumnValue
+        cpc->addItem(tr("Pitch"));    // ColumnPitch
         cpc->addItem(tr("Label"));    // ColumnLabel
         cpc->setCurrentIndex(int(m_format.getColumnPurpose(i)));
 
@@ -212,6 +213,9 @@
     case CSVFormat::TwoDimensionalModelWithDuration:
         s = f->getLayerPresentationName(LayerFactory::Regions);
         break;
+    case CSVFormat::TwoDimensionalModelWithDurationAndPitch:
+        s = f->getLayerPresentationName(LayerFactory::Notes);
+        break;
     case CSVFormat::ThreeDimensionalModel:
         s = f->getLayerPresentationName(LayerFactory::Colour3DPlot);
         break;
@@ -282,6 +286,7 @@
 
     bool haveStartTime = false;
     bool haveDuration = false;
+    bool havePitch = false;
     int valueCount = 0;
 
     for (int i = 0; i < m_columnPurposeCombos.size(); ++i) {
@@ -343,6 +348,9 @@
             cp == CSVFormat::ColumnDuration) {
             haveDuration = true;
         }
+        if (cp == CSVFormat::ColumnPitch) {
+            havePitch = true;
+        }
         if (cp == CSVFormat::ColumnValue) {
             ++valueCount;
         }
@@ -357,7 +365,11 @@
     }
 
     if (haveStartTime && haveDuration) {
-        m_format.setModelType(CSVFormat::TwoDimensionalModelWithDuration);
+        if (havePitch) {
+            m_format.setModelType(CSVFormat::TwoDimensionalModelWithDurationAndPitch);
+        } else {
+            m_format.setModelType(CSVFormat::TwoDimensionalModelWithDuration);
+        }
     } else {
         if (valueCount > 1) {
             m_format.setModelType(CSVFormat::ThreeDimensionalModel);
--- a/widgets/PropertyBox.cpp	Fri Apr 11 16:34:12 2014 +0100
+++ b/widgets/PropertyBox.cpp	Wed May 14 09:58:16 2014 +0100
@@ -24,10 +24,6 @@
 #include "base/UnitDatabase.h"
 #include "base/RangeMapper.h"
 
-#include "plugin/RealTimePluginFactory.h"
-#include "plugin/RealTimePluginInstance.h"
-#include "plugin/PluginXml.h"
-
 #include "AudioDial.h"
 #include "LEDButton.h"
 #include "IconLoader.h"
@@ -46,6 +42,7 @@
 #include <QApplication>
 #include <QColorDialog>
 #include <QInputDialog>
+#include <QDir>
 
 #include <cassert>
 #include <iostream>
@@ -188,16 +185,15 @@
 
 	layout->insertStretch(-1, 10);
 
-/*!!! todo: restore playback sample selection
-        if (params->getPlayPluginId() != "") {
-            QPushButton *pluginButton = new QPushButton(QIcon(":icons/faders.png"), "");
-            pluginButton->setFixedWidth(24);
-            pluginButton->setFixedHeight(24);
-            layout->addWidget(pluginButton);
-            connect(pluginButton, SIGNAL(clicked()),
-                    this, SLOT(editPlugin()));
+        if (params->getPlayClipId() != "") {
+            QPushButton *playParamButton =
+                new QPushButton(QIcon(":icons/faders.png"), "");
+            playParamButton->setFixedWidth(24);
+            playParamButton->setFixedHeight(24);
+            layout->addWidget(playParamButton);
+            connect(playParamButton, SIGNAL(clicked()),
+                    this, SLOT(editPlayParameters()));
         }
-*/
 
 	AudioDial *gainDial = new AudioDial;
 	layout->addWidget(gainDial);
@@ -463,7 +459,7 @@
                 // manages its own Add New Colour entry...
                 
                 ColourDatabase *db = ColourDatabase::getInstance();
-                for (size_t i = 0; i < db->getColourCount(); ++i) {
+                for (int i = 0; i < db->getColourCount(); ++i) {
                     QString name = db->getColourName(i);
                     cb->addItem(db->getExamplePixmap(i, QSize(12, 12)), name);
                 }
@@ -746,59 +742,60 @@
 
     updateContextHelp(obj);
 }
-/*!!! todo: restore playback sample selection
+
 void
-PropertyBox::editPlugin()
+PropertyBox::editPlayParameters()
 {
-    //!!! should probably just emit and let something else do this
-
     PlayParameters *params = m_container->getPlayParameters();
     if (!params) return;
 
-    QString pluginId = params->getPlayPluginId();
-    QString configurationXml = params->getPlayPluginConfiguration();
+    QString clip = params->getPlayClipId();
 
     PlayParameterRepository::EditCommand *command = 
         new PlayParameterRepository::EditCommand(params);
     
-    RealTimePluginFactory *factory =
-	RealTimePluginFactory::instanceFor(pluginId);
-    if (!factory) return;
+    QInputDialog *dialog = new QInputDialog(this);
 
-    RealTimePluginInstance *instance =
-        factory->instantiatePlugin(pluginId, 0, 0, 48000, 1024, 1);
-    if (!instance) return;
+    QDir dir(":/samples");
+    QStringList clipFiles = dir.entryList(QStringList() << "*.wav", QDir::Files);
 
-    PluginXml(instance).setParametersFromXml(configurationXml);
+    QStringList clips;
+    foreach (QString str, clipFiles) {
+        clips.push_back(str.replace(".wav", ""));
+    }
+    dialog->setComboBoxItems(clips);
 
-    PluginParameterDialog *dialog = new PluginParameterDialog(instance);
-    connect(dialog, SIGNAL(pluginConfigurationChanged(QString)),
-            this, SLOT(pluginConfigurationChanged(QString)));
+    dialog->setLabelText(tr("Set playback clip:"));
+
+    QComboBox *cb = dialog->findChild<QComboBox *>();
+    if (cb) cb->setCurrentText(clip);
+
+    connect(dialog, SIGNAL(textValueChanged(QString)), 
+            this, SLOT(playClipChanged(QString)));
 
     if (dialog->exec() == QDialog::Accepted) {
-        QString newConfiguration = PluginXml(instance).toXmlString();
-        command->setPlayPluginConfiguration(newConfiguration);
+        QString newClip = dialog->textValue();
+        command->setPlayClipId(newClip);
         CommandHistory::getInstance()->addCommand(command, true);
     } else {
         delete command;
         // restore in case we mucked about with the configuration
         // as a consequence of signals from the dialog
-        params->setPlayPluginConfiguration(configurationXml);
+        params->setPlayClipId(clip);
     }
 
     delete dialog;
-    delete instance;
 }
 
 void
-PropertyBox::pluginConfigurationChanged(QString configurationXml)
+PropertyBox::playClipChanged(QString id)
 {
     PlayParameters *params = m_container->getPlayParameters();
     if (!params) return;
 
-    params->setPlayPluginConfiguration(configurationXml);
+    params->setPlayClipId(id);
 }    
-*/
+
 void
 PropertyBox::layerVisibilityChanged(bool visible)
 {
--- a/widgets/PropertyBox.h	Fri Apr 11 16:34:12 2014 +0100
+++ b/widgets/PropertyBox.h	Wed May 14 09:58:16 2014 +0100
@@ -47,7 +47,7 @@
 public slots:
     void propertyContainerPropertyChanged(PropertyContainer *);
     void propertyContainerPropertyRangeChanged(PropertyContainer *);
-//!!!    void pluginConfigurationChanged(QString);
+    void playClipChanged(QString);
     void layerVisibilityChanged(bool);
 
 protected slots:
@@ -66,7 +66,7 @@
     void unitDatabaseChanged();
     void colourDatabaseChanged();
 
-//!!!    void editPlugin();
+    void editPlayParameters();
 
     void mouseEnteredWidget();
     void mouseLeftWidget();