Chris@0
|
1 /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@0
|
4 A waveform viewer and audio annotation editor.
|
Chris@2
|
5 Chris Cannam, Queen Mary University of London, 2005-2006
|
Chris@0
|
6
|
Chris@0
|
7 This is experimental software. Not for distribution.
|
Chris@0
|
8 */
|
Chris@0
|
9
|
Chris@0
|
10 #include "ViewManager.h"
|
Chris@0
|
11 #include "AudioPlaySource.h"
|
Chris@0
|
12 #include "PlayParameters.h"
|
Chris@0
|
13 #include "Model.h"
|
Chris@0
|
14
|
Chris@0
|
15 #include <iostream>
|
Chris@0
|
16
|
Chris@18
|
17 //#define DEBUG_VIEW_MANAGER 1
|
Chris@0
|
18
|
Chris@0
|
19 ViewManager::ViewManager() :
|
Chris@0
|
20 m_playSource(0),
|
Chris@0
|
21 m_globalCentreFrame(0),
|
Chris@0
|
22 m_globalZoom(1024),
|
Chris@24
|
23 m_playbackFrame(0),
|
Chris@0
|
24 m_lastLeft(0),
|
Chris@8
|
25 m_lastRight(0),
|
Chris@8
|
26 m_inProgressExclusive(true),
|
Chris@9
|
27 m_toolMode(NavigateMode),
|
Chris@9
|
28 m_playLoopMode(false),
|
Chris@20
|
29 m_playSelectionMode(false)
|
Chris@0
|
30 {
|
Chris@0
|
31 connect(this,
|
Chris@0
|
32 SIGNAL(centreFrameChanged(void *, unsigned long, bool)),
|
Chris@0
|
33 SLOT(considerSeek(void *, unsigned long, bool)));
|
Chris@0
|
34
|
Chris@0
|
35 connect(this,
|
Chris@0
|
36 SIGNAL(zoomLevelChanged(void *, unsigned long, bool)),
|
Chris@0
|
37 SLOT(considerZoomChange(void *, unsigned long, bool)));
|
Chris@0
|
38 }
|
Chris@0
|
39
|
Chris@0
|
40 unsigned long
|
Chris@0
|
41 ViewManager::getGlobalCentreFrame() const
|
Chris@0
|
42 {
|
Chris@0
|
43 #ifdef DEBUG_VIEW_MANAGER
|
Chris@0
|
44 std::cout << "ViewManager::getGlobalCentreFrame: returning " << m_globalCentreFrame << std::endl;
|
Chris@0
|
45 #endif
|
Chris@0
|
46 return m_globalCentreFrame;
|
Chris@0
|
47 }
|
Chris@0
|
48
|
Chris@0
|
49 unsigned long
|
Chris@0
|
50 ViewManager::getGlobalZoom() const
|
Chris@0
|
51 {
|
Chris@0
|
52 #ifdef DEBUG_VIEW_MANAGER
|
Chris@0
|
53 std::cout << "ViewManager::getGlobalZoom: returning " << m_globalZoom << std::endl;
|
Chris@0
|
54 #endif
|
Chris@0
|
55 return m_globalZoom;
|
Chris@0
|
56 }
|
Chris@0
|
57
|
Chris@24
|
58 unsigned long
|
Chris@24
|
59 ViewManager::getPlaybackFrame() const
|
Chris@24
|
60 {
|
Chris@24
|
61 if (m_playSource && m_playSource->isPlaying()) {
|
Chris@24
|
62 m_playbackFrame = m_playSource->getCurrentPlayingFrame();
|
Chris@24
|
63 }
|
Chris@24
|
64 return m_playbackFrame;
|
Chris@24
|
65 }
|
Chris@24
|
66
|
Chris@24
|
67 void
|
Chris@24
|
68 ViewManager::setPlaybackFrame(unsigned long f)
|
Chris@24
|
69 {
|
Chris@24
|
70 if (m_playbackFrame != f) {
|
Chris@24
|
71 m_playbackFrame = f;
|
Chris@24
|
72 if (m_playSource && m_playSource->isPlaying()) {
|
Chris@24
|
73 m_playSource->play(f);
|
Chris@24
|
74 }
|
Chris@24
|
75 emit playbackFrameChanged(f);
|
Chris@24
|
76 }
|
Chris@24
|
77 }
|
Chris@24
|
78
|
Chris@8
|
79 bool
|
Chris@8
|
80 ViewManager::haveInProgressSelection() const
|
Chris@8
|
81 {
|
Chris@8
|
82 return !m_inProgressSelection.isEmpty();
|
Chris@8
|
83 }
|
Chris@8
|
84
|
Chris@8
|
85 const Selection &
|
Chris@8
|
86 ViewManager::getInProgressSelection(bool &exclusive) const
|
Chris@8
|
87 {
|
Chris@8
|
88 exclusive = m_inProgressExclusive;
|
Chris@8
|
89 return m_inProgressSelection;
|
Chris@8
|
90 }
|
Chris@8
|
91
|
Chris@8
|
92 void
|
Chris@8
|
93 ViewManager::setInProgressSelection(const Selection &selection, bool exclusive)
|
Chris@8
|
94 {
|
Chris@8
|
95 m_inProgressExclusive = exclusive;
|
Chris@8
|
96 m_inProgressSelection = selection;
|
Chris@8
|
97 if (exclusive) clearSelections();
|
Chris@9
|
98 emit inProgressSelectionChanged();
|
Chris@8
|
99 }
|
Chris@8
|
100
|
Chris@8
|
101 void
|
Chris@8
|
102 ViewManager::clearInProgressSelection()
|
Chris@8
|
103 {
|
Chris@8
|
104 m_inProgressSelection = Selection();
|
Chris@9
|
105 emit inProgressSelectionChanged();
|
Chris@8
|
106 }
|
Chris@8
|
107
|
Chris@24
|
108 const MultiSelection::SelectionList &
|
Chris@8
|
109 ViewManager::getSelections() const
|
Chris@8
|
110 {
|
Chris@24
|
111 return m_selections.getSelections();
|
Chris@8
|
112 }
|
Chris@8
|
113
|
Chris@8
|
114 void
|
Chris@8
|
115 ViewManager::setSelection(const Selection &selection)
|
Chris@8
|
116 {
|
Chris@24
|
117 m_selections.setSelection(selection);
|
Chris@24
|
118 emit selectionChanged();
|
Chris@8
|
119 }
|
Chris@8
|
120
|
Chris@8
|
121 void
|
Chris@8
|
122 ViewManager::addSelection(const Selection &selection)
|
Chris@8
|
123 {
|
Chris@24
|
124 m_selections.addSelection(selection);
|
Chris@8
|
125 emit selectionChanged();
|
Chris@8
|
126 }
|
Chris@8
|
127
|
Chris@8
|
128 void
|
Chris@8
|
129 ViewManager::removeSelection(const Selection &selection)
|
Chris@8
|
130 {
|
Chris@24
|
131 m_selections.removeSelection(selection);
|
Chris@24
|
132 emit selectionChanged();
|
Chris@8
|
133 }
|
Chris@8
|
134
|
Chris@8
|
135 void
|
Chris@8
|
136 ViewManager::clearSelections()
|
Chris@8
|
137 {
|
Chris@24
|
138 m_selections.clearSelections();
|
Chris@24
|
139 emit selectionChanged();
|
Chris@8
|
140 }
|
Chris@8
|
141
|
Chris@9
|
142 Selection
|
Chris@9
|
143 ViewManager::getContainingSelection(size_t frame, bool defaultToFollowing)
|
Chris@9
|
144 {
|
Chris@24
|
145 return m_selections.getContainingSelection(frame, defaultToFollowing);
|
Chris@9
|
146 }
|
Chris@9
|
147
|
Chris@8
|
148 void
|
Chris@8
|
149 ViewManager::setToolMode(ToolMode mode)
|
Chris@8
|
150 {
|
Chris@8
|
151 m_toolMode = mode;
|
Chris@8
|
152
|
Chris@8
|
153 emit toolModeChanged();
|
Chris@8
|
154 }
|
Chris@8
|
155
|
Chris@0
|
156 void
|
Chris@9
|
157 ViewManager::setPlayLoopMode(bool mode)
|
Chris@9
|
158 {
|
Chris@9
|
159 m_playLoopMode = mode;
|
Chris@9
|
160
|
Chris@9
|
161 emit playLoopModeChanged();
|
Chris@9
|
162 }
|
Chris@9
|
163
|
Chris@9
|
164 void
|
Chris@9
|
165 ViewManager::setPlaySelectionMode(bool mode)
|
Chris@9
|
166 {
|
Chris@9
|
167 m_playSelectionMode = mode;
|
Chris@9
|
168
|
Chris@9
|
169 emit playSelectionModeChanged();
|
Chris@9
|
170 }
|
Chris@9
|
171
|
Chris@9
|
172 void
|
Chris@0
|
173 ViewManager::setAudioPlaySource(AudioPlaySource *source)
|
Chris@0
|
174 {
|
Chris@0
|
175 if (!m_playSource) {
|
Chris@0
|
176 QTimer::singleShot(100, this, SLOT(checkPlayStatus()));
|
Chris@0
|
177 }
|
Chris@0
|
178 m_playSource = source;
|
Chris@0
|
179 }
|
Chris@0
|
180
|
Chris@0
|
181 PlayParameters *
|
Chris@0
|
182 ViewManager::getPlayParameters(const Model *model)
|
Chris@0
|
183 {
|
Chris@0
|
184 if (m_playParameters.find(model) == m_playParameters.end()) {
|
Chris@0
|
185 // Give all models the same type of play parameters for the moment
|
Chris@0
|
186 m_playParameters[model] = new PlayParameters;
|
Chris@0
|
187 }
|
Chris@0
|
188
|
Chris@0
|
189 return m_playParameters[model];
|
Chris@0
|
190 }
|
Chris@0
|
191
|
Chris@0
|
192 void
|
Chris@0
|
193 ViewManager::clearPlayParameters()
|
Chris@0
|
194 {
|
Chris@0
|
195 while (!m_playParameters.empty()) {
|
Chris@0
|
196 delete m_playParameters.begin()->second;
|
Chris@0
|
197 m_playParameters.erase(m_playParameters.begin());
|
Chris@0
|
198 }
|
Chris@0
|
199 }
|
Chris@0
|
200
|
Chris@0
|
201 void
|
Chris@10
|
202 ViewManager::playStatusChanged(bool playing)
|
Chris@10
|
203 {
|
Chris@10
|
204 checkPlayStatus();
|
Chris@10
|
205 }
|
Chris@10
|
206
|
Chris@10
|
207 void
|
Chris@0
|
208 ViewManager::checkPlayStatus()
|
Chris@0
|
209 {
|
Chris@0
|
210 if (m_playSource && m_playSource->isPlaying()) {
|
Chris@0
|
211
|
Chris@0
|
212 float left = 0, right = 0;
|
Chris@0
|
213 if (m_playSource->getOutputLevels(left, right)) {
|
Chris@0
|
214 if (left != m_lastLeft || right != m_lastRight) {
|
Chris@0
|
215 emit outputLevelsChanged(left, right);
|
Chris@0
|
216 m_lastLeft = left;
|
Chris@0
|
217 m_lastRight = right;
|
Chris@0
|
218 }
|
Chris@0
|
219 }
|
Chris@0
|
220
|
Chris@24
|
221 m_playbackFrame = m_playSource->getCurrentPlayingFrame();
|
Chris@0
|
222
|
Chris@0
|
223 #ifdef DEBUG_VIEW_MANAGER
|
Chris@24
|
224 std::cout << "ViewManager::checkPlayStatus: Playing, frame " << m_playbackFrame << ", levels " << m_lastLeft << "," << m_lastRight << std::endl;
|
Chris@0
|
225 #endif
|
Chris@0
|
226
|
Chris@24
|
227 emit playbackFrameChanged(m_playbackFrame);
|
Chris@0
|
228
|
Chris@0
|
229 QTimer::singleShot(20, this, SLOT(checkPlayStatus()));
|
Chris@0
|
230
|
Chris@0
|
231 } else {
|
Chris@0
|
232
|
Chris@0
|
233 QTimer::singleShot(100, this, SLOT(checkPlayStatus()));
|
Chris@0
|
234
|
Chris@0
|
235 if (m_lastLeft != 0.0 || m_lastRight != 0.0) {
|
Chris@0
|
236 emit outputLevelsChanged(0.0, 0.0);
|
Chris@0
|
237 m_lastLeft = 0.0;
|
Chris@0
|
238 m_lastRight = 0.0;
|
Chris@0
|
239 }
|
Chris@0
|
240
|
Chris@0
|
241 #ifdef DEBUG_VIEW_MANAGER
|
Chris@0
|
242 // std::cout << "ViewManager::checkPlayStatus: Not playing" << std::endl;
|
Chris@0
|
243 #endif
|
Chris@0
|
244 }
|
Chris@0
|
245 }
|
Chris@0
|
246
|
Chris@8
|
247 bool
|
Chris@8
|
248 ViewManager::isPlaying() const
|
Chris@8
|
249 {
|
Chris@8
|
250 return m_playSource && m_playSource->isPlaying();
|
Chris@8
|
251 }
|
Chris@8
|
252
|
Chris@0
|
253 void
|
Chris@0
|
254 ViewManager::considerSeek(void *p, unsigned long f, bool locked)
|
Chris@0
|
255 {
|
Chris@0
|
256 if (locked) {
|
Chris@0
|
257 m_globalCentreFrame = f;
|
Chris@0
|
258 }
|
Chris@0
|
259
|
Chris@0
|
260 #ifdef DEBUG_VIEW_MANAGER
|
Chris@0
|
261 std::cout << "ViewManager::considerSeek(" << p << ", " << f << ", " << locked << ")" << std::endl;
|
Chris@0
|
262 #endif
|
Chris@0
|
263
|
Chris@0
|
264 if (p == this || !locked) return;
|
Chris@0
|
265
|
Chris@0
|
266 if (m_playSource && m_playSource->isPlaying()) {
|
Chris@0
|
267 unsigned long playFrame = m_playSource->getCurrentPlayingFrame();
|
Chris@0
|
268 unsigned long diff = std::max(f, playFrame) - std::min(f, playFrame);
|
Chris@0
|
269 if (diff > 20000) {
|
Chris@24
|
270 m_playbackFrame = f;
|
Chris@0
|
271 m_playSource->play(f);
|
Chris@0
|
272 #ifdef DEBUG_VIEW_MANAGER
|
Chris@0
|
273 std::cout << "ViewManager::considerSeek: reseeking from " << playFrame << " to " << f << std::endl;
|
Chris@0
|
274 #endif
|
Chris@0
|
275 }
|
Chris@24
|
276 } else {
|
Chris@24
|
277 m_playbackFrame = f; //!!! only if that view is in scroll mode?
|
Chris@0
|
278 }
|
Chris@0
|
279 }
|
Chris@0
|
280
|
Chris@0
|
281 void
|
Chris@0
|
282 ViewManager::considerZoomChange(void *p, unsigned long z, bool locked)
|
Chris@0
|
283 {
|
Chris@0
|
284 if (locked) {
|
Chris@0
|
285 m_globalZoom = z;
|
Chris@0
|
286 }
|
Chris@0
|
287
|
Chris@0
|
288 #ifdef DEBUG_VIEW_MANAGER
|
Chris@0
|
289 std::cout << "ViewManager::considerZoomChange(" << p << ", " << z << ", " << locked << ")" << std::endl;
|
Chris@0
|
290 #endif
|
Chris@0
|
291 }
|
Chris@0
|
292
|
Chris@0
|
293 #ifdef INCLUDE_MOCFILES
|
Chris@0
|
294 #include "ViewManager.moc.cpp"
|
Chris@0
|
295 #endif
|
Chris@0
|
296
|