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@127
|
7 This file copyright 2006 Chris Cannam.
|
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@127
|
21
|
Chris@127
|
22 #include <map>
|
Chris@127
|
23
|
Chris@128
|
24 #include "base/Selection.h"
|
Chris@128
|
25 #include "base/Command.h"
|
Chris@128
|
26 #include "base/Clipboard.h"
|
Chris@127
|
27
|
Chris@127
|
28 class AudioPlaySource;
|
Chris@127
|
29 class Model;
|
Chris@127
|
30
|
Chris@127
|
31 /**
|
Chris@127
|
32 * The ViewManager manages properties that may need to be synchronised
|
Chris@127
|
33 * between separate Views. For example, it handles signals associated
|
Chris@127
|
34 * with changes to the global pan and zoom, and it handles selections.
|
Chris@127
|
35 *
|
Chris@127
|
36 * Views should be implemented in such a way as to work
|
Chris@127
|
37 * correctly whether they are supplied with a ViewManager or not.
|
Chris@127
|
38 */
|
Chris@127
|
39
|
Chris@127
|
40 class ViewManager : public QObject
|
Chris@127
|
41 {
|
Chris@127
|
42 Q_OBJECT
|
Chris@127
|
43
|
Chris@127
|
44 public:
|
Chris@127
|
45 ViewManager();
|
Chris@127
|
46 virtual ~ViewManager();
|
Chris@127
|
47
|
Chris@127
|
48 void setAudioPlaySource(AudioPlaySource *source);
|
Chris@127
|
49
|
Chris@127
|
50 bool isPlaying() const;
|
Chris@127
|
51
|
Chris@127
|
52 unsigned long getGlobalCentreFrame() const;
|
Chris@127
|
53 unsigned long getGlobalZoom() const;
|
Chris@127
|
54
|
Chris@127
|
55 unsigned long getPlaybackFrame() const;
|
Chris@127
|
56 void setPlaybackFrame(unsigned long frame);
|
Chris@127
|
57
|
Chris@127
|
58 bool haveInProgressSelection() const;
|
Chris@127
|
59 const Selection &getInProgressSelection(bool &exclusive) const;
|
Chris@127
|
60 void setInProgressSelection(const Selection &selection, bool exclusive);
|
Chris@127
|
61 void clearInProgressSelection();
|
Chris@127
|
62
|
Chris@127
|
63 const MultiSelection &getSelection() const;
|
Chris@127
|
64
|
Chris@127
|
65 const MultiSelection::SelectionList &getSelections() const;
|
Chris@127
|
66 void setSelection(const Selection &selection);
|
Chris@127
|
67 void addSelection(const Selection &selection);
|
Chris@127
|
68 void removeSelection(const Selection &selection);
|
Chris@127
|
69 void clearSelections();
|
Chris@127
|
70
|
Chris@127
|
71 /**
|
Chris@127
|
72 * Return the selection that contains a given frame.
|
Chris@127
|
73 * If defaultToFollowing is true, and if the frame is not in a
|
Chris@127
|
74 * selected area, return the next selection after the given frame.
|
Chris@127
|
75 * Return the empty selection if no appropriate selection is found.
|
Chris@127
|
76 */
|
Chris@127
|
77 Selection getContainingSelection(size_t frame, bool defaultToFollowing) const;
|
Chris@127
|
78
|
Chris@127
|
79 Clipboard &getClipboard() { return m_clipboard; }
|
Chris@127
|
80
|
Chris@127
|
81 enum ToolMode {
|
Chris@127
|
82 NavigateMode,
|
Chris@127
|
83 SelectMode,
|
Chris@127
|
84 EditMode,
|
Chris@127
|
85 DrawMode
|
Chris@127
|
86 };
|
Chris@127
|
87 ToolMode getToolMode() const { return m_toolMode; }
|
Chris@127
|
88 void setToolMode(ToolMode mode);
|
Chris@127
|
89
|
Chris@127
|
90 bool getPlayLoopMode() const { return m_playLoopMode; }
|
Chris@127
|
91 void setPlayLoopMode(bool on);
|
Chris@127
|
92
|
Chris@127
|
93 bool getPlaySelectionMode() const { return m_playSelectionMode; }
|
Chris@127
|
94 void setPlaySelectionMode(bool on);
|
Chris@127
|
95
|
Chris@127
|
96 size_t getPlaybackSampleRate() const;
|
Chris@127
|
97 size_t getMainModelSampleRate() const { return m_mainModelSampleRate; }
|
Chris@127
|
98 void setMainModelSampleRate(size_t sr) { m_mainModelSampleRate = sr; }
|
Chris@127
|
99
|
Chris@127
|
100 enum OverlayMode {
|
Chris@127
|
101 NoOverlays,
|
Chris@127
|
102 BasicOverlays,
|
Chris@127
|
103 AllOverlays
|
Chris@127
|
104 };
|
Chris@127
|
105 void setOverlayMode(OverlayMode mode);
|
Chris@127
|
106 OverlayMode getOverlayMode() const { return m_overlayMode; }
|
Chris@127
|
107
|
Chris@133
|
108 void setZoomWheelsEnabled(bool enable);
|
Chris@133
|
109 bool getZoomWheelsEnabled() const { return m_zoomWheelsEnabled; }
|
Chris@133
|
110
|
Chris@127
|
111 signals:
|
Chris@127
|
112 /** Emitted when a widget pans. The originator identifies the widget. */
|
Chris@127
|
113 void centreFrameChanged(void *originator, unsigned long frame, bool locked);
|
Chris@127
|
114
|
Chris@127
|
115 /** Emitted when a widget zooms. The originator identifies the widget. */
|
Chris@127
|
116 void zoomLevelChanged(void *originator, unsigned long zoom, bool locked);
|
Chris@127
|
117
|
Chris@133
|
118 /** Emitted when a widget zooms. */
|
Chris@133
|
119 void zoomLevelChanged();
|
Chris@133
|
120
|
Chris@127
|
121 /** Emitted when the playback frame changes. */
|
Chris@127
|
122 void playbackFrameChanged(unsigned long frame);
|
Chris@127
|
123
|
Chris@127
|
124 /** Emitted when the output levels change. Values in range 0.0 -> 1.0. */
|
Chris@127
|
125 void outputLevelsChanged(float left, float right);
|
Chris@127
|
126
|
Chris@127
|
127 /** Emitted when the selection has changed. */
|
Chris@127
|
128 void selectionChanged();
|
Chris@127
|
129
|
Chris@127
|
130 /** Emitted when the in-progress (rubberbanding) selection has changed. */
|
Chris@127
|
131 void inProgressSelectionChanged();
|
Chris@127
|
132
|
Chris@127
|
133 /** Emitted when the tool mode has been changed. */
|
Chris@127
|
134 void toolModeChanged();
|
Chris@127
|
135
|
Chris@127
|
136 /** Emitted when the play loop mode has been changed. */
|
Chris@127
|
137 void playLoopModeChanged();
|
Chris@127
|
138
|
Chris@127
|
139 /** Emitted when the play selection mode has been changed. */
|
Chris@127
|
140 void playSelectionModeChanged();
|
Chris@127
|
141
|
Chris@127
|
142 /** Emitted when the overlay mode has been changed. */
|
Chris@127
|
143 void overlayModeChanged();
|
Chris@127
|
144
|
Chris@133
|
145 /** Emitted when the zoom wheels have been toggled. */
|
Chris@133
|
146 void zoomWheelsEnabledChanged();
|
Chris@133
|
147
|
Chris@127
|
148 protected slots:
|
Chris@127
|
149 void checkPlayStatus();
|
Chris@127
|
150 void playStatusChanged(bool playing);
|
Chris@127
|
151 void considerSeek(void *, unsigned long, bool);
|
Chris@127
|
152 void considerZoomChange(void *, unsigned long, bool);
|
Chris@127
|
153
|
Chris@127
|
154 protected:
|
Chris@127
|
155 AudioPlaySource *m_playSource;
|
Chris@127
|
156 unsigned long m_globalCentreFrame;
|
Chris@127
|
157 unsigned long m_globalZoom;
|
Chris@127
|
158 mutable unsigned long m_playbackFrame;
|
Chris@127
|
159 size_t m_mainModelSampleRate;
|
Chris@127
|
160
|
Chris@127
|
161 float m_lastLeft;
|
Chris@127
|
162 float m_lastRight;
|
Chris@127
|
163
|
Chris@127
|
164 MultiSelection m_selections;
|
Chris@127
|
165 Selection m_inProgressSelection;
|
Chris@127
|
166 bool m_inProgressExclusive;
|
Chris@127
|
167
|
Chris@127
|
168 Clipboard m_clipboard;
|
Chris@127
|
169
|
Chris@127
|
170 ToolMode m_toolMode;
|
Chris@127
|
171
|
Chris@127
|
172 bool m_playLoopMode;
|
Chris@127
|
173 bool m_playSelectionMode;
|
Chris@127
|
174
|
Chris@127
|
175 void setSelections(const MultiSelection &ms);
|
Chris@127
|
176 void signalSelectionChange();
|
Chris@127
|
177
|
Chris@127
|
178 class SetSelectionCommand : public Command
|
Chris@127
|
179 {
|
Chris@127
|
180 public:
|
Chris@127
|
181 SetSelectionCommand(ViewManager *vm, const MultiSelection &ms);
|
Chris@127
|
182 virtual ~SetSelectionCommand();
|
Chris@127
|
183 virtual void execute();
|
Chris@127
|
184 virtual void unexecute();
|
Chris@127
|
185 virtual QString getName() const;
|
Chris@127
|
186
|
Chris@127
|
187 protected:
|
Chris@127
|
188 ViewManager *m_vm;
|
Chris@127
|
189 MultiSelection m_oldSelection;
|
Chris@127
|
190 MultiSelection m_newSelection;
|
Chris@127
|
191 };
|
Chris@127
|
192
|
Chris@127
|
193 OverlayMode m_overlayMode;
|
Chris@133
|
194 bool m_zoomWheelsEnabled;
|
Chris@127
|
195 };
|
Chris@127
|
196
|
Chris@127
|
197 #endif
|
Chris@127
|
198
|