diff layer/SpectrogramLayer.cpp @ 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
line wrap: on
line diff
--- 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;
     }
 }
+