changeset 590:241929c5d57c sonification

Check the scale width in the View (which has access to it); ask the layer to do something when the user clicks in the scale regardless of the edit mode, and continue with normal processing if the layer has nothing interesting to do
author Chris Cannam
date Fri, 24 Jun 2011 14:27:32 +0100
parents 7ebd5a21d74f
children 0946feb81b79
files layer/Layer.h layer/SpectrogramLayer.cpp layer/SpectrogramLayer.h view/Pane.cpp
diffstat 4 files changed, 36 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/layer/Layer.h	Wed Jun 22 00:04:21 2011 +0100
+++ b/layer/Layer.h	Fri Jun 24 14:27:32 2011 +0100
@@ -247,6 +247,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) { }
@@ -511,11 +519,6 @@
      */
     virtual RangeMapper *getNewVerticalZoomRangeMapper() const { return 0; }
 
-    //function to override in Layer subclasses in order to handle mouse events
-    //within the layer (e.g. audio feedback when clicking on the piano keyboard notes
-    //in SpectrogramLayer and SpectrumLayer)
-    virtual void processMouseEvent(const View *, QMouseEvent *, int) {}
-
 public slots:
     void showLayer(View *, bool show);
 
--- a/layer/SpectrogramLayer.cpp	Wed Jun 22 00:04:21 2011 +0100
+++ b/layer/SpectrogramLayer.cpp	Fri Jun 24 14:27:32 2011 +0100
@@ -3781,18 +3781,10 @@
     setNormalizeVisibleArea(normalizeVisibleArea);
 }
     
-void
-SpectrogramLayer::processMouseEvent(const View *v, QMouseEvent *e, int w)
+bool
+SpectrogramLayer::scaleClicked(const View *v, QMouseEvent *e)
 {
-
-    std::cerr<< "Mouse click detected in the layer: (" << e->x() << "," << e->y() << ")" << std::endl;
-
-    //is there a way to declare pkw and w may as class private variables?
-
-    int pkw = (m_frequencyScale == LogFrequencyScale ? 10 : 0);
-
-    int pianoKeyboardXLeft = w - pkw - 1;
-    int pianoKeyboardXRight = w;    
+    std::cerr<< "Mouse click detected in the spectrogram scale area: (" << e->x() << "," << e->y() << ")" << std::endl;
 
     float freq;
     QString unit;
@@ -3800,17 +3792,15 @@
     float concertA = 0.0;
     int midipitch;
 
-    if ((e->x() >= pianoKeyboardXLeft)&&(e->x() <= pianoKeyboardXRight))
-    {
-        std::cerr << "Piano keyboard left border: " << pianoKeyboardXLeft<<std::endl;
-        std::cerr << "Piano keyboard right border: " << pianoKeyboardXRight<<std::endl;
-        std::cerr<< "Mouse click detected within the piano keyboard: (" << e->x() << "," << e->y() << ")" << std::endl;
-
-        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 (getYScaleValue(v, e->y(), freq, unit)) {
+
+        midipitch = Pitch::getPitchForFrequency(freq,centsOffsetReturn,concertA);
+
+        std::cerr<< "Frequency: " << freq << " " << unit.toStdString() << " (midi pitch = " << midipitch << ")" << std::endl;
+
+        return true;
+    } else {
+        return false;
     }
 }
+
--- a/layer/SpectrogramLayer.h	Wed Jun 22 00:04:21 2011 +0100
+++ b/layer/SpectrogramLayer.h	Fri Jun 24 14:27:32 2011 +0100
@@ -227,7 +227,7 @@
 
     virtual const Model *getSliceableModel() const;
 
-    virtual void processMouseEvent(const View *, QMouseEvent *, int);
+    virtual bool scaleClicked(const View *, QMouseEvent *);
 
 protected slots:
     void cacheInvalid();
--- a/view/Pane.cpp	Wed Jun 22 00:04:21 2011 +0100
+++ b/view/Pane.cpp	Fri Jun 24 14:27:32 2011 +0100
@@ -1290,6 +1290,20 @@
     m_resizing = false;
     m_editing = false;
     m_releasing = false;
+    
+    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) ||
@@ -1309,24 +1323,6 @@
             m_dragStartMinValue = dmin;
         }
 
-    //to process the mouse event when a left click is made in the layer and the tool mode is Select
-    //(to handle e.g. the audio feedback of the piano keyboard notes)
-    //does not work with the Navigate tool mode: (mode == ViewManager::NavigateMode) ||
-    //which could be also interesting
-    } else if ((mode == ViewManager::SelectMode) &&
-                   (e->buttons() & Qt::LeftButton)) {
-
-            Layer *layer = getTopLayer();
-            LayerFactory::LayerType type = LayerFactory::getInstance()->getLayerType(layer);
-
-            //if (type==(LayerFactory::LayerType) MelodicRangeSpectrogram) layer->checkMouseClick(this, e);
-
-            //std::cerr << "Vertical scale width: " << getVerticalScaleWidth() << std::endl;
-
-            //should call processMouseEvent only when a LogFrequencyScale is used but this is handled by
-            //overidding the function only in the relevant layer types
-            layer->processMouseEvent(this, e, getVerticalScaleWidth());
-
     } else if (mode == ViewManager::SelectMode) {
 
         if (!hasTopLayerTimeXAxis()) return;