# HG changeset patch # User Chris Cannam # Date 1156166330 0 # Node ID e981307646354b7cecdf780858e00e739d074ff6 # Parent 13949a6970abd8a877be12a7d130e6007131025a * Sensible default for vertical thumbwheel on spectrogram layer diff -r 13949a6970ab -r e98130764635 layer/SpectrogramLayer.cpp --- a/layer/SpectrogramLayer.cpp Wed Aug 16 14:57:47 2006 +0000 +++ b/layer/SpectrogramLayer.cpp Mon Aug 21 13:18:50 2006 +0000 @@ -51,6 +51,7 @@ m_colourRotation(0), m_minFrequency(10), m_maxFrequency(8000), + m_initialMaxFrequency(8000), m_colourScale(dBColourScale), m_colourScheme(DefaultColours), m_frequencyScale(LinearFrequencyScale), @@ -66,12 +67,14 @@ setWindowSize(8192); setWindowHopLevel(4); // setWindowType(ParzenWindow); + m_initialMaxFrequency = 1000; setMaxFrequency(1000); setColourScale(LinearColourScale); } else if (config == MelodicPeaks) { setWindowSize(4096); setWindowHopLevel(5); // setWindowType(BlackmanWindow); + m_initialMaxFrequency = 2000; setMaxFrequency(2000); setMinFrequency(40); setFrequencyScale(LogFrequencyScale); @@ -2768,8 +2771,33 @@ int SpectrogramLayer::getVerticalZoomSteps(int &defaultStep) const { + // Vertical zoom step 0 shows the entire range from DC -> Nyquist + // frequency. Step 1 shows 2^(1/4) of the range of step 0, and so + // on until the visible range is smaller than the frequency step + // between bins at the current fft size. + + if (!m_model) return 0; + + float min, max; + int sr = m_model->getSampleRate(); + min = float(sr) / m_fftSize; + max = float(sr) / 2; + + float dist = max - min; + + int n = 0; defaultStep = 0; - return 20; //!!! + float s2 = sqrtf(sqrtf(2)); + while (dist > min) { + if (max >= m_initialMaxFrequency) { + defaultStep = n; + } + ++n; + dist /= s2; + max = min + dist; + } + + return n; } int @@ -2789,9 +2817,11 @@ float ddist = dmax - dmin; int n = 0; - float s2 = sqrtf(2); + int discard = 0; + int m = getVerticalZoomSteps(discard); + float s2 = sqrtf(sqrtf(2)); while (mdist > ddist) { - if (++n > 20) break; + if (++n > m) break; mdist /= s2; } @@ -2814,7 +2844,7 @@ float ddist = mmax - mmin; int n = 0; - float s2 = sqrtf(2); + float s2 = sqrtf(sqrtf(2)); while (n < step) { ddist /= s2; ++n; diff -r 13949a6970ab -r e98130764635 layer/SpectrogramLayer.h --- a/layer/SpectrogramLayer.h Wed Aug 16 14:57:47 2006 +0000 +++ b/layer/SpectrogramLayer.h Mon Aug 21 13:18:50 2006 +0000 @@ -234,6 +234,7 @@ int m_colourRotation; size_t m_minFrequency; size_t m_maxFrequency; + size_t m_initialMaxFrequency; ColourScale m_colourScale; ColourScheme m_colourScheme; QColor m_crosshairColour; diff -r 13949a6970ab -r e98130764635 view/Pane.cpp --- a/view/Pane.cpp Wed Aug 16 14:57:47 2006 +0000 +++ b/view/Pane.cpp Mon Aug 21 13:18:50 2006 +0000 @@ -147,6 +147,11 @@ m_vthumb->setMaximumValue(max); m_vthumb->setDefaultValue(defaultStep); m_vthumb->setValue(layer->getCurrentVerticalZoomStep()); + + std::cerr << "Vertical thumbwheel: min 0, max " << max + << ", default " << defaultStep << ", value " + << m_vthumb->getValue() << std::endl; + } }