annotate view/ViewManager.cpp @ 1160:a429b2acb45d 3.0-integration

Make SVDEBUG always write to a log file -- formerly this was disabled in NDEBUG builds. I think there's little use to that, it just means that we keep adding more cerr debug output because we aren't getting the log we need. And SVDEBUG logging is not usually used in tight loops, I don't think the performance overhead is too serious. Also update the About box.
author Chris Cannam
date Thu, 03 Nov 2016 14:57:00 +0000
parents f2c63ec85901
children e0ac21f07ab0
rev   line source
Chris@127 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@127 2
Chris@127 3 /*
Chris@127 4 Sonic Visualiser
Chris@127 5 An audio file viewer and annotation editor.
Chris@127 6 Centre for Digital Music, Queen Mary, University of London.
Chris@182 7 This file copyright 2006 Chris Cannam and QMUL.
Chris@127 8
Chris@127 9 This program is free software; you can redistribute it and/or
Chris@127 10 modify it under the terms of the GNU General Public License as
Chris@127 11 published by the Free Software Foundation; either version 2 of the
Chris@127 12 License, or (at your option) any later version. See the file
Chris@127 13 COPYING included with this distribution for more information.
Chris@127 14 */
Chris@127 15
Chris@127 16 #include "ViewManager.h"
Chris@128 17 #include "base/AudioPlaySource.h"
Chris@502 18 #include "base/RealTime.h"
Chris@128 19 #include "data/model/Model.h"
Chris@376 20 #include "widgets/CommandHistory.h"
Chris@211 21 #include "View.h"
Chris@503 22 #include "Overview.h"
Chris@127 23
Chris@133 24 #include <QSettings>
Chris@292 25 #include <QApplication>
Chris@133 26
Chris@127 27 #include <iostream>
Chris@127 28
Chris@643 29 //#define DEBUG_VIEW_MANAGER 1
Chris@127 30
Chris@127 31 ViewManager::ViewManager() :
Chris@127 32 m_playSource(0),
Chris@127 33 m_globalCentreFrame(0),
Chris@127 34 m_globalZoom(1024),
Chris@127 35 m_playbackFrame(0),
Chris@301 36 m_playbackModel(0),
Chris@127 37 m_mainModelSampleRate(0),
Chris@127 38 m_lastLeft(0),
Chris@127 39 m_lastRight(0),
Chris@127 40 m_inProgressExclusive(true),
Chris@127 41 m_toolMode(NavigateMode),
Chris@127 42 m_playLoopMode(false),
Chris@127 43 m_playSelectionMode(false),
Chris@301 44 m_playSoloMode(false),
Chris@314 45 m_alignMode(false),
Chris@741 46 m_overlayMode(StandardOverlays),
Chris@292 47 m_zoomWheelsEnabled(true),
Chris@607 48 m_showCentreLine(true),
Chris@326 49 m_illuminateLocalFeatures(true),
Chris@326 50 m_showWorkTitle(false),
matthiasm@822 51 m_showDuration(true),
Chris@292 52 m_lightPalette(QApplication::palette()),
Chris@292 53 m_darkPalette(QApplication::palette())
Chris@127 54 {
Chris@133 55 QSettings settings;
Chris@133 56 settings.beginGroup("MainWindow");
Chris@133 57 m_overlayMode = OverlayMode
Chris@133 58 (settings.value("overlay-mode", int(m_overlayMode)).toInt());
Chris@607 59
Chris@607 60 if (m_overlayMode != NoOverlays &&
Chris@741 61 m_overlayMode != StandardOverlays &&
Chris@607 62 m_overlayMode != AllOverlays) {
Chris@741 63 m_overlayMode = StandardOverlays;
Chris@607 64 }
Chris@607 65
Chris@133 66 m_zoomWheelsEnabled =
Chris@133 67 settings.value("zoom-wheels-enabled", m_zoomWheelsEnabled).toBool();
Chris@607 68 m_showCentreLine =
Chris@607 69 settings.value("show-centre-line", m_showCentreLine).toBool();
Chris@133 70 settings.endGroup();
Chris@292 71
Chris@292 72 if (getGlobalDarkBackground()) {
Chris@343 73 /*
Chris@682 74 cerr << "dark palette:" << endl;
Chris@682 75 cerr << "window = " << QApplication::palette().color(QPalette::Window).name() << endl;
Chris@682 76 cerr << "windowtext = " << QApplication::palette().color(QPalette::WindowText).name() << endl;
Chris@682 77 cerr << "base = " << QApplication::palette().color(QPalette::Base).name() << endl;
Chris@682 78 cerr << "alternatebase = " << QApplication::palette().color(QPalette::AlternateBase).name() << endl;
Chris@682 79 cerr << "text = " << QApplication::palette().color(QPalette::Text).name() << endl;
Chris@682 80 cerr << "button = " << QApplication::palette().color(QPalette::Button).name() << endl;
Chris@682 81 cerr << "buttontext = " << QApplication::palette().color(QPalette::ButtonText).name() << endl;
Chris@682 82 cerr << "brighttext = " << QApplication::palette().color(QPalette::BrightText).name() << endl;
Chris@682 83 cerr << "light = " << QApplication::palette().color(QPalette::Light).name() << endl;
Chris@682 84 cerr << "dark = " << QApplication::palette().color(QPalette::Dark).name() << endl;
Chris@682 85 cerr << "mid = " << QApplication::palette().color(QPalette::Mid).name() << endl;
Chris@343 86 */
Chris@293 87 m_lightPalette = QPalette(QColor("#000000"), // WindowText
Chris@293 88 QColor("#dddfe4"), // Button
Chris@293 89 QColor("#ffffff"), // Light
Chris@293 90 QColor("#555555"), // Dark
Chris@293 91 QColor("#c7c7c7"), // Mid
Chris@293 92 QColor("#000000"), // Text
Chris@293 93 QColor("#ffffff"), // BrightText
Chris@293 94 QColor("#ffffff"), // Base
Chris@293 95 QColor("#efefef")); // Window
Chris@293 96
Chris@293 97
Chris@292 98 } else {
Chris@343 99 /*
Chris@682 100 cerr << "light palette:" << endl;
Chris@682 101 cerr << "window = " << QApplication::palette().color(QPalette::Window).name() << endl;
Chris@682 102 cerr << "windowtext = " << QApplication::palette().color(QPalette::WindowText).name() << endl;
Chris@682 103 cerr << "base = " << QApplication::palette().color(QPalette::Base).name() << endl;
Chris@682 104 cerr << "alternatebase = " << QApplication::palette().color(QPalette::AlternateBase).name() << endl;
Chris@682 105 cerr << "text = " << QApplication::palette().color(QPalette::Text).name() << endl;
Chris@682 106 cerr << "button = " << QApplication::palette().color(QPalette::Button).name() << endl;
Chris@682 107 cerr << "buttontext = " << QApplication::palette().color(QPalette::ButtonText).name() << endl;
Chris@682 108 cerr << "brighttext = " << QApplication::palette().color(QPalette::BrightText).name() << endl;
Chris@682 109 cerr << "light = " << QApplication::palette().color(QPalette::Light).name() << endl;
Chris@682 110 cerr << "dark = " << QApplication::palette().color(QPalette::Dark).name() << endl;
Chris@682 111 cerr << "mid = " << QApplication::palette().color(QPalette::Mid).name() << endl;
Chris@343 112 */
Chris@293 113 m_darkPalette = QPalette(QColor("#ffffff"), // WindowText
Chris@293 114 QColor("#3e3e3e"), // Button
Chris@293 115 QColor("#808080"), // Light
Chris@293 116 QColor("#1e1e1e"), // Dark
Chris@293 117 QColor("#404040"), // Mid
Chris@293 118 QColor("#ffffff"), // Text
Chris@293 119 QColor("#ffffff"), // BrightText
Chris@293 120 QColor("#000000"), // Base
Chris@293 121 QColor("#202020")); // Window
Chris@292 122 }
Chris@127 123 }
Chris@127 124
Chris@127 125 ViewManager::~ViewManager()
Chris@127 126 {
Chris@127 127 }
Chris@127 128
Chris@902 129 sv_frame_t
Chris@127 130 ViewManager::getGlobalCentreFrame() const
Chris@127 131 {
Chris@127 132 #ifdef DEBUG_VIEW_MANAGER
Chris@682 133 cerr << "ViewManager::getGlobalCentreFrame: returning " << m_globalCentreFrame << endl;
Chris@127 134 #endif
Chris@127 135 return m_globalCentreFrame;
Chris@127 136 }
Chris@127 137
Chris@180 138 void
Chris@902 139 ViewManager::setGlobalCentreFrame(sv_frame_t f)
Chris@180 140 {
Chris@180 141 #ifdef DEBUG_VIEW_MANAGER
Chris@682 142 cerr << "ViewManager::setGlobalCentreFrame to " << f << endl;
Chris@180 143 #endif
Chris@180 144 m_globalCentreFrame = f;
Chris@211 145 emit globalCentreFrameChanged(f);
Chris@180 146 }
Chris@180 147
Chris@806 148 int
Chris@127 149 ViewManager::getGlobalZoom() const
Chris@127 150 {
Chris@127 151 #ifdef DEBUG_VIEW_MANAGER
Chris@682 152 cerr << "ViewManager::getGlobalZoom: returning " << m_globalZoom << endl;
Chris@127 153 #endif
Chris@127 154 return m_globalZoom;
Chris@127 155 }
Chris@127 156
Chris@902 157 sv_frame_t
Chris@127 158 ViewManager::getPlaybackFrame() const
Chris@127 159 {
Chris@127 160 if (m_playSource && m_playSource->isPlaying()) {
Chris@127 161 m_playbackFrame = m_playSource->getCurrentPlayingFrame();
Chris@127 162 }
Chris@127 163 return m_playbackFrame;
Chris@127 164 }
Chris@127 165
Chris@127 166 void
Chris@902 167 ViewManager::setPlaybackFrame(sv_frame_t f)
Chris@127 168 {
Chris@968 169 if (f < 0) f = 0;
Chris@127 170 if (m_playbackFrame != f) {
Chris@127 171 m_playbackFrame = f;
Chris@127 172 emit playbackFrameChanged(f);
Chris@127 173 if (m_playSource && m_playSource->isPlaying()) {
Chris@127 174 m_playSource->play(f);
Chris@127 175 }
Chris@127 176 }
Chris@127 177 }
Chris@127 178
Chris@301 179 Model *
Chris@301 180 ViewManager::getPlaybackModel() const
Chris@301 181 {
Chris@301 182 return m_playbackModel;
Chris@301 183 }
Chris@301 184
Chris@301 185 void
Chris@301 186 ViewManager::setPlaybackModel(Model *model)
Chris@301 187 {
Chris@301 188 m_playbackModel = model;
Chris@301 189 }
Chris@301 190
Chris@902 191 sv_frame_t
Chris@902 192 ViewManager::alignPlaybackFrameToReference(sv_frame_t frame) const
Chris@333 193 {
Chris@830 194 #ifdef DEBUG_VIEW_MANAGER
Chris@830 195 cerr << "ViewManager::alignPlaybackFrameToReference(" << frame << "): playback model is " << m_playbackModel << endl;
Chris@830 196 #endif
Chris@830 197 if (!m_playbackModel) {
Chris@830 198 return frame;
Chris@830 199 } else {
Chris@902 200 sv_frame_t f = m_playbackModel->alignToReference(frame);
Chris@830 201 #ifdef DEBUG_VIEW_MANAGER
Chris@830 202 cerr << "aligned frame = " << f << endl;
Chris@830 203 #endif
Chris@830 204 return f;
Chris@830 205 }
Chris@333 206 }
Chris@333 207
Chris@902 208 sv_frame_t
Chris@902 209 ViewManager::alignReferenceToPlaybackFrame(sv_frame_t frame) const
Chris@333 210 {
Chris@830 211 #ifdef DEBUG_VIEW_MANAGER
Chris@830 212 cerr << "ViewManager::alignReferenceToPlaybackFrame(" << frame << "): playback model is " << m_playbackModel << endl;
Chris@830 213 #endif
Chris@830 214 if (!m_playbackModel) {
Chris@830 215 return frame;
Chris@830 216 } else {
Chris@902 217 sv_frame_t f = m_playbackModel->alignFromReference(frame);
Chris@830 218 #ifdef DEBUG_VIEW_MANAGER
Chris@830 219 cerr << "aligned frame = " << f << endl;
Chris@830 220 #endif
Chris@830 221 return f;
Chris@830 222 }
Chris@333 223 }
Chris@333 224
Chris@127 225 bool
Chris@127 226 ViewManager::haveInProgressSelection() const
Chris@127 227 {
Chris@127 228 return !m_inProgressSelection.isEmpty();
Chris@127 229 }
Chris@127 230
Chris@127 231 const Selection &
Chris@127 232 ViewManager::getInProgressSelection(bool &exclusive) const
Chris@127 233 {
Chris@127 234 exclusive = m_inProgressExclusive;
Chris@127 235 return m_inProgressSelection;
Chris@127 236 }
Chris@127 237
Chris@127 238 void
Chris@127 239 ViewManager::setInProgressSelection(const Selection &selection, bool exclusive)
Chris@127 240 {
Chris@127 241 m_inProgressExclusive = exclusive;
Chris@127 242 m_inProgressSelection = selection;
Chris@127 243 if (exclusive) clearSelections();
Chris@127 244 emit inProgressSelectionChanged();
Chris@127 245 }
Chris@127 246
Chris@127 247 void
Chris@127 248 ViewManager::clearInProgressSelection()
Chris@127 249 {
Chris@127 250 m_inProgressSelection = Selection();
Chris@127 251 emit inProgressSelectionChanged();
Chris@127 252 }
Chris@127 253
Chris@127 254 const MultiSelection &
Chris@127 255 ViewManager::getSelection() const
Chris@127 256 {
Chris@127 257 return m_selections;
Chris@127 258 }
Chris@127 259
Chris@127 260 const MultiSelection::SelectionList &
Chris@127 261 ViewManager::getSelections() const
Chris@127 262 {
Chris@127 263 return m_selections.getSelections();
Chris@127 264 }
Chris@127 265
Chris@127 266 void
Chris@127 267 ViewManager::setSelection(const Selection &selection)
Chris@127 268 {
Chris@127 269 MultiSelection ms(m_selections);
Chris@127 270 ms.setSelection(selection);
Chris@127 271 setSelections(ms);
Chris@127 272 }
Chris@127 273
Chris@127 274 void
Chris@127 275 ViewManager::addSelection(const Selection &selection)
Chris@127 276 {
Chris@127 277 MultiSelection ms(m_selections);
Chris@127 278 ms.addSelection(selection);
Chris@127 279 setSelections(ms);
Chris@127 280 }
Chris@127 281
Chris@127 282 void
Chris@762 283 ViewManager::addSelectionQuietly(const Selection &selection)
Chris@762 284 {
Chris@762 285 MultiSelection ms(m_selections);
Chris@762 286 ms.addSelection(selection);
Chris@762 287 setSelections(ms, true);
Chris@762 288 }
Chris@762 289
Chris@762 290 void
Chris@127 291 ViewManager::removeSelection(const Selection &selection)
Chris@127 292 {
Chris@127 293 MultiSelection ms(m_selections);
Chris@127 294 ms.removeSelection(selection);
Chris@127 295 setSelections(ms);
Chris@127 296 }
Chris@127 297
Chris@127 298 void
Chris@127 299 ViewManager::clearSelections()
Chris@127 300 {
Chris@127 301 MultiSelection ms(m_selections);
Chris@127 302 ms.clearSelections();
Chris@127 303 setSelections(ms);
Chris@127 304 }
Chris@127 305
Chris@127 306 void
Chris@762 307 ViewManager::setSelections(const MultiSelection &ms, bool quietly)
Chris@127 308 {
Chris@127 309 if (m_selections.getSelections() == ms.getSelections()) return;
Chris@127 310 SetSelectionCommand *command = new SetSelectionCommand(this, ms);
Chris@127 311 CommandHistory::getInstance()->addCommand(command);
Chris@762 312 if (!quietly) {
Chris@762 313 emit selectionChangedByUser();
Chris@762 314 }
Chris@127 315 }
Chris@127 316
Chris@902 317 sv_frame_t
Chris@902 318 ViewManager::constrainFrameToSelection(sv_frame_t frame) const
Chris@271 319 {
Chris@271 320 MultiSelection::SelectionList sl = getSelections();
Chris@271 321 if (sl.empty()) return frame;
Chris@271 322
Chris@368 323 for (MultiSelection::SelectionList::const_iterator i = sl.begin();
Chris@368 324 i != sl.end(); ++i) {
Chris@368 325
Chris@368 326 if (frame < i->getEndFrame()) {
Chris@368 327 if (frame < i->getStartFrame()) {
Chris@368 328 return i->getStartFrame();
Chris@368 329 } else {
Chris@368 330 return frame;
Chris@368 331 }
Chris@368 332 }
Chris@271 333 }
Chris@271 334
Chris@368 335 return sl.begin()->getStartFrame();
Chris@271 336 }
Chris@271 337
Chris@127 338 void
Chris@127 339 ViewManager::signalSelectionChange()
Chris@127 340 {
Chris@127 341 emit selectionChanged();
Chris@127 342 }
Chris@127 343
Chris@127 344 ViewManager::SetSelectionCommand::SetSelectionCommand(ViewManager *vm,
Chris@127 345 const MultiSelection &ms) :
Chris@127 346 m_vm(vm),
Chris@127 347 m_oldSelection(vm->m_selections),
Chris@127 348 m_newSelection(ms)
Chris@127 349 {
Chris@127 350 }
Chris@127 351
Chris@127 352 ViewManager::SetSelectionCommand::~SetSelectionCommand() { }
Chris@127 353
Chris@127 354 void
Chris@127 355 ViewManager::SetSelectionCommand::execute()
Chris@127 356 {
Chris@127 357 m_vm->m_selections = m_newSelection;
Chris@127 358 m_vm->signalSelectionChange();
Chris@127 359 }
Chris@127 360
Chris@127 361 void
Chris@127 362 ViewManager::SetSelectionCommand::unexecute()
Chris@127 363 {
Chris@127 364 m_vm->m_selections = m_oldSelection;
Chris@127 365 m_vm->signalSelectionChange();
Chris@127 366 }
Chris@127 367
Chris@127 368 QString
Chris@127 369 ViewManager::SetSelectionCommand::getName() const
Chris@127 370 {
Chris@127 371 if (m_newSelection.getSelections().empty()) return tr("Clear Selection");
Chris@502 372 if (m_newSelection.getSelections().size() > 1) return tr("Select Multiple Regions");
Chris@502 373 else return tr("Select Region");
Chris@127 374 }
Chris@127 375
Chris@127 376 Selection
Chris@902 377 ViewManager::getContainingSelection(sv_frame_t frame, bool defaultToFollowing) const
Chris@127 378 {
Chris@127 379 return m_selections.getContainingSelection(frame, defaultToFollowing);
Chris@127 380 }
Chris@127 381
Chris@127 382 void
Chris@127 383 ViewManager::setToolMode(ToolMode mode)
Chris@127 384 {
Chris@127 385 m_toolMode = mode;
Chris@127 386
Chris@127 387 emit toolModeChanged();
Chris@502 388
Chris@502 389 switch (mode) {
Chris@502 390 case NavigateMode: emit activity(tr("Enter Navigate mode")); break;
Chris@502 391 case SelectMode: emit activity(tr("Enter Select mode")); break;
Chris@502 392 case EditMode: emit activity(tr("Enter Edit mode")); break;
Chris@502 393 case DrawMode: emit activity(tr("Enter Draw mode")); break;
Chris@502 394 case EraseMode: emit activity(tr("Enter Erase mode")); break;
Chris@502 395 case MeasureMode: emit activity(tr("Enter Measure mode")); break;
gyorgyf@645 396 case NoteEditMode: emit activity(tr("Enter NoteEdit mode")); break; // GF: NoteEditMode activity (I'm not yet certain why we need to emit this.)
Chris@502 397 };
Chris@127 398 }
Chris@127 399
Chris@711 400 ViewManager::ToolMode
Chris@711 401 ViewManager::getToolModeFor(const View *v) const
Chris@711 402 {
Chris@711 403 if (m_toolModeOverrides.find(v) == m_toolModeOverrides.end()) {
Chris@711 404 return getToolMode();
Chris@711 405 } else {
Chris@711 406 return m_toolModeOverrides.find(v)->second;
Chris@711 407 }
Chris@711 408 }
Chris@711 409
Chris@711 410 void
Chris@711 411 ViewManager::setToolModeFor(const View *v, ToolMode mode)
Chris@711 412 {
Chris@711 413 m_toolModeOverrides[v] = mode;
Chris@711 414 }
Chris@711 415
Chris@711 416 void
Chris@711 417 ViewManager::clearToolModeOverrides()
Chris@711 418 {
Chris@711 419 m_toolModeOverrides.clear();
Chris@711 420 }
Chris@711 421
Chris@127 422 void
Chris@127 423 ViewManager::setPlayLoopMode(bool mode)
Chris@127 424 {
Chris@177 425 if (m_playLoopMode != mode) {
Chris@127 426
Chris@177 427 m_playLoopMode = mode;
Chris@177 428
Chris@177 429 emit playLoopModeChanged();
Chris@177 430 emit playLoopModeChanged(mode);
Chris@502 431
Chris@502 432 if (mode) emit activity(tr("Switch on Loop mode"));
Chris@502 433 else emit activity(tr("Switch off Loop mode"));
Chris@177 434 }
Chris@127 435 }
Chris@127 436
Chris@127 437 void
Chris@127 438 ViewManager::setPlaySelectionMode(bool mode)
Chris@127 439 {
Chris@177 440 if (m_playSelectionMode != mode) {
Chris@127 441
Chris@177 442 m_playSelectionMode = mode;
Chris@177 443
Chris@177 444 emit playSelectionModeChanged();
Chris@177 445 emit playSelectionModeChanged(mode);
Chris@502 446
Chris@502 447 if (mode) emit activity(tr("Switch on Play Selection mode"));
Chris@502 448 else emit activity(tr("Switch off Play Selection mode"));
Chris@177 449 }
Chris@127 450 }
Chris@127 451
Chris@301 452 void
Chris@301 453 ViewManager::setPlaySoloMode(bool mode)
Chris@301 454 {
Chris@301 455 if (m_playSoloMode != mode) {
Chris@301 456
Chris@301 457 m_playSoloMode = mode;
Chris@301 458
Chris@301 459 emit playSoloModeChanged();
Chris@301 460 emit playSoloModeChanged(mode);
Chris@502 461
Chris@502 462 if (mode) emit activity(tr("Switch on Play Solo mode"));
Chris@502 463 else emit activity(tr("Switch off Play Solo mode"));
Chris@301 464 }
Chris@301 465 }
Chris@301 466
Chris@314 467 void
Chris@314 468 ViewManager::setAlignMode(bool mode)
Chris@314 469 {
Chris@314 470 if (m_alignMode != mode) {
Chris@314 471
Chris@314 472 m_alignMode = mode;
Chris@314 473
Chris@314 474 emit alignModeChanged();
Chris@314 475 emit alignModeChanged(mode);
Chris@502 476
Chris@502 477 if (mode) emit activity(tr("Switch on Alignment mode"));
Chris@502 478 else emit activity(tr("Switch off Alignment mode"));
Chris@314 479 }
Chris@314 480 }
Chris@314 481
Chris@902 482 sv_samplerate_t
Chris@224 483 ViewManager::getPlaybackSampleRate() const
Chris@224 484 {
Chris@224 485 if (m_playSource) {
Chris@224 486 return m_playSource->getSourceSampleRate();
Chris@224 487 }
Chris@224 488 return 0;
Chris@224 489 }
Chris@224 490
Chris@902 491 sv_samplerate_t
Chris@224 492 ViewManager::getOutputSampleRate() const
Chris@127 493 {
Chris@127 494 if (m_playSource) {
Chris@127 495 return m_playSource->getTargetSampleRate();
Chris@127 496 }
Chris@127 497 return 0;
Chris@127 498 }
Chris@127 499
Chris@127 500 void
Chris@127 501 ViewManager::setAudioPlaySource(AudioPlaySource *source)
Chris@127 502 {
Chris@127 503 if (!m_playSource) {
Chris@127 504 QTimer::singleShot(100, this, SLOT(checkPlayStatus()));
Chris@127 505 }
Chris@127 506 m_playSource = source;
Chris@127 507 }
Chris@127 508
Chris@127 509 void
Chris@248 510 ViewManager::playStatusChanged(bool /* playing */)
Chris@127 511 {
Chris@689 512 #ifdef DEBUG_VIEW_MANAGER
Chris@689 513 cerr << "ViewManager::playStatusChanged" << endl;
Chris@689 514 #endif
Chris@127 515 checkPlayStatus();
Chris@127 516 }
Chris@127 517
Chris@127 518 void
Chris@127 519 ViewManager::checkPlayStatus()
Chris@127 520 {
Chris@127 521 if (m_playSource && m_playSource->isPlaying()) {
Chris@127 522
Chris@127 523 float left = 0, right = 0;
Chris@127 524 if (m_playSource->getOutputLevels(left, right)) {
Chris@127 525 if (left != m_lastLeft || right != m_lastRight) {
Chris@127 526 emit outputLevelsChanged(left, right);
Chris@127 527 m_lastLeft = left;
Chris@127 528 m_lastRight = right;
Chris@127 529 }
Chris@127 530 }
Chris@127 531
Chris@127 532 m_playbackFrame = m_playSource->getCurrentPlayingFrame();
Chris@127 533
Chris@127 534 #ifdef DEBUG_VIEW_MANAGER
Chris@682 535 cerr << "ViewManager::checkPlayStatus: Playing, frame " << m_playbackFrame << ", levels " << m_lastLeft << "," << m_lastRight << endl;
Chris@127 536 #endif
Chris@127 537
Chris@127 538 emit playbackFrameChanged(m_playbackFrame);
Chris@127 539
Chris@127 540 QTimer::singleShot(20, this, SLOT(checkPlayStatus()));
Chris@127 541
Chris@127 542 } else {
Chris@127 543
Chris@127 544 if (m_lastLeft != 0.0 || m_lastRight != 0.0) {
Chris@127 545 emit outputLevelsChanged(0.0, 0.0);
Chris@127 546 m_lastLeft = 0.0;
Chris@127 547 m_lastRight = 0.0;
Chris@127 548 }
Chris@127 549
Chris@127 550 #ifdef DEBUG_VIEW_MANAGER
Chris@689 551 cerr << "ViewManager::checkPlayStatus: Not playing" << endl;
Chris@127 552 #endif
Chris@127 553 }
Chris@127 554 }
Chris@127 555
Chris@127 556 bool
Chris@127 557 ViewManager::isPlaying() const
Chris@127 558 {
Chris@127 559 return m_playSource && m_playSource->isPlaying();
Chris@127 560 }
Chris@127 561
Chris@127 562 void
Chris@902 563 ViewManager::viewCentreFrameChanged(sv_frame_t f, bool locked,
Chris@211 564 PlaybackFollowMode mode)
Chris@127 565 {
Chris@211 566 View *v = dynamic_cast<View *>(sender());
Chris@211 567
Chris@398 568 #ifdef DEBUG_VIEW_MANAGER
Chris@682 569 cerr << "ViewManager::viewCentreFrameChanged(" << f << ", " << locked << ", " << mode << "), view is " << v << endl;
Chris@398 570 #endif
Chris@394 571
Chris@127 572 if (locked) {
Chris@211 573 m_globalCentreFrame = f;
Chris@211 574 emit globalCentreFrameChanged(f);
Chris@211 575 } else {
Chris@211 576 if (v) emit viewCentreFrameChanged(v, f);
Chris@127 577 }
Chris@127 578
Chris@815 579 if (!dynamic_cast<Overview *>(v) || (mode != PlaybackIgnore)) {
Chris@527 580 if (m_mainModelSampleRate != 0) {
Chris@527 581 emit activity(tr("Scroll to %1")
Chris@527 582 .arg(RealTime::frame2RealTime
Chris@527 583 (f, m_mainModelSampleRate).toText().c_str()));
Chris@527 584 }
Chris@503 585 }
Chris@502 586
Chris@815 587 if (mode == PlaybackScrollPageWithCentre ||
Chris@815 588 mode == PlaybackScrollContinuous) {
Chris@815 589 seek(f);
Chris@211 590 }
Chris@211 591 }
Chris@211 592
Chris@211 593 void
Chris@902 594 ViewManager::seek(sv_frame_t f)
Chris@211 595 {
Chris@127 596 #ifdef DEBUG_VIEW_MANAGER
Chris@682 597 cerr << "ViewManager::seek(" << f << ")" << endl;
Chris@127 598 #endif
Chris@127 599
Chris@127 600 if (m_playSource && m_playSource->isPlaying()) {
Chris@902 601 sv_frame_t playFrame = m_playSource->getCurrentPlayingFrame();
Chris@902 602 sv_frame_t diff = std::max(f, playFrame) - std::min(f, playFrame);
Chris@127 603 if (diff > 20000) {
Chris@127 604 m_playbackFrame = f;
Chris@127 605 m_playSource->play(f);
Chris@127 606 #ifdef DEBUG_VIEW_MANAGER
Chris@682 607 cerr << "ViewManager::considerSeek: reseeking from " << playFrame << " to " << f << endl;
Chris@127 608 #endif
Chris@211 609 emit playbackFrameChanged(f);
Chris@127 610 }
Chris@127 611 } else {
Chris@211 612 if (m_playbackFrame != f) {
Chris@211 613 m_playbackFrame = f;
Chris@211 614 emit playbackFrameChanged(f);
Chris@211 615 }
Chris@127 616 }
Chris@127 617 }
Chris@127 618
Chris@127 619 void
Chris@806 620 ViewManager::viewZoomLevelChanged(int z, bool locked)
Chris@127 621 {
Chris@222 622 View *v = dynamic_cast<View *>(sender());
Chris@222 623
Chris@222 624 if (!v) {
Chris@587 625 SVDEBUG << "ViewManager::viewZoomLevelChanged: WARNING: sender is not a view" << endl;
Chris@222 626 return;
Chris@222 627 }
Chris@222 628
Chris@222 629 //!!! emit zoomLevelChanged();
Chris@133 630
Chris@127 631 if (locked) {
Chris@127 632 m_globalZoom = z;
Chris@127 633 }
Chris@127 634
Chris@127 635 #ifdef DEBUG_VIEW_MANAGER
Chris@682 636 cerr << "ViewManager::viewZoomLevelChanged(" << v << ", " << z << ", " << locked << ")" << endl;
Chris@127 637 #endif
Chris@222 638
Chris@222 639 emit viewZoomLevelChanged(v, z, locked);
Chris@503 640
Chris@503 641 if (!dynamic_cast<Overview *>(v)) {
Chris@503 642 emit activity(tr("Zoom to %n sample(s) per pixel", "", z));
Chris@503 643 }
Chris@127 644 }
Chris@127 645
Chris@127 646 void
Chris@127 647 ViewManager::setOverlayMode(OverlayMode mode)
Chris@127 648 {
Chris@127 649 if (m_overlayMode != mode) {
Chris@127 650 m_overlayMode = mode;
Chris@127 651 emit overlayModeChanged();
Chris@502 652 emit activity(tr("Change overlay level"));
Chris@127 653 }
Chris@133 654
Chris@133 655 QSettings settings;
Chris@133 656 settings.beginGroup("MainWindow");
Chris@133 657 settings.setValue("overlay-mode", int(m_overlayMode));
Chris@133 658 settings.endGroup();
Chris@127 659 }
Chris@127 660
Chris@133 661 void
Chris@133 662 ViewManager::setZoomWheelsEnabled(bool enabled)
Chris@133 663 {
Chris@133 664 if (m_zoomWheelsEnabled != enabled) {
Chris@133 665 m_zoomWheelsEnabled = enabled;
Chris@133 666 emit zoomWheelsEnabledChanged();
Chris@502 667 if (enabled) emit activity("Show zoom wheels");
Chris@502 668 else emit activity("Hide zoom wheels");
Chris@133 669 }
Chris@127 670
Chris@133 671 QSettings settings;
Chris@133 672 settings.beginGroup("MainWindow");
Chris@133 673 settings.setValue("zoom-wheels-enabled", m_zoomWheelsEnabled);
Chris@133 674 settings.endGroup();
Chris@133 675 }
Chris@133 676
Chris@292 677 void
Chris@607 678 ViewManager::setShowCentreLine(bool show)
Chris@607 679 {
Chris@607 680 if (m_showCentreLine != show) {
Chris@607 681 m_showCentreLine = show;
Chris@607 682 emit showCentreLineChanged();
Chris@607 683 if (show) emit activity("Show centre line");
Chris@607 684 else emit activity("Hide centre line");
Chris@607 685 }
Chris@607 686
Chris@607 687 QSettings settings;
Chris@607 688 settings.beginGroup("MainWindow");
Chris@607 689 settings.setValue("show-centre-line", int(m_showCentreLine));
Chris@607 690 settings.endGroup();
Chris@607 691 }
Chris@607 692
Chris@607 693 void
Chris@292 694 ViewManager::setGlobalDarkBackground(bool dark)
Chris@292 695 {
Chris@292 696 // also save the current palette, in case the user has changed it
Chris@292 697 // since construction
Chris@292 698 if (getGlobalDarkBackground()) {
Chris@292 699 m_darkPalette = QApplication::palette();
Chris@292 700 } else {
Chris@292 701 m_lightPalette = QApplication::palette();
Chris@292 702 }
Chris@292 703
Chris@737 704 #ifndef Q_OS_MAC
Chris@292 705 if (dark) {
Chris@292 706 QApplication::setPalette(m_darkPalette);
Chris@292 707 } else {
Chris@292 708 QApplication::setPalette(m_lightPalette);
Chris@292 709 }
Chris@737 710 #endif
Chris@292 711 }
Chris@292 712
Chris@292 713 bool
Chris@292 714 ViewManager::getGlobalDarkBackground() const
Chris@292 715 {
Chris@292 716 bool dark = false;
Chris@292 717 QColor windowBg = QApplication::palette().color(QPalette::Window);
Chris@292 718 if (windowBg.red() + windowBg.green() + windowBg.blue() < 384) {
Chris@292 719 dark = true;
Chris@292 720 }
Chris@292 721 return dark;
Chris@292 722 }
Chris@292 723
Chris@894 724 int
Chris@894 725 ViewManager::scalePixelSize(int pixels)
Chris@894 726 {
Chris@908 727 static double ratio = 0.0;
Chris@908 728 if (ratio == 0.0) {
Chris@908 729 double baseEm;
Chris@894 730 #ifdef Q_OS_MAC
Chris@908 731 baseEm = 17.0;
Chris@894 732 #else
Chris@908 733 baseEm = 15.0;
Chris@894 734 #endif
Chris@908 735 double em = QFontMetrics(QFont()).height();
Chris@894 736 ratio = em / baseEm;
Chris@894 737 }
Chris@894 738
Chris@894 739 int scaled = int(pixels * ratio + 0.5);
Chris@910 740 // cerr << "scaledSize: " << pixels << " -> " << scaled << " at ratio " << ratio << endl;
Chris@894 741 if (pixels != 0 && scaled == 0) scaled = 1;
Chris@894 742 return scaled;
Chris@894 743 }
Chris@946 744