annotate base/Layer.h @ 10:ec6886f0e673

* Fix update and play limits for play-selection mode when not looping * Fix playback in loop mode when no selection -- but the GUI update for this is still wrong on the flyback * Various fixes and improvements to making selections, particularly during playback * Draw selection under non-opaque non-scrollable layers, so as to improve cacheing * Show selection limits as text when drawing selection * Allow user to find missing audio files when loading session * Cross-fade selections when in play-selection mode -- mostly. We don't cross-fade on a processing block boundary, and unfortunately with short selections the selection boundary is quite likely to coincide with a block boundary.
author Chris Cannam
date Wed, 25 Jan 2006 17:46:28 +0000
parents 214054a0d8b8
children f67ddc287bc3
rev   line source
Chris@0 1
Chris@0 2 /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 3
Chris@0 4 /*
Chris@0 5 A waveform viewer and audio annotation editor.
Chris@2 6 Chris Cannam, Queen Mary University of London, 2005-2006
Chris@0 7
Chris@0 8 This is experimental software. Not for distribution.
Chris@0 9 */
Chris@0 10
Chris@0 11 #ifndef _VIEWER_H_
Chris@0 12 #define _VIEWER_H_
Chris@0 13
Chris@0 14 #include "PropertyContainer.h"
Chris@3 15 #include "XmlExportable.h"
Chris@0 16
Chris@0 17 #include <QObject>
Chris@0 18 #include <QRect>
Chris@6 19 #include <QXmlAttributes>
Chris@0 20
Chris@0 21 class ZoomConstraint;
Chris@0 22 class Model;
Chris@0 23 class QPainter;
Chris@0 24 class View;
Chris@0 25
Chris@0 26 /**
Chris@0 27 * The base class for visual representations of the data found in a
Chris@0 28 * Model. Layers are expected to be able to draw themselves onto a
Chris@0 29 * View, and may also be editable.
Chris@0 30 */
Chris@0 31
Chris@0 32 class Layer : public QObject,
Chris@3 33 public PropertyContainer,
Chris@3 34 public XmlExportable
Chris@0 35 {
Chris@0 36 Q_OBJECT
Chris@0 37
Chris@0 38 public:
Chris@0 39 Layer(View *w);
Chris@0 40 virtual ~Layer();
Chris@0 41
Chris@0 42 virtual const Model *getModel() const = 0;
Chris@0 43 virtual const ZoomConstraint *getZoomConstraint() const { return 0; }
Chris@0 44 virtual void paint(QPainter &, QRect) const = 0;
Chris@0 45
Chris@0 46 enum VerticalPosition {
Chris@0 47 PositionTop, PositionMiddle, PositionBottom
Chris@0 48 };
Chris@0 49 virtual VerticalPosition getPreferredTimeRulerPosition() const {
Chris@0 50 return PositionMiddle;
Chris@0 51 }
Chris@0 52 virtual VerticalPosition getPreferredFrameCountPosition() const {
Chris@0 53 return PositionBottom;
Chris@0 54 }
Chris@0 55
Chris@0 56 virtual QString getPropertyContainerName() const {
Chris@0 57 return objectName();
Chris@0 58 }
Chris@0 59
Chris@0 60 virtual int getVerticalScaleWidth(QPainter &) const { return 0; }
Chris@0 61 virtual void paintVerticalScale(QPainter &, QRect) const { }
Chris@0 62
Chris@8 63 //!!! I don't like these. The layer should return a structured
Chris@8 64 //string-based description list and the pane should render it
Chris@8 65 //itself.
Chris@8 66
Chris@0 67 virtual QRect getFeatureDescriptionRect(QPainter &, QPoint) const {
Chris@0 68 return QRect(0, 0, 0, 0);
Chris@0 69 }
Chris@0 70 virtual void paintLocalFeatureDescription(QPainter &, QRect, QPoint) const {
Chris@0 71 }
Chris@0 72
Chris@8 73 //!!! We also need a method (like the vertical scale method) for
Chris@8 74 //drawing additional scales like a colour scale. That is, unless
Chris@8 75 //all applicable layers can actually do this from
Chris@8 76 //paintVerticalScale as well?
Chris@8 77
Chris@8 78 // Select mode:
Chris@8 79 //
Chris@8 80 //!!! Next, a method that gets the frame of the nearest feature in
Chris@8 81 //a particular snap direction. This would be used for selection
Chris@8 82 //mode, where we're selecting from the waveform based on feature
Chris@8 83 //location. Do we need multi-select on features as well? This is
Chris@8 84 //an issue; if you select a feature are you selecting that feature
Chris@8 85 //(in which case what do you do with it?) or a section of the
Chris@8 86 //underlying waveform?
Chris@8 87
Chris@8 88 virtual int getNearestFeatureFrame(int frame,
Chris@8 89 size_t &resolution,
Chris@8 90 bool snapRight = true) const {
Chris@8 91 resolution = 1;
Chris@8 92 return frame;
Chris@8 93 }
Chris@8 94
Chris@8 95 // Paint and edit modes:
Chris@8 96 //
Chris@8 97 // Layer needs to get actual mouse events, I guess. Paint mode is
Chris@8 98 // probably the easier.
Chris@8 99
Chris@8 100 // Text mode:
Chris@8 101 //
Chris@8 102 // Label nearest feature. We need to get the feature coordinates
Chris@8 103 // and current label from the layer, and then the pane can pop up
Chris@8 104 // a little text entry dialog at the right location. Or we edit
Chris@8 105 // in place? Probably the dialog is easier.
Chris@8 106
Chris@0 107 /**
Chris@0 108 * This should return true if the view can safely be scrolled
Chris@0 109 * automatically by the widget (simply copying the existing data
Chris@0 110 * and then refreshing the exposed area) without altering its
Chris@0 111 * meaning. For the widget as a whole this is usually not
Chris@0 112 * possible because of invariant (non-scrolling) material
Chris@0 113 * displayed over the top, but the widget may be able to optimise
Chris@0 114 * scrolling better if it is known that individual views can be
Chris@0 115 * scrolled safely in this way.
Chris@0 116 */
Chris@0 117 virtual bool isLayerScrollable() const { return true; }
Chris@0 118
Chris@0 119 /**
Chris@10 120 * This should return true if the layer completely obscures any
Chris@10 121 * underlying layers. It's used to determine whether the view can
Chris@10 122 * safely draw any selection rectangles under the layer instead of
Chris@10 123 * over it, in the case where the layer is not scrollable and
Chris@10 124 * therefore needs to be redrawn each time (so that the selection
Chris@10 125 * rectangle can be cached).
Chris@10 126 */
Chris@10 127 virtual bool isLayerOpaque() const { return false; }
Chris@10 128
Chris@10 129 /**
Chris@0 130 * Return the proportion of background work complete in drawing
Chris@0 131 * this view, as a percentage -- in most cases this will be the
Chris@0 132 * value returned by pointer from a call to the underlying model's
Chris@0 133 * isReady(int *) call. The widget may choose to show a progress
Chris@0 134 * meter if it finds that this returns < 100 at any given moment.
Chris@0 135 */
Chris@0 136 virtual int getCompletion() const { return 100; }
Chris@0 137
Chris@0 138 virtual void setObjectName(const QString &name);
Chris@0 139
Chris@7 140 /**
Chris@7 141 * Convert the layer's data (though not those of the model it
Chris@7 142 * refers to) into an XML string for file output. This class
Chris@7 143 * implements the basic name/type/model-id output; subclasses will
Chris@7 144 * typically call this superclass implementation with extra
Chris@7 145 * attributes describing their particular properties.
Chris@7 146 */
Chris@3 147 virtual QString toXmlString(QString indent = "",
Chris@3 148 QString extraAttributes = "") const;
Chris@3 149
Chris@7 150 /**
Chris@7 151 * Set the particular properties of a layer (those specific to the
Chris@7 152 * subclass) from a set of XML attributes. This is the effective
Chris@7 153 * inverse of the toXmlString method.
Chris@7 154 */
Chris@6 155 virtual void setProperties(const QXmlAttributes &) = 0;
Chris@6 156
Chris@0 157 signals:
Chris@0 158 void modelChanged();
Chris@0 159 void modelCompletionChanged();
Chris@0 160 void modelChanged(size_t startFrame, size_t endFrame);
Chris@0 161 void modelReplaced();
Chris@0 162
Chris@0 163 void layerParametersChanged();
Chris@0 164 void layerNameChanged();
Chris@0 165
Chris@0 166 protected:
Chris@0 167 View *m_view;
Chris@0 168 };
Chris@0 169
Chris@0 170 #endif
Chris@0 171