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