changeset 44:ad214997dddb

* Refactor Layer classes so as no longer to store a single View pointer; instead they need to be able to draw themselves on any View on demand. Layers with caches (e.g. spectrogram) will need to be further refactored so as to maintain a per-View cache * Begin refactoring MainWindow by pulling out the document stuff (set of layers, models etc) into a Document class. Not yet in use. This revision is fairly unstable.
author Chris Cannam
date Thu, 02 Mar 2006 16:58:49 +0000
parents 78515b1e29eb
children 25a2915d351d
files layer/Colour3DPlotLayer.cpp layer/Colour3DPlotLayer.h layer/LayerFactory.cpp layer/LayerFactory.h layer/NoteLayer.cpp layer/NoteLayer.h layer/SpectrogramLayer.cpp layer/SpectrogramLayer.h layer/TextLayer.cpp layer/TextLayer.h layer/TimeInstantLayer.cpp layer/TimeInstantLayer.h layer/TimeRulerLayer.cpp layer/TimeRulerLayer.h layer/TimeValueLayer.cpp layer/TimeValueLayer.h layer/WaveformLayer.cpp layer/WaveformLayer.h widgets/LayerTree.cpp widgets/Pane.cpp widgets/Pane.h widgets/PropertyBox.cpp
diffstat 22 files changed, 494 insertions(+), 530 deletions(-) [+]
line wrap: on
line diff
--- a/layer/Colour3DPlotLayer.cpp	Wed Mar 01 18:13:01 2006 +0000
+++ b/layer/Colour3DPlotLayer.cpp	Thu Mar 02 16:58:49 2006 +0000
@@ -21,12 +21,12 @@
 #include <cassert>
 
 
-Colour3DPlotLayer::Colour3DPlotLayer(View *w) :
-    Layer(w),
+Colour3DPlotLayer::Colour3DPlotLayer() :
+    Layer(),
     m_model(0),
     m_cache(0)
 {
-    m_view->addLayer(this);
+    
 }
 
 Colour3DPlotLayer::~Colour3DPlotLayer()
@@ -67,14 +67,14 @@
 }
 
 bool
-Colour3DPlotLayer::isLayerScrollable() const
+Colour3DPlotLayer::isLayerScrollable(const View *v) const
 {
     QPoint discard;
-    return !m_view->shouldIlluminateLocalFeatures(this, discard);
+    return !v->shouldIlluminateLocalFeatures(this, discard);
 }
 
 QString
-Colour3DPlotLayer::getFeatureDescription(QPoint &pos) const
+Colour3DPlotLayer::getFeatureDescription(View *v, QPoint &pos) const
 {
     if (!m_model) return "";
 
@@ -85,11 +85,11 @@
     size_t modelWindow = m_model->getWindowSize();
 
     int sx0 = modelWindow *
-	int((getFrameForX(x) - long(modelStart)) / long(modelWindow));
+	int((v->getFrameForX(x) - long(modelStart)) / long(modelWindow));
     int sx1 = sx0 + modelWindow;
 
-    float binHeight = float(m_view->height()) / m_model->getYBinCount();
-    int sy = (m_view->height() - y) / binHeight;
+    float binHeight = float(v->height()) / m_model->getYBinCount();
+    int sy = (v->height() - y) / binHeight;
 
     float value = m_model->getBinValue(sx0, sy);
     
@@ -109,7 +109,7 @@
 }
 
 int
-Colour3DPlotLayer::getVerticalScaleWidth(QPainter &paint) const
+Colour3DPlotLayer::getVerticalScaleWidth(View *v, QPainter &paint) const
 {
     if (!m_model) return 0;
 
@@ -129,19 +129,19 @@
 }
 
 void
