changeset 594:5fa210337bee integration_library

Merge from branch "sonification"
author mathieub <mathieu.barthet@eecs.qmul.ac.uk>
date Mon, 25 Jul 2011 18:56:28 +0100
parents aaa3be825207 (current diff) a13aa5320221 (diff)
children c080d14ff414
files view/ViewManager.cpp view/ViewManager.h
diffstat 11 files changed, 188 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/layer/Layer.h	Mon Jul 25 18:55:57 2011 +0100
+++ b/layer/Layer.h	Mon Jul 25 18:56:28 2011 +0100
@@ -129,6 +129,9 @@
     virtual QPixmap getLayerPresentationPixmap(QSize) const { return QPixmap(); }
 
     virtual int getVerticalScaleWidth(View *, QPainter &) const { return 0; }
+
+    //virtual int getHorizontalScaleHeight(View *, QPainter &) const { return 0; } //this causes the application to crash at startup?
+
     virtual void paintVerticalScale(View *, QPainter &, QRect) const { }
 
     virtual bool getCrosshairExtents(View *, QPainter &, QPoint /* cursorPos */,
@@ -247,6 +250,14 @@
      */
     virtual bool editOpen(View *, QMouseEvent *) { return false; }
 
+    /**
+     * A click occurred over the layer's scale area.  If the layer has
+     * a response to this (e.g. play a note corresponding to frequency
+     * scale), perform it and return true.  Return false if this click
+     * is not meaningful to the layer.
+     */
+    virtual bool scaleClicked(const View *, QMouseEvent *) { return false; }
+
     virtual void moveSelection(Selection, size_t /* newStartFrame */) { }
     virtual void resizeSelection(Selection, Selection /* newSize */) { }
     virtual void deleteSelection(Selection) { }
--- a/layer/SpectrogramLayer.cpp	Mon Jul 25 18:55:57 2011 +0100
+++ b/layer/SpectrogramLayer.cpp	Mon Jul 25 18:56:28 2011 +0100
@@ -3274,7 +3274,8 @@
     int fw = paint.fontMetrics().width(tr("43Hz"));
     if (tw < fw) tw = fw;
 
-    int tickw = (m_frequencyScale == LogFrequencyScale ? 10 : 4);
+    //int tickw = (m_frequencyScale == LogFrequencyScale ? 10 : 4);
+    int tickw = (m_frequencyScale == LogFrequencyScale ? 20 : 4);
     
     return cw + tickw + tw + 13;
 }
@@ -3292,8 +3293,11 @@
 
     int h = rect.height(), w = rect.width();
 
-    int tickw = (m_frequencyScale == LogFrequencyScale ? 10 : 4);
-    int pkw = (m_frequencyScale == LogFrequencyScale ? 10 : 0);
+    //int tickw = (m_frequencyScale == LogFrequencyScale ? 10 : 4);
+    //int pkw = (m_frequencyScale == LogFrequencyScale ? 10 : 0);
+
+    int tickw = (m_frequencyScale == LogFrequencyScale ? 20 : 4);
+    int pkw = (m_frequencyScale == LogFrequencyScale ? 20 : 0);
 
     size_t bins = m_fftSize / 2;
     int sr = m_model->getSampleRate();
@@ -3781,3 +3785,31 @@
     setNormalizeVisibleArea(normalizeVisibleArea);
 }
     
+bool
+SpectrogramLayer::scaleClicked(const View *v, QMouseEvent *e)
+{
+    std::cerr<< "Mouse click detected in the spectrogram scale area: (" << e->x() << "," << e->y() << ")" << std::endl;
+
+    float freq;
+    QString unit;
+    float *centsOffsetReturn = 0;
+    float concertA = 0.0;
+    int midipitch;
+
+    if (getYScaleValue(v, e->y(), freq, unit)) {
+
+        midipitch = Pitch::getPitchForFrequency(freq,centsOffsetReturn,concertA);
+
+        std::cerr<< "Frequency: " << freq << " " << unit.toStdString() << " (midi pitch = " << midipitch << ")" << std::endl;
+
+        if ((midipitch>=0)&&(midipitch<127)) {
+            v->playExampleNote(midipitch);
+        }
+
+        return true;
+
+    } else {
+        return false;
+    }
+}
+
--- a/layer/SpectrogramLayer.h	Mon Jul 25 18:55:57 2011 +0100
+++ b/layer/SpectrogramLayer.h	Mon Jul 25 18:56:28 2011 +0100
@@ -227,6 +227,8 @@
 
     virtual const Model *getSliceableModel() const;
 
