annotate base/Layer.h @ 20:742e6882e187

* Refactor sparse models. Previously the 1D and time-value models duplicated a lot of code; now there is a base class (SparseModel) templated on the stored point type, and the subclasses define point types with the necessary characteristics. * Add NoteModel, a new SparseModel subclass. * Reorganise local feature description display. Instead of asking the layer to draw its own, just query it for a textual description and draw that in Pane. Greatly simplifies this part of the layer code. * Add local feature descriptions to colour 3D plot and waveform layers. * Add pitch in MIDI-pitch-and-cents to spectrogram layer. * Give AudioGenerator its own mutex to shorten lock times in CallbackPlaySource. * Minor adjustments to layers menu &c
author Chris Cannam
date Thu, 02 Feb 2006 16:10:19 +0000
parents 4563a72c1d8b
children 6ace4286ba06
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@12 25 class QMouseEvent;
Chris@0 26
Chris@0 27 /**
Chris@0 28 * The base class for visual representations of the data found in a
Chris@0 29 * Model. Layers are expected to be able to draw themselves onto a
Chris@0 30 * View, and may also be editable.
Chris@0 31 */
Chris@0 32
Chris@0 33 class Layer : public QObject,
Chris@3 34 public PropertyContainer,
Chris@3 35 public XmlExportable
Chris@0 36 {
Chris@0 37 Q_OBJECT
Chris@0 38
Chris@0 39 public:
Chris@0 40 Layer(View *w);
Chris@0 41 virtual ~Layer();
Chris@0 42
Chris@0 43 virtual const Model *getModel() const = 0;
Chris@0 44 virtual const ZoomConstraint *getZoomConstraint() const { return 0; }
Chris@0 45 virtual void paint(QPainter &, QRect) const = 0;
Chris@0 46
Chris@0 47 enum VerticalPosition {
Chris@0 48 PositionTop, PositionMiddle, PositionBottom
Chris@0 49 };
Chris@0 50 virtual VerticalPosition getPreferredTimeRulerPosition() const {
Chris@0 51 return PositionMiddle;
Chris@0 52 }
Chris@0 53 virtual VerticalPosition getPreferredFrameCountPosition() const {
Chris@0 54 return PositionBottom;
Chris@0 55 }
Chris@0 56
Chris@12 57 virtual QString getPropertyContainerIconName() const;
Chris@12 58
Chris@0 59 virtual QString getPropertyContainerName() const {
Chris@0 60 return objectName();
Chris@0 61 }
Chris@0 62
Chris@0 63 virtual int getVerticalScaleWidth(QPainter &) const { return 0; }
Chris@0 64 virtual void paintVerticalScale(QPainter &, QRect) const { }
Chris@0 65
Chris@20 66 virtual QString getFeatureDescription(QPoint &) const {
Chris@20 67 return "";
Chris@0 68 }
Chris@0 69
Chris@8 70 //!!! We also need a method (like the vertical scale method) for
Chris@8 71 //drawing additional scales like a colour scale. That is, unless
Chris@8 72 //all applicable layers can actually do this from
Chris@8 73 //paintVerticalScale as well?
Chris@8 74
Chris@8 75 // Select mode:
Chris@8 76 //
Chris@8 77 //!!! Next, a method that gets the frame of the nearest feature in
Chris@8 78 //a particular snap direction. This would be used for selection
Chris@8 79 //mode, where we're selecting from the waveform based on feature
Chris@8 80 //location. Do we need multi-select on features as well? This is
Chris@8 81 //an issue; if you select a feature are you selecting that feature
Chris@8 82 //(in which case what do you do with it?) or a section of the
Chris@8 83 //underlying waveform?
Chris@8 84
Chris@8 85 virtual int getNearestFeatureFrame(int frame,
Chris@8 86 size_t &resolution,
Chris@8 87 bool snapRight = true) const {
Chris@8 88 resolution = 1;
Chris@8 89 return frame;
Chris@8 90 }
Chris@8 91
Chris@12 92 // Draw and edit modes:
Chris@8 93 //
Chris@12 94 // Layer needs to get actual mouse events, I guess. Draw mode is
Chris@8 95 // probably the easier.
Chris@8 96
Chris@13 97 virtual void drawStart(QMouseEvent *) { }
Chris@13 98 virtual void drawDrag(QMouseEvent *) { }
Chris@13 99 virtual void drawEnd(QMouseEvent *) { }
Chris@13 100
Chris@13 101 virtual void editStart(QMouseEvent *) { }
Chris@13 102 virtual void editDrag(QMouseEvent *) { }
Chris@13 103 virtual void editEnd(QMouseEvent *) { }
Chris@12 104
Chris@8 105 // Text mode:
Chris@8 106 //
Chris@8 107 // Label nearest feature. We need to get the feature coordinates
Chris@8 108 // and current label from the layer, and then the pane can pop up
Chris@8 109 // a little text entry dialog at the right location. Or we edit
Chris@8 110 // in place? Probably the dialog is easier.
Chris@8 111
Chris@0 112 /**
Chris@0 113 * This should return true if the view can safely be scrolled
Chris@0 114 * automatically by the widget (simply copying the existing data
Chris@0 115 * and then refreshing the exposed area) without altering its
Chris@0 116 * meaning. For the widget as a whole this is usually not
Chris@0 117 * possible because of invariant (non-scrolling) material
Chris@0 118 * displayed over the top, but the widget may be able to optimise
Chris@0 119 * scrolling better if it is known that individual views can be
Chris@0 120 * scrolled safely in this way.
Chris@0 121 */
Chris@0 122 virtual bool isLayerScrollable() const { return true; }
Chris@0 123
Chris@0 124 /**
Chris@10 125 * This should return true if the layer completely obscures any
Chris@10 126 * underlying layers. It's used to determine whether the view can
Chris@10 127 * safely draw any selection rectangles under the layer instead of
Chris@10 128 * over it, in the case where the layer is not scrollable and
Chris@10 129 * therefore needs to be redrawn each time (so that the selection
Chris@10 130 * rectangle can be cached).
Chris@10 131 */
Chris@10 132 virtual bool isLayerOpaque() const { return false; }
Chris@10 133
Chris@10 134 /**
Chris@18 135 * This should return true if the layer can be edited by the user.
Chris@18 136 * If this is the case, the appropriate edit tools may be made
Chris@18 137 * available by the application and the layer's drawStart/Drag/End
Chris@18 138 * and editStart/Drag/End methods should be implemented.
Chris@18 139 */
Chris@18 140 virtual bool isLayerEditable() const { return false; }
Chris@18 141
Chris@18 142 /**
Chris@0 143 * Return the proportion of background work complete in drawing
Chris@0 144 * this view, as a percentage -- in most cases this will be the
Chris@0 145 * value returned by pointer from a call to the underlying model's
Chris@0 146 * isReady(int *) call. The widget may choose to show a progress
Chris@0 147 * meter if it finds that this returns < 100 at any given moment.
Chris@0 148 */
Chris@0 149 virtual int getCompletion() const { return 100; }
Chris@0 150
Chris@0 151 virtual void setObjectName(const QString &name);
Chris@0 152
Chris@7 153 /**
Chris@15 154 * Return the pixel x-coordinate corresponding to a given sample
Chris@15 155 * frame (which may be negative).
Chris@15 156 */
Chris@15 157 int getXForFrame(long frame) const;
Chris@15 158
Chris@15 159 /**
Chris@15 160 * Return the closest frame to the given pixel x-coordinate.
Chris@15 161 */
Chris@15 162 long getFrameForX(int x) const;
Chris@15 163
Chris@15 164 /**
Chris@7 165 * Convert the layer's data (though not those of the model it
Chris@7 166 * refers to) into an XML string for file output. This class
Chris@7 167 * implements the basic name/type/model-id output; subclasses will
Chris@7 168 * typically call this superclass implementation with extra
Chris@7 169 * attributes describing their particular properties.
Chris@7 170 */
Chris@3 171 virtual QString toXmlString(QString indent = "",
Chris@3 172 QString extraAttributes = "") const;
Chris@3 173
Chris@7 174 /**
Chris@7 175 * Set the particular properties of a layer (those specific to the
Chris@7 176 * subclass) from a set of XML attributes. This is the effective
Chris@7 177 * inverse of the toXmlString method.
Chris@7 178 */
Chris@6 179 virtual void setProperties(const QXmlAttributes &) = 0;
Chris@6 180
Chris@0 181 signals:
Chris@0 182 void modelChanged();
Chris@0 183 void modelCompletionChanged();
Chris@0 184 void modelChanged(size_t startFrame, size_t endFrame);
Chris@0 185 void modelReplaced();
Chris@0 186
Chris@0 187 void layerParametersChanged();
Chris@0 188 void layerNameChanged();
Chris@0 189
Chris@0 190 protected:
Chris@0 191 View *m_view;
Chris@0 192 };
Chris@0 193
Chris@0 194 #endif
Chris@0 195