comparison base/ViewManager.cpp @ 0:da6937383da8

initial import
author Chris Cannam
date Tue, 10 Jan 2006 16:33:16 +0000
parents
children d86891498eef
comparison
equal deleted inserted replaced
-1:000000000000 0:da6937383da8
1 /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 A waveform viewer and audio annotation editor.
5 Chris Cannam, Queen Mary University of London, 2005
6
7 This is experimental software. Not for distribution.
8 */
9
10 #include "ViewManager.h"
11 #include "AudioPlaySource.h"
12 #include "PlayParameters.h"
13 #include "Model.h"
14
15 #include <iostream>
16
17 //#define DEBUG_VIEW_MANAGER 1
18
19 ViewManager::ViewManager() :
20 m_playSource(0),
21 m_globalCentreFrame(0),
22 m_globalZoom(1024),
23 m_lastLeft(0),
24 m_lastRight(0)
25 {
26 connect(this,
27 SIGNAL(centreFrameChanged(void *, unsigned long, bool)),
28 SLOT(considerSeek(void *, unsigned long, bool)));
29
30 connect(this,
31 SIGNAL(zoomLevelChanged(void *, unsigned long, bool)),
32 SLOT(considerZoomChange(void *, unsigned long, bool)));
33 }
34
35 unsigned long
36 ViewManager::getGlobalCentreFrame() const
37 {
38 #ifdef DEBUG_VIEW_MANAGER
39 std::cout << "ViewManager::getGlobalCentreFrame: returning " << m_globalCentreFrame << std::endl;
40 #endif
41 return m_globalCentreFrame;
42 }
43
44 unsigned long
45 ViewManager::getGlobalZoom() const
46 {
47 #ifdef DEBUG_VIEW_MANAGER
48 std::cout << "ViewManager::getGlobalZoom: returning " << m_globalZoom << std::endl;
49 #endif
50 return m_globalZoom;
51 }
52
53 void
54 ViewManager::setAudioPlaySource(AudioPlaySource *source)
55 {
56 if (!m_playSource) {
57 QTimer::singleShot(100, this, SLOT(checkPlayStatus()));
58 }
59 m_playSource = source;
60 }
61
62 PlayParameters *
63 ViewManager::getPlayParameters(const Model *model)
64 {
65 if (m_playParameters.find(model) == m_playParameters.end()) {
66 // Give all models the same type of play parameters for the moment
67 m_playParameters[model] = new PlayParameters;
68 }
69
70 return m_playParameters[model];
71 }
72
73 void
74 ViewManager::clearPlayParameters()
75 {
76 while (!m_playParameters.empty()) {
77 delete m_playParameters.begin()->second;
78 m_playParameters.erase(m_playParameters.begin());
79 }
80 }
81
82 void
83 ViewManager::checkPlayStatus()
84 {
85 if (m_playSource && m_playSource->isPlaying()) {
86
87 float left = 0, right = 0;
88 if (m_playSource->getOutputLevels(left, right)) {
89 if (left != m_lastLeft || right != m_lastRight) {
90 emit outputLevelsChanged(left, right);
91 m_lastLeft = left;
92 m_lastRight = right;
93 }
94 }
95
96 m_globalCentreFrame = m_playSource->getCurrentPlayingFrame();
97
98 #ifdef DEBUG_VIEW_MANAGER
99 std::cout << "ViewManager::checkPlayStatus: Playing, frame " << m_globalCentreFrame << ", levels " << m_lastLeft << "," << m_lastRight << std::endl;
100 #endif
101
102 emit playbackFrameChanged(m_globalCentreFrame);
103
104 QTimer::singleShot(20, this, SLOT(checkPlayStatus()));
105
106 } else {
107
108 QTimer::singleShot(100, this, SLOT(checkPlayStatus()));
109
110 if (m_lastLeft != 0.0 || m_lastRight != 0.0) {
111 emit outputLevelsChanged(0.0, 0.0);
112 m_lastLeft = 0.0;
113 m_lastRight = 0.0;
114 }
115
116 #ifdef DEBUG_VIEW_MANAGER
117 // std::cout << "ViewManager::checkPlayStatus: Not playing" << std::endl;
118 #endif
119 }
120 }
121
122 void
123 ViewManager::considerSeek(void *p, unsigned long f, bool locked)
124 {
125 if (locked) {
126 m_globalCentreFrame = f;
127 }
128
129 #ifdef DEBUG_VIEW_MANAGER
130 std::cout << "ViewManager::considerSeek(" << p << ", " << f << ", " << locked << ")" << std::endl;
131 #endif
132
133 if (p == this || !locked) return;
134
135 if (m_playSource && m_playSource->isPlaying()) {
136 unsigned long playFrame = m_playSource->getCurrentPlayingFrame();
137 unsigned long diff = std::max(f, playFrame) - std::min(f, playFrame);
138 if (diff > 20000) {
139 m_playSource->play(f);
140 #ifdef DEBUG_VIEW_MANAGER
141 std::cout << "ViewManager::considerSeek: reseeking from " << playFrame << " to " << f << std::endl;
142 #endif
143 }
144 }
145 }
146
147 void
148 ViewManager::considerZoomChange(void *p, unsigned long z, bool locked)
149 {
150 if (locked) {
151 m_globalZoom = z;
152 }
153
154 #ifdef DEBUG_VIEW_MANAGER
155 std::cout << "ViewManager::considerZoomChange(" << p << ", " << z << ", " << locked << ")" << std::endl;
156 #endif
157 }
158
159 #ifdef INCLUDE_MOCFILES
160 #include "ViewManager.moc.cpp"
161 #endif
162