changeset 122:71992cee2ece

* Finish preferences dialog (as far as it's going at the moment) and connect it up * Fix Parzen window shape (was triangular!) * Various fixes to spectrogram draw coordinates in smoothing mode etc * Draw C keys in grey on the piano
author Chris Cannam
date Fri, 21 Jul 2006 16:03:42 +0000
parents 7363cacf7de0
children 842bf484ee15
files layer/SpectrogramLayer.cpp layer/SpectrogramLayer.h widgets/Pane.cpp widgets/PluginParameterDialog.cpp
diffstat 4 files changed, 77 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/layer/SpectrogramLayer.cpp	Thu Jul 20 16:51:20 2006 +0000
+++ b/layer/SpectrogramLayer.cpp	Fri Jul 21 16:03:42 2006 +0000
@@ -79,6 +79,11 @@
 	setNormalizeColumns(true);
     }
 
+    Preferences *prefs = Preferences::getInstance();
+    connect(prefs, SIGNAL(propertyChanged(PropertyContainer::PropertyName)),
+            this, SLOT(preferenceChanged(PropertyContainer::PropertyName)));
+    setWindowType(prefs->getWindowType());
+
     setColourmap();
 }
 
@@ -549,6 +554,25 @@
 }
 
 void
+SpectrogramLayer::preferenceChanged(PropertyContainer::PropertyName name)
+{
+    std::cerr << "SpectrogramLayer::preferenceChanged(" << name.toStdString() << ")" << std::endl;
+
+    if (name == "Window Type") {
+        setWindowType(Preferences::getInstance()->getWindowType());
+        return;
+    }
+    if (name == "Smooth Spectrogram") {
+        invalidatePixmapCaches();
+        invalidateMagnitudes();
+        emit layerParametersChanged();
+    }
+    if (name == "Tuning Frequency") {
+        emit layerParametersChanged();
+    }
+}
+
+void
 SpectrogramLayer::setChannel(int ch)
 {
     if (m_channel == ch) return;
@@ -1336,8 +1360,6 @@
 
     int sr = m_model->getSampleRate();
 
-    //!!! wrong for smoothing -- wrong fft size for fft adapter
-
     for (int q = q0i; q <= q1i; ++q) {
 	if (q == q0i) freqMin = (sr * q) / m_fftSize;
 	if (q == q1i) freqMax = (sr * (q+1)) / m_fftSize;
@@ -1437,6 +1459,10 @@
 
     bool rv = false;
 
+    size_t zp = getZeroPadLevel(v);
+    q0i *= zp + 1;
+    q1i *= zp + 1;
+
     FFTFuzzyAdapter *fft = getFFTAdapter(v);
 
     if (fft) {
@@ -1864,6 +1890,10 @@
     m_drawBuffer.fill(m_colourMap.getColour(0).rgb());
 
     int sr = m_model->getSampleRate();
+
+    // Set minFreq and maxFreq to the frequency extents of the possibly
+    // zero-padded visible bin range, and displayMinFreq and displayMaxFreq
+    // to the actual scale frequency extents (presumably not zero padded).
     
     size_t bins = fftSize / 2;
     if (m_maxFrequency > 0) {
@@ -1881,9 +1911,17 @@
     float minFreq = (float(minbin) * sr) / fftSize;
     float maxFreq = (float(bins) * sr) / fftSize;
 
+    float displayMinFreq = minFreq;
+    float displayMaxFreq = maxFreq;
+
+    if (fftSize != m_fftSize) {
+        displayMinFreq = getEffectiveMinFrequency();
+        displayMaxFreq = getEffectiveMaxFrequency();
+    }
+
     float ymag[h];
     float ydiv[h];
-    float yval[bins + 1]; //!!! cache this
+    float yval[bins + 1]; //!!! cache this?
 
     size_t increment = getWindowIncrement();
     
@@ -1891,7 +1929,9 @@
 
     for (size_t q = minbin; q <= bins; ++q) {
         float f0 = (float(q) * sr) / fftSize;
-        yval[q] = v->getYForFrequency(f0, minFreq, maxFreq, logarithmic);
+        yval[q] = v->getYForFrequency(f0, displayMinFreq, displayMaxFreq,
+                                      logarithmic);
+//        std::cerr << "min: " << minFreq << ", max: " << maxFreq << ", yval[" << q << "]: " << yval[q] << std::endl;
     }
 
     MagnitudeRange overallMag = m_viewMags[v];
@@ -1959,7 +1999,7 @@
 						 steady);
 
 		    y0 = y1 = v->getYForFrequency
-			(f, minFreq, maxFreq, logarithmic);
+			(f, displayMinFreq, displayMaxFreq, logarithmic);
 		}
 		
 		int y0i = int(y0 + 0.001);
@@ -2429,6 +2469,8 @@
 	return;
     }
 
+    Profiler profiler("SpectrogramLayer::paintVerticalScale", true);
+
     //!!! cache this?
 
     int h = rect.height(), w = rect.width();
@@ -2615,14 +2657,34 @@
 	float minf = getEffectiveMinFrequency();
 	float maxf = getEffectiveMaxFrequency();
 
-	int py = h;
+	int py = h, ppy = h;
 	paint.setBrush(paint.pen().color());
 
 	for (int i = 0; i < 128; ++i) {
 
 	    float f = Pitch::getFrequencyForPitch(i);
 	    int y = lrintf(v->getYForFrequency(f, minf, maxf, true));
+
+            if (y < -2) break;
+            if (y > h + 2) {
+                continue;
+            }
+
 	    int n = (i % 12);
+
+            if (n == 1) {
+                // C# -- fill the C from here
+                if (ppy - y > 2) {
+                    paint.fillRect(w - pkw,
+//                                   y - (py - y) / 2 - (py - y) / 4, 
+                                   y,
+                                   pkw,
+                                   (py + ppy) / 2 - y,
+//                                   py - y + 1,
+                                   Qt::gray);
+                }
+            }
+
 	    if (n == 1 || n == 3 || n == 6 || n == 8 || n == 10) {
 		// black notes
 		paint.drawLine(w - pkw, y, w, y);
@@ -2630,12 +2692,13 @@
 		if (rh < 2) rh = 2;
 		paint.drawRect(w - pkw, y - (py-y)/4, pkw/2, rh);
 	    } else if (n == 0 || n == 5) {
-		// C, A
+		// C, F
 		if (py < h) {
 		    paint.drawLine(w - pkw, (y + py) / 2, w, (y + py) / 2);
 		}
 	    }
 
+            ppy = py;
 	    py = y;
 	}
     }
