annotate view/ViewManager.cpp @ 591:0946feb81b79 sonification

Add playExampleNote route through view manager out to the audio play source
author Chris Cannam
date Fri, 24 Jun 2011 16:42:48 +0100
parents 4806715f7a19
children 5fa210337bee
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@363 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@189 46 m_overlayMode(StandardOverlays),
Chris@292 47 m_zoomWheelsEnabled(true),
Chris@326 48 m_illuminateLocalFeatures(true),
Chris@326 49 m_showWorkTitle(false),
Chris@292 50 m_lightPalette(QApplication::palette()),
Chris@292 51 m_darkPalette(QApplication::palette())
Chris@127 52 {
Chris@133 53 QSettings settings;
Chris@133 54 settings.beginGroup("MainWindow");
Chris@133 55 m_overlayMode = OverlayMode
Chris@133 56 (settings.value("overlay-mode", int(m_overlayMode)).toInt());
Chris@133 57 m_zoomWheelsEnabled =
Chris@133 58 settings.value("zoom-wheels-enabled", m_zoomWheelsEnabled).toBool();
Chris@133 59 settings.endGroup();
Chris@292 60
Chris@292 61 if (getGlobalDarkBackground()) {
Chris@343 62 /*
Chris@293 63 std::cerr << "dark palette:" << std::endl;
Chris@584 64 std::cerr << "window = " << QApplication::palette().color(QPalette::Window).name() << std::endl;
Chris@584 65 std::cerr << "windowtext = " << QApplication::palette().color(QPalette::WindowText).name() << std::endl;
Chris@584 66 std::cerr << "base = " << QApplication::palette().color(QPalette::Base).name() << std::endl;
Chris@584 67 std::cerr << "alternatebase = " << QApplication::palette().color(QPalette::AlternateBase).name() << std::endl;
Chris@584 68 std::cerr << "text = " << QApplication::palette().color(QPalette::Text).name() << std::endl;
Chris@584 69 std::cerr << "button = " << QApplication::palette().color(QPalette::Button).name() << std::endl;
Chris@584 70 std::cerr << "buttontext = " << QApplication::palette().color(QPalette::ButtonText).name() << std::endl;
Chris@584 71 std::cerr << "brighttext = " << QApplication::palette().color(QPalette::BrightText).name() << std::endl;
Chris@584 72 std::cerr << "light = " << QApplication::palette().color(QPalette::Light).name() << std::endl;
Chris@584 73 std::cerr << "dark = " << QApplication::palette().color(QPalette::Dark).name() << std::endl;
Chris@584 74 std::cerr << "mid = " << QApplication::palette().color(QPalette::Mid).name() << std::endl;
Chris@343 75 */
Chris@293 76 m_lightPalette = QPalette(QColor("#000000"), // WindowText
Chris@293 77 QColor("#dddfe4"), // Button
Chris@293 78 QColor("#ffffff"), // Light
Chris@293 79 QColor("#555555"), // Dark
Chris@293 80 QColor("#c7c7c7"), // Mid
Chris@293 81 QColor("#000000"), // Text
Chris@293 82 QColor("#ffffff"), // BrightText
Chris@293 83 QColor("#ffffff"), // Base
Chris@293 84 QColor("#efefef")); // Window
Chris@293 85
Chris@293 86
Chris@292 87 } else {
Chris@343 88 /*
Chris@293 89 std::cerr << "light palette:" << std::endl;
Chris@584 90 std::cerr << "window = " << QApplication::palette().color(QPalette::Window).name() << std::endl;
Chris@584 91 std::cerr << "windowtext = " << QApplication::palette().color(QPalette::WindowText).name() << std::endl;
Chris@584 92 std::cerr << "base = " << QApplication::palette().color(QPalette::Base).name() << std::endl;
Chris@584 93 std::cerr << "alternatebase = " << QApplication::palette().color(QPalette::AlternateBase).name() << std::endl;
Chris@584 94 std::cerr << "text = " << QApplication::palette().color(QPalette::Text).name() << std::endl;
Chris@584 95 std::cerr << "button = " << QApplication::palette().color(QPalette::Button).name() << std::endl;
Chris@584 96 std::cerr << "buttontext = " << QApplication::palette().color(QPalette::ButtonText).name() << std::endl;
Chris@584 97 std::cerr << "brighttext = " << QApplication::palette().color(QPalette::BrightText).name() << std::endl;
Chris@584 98 std::cerr << "light = " << QApplication::palette().color(QPalette::Light).name() << std::endl;
Chris@584 99 std::cerr << "dark = " << QApplication::palette().color(QPalette::Dark).name() << std::endl;
Chris@584 100 std::cerr << "mid = " << QApplication::palette().color(QPalette::Mid).name() << std::endl;
Chris@343 101 */
Chris@293 102 m_darkPalette = QPalette(QColor("#ffffff"), // WindowText
Chris@293 103 QColor("#3e3e3e"), // Button
Chris@293 104 QColor("#808080"), // Light
Chris@293 105 QColor("#1e1e1e"), // Dark
Chris@293 106 QColor("#404040"), // Mid
Chris@293 107 QColor("#ffffff"), // Text
Chris@293 108 QColor("#ffffff"), // BrightText
Chris@293 109 QColor("#000000"), // Base
Chris@293 110 QColor("#202020")); // Window
Chris@292 111 }
Chris@127 112 }
Chris@127 113
Chris@127 114 ViewManager::~ViewManager()
Chris@127 115 {
Chris@127 116 }
Chris@127 117
Chris@127 118 unsigned long
Chris@127 119 ViewManager::getGlobalCentreFrame() const
Chris@127 120 {
Chris@127 121 #ifdef DEBUG_VIEW_MANAGER
Chris@127 122 std::cout << "ViewManager::getGlobalCentreFrame: returning " << m_globalCentreFrame << std::endl;
Chris@127 123 #endif
Chris@127 124 return m_globalCentreFrame;
Chris@127 125 }
Chris@127 126
Chris@180 127 void
Chris@180 128 ViewManager::setGlobalCentreFrame(unsigned long f)
Chris@180 129 {
Chris@180 130 #ifdef DEBUG_VIEW_MANAGER
Chris@180 131 std::cout << "ViewManager::setGlobalCentreFrame to " << f << std::endl;
Chris@180 132 #endif
Chris@180 133 m_globalCentreFrame = f;
Chris@211 134 emit globalCentreFrameChanged(f);
Chris@180 135 }
Chris@180 136
Chris@127 137 unsigned long
Chris@127 138 ViewManager::getGlobalZoom() const
Chris@127 139 {
Chris@127 140 #ifdef DEBUG_VIEW_MANAGER
Chris@127 141 std::cout << "ViewManager::getGlobalZoom: returning " << m_globalZoom << std::endl;
Chris@127 142 #endif
Chris@127 143 return m_globalZoom;
Chris@127 144 }
Chris@127 145
Chris@127 146 unsigned long
Chris@127 147 ViewManager::getPlaybackFrame() const
Chris@127 148 {
Chris@127 149 if (m_playSource && m_playSource->isPlaying()) {
Chris@127 150 m_playbackFrame = m_playSource->getCurrentPlayingFrame();
Chris@127 151 }
Chris@127 152 return m_playbackFrame;
Chris@127 153 }
Chris@127 154
Chris@127 155 void
Chris@127 156 ViewManager::setPlaybackFrame(unsigned long f)
Chris@127 157 {
Chris@127 158 if (m_playbackFrame != f) {
Chris@127 159 m_playbackFrame = f;
Chris@127 160 emit playbackFrameChanged(f);
Chris@127 161 if (m_playSource && m_playSource->isPlaying()) {
Chris@127 162 m_playSource->play(f);
Chris@127 163 }
Chris@127 164 }
Chris@127 165 }
Chris@127 166
Chris@301 167 Model *
Chris@301 168 ViewManager::getPlaybackModel() const
Chris@301 169 {
Chris@301 170 return m_playbackModel;
Chris@301 171 }
Chris@301 172
Chris@301 173 void
Chris@301 174 ViewManager::setPlaybackModel(Model *model)
Chris@301 175 {
Chris@301 176 m_playbackModel = model;
Chris@301 177 }
Chris@301 178
Chris@333 179 size_t
Chris@333 180 ViewManager::alignPlaybackFrameToReference(size_t frame) const
Chris@333 181 {
Chris@333 182 if (!m_playbackModel) return frame;
Chris@333 183 else return m_playbackModel->alignToReference(frame);
Chris@333 184 }
Chris@333 185
Chris@333 186 size_t
Chris@333 187 ViewManager::alignReferenceToPlaybackFrame(size_t frame) const
Chris@333 188 {
Chris@333 189 if (!m_playbackModel) return frame;
Chris@333 190 else return m_playbackModel->alignFromReference(frame);
Chris@333 191 }
Chris@333 192
Chris@591 193 void
Chris@591 194 ViewManager::playExampleNote(int midiPitch)
Chris@591 195 {
Chris@591 196 m_playSource->queueExampleNote(midiPitch);
Chris@591 197 }
Chris@591 198
Chris@127 199 bool
Chris@127 200 ViewManager::haveInProgressSelection() const
Chris@127 201 {
Chris@127 202 return !m_inProgressSelection.isEmpty();
Chris@127 203 }
Chris@127 204
Chris@127 205 const Selection &
Chris@127 206 ViewManager::getInProgressSelection(bool &exclusive) const
Chris@127 207 {
Chris@127 208 exclusive = m_inProgressExclusive;
Chris@127 209 return m_inProgressSelection;
Chris@127 210 }
Chris@127 211
Chris@127 212 void
Chris@127 213 ViewManager::setInProgressSelection(const Selection &selection, bool exclusive)
Chris@127 214 {
Chris@127 215 m_inProgressExclusive = exclusive;
Chris@127 216 m_inProgressSelection = selection;
Chris@127 217 if (exclusive) clearSelections();
Chris@127 218 emit inProgressSelectionChanged();
Chris@127 219 }
Chris@127 220
Chris@127 221 void
Chris@127 222 ViewManager::clearInProgressSelection()
Chris@127 223 {
Chris@127 224 m_inProgressSelection = Selection();
Chris@127 225 emit inProgressSelectionChanged();
Chris@127 226 }
Chris@127 227
Chris@127 228 const MultiSelection &
Chris@127 229 ViewManager::getSelection() const
Chris@127 230 {
Chris@127 231 return m_selections;
Chris@127 232 }
Chris@127 233
Chris@127 234 const MultiSelection::SelectionList &
Chris@127 235 ViewManager::getSelections() const
Chris@127 236 {
Chris@127 237 return m_selections.getSelections();
Chris@127 238 }
Chris@127 239
Chris@127 240 void
Chris@127 241 ViewManager::setSelection(const Selection &selection)
Chris@127 242 {
Chris@127 243 MultiSelection ms(m_selections);
Chris@127 244 ms.setSelection(selection);
Chris@127 245 setSelections(ms);
Chris@127 246 }
Chris@127 247
Chris@127 248 void
Chris@127 249 ViewManager::addSelection(const Selection &selection)
Chris@127 250 {
Chris@127 251 MultiSelection ms(m_selections);
Chris@127 252 ms.addSelection(selection);
Chris@127 253 setSelections(ms);
Chris@127 254 }
Chris@127 255
Chris@127 256 void
Chris@127 257 ViewManager::removeSelection(const Selection &selection)
Chris@127 258 {
Chris@127 259 MultiSelection ms(m_selections);
Chris@127 260 ms.removeSelection(selection);
Chris@127 261 setSelections(ms);
Chris@127 262 }
Chris@127 263
Chris@127 264 void
Chris@127 265 ViewManager::clearSelections()
Chris@127 266 {
Chris@127 267 MultiSelection ms(m_selections);
Chris@127 268 ms.clearSelections();
Chris@127 269 setSelections(ms);
Chris@127 270 }
Chris@127 271
Chris@127 272 void
Chris@127 273 ViewManager::setSelections(const MultiSelection &ms)
Chris@127 274 {
Chris@127 275 if (m_selections.getSelections() == ms.getSelections()) return;
Chris@127 276 SetSelectionCommand *command = new SetSelectionCommand(this, ms);
Chris@127 277 CommandHistory::getInstance()->addCommand(command);
Chris@127 278 }
Chris@127 279
Chris@271 280 size_t
Chris@271 281 ViewManager::constrainFrameToSelection(size_t frame) const
Chris@271 282 {
Chris@271 283 MultiSelection::SelectionList sl = getSelections();
Chris@271 284 if (sl.empty()) return frame;
Chris@271 285
Chris@368 286 for (MultiSelection::SelectionList::const_iterator i = sl.begin();
Chris@368 287 i != sl.end(); ++i) {
Chris@368 288
Chris@368 289 if (frame < i->getEndFrame()) {
Chris@368 290 if (frame < i->getStartFrame()) {
Chris@368 291 return i->getStartFrame();
Chris@368 292 } else {
Chris@368 293 return frame;
Chris@368 294 }
Chris@368 295 }
Chris@271 296 }
Chris@271 297
Chris@368 298 return sl.begin()->getStartFrame();
Chris@271 299 }
Chris@271 300
Chris@127 301 void
Chris@127 302 ViewManager::signalSelectionChange()
Chris@127 303 {
Chris@127 304 emit selectionChanged();
Chris@127 305 }
Chris@127 306
Chris@127 307 ViewManager::SetSelectionCommand::SetSelectionCommand(ViewManager *vm,
Chris@127 308 const MultiSelection &ms) :
Chris@127 309 m_vm(vm),
Chris@127 310 m_oldSelection(vm->m_selections),
Chris@127 311 m_newSelection(ms)
Chris@127 312 {
Chris@127 313 }
Chris@127 314
Chris@127 315 ViewManager::SetSelectionCommand::~SetSelectionCommand() { }
Chris@127 316
Chris@127 317 void
Chris@127 318 ViewManager::SetSelectionCommand::execute()
Chris@127 319 {
Chris@127 320 m_vm->m_selections = m_newSelection;
Chris@127 321 m_vm->signalSelectionChange();
Chris@127 322 }
Chris@127 323
Chris@127 324 void
Chris@127 325 ViewManager::SetSelectionCommand::unexecute()
Chris@127 326 {
Chris@127 327 m_vm->m_selections = m_oldSelection;
Chris@127 328 m_vm->signalSelectionChange();
Chris@127 329 }
Chris@127 330
Chris@127 331 QString
Chris@127 332 ViewManager::SetSelectionCommand::getName() const
Chris@127 333 {
Chris@127 334 if (m_newSelection.getSelections().empty()) return tr("Clear Selection");
Chris@502 335 if (m_newSelection.getSelections().size() > 1) return tr("Select Multiple Regions");
Chris@502 336 else return tr("Select Region");
Chris@127 337 }
Chris@127 338
Chris@127 339 Selection
Chris@127 340 ViewManager::getContainingSelection(size_t frame, bool defaultToFollowing) const
Chris@127 341 {
Chris@127 342 return m_selections.getContainingSelection(frame, defaultToFollowing);
Chris@127 343 }
Chris@127 344
Chris@127 345 void
Chris@127 346 ViewManager::setToolMode(ToolMode mode)
Chris@127 347 {
Chris@127 348 m_toolMode = mode;
Chris@127 349
Chris@127 350 emit toolModeChanged();
Chris@502 351
Chris@502 352 switch (mode) {
Chris@502 353 case NavigateMode: emit activity(tr("Enter Navigate mode")); break;
Chris@502 354 case SelectMode: emit activity(tr("Enter Select mode")); break;
Chris@502 355 case EditMode: emit activity(tr("Enter Edit mode")); break;
Chris@502 356 case DrawMode: emit activity(tr("Enter Draw mode")); break;
Chris@502 357 case EraseMode: emit activity(tr("Enter Erase mode")); break;
Chris@502 358 case MeasureMode: emit activity(tr("Enter Measure mode")); break;
Chris@502 359 };
Chris@127 360 }
Chris@127 361
Chris@127 362 void
Chris@127 363 ViewManager::setPlayLoopMode(bool mode)
Chris@127 364 {
Chris@177 365 if (m_playLoopMode != mode) {
Chris@127 366
Chris@177 367 m_playLoopMode = mode;
Chris@177 368
Chris@177 369 emit playLoopModeChanged();
Chris@177 370 emit playLoopModeChanged(mode);
Chris@502 371
Chris@502 372 if (mode) emit activity(tr("Switch on Loop mode"));
Chris@502 373 else emit activity(tr("Switch off Loop mode"));
Chris@177 374 }
Chris@127 375 }
Chris@127 376
Chris@127 377 void
Chris@127 378 ViewManager::setPlaySelectionMode(bool mode)
Chris@127 379 {
Chris@177 380 if (m_playSelectionMode != mode) {
Chris@127 381
Chris@177 382 m_playSelectionMode = mode;
Chris@177 383
Chris@177 384 emit playSelectionModeChanged();
Chris@177 385 emit playSelectionModeChanged(mode);
Chris@502 386
Chris@502 387 if (mode) emit activity(tr("Switch on Play Selection mode"));
Chris@502 388 else emit activity(tr("Switch off Play Selection mode"));
Chris@177 389 }
Chris@127 390 }
Chris@127 391
Chris@301 392 void
Chris@301 393 ViewManager::setPlaySoloMode(bool mode)
Chris@301 394 {
Chris@301 395 if (m_playSoloMode != mode) {
Chris@301 396
Chris@301 397 m_playSoloMode = mode;
Chris@301 398
Chris@301 399 emit playSoloModeChanged();
Chris@301 400 emit playSoloModeChanged(mode);
Chris@502 401
Chris@502 402 if (mode) emit activity(tr("Switch on Play Solo mode"));
Chris@502 403 else emit activity(tr("Switch off Play Solo mode"));
Chris@301 404 }
Chris@301 405 }
Chris@301 406
Chris@314 407 void
Chris@314 408 ViewManager::setAlignMode(bool mode)
Chris@314 409 {
Chris@314 410 if (m_alignMode != mode) {
Chris@314 411
Chris@314 412 m_alignMode = mode;
Chris@314 413
Chris@314 414 emit alignModeChanged();
Chris@314 415 emit alignModeChanged(mode);
Chris@502 416
Chris@502 417 if (mode) emit activity(tr("Switch on Alignment mode"));
Chris@502 418 else emit activity(tr("Switch off Alignment mode"));
Chris@314 419 }
Chris@314 420 }
Chris@314 421
Chris@224 422 size_t
Chris@224 423 ViewManager::getPlaybackSampleRate() const
Chris@224 424 {
Chris@224 425 if (m_playSource) {
Chris@224 426 return m_playSource->getSourceSampleRate();
Chris@224 427 }
Chris@224 428 return 0;
Chris@224 429 }
Chris@224 430
Chris@127 431 size_t
Chris@224 432 ViewManager::getOutputSampleRate() const
Chris@127 433 {
Chris@127 434 if (m_playSource) {
Chris@127 435 return m_playSource->getTargetSampleRate();
Chris@127 436 }
Chris@127 437 return 0;
Chris@127 438 }
Chris@127 439
Chris@127 440 void
Chris@127 441 ViewManager::setAudioPlaySource(AudioPlaySource *source)
Chris@127 442 {
Chris@127 443 if (!m_playSource) {
Chris@127 444 QTimer::singleShot(100, this, SLOT(checkPlayStatus()));
Chris@127 445 }
Chris@127 446 m_playSource = source;
Chris@127 447 }
Chris@127 448
Chris@127 449 void
Chris@248 450 ViewManager::playStatusChanged(bool /* playing */)
Chris@127 451 {
Chris@127 452 checkPlayStatus();
Chris@127 453 }
Chris@127 454
Chris@127 455 void
Chris@127 456 ViewManager::checkPlayStatus()
Chris@127 457 {
Chris@127 458 if (m_playSource && m_playSource->isPlaying()) {
Chris@127 459
Chris@127 460 float left = 0, right = 0;
Chris@127 461 if (m_playSource->getOutputLevels(left, right)) {
Chris@127 462 if (left != m_lastLeft || right != m_lastRight) {
Chris@127 463 emit outputLevelsChanged(left, right);
Chris@127 464 m_lastLeft = left;
Chris@127 465 m_lastRight = right;
Chris@127 466 }
Chris@127 467 }
Chris@127 468
Chris@127 469 m_playbackFrame = m_playSource->getCurrentPlayingFrame();
Chris@127 470
Chris@127 471 #ifdef DEBUG_VIEW_MANAGER
Chris@127 472 std::cout << "ViewManager::checkPlayStatus: Playing, frame " << m_playbackFrame << ", levels " << m_lastLeft << "," << m_lastRight << std::endl;
Chris@127 473 #endif
Chris@127 474
Chris@127 475 emit playbackFrameChanged(m_playbackFrame);
Chris@127 476
Chris@127 477 QTimer::singleShot(20, this, SLOT(checkPlayStatus()));
Chris@127 478
Chris@127 479 } else {
Chris@127 480
Chris@127 481 QTimer::singleShot(100, this, SLOT(checkPlayStatus()));
Chris@127 482
Chris@127 483 if (m_lastLeft != 0.0 || m_lastRight != 0.0) {
Chris@127 484 emit outputLevelsChanged(0.0, 0.0);
Chris@127 485 m_lastLeft = 0.0;
Chris@127 486 m_lastRight = 0.0;
Chris@127 487 }
Chris@127 488
Chris@127 489 #ifdef DEBUG_VIEW_MANAGER
Chris@127 490 // std::cout << "ViewManager::checkPlayStatus: Not playing" << std::endl;
Chris@127 491 #endif
Chris@127 492 }
Chris@127 493 }
Chris@127 494
Chris@127 495 bool
Chris@127 496 ViewManager::isPlaying() const
Chris@127 497 {
Chris@127 498 return m_playSource && m_playSource->isPlaying();
Chris@127 499 }
Chris@127 500
Chris@127 501 void
Chris@211 502 ViewManager::viewCentreFrameChanged(unsigned long f, bool locked,
Chris@211 503 PlaybackFollowMode mode)
Chris@127 504 {
Chris@211 505 View *v = dynamic_cast<View *>(sender());
Chris@211 506
Chris@398 507 #ifdef DEBUG_VIEW_MANAGER
Chris@587 508 SVDEBUG << "ViewManager::viewCentreFrameChanged(" << f << ", " << locked << ", " << mode << "), view is " << v << endl;
Chris@398 509 #endif
Chris@394 510
Chris@127 511 if (locked) {
Chris@211 512 m_globalCentreFrame = f;
Chris@211 513 emit globalCentreFrameChanged(f);
Chris@211 514 } else {
Chris@211 515 if (v) emit viewCentreFrameChanged(v, f);
Chris@127 516 }
Chris@127 517
Chris@503 518 if (!dynamic_cast<Overview *>(v) || (mode != PlaybackIgnore)) {
Chris@527 519 if (m_mainModelSampleRate != 0) {
Chris@527 520 emit activity(tr("Scroll to %1")
Chris@527 521 .arg(RealTime::frame2RealTime
Chris@527 522 (f, m_mainModelSampleRate).toText().c_str()));
Chris@527 523 }
Chris@503 524 }
Chris@502 525
Chris@211 526 if (mode == PlaybackIgnore) {
Chris@211 527 return;
Chris@211 528 }
Chris@211 529
Chris@211 530 seek(f);
Chris@211 531 }
Chris@211 532
Chris@211 533 void
Chris@211 534 ViewManager::seek(unsigned long f)
Chris@211 535 {
Chris@127 536 #ifdef DEBUG_VIEW_MANAGER
Chris@211 537 std::cout << "ViewManager::seek(" << f << ")" << std::endl;
Chris@127 538 #endif
Chris@127 539
Chris@127 540 if (m_playSource && m_playSource->isPlaying()) {
Chris@127 541 unsigned long playFrame = m_playSource->getCurrentPlayingFrame();
Chris@127 542 unsigned long diff = std::max(f, playFrame) - std::min(f, playFrame);
Chris@127 543 if (diff > 20000) {
Chris@127 544 m_playbackFrame = f;
Chris@127 545 m_playSource->play(f);
Chris@127 546 #ifdef DEBUG_VIEW_MANAGER
Chris@127 547 std::cout << "ViewManager::considerSeek: reseeking from " << playFrame << " to " << f << std::endl;
Chris@127 548 #endif
Chris@211 549 emit playbackFrameChanged(f);
Chris@127 550 }
Chris@127 551 } else {
Chris@211 552 if (m_playbackFrame != f) {
Chris@211 553 m_playbackFrame = f;
Chris@211 554 emit playbackFrameChanged(f);
Chris@211 555 }
Chris@127 556 }
Chris@127 557 }
Chris@127 558
Chris@127 559 void
Chris@222 560 ViewManager::viewZoomLevelChanged(unsigned long z, bool locked)
Chris@127 561 {
Chris@222 562 View *v = dynamic_cast<View *>(sender());
Chris@222 563
Chris@222 564 if (!v) {
Chris@587 565 SVDEBUG << "ViewManager::viewZoomLevelChanged: WARNING: sender is not a view" << endl;
Chris@222 566 return;
Chris@222 567 }
Chris@222 568
Chris@222 569 //!!! emit zoomLevelChanged();
Chris@133 570
Chris@127 571 if (locked) {
Chris@127 572 m_globalZoom = z;
Chris@127 573 }
Chris@127 574
Chris@127 575 #ifdef DEBUG_VIEW_MANAGER
Chris@222 576 std::cout << "ViewManager::viewZoomLevelChanged(" << v << ", " << z << ", " << locked << ")" << std::endl;
Chris@127 577 #endif
Chris@222 578
Chris@222 579 emit viewZoomLevelChanged(v, z, locked);
Chris@503 580
Chris@503 581 if (!dynamic_cast<Overview *>(v)) {
Chris@503 582 emit activity(tr("Zoom to %n sample(s) per pixel", "", z));
Chris@503 583 }
Chris@127 584 }
Chris@127 585
Chris@127 586 void
Chris@127 587 ViewManager::setOverlayMode(OverlayMode mode)
Chris@127 588 {
Chris@127 589 if (m_overlayMode != mode) {
Chris@127 590 m_overlayMode = mode;
Chris@127 591 emit overlayModeChanged();
Chris@502 592 emit activity(tr("Change overlay level"));
Chris@127 593 }
Chris@133 594
Chris@133 595 QSettings settings;
Chris@133 596 settings.beginGroup("MainWindow");
Chris@133 597 settings.setValue("overlay-mode", int(m_overlayMode));
Chris@133 598 settings.endGroup();
Chris@127 599 }
Chris@127 600
Chris@133 601 void
Chris@133 602 ViewManager::setZoomWheelsEnabled(bool enabled)
Chris@133 603 {
Chris@133 604 if (m_zoomWheelsEnabled != enabled) {
Chris@133 605 m_zoomWheelsEnabled = enabled;
Chris@133 606 emit zoomWheelsEnabledChanged();
Chris@502 607 if (enabled) emit activity("Show zoom wheels");
Chris@502 608 else emit activity("Hide zoom wheels");
Chris@133 609 }
Chris@127 610
Chris@133 611 QSettings settings;
Chris@133 612 settings.beginGroup("MainWindow");
Chris@133 613 settings.setValue("zoom-wheels-enabled", m_zoomWheelsEnabled);
Chris@133 614 settings.endGroup();
Chris@133 615 }
Chris@133 616
Chris@292 617 void
Chris@292 618 ViewManager::setGlobalDarkBackground(bool dark)
Chris@292 619 {
Chris@292 620 // also save the current palette, in case the user has changed it
Chris@292 621 // since construction
Chris@292 622 if (getGlobalDarkBackground()) {
Chris@292 623 m_darkPalette = QApplication::palette();
Chris@292 624 } else {
Chris@292 625 m_lightPalette = QApplication::palette();
Chris@292 626 }
Chris@292 627
Chris@292 628 if (dark) {
Chris@292 629 QApplication::setPalette(m_darkPalette);
Chris@292 630 } else {
Chris@292 631 QApplication::setPalette(m_lightPalette);
Chris@292 632 }
Chris@292 633 }
Chris@292 634
Chris@292 635 bool
Chris@292 636 ViewManager::getGlobalDarkBackground() const
Chris@292 637 {
Chris@292 638 bool dark = false;
Chris@292 639 QColor windowBg = QApplication::palette().color(QPalette::Window);
Chris@292 640 if (windowBg.red() + windowBg.green() + windowBg.blue() < 384) {
Chris@292 641 dark = true;
Chris@292 642 }
Chris@292 643 return dark;
Chris@292 644 }
Chris@292 645