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@376
|
25 #include "base/ViewManagerBase.h"
|
Chris@128
|
26 #include "base/Selection.h"
|
Chris@128
|
27 #include "base/Command.h"
|
Chris@128
|
28 #include "base/Clipboard.h"
|
Chris@127
|
29
|
Chris@127
|
30 class AudioPlaySource;
|
Chris@127
|
31 class Model;
|
Chris@127
|
32
|
Chris@211
|
33 enum PlaybackFollowMode {
|
Chris@815
|
34
|
Chris@815
|
35 /**
|
Chris@815
|
36 * View scrolls continuously during playback, keeping the playback
|
Chris@815
|
37 * position at the centre.
|
Chris@815
|
38 */
|
Chris@211
|
39 PlaybackScrollContinuous,
|
Chris@815
|
40
|
Chris@815
|
41 /**
|
Chris@815
|
42 * View follows playback page-by-page, but dragging the view
|
Chris@815
|
43 * relocates playback to the centre frame. This is the classic
|
Chris@815
|
44 * Sonic Visualiser behaviour.
|
Chris@815
|
45 */
|
Chris@815
|
46 PlaybackScrollPageWithCentre,
|
Chris@815
|
47
|
Chris@815
|
48 /**
|
Chris@815
|
49 * View follows playback page-by-page, and the play head is moved
|
Chris@815
|
50 * (by the user) separately from dragging the view. This is
|
Chris@815
|
51 * roughly the behaviour of a typical DAW or audio editor.
|
Chris@815
|
52 */
|
Chris@211
|
53 PlaybackScrollPage,
|
Chris@815
|
54
|
Chris@815
|
55 /**
|
Chris@815
|
56 * View is detached from playback. It doesn't follow playback, and
|
Chris@815
|
57 * dragging the view does not affect the play head.
|
Chris@815
|
58 */
|
Chris@211
|
59 PlaybackIgnore
|
Chris@211
|
60 };
|
Chris@211
|
61
|
Chris@211
|
62 class View;
|
Chris@211
|
63
|
Chris@127
|
64 /**
|
Chris@127
|
65 * The ViewManager manages properties that may need to be synchronised
|
Chris@127
|
66 * between separate Views. For example, it handles signals associated
|
Chris@127
|
67 * with changes to the global pan and zoom, and it handles selections.
|
Chris@127
|
68 *
|
Chris@127
|
69 * Views should be implemented in such a way as to work
|
Chris@127
|
70 * correctly whether they are supplied with a ViewManager or not.
|
Chris@127
|
71 */
|
Chris@127
|
72
|
Chris@376
|
73 class ViewManager : public ViewManagerBase
|
Chris@127
|
74 {
|
Chris@127
|
75 Q_OBJECT
|
Chris@127
|
76
|
Chris@127
|
77 public:
|
Chris@127
|
78 ViewManager();
|
Chris@127
|
79 virtual ~ViewManager();
|
Chris@127
|
80
|
Chris@127
|
81 void setAudioPlaySource(AudioPlaySource *source);
|
Chris@127
|
82
|
Chris@127
|
83 bool isPlaying() const;
|
Chris@127
|
84
|
Chris@806
|
85 int getGlobalCentreFrame() const; // the set method is a slot
|
Chris@806
|
86 int getGlobalZoom() const;
|
Chris@127
|
87
|
Chris@806
|
88 int getPlaybackFrame() const; // the set method is a slot
|
Chris@127
|
89
|
Chris@301
|
90 // Only meaningful in solo mode, and used for optional alignment feature
|
Chris@301
|
91 Model *getPlaybackModel() const;
|
Chris@301
|
92 void setPlaybackModel(Model *);
|
Chris@301
|
93
|
Chris@806
|
94 int alignPlaybackFrameToReference(int) const;
|
Chris@806
|
95 int alignReferenceToPlaybackFrame(int) const;
|
Chris@333
|
96
|
Chris@127
|
97 bool haveInProgressSelection() const;
|
Chris@127
|
98 const Selection &getInProgressSelection(bool &exclusive) const;
|
Chris@127
|
99 void setInProgressSelection(const Selection &selection, bool exclusive);
|
Chris@127
|
100 void clearInProgressSelection();
|
Chris@127
|
101
|
Chris@127
|
102 const MultiSelection &getSelection() const;
|
Chris@127
|
103
|
Chris@127
|
104 const MultiSelection::SelectionList &getSelections() const;
|
Chris@127
|
105 void setSelection(const Selection &selection);
|
Chris@127
|
106 void addSelection(const Selection &selection);
|
Chris@127
|
107 void removeSelection(const Selection &selection);
|
Chris@127
|
108 void clearSelections();
|
Chris@806
|
109 int constrainFrameToSelection(int frame) const;
|
Chris@127
|
110
|
Chris@127
|
111 /**
|
Chris@762
|
112 * Adding a selection normally emits the selectionChangedByUser
|
Chris@762
|
113 * signal. Call this to add a selection without emitting that signal.
|
Chris@762
|
114 * This is used in session file load, for example.
|
Chris@762
|
115 */
|
Chris@762
|
116 void addSelectionQuietly(const Selection &selection);
|
Chris@762
|
117
|
Chris@762
|
118 /**
|
Chris@127
|
119 * Return the selection that contains a given frame.
|
Chris@127
|
120 * If defaultToFollowing is true, and if the frame is not in a
|
Chris@127
|
121 * selected area, return the next selection after the given frame.
|
Chris@127
|
122 * Return the empty selection if no appropriate selection is found.
|
Chris@127
|
123 */
|
Chris@806
|
124 Selection getContainingSelection(int frame, bool defaultToFollowing) const;
|
Chris@127
|
125
|
Chris@127
|
126 Clipboard &getClipboard() { return m_clipboard; }
|
Chris@127
|
127
|
Chris@127
|
128 enum ToolMode {
|
Chris@127
|
129 NavigateMode,
|
Chris@127
|
130 SelectMode,
|
Chris@711
|
131 EditMode,
|
Chris@257
|
132 DrawMode,
|
Chris@335
|
133 EraseMode,
|
gyorgyf@645
|
134 MeasureMode,
|
gyorgyf@645
|
135 NoteEditMode //GF: Tonioni: this tool mode will be context sensitive.
|
Chris@127
|
136 };
|
Chris@127
|
137 ToolMode getToolMode() const { return m_toolMode; }
|
Chris@127
|
138 void setToolMode(ToolMode mode);
|
Chris@127
|
139
|
Chris@711
|
140 /// Override the tool mode for a specific view
|
Chris@711
|
141 void setToolModeFor(const View *v, ToolMode mode);
|
Chris@711
|
142 /// Return override mode if it exists for this view or global mode otherwise
|
Chris@711
|
143 ToolMode getToolModeFor(const View *v) const;
|
Chris@711
|
144 /// Clear all current view-specific overrides
|
Chris@711
|
145 void clearToolModeOverrides();
|
Chris@711
|
146
|
Chris@127
|
147 bool getPlayLoopMode() const { return m_playLoopMode; }
|
Chris@127
|
148 void setPlayLoopMode(bool on);
|
Chris@127
|
149
|
Chris@127
|
150 bool getPlaySelectionMode() const { return m_playSelectionMode; }
|
Chris@127
|
151 void setPlaySelectionMode(bool on);
|
Chris@127
|
152
|
Chris@301
|
153 bool getPlaySoloMode() const { return m_playSoloMode; }
|
Chris@301
|
154 void setPlaySoloMode(bool on);
|
Chris@301
|
155
|
Chris@314
|
156 bool getAlignMode() const { return m_alignMode; }
|
Chris@314
|
157 void setAlignMode(bool on);
|
Chris@314
|
158
|
Chris@326
|
159 void setIlluminateLocalFeatures(bool i) { m_illuminateLocalFeatures = i; }
|
Chris@326
|
160 void setShowWorkTitle(bool show) { m_showWorkTitle = show; }
|
matthiasm@822
|
161 void setShowDuration(bool show) { m_showDuration = show; }
|
Chris@326
|
162
|
Chris@224
|
163 /**
|
Chris@224
|
164 * The sample rate that is used for playback. This is usually the
|
Chris@224
|
165 * rate of the main model, but not always. Models whose rates
|
Chris@224
|
166 * differ from this will play back at the wrong speed -- there is
|
Chris@224
|
167 * no per-model resampler.
|
Chris@224
|
168 */
|
Chris@806
|
169 int getPlaybackSampleRate() const;
|
Chris@224
|
170
|
Chris@224
|
171 /**
|
Chris@224
|
172 * The sample rate of the audio output device. If the playback
|
Chris@224
|
173 * sample rate differs from this, everything will be resampled at
|
Chris@224
|
174 * the output stage.
|
Chris@224
|
175 */
|
Chris@806
|
176 int getOutputSampleRate() const;
|
Chris@224
|
177
|
Chris@224
|
178 /**
|
Chris@224
|
179 * The sample rate of the current main model. This may in theory
|
Chris@224
|
180 * differ from the playback sample rate, in which case even the
|
Chris@224
|
181 * main model will play at the wrong speed.
|
Chris@224
|
182 */
|
Chris@806
|
183 int getMainModelSampleRate() const { return m_mainModelSampleRate; }
|
Chris@224
|
184
|
Chris@806
|
185 void setMainModelSampleRate(int sr) { m_mainModelSampleRate = sr; }
|
Chris@127
|
186
|
Chris@896
|
187 /**
|
Chris@896
|
188 * Take a "design pixel" size and scale it for the actual
|
Chris@896
|
189 * display. This is relevant to hi-dpi systems that do not do
|
Chris@896
|
190 * pixel doubling (i.e. Windows and Linux rather than OS/X).
|
Chris@896
|
191 */
|
Chris@896
|
192 int scalePixelSize(int pixels);
|
Chris@896
|
193
|
Chris@127
|
194 enum OverlayMode {
|
Chris@127
|
195 NoOverlays,
|
Chris@741
|
196 GlobalOverlays,
|
Chris@741
|
197 StandardOverlays,
|
Chris@127
|
198 AllOverlays
|
Chris@127
|
199 };
|
Chris@127
|
200 void setOverlayMode(OverlayMode mode);
|
Chris@127
|
201 OverlayMode getOverlayMode() const { return m_overlayMode; }
|
Chris@127
|
202
|
Chris@607
|
203 void setShowCentreLine(bool show);
|
Chris@607
|
204 bool shouldShowCentreLine() const { return m_showCentreLine; }
|
Chris@607
|
205
|
Chris@607
|
206 bool shouldShowDuration() const {
|
matthiasm@822
|
207 return m_overlayMode != NoOverlays && m_showDuration;
|
Chris@189
|
208 }
|
Chris@189
|
209 bool shouldShowFrameCount() const {
|
Chris@607
|
210 return m_showCentreLine && shouldShowDuration();
|
Chris@607
|
211 }
|
Chris@607
|
212 bool shouldShowVerticalScale() const {
|
Chris@189
|
213 return m_overlayMode != NoOverlays;
|
Chris@189
|
214 }
|
Chris@607
|
215 bool shouldShowVerticalColourScale() const {
|
Chris@607
|
216 return m_overlayMode == AllOverlays;
|
Chris@189
|
217 }
|
Chris@189
|
218 bool shouldShowSelectionExtents() const {
|
Chris@741
|
219 return m_overlayMode != NoOverlays && m_overlayMode != GlobalOverlays;
|
Chris@189
|
220 }
|
Chris@189
|
221 bool shouldShowLayerNames() const {
|
Chris@189
|
222 return m_overlayMode == AllOverlays;
|
Chris@189
|
223 }
|
Chris@195
|
224 bool shouldShowScaleGuides() const {
|
Chris@195
|
225 return m_overlayMode != NoOverlays;
|
Chris@195
|
226 }
|
Chris@326
|
227 bool shouldShowWorkTitle() const {
|
Chris@326
|
228 return m_showWorkTitle;
|
Chris@326
|
229 }
|
Chris@326
|
230 bool shouldIlluminateLocalFeatures() const {
|
Chris@326
|
231 return m_illuminateLocalFeatures;
|
Chris@326
|
232 }
|
Chris@741
|
233 bool shouldShowFeatureLabels() const {
|
Chris@741
|
234 return m_overlayMode != NoOverlays && m_overlayMode != GlobalOverlays;
|
Chris@741
|
235 }
|
Chris@189
|
236
|
Chris@133
|
237 void setZoomWheelsEnabled(bool enable);
|
Chris@133
|
238 bool getZoomWheelsEnabled() const { return m_zoomWheelsEnabled; }
|
Chris@133
|
239
|
Chris@292
|
240 void setGlobalDarkBackground(bool dark);
|
Chris@292
|
241 bool getGlobalDarkBackground() const;
|
Chris@292
|
242
|
Chris@127
|
243 signals:
|
Chris@211
|
244 /** Emitted when user causes the global centre frame to change. */
|
Chris@806
|
245 void globalCentreFrameChanged(int frame);
|
Chris@127
|
246
|
Chris@211
|
247 /** Emitted when user scrolls a view, but doesn't affect global centre. */
|
Chris@806
|
248 void viewCentreFrameChanged(View *v, int frame);
|
Chris@211
|
249
|
Chris@211
|
250 /** Emitted when a view zooms. */
|
Chris@806
|
251 void viewZoomLevelChanged(View *v, int zoom, bool locked);
|
Chris@133
|
252
|
Chris@127
|
253 /** Emitted when the playback frame changes. */
|
Chris@806
|
254 void playbackFrameChanged(int frame);
|
Chris@127
|
255
|
Chris@127
|
256 /** Emitted when the output levels change. Values in range 0.0 -> 1.0. */
|
Chris@127
|
257 void outputLevelsChanged(float left, float right);
|
Chris@127
|
258
|
Chris@731
|
259 /** Emitted whenever the selection has changed. */
|
Chris@127
|
260 void selectionChanged();
|
Chris@127
|
261
|
Chris@731
|
262 /** Emitted when the selection has been changed through an
|
Chris@731
|
263 * explicit selection-editing action. *Not* emitted when the
|
Chris@731
|
264 * selection has been changed through undo or redo. */
|
Chris@731
|
265 void selectionChangedByUser();
|
Chris@731
|
266
|
Chris@127
|
267 /** Emitted when the in-progress (rubberbanding) selection has changed. */
|
Chris@127
|
268 void inProgressSelectionChanged();
|
Chris@127
|
269
|
Chris@127
|
270 /** Emitted when the tool mode has been changed. */
|
Chris@127
|
271 void toolModeChanged();
|
Chris@127
|
272
|
Chris@127
|
273 /** Emitted when the play loop mode has been changed. */
|
Chris@127
|
274 void playLoopModeChanged();
|
Chris@177
|
275 void playLoopModeChanged(bool);
|
Chris@127
|
276
|
Chris@127
|
277 /** Emitted when the play selection mode has been changed. */
|
Chris@127
|
278 void playSelectionModeChanged();
|
Chris@177
|
279 void playSelectionModeChanged(bool);
|
Chris@127
|
280
|
Chris@301
|
281 /** Emitted when the play solo mode has been changed. */
|
Chris@301
|
282 void playSoloModeChanged();
|
Chris@301
|
283 void playSoloModeChanged(bool);
|
Chris@301
|
284
|
Chris@314
|
285 /** Emitted when the alignment mode has been changed. */
|
Chris@314
|
286 void alignModeChanged();
|
Chris@314
|
287 void alignModeChanged(bool);
|
Chris@314
|
288
|
Chris@127
|
289 /** Emitted when the overlay mode has been changed. */
|
Chris@127
|
290 void overlayModeChanged();
|
Chris@127
|
291
|
Chris@607
|
292 /** Emitted when the centre line visibility has been changed. */
|
Chris@607
|
293 void showCentreLineChanged();
|
Chris@607
|
294
|
Chris@133
|
295 /** Emitted when the zoom wheels have been toggled. */
|
Chris@133
|
296 void zoomWheelsEnabledChanged();
|
Chris@133
|
297
|
Chris@502
|
298 /** Emitted when any loggable activity has occurred. */
|
Chris@502
|
299 void activity(QString);
|
Chris@502
|
300
|
Chris@211
|
301 public slots:
|
Chris@806
|
302 void viewCentreFrameChanged(int, bool, PlaybackFollowMode);
|
Chris@806
|
303 void viewZoomLevelChanged(int, bool);
|
Chris@806
|
304 void setGlobalCentreFrame(int);
|
Chris@806
|
305 void setPlaybackFrame(int);
|
Chris@689
|
306 void playStatusChanged(bool playing);
|
Chris@211
|
307
|
Chris@127
|
308 protected slots:
|
Chris@127
|
309 void checkPlayStatus();
|
Chris@806
|
310 void seek(int);
|
Chris@806
|
311 //!!! void considerZoomChange(void *, int, bool);
|
Chris@127
|
312
|
Chris@127
|
313 protected:
|
Chris@127
|
314 AudioPlaySource *m_playSource;
|
Chris@806
|
315 int m_globalCentreFrame;
|
Chris@806
|
316 int m_globalZoom;
|
Chris@806
|
317 mutable int m_playbackFrame;
|
Chris@301
|
318 Model *m_playbackModel; //!!!
|
Chris@806
|
319 int m_mainModelSampleRate;
|
Chris@127
|
320
|
Chris@127
|
321 float m_lastLeft;
|
Chris@127
|
322 float m_lastRight;
|
Chris@127
|
323
|
Chris@127
|
324 MultiSelection m_selections;
|
Chris@127
|
325 Selection m_inProgressSelection;
|
Chris@127
|
326 bool m_inProgressExclusive;
|
Chris@127
|
327
|
Chris@127
|
328 Clipboard m_clipboard;
|
Chris@127
|
329
|
Chris@127
|
330 ToolMode m_toolMode;
|
Chris@711
|
331 std::map<const View *, ToolMode> m_toolModeOverrides;
|
Chris@127
|
332
|
Chris@127
|
333 bool m_playLoopMode;
|
Chris@127
|
334 bool m_playSelectionMode;
|
Chris@301
|
335 bool m_playSoloMode;
|
Chris@314
|
336 bool m_alignMode;
|
Chris@127
|
337
|
Chris@762
|
338 void setSelections(const MultiSelection &ms, bool quietly = false);
|
Chris@127
|
339 void signalSelectionChange();
|
Chris@127
|
340
|
Chris@127
|
341 class SetSelectionCommand : public Command
|
Chris@127
|
342 {
|
Chris@127
|
343 public:
|
Chris@127
|
344 SetSelectionCommand(ViewManager *vm, const MultiSelection &ms);
|
Chris@127
|
345 virtual ~SetSelectionCommand();
|
Chris@127
|
346 virtual void execute();
|
Chris@127
|
347 virtual void unexecute();
|
Chris@127
|
348 virtual QString getName() const;
|
Chris@127
|
349
|
Chris@127
|
350 protected:
|
Chris@127
|
351 ViewManager *m_vm;
|
Chris@127
|
352 MultiSelection m_oldSelection;
|
Chris@127
|
353 MultiSelection m_newSelection;
|
Chris@127
|
354 };
|
Chris@127
|
355
|
Chris@127
|
356 OverlayMode m_overlayMode;
|
Chris@133
|
357 bool m_zoomWheelsEnabled;
|
Chris@607
|
358 bool m_showCentreLine;
|
Chris@326
|
359 bool m_illuminateLocalFeatures;
|
Chris@326
|
360 bool m_showWorkTitle;
|
matthiasm@822
|
361 bool m_showDuration;
|
Chris@292
|
362
|
Chris@292
|
363 QPalette m_lightPalette;
|
Chris@292
|
364 QPalette m_darkPalette;
|
Chris@127
|
365 };
|
Chris@127
|
366
|
Chris@127
|
367 #endif
|
Chris@127
|
368
|