annotate base/ViewManager.cpp @ 38:a6b2128eed56

* Continue MainWindow refactoring by making MainWindow actually use the new Document class -- still somewhat unstable * Fix crash in spectrogram layer * Rename tonalestimator to TonalEstimator and add to project file
author Chris Cannam
date Fri, 03 Mar 2006 16:56:20 +0000
parents 935a2419a77c
children b2d1a61ab916
rev   line source
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@34 107 const MultiSelection &
Chris@34 108 ViewManager::getSelection() const
Chris@34 109 {
Chris@34 110 return m_selections;
Chris@34 111 }
Chris@34 112
Chris@24 113 const MultiSelection::SelectionList &
Chris@8 114 ViewManager::getSelections() const
Chris@8 115 {
Chris@24 116 return m_selections.getSelections();
Chris@8 117 }
Chris@8 118
Chris@8 119 void
Chris@8 120 ViewManager::setSelection(const Selection &selection)
Chris@8 121 {
Chris@24 122 m_selections.setSelection(selection);
Chris@24 123 emit selectionChanged();
Chris@8 124 }
Chris@8 125
Chris@8 126 void
Chris@8 127 ViewManager::addSelection(const Selection &selection)
Chris@8 128 {
Chris@24 129 m_selections.addSelection(selection);
Chris@8 130 emit selectionChanged();
Chris@8 131 }
Chris@8 132
Chris@8 133 void
Chris@8 134 ViewManager::removeSelection(const Selection &selection)
Chris@8 135 {
Chris@24 136 m_selections.removeSelection(selection);
Chris@24 137 emit selectionChanged();
Chris@8 138 }
Chris@8 139
Chris@8 140 void
Chris@8 141 ViewManager::clearSelections()
Chris@8 142 {
Chris@24 143 m_selections.clearSelections();
Chris@24 144 emit selectionChanged();
Chris@8 145 }
Chris@8 146
Chris@9 147 Selection
Chris@36 148 ViewManager::getContainingSelection(size_t frame, bool defaultToFollowing) const
Chris@9 149 {
Chris@24 150 return m_selections.getContainingSelection(frame, defaultToFollowing);
Chris@9 151 }
Chris@9 152
Chris@8 153 void
Chris@8 154 ViewManager::setToolMode(ToolMode mode)
Chris@8 155 {
Chris@8 156 m_toolMode = mode;
Chris@8 157
Chris@8 158 emit toolModeChanged();
Chris@8 159 }
Chris@8 160
Chris@0 161 void
Chris@9 162 ViewManager::setPlayLoopMode(bool mode)
Chris@9 163 {
Chris@9 164 m_playLoopMode = mode;
Chris@9 165
Chris@9 166 emit playLoopModeChanged();
Chris@9 167 }
Chris@9 168
Chris@9 169 void
Chris@9 170 ViewManager::setPlaySelectionMode(bool mode)
Chris@9 171 {
Chris@9 172 m_playSelectionMode = mode;
Chris@9 173
Chris@9 174 emit playSelectionModeChanged();
Chris@9 175 }
Chris@9 176
Chris@9 177 void
Chris@0 178 ViewManager::setAudioPlaySource(AudioPlaySource *source)
Chris@0 179 {
Chris@0 180 if (!m_playSource) {
Chris@0 181 QTimer::singleShot(100, this, SLOT(checkPlayStatus()));
Chris@0 182 }
Chris@0 183 m_playSource = source;
Chris@0 184 }
Chris@0 185
Chris@0 186 void
Chris@10 187 ViewManager::playStatusChanged(bool playing)
Chris@10 188 {
Chris@10 189 checkPlayStatus();
Chris@10 190 }
Chris@10 191
Chris@10 192 void
Chris@0 193 ViewManager::checkPlayStatus()
Chris@0 194 {
Chris@0 195 if (m_playSource && m_playSource->isPlaying()) {
Chris@0 196
Chris@0 197 float left = 0, right = 0;
Chris@0 198 if (m_playSource->getOutputLevels(left, right)) {
Chris@0 199 if (left != m_lastLeft || right != m_lastRight) {
Chris@0 200 emit outputLevelsChanged(left, right);
Chris@0 201 m_lastLeft = left;
Chris@0 202 m_lastRight = right;
Chris@0 203 }
Chris@0 204 }
Chris@0 205
Chris@24 206 m_playbackFrame = m_playSource->getCurrentPlayingFrame();
Chris@0 207
Chris@0 208 #ifdef DEBUG_VIEW_MANAGER
Chris@24 209 std::cout << "ViewManager::checkPlayStatus: Playing, frame " << m_playbackFrame << ", levels " << m_lastLeft << "," << m_lastRight << std::endl;
Chris@0 210 #endif
Chris@0 211
Chris@24 212 emit playbackFrameChanged(m_playbackFrame);
Chris@0 213
Chris@0 214 QTimer::singleShot(20, this, SLOT(checkPlayStatus()));
Chris@0 215
Chris@0 216 } else {
Chris@0 217
Chris@0 218 QTimer::singleShot(100, this, SLOT(checkPlayStatus()));
Chris@0 219
Chris@0 220 if (m_lastLeft != 0.0 || m_lastRight != 0.0) {
Chris@0 221 emit outputLevelsChanged(0.0, 0.0);
Chris@0 222 m_lastLeft = 0.0;
Chris@0 223 m_lastRight = 0.0;
Chris@0 224 }
Chris@0 225
Chris@0 226 #ifdef DEBUG_VIEW_MANAGER
Chris@0 227 // std::cout << "ViewManager::checkPlayStatus: Not playing" << std::endl;
Chris@0 228 #endif
Chris@0 229 }
Chris@0 230 }
Chris@0 231
Chris@8 232 bool
Chris@8 233 ViewManager::isPlaying() const
Chris@8 234 {
Chris@8 235 return m_playSource && m_playSource->isPlaying();
Chris@8 236 }
Chris@8 237
Chris@0 238 void
Chris@0 239 ViewManager::considerSeek(void *p, unsigned long f, bool locked)
Chris@0 240 {
Chris@0 241 if (locked) {
Chris@0 242 m_globalCentreFrame = f;
Chris@0 243 }
Chris@0 244
Chris@0 245 #ifdef DEBUG_VIEW_MANAGER
Chris@0 246 std::cout << "ViewManager::considerSeek(" << p << ", " << f << ", " << locked << ")" << std::endl;
Chris@0 247 #endif
Chris@0 248
Chris@0 249 if (p == this || !locked) return;
Chris@0 250
Chris@0 251 if (m_playSource && m_playSource->isPlaying()) {
Chris@0 252 unsigned long playFrame = m_playSource->getCurrentPlayingFrame();
Chris@0 253 unsigned long diff = std::max(f, playFrame) - std::min(f, playFrame);
Chris@0 254 if (diff > 20000) {
Chris@24 255 m_playbackFrame = f;
Chris@0 256 m_playSource->play(f);
Chris@0 257 #ifdef DEBUG_VIEW_MANAGER
Chris@0 258 std::cout << "ViewManager::considerSeek: reseeking from " << playFrame << " to " << f << std::endl;
Chris@0 259 #endif
Chris@0 260 }
Chris@24 261 } else {
Chris@24 262 m_playbackFrame = f; //!!! only if that view is in scroll mode?
Chris@0 263 }
Chris@0 264 }
Chris@0 265
Chris@0 266 void
Chris@0 267 ViewManager::considerZoomChange(void *p, unsigned long z, bool locked)
Chris@0 268 {
Chris@0 269 if (locked) {
Chris@0 270 m_globalZoom = z;
Chris@0 271 }
Chris@0 272
Chris@0 273 #ifdef DEBUG_VIEW_MANAGER
Chris@0 274 std::cout << "ViewManager::considerZoomChange(" << p << ", " << z << ", " << locked << ")" << std::endl;
Chris@0 275 #endif
Chris@0 276 }
Chris@0 277
Chris@0 278 #ifdef INCLUDE_MOCFILES
Chris@0 279 #include "ViewManager.moc.cpp"
Chris@0 280 #endif
Chris@0 281