+    virtual bool scaleClicked(const View *, QMouseEvent *);
+
 protected slots:
     void cacheInvalid();
     void cacheInvalid(size_t startFrame, size_t endFrame);
--- a/layer/SpectrumLayer.cpp	Mon Jul 25 18:55:57 2011 +0100
+++ b/layer/SpectrumLayer.cpp	Mon Jul 25 18:56:28 2011 +0100
@@ -25,7 +25,7 @@
 
 #include <QPainter>
 #include <QTextStream>
-
+#include <QMouseEvent>
 
 SpectrumLayer::SpectrumLayer() :
     m_originModel(0),
@@ -673,7 +673,9 @@
 
     int pkh = 0;
 //!!!    if (m_binScale == LogBins) {
-        pkh = 10;
+        //pkh = 10; //too small
+    pkh = 20;
+
 //!!!    }
 
     paint.save();
@@ -823,6 +825,17 @@
     paint.restore();
 }
 
+/*
+int
+SpectrumLayer::getHorizontalScaleHeight(View *v, QPainter &paint) const
+{
+    int h = v->height();
+    int pkh = 10;
+
+    return h - pkh - 1;
+}*/
+
+
 void
 SpectrumLayer::getBiasCurve(BiasCurve &curve) const
 {
@@ -860,4 +873,30 @@
     setShowPeaks(showPeaks);
 }
 
-    
+bool
+SpectrumLayer::scaleClicked(const View *v, QMouseEvent *e)
+{
+    std::cerr<< "Mouse click detected in the spectrum scale area: (" << e->x() << "," << e->y() << ")" << std::endl;
+
+    float freq;
+    QString unit;
+    float *centsOffsetReturn = 0;
+    float concertA = 0.0;
+    int midipitch;
+
+    if (getXScaleValue(v, e->x(), freq, unit)) {
+
+        midipitch = Pitch::getPitchForFrequency(freq,centsOffsetReturn,concertA);
+
+        std::cerr<< "Frequency: " << freq << " " << unit.toStdString() << " (midi pitch = " << midipitch << ")" << std::endl;
+
+        if ((midipitch>=0)&&(midipitch<127)) {
+            v->playExampleNote(midipitch);
+        }
+
+        return true;
+
+    } else {
+        return false;
+    }
+}
--- a/layer/SpectrumLayer.h	Mon Jul 25 18:55:57 2011 +0100
+++ b/layer/SpectrumLayer.h	Mon Jul 25 18:56:28 2011 +0100
@@ -45,6 +45,8 @@
 
     virtual QString getFeatureDescription(View *v, QPoint &) const;
 