--- a/layer/SpectrogramLayer.h	Thu Jul 20 16:51:20 2006 +0000
+++ b/layer/SpectrogramLayer.h	Fri Jul 21 16:03:42 2006 +0000
@@ -20,6 +20,7 @@
 #include "base/Window.h"
 #include "base/RealTime.h"
 #include "base/Thread.h"
+#include "base/PropertyContainer.h"
 #include "model/PowerOfSqrtTwoZoomConstraint.h"
 #include "model/DenseTimeValueModel.h"
 
@@ -211,6 +212,8 @@
 protected slots:
     void cacheInvalid();
     void cacheInvalid(size_t startFrame, size_t endFrame);
+    
+    void preferenceChanged(PropertyContainer::PropertyName name);
 
     void fillTimerTimedOut();
 
--- a/widgets/Pane.cpp	Thu Jul 20 16:51:20 2006 +0000
+++ b/widgets/Pane.cpp	Fri Jul 21 16:03:42 2006 +0000
@@ -109,6 +109,8 @@
 void
 Pane::paintEvent(QPaintEvent *e)
 {
+    Profiler profiler("Pane::paintEvent", true);
+
     QPainter paint;
 
     QRect r(rect());
--- a/widgets/PluginParameterDialog.cpp	Thu Jul 20 16:51:20 2006 +0000
+++ b/widgets/PluginParameterDialog.cpp	Fri Jul 21 16:03:42 2006 +0000
@@ -38,6 +38,8 @@
     m_channel(defaultChannel),
     m_parameterBox(0)
 {
+    setWindowTitle(tr("Plugin Parameters"));
+
     QGridLayout *grid = new QGridLayout;
     setLayout(grid);