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; }
|
Chris@326
|
161
|
Chris@224
|
162 /**
|
Chris@224
|
163 * The sample rate that is used for playback. This is usually the
|
Chris@224
|
164 * rate of the main model, but not always. Models whose rates
|
Chris@224
|
165 * differ from this will play back at the wrong speed -- there is
|
Chris@224
|
166 * no per-model resampler.
|
Chris@224
|
167 */
|
Chris@806
|
168 int getPlaybackSampleRate() const;
|
Chris@224
|
169
|
Chris@224
|
170 /**
|
Chris@224
|
171 * The sample rate of the audio output device. If the playback
|
Chris@224
|
172 * sample rate differs from this, everything will be resampled at
|
Chris@224
|
173 * the output stage.
|
Chris@224
|
174 */
|
Chris@806
|
175 int getOutputSampleRate() const;
|
Chris@224
|
176
|
Chris@224
|
177 /**
|
Chris@224
|
178 * The sample rate of the current main model. This may in theory
|
Chris@224
|
179 * differ from the playback sample rate, in which case even the
|
Chris@224
|
180 * main model will play at the wrong speed.
|
Chris@224
|
181 */
|
Chris@806
|
182 int getMainModelSampleRate() const { return m_mainModelSampleRate; }
|
Chris@224
|
183
|
Chris@806
|
184 void setMainModelSampleRate(int sr) { m_mainModelSampleRate = sr; }
|
Chris@127
|
185
|
Chris@127
|
186 enum OverlayMode {
|
Chris@127
|
187 NoOverlays,
|
Chris@741
|
188 GlobalOverlays,
|
Chris@741
|
189 StandardOverlays,
|
Chris@127
|
190 AllOverlays
|
Chris@127
|
191 };
|
Chris@127
|
192 void setOverlayMode(OverlayMode mode);
|
Chris@127
|
193 OverlayMode getOverlayMode() const { return m_overlayMode; }
|
Chris@127
|
194
|
Chris@607
|
195 void setShowCentreLine(bool show);
|
Chris@607
|
196 bool shouldShowCentreLine() const { return m_showCentreLine; }
|
Chris@607
|
197
|
Chris@607
|
198 bool shouldShowDuration() const {
|
Chris@189
|
199 return m_overlayMode != NoOverlays;
|
Chris@189
|
200 }
|
Chris@189
|
201 bool shouldShowFrameCount() const {
|
Chris@607
|
202 return m_showCentreLine && shouldShowDuration();
|
Chris@607
|
203 }
|
Chris@607
|
204 bool shouldShowVerticalScale() const {
|
Chris@189
|
205 return m_overlayMode != NoOverlays;
|
Chris@189
|
206 }
|
Chris@607
|
207 bool shouldShowVerticalColourScale() const {
|
Chris@607
|
208 return m_overlayMode == AllOverlays;
|
Chris@189
|
209 }
|
Chris@189
|
210 bool shouldShowSelectionExtents() const {
|
Chris@741
|
211 return m_overlayMode != NoOverlays && m_overlayMode != GlobalOverlays;
|
Chris@189
|
212 }
|
Chris@189
|
213 bool shouldShowLayerNames() const {
|
Chris@189
|
214 return m_overlayMode == AllOverlays;
|
Chris@189
|
215 }
|
Chris@195
|
216 bool shouldShowScaleGuides() const {
|
Chris@195
|
217 return m_overlayMode != NoOverlays;
|
Chris@195
|
218 }
|
Chris@326
|
219 bool shouldShowWorkTitle() const {
|
Chris@326
|
220 return m_showWorkTitle;
|
Chris@326
|
221 }
|
Chris@326
|
222 bool shouldIlluminateLocalFeatures() const {
|
Chris@326
|
223 return m_illuminateLocalFeatures;
|
Chris@326
|
224 }
|
Chris@741
|
225 bool shouldShowFeatureLabels() const {
|
Chris@741
|
226 return m_overlayMode != NoOverlays && m_overlayMode != GlobalOverlays;
|
Chris@741
|
227 }
|
Chris@189
|
228
|
Chris@133
|
229 void setZoomWheelsEnabled(bool enable);
|
Chris@133
|
230 bool getZoomWheelsEnabled() const { return m_zoomWheelsEnabled; }
|
Chris@133
|
231
|
Chris@292
|
232 void setGlobalDarkBackground(bool dark);
|
Chris@292
|
233 bool getGlobalDarkBackground() const;
|
Chris@292
|
234
|
Chris@127
|
235 signals:
|
Chris@211
|
236 /** Emitted when user causes the global centre frame to change. */
|
Chris@806
|
237 void globalCentreFrameChanged(int frame);
|
Chris@127
|
238
|
Chris@211
|
239 /** Emitted when user scrolls a view, but doesn't affect global centre. */
|
Chris@806
|
240 void viewCentreFrameChanged(View *v, int frame);
|
Chris@211
|
241
|
Chris@211
|
242 /** Emitted when a view zooms. */
|
Chris@806
|
243 void viewZoomLevelChanged(View *v, int zoom, bool locked);
|
Chris@133
|
244
|
Chris@127
|
245 /** Emitted when the playback frame changes. */
|
Chris@806
|
246 void playbackFrameChanged(int frame);
|
Chris@127
|
247
|
Chris@127
|
248 /** Emitted when the output levels change. Values in range 0.0 -> 1.0. */
|
Chris@127
|
249 void outputLevelsChanged(float left, float right);
|
Chris@127
|
250
|
Chris@731
|
251 /** Emitted whenever the selection has changed. */
|
Chris@127
|
252 void selectionChanged();
|
Chris@127
|
253
|
Chris@731
|
254 /** Emitted when the selection has been changed through an
|
Chris@731
|
255 * explicit selection-editing action. *Not* emitted when the
|
Chris@731
|
256 * selection has been changed through undo or redo. */
|
Chris@731
|
257 void selectionChangedByUser();
|
Chris@731
|
258
|
Chris@127
|
259 /** Emitted when the in-progress (rubberbanding) selection has changed. */
|
Chris@127
|
260 void inProgressSelectionChanged();
|
Chris@127
|
261
|
Chris@127
|
262 /** Emitted when the tool mode has been changed. */
|
Chris@127
|
263 void toolModeChanged();
|
Chris@127
|
264
|
Chris@127
|
265 /** Emitted when the play loop mode has been changed. */
|
Chris@127
|
266 void playLoopModeChanged();
|
Chris@177
|
267 void playLoopModeChanged(bool);
|
Chris@127
|
268
|
Chris@127
|
269 /** Emitted when the play selection mode has been changed. */
|
Chris@127
|
270 void playSelectionModeChanged();
|
Chris@177
|
271 void playSelectionModeChanged(bool);
|
Chris@127
|
272
|
Chris@301
|
273 /** Emitted when the play solo mode has been changed. */
|
Chris@301
|
274 void playSoloModeChanged();
|
Chris@301
|
275 void playSoloModeChanged(bool);
|
Chris@301
|
276
|
Chris@314
|
277 /** Emitted when the alignment mode has been changed. */
|
Chris@314
|
278 void alignModeChanged();
|
Chris@314
|
279 void alignModeChanged(bool);
|
Chris@314
|
280
|
Chris@127
|
281 /** Emitted when the overlay mode has been changed. */
|
Chris@127
|
282 void overlayModeChanged();
|
Chris@127
|
283
|
Chris@607
|
284 /** Emitted when the centre line visibility has been changed. */
|
Chris@607
|
285 void showCentreLineChanged();
|
Chris@607
|
286
|
Chris@133
|
287 /** Emitted when the zoom wheels have been toggled. */
|
Chris@133
|
288 void zoomWheelsEnabledChanged();
|
Chris@133
|
289
|
Chris@502
|
290 /** Emitted when any loggable activity has occurred. */
|
Chris@502
|
291 void activity(QString);
|
Chris@502
|
292
|
Chris@211
|
293 public slots:
|
Chris@806
|
294 void viewCentreFrameChanged(int, bool, PlaybackFollowMode);
|
Chris@806
|
295 void viewZoomLevelChanged(int, bool);
|
Chris@806
|
296 void setGlobalCentreFrame(int);
|
Chris@806
|
297 void setPlaybackFrame(int);
|
Chris@689
|
298 void playStatusChanged(bool playing);
|
Chris@211
|
299
|
Chris@127
|
300 protected slots:
|
Chris@127
|
301 void checkPlayStatus();
|
Chris@806
|
302 void seek(int);
|
Chris@806
|
303 //!!! void considerZoomChange(void *, int, bool);
|
Chris@127
|
304
|
Chris@127
|
305 protected:
|
Chris@127
|
306 AudioPlaySource *m_playSource;
|
Chris@806
|
307 int m_globalCentreFrame;
|
Chris@806
|
308 int m_globalZoom;
|
Chris@806
|
309 mutable int m_playbackFrame;
|
Chris@301
|
310 Model *m_playbackModel; //!!!
|
Chris@806
|
311 int m_mainModelSampleRate;
|
Chris@127
|
312
|
Chris@127
|
313 float m_lastLeft;
|
Chris@127
|
314 float m_lastRight;
|
Chris@127
|
315
|
Chris@127
|
316 MultiSelection m_selections;
|
Chris@127
|
317 Selection m_inProgressSelection;
|
Chris@127
|
318 bool m_inProgressExclusive;
|
Chris@127
|
319
|
Chris@127
|
320 Clipboard m_clipboard;
|
Chris@127
|
321
|
Chris@127
|
322 ToolMode m_toolMode;
|
Chris@711
|
323 std::map<const View *, ToolMode> m_toolModeOverrides;
|
Chris@127
|
324
|
Chris@127
|
325 bool m_playLoopMode;
|
Chris@127
|
326 bool m_playSelectionMode;
|
Chris@301
|
327 bool m_playSoloMode;
|
Chris@314
|
328 bool m_alignMode;
|
Chris@127
|
329
|
Chris@762
|
330 void setSelections(const MultiSelection &ms, bool quietly = false);
|
Chris@127
|
331 void signalSelectionChange();
|
Chris@127
|
332
|
Chris@127
|
333 class SetSelectionCommand : public Command
|
Chris@127
|
334 {
|
Chris@127
|
335 public:
|
Chris@127
|
336 SetSelectionCommand(ViewManager *vm, const MultiSelection &ms);
|
Chris@127
|
337 virtual ~SetSelectionCommand();
|
Chris@127
|
338 virtual void execute();
|
Chris@127
|
339 virtual void unexecute();
|
Chris@127
|
340 virtual QString getName() const;
|
Chris@127
|
341
|
Chris@127
|
342 protected:
|
Chris@127
|
343 ViewManager *m_vm;
|
Chris@127
|
344 MultiSelection m_oldSelection;
|
Chris@127
|
345 MultiSelection m_newSelection;
|
Chris@127
|
346 };
|
Chris@127
|
347
|
Chris@127
|
348 OverlayMode m_overlayMode;
|
Chris@133
|
349 bool m_zoomWheelsEnabled;
|
Chris@607
|
350 bool m_showCentreLine;
|
Chris@326
|
351 bool m_illuminateLocalFeatures;
|
Chris@326
|
352 bool m_showWorkTitle;
|
Chris@292
|
353
|
Chris@292
|
354 QPalette m_lightPalette;
|
Chris@292
|
355 QPalette m_darkPalette;
|
Chris@127
|
356 };
|
Chris@127
|
357
|
Chris@127
|
358 #endif
|
Chris@127
|
359
|