+    //virtual int getHorizontalScaleHeight(View *, QPainter &) const;
+
     virtual void paint(View *v, QPainter &paint, QRect rect) const;
 
     virtual VerticalPosition getPreferredFrameCountPosition() const {
@@ -96,6 +98,8 @@
     virtual void toXml(QTextStream &stream, QString indent = "",
                        QString extraAttributes = "") const;
 
+    virtual bool scaleClicked(const View *, QMouseEvent *);
+
 protected slots:
     void preferenceChanged(PropertyContainer::PropertyName name);
 
--- a/view/Pane.cpp	Mon Jul 25 18:55:57 2011 +0100
+++ b/view/Pane.cpp	Mon Jul 25 18:56:28 2011 +0100
@@ -14,7 +14,6 @@
 */
 
 #include "Pane.h"
-#include "layer/Layer.h"
 #include "data/model/Model.h"
 #include "base/ZoomConstraint.h"
 #include "base/RealTime.h"
@@ -25,6 +24,10 @@
 #include "base/Preferences.h"
 #include "layer/WaveformLayer.h"
 
+#include "layer/LayerFactory.h"
+#include "layer/Layer.h"
+#include "layer/SpectrogramLayer.h"
+
 //!!! ugh
 #include "data/model/WaveFileModel.h"
 
@@ -1287,6 +1290,79 @@
     m_editing = false;
     m_releasing = false;
 
+    bool scaleclick = false;
+
+    Layer *layer = getTopLayer();
+    if (layer) {
+        LayerFactory::LayerType type = LayerFactory::getInstance()->getLayerType(layer);
+
+        //std::cerr << "hello before switch: " << LayerFactory::getInstance()->getLayerTypeName(type) << std::endl;
+
+        switch(type) {
+
+            case LayerFactory::Spectrogram:
+            {
+                std::cerr << "hello spectrogram ("<< e->x() <<", " << e->y() << ")" << std::endl;                
+            }
+            case LayerFactory::MelodicRangeSpectrogram:
+            {
+                std::cerr << "hello melodic ("<< e->x() <<", " << e->y() << ")" << std::endl;
+                int sw = getVerticalScaleWidth();
+                int pkhms = 20; //this value should be retrieved from SpectrogramLayer
+                int slb = sw - pkhms - 1; //scale left border
+
+                //std::cerr << "slb: "<< slb << std::endl;
+
+                if ((e->x() < sw)&&(e->x() > slb)) {
+                    scaleclick = true;
+                }
+                break;
+            }
+            case LayerFactory::Spectrum:
+            {
+                std::cerr << "hello spectrum ("<< e->x() <<", " << e->y() << ")" << std::endl;
+
+                int h = height();
+                int pkhs = 20; //this value should be retrieved from SpectrumLayer
+
+                int sh = h - pkhs - 1;
+
+                //if (e->y() < layer->getHorizontalScaleHeight(this)) {
+
+                if (e->y() > sh) {                    
+                    scaleclick = true;
+                 }
+                break;
+            }
+        }
+
+        if (scaleclick) {
+            // Click occurred over the layer's scale area.  Ask the layer
+            // to do something with it: if it does so (i.e. returns true),
+            // we've nothing else to do
+            if (layer->scaleClicked(this, e)) {
+                m_clickedInRange = false;
+                emit paneInteractedWith();
+                return;
+            }
+        }
+    }
+    /*
+    if (e->x() < getVerticalScaleWidth()) {
+        // Click occurred over the layer's scale area.  Ask the layer
+        // to do something with it: if it does so (i.e. returns true),
+        // we've nothing else to do
+        Layer *layer = getTopLayer();
+        if (layer) {
+            if (layer->scaleClicked(this, e)) {
+                m_clickedInRange = false;
+                emit paneInteractedWith();
+                return;
+            }
+        }
+    }
+    */
+
     if (mode == ViewManager::NavigateMode ||
         (e->buttons() & Qt::MidButton) ||
         (mode == ViewManager::MeasureMode &&
--- a/view/Pane.h	Mon Jul 25 18:55:57 2011 +0100
+++ b/view/Pane.h	Mon Jul 25 18:56:28 2011 +0100
@@ -52,6 +52,8 @@
 
     virtual size_t getVerticalScaleWidth() const;
 
+    //virtual size_t getHorizontalScaleHeight() const;
+
     virtual QImage *toNewImage(size_t f0, size_t f1);
     virtual QImage *toNewImage() { return View::toNewImage(); }
     virtual QSize getImageSize(size_t f0, size_t f1);
--- a/view/View.cpp	Mon Jul 25 18:55:57 2011 +0100
+++ b/view/View.cpp	Mon Jul 25 18:56:28 2011 +0100
@@ -2365,6 +2365,12 @@
 }
 
 void
+View::playExampleNote(int midiPitch) const
+{
+    if (m_manager) m_manager->playExampleNote(midiPitch);
+}
+
+void
 View::toXml(QTextStream &stream,
             QString indent, QString extraAttributes) const
 {
--- a/view/View.h	Mon Jul 25 18:55:57 2011 +0100
+++ b/view/View.h	Mon Jul 25 18:56:28 2011 +0100
@@ -307,6 +307,8 @@
 
     virtual void progressCheckStalledTimerElapsed();
 
+    virtual void playExampleNote(int midiPitch) const;
+
 protected:
     View(QWidget *, bool showProgress);
     virtual void paintEvent(QPaintEvent *e);
--- a/view/ViewManager.cpp	Mon Jul 25 18:55:57 2011 +0100
+++ b/view/ViewManager.cpp	Mon Jul 25 18:56:28 2011 +0100
@@ -191,6 +191,12 @@
     else return m_playbackModel->alignFromReference(frame);
 }
 
+void
+ViewManager::playExampleNote(int midiPitch)
+{
+    m_playSource->queueExampleNote(midiPitch);
+}
+
 bool
 ViewManager::haveInProgressSelection() const
 {
--- a/view/ViewManager.h	Mon Jul 25 18:55:57 2011 +0100
+++ b/view/ViewManager.h	Mon Jul 25 18:56:28 2011 +0100
@@ -251,6 +251,7 @@
     void viewZoomLevelChanged(unsigned long, bool);
     void setGlobalCentreFrame(unsigned long);
     void setPlaybackFrame(unsigned long);
+    void playExampleNote(int midiPitch);
 
 protected slots:
     void checkPlayStatus();