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@0
|
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@0
|
23 m_lastLeft(0),
|
Chris@0
|
24 m_lastRight(0)
|
Chris@0
|
25 {
|
Chris@0
|
26 connect(this,
|
Chris@0
|
27 SIGNAL(centreFrameChanged(void *, unsigned long, bool)),
|
Chris@0
|
28 SLOT(considerSeek(void *, unsigned long, bool)));
|
Chris@0
|
29
|
Chris@0
|
30 connect(this,
|
Chris@0
|
31 SIGNAL(zoomLevelChanged(void *, unsigned long, bool)),
|
Chris@0
|
32 SLOT(considerZoomChange(void *, unsigned long, bool)));
|
Chris@0
|
33 }
|
Chris@0
|
34
|
Chris@0
|
35 unsigned long
|
Chris@0
|
36 ViewManager::getGlobalCentreFrame() const
|
Chris@0
|
37 {
|
Chris@0
|
38 #ifdef DEBUG_VIEW_MANAGER
|
Chris@0
|
39 std::cout << "ViewManager::getGlobalCentreFrame: returning " << m_globalCentreFrame << std::endl;
|
Chris@0
|
40 #endif
|
Chris@0
|
41 return m_globalCentreFrame;
|
Chris@0
|
42 }
|
Chris@0
|
43
|
Chris@0
|
44 unsigned long
|
Chris@0
|
45 ViewManager::getGlobalZoom() const
|
Chris@0
|
46 {
|
Chris@0
|
47 #ifdef DEBUG_VIEW_MANAGER
|
Chris@0
|
48 std::cout << "ViewManager::getGlobalZoom: returning " << m_globalZoom << std::endl;
|
Chris@0
|
49 #endif
|
Chris@0
|
50 return m_globalZoom;
|
Chris@0
|
51 }
|
Chris@0
|
52
|
Chris@0
|
53 void
|
Chris@0
|
54 ViewManager::setAudioPlaySource(AudioPlaySource *source)
|
Chris@0
|
55 {
|
Chris@0
|
56 if (!m_playSource) {
|
Chris@0
|
57 QTimer::singleShot(100, this, SLOT(checkPlayStatus()));
|
Chris@0
|
58 }
|
Chris@0
|
59 m_playSource = source;
|
Chris@0
|
60 }
|
Chris@0
|
61
|
Chris@0
|
62 PlayParameters *
|
Chris@0
|
63 ViewManager::getPlayParameters(const Model *model)
|
Chris@0
|
64 {
|
Chris@0
|
65 if (m_playParameters.find(model) == m_playParameters.end()) {
|
Chris@0
|
66 // Give all models the same type of play parameters for the moment
|
Chris@0
|
67 m_playParameters[model] = new PlayParameters;
|
Chris@0
|
68 }
|
Chris@0
|
69
|
Chris@0
|
70 return m_playParameters[model];
|
Chris@0
|
71 }
|
Chris@0
|
72
|
Chris@0
|
73 void
|
Chris@0
|
74 ViewManager::clearPlayParameters()
|
Chris@0
|
75 {
|
Chris@0
|
76 while (!m_playParameters.empty()) {
|
Chris@0
|
77 delete m_playParameters.begin()->second;
|
Chris@0
|
78 m_playParameters.erase(m_playParameters.begin());
|
Chris@0
|
79 }
|
Chris@0
|
80 }
|
Chris@0
|
81
|
Chris@0
|
82 void
|
Chris@0
|
83 ViewManager::checkPlayStatus()
|
Chris@0
|
84 {
|
Chris@0
|
85 if (m_playSource && m_playSource->isPlaying()) {
|
Chris@0
|
86
|
Chris@0
|
87 float left = 0, right = 0;
|
Chris@0
|
88 if (m_playSource->getOutputLevels(left, right)) {
|
Chris@0
|
89 if (left != m_lastLeft || right != m_lastRight) {
|
Chris@0
|
90 emit outputLevelsChanged(left, right);
|
Chris@0
|
91 m_lastLeft = left;
|
Chris@0
|
92 m_lastRight = right;
|
Chris@0
|
93 }
|
Chris@0
|
94 }
|
Chris@0
|
95
|
Chris@0
|
96 m_globalCentreFrame = m_playSource->getCurrentPlayingFrame();
|
Chris@0
|
97
|
Chris@0
|
98 #ifdef DEBUG_VIEW_MANAGER
|
Chris@0
|
99 std::cout << "ViewManager::checkPlayStatus: Playing, frame " << m_globalCentreFrame << ", levels " << m_lastLeft << "," << m_lastRight << std::endl;
|
Chris@0
|
100 #endif
|
Chris@0
|
101
|
Chris@0
|
102 emit playbackFrameChanged(m_globalCentreFrame);
|
Chris@0
|
103
|
Chris@0
|
104 QTimer::singleShot(20, this, SLOT(checkPlayStatus()));
|
Chris@0
|
105
|
Chris@0
|
106 } else {
|
Chris@0
|
107
|
Chris@0
|
108 QTimer::singleShot(100, this, SLOT(checkPlayStatus()));
|
Chris@0
|
109
|
Chris@0
|
110 if (m_lastLeft != 0.0 || m_lastRight != 0.0) {
|
Chris@0
|
111 emit outputLevelsChanged(0.0, 0.0);
|
Chris@0
|
112 m_lastLeft = 0.0;
|
Chris@0
|
113 m_lastRight = 0.0;
|
Chris@0
|
114 }
|
Chris@0
|
115
|
Chris@0
|
116 #ifdef DEBUG_VIEW_MANAGER
|
Chris@0
|
117 // std::cout << "ViewManager::checkPlayStatus: Not playing" << std::endl;
|
Chris@0
|
118 #endif
|
Chris@0
|
119 }
|
Chris@0
|
120 }
|
Chris@0
|
121
|
Chris@0
|
122 void
|
Chris@0
|
123 ViewManager::considerSeek(void *p, unsigned long f, bool locked)
|
Chris@0
|
124 {
|
Chris@0
|
125 if (locked) {
|
Chris@0
|
126 m_globalCentreFrame = f;
|
Chris@0
|
127 }
|
Chris@0
|
128
|
Chris@0
|
129 #ifdef DEBUG_VIEW_MANAGER
|
Chris@0
|
130 std::cout << "ViewManager::considerSeek(" << p << ", " << f << ", " << locked << ")" << std::endl;
|
Chris@0
|
131 #endif
|
Chris@0
|
132
|
Chris@0
|
133 if (p == this || !locked) return;
|
Chris@0
|
134
|
Chris@0
|
135 if (m_playSource && m_playSource->isPlaying()) {
|
Chris@0
|
136 unsigned long playFrame = m_playSource->getCurrentPlayingFrame();
|
Chris@0
|
137 unsigned long diff = std::max(f, playFrame) - std::min(f, playFrame);
|
Chris@0
|
138 if (diff > 20000) {
|
Chris@0
|
139 m_playSource->play(f);
|
Chris@0
|
140 #ifdef DEBUG_VIEW_MANAGER
|
Chris@0
|
141 std::cout << "ViewManager::considerSeek: reseeking from " << playFrame << " to " << f << std::endl;
|
Chris@0
|
142 #endif
|
Chris@0
|
143 }
|
Chris@0
|
144 }
|
Chris@0
|
145 }
|
Chris@0
|
146
|
Chris@0
|
147 void
|
Chris@0
|
148 ViewManager::considerZoomChange(void *p, unsigned long z, bool locked)
|
Chris@0
|
149 {
|
Chris@0
|
150 if (locked) {
|
Chris@0
|
151 m_globalZoom = z;
|
Chris@0
|
152 }
|
Chris@0
|
153
|
Chris@0
|
154 #ifdef DEBUG_VIEW_MANAGER
|
Chris@0
|
155 std::cout << "ViewManager::considerZoomChange(" << p << ", " << z << ", " << locked << ")" << std::endl;
|
Chris@0
|
156 #endif
|
Chris@0
|
157 }
|
Chris@0
|
158
|
Chris@0
|
159 #ifdef INCLUDE_MOCFILES
|
Chris@0
|
160 #include "ViewManager.moc.cpp"
|
Chris@0
|
161 #endif
|
Chris@0
|
162
|