Mercurial > hg > svgui
changeset 20:1deb5f87a18c
* Add getXForFrame / getFrameForX in preference to using the zoom level everywhere
author | Chris Cannam |
---|---|
date | Mon, 30 Jan 2006 13:19:42 +0000 |
parents | 46d8f5add6f0 |
children | 3a506d25d95a |
files | layer/Colour3DPlotLayer.cpp layer/SpectrogramLayer.cpp layer/SpectrogramLayer.h layer/TimeInstantLayer.cpp layer/TimeValueLayer.cpp widgets/Pane.cpp |
diffstat | 6 files changed, 68 insertions(+), 86 deletions(-) [+] |
line wrap: on
line diff
--- a/layer/Colour3DPlotLayer.cpp Fri Jan 27 18:04:07 2006 +0000 +++ b/layer/Colour3DPlotLayer.cpp Mon Jan 30 13:19:42 2006 +0000 @@ -181,10 +181,8 @@ //direction. This one is only really appropriate for models with //far fewer bins in both directions. - int sx0 = ((startFrame + x0 * zoomLevel) - int(modelStart)) / - int(modelWindow); - int sx1 = ((startFrame + x1 * zoomLevel) - int(modelStart)) / - int(modelWindow); + int sx0 = int((getFrameForX(x0) - long(modelStart)) / long(modelWindow)); + int sx1 = int((getFrameForX(x1) - long(modelStart)) / long(modelWindow)); int sw = sx1 - sx0; int sh = m_model->getYBinCount(); @@ -202,10 +200,8 @@ for (int sy = 0; sy < sh; ++sy) { - int rx0 = ((fx + int(modelStart)) - - int(startFrame)) / zoomLevel; - int rx1 = ((fx + int(modelWindow) + int(modelStart)) - - int(startFrame)) / zoomLevel; + int rx0 = getXForFrame(fx + int(modelStart)); + int rx1 = getXForFrame(fx + int(modelStart) + int(modelWindow)); int ry0 = h - (sy * h) / sh - 1; int ry1 = h - ((sy + 1) * h) / sh - 2;
--- a/layer/SpectrogramLayer.cpp Fri Jan 27 18:04:07 2006 +0000 +++ b/layer/SpectrogramLayer.cpp Mon Jan 30 13:19:42 2006 +0000 @@ -1101,31 +1101,28 @@ } bool -SpectrogramLayer::getXBinRange(int x, float &s0, float &s1, LayerRange *range) const +SpectrogramLayer::getXBinRange(int x, float &s0, float &s1) const { - long startFrame; - int zoomLevel; +// long startFrame; +// int zoomLevel; size_t modelStart; size_t modelEnd; - if (range) { - startFrame = range->startFrame; - zoomLevel = range->zoomLevel; - modelStart = range->modelStart; - modelEnd = range->modelEnd; - } else { - startFrame = m_view->getStartFrame(); - zoomLevel = m_view->getZoomLevel(); - modelStart = m_model->getStartFrame(); - modelEnd = m_model->getEndFrame(); - } +// startFrame = m_view->getStartFrame(); +// zoomLevel = m_view->getZoomLevel(); + modelStart = m_model->getStartFrame(); + modelEnd = m_model->getEndFrame(); // Each pixel column covers an exact range of sample frames: + int f0 = getFrameForX(x) - modelStart; + int f1 = getFrameForX(x + 1) - modelStart - 1; + +/* int f0 = startFrame + x * zoomLevel - modelStart; int f1 = f0 + zoomLevel - 1; - +*/ if (f1 < int(modelStart) || f0 > int(modelEnd)) return false; - + // And that range may be drawn from a possibly non-integral // range of spectrogram windows: @@ -1290,8 +1287,8 @@ m_pixmapCache->width() == m_view->width() && m_pixmapCache->height() == m_view->height()) { - if (m_pixmapCacheStartFrame / zoomLevel == - startFrame / zoomLevel) { + if (getXForFrame(m_pixmapCacheStartFrame) == + getXForFrame(startFrame)) { #ifdef DEBUG_SPECTROGRAM_REPAINT std::cerr << "SpectrogramLayer: pixmap cache good" << std::endl; @@ -1309,7 +1306,8 @@ recreateWholePixmapCache = false; - int dx = (m_pixmapCacheStartFrame - startFrame) / zoomLevel; + int dx = getXForFrame(m_pixmapCacheStartFrame) - + getXForFrame(startFrame); #ifdef DEBUG_SPECTROGRAM_REPAINT std::cerr << "SpectrogramLayer: dx = " << dx << " (pixmap cache " << m_pixmapCache->width() << "x" << m_pixmapCache->height() << ")" << std::endl; @@ -1377,9 +1375,6 @@ QImage scaled(w, h, QImage::Format_RGB32); - LayerRange range = { m_view->getStartFrame(), m_view->getZoomLevel(), - m_model->getStartFrame(), m_model->getEndFrame() }; - m_mutex.unlock(); for (int y = 0; y < h; ++y) { @@ -1411,7 +1406,7 @@ float s0 = 0, s1 = 0; - if (!getXBinRange(x0 + x, s0, s1, &range)) { + if (!getXBinRange(x0 + x, s0, s1)) { assert(x <= scaled.width()); scaled.setPixel(x, y, qRgb(0, 0, 0)); continue;
--- a/layer/SpectrogramLayer.h Fri Jan 27 18:04:07 2006 +0000 +++ b/layer/SpectrogramLayer.h Mon Jan 30 13:19:42 2006 +0000 @@ -217,9 +217,7 @@ size_t modelStart; size_t modelEnd; }; - /// LayerRange is only passed in to save lookup time - bool getXBinRange(int x, float &windowMin, float &windowMax, - LayerRange *range = 0) const; + bool getXBinRange(int x, float &windowMin, float &windowMax) const; bool getYBinSourceRange(int y, float &freqMin, float &freqMax) const; bool getXBinSourceRange(int x, RealTime &timeMin, RealTime &timeMax) const;
--- a/layer/TimeInstantLayer.cpp Fri Jan 27 18:04:07 2006 +0000 +++ b/layer/TimeInstantLayer.cpp Mon Jan 30 13:19:42 2006 +0000 @@ -58,7 +58,7 @@ } Layer::PropertyType -TimeInstantLayer::getPropertyType(const PropertyName &name) const +TimeInstantLayer::getPropertyType(const PropertyName &) const { return ValueProperty; } @@ -151,10 +151,7 @@ { if (!m_model) return SparseOneDimensionalModel::PointList(); - long startFrame = m_view->getStartFrame(); - long endFrame = m_view->getEndFrame(); - int zoomLevel = m_view->getZoomLevel(); - long frame = startFrame + x * zoomLevel; + long frame = getFrameForX(x); SparseOneDimensionalModel::PointList onPoints = m_model->getPoints(frame); @@ -172,8 +169,8 @@ if (prevPoints.empty()) { usePoints = nextPoints; - } else if (prevPoints.begin()->frame < startFrame && - !(nextPoints.begin()->frame > endFrame)) { + } else if (prevPoints.begin()->frame < m_view->getStartFrame() && + !(nextPoints.begin()->frame > m_view->getEndFrame())) { usePoints = nextPoints; } else if (nextPoints.begin()->frame - frame < frame - prevPoints.begin()->frame) { @@ -266,12 +263,10 @@ // Profiler profiler("TimeInstantLayer::paint", true); - long startFrame = m_view->getStartFrame(); - int zoomLevel = m_view->getZoomLevel(); + int x0 = rect.left(), x1 = rect.right(); - int x0 = rect.left(), x1 = rect.right(); - long frame0 = startFrame + x0 * zoomLevel; - long frame1 = startFrame + x1 * zoomLevel; + long frame0 = getFrameForX(x0); + long frame1 = getFrameForX(x1); SparseOneDimensionalModel::PointList points(m_model->getPoints (frame0, frame1)); @@ -301,21 +296,20 @@ SparseOneDimensionalModel::PointList::const_iterator j = i; ++j; - int x = (p.frame - startFrame) / zoomLevel; - float w = float(m_model->getResolution()) / zoomLevel; - int iw = w; + int x = getXForFrame(p.frame); + int iw = getXForFrame(p.frame + m_model->getResolution()) - x; if (iw < 2) { if (iw < 1) { iw = 2; if (j != points.end()) { - int nx = ((*j).frame - startFrame) / zoomLevel; + int nx = getXForFrame(j->frame); if (nx < x + 3) iw = 1; } } else { iw = 2; } } - + if (p.frame == illuminateFrame) { paint.setPen(Qt::black); //!!! } else { @@ -332,12 +326,12 @@ bool good = true; if (j != points.end()) { - int nx = (j->frame - startFrame) / zoomLevel; - if (nx >= x && nx - x - w - 3 <= lw) good = false; + int nx = getXForFrame(j->frame); + if (nx >= x && nx - x - iw - 3 <= lw) good = false; } if (good) { - paint.drawText(x + w + 2, + paint.drawText(x + iw + 2, m_view->height() - paint.fontMetrics().height(), p.label); } @@ -352,7 +346,7 @@ if (!m_model) return; - long frame = e->x() * m_view->getZoomLevel() + m_view->getStartFrame(); + long frame = getFrameForX(e->x()); if (frame < 0) frame = 0; m_editingPoint = SparseOneDimensionalModel::Point(frame, tr("New Point")); m_model->addPoint(m_editingPoint); @@ -366,7 +360,7 @@ if (!m_model || !m_editing) return; - long frame = e->x() * m_view->getZoomLevel() + m_view->getStartFrame(); + long frame = getFrameForX(e->x()); if (frame < 0) frame = 0; m_model->deletePoint(m_editingPoint); m_editingPoint.frame = frame; @@ -402,7 +396,7 @@ if (!m_model || !m_editing) return; - long frame = e->x() * m_view->getZoomLevel() + m_view->getStartFrame(); + long frame = getFrameForX(e->x()); if (frame < 0) frame = 0; m_model->deletePoint(m_editingPoint); m_editingPoint.frame = frame;
--- a/layer/TimeValueLayer.cpp Fri Jan 27 18:04:07 2006 +0000 +++ b/layer/TimeValueLayer.cpp Mon Jan 30 13:19:42 2006 +0000 @@ -188,10 +188,7 @@ { if (!m_model) return SparseTimeValueModel::PointList(); - long startFrame = m_view->getStartFrame(); - long endFrame = m_view->getEndFrame(); - int zoomLevel = m_view->getZoomLevel(); - long frame = startFrame + x * zoomLevel; + long frame = getFrameForX(x); SparseTimeValueModel::PointList onPoints = m_model->getPoints(frame); @@ -209,8 +206,8 @@ if (prevPoints.empty()) { usePoints = nextPoints; - } else if (prevPoints.begin()->frame < startFrame && - !(nextPoints.begin()->frame > endFrame)) { + } else if (prevPoints.begin()->frame < m_view->getStartFrame() && + !(nextPoints.begin()->frame > m_view->getEndFrame())) { usePoints = nextPoints; } else if (nextPoints.begin()->frame - frame < frame - prevPoints.begin()->frame) { @@ -310,12 +307,9 @@ // Profiler profiler("TimeValueLayer::paint", true); - long startFrame = m_view->getStartFrame(); - int zoomLevel = m_view->getZoomLevel(); - int x0 = rect.left(), x1 = rect.right(); - long frame0 = startFrame + x0 * zoomLevel; - long frame1 = startFrame + x1 * zoomLevel; + long frame0 = getFrameForX(x0); + long frame1 = getFrameForX(x1); SparseTimeValueModel::PointList points(m_model->getPoints (frame0, frame1)); @@ -346,7 +340,9 @@ if (!localPoints.empty()) illuminateFrame = localPoints.begin()->frame; } - int w = m_model->getResolution() / zoomLevel; + int w = + getXForFrame(frame0 + m_model->getResolution()) - + getXForFrame(frame0); paint.save(); @@ -362,7 +358,7 @@ const SparseTimeValueModel::Point &p(*i); - int x = (p.frame - startFrame) / zoomLevel; + int x = getXForFrame(p.frame); int y = int(nearbyint(m_view->height() - ((p.value - min) * m_view->height()) / (max - min))); @@ -419,7 +415,7 @@ if (j != points.end()) { const SparseTimeValueModel::Point &q(*j); - int nx = (q.frame - startFrame) / zoomLevel; + int nx = getXForFrame(q.frame); int ny = int(nearbyint(m_view->height() - ((q.value - min) * m_view->height()) / (max - min)));
--- a/widgets/Pane.cpp Fri Jan 27 18:04:07 2006 +0000 +++ b/widgets/Pane.cpp Mon Jan 30 13:19:42 2006 +0000 @@ -247,17 +247,17 @@ if (!m_manager) return Selection(); - long testFrame = (x - 5) * m_zoomLevel + getStartFrame(); + long testFrame = getFrameForX(x - 5); if (testFrame < 0) { - testFrame = x * m_zoomLevel + getStartFrame(); + testFrame = getFrameForX(x); if (testFrame < 0) return Selection(); } Selection selection = m_manager->getContainingSelection(testFrame, true); if (selection.isEmpty()) return selection; - int lx = (int(selection.getStartFrame()) - getStartFrame()) / m_zoomLevel; - int rx = (int(selection.getEndFrame()) - getStartFrame()) / m_zoomLevel; + int lx = getXForFrame(selection.getStartFrame()); + int rx = getXForFrame(selection.getEndFrame()); int fuzz = 2; if (x < lx - fuzz || x > rx + fuzz) return Selection(); @@ -315,7 +315,7 @@ } else { - int mouseFrame = e->x() * m_zoomLevel + getStartFrame(); + int mouseFrame = getFrameForX(e->x()); size_t resolution = 1; int snapFrame = mouseFrame; @@ -381,10 +381,11 @@ int x1 = std::max(m_clickPos.x(), m_mousePos.x()); int w = x1 - x0; - long newStartFrame = getStartFrame() + m_zoomLevel * x0; + long newStartFrame = getFrameForX(x0); - if (newStartFrame <= -long(width() * m_zoomLevel)) { - newStartFrame = -long(width() * m_zoomLevel) + 1; + long visibleFrames = getEndFrame() - getStartFrame(); + if (newStartFrame <= -visibleFrames) { + newStartFrame = -visibleFrames + 1; } if (newStartFrame >= long(getModelsEndFrame())) { @@ -492,9 +493,8 @@ } else { - long xoff = int(e->x()) - int(m_clickPos.x()); - long frameOff = xoff * m_zoomLevel; - + long frameOff = getFrameForX(e->x()) - getFrameForX(m_clickPos.x()); + size_t newCentreFrame = m_dragCentreFrame; if (frameOff < 0) { @@ -509,16 +509,15 @@ newCentreFrame = getModelsEndFrame(); if (newCentreFrame > 0) --newCentreFrame; } - - if (std::max(m_centreFrame, newCentreFrame) - - std::min(m_centreFrame, newCentreFrame) > size_t(m_zoomLevel)) { + + if (getXForFrame(m_centreFrame) != getXForFrame(newCentreFrame)) { setCentreFrame(newCentreFrame); } } } else if (mode == ViewManager::SelectMode) { - int mouseFrame = e->x() * m_zoomLevel + getStartFrame(); + int mouseFrame = getFrameForX(e->x()); size_t resolution = 1; int snapFrameLeft = mouseFrame; int snapFrameRight = mouseFrame; @@ -626,6 +625,8 @@ if (e->modifiers() & Qt::ControlModifier) { + // Scroll left or right, rapidly + if (getStartFrame() < 0 && getEndFrame() >= getModelsEndFrame()) return; @@ -641,6 +642,8 @@ } else { + // Zoom in or out + int newZoomLevel = m_zoomLevel; while (count > 0) {