Mercurial > hg > svgui
changeset 41:f2c416cbdaa9
* Add time/Hz description for waveform model to the bottom right of a pane
containing a waveform (also tried this in the status bar, wasn't so good)
* Further spectrogram fixes
author | Chris Cannam |
---|---|
date | Fri, 24 Feb 2006 17:26:11 +0000 |
parents | 3be4438b186d |
children | 1bdf285c4eac |
files | layer/SpectrogramLayer.cpp layer/SpectrogramLayer.h layer/WaveformLayer.cpp widgets/Pane.cpp |
diffstat | 4 files changed, 43 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/layer/SpectrogramLayer.cpp Fri Feb 24 15:46:47 2006 +0000 +++ b/layer/SpectrogramLayer.cpp Fri Feb 24 17:26:11 2006 +0000 @@ -70,7 +70,7 @@ setMaxFrequency(2000); setMinFrequency(40); setFrequencyScale(LogFrequencyScale); - setColourScale(dBColourScale); + setColourScale(MeterColourScale); setBinDisplay(PeakFrequencies); setNormalizeColumns(true); } @@ -1221,6 +1221,8 @@ m_width = width; m_height = height; + + std::cerr << "done, width = " << m_width << " height = " << m_height << std::endl; } void @@ -1296,6 +1298,8 @@ size_t start = m_layer.m_model->getStartFrame(); size_t end = m_layer.m_model->getEndFrame(); + std::cerr << "start = " << start << ", end = " << end << std::endl; + WindowType windowType = m_layer.m_windowType; size_t windowSize = m_layer.m_windowSize; size_t windowIncrement = m_layer.getWindowIncrement(); @@ -1533,7 +1537,9 @@ int f0 = getFrameForX(x) - modelStart; int f1 = getFrameForX(x + 1) - modelStart - 1; - if (f1 < int(modelStart) || f0 > int(modelEnd)) return false; + if (f1 < int(modelStart) || f0 > int(modelEnd)) { + return false; + } // And that range may be drawn from a possibly non-integral // range of spectrogram windows: @@ -1864,7 +1870,7 @@ // std::cerr << "x0 " << x0 << ", x1 " << x1 << ", w " << w << ", h " << h << std::endl; QImage scaled(w, h, QImage::Format_RGB32); - scaled.fill(0); + scaled.fill(m_cache->getColour(0).rgb()); float ymag[h]; float ydiv[h]; @@ -1910,9 +1916,6 @@ if (!getXBinRange(x0 + x, s0, s1)) { assert(x <= scaled.width()); - for (int y = 0; y < h; ++y) { - scaled.setPixel(x, y, qRgb(0, 0, 0)); - } m_mutex.unlock(); continue; } @@ -2338,7 +2341,9 @@ if (n == 1 || n == 3 || n == 6 || n == 8 || n == 10) { // black notes paint.drawLine(w - pkw, y, w, y); - paint.drawRect(w - pkw, y - (py-y)/4, pkw/2, 2*((py-y)/4)); + int rh = ((py - y) / 4) * 2; + if (rh < 2) rh = 2; + paint.drawRect(w - pkw, y - (py-y)/4, pkw/2, rh); } else if (n == 0 || n == 5) { // C, A if (py < h) {
--- a/layer/SpectrogramLayer.h Fri Feb 24 15:46:47 2006 +0000 +++ b/layer/SpectrogramLayer.h Fri Feb 24 17:26:11 2006 +0000 @@ -260,7 +260,7 @@ } void setNormalizationFactor(size_t x, float factor) { - m_factor[x] = factor; + if (x < m_width) m_factor[x] = factor; } void setMagnitudeAt(size_t x, size_t y, float mag) { @@ -269,12 +269,16 @@ } void setNormalizedMagnitudeAt(size_t x, size_t y, float norm) { - m_magnitude[y][x] = uint16_t(norm * 65535.0); + if (x < m_width && y < m_height) { + m_magnitude[y][x] = uint16_t(norm * 65535.0); + } } void setPhaseAt(size_t x, size_t y, float phase) { // phase in range -pi -> pi - m_phase[y][x] = uint16_t(int16_t((phase * 32767) / M_PI)); + if (x < m_width && y < m_height) { + m_phase[y][x] = uint16_t(int16_t((phase * 32767) / M_PI)); + } } QColor getColour(unsigned char index) const {
--- a/layer/WaveformLayer.cpp Fri Feb 24 15:46:47 2006 +0000 +++ b/layer/WaveformLayer.cpp Fri Feb 24 17:26:11 2006 +0000 @@ -659,6 +659,7 @@ } if (m_aggressive) { + if (ready && rect == m_view->rect()) { m_cacheValid = true; m_cacheZoomLevel = zoomLevel;
--- a/widgets/Pane.cpp Fri Feb 24 15:46:47 2006 +0000 +++ b/widgets/Pane.cpp Fri Feb 24 17:26:11 2006 +0000 @@ -14,6 +14,7 @@ #include "base/RealTime.h" #include "base/Profiler.h" #include "base/ViewManager.h" +#include "layer/WaveformLayer.h" #include <QPaintEvent> #include <QPainter> @@ -87,10 +88,16 @@ if (e) { paint.setClipRect(r); } - + + const Model *waveformModel = 0; // just for reporting purposes + for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) { --vi; + if (dynamic_cast<WaveformLayer *>(*vi)) { + waveformModel = (*vi)->getModel(); + } + int sw = (*vi)->getVerticalScaleWidth(paint); if (sw > 0 && r.left() < sw) { @@ -109,7 +116,7 @@ paint.restore(); } - + if (m_identifyFeatures) { QPoint pos = m_identifyPoint; @@ -247,6 +254,20 @@ paint.setPen(QColor(200, 200, 200)); } paint.drawText(x, y, text); + + if (waveformModel) { + + QString desc = tr("%1 / %2Hz") + .arg(RealTime::frame2RealTime(waveformModel->getEndFrame(), + waveformModel->getSampleRate()) + .toText(false).c_str()) + .arg(waveformModel->getSampleRate()); + + paint.drawText(width() - paint.fontMetrics().width(desc) - 5, + height() - paint.fontMetrics().height() + + paint.fontMetrics().ascent() - 6, + desc); + } } if (m_clickedInRange && m_shiftPressed) {