-Colour3DPlotLayer::paintVerticalScale(QPainter &paint, QRect rect) const
+Colour3DPlotLayer::paintVerticalScale(View *v, QPainter &paint, QRect rect) const
 {
     if (!m_model) return;
 
     int h = rect.height(), w = rect.width();
-    float binHeight = float(m_view->height()) / m_model->getYBinCount();
+    float binHeight = float(v->height()) / m_model->getYBinCount();
 
 //    int textHeight = paint.fontMetrics().height();
 //    int toff = -textHeight + paint.fontMetrics().ascent() + 2;
 
     for (size_t i = 0; i < m_model->getYBinCount(); ++i) {
 
-	int y0 = m_view->height() - (i * binHeight) - 1;
+	int y0 = v->height() - (i * binHeight) - 1;
 	
 	QString text = m_model->getBinName(i);
 	if (text == "") text = QString("[%1]").arg(i + 1);
@@ -157,10 +157,10 @@
 }
 
 void
-Colour3DPlotLayer::paint(QPainter &paint, QRect rect) const
+Colour3DPlotLayer::paint(View *v, QPainter &paint, QRect rect) const
 {
 //    Profiler profiler("Colour3DPlotLayer::paint");
-//    std::cerr << "Colour3DPlotLayer::paint(): m_model is " << m_model << ", zoom level is " << m_view->getZoomLevel() << std::endl;
+//    std::cerr << "Colour3DPlotLayer::paint(): m_model is " << m_model << ", zoom level is " << v->getZoomLevel() << std::endl;
 
     //!!! This doesn't yet accommodate the fact that the model may
     //have a different sample rate from an underlying model.  At the
@@ -176,14 +176,14 @@
     int completion = 0;
     if (!m_model || !m_model->isOK() || !m_model->isReady(&completion)) {
 	if (completion > 0) {
-	    paint.fillRect(0, 10, m_view->width() * completion / 100,
+	    paint.fillRect(0, 10, v->width() * completion / 100,
 			   10, QColor(120, 120, 120));
 	}
 	return;
     }
 
-    long startFrame = m_view->getStartFrame();
-    int zoomLevel = m_view->getZoomLevel();
+    long startFrame = v->getStartFrame();
+    int zoomLevel = v->getZoomLevel();
 
     size_t modelStart = m_model->getStartFrame();
     size_t modelEnd = m_model->getEndFrame();
@@ -261,7 +261,7 @@
 //    int y0 = rect.top();
 //    int y1 = rect.bottom();
     int w = x1 - x0;
-    int h = m_view->height();
+    int h = v->height();
 
     // The cache is from the model's start frame to the model's end
     // frame at the model's window increment frames per pixel.  We
@@ -273,8 +273,8 @@
     //direction.  This one is only really appropriate for models with
     //far fewer bins in both directions.
 
-    int sx0 = int((getFrameForX(x0) - long(modelStart)) / long(modelWindow));
-    int sx1 = int((getFrameForX(x1) - long(modelStart)) / long(modelWindow));
+    int sx0 = int((v->getFrameForX(x0) - long(modelStart)) / long(modelWindow));
+    int sx1 = int((v->getFrameForX(x1) - long(modelStart)) / long(modelWindow));
     int sw = sx1 - sx0;
     int sh = m_model->getYBinCount();
 
@@ -284,7 +284,7 @@
 */
 
     QPoint illuminatePos;
-    bool illuminate = m_view->shouldIlluminateLocalFeatures(this, illuminatePos);
+    bool illuminate = v->shouldIlluminateLocalFeatures(this, illuminatePos);
 
     for (int sx = sx0 - 1; sx <= sx1; ++sx) {
 
@@ -295,8 +295,8 @@
 
 	for (int sy = 0; sy < sh; ++sy) {
 
-	    int rx0 = getXForFrame(fx + int(modelStart));
-	    int rx1 = getXForFrame(fx + int(modelStart) + int(modelWindow));
+	    int rx0 = v->getXForFrame(fx + int(modelStart));
+	    int rx1 = v->getXForFrame(fx + int(modelStart) + int(modelWindow));
 
 	    int ry0 = h - (sy * h) / sh - 1;
 	    int ry1 = h - ((sy + 1) * h) / sh - 2;
@@ -375,12 +375,12 @@
 }
 
 bool
-Colour3DPlotLayer::snapToFeatureFrame(int &frame,
+Colour3DPlotLayer::snapToFeatureFrame(View *v, int &frame,
 				      size_t &resolution,
 				      SnapType snap) const
 {
     if (!m_model) {
-	return Layer::snapToFeatureFrame(frame, resolution, snap);
+	return Layer::snapToFeatureFrame(v, frame, resolution, snap);
     }
 
     resolution = m_model->getWindowSize();
--- a/layer/Colour3DPlotLayer.h	Wed Mar 01 18:13:01 2006 +0000
+++ b/layer/Colour3DPlotLayer.h	Thu Mar 02 16:58:49 2006 +0000
@@ -36,23 +36,23 @@
     Q_OBJECT
 
 public:
-    Colour3DPlotLayer(View *w);
+    Colour3DPlotLayer();
     ~Colour3DPlotLayer();
 
     virtual const ZoomConstraint *getZoomConstraint() const { return m_model; }
     virtual const Model *getModel() const { return m_model; }
-    virtual void paint(QPainter &paint, QRect rect) const;
+    virtual void paint(View *v, QPainter &paint, QRect rect) const;
 
-    virtual int getVerticalScaleWidth(QPainter &) const;
-    virtual void paintVerticalScale(QPainter &paint, QRect rect) const;
+    virtual int getVerticalScaleWidth(View *v, QPainter &) const;
+    virtual void paintVerticalScale(View *v, QPainter &paint, QRect rect) const;
 
-    virtual QString getFeatureDescription(QPoint &) const;
+    virtual QString getFeatureDescription(View *v, QPoint &) const;
 
-    virtual bool snapToFeatureFrame(int &frame, 
+    virtual bool snapToFeatureFrame(View *v, int &frame, 
 				    size_t &resolution,
 				    SnapType snap) const;
 
-    virtual bool isLayerScrollable() const;
+    virtual bool isLayerScrollable(const View *v) const;
 
     void setModel(const DenseThreeDimensionalModel *model);
 
--- a/layer/LayerFactory.cpp	Wed Mar 01 18:13:01 2006 +0000
+++ b/layer/LayerFactory.cpp	Thu Mar 02 16:58:49 2006 +0000
@@ -231,54 +231,53 @@
 }
 
 Layer *
-LayerFactory::createLayer(LayerType type, View *view,
-			  Model *model, int channel)
+LayerFactory::createLayer(LayerType type, Model *model, int channel)
 {
     Layer *layer = 0;
 
     switch (type) {
 
     case Waveform:
-	layer = new WaveformLayer(view);
+	layer = new WaveformLayer;
 	static_cast<WaveformLayer *>(layer)->setChannel(channel);
 	break;
 
     case Spectrogram:
-	layer = new SpectrogramLayer(view);
+	layer = new SpectrogramLayer;
 	static_cast<SpectrogramLayer *>(layer)->setChannel(channel);
 	break;
 
     case TimeRuler:
-	layer = new TimeRulerLayer(view);
+	layer = new TimeRulerLayer;
 	break;
 
     case TimeInstants:
-	layer = new TimeInstantLayer(view);
+	layer = new TimeInstantLayer;
 	break;
 
     case TimeValues:
-	layer = new TimeValueLayer(view);
+	layer = new TimeValueLayer;
 	break;
 
     case Notes:
-	layer = new NoteLayer(view);
+	layer = new NoteLayer;
 	break;
 
     case Text:
-	layer = new TextLayer(view);
+	layer = new TextLayer;
 	break;
 
     case Colour3DPlot:
-	layer = new Colour3DPlotLayer(view);
+	layer = new Colour3DPlotLayer;
 	break;
 
     case MelodicRangeSpectrogram: 
-	layer = new SpectrogramLayer(view, SpectrogramLayer::MelodicRange);
+	layer = new SpectrogramLayer(SpectrogramLayer::MelodicRange);
 	static_cast<SpectrogramLayer *>(layer)->setChannel(channel);
 	break;
 
     case PeakFrequencySpectrogram: 
-	layer = new SpectrogramLayer(view, SpectrogramLayer::MelodicPeaks);
+	layer = new SpectrogramLayer(SpectrogramLayer::MelodicPeaks);
 	static_cast<SpectrogramLayer *>(layer)->setChannel(channel);
 	break;
 
--- a/layer/LayerFactory.h	Wed Mar 01 18:13:01 2006 +0000
+++ b/layer/LayerFactory.h	Thu Mar 02 16:58:49 2006 +0000
@@ -14,7 +14,6 @@
 #include <set>
 
 class Layer;
-class View;
 class Model;
 
 class LayerFactory
@@ -50,8 +49,7 @@
 
     LayerType getLayerType(const Layer *);
 
-    Layer *createLayer(LayerType type, View *view,
-		       Model *model = 0, int channel = -1);
+    Layer *createLayer(LayerType type, Model *model = 0, int channel = -1);
 
     QString getLayerPresentationName(LayerType type);
 
--- a/layer/NoteLayer.cpp	Wed Mar 01 18:13:01 2006 +0000
+++ b/layer/NoteLayer.cpp	Thu Mar 02 16:58:49 2006 +0000
@@ -26,8 +26,8 @@
 #include <iostream>
 #include <cmath>
 
-NoteLayer::NoteLayer(View *w) :
-    Layer(w),
+NoteLayer::NoteLayer() :
+    Layer(),
     m_model(0),
     m_editing(false),
     m_originalPoint(0, 0.0, 0, tr("New Point")),
@@ -36,7 +36,7 @@
     m_colour(Qt::black),
     m_verticalScale(MinMaxRangeScale)
 {
-    m_view->addLayer(this);
+    
 }
 
 void
@@ -167,18 +167,18 @@
 }
 
 bool
-NoteLayer::isLayerScrollable() const
+NoteLayer::isLayerScrollable(const View *v) const
 {
     QPoint discard;
-    return !m_view->shouldIlluminateLocalFeatures(this, discard);
+    return !v->shouldIlluminateLocalFeatures(this, discard);
 }
 
 NoteModel::PointList
-NoteLayer::getLocalPoints(int x) const
+NoteLayer::getLocalPoints(View *v, int x) const
 {
     if (!m_model) return NoteModel::PointList();
 
-    long frame = getFrameForX(x);
+    long frame = v->getFrameForX(x);
 
     NoteModel::PointList onPoints =
 	m_model->getPoints(frame);
@@ -196,8 +196,8 @@
 
     if (prevPoints.empty()) {
 	usePoints = nextPoints;
-    } else if (prevPoints.begin()->frame < m_view->getStartFrame() &&
-	       !(nextPoints.begin()->frame > m_view->getEndFrame())) {
+    } else if (prevPoints.begin()->frame < v->getStartFrame() &&
+	       !(nextPoints.begin()->frame > v->getEndFrame())) {
 	usePoints = nextPoints;
     } else if (nextPoints.begin()->frame - frame <
 	       frame - prevPoints.begin()->frame) {
@@ -206,7 +206,7 @@
 
     if (!usePoints.empty()) {
 	int fuzz = 2;
-	int px = getXForFrame(usePoints.begin()->frame);
+	int px = v->getXForFrame(usePoints.begin()->frame);
 	if ((px > x && px - x > fuzz) ||
 	    (px < x && x - px > fuzz + 1)) {
 	    usePoints.clear();
@@ -217,13 +217,13 @@
 }
 
 QString
-NoteLayer::getFeatureDescription(QPoint &pos) const
+NoteLayer::getFeatureDescription(View *v, QPoint &pos) const
 {
     int x = pos.x();
 
     if (!m_model || !m_model->getSampleRate()) return "";
 
-    NoteModel::PointList points = getLocalPoints(x);
+    NoteModel::PointList points = getLocalPoints(v, x);
 
     if (points.empty()) {
 	if (!m_model->isReady()) {
@@ -238,11 +238,11 @@
 
     for (i = points.begin(); i != points.end(); ++i) {
 
-	int y = getYForValue(i->value);
+	int y = getYForValue(v, i->value);
 	int h = 3;
 
 	if (m_model->getValueQuantization() != 0.0) {
-	    h = y - getYForValue(i->value + m_model->getValueQuantization());
+	    h = y - getYForValue(v, i->value + m_model->getValueQuantization());
 	    if (h < 3) h = 3;
 	}
 
@@ -274,18 +274,18 @@
 	    .arg(note.label);
     }
 
-    pos = QPoint(getXForFrame(note.frame),
-		 getYForValue(note.value));
+    pos = QPoint(v->getXForFrame(note.frame),
+		 getYForValue(v, note.value));
     return text;
 }
 
 bool
-NoteLayer::snapToFeatureFrame(int &frame,
-				   size_t &resolution,
-				   SnapType snap) const
+NoteLayer::snapToFeatureFrame(View *v, int &frame,
+			      size_t &resolution,
+			      SnapType snap) const
 {
     if (!m_model) {
-	return Layer::snapToFeatureFrame(frame, resolution, snap);
+	return Layer::snapToFeatureFrame(v, frame, resolution, snap);
     }
 
     resolution = m_model->getResolution();
@@ -293,7 +293,7 @@
 
     if (snap == SnapNeighbouring) {
 	
-	points = getLocalPoints(getXForFrame(frame));
+	points = getLocalPoints(v, v->getXForFrame(frame));
 	if (points.empty()) return false;
 	frame = points.begin()->frame;
 	return true;
@@ -352,9 +352,9 @@
 }
 
 int
-NoteLayer::getYForValue(float value) const
+NoteLayer::getYForValue(View *v, float value) const
 {
-    float min, max, h = m_view->height();
+    float min, max, h = v->height();
 
     switch (m_verticalScale) {
 
@@ -375,11 +375,11 @@
 
 	// If we have a spectrogram layer on the same view as us, align
 	// ourselves with it...
-	for (int i = 0; i < m_view->getLayerCount(); ++i) {
+	for (int i = 0; i < v->getLayerCount(); ++i) {
 	    SpectrogramLayer *spectrogram = dynamic_cast<SpectrogramLayer *>
-		(m_view->getLayer(i));
+		(v->getLayer(i));
 	    if (spectrogram) {
-		return spectrogram->getYForFrequency(value);
+		return spectrogram->getYForFrequency(v, value);
 	    }
 	}
 
@@ -400,19 +400,19 @@
 }
 
 float
-NoteLayer::getValueForY(int y) const
+NoteLayer::getValueForY(View *v, int y) const
 {
     float min = m_model->getValueMinimum();
     float max = m_model->getValueMaximum();
     if (max == min) max = min + 1.0;
 
-    int h = m_view->height();
+    int h = v->height();
 
     return min + (float(h - y) * float(max - min)) / h;
 }
 
 void
-NoteLayer::paint(QPainter &paint, QRect rect) const
+NoteLayer::paint(View *v, QPainter &paint, QRect rect) const
 {
     if (!m_model || !m_model->isOK()) return;
 
@@ -422,8 +422,8 @@
 //    Profiler profiler("NoteLayer::paint", true);
 
     int x0 = rect.left(), x1 = rect.right();
-    long frame0 = getFrameForX(x0);
-    long frame1 = getFrameForX(x1);
+    long frame0 = v->getFrameForX(x0);
+    long frame1 = v->getFrameForX(x1);
 
     NoteModel::PointList points(m_model->getPoints(frame0, frame1));
     if (points.empty()) return;
@@ -440,15 +440,15 @@
     float max = m_model->getValueMaximum();
     if (max == min) max = min + 1.0;
 
-    int origin = int(nearbyint(m_view->height() -
-			       (-min * m_view->height()) / (max - min)));
+    int origin = int(nearbyint(v->height() -
+			       (-min * v->height()) / (max - min)));
 
     QPoint localPos;
     long illuminateFrame = -1;
 
-    if (m_view->shouldIlluminateLocalFeatures(this, localPos)) {
+    if (v->shouldIlluminateLocalFeatures(this, localPos)) {
 	NoteModel::PointList localPoints =
-	    getLocalPoints(localPos.x());
+	    getLocalPoints(v, localPos.x());
 	if (!localPoints.empty()) illuminateFrame = localPoints.begin()->frame;
     }
 
@@ -460,13 +460,13 @@
 
 	const NoteModel::Point &p(*i);
 
-	int x = getXForFrame(p.frame);
-	int y = getYForValue(p.value);
-	int w = getXForFrame(p.frame + p.duration) - x;
+	int x = v->getXForFrame(p.frame);
+	int y = getYForValue(v, p.value);
+	int w = v->getXForFrame(p.frame + p.duration) - x;
 	int h = 3;
 	
 	if (m_model->getValueQuantization() != 0.0) {
-	    h = y - getYForValue(p.value + m_model->getValueQuantization());
+	    h = y - getYForValue(v, p.value + m_model->getValueQuantization());
 	    if (h < 3) h = 3;
 	}
 
@@ -492,17 +492,17 @@
 }
 
 void
-NoteLayer::drawStart(QMouseEvent *e)
+NoteLayer::drawStart(View *v, QMouseEvent *e)
 {
     std::cerr << "NoteLayer::drawStart(" << e->x() << "," << e->y() << ")" << std::endl;
 
     if (!m_model) return;
 
-    long frame = getFrameForX(e->x());
+    long frame = v->getFrameForX(e->x());
     if (frame < 0) frame = 0;
     frame = frame / m_model->getResolution() * m_model->getResolution();
 
-    float value = getValueForY(e->y());
+    float value = getValueForY(v, e->y());
 
     m_editingPoint = NoteModel::Point(frame, value, 0, tr("New Point"));
     m_originalPoint = m_editingPoint;
@@ -516,17 +516,17 @@
 }
 
 void
-NoteLayer::drawDrag(QMouseEvent *e)
+NoteLayer::drawDrag(View *v, QMouseEvent *e)
 {
     std::cerr << "NoteLayer::drawDrag(" << e->x() << "," << e->y() << ")" << std::endl;
 
     if (!m_model || !m_editing) return;
 
-    long frame = getFrameForX(e->x());
+    long frame = v->getFrameForX(e->x());
     if (frame < 0) frame = 0;
     frame = frame / m_model->getResolution() * m_model->getResolution();
 
-    float value = getValueForY(e->y());
+    float value = getValueForY(v, e->y());
 
     m_editingCommand->deletePoint(m_editingPoint);
     m_editingPoint.frame = frame;
@@ -535,7 +535,7 @@
 }
 
 void
-NoteLayer::drawEnd(QMouseEvent *e)
+NoteLayer::drawEnd(View *v, QMouseEvent *e)
 {
     std::cerr << "NoteLayer::drawEnd(" << e->x() << "," << e->y() << ")" << std::endl;
     if (!m_model || !m_editing) return;
@@ -545,13 +545,13 @@
 }
 
 void
-NoteLayer::editStart(QMouseEvent *e)
+NoteLayer::editStart(View *v, QMouseEvent *e)
 {
     std::cerr << "NoteLayer::editStart(" << e->x() << "," << e->y() << ")" << std::endl;
 
     if (!m_model) return;
 
-    NoteModel::PointList points = getLocalPoints(e->x());
+    NoteModel::PointList points = getLocalPoints(v, e->x());
     if (points.empty()) return;
 
     m_editingPoint = *points.begin();
@@ -566,17 +566,17 @@
 }
 
 void
-NoteLayer::editDrag(QMouseEvent *e)
+NoteLayer::editDrag(View *v, QMouseEvent *e)
 {
     std::cerr << "NoteLayer::editDrag(" << e->x() << "," << e->y() << ")" << std::endl;
 
     if (!m_model || !m_editing) return;
 
-    long frame = getFrameForX(e->x());
+    long frame = v->getFrameForX(e->x());
     if (frame < 0) frame = 0;
     frame = frame / m_model->getResolution() * m_model->getResolution();
 
-    float value = getValueForY(e->y());
+    float value = getValueForY(v, e->y());
 
     if (!m_editingCommand) {
 	m_editingCommand = new NoteModel::EditCommand(m_model,
@@ -590,7 +590,7 @@
 }
 
 void
-NoteLayer::editEnd(QMouseEvent *e)
+NoteLayer::editEnd(View *v, QMouseEvent *e)
 {
     std::cerr << "NoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << std::endl;
     if (!m_model || !m_editing) return;
--- a/layer/NoteLayer.h	Wed Mar 01 18:13:01 2006 +0000
+++ b/layer/NoteLayer.h	Thu Mar 02 16:58:49 2006 +0000
@@ -24,23 +24,23 @@
     Q_OBJECT
 
 public:
-    NoteLayer(View *w);
+    NoteLayer();
 
-    virtual void paint(QPainter &paint, QRect rect) const;
+    virtual void paint(View *v, QPainter &paint, QRect rect) const;
 
-    virtual QString getFeatureDescription(QPoint &) const;
+    virtual QString getFeatureDescription(View *v, QPoint &) const;
 
-    virtual bool snapToFeatureFrame(int &frame,
+    virtual bool snapToFeatureFrame(View *v, int &frame,
 				    size_t &resolution,
 				    SnapType snap) const;
 
-    virtual void drawStart(QMouseEvent *);
-    virtual void drawDrag(QMouseEvent *);
-    virtual void drawEnd(QMouseEvent *);
+    virtual void drawStart(View *v, QMouseEvent *);
+    virtual void drawDrag(View *v, QMouseEvent *);
+    virtual void drawEnd(View *v, QMouseEvent *);
 
-    virtual void editStart(QMouseEvent *);
-    virtual void editDrag(QMouseEvent *);
-    virtual void editEnd(QMouseEvent *);
+    virtual void editStart(View *v, QMouseEvent *);
+    virtual void editDrag(View *v, QMouseEvent *);
+    virtual void editEnd(View *v, QMouseEvent *);
 
     virtual void moveSelection(Selection s, size_t newStartFrame);
     virtual void resizeSelection(Selection s, Selection newSize);
@@ -68,7 +68,7 @@
     void setVerticalScale(VerticalScale scale);
     VerticalScale getVerticalScale() const { return m_verticalScale; }
 
-    virtual bool isLayerScrollable() const;
+    virtual bool isLayerScrollable(const View *v) const;
 
     virtual bool isLayerEditable() const { return true; }
 
@@ -80,10 +80,10 @@
     void setProperties(const QXmlAttributes &attributes);
 
 protected:
-    int getYForValue(float value) const;
-    float getValueForY(int y) const;
+    int getYForValue(View *v, float value) const;
+    float getValueForY(View *v, int y) const;
 
-    NoteModel::PointList getLocalPoints(int) const;
+    NoteModel::PointList getLocalPoints(View *v, int) const;
 
     NoteModel *m_model;
     bool m_editing;
--- a/layer/SpectrogramLayer.cpp	Wed Mar 01 18:13:01 2006 +0000
+++ b/layer/SpectrogramLayer.cpp	Thu Mar 02 16:58:49 2006 +0000
@@ -31,8 +31,8 @@
 //#define DEBUG_SPECTROGRAM_REPAINT 1
 
 
-SpectrogramLayer::SpectrogramLayer(View *w, Configuration config) :
-    Layer(w),
+SpectrogramLayer::SpectrogramLayer(Configuration config) :
+    Layer(),
     m_model(0),
     m_channel(0),
     m_windowSize(1024),
@@ -54,6 +54,7 @@
     m_pixmapCacheInvalid(true),
     m_fillThread(0),
     m_updateTimer(0),
+    m_candidateFillStartFrame(0),
     m_lastFillExtent(0),
     m_exiting(false)
 {
@@ -74,9 +75,6 @@
 	setBinDisplay(PeakFrequencies);
 	setNormalizeColumns(true);
     }
-
-    if (m_view) m_view->setLightBackground(false);
-    m_view->addLayer(this);
 }
 
 SpectrogramLayer::~SpectrogramLayer()
@@ -414,7 +412,7 @@
     } else if (name == tr("Colour Rotation")) {
 	setColourRotation(value);
     } else if (name == tr("Colour")) {
-	if (m_view) m_view->setLightBackground(value == 2);
+//!!!	if (v) v->setLightBackground(value == 2);
 	switch (value) {
 	default:
 	case 0:	setColourScheme(DefaultColours); break;
@@ -800,7 +798,7 @@
 }
 
 void
-SpectrogramLayer::setLayerDormant(bool dormant)
+SpectrogramLayer::setLayerDormant(const bool dormant)
 {
     if (dormant == m_dormant) return;
 
@@ -893,16 +891,16 @@
 		m_lastFillExtent = fillExtent;
 	    }
 	} else {
-	    if (m_view) {
+//	    if (v) {
 		size_t sf = 0;
-		if (m_view->getStartFrame() > 0) sf = m_view->getStartFrame();
+//!!!		if (v->getStartFrame() > 0) sf = v->getStartFrame();
 #ifdef DEBUG_SPECTROGRAM_REPAINT
 		std::cerr << "SpectrogramLayer: going backwards, emitting modelChanged("
-			  << sf << "," << m_view->getEndFrame() << ")" << std::endl;
+			  << sf << "," << m_model->getEndFrame() << ")" << std::endl;
 #endif
-		emit modelChanged(sf, m_view->getEndFrame());
+		emit modelChanged(sf, m_model->getEndFrame());
 		m_pixmapCacheInvalid = true;
-	    }
+//	    }
 	    m_lastFillExtent = fillExtent;
 	}
     }
@@ -1197,7 +1195,7 @@
 
 SpectrogramLayer::Cache::~Cache()
 {
-    for (size_t i = 0; i < m_height; ++i) {
+    for (size_t i = 0; i < m_width; ++i) {
 	if (m_magnitude && m_magnitude[i]) free(m_magnitude[i]);
 	if (m_phase && m_phase[i]) free(m_phase[i]);
     }
@@ -1228,24 +1226,24 @@
 void
 SpectrogramLayer::Cache::resize(uint16_t **&array, size_t width, size_t height)
 {
-    for (size_t i = height; i < m_height; ++i) {
+    for (size_t i = width; i < m_width; ++i) {
 	free(array[i]);
     }
 
-    if (height != m_height) {
-	array = (uint16_t **)realloc(array, height * sizeof(uint16_t *));
+    if (width != m_width) {
+	array = (uint16_t **)realloc(array, width * sizeof(uint16_t *));
 	if (!array) throw std::bad_alloc();
-	MUNLOCK(array, height * sizeof(uint16_t *));
+	MUNLOCK(array, width * sizeof(uint16_t *));
     }
 
-    for (size_t i = m_height; i < height; ++i) {
+    for (size_t i = m_width; i < width; ++i) {
 	array[i] = 0;
     }
 
-    for (size_t i = 0; i < height; ++i) {
-	array[i] = (uint16_t *)realloc(array[i], width * sizeof(uint16_t));
+    for (size_t i = 0; i < width; ++i) {
+	array[i] = (uint16_t *)realloc(array[i], height * sizeof(uint16_t));
 	if (!array[i]) throw std::bad_alloc();
-	MUNLOCK(array[i], width * sizeof(uint16_t));
+	MUNLOCK(array[i], height * sizeof(uint16_t));
     }
 }
 
@@ -1254,8 +1252,8 @@
 {
     for (size_t x = 0; x < m_width; ++x) {
 	for (size_t y = 0; y < m_height; ++y) {
-	    m_magnitude[y][x] = 0;
-	    m_phase[y][x] = 0;
+	    m_magnitude[x][y] = 0;
+	    m_phase[x][y] = 0;
 	}
 	m_factor[x] = 1.0;
     }
@@ -1304,19 +1302,8 @@
 	    size_t windowSize = m_layer.m_windowSize;
 	    size_t windowIncrement = m_layer.getWindowIncrement();
 
-	    size_t visibleStart = start;
-	    size_t visibleEnd = end;
-
-	    if (m_layer.m_view) {
-		if (m_layer.m_view->getStartFrame() < 0) {
-		    visibleStart = 0;
-		} else {
-		    visibleStart = m_layer.m_view->getStartFrame();
-		    visibleStart = (visibleStart / windowIncrement) *
-			windowIncrement;
-		}
-		visibleEnd = m_layer.m_view->getEndFrame();
-	    }
+	    size_t visibleStart = m_layer.m_candidateFillStartFrame;
+	    visibleStart = (visibleStart / windowIncrement) * windowIncrement;
 
 	    size_t width = (end - start) / windowIncrement + 1;
 	    size_t height = windowSize / 2;
@@ -1363,39 +1350,11 @@
 	    int updateAt = (end / windowIncrement) / 20;
 	    if (updateAt < 100) updateAt = 100;
 
-	    bool doVisibleFirst = (visibleStart != start && visibleEnd != end);
+	    bool doVisibleFirst = (visibleStart != start);
 
 	    if (doVisibleFirst) {
 
-		for (size_t f = visibleStart; f < visibleEnd; f += windowIncrement) {
-	    
-		    m_layer.fillCacheColumn(int((f - start) / windowIncrement),
-					    input, output, plan,
-					    windowSize, windowIncrement,
-					    windower);
-
-		    if (m_layer.m_cacheInvalid || m_layer.m_exiting) {
-			interrupted = true;
-			m_fillExtent = 0;
-			break;
-		    }
-
-		    if (++counter == updateAt ||
-			(f >= visibleEnd - 1 && f < visibleEnd + windowIncrement)) {
-			if (f < end) m_fillExtent = f;
-			m_fillCompletion = size_t(100 * fabsf(float(f - visibleStart) /
-							      float(end - start)));
-			counter = 0;
-		    }
-		}
-
-		std::cerr << "SpectrogramLayer::CacheFillThread::run: visible bit done" << std::endl;
-		m_layer.m_view->update();
-	    }
-
-	    if (!interrupted && doVisibleFirst) {
-		
-		for (size_t f = visibleEnd; f < end; f += windowIncrement) {
+		for (size_t f = visibleStart; f < end; f += windowIncrement) {
 	    
 		    m_layer.fillCacheColumn(int((f - start) / windowIncrement),
 					    input, output, plan,
@@ -1440,8 +1399,7 @@
 			break;
 		    }
 		    
-		    if (++counter == updateAt ||
-			(f >= visibleEnd - 1 && f < visibleEnd + windowIncrement)) {
+		    if (++counter == updateAt) {
 			m_fillExtent = f;
 			m_fillCompletion = baseCompletion +
 			    size_t(100 * fabsf(float(f - start) /
@@ -1498,9 +1456,9 @@
 }
 
 bool
-SpectrogramLayer::getYBinRange(int y, float &q0, float &q1) const
+SpectrogramLayer::getYBinRange(View *v, int y, float &q0, float &q1) const
 {
-    int h = m_view->height();
+    int h = v->height();
     if (y < 0 || y >= h) return false;
 
     int sr = m_model->getSampleRate();
@@ -1509,8 +1467,8 @@
 
     bool logarithmic = (m_frequencyScale == LogFrequencyScale);
 
-    q0 = m_view->getFrequencyForY(y, minf, maxf, logarithmic);
-    q1 = m_view->getFrequencyForY(y - 1, minf, maxf, logarithmic);
+    q0 = v->getFrequencyForY(y, minf, maxf, logarithmic);
+    q1 = v->getFrequencyForY(y - 1, minf, maxf, logarithmic);
 
     // Now map these on to actual bins
 
@@ -1528,14 +1486,14 @@
 }
     
 bool
-SpectrogramLayer::getXBinRange(int x, float &s0, float &s1) const
+SpectrogramLayer::getXBinRange(View *v, int x, float &s0, float &s1) const
 {
     size_t modelStart = m_model->getStartFrame();
     size_t 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 = v->getFrameForX(x) - modelStart;
+    int f1 = v->getFrameForX(x + 1) - modelStart - 1;
 
     if (f1 < int(modelStart) || f0 > int(modelEnd)) {
 	return false;
@@ -1552,10 +1510,10 @@
 }
  
 bool
-SpectrogramLayer::getXBinSourceRange(int x, RealTime &min, RealTime &max) const
+SpectrogramLayer::getXBinSourceRange(View *v, int x, RealTime &min, RealTime &max) const
 {
     float s0 = 0, s1 = 0;
-    if (!getXBinRange(x, s0, s1)) return false;
+    if (!getXBinRange(v, x, s0, s1)) return false;
     
     int s0i = int(s0 + 0.001);
     int s1i = int(s1);
@@ -1571,11 +1529,11 @@
 }
 
 bool
-SpectrogramLayer::getYBinSourceRange(int y, float &freqMin, float &freqMax)
+SpectrogramLayer::getYBinSourceRange(View *v, int y, float &freqMin, float &freqMax)
 const
 {
     float q0 = 0, q1 = 0;
-    if (!getYBinRange(y, q0, q1)) return false;
+    if (!getYBinRange(v, y, q0, q1)) return false;
 
     int q0i = int(q0 + 0.001);
     int q1i = int(q1);
@@ -1591,16 +1549,16 @@
 }
 
 bool
-SpectrogramLayer::getAdjustedYBinSourceRange(int x, int y,
+SpectrogramLayer::getAdjustedYBinSourceRange(View *v, int x, int y,
 					     float &freqMin, float &freqMax,
 					     float &adjFreqMin, float &adjFreqMax)
 const
 {
     float s0 = 0, s1 = 0;
-    if (!getXBinRange(x, s0, s1)) return false;
+    if (!getXBinRange(v, x, s0, s1)) return false;
 
     float q0 = 0, q1 = 0;
-    if (!getYBinRange(y, q0, q1)) return false;
+    if (!getYBinRange(v, y, q0, q1)) return false;
 
     int s0i = int(s0 + 0.001);
     int s1i = int(s1);
@@ -1661,15 +1619,15 @@
 }
     
 bool
-SpectrogramLayer::getXYBinSourceRange(int x, int y,
+SpectrogramLayer::getXYBinSourceRange(View *v, int x, int y,
 				      float &min, float &max,
 				      float &phaseMin, float &phaseMax) const
 {
     float q0 = 0, q1 = 0;
-    if (!getYBinRange(y, q0, q1)) return false;
+    if (!getYBinRange(v, y, q0, q1)) return false;
 
     float s0 = 0, s1 = 0;
-    if (!getXBinRange(x, s0, s1)) return false;
+    if (!getXBinRange(v, x, s0, s1)) return false;
     
     int q0i = int(q0 + 0.001);
     int q1i = int(q1);
@@ -1722,13 +1680,15 @@
 }
    
 void
-SpectrogramLayer::paint(QPainter &paint, QRect rect) const
+SpectrogramLayer::paint(View *v, QPainter &paint, QRect rect) const
 {
 //    Profiler profiler("SpectrogramLayer::paint", true);
 #ifdef DEBUG_SPECTROGRAM_REPAINT
-    std::cerr << "SpectrogramLayer::paint(): m_model is " << m_model << ", zoom level is " << m_view->getZoomLevel() << ", m_updateTimer " << m_updateTimer << ", pixmap cache invalid " << m_pixmapCacheInvalid << std::endl;
+    std::cerr << "SpectrogramLayer::paint(): m_model is " << m_model << ", zoom level is " << v->getZoomLevel() << ", m_updateTimer " << m_updateTimer << ", pixmap cache invalid " << m_pixmapCacheInvalid << std::endl;
 #endif
 
+    m_candidateFillStartFrame = v->getStartFrame();
+
     if (!m_model || !m_model->isOK() || !m_model->isReady()) {
 	return;
     }
@@ -1762,13 +1722,13 @@
     std::cerr << "SpectrogramLayer::paint(): Still cacheing = " << stillCacheing << std::endl;
 #endif
 
-    long startFrame = m_view->getStartFrame();
-    int zoomLevel = m_view->getZoomLevel();
+    long startFrame = v->getStartFrame();
+    int zoomLevel = v->getZoomLevel();
 
     int x0 = 0;
-    int x1 = m_view->width();
+    int x1 = v->width();
     int y0 = 0;
-    int y1 = m_view->height();
+    int y1 = v->height();
 
     bool recreateWholePixmapCache = true;
 
@@ -1780,11 +1740,11 @@
 	//make it optional)
 
 	if (int(m_pixmapCacheZoomLevel) == zoomLevel &&
-	    m_pixmapCache->width() == m_view->width() &&
-	    m_pixmapCache->height() == m_view->height()) {
-
-	    if (getXForFrame(m_pixmapCacheStartFrame) ==
-		getXForFrame(startFrame)) {
+	    m_pixmapCache->width() == v->width() &&
+	    m_pixmapCache->height() == v->height()) {
+
+	    if (v->getXForFrame(m_pixmapCacheStartFrame) ==
+		v->getXForFrame(startFrame)) {
 	    
 #ifdef DEBUG_SPECTROGRAM_REPAINT
 		std::cerr << "SpectrogramLayer: pixmap cache good" << std::endl;
@@ -1802,8 +1762,8 @@
 
 		recreateWholePixmapCache = false;
 
-		int dx = getXForFrame(m_pixmapCacheStartFrame) -
-		         getXForFrame(startFrame);
+		int dx = v->getXForFrame(m_pixmapCacheStartFrame) -
+		         v->getXForFrame(startFrame);
 
 #ifdef DEBUG_SPECTROGRAM_REPAINT
 		std::cerr << "SpectrogramLayer: dx = " << dx << " (pixmap cache " << m_pixmapCache->width() << "x" << m_pixmapCache->height() << ")" << std::endl;
@@ -1914,7 +1874,7 @@
 
 	float s0 = 0, s1 = 0;
 
-	if (!getXBinRange(x0 + x, s0, s1)) {
+	if (!getXBinRange(v, x0 + x, s0, s1)) {
 	    assert(x <= scaled.width());
 	    m_mutex.unlock();
 	    continue;
@@ -1932,8 +1892,8 @@
 
 	    if (m_binDisplay != PeakFrequencies ||
 		s1i >= int(m_cache->getWidth())) {
-		y0 = m_view->getYForFrequency(f1, minFreq, maxFreq, logarithmic);
-		y1 = m_view->getYForFrequency(f0, minFreq, maxFreq, logarithmic);
+		y0 = v->getYForFrequency(f1, minFreq, maxFreq, logarithmic);
+		y1 = v->getYForFrequency(f0, minFreq, maxFreq, logarithmic);
 	    }
 
 	    for (int s = s0i; s <= s1i; ++s) {
@@ -1961,7 +1921,7 @@
 						 m_cache->getPhaseAt(s+1, q),
 						 steady);
 
-		    y0 = y1 = m_view->getYForFrequency
+		    y0 = y1 = v->getYForFrequency
 			(f0, minFreq, maxFreq, logarithmic);
 		}
 		
@@ -2032,21 +1992,21 @@
 }
 
 float
-SpectrogramLayer::getYForFrequency(float frequency) const
+SpectrogramLayer::getYForFrequency(View *v, float frequency) const
 {
-    return m_view->getYForFrequency(frequency,
-				    getEffectiveMinFrequency(),
-				    getEffectiveMaxFrequency(),
-				    m_frequencyScale == LogFrequencyScale);
+    return v->getYForFrequency(frequency,
+			       getEffectiveMinFrequency(),
+			       getEffectiveMaxFrequency(),
+			       m_frequencyScale == LogFrequencyScale);
 }
 
 float
-SpectrogramLayer::getFrequencyForY(int y) const
+SpectrogramLayer::getFrequencyForY(View *v, int y) const
 {
-    return m_view->getFrequencyForY(y,
-				    getEffectiveMinFrequency(),
-				    getEffectiveMaxFrequency(),
-				    m_frequencyScale == LogFrequencyScale);
+    return v->getFrequencyForY(y,
+			       getEffectiveMinFrequency(),
+			       getEffectiveMaxFrequency(),
+			       m_frequencyScale == LogFrequencyScale);
 }
 
 int
@@ -2059,7 +2019,7 @@
 }
 
 bool
-SpectrogramLayer::snapToFeatureFrame(int &frame,
+SpectrogramLayer::snapToFeatureFrame(View *v, int &frame,
 				     size_t &resolution,
 				     SnapType snap) const
 {
@@ -2081,7 +2041,7 @@
 } 
 
 QString
-SpectrogramLayer::getFeatureDescription(QPoint &pos) const
+SpectrogramLayer::getFeatureDescription(View *v, QPoint &pos) const
 {
     int x = pos.x();
     int y = pos.y();
@@ -2097,10 +2057,10 @@
 
     bool haveValues = false;
 
-    if (!getXBinSourceRange(x, rtMin, rtMax)) {
+    if (!getXBinSourceRange(v, x, rtMin, rtMax)) {
 	return "";
     }
-    if (getXYBinSourceRange(x, y, magMin, magMax, phaseMin, phaseMax)) {
+    if (getXYBinSourceRange(v, x, y, magMin, magMax, phaseMin, phaseMax)) {
 	haveValues = true;
     }
 
@@ -2108,7 +2068,7 @@
 
     if (m_binDisplay == PeakFrequencies) {
 
-	if (!getAdjustedYBinSourceRange(x, y, freqMin, freqMax,
+	if (!getAdjustedYBinSourceRange(v, x, y, freqMin, freqMax,
 					adjFreqMin, adjFreqMax)) {
 	    return "";
 	}
@@ -2132,7 +2092,7 @@
 
     } else {
 	
-	if (!getYBinSourceRange(y, freqMin, freqMax)) return "";
+	if (!getYBinSourceRange(v, y, freqMin, freqMax)) return "";
     }
 
     QString text;
@@ -2218,7 +2178,7 @@
 }
 
 int
-SpectrogramLayer::getVerticalScaleWidth(QPainter &paint) const
+SpectrogramLayer::getVerticalScaleWidth(View *v, QPainter &paint) const
 {
     if (!m_model || !m_model->isOK()) return 0;
 
@@ -2238,7 +2198,7 @@
 }
 
 void
-SpectrogramLayer::paintVerticalScale(QPainter &paint, QRect rect) const
+SpectrogramLayer::paintVerticalScale(View *v, QPainter &paint, QRect rect) const
 {
     if (!m_model || !m_model->isOK()) {
 	return;
@@ -2317,10 +2277,10 @@
 
     int bin = -1;
 
-    for (int y = 0; y < m_view->height(); ++y) {
+    for (int y = 0; y < v->height(); ++y) {
 
 	float q0, q1;
-	if (!getYBinRange(m_view->height() - y, q0, q1)) continue;
+	if (!getYBinRange(v, v->height() - y, q0, q1)) continue;
 
 	int vy;
 
@@ -2366,7 +2326,7 @@
 	for (int i = 0; i < 128; ++i) {
 
 	    float f = Pitch::getFrequencyForPitch(i);
-	    int y = lrintf(m_view->getYForFrequency(f, minf, maxf, true));
+	    int y = lrintf(v->getYForFrequency(f, minf, maxf, true));
 	    int n = (i % 12);
 	    if (n == 1 || n == 3 || n == 6 || n == 8 || n == 10) {
 		// black notes
--- a/layer/SpectrogramLayer.h	Wed Mar 01 18:13:01 2006 +0000
+++ b/layer/SpectrogramLayer.h	Thu Mar 02 16:58:49 2006 +0000
@@ -43,19 +43,19 @@
 public:
     enum Configuration { FullRangeDb, MelodicRange, MelodicPeaks };
     
-    SpectrogramLayer(View *w, Configuration = FullRangeDb);
+    SpectrogramLayer(Configuration = FullRangeDb);
     ~SpectrogramLayer();
 
     virtual const ZoomConstraint *getZoomConstraint() const { return this; }
     virtual const Model *getModel() const { return m_model; }
-    virtual void paint(QPainter &paint, QRect rect) const;
+    virtual void paint(View *v, QPainter &paint, QRect rect) const;
 
-    virtual int getVerticalScaleWidth(QPainter &) const;
-    virtual void paintVerticalScale(QPainter &paint, QRect rect) const;
+    virtual int getVerticalScaleWidth(View *v, QPainter &) const;
+    virtual void paintVerticalScale(View *v, QPainter &paint, QRect rect) const;
 
-    virtual QString getFeatureDescription(QPoint &) const;
+    virtual QString getFeatureDescription(View *v, QPoint &) const;
 
-    virtual bool snapToFeatureFrame(int &frame,
+    virtual bool snapToFeatureFrame(View *v, int &frame,
 				    size_t &resolution,
 				    SnapType snap) const;
 
@@ -169,8 +169,8 @@
 
     virtual bool isLayerOpaque() const { return true; }
 
-    float getYForFrequency(float frequency) const;
-    float getFrequencyForY(int y) const;
+    float getYForFrequency(View *v, float frequency) const;
+    float getFrequencyForY(View *v, int y) const;
 
     virtual int getCompletion() const;
 
@@ -179,7 +179,7 @@
 
     void setProperties(const QXmlAttributes &attributes);
 
-    virtual void setLayerDormant(bool dormant);
+    virtual void setLayerDormant(const bool dormant);
 
 protected slots:
     void cacheInvalid();
@@ -243,17 +243,17 @@
 	}
 
 	float getNormalizedMagnitudeAt(size_t x, size_t y) const {
-	    return float(m_magnitude[y][x]) / 65535.0;
+	    return float(m_magnitude[x][y]) / 65535.0;
 	}
 
 	float getPhaseAt(size_t x, size_t y) const {
-	    int16_t i = (int16_t)m_phase[y][x];
+	    int16_t i = (int16_t)m_phase[x][y];
 	    return (float(i) / 32767.0) * M_PI;
 	}
 
 	bool isLocalPeak(size_t x, size_t y) const {
-	    if (y > 0 && m_magnitude[y][x] < m_magnitude[y-1][x]) return false;
-	    if (y < m_height-1 && m_magnitude[y][x] < m_magnitude[y+1][x]) return false;
+	    if (y > 0 && m_magnitude[x][y] < m_magnitude[x][y-1]) return false;
+	    if (y < m_height-1 && m_magnitude[x][y] < m_magnitude[x][y+1]) return false;
 	    return true;
 	}
 
@@ -273,14 +273,14 @@
 
 	void setNormalizedMagnitudeAt(size_t x, size_t y, float norm) {
 	    if (x < m_width && y < m_height) {
-		m_magnitude[y][x] = uint16_t(norm * 65535.0);
+		m_magnitude[x][y] = uint16_t(norm * 65535.0);
 	    }
 	}
 
 	void setPhaseAt(size_t x, size_t y, float phase) {
 	    // phase in range -pi -> pi
 	    if (x < m_width && y < m_height) {
-		m_phase[y][x] = uint16_t(int16_t((phase * 32767) / M_PI));
+		m_phase[x][y] = uint16_t(int16_t((phase * 32767) / M_PI));
 	    }
 	}
 
@@ -336,6 +336,7 @@
 
     CacheFillThread *m_fillThread;
     QTimer *m_updateTimer;
+    mutable size_t m_candidateFillStartFrame;
     size_t m_lastFillExtent;
     bool m_exiting;
 
@@ -367,22 +368,21 @@
     float getEffectiveMinFrequency() const;
     float getEffectiveMaxFrequency() const;
 
-    bool getYBinRange(int y, float &freqBinMin, float &freqBinMax) const;
-
     struct LayerRange {
 	long   startFrame;
 	int    zoomLevel;
 	size_t modelStart;
 	size_t modelEnd;
     };
-    bool getXBinRange(int x, float &windowMin, float &windowMax) const;
+    bool getXBinRange(View *v, int x, float &windowMin, float &windowMax) const;
+    bool getYBinRange(View *v, int y, float &freqBinMin, float &freqBinMax) const;
 
-    bool getYBinSourceRange(int y, float &freqMin, float &freqMax) const;
-    bool getAdjustedYBinSourceRange(int x, int y,
+    bool getYBinSourceRange(View *v, int y, float &freqMin, float &freqMax) const;
+    bool getAdjustedYBinSourceRange(View *v, int x, int y,
 				    float &freqMin, float &freqMax,
 				    float &adjFreqMin, float &adjFreqMax) const;
-    bool getXBinSourceRange(int x, RealTime &timeMin, RealTime &timeMax) const;
-    bool getXYBinSourceRange(int x, int y, float &min, float &max,
+    bool getXBinSourceRange(View *v, int x, RealTime &timeMin, RealTime &timeMax) const;
+    bool getXYBinSourceRange(View *v, int x, int y, float &min, float &max,
 			     float &phaseMin, float &phaseMax) const;
 
     size_t getWindowIncrement() const {
--- a/layer/TextLayer.cpp	Wed Mar 01 18:13:01 2006 +0000
+++ b/layer/TextLayer.cpp	Thu Mar 02 16:58:49 2006 +0000
@@ -23,8 +23,8 @@
 #include <iostream>
 #include <cmath>
 
-TextLayer::TextLayer(View *w) :
-    Layer(w),
+TextLayer::TextLayer() :
+    Layer(),
     m_model(0),
     m_editing(false),
     m_originalPoint(0, 0.0, tr("Empty Label")),
@@ -32,7 +32,7 @@
     m_editingCommand(0),
     m_colour(255, 150, 50) // orange
 {
-    m_view->addLayer(this);
+    
 }
 
 void
@@ -138,20 +138,20 @@
 }
 
 bool
-TextLayer::isLayerScrollable() const
+TextLayer::isLayerScrollable(const View *v) const
 {
     QPoint discard;
-    return !m_view->shouldIlluminateLocalFeatures(this, discard);
+    return !v->shouldIlluminateLocalFeatures(this, discard);
 }
 
 
 TextModel::PointList
-TextLayer::getLocalPoints(int x, int y) const
+TextLayer::getLocalPoints(View *v, int x, int y) const
 {
     if (!m_model) return TextModel::PointList();
 
-    long frame0 = getFrameForX(-150);
-    long frame1 = getFrameForX(m_view->width() + 150);
+    long frame0 = v->getFrameForX(-150);
+    long frame1 = v->getFrameForX(v->width() + 150);
     
     TextModel::PointList points(m_model->getPoints(frame0, frame1));
 
@@ -163,8 +163,8 @@
 
 	const TextModel::Point &p(*i);
 
-	int px = getXForFrame(p.frame);
-	int py = getYForHeight(p.height);
+	int px = v->getXForFrame(p.frame);
+	int py = getYForHeight(v, p.height);
 
 	QString label = p.label;
 	if (label == "") {
@@ -175,9 +175,9 @@
 	    (QRect(0, 0, 150, 200),
 	     Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, label);
 
-	if (py + rect.height() > m_view->height()) {
-	    if (rect.height() > m_view->height()) py = 0;
-	    else py = m_view->height() - rect.height() - 1;
+	if (py + rect.height() > v->height()) {
+	    if (rect.height() > v->height()) py = 0;
+	    else py = v->height() - rect.height() - 1;
 	}
 
 	if (x >= px && x < px + rect.width() &&
@@ -190,13 +190,13 @@
 }
 
 QString
-TextLayer::getFeatureDescription(QPoint &pos) const
+TextLayer::getFeatureDescription(View *v, QPoint &pos) const
 {
     int x = pos.x();
 
     if (!m_model || !m_model->getSampleRate()) return "";
 
-    TextModel::PointList points = getLocalPoints(x, pos.y());
+    TextModel::PointList points = getLocalPoints(v, x, pos.y());
 
     if (points.empty()) {
 	if (!m_model->isReady()) {
@@ -219,7 +219,8 @@
 	    .arg(points.begin()->label);
     }
 
-    pos = QPoint(getXForFrame(useFrame), getYForHeight(points.begin()->height));
+    pos = QPoint(v->getXForFrame(useFrame),
+		 getYForHeight(v, points.begin()->height));
     return text;
 }
 
@@ -227,12 +228,12 @@
 //!!! too much overlap with TimeValueLayer/TimeInstantLayer
 
 bool
-TextLayer::snapToFeatureFrame(int &frame,
+TextLayer::snapToFeatureFrame(View *v, int &frame,
 			      size_t &resolution,
 			      SnapType snap) const
 {
     if (!m_model) {
-	return Layer::snapToFeatureFrame(frame, resolution, snap);
+	return Layer::snapToFeatureFrame(v, frame, resolution, snap);
     }
 
     resolution = m_model->getResolution();
@@ -240,7 +241,7 @@
 
     if (snap == SnapNeighbouring) {
 	
-	points = getLocalPoints(getXForFrame(frame), -1);
+	points = getLocalPoints(v, v->getXForFrame(frame), -1);
 	if (points.empty()) return false;
 	frame = points.begin()->frame;
 	return true;
@@ -299,21 +300,21 @@
 }
 
 int
-TextLayer::getYForHeight(float height) const
+TextLayer::getYForHeight(View *v, float height) const
 {
-    int h = m_view->height();
+    int h = v->height();
     return h - int(height * h);
 }
 
 float
-TextLayer::getHeightForY(int y) const
+TextLayer::getHeightForY(View *v, int y) const
 {
-    int h = m_view->height();
+    int h = v->height();
     return float(h - y) / h;
 }
 
 void
-TextLayer::paint(QPainter &paint, QRect rect) const
+TextLayer::paint(View *v, QPainter &paint, QRect rect) const
 {
     if (!m_model || !m_model->isOK()) return;
 
@@ -323,20 +324,20 @@
 //    Profiler profiler("TextLayer::paint", true);
 
     int x0 = rect.left(), x1 = rect.right();
-    long frame0 = getFrameForX(x0);
-    long frame1 = getFrameForX(x1);
+    long frame0 = v->getFrameForX(x0);
+    long frame1 = v->getFrameForX(x1);
 
     TextModel::PointList points(m_model->getPoints(frame0, frame1));
     if (points.empty()) return;
 
     QColor brushColour(m_colour);
 
-    int h, s, v;
-    brushColour.getHsv(&h, &s, &v);
+    int h, s, val;
+    brushColour.getHsv(&h, &s, &val);
     brushColour.setHsv(h, s, 255, 100);
 
     QColor penColour;
-    if (m_view->hasLightBackground()) {
+    if (v->hasLightBackground()) {
 	penColour = Qt::black;
     } else {
 	penColour = Qt::white;
@@ -348,8 +349,8 @@
     QPoint localPos;
     long illuminateFrame = -1;
 
-    if (m_view->shouldIlluminateLocalFeatures(this, localPos)) {
-	TextModel::PointList localPoints = getLocalPoints(localPos.x(),
+    if (v->shouldIlluminateLocalFeatures(this, localPos)) {
+	TextModel::PointList localPoints = getLocalPoints(v, localPos.x(),
 							  localPos.y());
 	if (!localPoints.empty()) illuminateFrame = localPoints.begin()->frame;
     }
@@ -358,19 +359,19 @@
     int boxMaxHeight = 200;
 
     paint.save();
-    paint.setClipRect(rect.x(), 0, rect.width() + boxMaxWidth, m_view->height());
+    paint.setClipRect(rect.x(), 0, rect.width() + boxMaxWidth, v->height());
     
     for (TextModel::PointList::const_iterator i = points.begin();
 	 i != points.end(); ++i) {
 
 	const TextModel::Point &p(*i);
 
-	int x = getXForFrame(p.frame);
-	int y = getYForHeight(p.height);
+	int x = v->getXForFrame(p.frame);
+	int y = getYForHeight(v, p.height);
 
 	if (illuminateFrame == p.frame) {
 	    paint.setBrush(penColour);
-	    if (m_view->hasLightBackground()) {
+	    if (v->hasLightBackground()) {
 		paint.setPen(Qt::white);
 	    } else {
 		paint.setPen(Qt::black);
@@ -392,9 +393,9 @@
 	QRect textRect = QRect(3, 2, boxRect.width(), boxRect.height());
 	boxRect = QRect(0, 0, boxRect.width() + 6, boxRect.height() + 2);
 
-	if (y + boxRect.height() > m_view->height()) {
-	    if (boxRect.height() > m_view->height()) y = 0;
-	    else y = m_view->height() - boxRect.height() - 1;
+	if (y + boxRect.height() > v->height()) {
+	    if (boxRect.height() > v->height()) y = 0;
+	    else y = v->height() - boxRect.height() - 1;
 	}
 
 	boxRect = QRect(x, y, boxRect.width(), boxRect.height());
@@ -423,7 +424,7 @@
 }
 
 void
-TextLayer::drawStart(QMouseEvent *e)
+TextLayer::drawStart(View *v, QMouseEvent *e)
 {
 //    std::cerr << "TextLayer::drawStart(" << e->x() << "," << e->y() << ")" << std::endl;
 
@@ -432,11 +433,11 @@
 	return;
     }
 
-    long frame = getFrameForX(e->x());
+    long frame = v->getFrameForX(e->x());
     if (frame < 0) frame = 0;
     frame = frame / m_model->getResolution() * m_model->getResolution();
 
-    float height = getHeightForY(e->y());
+    float height = getHeightForY(v, e->y());
 
     m_editingPoint = TextModel::Point(frame, height, "");
     m_originalPoint = m_editingPoint;
@@ -449,17 +450,17 @@
 }
 
 void
-TextLayer::drawDrag(QMouseEvent *e)
+TextLayer::drawDrag(View *v, QMouseEvent *e)
 {
 //    std::cerr << "TextLayer::drawDrag(" << e->x() << "," << e->y() << ")" << std::endl;
 
     if (!m_model || !m_editing) return;
 
-    long frame = getFrameForX(e->x());
+    long frame = v->getFrameForX(e->x());
     if (frame < 0) frame = 0;
     frame = frame / m_model->getResolution() * m_model->getResolution();
 
-    float height = getHeightForY(e->y());
+    float height = getHeightForY(v, e->y());
 
     m_editingCommand->deletePoint(m_editingPoint);
     m_editingPoint.frame = frame;
@@ -468,13 +469,13 @@
 }
 
 void
-TextLayer::drawEnd(QMouseEvent *e)
+TextLayer::drawEnd(View *v, QMouseEvent *e)
 {
 //    std::cerr << "TextLayer::drawEnd(" << e->x() << "," << e->y() << ")" << std::endl;
     if (!m_model || !m_editing) return;
 
     bool ok = false;
-    QString label = QInputDialog::getText(m_view, tr("Enter label"),
+    QString label = QInputDialog::getText(v, tr("Enter label"),
 					  tr("Please enter a new label:"),
 					  QLineEdit::Normal, "", &ok);
 
@@ -490,13 +491,13 @@
 }
 
 void
-TextLayer::editStart(QMouseEvent *e)
+TextLayer::editStart(View *v, QMouseEvent *e)
 {
 //    std::cerr << "TextLayer::editStart(" << e->x() << "," << e->y() << ")" << std::endl;
 
     if (!m_model) return;
 
-    TextModel::PointList points = getLocalPoints(e->x(), e->y());
+    TextModel::PointList points = getLocalPoints(v, e->x(), e->y());
     if (points.empty()) return;
 
     m_editOrigin = e->pos();
@@ -512,21 +513,21 @@
 }
 
 void
-TextLayer::editDrag(QMouseEvent *e)
+TextLayer::editDrag(View *v, QMouseEvent *e)
 {
     if (!m_model || !m_editing) return;
 
-    long frameDiff = getFrameForX(e->x()) - getFrameForX(m_editOrigin.x());
-    float heightDiff = getHeightForY(e->y()) - getHeightForY(m_editOrigin.y());
+    long frameDiff = v->getFrameForX(e->x()) - v->getFrameForX(m_editOrigin.x());
+    float heightDiff = getHeightForY(v, e->y()) - getHeightForY(v, m_editOrigin.y());
 
     long frame = m_originalPoint.frame + frameDiff;
     float height = m_originalPoint.height + heightDiff;
 
-//    long frame = getFrameForX(e->x());
+//    long frame = v->getFrameForX(e->x());
     if (frame < 0) frame = 0;
     frame = (frame / m_model->getResolution()) * m_model->getResolution();
 
-//    float height = getHeightForY(e->y());
+//    float height = getHeightForY(v, e->y());
 
     if (!m_editingCommand) {
 	m_editingCommand = new TextModel::EditCommand(m_model, tr("Drag Label"));
@@ -539,7 +540,7 @@
 }
 
 void
-TextLayer::editEnd(QMouseEvent *e)
+TextLayer::editEnd(View *v, QMouseEvent *e)
 {
 //    std::cerr << "TextLayer::editEnd(" << e->x() << "," << e->y() << ")" << std::endl;
     if (!m_model || !m_editing) return;
@@ -567,19 +568,19 @@
 }
 
 void
-TextLayer::editOpen(QMouseEvent *e)
+TextLayer::editOpen(View *v, QMouseEvent *e)
 {
     std::cerr << "TextLayer::editOpen" << std::endl;
 
     if (!m_model) return;
 
-    TextModel::PointList points = getLocalPoints(e->x(), e->y());
+    TextModel::PointList points = getLocalPoints(v, e->x(), e->y());
     if (points.empty()) return;
 
     QString label = points.begin()->label;
 
     bool ok = false;
-    label = QInputDialog::getText(m_view, tr("Enter label"),
+    label = QInputDialog::getText(v, tr("Enter label"),
 				  tr("Please enter a new label:"),
 				  QLineEdit::Normal, label, &ok);
     if (ok && label != points.begin()->label) {
--- a/layer/TextLayer.h	Wed Mar 01 18:13:01 2006 +0000
+++ b/layer/TextLayer.h	Thu Mar 02 16:58:49 2006 +0000
@@ -24,28 +24,28 @@
     Q_OBJECT
 
 public:
-    TextLayer(View *w);
+    TextLayer();
 
-    virtual void paint(QPainter &paint, QRect rect) const;
+    virtual void paint(View *v, QPainter &paint, QRect rect) const;
 
-    virtual QString getFeatureDescription(QPoint &) const;
+    virtual QString getFeatureDescription(View *v, QPoint &) const;
 
-    virtual bool snapToFeatureFrame(int &frame,
+    virtual bool snapToFeatureFrame(View *v, int &frame,
 				    size_t &resolution,
 				    SnapType snap) const;
 
-    virtual void drawStart(QMouseEvent *);
-    virtual void drawDrag(QMouseEvent *);
-    virtual void drawEnd(QMouseEvent *);
+    virtual void drawStart(View *v, QMouseEvent *);
+    virtual void drawDrag(View *v, QMouseEvent *);
+    virtual void drawEnd(View *v, QMouseEvent *);
 
-    virtual void editStart(QMouseEvent *);
-    virtual void editDrag(QMouseEvent *);
-    virtual void editEnd(QMouseEvent *);
+    virtual void editStart(View *v, QMouseEvent *);
+    virtual void editDrag(View *v, QMouseEvent *);
+    virtual void editEnd(View *v, QMouseEvent *);
 
     virtual void moveSelection(Selection s, size_t newStartFrame);
     virtual void resizeSelection(Selection s, Selection newSize);
 
-    virtual void editOpen(QMouseEvent *); // on double-click
+    virtual void editOpen(View *, QMouseEvent *); // on double-click
 
     virtual const Model *getModel() const { return m_model; }
     void setModel(TextModel *model);
@@ -61,7 +61,7 @@
     void setBaseColour(QColor);
     QColor getBaseColour() const { return m_colour; }
 
-    virtual bool isLayerScrollable() const;
+    virtual bool isLayerScrollable(const View *v) const;
 
     virtual bool isLayerEditable() const { return true; }
 
@@ -73,10 +73,10 @@
     void setProperties(const QXmlAttributes &attributes);
 
 protected:
-    int getYForHeight(float height) const;
-    float getHeightForY(int y) const;
+    int getYForHeight(View *v, float height) const;
+    float getHeightForY(View *v, int y) const;
 
-    TextModel::PointList getLocalPoints(int x, int y) const;
+    TextModel::PointList getLocalPoints(View *v, int x, int y) const;
 
     TextModel *m_model;
     bool m_editing;
--- a/layer/TimeInstantLayer.cpp	Wed Mar 01 18:13:01 2006 +0000
+++ b/layer/TimeInstantLayer.cpp	Thu Mar 02 16:58:49 2006 +0000
@@ -21,8 +21,8 @@
 
 #include <iostream>
 
-TimeInstantLayer::TimeInstantLayer(View *w) :
-    Layer(w),
+TimeInstantLayer::TimeInstantLayer() :
+    Layer(),
     m_model(0),
     m_editing(false),
     m_editingPoint(0, tr("New Point")),
@@ -30,7 +30,7 @@
     m_colour(QColor(200, 50, 255)),
     m_plotStyle(PlotInstants)
 {
-    m_view->addLayer(this);
+    
 }
 
 void
@@ -158,14 +158,14 @@
 }
 
 bool
-TimeInstantLayer::isLayerScrollable() const
+TimeInstantLayer::isLayerScrollable(const View *v) const
 {
     QPoint discard;
-    return !m_view->shouldIlluminateLocalFeatures(this, discard);
+    return !v->shouldIlluminateLocalFeatures(this, discard);
 }
 
 SparseOneDimensionalModel::PointList
-TimeInstantLayer::getLocalPoints(int x) const
+TimeInstantLayer::getLocalPoints(View *v, int x) const
 {
     // Return a set of points that all have the same frame number, the
     // nearest to the given x coordinate, and that are within a
@@ -173,7 +173,7 @@
 
     if (!m_model) return SparseOneDimensionalModel::PointList();
 
-    long frame = getFrameForX(x);
+    long frame = v->getFrameForX(x);
 
     SparseOneDimensionalModel::PointList onPoints =
 	m_model->getPoints(frame);
@@ -191,8 +191,8 @@
 
     if (prevPoints.empty()) {
 	usePoints = nextPoints;
-    } else if (prevPoints.begin()->frame < m_view->getStartFrame() &&
-	       !(nextPoints.begin()->frame > m_view->getEndFrame())) {
+    } else if (prevPoints.begin()->frame < v->getStartFrame() &&
+	       !(nextPoints.begin()->frame > v->getEndFrame())) {
 	usePoints = nextPoints;
     } else if (nextPoints.begin()->frame - frame <
 	       frame - prevPoints.begin()->frame) {
@@ -201,7 +201,7 @@
 
     if (!usePoints.empty()) {
 	int fuzz = 2;
-	int px = getXForFrame(usePoints.begin()->frame);
+	int px = v->getXForFrame(usePoints.begin()->frame);
 	if ((px > x && px - x > fuzz) ||
 	    (px < x && x - px > fuzz + 1)) {
 	    usePoints.clear();
@@ -212,13 +212,13 @@
 }
 
 QString
-TimeInstantLayer::getFeatureDescription(QPoint &pos) const
+TimeInstantLayer::getFeatureDescription(View *v, QPoint &pos) const
 {
     int x = pos.x();
 
     if (!m_model || !m_model->getSampleRate()) return "";
 
-    SparseOneDimensionalModel::PointList points = getLocalPoints(x);
+    SparseOneDimensionalModel::PointList points = getLocalPoints(v, x);
 
     if (points.empty()) {
 	if (!m_model->isReady()) {
@@ -243,17 +243,17 @@
 	    .arg(points.begin()->label);
     }
 
-    pos = QPoint(getXForFrame(useFrame), pos.y());
+    pos = QPoint(v->getXForFrame(useFrame), pos.y());
     return text;
 }
 
 bool
-TimeInstantLayer::snapToFeatureFrame(int &frame,
+TimeInstantLayer::snapToFeatureFrame(View *v, int &frame,
 				     size_t &resolution,
 				     SnapType snap) const
 {
     if (!m_model) {
-	return Layer::snapToFeatureFrame(frame, resolution, snap);
+	return Layer::snapToFeatureFrame(v, frame, resolution, snap);
     }
 
     resolution = m_model->getResolution();
@@ -261,7 +261,7 @@
 
     if (snap == SnapNeighbouring) {
 	
-	points = getLocalPoints(getXForFrame(frame));
+	points = getLocalPoints(v, v->getXForFrame(frame));
 	if (points.empty()) return false;
 	frame = points.begin()->frame;
 	return true;
@@ -320,7 +320,7 @@
 }
 
 void
-TimeInstantLayer::paint(QPainter &paint, QRect rect) const
+TimeInstantLayer::paint(View *v, QPainter &paint, QRect rect) const
 {
     if (!m_model || !m_model->isOK()) return;
 
@@ -328,8 +328,8 @@
 
     int x0 = rect.left(), x1 = rect.right();
 
-    long frame0 = getFrameForX(x0);
-    long frame1 = getFrameForX(x1);
+    long frame0 = v->getFrameForX(x0);
+    long frame1 = v->getFrameForX(x1);
 
     SparseOneDimensionalModel::PointList points(m_model->getPoints
 						(frame0, frame1));
@@ -368,9 +368,9 @@
     QPoint localPos;
     long illuminateFrame = -1;
 
-    if (m_view->shouldIlluminateLocalFeatures(this, localPos)) {
+    if (v->shouldIlluminateLocalFeatures(this, localPos)) {
 	SparseOneDimensionalModel::PointList localPoints =
-	    getLocalPoints(localPos.x());
+	    getLocalPoints(v, localPos.x());
 	if (!localPoints.empty()) illuminateFrame = localPoints.begin()->frame;
     }
 	
@@ -383,15 +383,15 @@
 	SparseOneDimensionalModel::PointList::const_iterator j = i;
 	++j;
 
-	int x = getXForFrame(p.frame);
+	int x = v->getXForFrame(p.frame);
 	if (x == prevX && p.frame != illuminateFrame) continue;
 
-	int iw = getXForFrame(p.frame + m_model->getResolution()) - x;
+	int iw = v->getXForFrame(p.frame + m_model->getResolution()) - x;
 	if (iw < 2) {
 	    if (iw < 1) {
 		iw = 2;
 		if (j != points.end()) {
-		    int nx = getXForFrame(j->frame);
+		    int nx = v->getXForFrame(j->frame);
 		    if (nx < x + 3) iw = 1;
 		}
 	    } else {
@@ -407,9 +407,9 @@
 
 	if (m_plotStyle == PlotInstants) {
 	    if (iw > 1) {
-		paint.drawRect(x, 0, iw - 1, m_view->height() - 1);
+		paint.drawRect(x, 0, iw - 1, v->height() - 1);
 	    } else {
-		paint.drawLine(x, 0, x, m_view->height() - 1);
+		paint.drawLine(x, 0, x, v->height() - 1);
 	    }
 	} else {
 
@@ -420,19 +420,19 @@
 	    
 	    if (j != points.end()) {
 		const SparseOneDimensionalModel::Point &q(*j);
-		nx = getXForFrame(q.frame);
+		nx = v->getXForFrame(q.frame);
 	    } else {
-		nx = getXForFrame(m_model->getEndFrame());
+		nx = v->getXForFrame(m_model->getEndFrame());
 	    }
 
 	    if (nx >= x) {
 		
 		if (illuminateFrame != p.frame &&
-		    (nx < x + 5 || x >= m_view->width() - 1)) {
+		    (nx < x + 5 || x >= v->width() - 1)) {
 		    paint.setPen(Qt::NoPen);
 		}
 
-		paint.drawRect(x, -1, nx - x, m_view->height() + 1);
+		paint.drawRect(x, -1, nx - x, v->height() + 1);
 	    }
 
 	    odd = !odd;
@@ -448,13 +448,13 @@
 	    bool good = true;
 
 	    if (j != points.end()) {
-		int nx = getXForFrame(j->frame);
+		int nx = v->getXForFrame(j->frame);
 		if (nx >= x && nx - x - iw - 3 <= lw) good = false;
 	    }
 
 	    if (good) {
 		paint.drawText(x + iw + 2,
-			       m_view->height() - paint.fontMetrics().height(),
+			       v->height() - paint.fontMetrics().height(),
 			       p.label);
 	    }
 	}
@@ -464,13 +464,13 @@
 }
 
 void
-TimeInstantLayer::drawStart(QMouseEvent *e)
+TimeInstantLayer::drawStart(View *v, QMouseEvent *e)
 {
     std::cerr << "TimeInstantLayer::drawStart(" << e->x() << ")" << std::endl;
 
     if (!m_model) return;
 
-    long frame = getFrameForX(e->x());
+    long frame = v->getFrameForX(e->x());
     if (frame < 0) frame = 0;
     frame = frame / m_model->getResolution() * m_model->getResolution();
 
@@ -485,13 +485,13 @@
 }
 
 void
-TimeInstantLayer::drawDrag(QMouseEvent *e)
+TimeInstantLayer::drawDrag(View *v, QMouseEvent *e)
 {
     std::cerr << "TimeInstantLayer::drawDrag(" << e->x() << ")" << std::endl;
 
     if (!m_model || !m_editing) return;
 
-    long frame = getFrameForX(e->x());
+    long frame = v->getFrameForX(e->x());
     if (frame < 0) frame = 0;
     frame = frame / m_model->getResolution() * m_model->getResolution();
     m_editingCommand->deletePoint(m_editingPoint);
@@ -500,7 +500,7 @@
 }
 
 void
-TimeInstantLayer::drawEnd(QMouseEvent *e)
+TimeInstantLayer::drawEnd(View *v, QMouseEvent *e)
 {
     std::cerr << "TimeInstantLayer::drawEnd(" << e->x() << ")" << std::endl;
     if (!m_model || !m_editing) return;
@@ -515,13 +515,13 @@
 }
 
 void
-TimeInstantLayer::editStart(QMouseEvent *e)
+TimeInstantLayer::editStart(View *v, QMouseEvent *e)
 {
     std::cerr << "TimeInstantLayer::editStart(" << e->x() << ")" << std::endl;
 
     if (!m_model) return;
 
-    SparseOneDimensionalModel::PointList points = getLocalPoints(e->x());
+    SparseOneDimensionalModel::PointList points = getLocalPoints(v, e->x());
     if (points.empty()) return;
 
     m_editingPoint = *points.begin();
@@ -535,13 +535,13 @@
 }
 
 void
-TimeInstantLayer::editDrag(QMouseEvent *e)
+TimeInstantLayer::editDrag(View *v, QMouseEvent *e)
 {
     std::cerr << "TimeInstantLayer::editDrag(" << e->x() << ")" << std::endl;
 
     if (!m_model || !m_editing) return;
 
-    long frame = getFrameForX(e->x());
+    long frame = v->getFrameForX(e->x());
     if (frame < 0) frame = 0;
     frame = frame / m_model->getResolution() * m_model->getResolution();
 
@@ -556,7 +556,7 @@
 }
 
 void
-TimeInstantLayer::editEnd(QMouseEvent *e)
+TimeInstantLayer::editEnd(View *v, QMouseEvent *e)
 {
     std::cerr << "TimeInstantLayer::editEnd(" << e->x() << ")" << std::endl;
     if (!m_model || !m_editing) return;
--- a/layer/TimeInstantLayer.h	Wed Mar 01 18:13:01 2006 +0000
+++ b/layer/TimeInstantLayer.h	Thu Mar 02 16:58:49 2006 +0000
@@ -24,23 +24,23 @@
     Q_OBJECT
 
 public:
-    TimeInstantLayer(View *w);
+    TimeInstantLayer();
 
-    virtual void paint(QPainter &paint, QRect rect) const;
+    virtual void paint(View *v, QPainter &paint, QRect rect) const;
 
-    virtual QString getFeatureDescription(QPoint &) const;
+    virtual QString getFeatureDescription(View *v, QPoint &) const;
 
-    virtual bool snapToFeatureFrame(int &frame,
+    virtual bool snapToFeatureFrame(View *v, int &frame,
 				    size_t &resolution,
 				    SnapType snap) const;
 
-    virtual void drawStart(QMouseEvent *);
-    virtual void drawDrag(QMouseEvent *);
-    virtual void drawEnd(QMouseEvent *);
+    virtual void drawStart(View *v, QMouseEvent *);
+    virtual void drawDrag(View *v, QMouseEvent *);
+    virtual void drawEnd(View *v, QMouseEvent *);
 
-    virtual void editStart(QMouseEvent *);
-    virtual void editDrag(QMouseEvent *);
-    virtual void editEnd(QMouseEvent *);
+    virtual void editStart(View *v, QMouseEvent *);
+    virtual void editDrag(View *v, QMouseEvent *);
+    virtual void editEnd(View *v, QMouseEvent *);
 
     virtual void moveSelection(Selection s, size_t newStartFrame);
     virtual void resizeSelection(Selection s, Selection newSize);
@@ -68,7 +68,7 @@
     void setPlotStyle(PlotStyle style);
     PlotStyle getPlotStyle() const { return m_plotStyle; }
 
-    virtual bool isLayerScrollable() const;
+    virtual bool isLayerScrollable(const View *v) const;
 
     virtual bool isLayerEditable() const { return true; }
 
@@ -80,7 +80,7 @@
     void setProperties(const QXmlAttributes &attributes);
 
 protected:
-    SparseOneDimensionalModel::PointList getLocalPoints(int) const;
+    SparseOneDimensionalModel::PointList getLocalPoints(View *v, int) const;
 
     SparseOneDimensionalModel *m_model;
     bool m_editing;
--- a/layer/TimeRulerLayer.cpp	Wed Mar 01 18:13:01 2006 +0000
+++ b/layer/TimeRulerLayer.cpp	Thu Mar 02 16:58:49 2006 +0000
@@ -20,13 +20,13 @@
 using std::cerr;
 using std::endl;
 
-TimeRulerLayer::TimeRulerLayer(View *w) :
-    Layer(w),
+TimeRulerLayer::TimeRulerLayer() :
+    Layer(),
     m_model(0),
     m_colour(Qt::black),
     m_labelHeight(LabelTop)
 {
-    m_view->addLayer(this);
+    
 }
 
 void
@@ -120,7 +120,7 @@
 }
 
 void
-TimeRulerLayer::paint(QPainter &paint, QRect rect) const
+TimeRulerLayer::paint(View *v, QPainter &paint, QRect rect) const
 {
 //    std::cerr << "TimeRulerLayer::paint (" << rect.x() << "," << rect.y()
 //	      << ") [" << rect.width() << "x" << rect.height() << "]" << std::endl;
@@ -130,10 +130,10 @@
     int sampleRate = m_model->getSampleRate();
     if (!sampleRate) return;
 
-    long startFrame = m_view->getStartFrame();
-    long endFrame = m_view->getEndFrame();
+    long startFrame = v->getStartFrame();
+    long endFrame = v->getEndFrame();
 
-    int zoomLevel = m_view->getZoomLevel();
+    int zoomLevel = v->getZoomLevel();
 
     long rectStart = startFrame + (rect.x() - 100) * zoomLevel;
     long rectEnd = startFrame + (rect.x() + rect.width() + 100) * zoomLevel;
@@ -142,14 +142,14 @@
 
 //    std::cerr << "TimeRulerLayer::paint: calling paint.save()" << std::endl;
     paint.save();
-//!!!    paint.setClipRect(m_view->rect());
+//!!!    paint.setClipRect(v->rect());
 
     int minPixelSpacing = 50;
 
     RealTime rtStart = RealTime::frame2RealTime(startFrame, sampleRate);
     RealTime rtEnd = RealTime::frame2RealTime(endFrame, sampleRate);
-//    cerr << "startFrame " << startFrame << ", endFrame " << m_view->getEndFrame() << ", rtStart " << rtStart << ", rtEnd " << rtEnd << endl;
-    int count = m_view->width() / minPixelSpacing;
+//    cerr << "startFrame " << startFrame << ", endFrame " << v->getEndFrame() << ", rtStart " << rtStart << ", rtEnd " << rtEnd << endl;
+    int count = v->width() / minPixelSpacing;
     if (count < 1) count = 1;
     RealTime rtGap = (rtEnd - rtStart) / count;
 //    cerr << "rtGap is " << rtGap << endl;
@@ -217,11 +217,11 @@
 	if (x < rect.x() || x >= rect.x() + rect.width()) continue;
 
 	paint.setPen(greyColour);
-	paint.drawLine(x, 0, x, m_view->height());
+	paint.drawLine(x, 0, x, v->height());
 
 	paint.setPen(m_colour);
 	paint.drawLine(x, 0, x, 5);
-	paint.drawLine(x, m_view->height() - 6, x, m_view->height() - 1);
+	paint.drawLine(x, v->height() - 6, x, v->height() - 1);
 
 	QString text(QString::fromStdString(rt.toText()));
 
@@ -233,15 +233,15 @@
 	    y = 6 + metrics.ascent();
 	    break;
 	case LabelMiddle:
-	    y = m_view->height() / 2 - metrics.height() / 2 + metrics.ascent();
+	    y = v->height() / 2 - metrics.height() / 2 + metrics.ascent();
 	    break;
 	case LabelBottom:
-	    y = m_view->height() - metrics.height() + metrics.ascent() - 6;
+	    y = v->height() - metrics.height() + metrics.ascent() - 6;
 	}
 
 	int tw = metrics.width(text);
 
-	paint.setPen(m_view->palette().background().color());
+	paint.setPen(v->palette().background().color());
 
 	//!!! simple drawing function for this please
 	//!!! and need getContrastingColour() in widget, or use the
@@ -267,14 +267,14 @@
 	    if (ticks == 10) {
 		if ((i % 2) == 1) {
 		    if (i == 5) {
-			paint.drawLine(x, 0, x, m_view->height());
+			paint.drawLine(x, 0, x, v->height());
 		    } else sz = 3;
 		} else {
 		    sz = 7;
 		}
 	    }
 	    paint.drawLine(x, 0, x, sz);
-	    paint.drawLine(x, m_view->height() - sz - 1, x, m_view->height() - 1);
+	    paint.drawLine(x, v->height() - sz - 1, x, v->height() - 1);
 	}
     }
 
--- a/layer/TimeRulerLayer.h	Wed Mar 01 18:13:01 2006 +0000
+++ b/layer/TimeRulerLayer.h	Thu Mar 02 16:58:49 2006 +0000
@@ -24,9 +24,9 @@
     Q_OBJECT
 
 public:
-    TimeRulerLayer(View *w);
+    TimeRulerLayer();
 
-    virtual void paint(QPainter &paint, QRect rect) const;
+    virtual void paint(View *v, QPainter &paint, QRect rect) const;
 
     void setModel(Model *);
     virtual const Model *getModel() const { return m_model; }
--- a/layer/TimeValueLayer.cpp	Wed Mar 01 18:13:01 2006 +0000
+++ b/layer/TimeValueLayer.cpp	Thu Mar 02 16:58:49 2006 +0000
@@ -23,8 +23,8 @@
 #include <iostream>
 #include <cmath>
 
-TimeValueLayer::TimeValueLayer(View *w) :
-    Layer(w),
+TimeValueLayer::TimeValueLayer() :
+    Layer(),
     m_model(0),
     m_editing(false),
     m_originalPoint(0, 0.0, tr("New Point")),
@@ -33,7 +33,7 @@
     m_colour(Qt::black),
     m_plotStyle(PlotConnectedPoints)
 {
-    m_view->addLayer(this);
+    
 }
 
 void
@@ -167,7 +167,7 @@
 }
 
 bool
-TimeValueLayer::isLayerScrollable() const
+TimeValueLayer::isLayerScrollable(const View *v) const
 {
     // We don't illuminate sections in the line or curve modes, so
     // they're always scrollable
@@ -176,15 +176,15 @@
 	m_plotStyle == PlotCurve) return true;
 
     QPoint discard;
-    return !m_view->shouldIlluminateLocalFeatures(this, discard);
+    return !v->shouldIlluminateLocalFeatures(this, discard);
 }
 
 SparseTimeValueModel::PointList
-TimeValueLayer::getLocalPoints(int x) const
+TimeValueLayer::getLocalPoints(View *v, int x) const
 {
     if (!m_model) return SparseTimeValueModel::PointList();
 
-    long frame = getFrameForX(x);
+    long frame = v->getFrameForX(x);
 
     SparseTimeValueModel::PointList onPoints =
 	m_model->getPoints(frame);
@@ -202,8 +202,8 @@
 
     if (prevPoints.empty()) {
 	usePoints = nextPoints;
-    } else if (prevPoints.begin()->frame < m_view->getStartFrame() &&
-	       !(nextPoints.begin()->frame > m_view->getEndFrame())) {
+    } else if (prevPoints.begin()->frame < v->getStartFrame() &&
+	       !(nextPoints.begin()->frame > v->getEndFrame())) {
 	usePoints = nextPoints;
     } else if (nextPoints.begin()->frame - frame <
 	       frame - prevPoints.begin()->frame) {
@@ -212,7 +212,7 @@
 
     if (!usePoints.empty()) {
 	int fuzz = 2;
-	int px = getXForFrame(usePoints.begin()->frame);
+	int px = v->getXForFrame(usePoints.begin()->frame);
 	if ((px > x && px - x > fuzz) ||
 	    (px < x && x - px > fuzz + 1)) {
 	    usePoints.clear();
@@ -223,13 +223,13 @@
 }
 
 QString
-TimeValueLayer::getFeatureDescription(QPoint &pos) const
+TimeValueLayer::getFeatureDescription(View *v, QPoint &pos) const
 {
     int x = pos.x();
 
     if (!m_model || !m_model->getSampleRate()) return "";
 
-    SparseTimeValueModel::PointList points = getLocalPoints(x);
+    SparseTimeValueModel::PointList points = getLocalPoints(v, x);
 
     if (points.empty()) {
 	if (!m_model->isReady()) {
@@ -256,17 +256,18 @@
 	    .arg(points.begin()->label);
     }
 
-    pos = QPoint(getXForFrame(useFrame), getYForValue(points.begin()->value));
+    pos = QPoint(v->getXForFrame(useFrame),
+		 getYForValue(v, points.begin()->value));
     return text;
 }
 
 bool
-TimeValueLayer::snapToFeatureFrame(int &frame,
+TimeValueLayer::snapToFeatureFrame(View *v, int &frame,
 				   size_t &resolution,
 				   SnapType snap) const
 {
     if (!m_model) {
-	return Layer::snapToFeatureFrame(frame, resolution, snap);
+	return Layer::snapToFeatureFrame(v, frame, resolution, snap);
     }
 
     resolution = m_model->getResolution();
@@ -274,7 +275,7 @@
 
     if (snap == SnapNeighbouring) {
 	
-	points = getLocalPoints(getXForFrame(frame));
+	points = getLocalPoints(v, v->getXForFrame(frame));
 	if (points.empty()) return false;
 	frame = points.begin()->frame;
 	return true;
@@ -333,31 +334,31 @@
 }
 
 int
-TimeValueLayer::getYForValue(float value) const
+TimeValueLayer::getYForValue(View *v, float value) const
 {
     float min = m_model->getValueMinimum();
     float max = m_model->getValueMaximum();
     if (max == min) max = min + 1.0;
 
-    int h = m_view->height();
+    int h = v->height();
 
     return int(h - ((value - min) * h) / (max - min));
 }
 
 float
-TimeValueLayer::getValueForY(int y) const
+TimeValueLayer::getValueForY(View *v, int y) const
 {
     float min = m_model->getValueMinimum();
     float max = m_model->getValueMaximum();
     if (max == min) max = min + 1.0;
 
-    int h = m_view->height();
+    int h = v->height();
 
     return min + (float(h - y) * float(max - min)) / h;
 }
 
 void
-TimeValueLayer::paint(QPainter &paint, QRect rect) const
+TimeValueLayer::paint(View *v, QPainter &paint, QRect rect) const
 {
     if (!m_model || !m_model->isOK()) return;
 
@@ -367,8 +368,8 @@
 //    Profiler profiler("TimeValueLayer::paint", true);
 
     int x0 = rect.left(), x1 = rect.right();
-    long frame0 = getFrameForX(x0);
-    long frame1 = getFrameForX(x1);
+    long frame0 = v->getFrameForX(x0);
+    long frame1 = v->getFrameForX(x1);
 
     SparseTimeValueModel::PointList points(m_model->getPoints
 					   (frame0, frame1));
@@ -387,21 +388,21 @@
     float max = m_model->getValueMaximum();
     if (max == min) max = min + 1.0;
 
-    int origin = int(nearbyint(m_view->height() -
-			       (-min * m_view->height()) / (max - min)));
+    int origin = int(nearbyint(v->height() -
+			       (-min * v->height()) / (max - min)));
 
     QPoint localPos;
     long illuminateFrame = -1;
 
-    if (m_view->shouldIlluminateLocalFeatures(this, localPos)) {
+    if (v->shouldIlluminateLocalFeatures(this, localPos)) {
 	SparseTimeValueModel::PointList localPoints =
-	    getLocalPoints(localPos.x());
+	    getLocalPoints(v, localPos.x());
 	if (!localPoints.empty()) illuminateFrame = localPoints.begin()->frame;
     }
 
     int w =
-	getXForFrame(frame0 + m_model->getResolution()) -
-	getXForFrame(frame0);
+	v->getXForFrame(frame0 + m_model->getResolution()) -
+	v->getXForFrame(frame0);
 
     paint.save();
 
@@ -417,11 +418,11 @@
 
 	const SparseTimeValueModel::Point &p(*i);
 
-	int x = getXForFrame(p.frame);
-	int y = getYForValue(p.value);
+	int x = v->getXForFrame(p.frame);
+	int y = getYForValue(v, p.value);
 
 	bool haveNext = false;
-	int nx = getXForFrame(m_model->getEndFrame());
+	int nx = v->getXForFrame(m_model->getEndFrame());
 	int ny = y;
 
 	SparseTimeValueModel::PointList::const_iterator j = i;
@@ -429,8 +430,8 @@
 
 	if (j != points.end()) {
 	    const SparseTimeValueModel::Point &q(*j);
-	    nx = getXForFrame(q.frame);
-	    ny = getYForValue(q.value);
+	    nx = v->getXForFrame(q.frame);
+	    ny = getYForValue(v, q.value);
 	    haveNext = true;
 	}
 
@@ -444,7 +445,7 @@
 	    QColor colour = QColor::fromHsv(256 - value, value / 2 + 128, value);
 	    paint.setBrush(QColor(colour.red(), colour.green(), colour.blue(),
 				  120));
-	    labelY = m_view->height();
+	    labelY = v->height();
 	} else if (m_plotStyle == PlotLines ||
 		   m_plotStyle == PlotCurve) {
 	    paint.setBrush(Qt::NoBrush);
@@ -521,11 +522,11 @@
 	    if (nx <= x) continue;
 
 	    if (illuminateFrame != p.frame &&
-		(nx < x + 5 || x >= m_view->width() - 1)) {
+		(nx < x + 5 || x >= v->width() - 1)) {
 		paint.setPen(Qt::NoPen);
 	    }
 
-	    paint.drawRect(x, -1, nx - x, m_view->height() + 1);
+	    paint.drawRect(x, -1, nx - x, v->height() + 1);
 	}
 
 ///	if (p.label != "") {
@@ -544,43 +545,43 @@
 }
 
 int
-TimeValueLayer::getVerticalScaleWidth(QPainter &paint) const
+TimeValueLayer::getVerticalScaleWidth(View *v, QPainter &paint) const
 {
     return 100; //!!!
 }
 
 void
-TimeValueLayer::paintVerticalScale(QPainter &paint, QRect rect) const
+TimeValueLayer::paintVerticalScale(View *v, QPainter &paint, QRect rect) const
 {
     if (!m_model) return;
 
-    float v = m_model->getValueMinimum();
-    float inc = (m_model->getValueMaximum() - v) / 10;
+    float val = m_model->getValueMinimum();
+    float inc = (m_model->getValueMaximum() - val) / 10;
 
-    while (v < m_model->getValueMaximum()) {
-	int y = getYForValue(v);
-	QString label = QString("%1").arg(v);
+    while (val < m_model->getValueMaximum()) {
+	int y = getYForValue(v, val);
+	QString label = QString("%1").arg(val);
 	paint.drawLine(100 - 10, y, 100, y);
 	paint.drawText(100 - 15 - paint.fontMetrics().width(label),
 		       y - paint.fontMetrics().height() /2 + paint.fontMetrics().ascent(),
 		       label);
-	v += inc;
+	val += inc;
     }
 
 }
 
 void
-TimeValueLayer::drawStart(QMouseEvent *e)
+TimeValueLayer::drawStart(View *v, QMouseEvent *e)
 {
     std::cerr << "TimeValueLayer::drawStart(" << e->x() << "," << e->y() << ")" << std::endl;
 
     if (!m_model) return;
 
-    long frame = getFrameForX(e->x());
+    long frame = v->getFrameForX(e->x());
     if (frame < 0) frame = 0;
     frame = frame / m_model->getResolution() * m_model->getResolution();
 
-    float value = getValueForY(e->y());
+    float value = getValueForY(v, e->y());
 
     m_editingPoint = SparseTimeValueModel::Point(frame, value, tr("New Point"));
     m_originalPoint = m_editingPoint;
@@ -594,17 +595,17 @@
 }
 
 void
-TimeValueLayer::drawDrag(QMouseEvent *e)
+TimeValueLayer::drawDrag(View *v, QMouseEvent *e)
 {
     std::cerr << "TimeValueLayer::drawDrag(" << e->x() << "," << e->y() << ")" << std::endl;
 
     if (!m_model || !m_editing) return;
 
-    long frame = getFrameForX(e->x());
+    long frame = v->getFrameForX(e->x());
     if (frame < 0) frame = 0;
     frame = frame / m_model->getResolution() * m_model->getResolution();
 
-    float value = getValueForY(e->y());
+    float value = getValueForY(v, e->y());
 
     m_editingCommand->deletePoint(m_editingPoint);
     m_editingPoint.frame = frame;
@@ -613,7 +614,7 @@
 }
 
 void
-TimeValueLayer::drawEnd(QMouseEvent *e)
+TimeValueLayer::drawEnd(View *v, QMouseEvent *e)
 {
     std::cerr << "TimeValueLayer::drawEnd(" << e->x() << "," << e->y() << ")" << std::endl;
     if (!m_model || !m_editing) return;
@@ -623,13 +624,13 @@
 }
 
 void
-TimeValueLayer::editStart(QMouseEvent *e)
+TimeValueLayer::editStart(View *v, QMouseEvent *e)
 {
     std::cerr << "TimeValueLayer::editStart(" << e->x() << "," << e->y() << ")" << std::endl;
 
     if (!m_model) return;
 
-    SparseTimeValueModel::PointList points = getLocalPoints(e->x());
+    SparseTimeValueModel::PointList points = getLocalPoints(v, e->x());
     if (points.empty()) return;
 
     m_editingPoint = *points.begin();
@@ -644,17 +645,17 @@
 }
 
 void
-TimeValueLayer::editDrag(QMouseEvent *e)
+TimeValueLayer::editDrag(View *v, QMouseEvent *e)
 {
     std::cerr << "TimeValueLayer::editDrag(" << e->x() << "," << e->y() << ")" << std::endl;
 
     if (!m_model || !m_editing) return;
 
-    long frame = getFrameForX(e->x());
+    long frame = v->getFrameForX(e->x());
     if (frame < 0) frame = 0;
     frame = frame / m_model->getResolution() * m_model->getResolution();
 
-    float value = getValueForY(e->y());
+    float value = getValueForY(v, e->y());
 
     if (!m_editingCommand) {
 	m_editingCommand = new SparseTimeValueModel::EditCommand(m_model,
@@ -668,7 +669,7 @@
 }
 
 void
-TimeValueLayer::editEnd(QMouseEvent *e)
+TimeValueLayer::editEnd(View *v, QMouseEvent *e)
 {
     std::cerr << "TimeValueLayer::editEnd(" << e->x() << "," << e->y() << ")" << std::endl;
     if (!m_model || !m_editing) return;
--- a/layer/TimeValueLayer.h	Wed Mar 01 18:13:01 2006 +0000
+++ b/layer/TimeValueLayer.h	Thu Mar 02 16:58:49 2006 +0000
@@ -24,26 +24,26 @@
     Q_OBJECT
 
 public:
-    TimeValueLayer(View *w);
+    TimeValueLayer();
 
-    virtual void paint(QPainter &paint, QRect rect) const;
+    virtual void paint(View *v, QPainter &paint, QRect rect) const;
 
-    virtual int getVerticalScaleWidth(QPainter &) const;
-    virtual void paintVerticalScale(QPainter &paint, QRect rect) const;
+    virtual int getVerticalScaleWidth(View *v, QPainter &) const;
+    virtual void paintVerticalScale(View *v, QPainter &paint, QRect rect) const;
 
-    virtual QString getFeatureDescription(QPoint &) const;
+    virtual QString getFeatureDescription(View *v, QPoint &) const;
 
-    virtual bool snapToFeatureFrame(int &frame,
+    virtual bool snapToFeatureFrame(View *v, int &frame,
 				    size_t &resolution,
 				    SnapType snap) const;
 
-    virtual void drawStart(QMouseEvent *);
-    virtual void drawDrag(QMouseEvent *);
-    virtual void drawEnd(QMouseEvent *);
+    virtual void drawStart(View *v, QMouseEvent *);
+    virtual void drawDrag(View *v, QMouseEvent *);
+    virtual void drawEnd(View *v, QMouseEvent *);
 
-    virtual void editStart(QMouseEvent *);
-    virtual void editDrag(QMouseEvent *);
-    virtual void editEnd(QMouseEvent *);
+    virtual void editStart(View *v, QMouseEvent *);
+    virtual void editDrag(View *v, QMouseEvent *);
+    virtual void editEnd(View *v, QMouseEvent *);
 
     virtual void moveSelection(Selection s, size_t newStartFrame);
     virtual void resizeSelection(Selection s, Selection newSize);
@@ -74,7 +74,7 @@
     void setPlotStyle(PlotStyle style);
     PlotStyle getPlotStyle() const { return m_plotStyle; }
 
-    virtual bool isLayerScrollable() const;
+    virtual bool isLayerScrollable(const View *v) const;
 
     virtual bool isLayerEditable() const { return true; }
 
@@ -86,10 +86,10 @@
     void setProperties(const QXmlAttributes &attributes);
 
 protected:
-    int getYForValue(float value) const;
-    float getValueForY(int y) const;
+    int getYForValue(View *, float value) const;
+    float getValueForY(View *, int y) const;
 
-    SparseTimeValueModel::PointList getLocalPoints(int) const;
+    SparseTimeValueModel::PointList getLocalPoints(View *v, int) const;
 
     SparseTimeValueModel *m_model;
     bool m_editing;
--- a/layer/WaveformLayer.cpp	Wed Mar 01 18:13:01 2006 +0000
+++ b/layer/WaveformLayer.cpp	Thu Mar 02 16:58:49 2006 +0000
@@ -24,8 +24,8 @@
 using std::cerr;
 using std::endl;
 
-WaveformLayer::WaveformLayer(View *w) :
-    Layer(w),
+WaveformLayer::WaveformLayer() :
+    Layer(),
     m_model(0),
     m_gain(1.0f),
     m_colour(Qt::black),
@@ -38,7 +38,7 @@
     m_cache(0),
     m_cacheValid(false)
 {
-    m_view->addLayer(this);
+    
 }
 
 WaveformLayer::~WaveformLayer()
@@ -333,14 +333,14 @@
 }    
 
 void
-WaveformLayer::paint(QPainter &viewPainter, QRect rect) const
+WaveformLayer::paint(View *v, QPainter &viewPainter, QRect rect) const
 {
     if (!m_model || !m_model->isOK()) {
 	return;
     }
   
-    long startFrame = m_view->getStartFrame();
-    int zoomLevel = m_view->getZoomLevel();
+    long startFrame = v->getStartFrame();
+    int zoomLevel = v->getZoomLevel();
 
 #ifdef DEBUG_WAVEFORM_PAINT
     Profiler profiler("WaveformLayer::paint", true);
@@ -354,8 +354,8 @@
     channels = getChannelArrangement(minChannel, maxChannel, mergingChannels);
     if (channels == 0) return;
 
-    int w = m_view->width();
-    int h = m_view->height();
+    int w = v->width();
+    int h = v->height();
 
     bool ready = m_model->isReady();
     QPainter *paint;
@@ -379,7 +379,7 @@
 	paint = new QPainter(m_cache);
 
 	paint->setPen(Qt::NoPen);
-	paint->setBrush(m_view->palette().background());
+	paint->setBrush(v->palette().background());
 	paint->drawRect(rect);
 
 	paint->setPen(Qt::black);
@@ -400,10 +400,10 @@
     y1 = rect.bottom();
 
     if (x0 > 0) --x0;
-    if (x1 < m_view->width()) ++x1;
+    if (x1 < v->width()) ++x1;
 
-    long frame0 = getFrameForX(x0);
-    long frame1 = getFrameForX(x1 + 1);
+    long frame0 = v->getFrameForX(x0);
+    long frame1 = v->getFrameForX(x1 + 1);
      
 #ifdef DEBUG_WAVEFORM_PAINT
     std::cerr << "Painting waveform from " << frame0 << " to " << frame1 << " (" << (x1-x0+1) << " pixels at zoom " << zoomLevel << ")" <<  std::endl;
@@ -420,13 +420,13 @@
 	    greys[i] = QColor(level, level, level);
 	}
     } else {
-	int h, s, v;
-	m_colour.getHsv(&h, &s, &v);
+	int hue, sat, val;
+	m_colour.getHsv(&hue, &sat, &val);
 	for (int i = 0; i < 3; ++i) { // 0 lightest, 2 darkest
-	    if (m_view->hasLightBackground()) {
-		greys[i] = QColor::fromHsv(h, s * (i + 1) / 4, v);
+	    if (v->hasLightBackground()) {
+		greys[i] = QColor::fromHsv(hue, sat * (i + 1) / 4, val);
 	    } else {
-		greys[i] = QColor::fromHsv(h, s * (3 - i) / 4, v);
+		greys[i] = QColor::fromHsv(hue, sat * (3 - i) / 4, val);
 	    }
 	}
     }
@@ -434,7 +434,7 @@
     QColor midColour = m_colour;
     if (midColour == Qt::black) {
 	midColour = Qt::gray;
-    } else if (m_view->hasLightBackground()) {
+    } else if (v->hasLightBackground()) {
 	midColour = midColour.light(150);
     } else {
 	midColour = midColour.light(50);
@@ -660,7 +660,7 @@
 
     if (m_aggressive) {
 
-	if (ready && rect == m_view->rect()) {
+	if (ready && rect == v->rect()) {
 	    m_cacheValid = true;
 	    m_cacheZoomLevel = zoomLevel;
 	}
@@ -671,14 +671,14 @@
 }
 
 QString
-WaveformLayer::getFeatureDescription(QPoint &pos) const
+WaveformLayer::getFeatureDescription(View *v, QPoint &pos) const
 {
     int x = pos.x();
 
     if (!m_model || !m_model->isOK()) return "";
 
-    long f0 = getFrameForX(x);
-    long f1 = getFrameForX(x + 1);
+    long f0 = v->getFrameForX(x);
+    long f1 = v->getFrameForX(x + 1);
 
     if (f0 < 0) f0 = 0;
     if (f1 <= f0) return "";
@@ -705,7 +705,7 @@
 
     for (size_t ch = minChannel; ch <= maxChannel; ++ch) {
 
-	size_t blockSize = m_view->getZoomLevel();
+	size_t blockSize = v->getZoomLevel();
 	RangeSummarisableTimeValueModel::RangeBlock ranges =
 	    m_model->getRanges(ch, f0, f1, blockSize);
 
@@ -739,7 +739,7 @@
 }
 
 int
-WaveformLayer::getVerticalScaleWidth(QPainter &paint) const
+WaveformLayer::getVerticalScaleWidth(View *v, QPainter &paint) const
 {
     if (m_scale == LinearScale) {
 	return paint.fontMetrics().width("0.0") + 13;
@@ -750,7 +750,7 @@
 }
 
 void
-WaveformLayer::paintVerticalScale(QPainter &paint, QRect rect) const
+WaveformLayer::paintVerticalScale(View *v, QPainter &paint, QRect rect) const
 {
     if (!m_model || !m_model->isOK()) {
 	return;
--- a/layer/WaveformLayer.h	Wed Mar 01 18:13:01 2006 +0000
+++ b/layer/WaveformLayer.h	Thu Mar 02 16:58:49 2006 +0000
@@ -26,17 +26,17 @@
     Q_OBJECT
 
 public:
-    WaveformLayer(View *w);
+    WaveformLayer();
     ~WaveformLayer();
 
     virtual const ZoomConstraint *getZoomConstraint() const { return m_model; }
     virtual const Model *getModel() const { return m_model; }
-    virtual void paint(QPainter &paint, QRect rect) const;
+    virtual void paint(View *v, QPainter &paint, QRect rect) const;
 
-    virtual QString getFeatureDescription(QPoint &) const;
+    virtual QString getFeatureDescription(View *v, QPoint &) const;
 
-    virtual int getVerticalScaleWidth(QPainter &) const;
-    virtual void paintVerticalScale(QPainter &paint, QRect rect) const;
+    virtual int getVerticalScaleWidth(View *v, QPainter &) const;
+    virtual void paintVerticalScale(View *v, QPainter &paint, QRect rect) const;
 
     void setModel(const RangeSummarisableTimeValueModel *model);
 
--- a/widgets/LayerTree.cpp	Wed Mar 01 18:13:01 2006 +0000
+++ b/widgets/LayerTree.cpp	Thu Mar 02 16:58:49 2006 +0000
@@ -135,7 +135,8 @@
 
     Layer *layer = dynamic_cast<Layer *>(obj);
     if (layer) {
-	const View *view = layer->getView();
+//!!!	const View *view = layer->getView();
+	const View *view = 0;
 	Pane *pane = const_cast<Pane *>(dynamic_cast<const Pane *>(view));
 	if (pane) {
 	    // need index of pane in pane stack
--- a/widgets/Pane.cpp	Wed Mar 01 18:13:01 2006 +0000
+++ b/widgets/Pane.cpp	Thu Mar 02 16:58:49 2006 +0000
@@ -39,7 +39,7 @@
 }
 
 bool
-Pane::shouldIlluminateLocalFeatures(const Layer *layer, QPoint &pos)
+Pane::shouldIlluminateLocalFeatures(const Layer *layer, QPoint &pos) const
 {
     QPoint discard;
     bool b0, b1;
@@ -57,7 +57,7 @@
 bool
 Pane::shouldIlluminateLocalSelection(QPoint &pos,
 				     bool &closeToLeft,
-				     bool &closeToRight)
+				     bool &closeToRight) const
 {
     if (m_identifyFeatures &&
 	m_manager &&
@@ -141,7 +141,7 @@
 	    waveformModel = (*vi)->getModel();
 	}
 
-	int sw = (*vi)->getVerticalScaleWidth(paint);
+	int sw = (*vi)->getVerticalScaleWidth(this, paint);
 
 	if (sw > 0 && r.left() < sw) {
 
@@ -155,7 +155,7 @@
 	    paint.drawRect(0, 0, sw, height());
 
 	    paint.setBrush(Qt::NoBrush);
-	    (*vi)->paintVerticalScale(paint, QRect(0, 0, sw, height()));
+	    (*vi)->paintVerticalScale(this, paint, QRect(0, 0, sw, height()));
 
 	    paint.restore();
 	}
@@ -163,7 +163,7 @@
 	if (m_identifyFeatures) {
 
 	    QPoint pos = m_identifyPoint;
-	    QString desc = (*vi)->getFeatureDescription(pos);
+	    QString desc = (*vi)->getFeatureDescription(this, pos);
 	    
 	    if (desc != "") {
 
@@ -364,7 +364,7 @@
 }
 
 Selection
-Pane::getSelectionAt(int x, bool &closeToLeftEdge, bool &closeToRightEdge)
+Pane::getSelectionAt(int x, bool &closeToLeftEdge, bool &closeToRightEdge) const
 {
     closeToLeftEdge = closeToRightEdge = false;
 
@@ -446,7 +446,8 @@
 	
 	    Layer *layer = getSelectedLayer();
 	    if (layer) {
-		layer->snapToFeatureFrame(snapFrame, resolution, Layer::SnapLeft);
+		layer->snapToFeatureFrame(this, snapFrame,
+					  resolution, Layer::SnapLeft);
 	    }
 	    
 	    if (snapFrame < 0) snapFrame = 0;
@@ -466,7 +467,7 @@
 
 	Layer *layer = getSelectedLayer();
 	if (layer && layer->isLayerEditable()) {
-	    layer->drawStart(e);
+	    layer->drawStart(this, e);
 	}
 
     } else if (mode == ViewManager::EditMode) {
@@ -474,7 +475,7 @@
 	if (!editSelectionStart(e)) {
 	    Layer *layer = getSelectedLayer();
 	    if (layer && layer->isLayerEditable()) {
-		layer->editStart(e);
+		layer->editStart(this, e);
 	    }
 	}
     }
@@ -557,7 +558,7 @@
 
 	Layer *layer = getSelectedLayer();
 	if (layer && layer->isLayerEditable()) {
-	    layer->drawEnd(e);
+	    layer->drawEnd(this, e);
 	    update();
 	}
 
@@ -566,7 +567,7 @@
 	if (!editSelectionEnd(e)) {
 	    Layer *layer = getSelectedLayer();
 	    if (layer && layer->isLayerEditable()) {
-		layer->editEnd(e);
+		layer->editEnd(this, e);
 		update();
 	    }
 	}
@@ -652,8 +653,10 @@
 	
 	Layer *layer = getSelectedLayer();
 	if (layer) {
-	    layer->snapToFeatureFrame(snapFrameLeft, resolution, Layer::SnapLeft);
-	    layer->snapToFeatureFrame(snapFrameRight, resolution, Layer::SnapRight);
+	    layer->snapToFeatureFrame(this, snapFrameLeft,
+				      resolution, Layer::SnapLeft);
+	    layer->snapToFeatureFrame(this, snapFrameRight,
+				      resolution, Layer::SnapRight);
 	}
 	
 //	std::cerr << "snap: frame = " << mouseFrame << ", start frame = " << m_selectionStartFrame << ", left = " << snapFrameLeft << ", right = " << snapFrameRight << std::endl;
@@ -706,7 +709,7 @@
 
 	Layer *layer = getSelectedLayer();
 	if (layer && layer->isLayerEditable()) {
-	    layer->drawDrag(e);
+	    layer->drawDrag(this, e);
 	}
 
     } else if (mode == ViewManager::EditMode) {
@@ -714,7 +717,7 @@
 	if (!editSelectionDrag(e)) {
 	    Layer *layer = getSelectedLayer();
 	    if (layer && layer->isLayerEditable()) {
-		layer->editDrag(e);
+		layer->editDrag(this, e);
 	    }
 	}
     }
@@ -737,7 +740,7 @@
 
 	Layer *layer = getSelectedLayer();
 	if (layer && layer->isLayerEditable()) {
-	    layer->editOpen(e);
+	    layer->editOpen(this, e);
 	}
     }
 }
--- a/widgets/Pane.h	Wed Mar 01 18:13:01 2006 +0000
+++ b/widgets/Pane.h	Thu Mar 02 16:58:49 2006 +0000
@@ -30,10 +30,11 @@
     Pane(QWidget *parent = 0);
     virtual QString getPropertyContainerIconName() const { return "pane"; }
 
-    virtual bool shouldIlluminateLocalFeatures(const Layer *layer, QPoint &pos);
+    virtual bool shouldIlluminateLocalFeatures(const Layer *layer,
+					       QPoint &pos) const;
     virtual bool shouldIlluminateLocalSelection(QPoint &pos,
 						bool &closeToLeft,
-						bool &closeToRight);
+						bool &closeToRight) const;
 
     void setCentreLineVisible(bool visible);
     bool getCentreLineVisible() const { return m_centreLineVisible; }
@@ -56,7 +57,7 @@
     virtual void leaveEvent(QEvent *e);
     virtual void wheelEvent(QWheelEvent *e);
 
-    Selection getSelectionAt(int x, bool &closeToLeft, bool &closeToRight);
+    Selection getSelectionAt(int x, bool &closeToLeft, bool &closeToRight) const;
 
     bool editSelectionStart(QMouseEvent *e);
     bool editSelectionDrag(QMouseEvent *e);
--- a/widgets/PropertyBox.cpp	Wed Mar 01 18:13:01 2006 +0000
+++ b/widgets/PropertyBox.cpp	Thu Mar 02 16:58:49 2006 +0000
@@ -122,8 +122,8 @@
 
 	LEDButton *showButton = new LEDButton(Qt::blue);
 	layout->addWidget(showButton);
-	connect(showButton, SIGNAL(stateChanged(bool)),
-		layer, SLOT(showLayer(bool)));
+//!!!	connect(showButton, SIGNAL(stateChanged(bool)),
+//		layer, SLOT(showLayer(bool)));
 	layout->setAlignment(showButton, Qt::AlignVCenter);
     }