Chris@916
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@916
|
2
|
Chris@916
|
3 /*
|
Chris@916
|
4 Sonic Visualiser
|
Chris@916
|
5 An audio file viewer and annotation editor.
|
Chris@916
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@916
|
7
|
Chris@916
|
8 This program is free software; you can redistribute it and/or
|
Chris@916
|
9 modify it under the terms of the GNU General Public License as
|
Chris@916
|
10 published by the Free Software Foundation; either version 2 of the
|
Chris@916
|
11 License, or (at your option) any later version. See the file
|
Chris@916
|
12 COPYING included with this distribution for more information.
|
Chris@916
|
13 */
|
Chris@916
|
14
|
Chris@916
|
15 #ifndef LAYER_GEOMETRY_PROVIDER_H
|
Chris@916
|
16 #define LAYER_GEOMETRY_PROVIDER_H
|
Chris@916
|
17
|
Chris@916
|
18 #include "base/BaseTypes.h"
|
Chris@916
|
19
|
Chris@1030
|
20 #include <QMutex>
|
Chris@1030
|
21 #include <QMutexLocker>
|
Chris@1031
|
22 #include <QPainter>
|
Chris@1030
|
23
|
Chris@916
|
24 class ViewManager;
|
Chris@918
|
25 class View;
|
Chris@916
|
26 class Layer;
|
Chris@916
|
27
|
Chris@916
|
28 class LayerGeometryProvider
|
Chris@916
|
29 {
|
Chris@1044
|
30 protected:
|
Chris@1044
|
31 static int getNextId() {
|
Chris@1030
|
32 static QMutex idMutex;
|
Chris@1030
|
33 static int nextId = 1;
|
Chris@1044
|
34 static int maxId = INT_MAX;
|
Chris@1030
|
35 QMutexLocker locker(&idMutex);
|
Chris@1044
|
36 int id = nextId;
|
Chris@1044
|
37 if (nextId == maxId) {
|
Chris@1044
|
38 // we don't expect this to happen in the lifetime of a
|
Chris@1044
|
39 // process, but it would be undefined behaviour if it did
|
Chris@1044
|
40 // since we're using a signed int, so we should really
|
Chris@1044
|
41 // guard for it...
|
Chris@1044
|
42 nextId = 1;
|
Chris@1044
|
43 } else {
|
Chris@1044
|
44 nextId++;
|
Chris@1044
|
45 }
|
Chris@1044
|
46 return id;
|
Chris@1044
|
47 }
|
Chris@1044
|
48
|
Chris@1044
|
49 public:
|
Chris@1044
|
50 LayerGeometryProvider() { }
|
Chris@1030
|
51
|
Chris@1030
|
52 /**
|
Chris@1044
|
53 * Retrieve the id of this object.
|
Chris@1030
|
54 */
|
Chris@1044
|
55 virtual int getId() const = 0;
|
Chris@1030
|
56
|
Chris@916
|
57 /**
|
Chris@916
|
58 * Retrieve the first visible sample frame on the widget.
|
Chris@916
|
59 * This is a calculated value based on the centre-frame, widget
|
Chris@916
|
60 * width and zoom level. The result may be negative.
|
Chris@916
|
61 */
|
Chris@916
|
62 virtual sv_frame_t getStartFrame() const = 0;
|
Chris@916
|
63
|
Chris@916
|
64 /**
|
Chris@916
|
65 * Return the centre frame of the visible widget. This is an
|
Chris@916
|
66 * exact value that does not depend on the zoom block size. Other
|
Chris@916
|
67 * frame values (start, end) are calculated from this based on the
|
Chris@916
|
68 * zoom and other factors.
|
Chris@916
|
69 */
|
Chris@916
|
70 virtual sv_frame_t getCentreFrame() const = 0;
|
Chris@916
|
71
|
Chris@916
|
72 /**
|
Chris@916
|
73 * Retrieve the last visible sample frame on the widget.
|
Chris@916
|
74 * This is a calculated value based on the centre-frame, widget
|
Chris@916
|
75 * width and zoom level.
|
Chris@916
|
76 */
|
Chris@916
|
77 virtual sv_frame_t getEndFrame() const = 0;
|
Chris@916
|
78
|
Chris@916
|
79 /**
|
Chris@916
|
80 * Return the pixel x-coordinate corresponding to a given sample
|
Chris@916
|
81 * frame (which may be negative).
|
Chris@916
|
82 */
|
Chris@916
|
83 virtual int getXForFrame(sv_frame_t frame) const = 0;
|
Chris@916
|
84
|
Chris@916
|
85 /**
|
Chris@916
|
86 * Return the closest frame to the given pixel x-coordinate.
|
Chris@916
|
87 */
|
Chris@916
|
88 virtual sv_frame_t getFrameForX(int x) const = 0;
|
Chris@916
|
89
|
Chris@919
|
90 virtual sv_frame_t getModelsStartFrame() const = 0;
|
Chris@919
|
91 virtual sv_frame_t getModelsEndFrame() const = 0;
|
Chris@919
|
92
|
Chris@916
|
93 /**
|
Chris@1030
|
94 * Return the closest pixel x-coordinate corresponding to a given
|
Chris@1030
|
95 * view x-coordinate.
|
Chris@1030
|
96 */
|
Chris@1030
|
97 virtual int getXForViewX(int viewx) const = 0;
|
Chris@1030
|
98
|
Chris@1030
|
99 /**
|
Chris@1030
|
100 * Return the closest view x-coordinate corresponding to a given
|
Chris@1030
|
101 * pixel x-coordinate.
|
Chris@1030
|
102 */
|
Chris@1030
|
103 virtual int getViewXForX(int x) const = 0;
|
Chris@1030
|
104
|
Chris@1030
|
105 /**
|
Chris@1085
|
106 * Return the (maybe fractional) pixel y-coordinate corresponding
|
Chris@1085
|
107 * to a given frequency, if the frequency range is as specified.
|
Chris@1085
|
108 * This does not imply any policy about layer frequency ranges,
|
Chris@1085
|
109 * but it might be useful for layers to match theirs up if
|
Chris@1085
|
110 * desired.
|
Chris@916
|
111 *
|
Chris@916
|
112 * Not thread-safe in logarithmic mode. Call only from GUI thread.
|
Chris@916
|
113 */
|
Chris@1085
|
114 virtual double getYForFrequency(double frequency,
|
Chris@1085
|
115 double minFreq, double maxFreq,
|
Chris@916
|
116 bool logarithmic) const = 0;
|
Chris@916
|
117
|
Chris@916
|
118 /**
|
Chris@1085
|
119 * Return the closest frequency to the given (maybe fractional)
|
Chris@1085
|
120 * pixel y-coordinate, if the frequency range is as specified.
|
Chris@916
|
121 *
|
Chris@916
|
122 * Not thread-safe in logarithmic mode. Call only from GUI thread.
|
Chris@916
|
123 */
|
Chris@1085
|
124 virtual double getFrequencyForY(double y,
|
Chris@1085
|
125 double minFreq, double maxFreq,
|
Chris@1082
|
126 bool logarithmic) const = 0;
|
Chris@916
|
127
|
Chris@918
|
128 virtual int getTextLabelHeight(const Layer *layer, QPainter &) const = 0;
|
Chris@918
|
129
|
Chris@918
|
130 virtual bool getValueExtents(QString unit, double &min, double &max,
|
Chris@918
|
131 bool &log) const = 0;
|
Chris@918
|
132
|
Chris@916
|
133 /**
|
Chris@916
|
134 * Return the zoom level, i.e. the number of frames per pixel
|
Chris@916
|
135 */
|
Chris@916
|
136 virtual int getZoomLevel() const = 0;
|
Chris@916
|
137
|
Chris@916
|
138 /**
|
Chris@916
|
139 * To be called from a layer, to obtain the extent of the surface
|
Chris@916
|
140 * that the layer is currently painting to. This may be the extent
|
Chris@916
|
141 * of the view (if 1x display scaling is in effect) or of a larger
|
Chris@916
|
142 * cached pixmap (if greater display scaling is in effect).
|
Chris@916
|
143 */
|
Chris@916
|
144 virtual QRect getPaintRect() const = 0;
|
Chris@916
|
145
|
Chris@916
|
146 virtual QSize getPaintSize() const { return getPaintRect().size(); }
|
Chris@916
|
147 virtual int getPaintWidth() const { return getPaintRect().width(); }
|
Chris@916
|
148 virtual int getPaintHeight() const { return getPaintRect().height(); }
|
Chris@916
|
149
|
Chris@916
|
150 virtual bool hasLightBackground() const = 0;
|
Chris@916
|
151 virtual QColor getForeground() const = 0;
|
Chris@916
|
152 virtual QColor getBackground() const = 0;
|
Chris@916
|
153
|
Chris@916
|
154 virtual ViewManager *getViewManager() const = 0;
|
Chris@916
|
155
|
Chris@916
|
156 virtual bool shouldIlluminateLocalFeatures(const Layer *, QPoint &) const = 0;
|
Chris@919
|
157 virtual bool shouldShowFeatureLabels() const = 0;
|
Chris@916
|
158
|
Chris@916
|
159 virtual void drawMeasurementRect(QPainter &p, const Layer *,
|
Chris@916
|
160 QRect rect, bool focus) const = 0;
|
Chris@916
|
161
|
Chris@1030
|
162 virtual void updatePaintRect(QRect r) = 0;
|
Chris@1030
|
163
|
Chris@918
|
164 virtual View *getView() = 0;
|
Chris@918
|
165 virtual const View *getView() const = 0;
|
Chris@916
|
166 };
|
Chris@916
|
167
|
Chris@916
|
168 #endif
|