Chris@127
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@127
|
2
|
Chris@127
|
3 /*
|
Chris@127
|
4 Sonic Visualiser
|
Chris@127
|
5 An audio file viewer and annotation editor.
|
Chris@127
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@182
|
7 This file copyright 2006 Chris Cannam and QMUL.
|
Chris@127
|
8
|
Chris@127
|
9 This program is free software; you can redistribute it and/or
|
Chris@127
|
10 modify it under the terms of the GNU General Public License as
|
Chris@127
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@127
|
12 License, or (at your option) any later version. See the file
|
Chris@127
|
13 COPYING included with this distribution for more information.
|
Chris@127
|
14 */
|
Chris@127
|
15
|
Chris@127
|
16 #ifndef _VIEW_MANAGER_H_
|
Chris@127
|
17 #define _VIEW_MANAGER_H_
|
Chris@127
|
18
|
Chris@127
|
19 #include <QObject>
|
Chris@127
|
20 #include <QTimer>
|
Chris@292
|
21 #include <QPalette>
|
Chris@127
|
22
|
Chris@127
|
23 #include <map>
|
Chris@127
|
24
|
Chris@128
|
25 #include "base/Selection.h"
|
Chris@128
|
26 #include "base/Command.h"
|
Chris@128
|
27 #include "base/Clipboard.h"
|
Chris@127
|
28
|
Chris@127
|
29 class AudioPlaySource;
|
Chris@127
|
30 class Model;
|
Chris@127
|
31
|
Chris@211
|
32 enum PlaybackFollowMode {
|
Chris@211
|
33 PlaybackScrollContinuous,
|
Chris@211
|
34 PlaybackScrollPage,
|
Chris@211
|
35 PlaybackIgnore
|
Chris@211
|
36 };
|
Chris@211
|
37
|
Chris@211
|
38 class View;
|
Chris@211
|
39
|
Chris@127
|
40 /**
|
Chris@127
|
41 * The ViewManager manages properties that may need to be synchronised
|
Chris@127
|
42 * between separate Views. For example, it handles signals associated
|
Chris@127
|
43 * with changes to the global pan and zoom, and it handles selections.
|
Chris@127
|
44 *
|
Chris@127
|
45 * Views should be implemented in such a way as to work
|
Chris@127
|
46 * correctly whether they are supplied with a ViewManager or not.
|
Chris@127
|
47 */
|
Chris@127
|
48
|
Chris@127
|
49 class ViewManager : public QObject
|
Chris@127
|
50 {
|
Chris@127
|
51 Q_OBJECT
|
Chris@127
|
52
|
Chris@127
|
53 public:
|
Chris@127
|
54 ViewManager();
|
Chris@127
|
55 virtual ~ViewManager();
|
Chris@127
|
56
|
Chris@127
|
57 void setAudioPlaySource(AudioPlaySource *source);
|
Chris@127
|
58
|
Chris@127
|
59 bool isPlaying() const;
|
Chris@127
|
60
|
Chris@127
|
61 unsigned long getGlobalCentreFrame() const;
|
Chris@180
|
62 void setGlobalCentreFrame(unsigned long);
|
Chris@127
|
63 unsigned long getGlobalZoom() const;
|
Chris@127
|
64
|
Chris@127
|
65 unsigned long getPlaybackFrame() const;
|
Chris@127
|
66 void setPlaybackFrame(unsigned long frame);
|
Chris@127
|
67
|
Chris@301
|
68 // Only meaningful in solo mode, and used for optional alignment feature
|
Chris@301
|
69 Model *getPlaybackModel() const;
|
Chris@301
|
70 void setPlaybackModel(Model *);
|
Chris@301
|
71
|
Chris@333
|
72 size_t alignPlaybackFrameToReference(size_t) const;
|
Chris@333
|
73 size_t alignReferenceToPlaybackFrame(size_t) const;
|
Chris@333
|
74
|
Chris@127
|
75 bool haveInProgressSelection() const;
|
Chris@127
|
76 const Selection &getInProgressSelection(bool &exclusive) const;
|
Chris@127
|
77 void setInProgressSelection(const Selection &selection, bool exclusive);
|
Chris@127
|
78 void clearInProgressSelection();
|
Chris@127
|
79
|
Chris@127
|
80 const MultiSelection &getSelection() const;
|
Chris@127
|
81
|
Chris@127
|
82 const MultiSelection::SelectionList &getSelections() const;
|
Chris@127
|
83 void setSelection(const Selection &selection);
|
Chris@127
|
84 void addSelection(const Selection &selection);
|
Chris@127
|
85 void removeSelection(const Selection &selection);
|
Chris@127
|
86 void clearSelections();
|
Chris@271
|
87 size_t constrainFrameToSelection(size_t frame) const;
|
Chris@127
|
88
|
Chris@127
|
89 /**
|
Chris@127
|
90 * Return the selection that contains a given frame.
|
Chris@127
|
91 * If defaultToFollowing is true, and if the frame is not in a
|
Chris@127
|
92 * selected area, return the next selection after the given frame.
|
Chris@127
|
93 * Return the empty selection if no appropriate selection is found.
|
Chris@127
|
94 */
|
Chris@127
|
95 Selection getContainingSelection(size_t frame, bool defaultToFollowing) const;
|
Chris@127
|
96
|
Chris@127
|
97 Clipboard &getClipboard() { return m_clipboard; }
|
Chris@127
|
98
|
Chris@127
|
99 enum ToolMode {
|
Chris@127
|
100 NavigateMode,
|
Chris@127
|
101 SelectMode,
|
Chris@127
|
102 EditMode,
|
Chris@257
|
103 DrawMode,
|
Chris@335
|
104 EraseMode,
|
Chris@257
|
105 MeasureMode
|
Chris@127
|
106 };
|
Chris@127
|
107 ToolMode getToolMode() const { return m_toolMode; }
|
Chris@127
|
108 void setToolMode(ToolMode mode);
|
Chris@127
|
109
|
Chris@127
|
110 bool getPlayLoopMode() const { return m_playLoopMode; }
|
Chris@127
|
111 void setPlayLoopMode(bool on);
|
Chris@127
|
112
|
Chris@127
|
113 bool getPlaySelectionMode() const { return m_playSelectionMode; }
|
Chris@127
|
114 void setPlaySelectionMode(bool on);
|
Chris@127
|
115
|
Chris@301
|
116 bool getPlaySoloMode() const { return m_playSoloMode; }
|
Chris@301
|
117 void setPlaySoloMode(bool on);
|
Chris@301
|
118
|
Chris@314
|
119 bool getAlignMode() const { return m_alignMode; }
|
Chris@314
|
120 void setAlignMode(bool on);
|
Chris@314
|
121
|
Chris@326
|
122 void setIlluminateLocalFeatures(bool i) { m_illuminateLocalFeatures = i; }
|
Chris@326
|
123 void setShowWorkTitle(bool show) { m_showWorkTitle = show; }
|
Chris@326
|
124
|
Chris@224
|
125 /**
|
Chris@224
|
126 * The sample rate that is used for playback. This is usually the
|
Chris@224
|
127 * rate of the main model, but not always. Models whose rates
|
Chris@224
|
128 * differ from this will play back at the wrong speed -- there is
|
Chris@224
|
129 * no per-model resampler.
|
Chris@224
|
130 */
|
Chris@127
|
131 size_t getPlaybackSampleRate() const;
|
Chris@224
|
132
|
Chris@224
|
133 /**
|
Chris@224
|
134 * The sample rate of the audio output device. If the playback
|
Chris@224
|
135 * sample rate differs from this, everything will be resampled at
|
Chris@224
|
136 * the output stage.
|
Chris@224
|
137 */
|
Chris@224
|
138 size_t getOutputSampleRate() const;
|
Chris@224
|
139
|
Chris@224
|
140 /**
|
Chris@224
|
141 * The sample rate of the current main model. This may in theory
|
Chris@224
|
142 * differ from the playback sample rate, in which case even the
|
Chris@224
|
143 * main model will play at the wrong speed.
|
Chris@224
|
144 */
|
Chris@127
|
145 size_t getMainModelSampleRate() const { return m_mainModelSampleRate; }
|
Chris@224
|
146
|
Chris@127
|
147 void setMainModelSampleRate(size_t sr) { m_mainModelSampleRate = sr; }
|
Chris@127
|
148
|
Chris@127
|
149 enum OverlayMode {
|
Chris@127
|
150 NoOverlays,
|
Chris@189
|
151 MinimalOverlays,
|
Chris@189
|
152 StandardOverlays,
|
Chris@127
|
153 AllOverlays
|
Chris@127
|
154 };
|
Chris@127
|
155 void setOverlayMode(OverlayMode mode);
|
Chris@127
|
156 OverlayMode getOverlayMode() const { return m_overlayMode; }
|
Chris@127
|
157
|
Chris@189
|
158 bool shouldShowCentreLine() const {
|
Chris@189
|
159 return m_overlayMode != NoOverlays;
|
Chris@189
|
160 }
|
Chris@189
|
161 bool shouldShowFrameCount() const {
|
Chris@189
|
162 return m_overlayMode != NoOverlays;
|
Chris@189
|
163 }
|
Chris@189
|
164 bool shouldShowDuration() const {
|
Chris@189
|
165 return m_overlayMode > MinimalOverlays;
|
Chris@189
|
166 }
|
Chris@189
|
167 bool shouldShowVerticalScale() const {
|
Chris@189
|
168 return m_overlayMode > MinimalOverlays;
|
Chris@189
|
169 }
|
Chris@189
|
170 bool shouldShowSelectionExtents() const {
|
Chris@189
|
171 return m_overlayMode > MinimalOverlays;
|
Chris@189
|
172 }
|
Chris@189
|
173 bool shouldShowLayerNames() const {
|
Chris@189
|
174 return m_overlayMode == AllOverlays;
|
Chris@189
|
175 }
|
Chris@195
|
176 bool shouldShowScaleGuides() const {
|
Chris@195
|
177 return m_overlayMode != NoOverlays;
|
Chris@195
|
178 }
|
Chris@326
|
179 bool shouldShowWorkTitle() const {
|
Chris@326
|
180 return m_showWorkTitle;
|
Chris@326
|
181 }
|
Chris@326
|
182 bool shouldIlluminateLocalFeatures() const {
|
Chris@326
|
183 return m_illuminateLocalFeatures;
|
Chris@326
|
184 }
|
Chris@189
|
185
|
Chris@133
|
186 void setZoomWheelsEnabled(bool enable);
|
Chris@133
|
187 bool getZoomWheelsEnabled() const { return m_zoomWheelsEnabled; }
|
Chris@133
|
188
|
Chris@292
|
189 void setGlobalDarkBackground(bool dark);
|
Chris@292
|
190 bool getGlobalDarkBackground() const;
|
Chris@292
|
191
|
Chris@127
|
192 signals:
|
Chris@211
|
193 /** Emitted when user causes the global centre frame to change. */
|
Chris@211
|
194 void globalCentreFrameChanged(unsigned long frame);
|
Chris@127
|
195
|
Chris@211
|
196 /** Emitted when user scrolls a view, but doesn't affect global centre. */
|
Chris@211
|
197 void viewCentreFrameChanged(View *v, unsigned long frame);
|
Chris@211
|
198
|
Chris@211
|
199 /** Emitted when a view zooms. */
|
Chris@222
|
200 void viewZoomLevelChanged(View *v, unsigned long zoom, bool locked);
|
Chris@133
|
201
|
Chris@127
|
202 /** Emitted when the playback frame changes. */
|
Chris@127
|
203 void playbackFrameChanged(unsigned long frame);
|
Chris@127
|
204
|
Chris@127
|
205 /** Emitted when the output levels change. Values in range 0.0 -> 1.0. */
|
Chris@127
|
206 void outputLevelsChanged(float left, float right);
|
Chris@127
|
207
|
Chris@127
|
208 /** Emitted when the selection has changed. */
|
Chris@127
|
209 void selectionChanged();
|
Chris@127
|
210
|
Chris@127
|
211 /** Emitted when the in-progress (rubberbanding) selection has changed. */
|
Chris@127
|
212 void inProgressSelectionChanged();
|
Chris@127
|
213
|
Chris@127
|
214 /** Emitted when the tool mode has been changed. */
|
Chris@127
|
215 void toolModeChanged();
|
Chris@127
|
216
|
Chris@127
|
217 /** Emitted when the play loop mode has been changed. */
|
Chris@127
|
218 void playLoopModeChanged();
|
Chris@177
|
219 void playLoopModeChanged(bool);
|
Chris@127
|
220
|
Chris@127
|
221 /** Emitted when the play selection mode has been changed. */
|
Chris@127
|
222 void playSelectionModeChanged();
|
Chris@177
|
223 void playSelectionModeChanged(bool);
|
Chris@127
|
224
|
Chris@301
|
225 /** Emitted when the play solo mode has been changed. */
|
Chris@301
|
226 void playSoloModeChanged();
|
Chris@301
|
227 void playSoloModeChanged(bool);
|
Chris@301
|
228
|
Chris@314
|
229 /** Emitted when the alignment mode has been changed. */
|
Chris@314
|
230 void alignModeChanged();
|
Chris@314
|
231 void alignModeChanged(bool);
|
Chris@314
|
232
|
Chris@127
|
233 /** Emitted when the overlay mode has been changed. */
|
Chris@127
|
234 void overlayModeChanged();
|
Chris@127
|
235
|
Chris@133
|
236 /** Emitted when the zoom wheels have been toggled. */
|
Chris@133
|
237 void zoomWheelsEnabledChanged();
|
Chris@133
|
238
|
Chris@211
|
239 public slots:
|
Chris@211
|
240 void viewCentreFrameChanged(unsigned long, bool, PlaybackFollowMode);
|
Chris@222
|
241 void viewZoomLevelChanged(unsigned long, bool);
|
Chris@211
|
242
|
Chris@127
|
243 protected slots:
|
Chris@127
|
244 void checkPlayStatus();
|
Chris@127
|
245 void playStatusChanged(bool playing);
|
Chris@211
|
246 void seek(unsigned long);
|
Chris@222
|
247 //!!! void considerZoomChange(void *, unsigned long, bool);
|
Chris@127
|
248
|
Chris@127
|
249 protected:
|
Chris@127
|
250 AudioPlaySource *m_playSource;
|
Chris@127
|
251 unsigned long m_globalCentreFrame;
|
Chris@127
|
252 unsigned long m_globalZoom;
|
Chris@127
|
253 mutable unsigned long m_playbackFrame;
|
Chris@301
|
254 Model *m_playbackModel; //!!!
|
Chris@127
|
255 size_t m_mainModelSampleRate;
|
Chris@127
|
256
|
Chris@127
|
257 float m_lastLeft;
|
Chris@127
|
258 float m_lastRight;
|
Chris@127
|
259
|
Chris@127
|
260 MultiSelection m_selections;
|
Chris@127
|
261 Selection m_inProgressSelection;
|
Chris@127
|
262 bool m_inProgressExclusive;
|
Chris@127
|
263
|
Chris@127
|
264 Clipboard m_clipboard;
|
Chris@127
|
265
|
Chris@127
|
266 ToolMode m_toolMode;
|
Chris@127
|
267
|
Chris@127
|
268 bool m_playLoopMode;
|
Chris@127
|
269 bool m_playSelectionMode;
|
Chris@301
|
270 bool m_playSoloMode;
|
Chris@314
|
271 bool m_alignMode;
|
Chris@127
|
272
|
Chris@127
|
273 void setSelections(const MultiSelection &ms);
|
Chris@127
|
274 void signalSelectionChange();
|
Chris@127
|
275
|
Chris@127
|
276 class SetSelectionCommand : public Command
|
Chris@127
|
277 {
|
Chris@127
|
278 public:
|
Chris@127
|
279 SetSelectionCommand(ViewManager *vm, const MultiSelection &ms);
|
Chris@127
|
280 virtual ~SetSelectionCommand();
|
Chris@127
|
281 virtual void execute();
|
Chris@127
|
282 virtual void unexecute();
|
Chris@127
|
283 virtual QString getName() const;
|
Chris@127
|
284
|
Chris@127
|
285 protected:
|
Chris@127
|
286 ViewManager *m_vm;
|
Chris@127
|
287 MultiSelection m_oldSelection;
|
Chris@127
|
288 MultiSelection m_newSelection;
|
Chris@127
|
289 };
|
Chris@127
|
290
|
Chris@127
|
291 OverlayMode m_overlayMode;
|
Chris@133
|
292 bool m_zoomWheelsEnabled;
|
Chris@326
|
293 bool m_illuminateLocalFeatures;
|
Chris@326
|
294 bool m_showWorkTitle;
|
Chris@292
|
295
|
Chris@292
|
296 QPalette m_lightPalette;
|
Chris@292
|
297 QPalette m_darkPalette;
|
Chris@127
|
298 };
|
Chris@127
|
299
|
Chris@127
|
300 #endif
|
Chris@127
|
301
|