annotate framework/MainWindowBase.cpp @ 221:e06a0124c662 templating

Add ReplaceSession open mode for audio files, which discards the session and creates a new one using the template if available. Currently this is available as an additional option in the AskUser mode dialog -- this might bear future simplification. Addresses first bit of #148
author Chris Cannam
date Wed, 27 Apr 2011 14:46:06 +0100
parents 0b1886cee2cf
children ed5804224121
rev   line source
Chris@45 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@45 2
Chris@45 3 /*
Chris@45 4 Sonic Visualiser
Chris@45 5 An audio file viewer and annotation editor.
Chris@45 6 Centre for Digital Music, Queen Mary, University of London.
Chris@45 7 This file copyright 2006-2007 Chris Cannam and QMUL.
Chris@45 8
Chris@45 9 This program is free software; you can redistribute it and/or
Chris@45 10 modify it under the terms of the GNU General Public License as
Chris@45 11 published by the Free Software Foundation; either version 2 of the
Chris@45 12 License, or (at your option) any later version. See the file
Chris@45 13 COPYING included with this distribution for more information.
Chris@45 14 */
Chris@45 15
Chris@45 16 #include "MainWindowBase.h"
Chris@46 17 #include "Document.h"
Chris@45 18
Chris@45 19
Chris@45 20 #include "view/Pane.h"
Chris@45 21 #include "view/PaneStack.h"
Chris@45 22 #include "data/model/WaveFileModel.h"
Chris@45 23 #include "data/model/SparseOneDimensionalModel.h"
Chris@45 24 #include "data/model/NoteModel.h"
Chris@45 25 #include "data/model/Labeller.h"
Chris@124 26 #include "data/model/TabularModel.h"
Chris@45 27 #include "view/ViewManager.h"
Chris@45 28
Chris@45 29 #include "layer/WaveformLayer.h"
Chris@45 30 #include "layer/TimeRulerLayer.h"
Chris@45 31 #include "layer/TimeInstantLayer.h"
Chris@45 32 #include "layer/TimeValueLayer.h"
Chris@45 33 #include "layer/Colour3DPlotLayer.h"
Chris@45 34 #include "layer/SliceLayer.h"
Chris@45 35 #include "layer/SliceableLayer.h"
Chris@45 36 #include "layer/ImageLayer.h"
Chris@184 37 #include "layer/NoteLayer.h"
Chris@184 38 #include "layer/RegionLayer.h"
Chris@45 39
Chris@45 40 #include "widgets/ListInputDialog.h"
Chris@105 41 #include "widgets/CommandHistory.h"
Chris@109 42 #include "widgets/ProgressDialog.h"
Chris@109 43 #include "widgets/MIDIFileImportDialog.h"
Chris@109 44 #include "widgets/CSVFormatDialog.h"
Chris@123 45 #include "widgets/ModelDataTableDialog.h"
Chris@45 46
Chris@45 47 #include "audioio/AudioCallbackPlaySource.h"
Chris@45 48 #include "audioio/AudioCallbackPlayTarget.h"
Chris@45 49 #include "audioio/AudioTargetFactory.h"
Chris@45 50 #include "audioio/PlaySpeedRangeMapper.h"
Chris@45 51 #include "data/fileio/DataFileReaderFactory.h"
Chris@45 52 #include "data/fileio/PlaylistFileReader.h"
Chris@45 53 #include "data/fileio/WavFileWriter.h"
Chris@45 54 #include "data/fileio/CSVFileWriter.h"
Chris@45 55 #include "data/fileio/MIDIFileWriter.h"
Chris@45 56 #include "data/fileio/BZipFileDevice.h"
Chris@45 57 #include "data/fileio/FileSource.h"
Chris@152 58 #include "data/fileio/AudioFileReaderFactory.h"
Chris@134 59 #include "rdf/RDFImporter.h"
Chris@45 60
Chris@45 61 #include "data/fft/FFTDataServer.h"
Chris@45 62
Chris@45 63 #include "base/RecentFiles.h"
Chris@45 64
Chris@45 65 #include "base/PlayParameterRepository.h"
Chris@45 66 #include "base/XmlExportable.h"
Chris@45 67 #include "base/Profiler.h"
Chris@45 68 #include "base/Preferences.h"
Chris@217 69 #include "base/TempWriteFile.h"
Chris@217 70 #include "base/Exceptions.h"
Chris@45 71
Chris@45 72 #include "data/osc/OSCQueue.h"
Chris@157 73 #include "data/midi/MIDIInput.h"
Chris@45 74
Chris@45 75 #include <QApplication>
Chris@45 76 #include <QMessageBox>
Chris@45 77 #include <QGridLayout>
Chris@45 78 #include <QLabel>
Chris@45 79 #include <QAction>
Chris@45 80 #include <QMenuBar>
Chris@45 81 #include <QToolBar>
Chris@45 82 #include <QInputDialog>
Chris@45 83 #include <QStatusBar>
Chris@45 84 #include <QTreeView>
Chris@45 85 #include <QFile>
Chris@45 86 #include <QFileInfo>
Chris@45 87 #include <QDir>
Chris@45 88 #include <QTextStream>
Chris@45 89 #include <QProcess>
Chris@45 90 #include <QShortcut>
Chris@45 91 #include <QSettings>
Chris@45 92 #include <QDateTime>
Chris@45 93 #include <QProcess>
Chris@45 94 #include <QCheckBox>
Chris@45 95 #include <QRegExp>
Chris@45 96 #include <QScrollArea>
Chris@168 97 #include <QDesktopWidget>
Chris@45 98
Chris@45 99 #include <iostream>
Chris@45 100 #include <cstdio>
Chris@45 101 #include <errno.h>
Chris@45 102
Chris@45 103 using std::cerr;
Chris@45 104 using std::endl;
Chris@45 105
Chris@45 106 using std::vector;
Chris@45 107 using std::map;
Chris@45 108 using std::set;
Chris@45 109
Chris@45 110
Chris@161 111 MainWindowBase::MainWindowBase(bool withAudioOutput,
Chris@161 112 bool withOSCSupport,
Chris@161 113 bool withMIDIInput) :
Chris@45 114 m_document(0),
Chris@45 115 m_paneStack(0),
Chris@45 116 m_viewManager(0),
Chris@45 117 m_timeRulerLayer(0),
Chris@45 118 m_audioOutput(withAudioOutput),
Chris@45 119 m_playSource(0),
Chris@45 120 m_playTarget(0),
Chris@113 121 m_oscQueue(0),
Chris@113 122 m_oscQueueStarter(0),
Chris@157 123 m_midiInput(0),
Chris@45 124 m_recentFiles("RecentFiles", 20),
Chris@54 125 m_recentTransforms("RecentTransforms", 20),
Chris@45 126 m_documentModified(false),
Chris@45 127 m_openingAudioFile(false),
Chris@45 128 m_abandoning(false),
Chris@121 129 m_labeller(0),
Chris@121 130 m_lastPlayStatusSec(0)
Chris@45 131 {
Chris@113 132 Profiler profiler("MainWindowBase::MainWindowBase");
Chris@113 133
Chris@45 134 connect(CommandHistory::getInstance(), SIGNAL(commandExecuted()),
Chris@45 135 this, SLOT(documentModified()));
Chris@45 136 connect(CommandHistory::getInstance(), SIGNAL(documentRestored()),
Chris@45 137 this, SLOT(documentRestored()));
Chris@45 138
Chris@45 139 m_viewManager = new ViewManager();
Chris@45 140 connect(m_viewManager, SIGNAL(selectionChanged()),
Chris@45 141 this, SLOT(updateMenuStates()));
Chris@45 142 connect(m_viewManager, SIGNAL(inProgressSelectionChanged()),
Chris@45 143 this, SLOT(inProgressSelectionChanged()));
Chris@45 144
Chris@105 145 // set a sensible default font size for views -- cannot do this
Chris@105 146 // in Preferences, which is in base and not supposed to use QtGui
Chris@105 147 int viewFontSize = QApplication::font().pointSize() * 0.9;
Chris@105 148 QSettings settings;
Chris@105 149 settings.beginGroup("Preferences");
Chris@105 150 viewFontSize = settings.value("view-font-size", viewFontSize).toInt();
Chris@105 151 settings.setValue("view-font-size", viewFontSize);
Chris@105 152 settings.endGroup();
Chris@105 153
Chris@45 154 Preferences::BackgroundMode mode =
Chris@45 155 Preferences::getInstance()->getBackgroundMode();
Chris@45 156 m_initialDarkBackground = m_viewManager->getGlobalDarkBackground();
Chris@45 157 if (mode != Preferences::BackgroundFromTheme) {
Chris@45 158 m_viewManager->setGlobalDarkBackground
Chris@45 159 (mode == Preferences::DarkBackground);
Chris@45 160 }
Chris@45 161
Chris@45 162 m_paneStack = new PaneStack(0, m_viewManager);
Chris@45 163 connect(m_paneStack, SIGNAL(currentPaneChanged(Pane *)),
Chris@45 164 this, SLOT(currentPaneChanged(Pane *)));
Chris@45 165 connect(m_paneStack, SIGNAL(currentLayerChanged(Pane *, Layer *)),
Chris@45 166 this, SLOT(currentLayerChanged(Pane *, Layer *)));
Chris@45 167 connect(m_paneStack, SIGNAL(rightButtonMenuRequested(Pane *, QPoint)),
Chris@45 168 this, SLOT(rightButtonMenuRequested(Pane *, QPoint)));
Chris@45 169 connect(m_paneStack, SIGNAL(contextHelpChanged(const QString &)),
Chris@45 170 this, SLOT(contextHelpChanged(const QString &)));
Chris@45 171 connect(m_paneStack, SIGNAL(paneAdded(Pane *)),
Chris@45 172 this, SLOT(paneAdded(Pane *)));
Chris@45 173 connect(m_paneStack, SIGNAL(paneHidden(Pane *)),
Chris@45 174 this, SLOT(paneHidden(Pane *)));
Chris@45 175 connect(m_paneStack, SIGNAL(paneAboutToBeDeleted(Pane *)),
Chris@45 176 this, SLOT(paneAboutToBeDeleted(Pane *)));
Chris@45 177 connect(m_paneStack, SIGNAL(dropAccepted(Pane *, QStringList)),
Chris@45 178 this, SLOT(paneDropAccepted(Pane *, QStringList)));
Chris@45 179 connect(m_paneStack, SIGNAL(dropAccepted(Pane *, QString)),
Chris@45 180 this, SLOT(paneDropAccepted(Pane *, QString)));
Chris@55 181 connect(m_paneStack, SIGNAL(paneDeleteButtonClicked(Pane *)),
Chris@55 182 this, SLOT(paneDeleteButtonClicked(Pane *)));
Chris@45 183
Chris@57 184 m_playSource = new AudioCallbackPlaySource(m_viewManager,
Chris@57 185 QApplication::applicationName());
Chris@45 186
Chris@45 187 connect(m_playSource, SIGNAL(sampleRateMismatch(size_t, size_t, bool)),
Chris@45 188 this, SLOT(sampleRateMismatch(size_t, size_t, bool)));
Chris@45 189 connect(m_playSource, SIGNAL(audioOverloadPluginDisabled()),
Chris@45 190 this, SLOT(audioOverloadPluginDisabled()));
Chris@130 191 connect(m_playSource, SIGNAL(audioTimeStretchMultiChannelDisabled()),
Chris@130 192 this, SLOT(audioTimeStretchMultiChannelDisabled()));
Chris@45 193
Chris@45 194 connect(m_viewManager, SIGNAL(outputLevelsChanged(float, float)),
Chris@45 195 this, SLOT(outputLevelsChanged(float, float)));
Chris@45 196
Chris@45 197 connect(m_viewManager, SIGNAL(playbackFrameChanged(unsigned long)),
Chris@45 198 this, SLOT(playbackFrameChanged(unsigned long)));
Chris@45 199
Chris@45 200 connect(m_viewManager, SIGNAL(globalCentreFrameChanged(unsigned long)),
Chris@45 201 this, SLOT(globalCentreFrameChanged(unsigned long)));
Chris@45 202
Chris@45 203 connect(m_viewManager, SIGNAL(viewCentreFrameChanged(View *, unsigned long)),
Chris@45 204 this, SLOT(viewCentreFrameChanged(View *, unsigned long)));
Chris@45 205
Chris@45 206 connect(m_viewManager, SIGNAL(viewZoomLevelChanged(View *, unsigned long, bool)),
Chris@45 207 this, SLOT(viewZoomLevelChanged(View *, unsigned long, bool)));
Chris@45 208
Chris@45 209 connect(Preferences::getInstance(),
Chris@45 210 SIGNAL(propertyChanged(PropertyContainer::PropertyName)),
Chris@45 211 this,
Chris@45 212 SLOT(preferenceChanged(PropertyContainer::PropertyName)));
Chris@45 213
Chris@45 214 Labeller::ValueType labellerType = Labeller::ValueFromTwoLevelCounter;
Chris@45 215 settings.beginGroup("MainWindow");
Chris@45 216 labellerType = (Labeller::ValueType)
Chris@45 217 settings.value("labellertype", (int)labellerType).toInt();
Chris@45 218 int cycle = settings.value("labellercycle", 4).toInt();
Chris@45 219 settings.endGroup();
Chris@45 220
Chris@45 221 m_labeller = new Labeller(labellerType);
Chris@45 222 m_labeller->setCounterCycleSize(cycle);
Chris@113 223
Chris@161 224 if (withMIDIInput) {
Chris@161 225 m_midiInput = new MIDIInput(QApplication::applicationName(), this);
Chris@161 226 }
Chris@157 227
Chris@113 228 if (withOSCSupport) {
Chris@113 229 m_oscQueueStarter = new OSCQueueStarter(this);
Chris@113 230 connect(m_oscQueueStarter, SIGNAL(finished()), this, SLOT(oscReady()));
Chris@113 231 m_oscQueueStarter->start();
Chris@113 232 }
Chris@45 233 }
Chris@45 234
Chris@45 235 MainWindowBase::~MainWindowBase()
Chris@45 236 {
Chris@177 237 std::cerr << "MainWindowBase::~MainWindowBase" << std::endl;
Chris@70 238 if (m_playTarget) m_playTarget->shutdown();
Chris@70 239 // delete m_playTarget;
Chris@45 240 delete m_playSource;
Chris@45 241 delete m_viewManager;
Chris@45 242 delete m_oscQueue;
Chris@157 243 delete m_midiInput;
Chris@45 244 Profiles::getInstance()->dump();
Chris@45 245 }
Chris@45 246
Chris@113 247 void
Chris@168 248 MainWindowBase::resizeConstrained(QSize size)
Chris@168 249 {
Chris@168 250 QDesktopWidget *desktop = QApplication::desktop();
Chris@168 251 QRect available = desktop->availableGeometry();
Chris@168 252 QSize actual(std::min(size.width(), available.width()),
Chris@168 253 std::min(size.height(), available.height()));
Chris@168 254 resize(actual);
Chris@168 255 }
Chris@168 256
Chris@168 257 void
Chris@113 258 MainWindowBase::oscReady()
Chris@113 259 {
Chris@113 260 if (m_oscQueue && m_oscQueue->isOK()) {
Chris@113 261 connect(m_oscQueue, SIGNAL(messagesAvailable()), this, SLOT(pollOSC()));
Chris@113 262 QTimer *oscTimer = new QTimer(this);
Chris@113 263 connect(oscTimer, SIGNAL(timeout()), this, SLOT(pollOSC()));
Chris@113 264 oscTimer->start(1000);
Chris@113 265 std::cerr << "Finished setting up OSC interface" << std::endl;
Chris@113 266 }
Chris@113 267 }
Chris@113 268
Chris@45 269 QString
Chris@45 270 MainWindowBase::getOpenFileName(FileFinder::FileType type)
Chris@45 271 {
Chris@45 272 FileFinder *ff = FileFinder::getInstance();
Chris@45 273 switch (type) {
Chris@45 274 case FileFinder::SessionFile:
Chris@45 275 return ff->getOpenFileName(type, m_sessionFile);
Chris@45 276 case FileFinder::AudioFile:
Chris@45 277 return ff->getOpenFileName(type, m_audioFile);
Chris@45 278 case FileFinder::LayerFile:
Chris@45 279 return ff->getOpenFileName(type, m_sessionFile);
Chris@45 280 case FileFinder::LayerFileNoMidi:
Chris@45 281 return ff->getOpenFileName(type, m_sessionFile);
Chris@45 282 case FileFinder::SessionOrAudioFile:
Chris@45 283 return ff->getOpenFileName(type, m_sessionFile);
Chris@45 284 case FileFinder::ImageFile:
Chris@45 285 return ff->getOpenFileName(type, m_sessionFile);
Chris@45 286 case FileFinder::AnyFile:
Chris@45 287 if (getMainModel() != 0 &&
Chris@45 288 m_paneStack != 0 &&
Chris@45 289 m_paneStack->getCurrentPane() != 0) { // can import a layer
Chris@45 290 return ff->getOpenFileName(FileFinder::AnyFile, m_sessionFile);
Chris@45 291 } else {
Chris@45 292 return ff->getOpenFileName(FileFinder::SessionOrAudioFile,
Chris@45 293 m_sessionFile);
Chris@45 294 }
Chris@45 295 }
Chris@45 296 return "";
Chris@45 297 }
Chris@45 298
Chris@45 299 QString
Chris@45 300 MainWindowBase::getSaveFileName(FileFinder::FileType type)
Chris@45 301 {
Chris@45 302 FileFinder *ff = FileFinder::getInstance();
Chris@45 303 switch (type) {
Chris@45 304 case FileFinder::SessionFile:
Chris@45 305 return ff->getSaveFileName(type, m_sessionFile);
Chris@45 306 case FileFinder::AudioFile:
Chris@45 307 return ff->getSaveFileName(type, m_audioFile);
Chris@45 308 case FileFinder::LayerFile:
Chris@45 309 return ff->getSaveFileName(type, m_sessionFile);
Chris@45 310 case FileFinder::LayerFileNoMidi:
Chris@45 311 return ff->getSaveFileName(type, m_sessionFile);
Chris@45 312 case FileFinder::SessionOrAudioFile:
Chris@45 313 return ff->getSaveFileName(type, m_sessionFile);
Chris@45 314 case FileFinder::ImageFile:
Chris@45 315 return ff->getSaveFileName(type, m_sessionFile);
Chris@45 316 case FileFinder::AnyFile:
Chris@45 317 return ff->getSaveFileName(type, m_sessionFile);
Chris@45 318 }
Chris@45 319 return "";
Chris@45 320 }
Chris@45 321
Chris@45 322 void
Chris@45 323 MainWindowBase::registerLastOpenedFilePath(FileFinder::FileType type, QString path)
Chris@45 324 {
Chris@45 325 FileFinder *ff = FileFinder::getInstance();
Chris@45 326 ff->registerLastOpenedFilePath(type, path);
Chris@45 327 }
Chris@45 328
Chris@45 329 void
Chris@45 330 MainWindowBase::updateMenuStates()
Chris@45 331 {
Chris@45 332 Pane *currentPane = 0;
Chris@45 333 Layer *currentLayer = 0;
Chris@45 334
Chris@45 335 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
Chris@45 336 if (currentPane) currentLayer = currentPane->getSelectedLayer();
Chris@45 337
Chris@73 338 bool havePrevPane = false, haveNextPane = false;
Chris@73 339 bool havePrevLayer = false, haveNextLayer = false;
Chris@73 340
Chris@73 341 if (currentPane) {
Chris@73 342 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@73 343 if (m_paneStack->getPane(i) == currentPane) {
Chris@73 344 if (i > 0) havePrevPane = true;
Chris@73 345 if (i < m_paneStack->getPaneCount()-1) haveNextPane = true;
Chris@73 346 break;
Chris@73 347 }
Chris@73 348 }
Chris@73 349 if (currentLayer) {
Chris@73 350 for (int i = 0; i < currentPane->getLayerCount(); ++i) {
Chris@73 351 if (currentPane->getLayer(i) == currentLayer) {
Chris@73 352 if (i > 0) havePrevLayer = true;
Chris@73 353 if (i < currentPane->getLayerCount()-1) haveNextLayer = true;
Chris@73 354 break;
Chris@73 355 }
Chris@73 356 }
Chris@73 357 }
Chris@73 358 }
Chris@73 359
Chris@45 360 bool haveCurrentPane =
Chris@45 361 (currentPane != 0);
Chris@45 362 bool haveCurrentLayer =
Chris@45 363 (haveCurrentPane &&
Chris@45 364 (currentLayer != 0));
Chris@45 365 bool haveMainModel =
Chris@45 366 (getMainModel() != 0);
Chris@45 367 bool havePlayTarget =
Chris@45 368 (m_playTarget != 0);
Chris@45 369 bool haveSelection =
Chris@45 370 (m_viewManager &&
Chris@45 371 !m_viewManager->getSelections().empty());
Chris@45 372 bool haveCurrentEditableLayer =
Chris@45 373 (haveCurrentLayer &&
Chris@45 374 currentLayer->isLayerEditable());
Chris@45 375 bool haveCurrentTimeInstantsLayer =
Chris@45 376 (haveCurrentLayer &&
Chris@45 377 dynamic_cast<TimeInstantLayer *>(currentLayer));
Chris@184 378 bool haveCurrentDurationLayer =
Chris@184 379 (haveCurrentLayer &&
Chris@184 380 (dynamic_cast<NoteLayer *>(currentLayer) ||
Chris@184 381 dynamic_cast<RegionLayer *>(currentLayer)));
Chris@45 382 bool haveCurrentColour3DPlot =
Chris@45 383 (haveCurrentLayer &&
Chris@45 384 dynamic_cast<Colour3DPlotLayer *>(currentLayer));
Chris@45 385 bool haveClipboardContents =
Chris@45 386 (m_viewManager &&
Chris@45 387 !m_viewManager->getClipboard().empty());
Chris@146 388 bool haveTabularLayer =
Chris@146 389 (haveCurrentLayer &&
Chris@146 390 dynamic_cast<TabularModel *>(currentLayer->getModel()));
Chris@45 391
Chris@45 392 emit canAddPane(haveMainModel);
Chris@45 393 emit canDeleteCurrentPane(haveCurrentPane);
Chris@45 394 emit canZoom(haveMainModel && haveCurrentPane);
Chris@45 395 emit canScroll(haveMainModel && haveCurrentPane);
Chris@45 396 emit canAddLayer(haveMainModel && haveCurrentPane);
Chris@45 397 emit canImportMoreAudio(haveMainModel);
Chris@45 398 emit canImportLayer(haveMainModel && haveCurrentPane);
Chris@45 399 emit canExportAudio(haveMainModel);
Chris@45 400 emit canExportLayer(haveMainModel &&
Chris@45 401 (haveCurrentEditableLayer || haveCurrentColour3DPlot));
Chris@45 402 emit canExportImage(haveMainModel && haveCurrentPane);
Chris@45 403 emit canDeleteCurrentLayer(haveCurrentLayer);
Chris@45 404 emit canRenameLayer(haveCurrentLayer);
Chris@45 405 emit canEditLayer(haveCurrentEditableLayer);
Chris@146 406 emit canEditLayerTabular(haveCurrentEditableLayer || haveTabularLayer);
Chris@45 407 emit canMeasureLayer(haveCurrentLayer);
Chris@45 408 emit canSelect(haveMainModel && haveCurrentPane);
Chris@188 409 emit canPlay(haveMainModel && havePlayTarget);
Chris@45 410 emit canFfwd(true);
Chris@45 411 emit canRewind(true);
Chris@87 412 emit canPaste(haveClipboardContents);
Chris@45 413 emit canInsertInstant(haveCurrentPane);
Chris@45 414 emit canInsertInstantsAtBoundaries(haveCurrentPane && haveSelection);
Chris@184 415 emit canInsertItemAtSelection(haveCurrentPane && haveSelection && haveCurrentDurationLayer);
Chris@45 416 emit canRenumberInstants(haveCurrentTimeInstantsLayer && haveSelection);
Chris@45 417 emit canPlaySelection(haveMainModel && havePlayTarget && haveSelection);
Chris@45 418 emit canClearSelection(haveSelection);
Chris@45 419 emit canEditSelection(haveSelection && haveCurrentEditableLayer);
Chris@45 420 emit canSave(m_sessionFile != "" && m_documentModified);
Chris@73 421 emit canSelectPreviousPane(havePrevPane);
Chris@73 422 emit canSelectNextPane(haveNextPane);
Chris@73 423 emit canSelectPreviousLayer(havePrevLayer);
Chris@73 424 emit canSelectNextLayer(haveNextLayer);
Chris@45 425 }
Chris@45 426
Chris@45 427 void
Chris@45 428 MainWindowBase::documentModified()
Chris@45 429 {
Chris@45 430 // std::cerr << "MainWindowBase::documentModified" << std::endl;
Chris@45 431
Chris@45 432 if (!m_documentModified) {
Chris@45 433 //!!! this in subclass implementation?
Chris@45 434 setWindowTitle(tr("%1 (modified)").arg(windowTitle()));
Chris@45 435 }
Chris@45 436
Chris@45 437 m_documentModified = true;
Chris@45 438 updateMenuStates();
Chris@45 439 }
Chris@45 440
Chris@45 441 void
Chris@45 442 MainWindowBase::documentRestored()
Chris@45 443 {
Chris@45 444 // std::cerr << "MainWindowBase::documentRestored" << std::endl;
Chris@45 445
Chris@45 446 if (m_documentModified) {
Chris@45 447 //!!! this in subclass implementation?
Chris@45 448 QString wt(windowTitle());
Chris@45 449 wt.replace(tr(" (modified)"), "");
Chris@45 450 setWindowTitle(wt);
Chris@45 451 }
Chris@45 452
Chris@45 453 m_documentModified = false;
Chris@45 454 updateMenuStates();
Chris@45 455 }
Chris@45 456
Chris@45 457 void
Chris@45 458 MainWindowBase::playLoopToggled()
Chris@45 459 {
Chris@45 460 QAction *action = dynamic_cast<QAction *>(sender());
Chris@45 461
Chris@45 462 if (action) {
Chris@45 463 m_viewManager->setPlayLoopMode(action->isChecked());
Chris@45 464 } else {
Chris@45 465 m_viewManager->setPlayLoopMode(!m_viewManager->getPlayLoopMode());
Chris@45 466 }
Chris@45 467 }
Chris@45 468
Chris@45 469 void
Chris@45 470 MainWindowBase::playSelectionToggled()
Chris@45 471 {
Chris@45 472 QAction *action = dynamic_cast<QAction *>(sender());
Chris@45 473
Chris@45 474 if (action) {
Chris@45 475 m_viewManager->setPlaySelectionMode(action->isChecked());
Chris@45 476 } else {
Chris@45 477 m_viewManager->setPlaySelectionMode(!m_viewManager->getPlaySelectionMode());
Chris@45 478 }
Chris@45 479 }
Chris@45 480
Chris@45 481 void
Chris@45 482 MainWindowBase::playSoloToggled()
Chris@45 483 {
Chris@45 484 QAction *action = dynamic_cast<QAction *>(sender());
Chris@45 485
Chris@45 486 if (action) {
Chris@45 487 m_viewManager->setPlaySoloMode(action->isChecked());
Chris@45 488 } else {
Chris@45 489 m_viewManager->setPlaySoloMode(!m_viewManager->getPlaySoloMode());
Chris@45 490 }
Chris@45 491
Chris@45 492 if (m_viewManager->getPlaySoloMode()) {
Chris@45 493 currentPaneChanged(m_paneStack->getCurrentPane());
Chris@45 494 } else {
Chris@45 495 m_viewManager->setPlaybackModel(0);
Chris@45 496 if (m_playSource) {
Chris@45 497 m_playSource->clearSoloModelSet();
Chris@45 498 }
Chris@45 499 }
Chris@45 500 }
Chris@45 501
Chris@45 502 void
Chris@45 503 MainWindowBase::currentPaneChanged(Pane *p)
Chris@45 504 {
Chris@45 505 updateMenuStates();
Chris@45 506 updateVisibleRangeDisplay(p);
Chris@45 507
Chris@45 508 if (!p) return;
Chris@45 509
Chris@45 510 if (!(m_viewManager &&
Chris@45 511 m_playSource &&
Chris@45 512 m_viewManager->getPlaySoloMode())) {
Chris@45 513 if (m_viewManager) m_viewManager->setPlaybackModel(0);
Chris@45 514 return;
Chris@45 515 }
Chris@45 516
Chris@45 517 Model *prevPlaybackModel = m_viewManager->getPlaybackModel();
Chris@60 518
Chris@93 519 // What we want here is not the currently playing frame (unless we
Chris@93 520 // are about to clear out the audio playback buffers -- which may
Chris@93 521 // or may not be possible, depending on the audio driver). What
Chris@93 522 // we want is the frame that was last committed to the soundcard
Chris@93 523 // buffers, as the audio driver will continue playing up to that
Chris@93 524 // frame before switching to whichever one we decide we want to
Chris@93 525 // switch to, regardless of our efforts.
Chris@93 526
Chris@93 527 int frame = m_playSource->getCurrentBufferedFrame();
Chris@93 528
Chris@93 529 // std::cerr << "currentPaneChanged: current frame (in ref model) = " << frame << std::endl;
Chris@45 530
Chris@45 531 View::ModelSet soloModels = p->getModels();
Chris@45 532
Chris@57 533 View::ModelSet sources;
Chris@57 534 for (View::ModelSet::iterator mi = soloModels.begin();
Chris@57 535 mi != soloModels.end(); ++mi) {
Chris@190 536 // If a model in this pane is derived from something else,
Chris@190 537 // then we want to play that model as well -- if the model
Chris@190 538 // that's derived from it is not something that is itself
Chris@190 539 // individually playable (e.g. a waveform)
Chris@190 540 if (*mi &&
Chris@190 541 !dynamic_cast<RangeSummarisableTimeValueModel *>(*mi) &&
Chris@190 542 (*mi)->getSourceModel()) {
Chris@57 543 sources.insert((*mi)->getSourceModel());
Chris@57 544 }
Chris@57 545 }
Chris@57 546 for (View::ModelSet::iterator mi = sources.begin();
Chris@57 547 mi != sources.end(); ++mi) {
Chris@57 548 soloModels.insert(*mi);
Chris@57 549 }
Chris@57 550
Chris@60 551 //!!! Need an "atomic" way of telling the play source that the
Chris@60 552 //playback model has changed, and changing it on ViewManager --
Chris@60 553 //the play source should be making the setPlaybackModel call to
Chris@60 554 //ViewManager
Chris@60 555
Chris@45 556 for (View::ModelSet::iterator mi = soloModels.begin();
Chris@45 557 mi != soloModels.end(); ++mi) {
Chris@45 558 if (dynamic_cast<RangeSummarisableTimeValueModel *>(*mi)) {
Chris@45 559 m_viewManager->setPlaybackModel(*mi);
Chris@45 560 }
Chris@45 561 }
Chris@45 562
Chris@45 563 RangeSummarisableTimeValueModel *a =
Chris@45 564 dynamic_cast<RangeSummarisableTimeValueModel *>(prevPlaybackModel);
Chris@45 565 RangeSummarisableTimeValueModel *b =
Chris@45 566 dynamic_cast<RangeSummarisableTimeValueModel *>(m_viewManager->
Chris@45 567 getPlaybackModel());
Chris@45 568
Chris@45 569 m_playSource->setSoloModelSet(soloModels);
Chris@45 570
Chris@45 571 if (a && b && (a != b)) {
Chris@60 572 if (m_playSource->isPlaying()) m_playSource->play(frame);
Chris@45 573 }
Chris@45 574 }
Chris@45 575
Chris@45 576 void
Chris@45 577 MainWindowBase::currentLayerChanged(Pane *p, Layer *)
Chris@45 578 {
Chris@45 579 updateMenuStates();
Chris@45 580 updateVisibleRangeDisplay(p);
Chris@45 581 }
Chris@45 582
Chris@45 583 void
Chris@45 584 MainWindowBase::selectAll()
Chris@45 585 {
Chris@45 586 if (!getMainModel()) return;
Chris@45 587 m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(),
Chris@45 588 getMainModel()->getEndFrame()));
Chris@45 589 }
Chris@45 590
Chris@45 591 void
Chris@45 592 MainWindowBase::selectToStart()
Chris@45 593 {
Chris@45 594 if (!getMainModel()) return;
Chris@45 595 m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(),
Chris@45 596 m_viewManager->getGlobalCentreFrame()));
Chris@45 597 }
Chris@45 598
Chris@45 599 void
Chris@45 600 MainWindowBase::selectToEnd()
Chris@45 601 {
Chris@45 602 if (!getMainModel()) return;
Chris@45 603 m_viewManager->setSelection(Selection(m_viewManager->getGlobalCentreFrame(),
Chris@45 604 getMainModel()->getEndFrame()));
Chris@45 605 }
Chris@45 606
Chris@45 607 void
Chris@45 608 MainWindowBase::selectVisible()
Chris@45 609 {
Chris@45 610 Model *model = getMainModel();
Chris@45 611 if (!model) return;
Chris@45 612
Chris@45 613 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 614 if (!currentPane) return;
Chris@45 615
Chris@45 616 size_t startFrame, endFrame;
Chris@45 617
Chris@45 618 if (currentPane->getStartFrame() < 0) startFrame = 0;
Chris@45 619 else startFrame = currentPane->getStartFrame();
Chris@45 620
Chris@45 621 if (currentPane->getEndFrame() > model->getEndFrame()) endFrame = model->getEndFrame();
Chris@45 622 else endFrame = currentPane->getEndFrame();
Chris@45 623
Chris@45 624 m_viewManager->setSelection(Selection(startFrame, endFrame));
Chris@45 625 }
Chris@45 626
Chris@45 627 void
Chris@45 628 MainWindowBase::clearSelection()
Chris@45 629 {
Chris@45 630 m_viewManager->clearSelections();
Chris@45 631 }
Chris@45 632
Chris@45 633 void
Chris@45 634 MainWindowBase::cut()
Chris@45 635 {
Chris@45 636 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 637 if (!currentPane) return;
Chris@45 638
Chris@45 639 Layer *layer = currentPane->getSelectedLayer();
Chris@45 640 if (!layer) return;
Chris@45 641
Chris@45 642 Clipboard &clipboard = m_viewManager->getClipboard();
Chris@45 643 clipboard.clear();
Chris@45 644
Chris@45 645 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@45 646
Chris@45 647 CommandHistory::getInstance()->startCompoundOperation(tr("Cut"), true);
Chris@45 648
Chris@45 649 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@45 650 i != selections.end(); ++i) {
Chris@86 651 layer->copy(currentPane, *i, clipboard);
Chris@45 652 layer->deleteSelection(*i);
Chris@45 653 }
Chris@45 654
Chris@45 655 CommandHistory::getInstance()->endCompoundOperation();
Chris@45 656 }
Chris@45 657
Chris@45 658 void
Chris@45 659 MainWindowBase::copy()
Chris@45 660 {
Chris@45 661 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 662 if (!currentPane) return;
Chris@45 663
Chris@45 664 Layer *layer = currentPane->getSelectedLayer();
Chris@45 665 if (!layer) return;
Chris@45 666
Chris@45 667 Clipboard &clipboard = m_viewManager->getClipboard();
Chris@45 668 clipboard.clear();
Chris@45 669
Chris@45 670 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@45 671
Chris@45 672 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@45 673 i != selections.end(); ++i) {
Chris@86 674 layer->copy(currentPane, *i, clipboard);
Chris@45 675 }
Chris@45 676 }
Chris@45 677
Chris@45 678 void
Chris@45 679 MainWindowBase::paste()
Chris@45 680 {
Chris@215 681 pasteRelative(0);
Chris@215 682 }
Chris@215 683
Chris@215 684 void
Chris@215 685 MainWindowBase::pasteAtPlaybackPosition()
Chris@215 686 {
Chris@215 687 unsigned long pos = getFrame();
Chris@215 688 Clipboard &clipboard = m_viewManager->getClipboard();
Chris@215 689 if (!clipboard.empty()) {
Chris@215 690 long firstEventFrame = clipboard.getPoints()[0].getFrame();
Chris@215 691 long offset = 0;
Chris@215 692 if (firstEventFrame < 0) {
Chris@221 693 offset = (long)pos - firstEventFrame;
Chris@215 694 } else if (firstEventFrame < pos) {
Chris@221 695 offset = pos - (unsigned long)firstEventFrame;
Chris@215 696 } else {
Chris@221 697 offset = -((unsigned long)firstEventFrame - pos);
Chris@215 698 }
Chris@215 699 pasteRelative(offset);
Chris@215 700 }
Chris@215 701 }
Chris@215 702
Chris@215 703 void
Chris@215 704 MainWindowBase::pasteRelative(int offset)
Chris@215 705 {
Chris@45 706 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 707 if (!currentPane) return;
Chris@45 708
Chris@45 709 Layer *layer = currentPane->getSelectedLayer();
Chris@45 710
Chris@45 711 Clipboard &clipboard = m_viewManager->getClipboard();
Chris@87 712
Chris@98 713 bool inCompound = false;
Chris@87 714
Chris@87 715 if (!layer || !layer->isLayerEditable()) {
Chris@87 716
Chris@87 717 CommandHistory::getInstance()->startCompoundOperation
Chris@87 718 (tr("Paste"), true);
Chris@87 719
Chris@87 720 // no suitable current layer: create one of the most
Chris@87 721 // appropriate sort
Chris@87 722 LayerFactory::LayerType type =
Chris@87 723 LayerFactory::getInstance()->getLayerTypeForClipboardContents(clipboard);
Chris@87 724 layer = m_document->createEmptyLayer(type);
Chris@87 725
Chris@87 726 if (!layer) {
Chris@87 727 CommandHistory::getInstance()->endCompoundOperation();
Chris@87 728 return;
Chris@45 729 }
Chris@87 730
Chris@87 731 m_document->addLayerToView(currentPane, layer);
Chris@87 732 m_paneStack->setCurrentLayer(currentPane, layer);
Chris@87 733
Chris@87 734 inCompound = true;
Chris@45 735 }
Chris@45 736
Chris@215 737 layer->paste(currentPane, clipboard, offset, true);
Chris@45 738
Chris@87 739 if (inCompound) CommandHistory::getInstance()->endCompoundOperation();
Chris@45 740 }
Chris@45 741
Chris@45 742 void
Chris@45 743 MainWindowBase::deleteSelected()
Chris@45 744 {
Chris@45 745 if (m_paneStack->getCurrentPane() &&
Chris@45 746 m_paneStack->getCurrentPane()->getSelectedLayer()) {
Chris@45 747
Chris@45 748 Layer *layer = m_paneStack->getCurrentPane()->getSelectedLayer();
Chris@45 749
Chris@45 750 if (m_viewManager &&
Chris@45 751 (m_viewManager->getToolMode() == ViewManager::MeasureMode)) {
Chris@45 752
Chris@45 753 layer->deleteCurrentMeasureRect();
Chris@45 754
Chris@45 755 } else {
Chris@45 756
Chris@45 757 MultiSelection::SelectionList selections =
Chris@45 758 m_viewManager->getSelections();
Chris@45 759
Chris@45 760 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@45 761 i != selections.end(); ++i) {
Chris@45 762 layer->deleteSelection(*i);
Chris@45 763 }
Chris@45 764 }
Chris@45 765 }
Chris@45 766 }
Chris@45 767
Chris@161 768 // FrameTimer method
Chris@161 769
Chris@161 770 unsigned long
Chris@161 771 MainWindowBase::getFrame() const
Chris@161 772 {
Chris@161 773 if (m_playSource && m_playSource->isPlaying()) {
Chris@161 774 return m_playSource->getCurrentPlayingFrame();
Chris@161 775 } else {
Chris@161 776 return m_viewManager->getPlaybackFrame();
Chris@161 777 }
Chris@161 778 }
Chris@161 779
Chris@45 780 void
Chris@45 781 MainWindowBase::insertInstant()
Chris@45 782 {
Chris@161 783 insertInstantAt(getFrame());
Chris@45 784 }
Chris@45 785
Chris@45 786 void
Chris@45 787 MainWindowBase::insertInstantsAtBoundaries()
Chris@45 788 {
Chris@45 789 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@45 790 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@45 791 i != selections.end(); ++i) {
Chris@45 792 size_t start = i->getStartFrame();
Chris@45 793 size_t end = i->getEndFrame();
Chris@45 794 if (start != end) {
Chris@184 795 insertInstantAt(start);
Chris@184 796 insertInstantAt(end);
Chris@45 797 }
Chris@45 798 }
Chris@45 799 }
Chris@45 800
Chris@45 801 void
Chris@45 802 MainWindowBase::insertInstantAt(size_t frame)
Chris@45 803 {
Chris@45 804 Pane *pane = m_paneStack->getCurrentPane();
Chris@45 805 if (!pane) {
Chris@45 806 return;
Chris@45 807 }
Chris@45 808
Chris@74 809 frame = pane->alignFromReference(frame);
Chris@74 810
Chris@45 811 Layer *layer = dynamic_cast<TimeInstantLayer *>
Chris@45 812 (pane->getSelectedLayer());
Chris@45 813
Chris@45 814 if (!layer) {
Chris@45 815 for (int i = pane->getLayerCount(); i > 0; --i) {
Chris@45 816 layer = dynamic_cast<TimeInstantLayer *>(pane->getLayer(i - 1));
Chris@45 817 if (layer) break;
Chris@45 818 }
Chris@45 819
Chris@45 820 if (!layer) {
Chris@45 821 CommandHistory::getInstance()->startCompoundOperation
Chris@45 822 (tr("Add Point"), true);
Chris@45 823 layer = m_document->createEmptyLayer(LayerFactory::TimeInstants);
Chris@45 824 if (layer) {
Chris@45 825 m_document->addLayerToView(pane, layer);
Chris@45 826 m_paneStack->setCurrentLayer(pane, layer);
Chris@45 827 }
Chris@45 828 CommandHistory::getInstance()->endCompoundOperation();
Chris@45 829 }
Chris@45 830 }
Chris@45 831
Chris@45 832 if (layer) {
Chris@45 833
Chris@45 834 Model *model = layer->getModel();
Chris@45 835 SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *>
Chris@45 836 (model);
Chris@45 837
Chris@45 838 if (sodm) {
Chris@45 839 SparseOneDimensionalModel::Point point(frame, "");
Chris@45 840
Chris@45 841 SparseOneDimensionalModel::Point prevPoint(0);
Chris@45 842 bool havePrevPoint = false;
Chris@45 843
Chris@45 844 SparseOneDimensionalModel::EditCommand *command =
Chris@45 845 new SparseOneDimensionalModel::EditCommand(sodm, tr("Add Point"));
Chris@45 846
Chris@74 847 if (m_labeller->requiresPrevPoint()) {
Chris@45 848
Chris@45 849 SparseOneDimensionalModel::PointList prevPoints =
Chris@45 850 sodm->getPreviousPoints(frame);
Chris@45 851
Chris@45 852 if (!prevPoints.empty()) {
Chris@45 853 prevPoint = *prevPoints.begin();
Chris@45 854 havePrevPoint = true;
Chris@45 855 }
Chris@45 856 }
Chris@45 857
Chris@45 858 if (m_labeller) {
Chris@45 859
Chris@45 860 m_labeller->setSampleRate(sodm->getSampleRate());
Chris@45 861
Chris@74 862 if (m_labeller->actingOnPrevPoint()) {
Chris@45 863 command->deletePoint(prevPoint);
Chris@45 864 }
Chris@45 865
Chris@45 866 m_labeller->label<SparseOneDimensionalModel::Point>
Chris@45 867 (point, havePrevPoint ? &prevPoint : 0);
Chris@45 868
Chris@74 869 if (m_labeller->actingOnPrevPoint()) {
Chris@45 870 command->addPoint(prevPoint);
Chris@45 871 }
Chris@45 872 }
Chris@45 873
Chris@45 874 command->addPoint(point);
Chris@45 875
Chris@45 876 command->setName(tr("Add Point at %1 s")
Chris@45 877 .arg(RealTime::frame2RealTime
Chris@45 878 (frame,
Chris@45 879 sodm->getSampleRate())
Chris@45 880 .toText(false).c_str()));
Chris@45 881
Chris@108 882 Command *c = command->finish();
Chris@108 883 if (c) CommandHistory::getInstance()->addCommand(c, false);
Chris@45 884 }
Chris@45 885 }
Chris@45 886 }
Chris@45 887
Chris@45 888 void
Chris@184 889 MainWindowBase::insertItemAtSelection()
Chris@184 890 {
Chris@184 891 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@184 892 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@184 893 i != selections.end(); ++i) {
Chris@184 894 size_t start = i->getStartFrame();
Chris@184 895 size_t end = i->getEndFrame();
Chris@184 896 if (start < end) {
Chris@184 897 insertItemAt(start, end - start);
Chris@184 898 }
Chris@184 899 }
Chris@184 900 }
Chris@184 901
Chris@184 902 void
Chris@184 903 MainWindowBase::insertItemAt(size_t frame, size_t duration)
Chris@184 904 {
Chris@184 905 Pane *pane = m_paneStack->getCurrentPane();
Chris@184 906 if (!pane) {
Chris@184 907 return;
Chris@184 908 }
Chris@184 909
Chris@184 910 // ugh!
Chris@184 911
Chris@184 912 size_t alignedStart = pane->alignFromReference(frame);
Chris@184 913 size_t alignedEnd = pane->alignFromReference(frame + duration);
Chris@184 914 if (alignedStart >= alignedEnd) return;
Chris@184 915 size_t alignedDuration = alignedEnd - alignedStart;
Chris@184 916
Chris@184 917 Command *c = 0;
Chris@184 918
Chris@184 919 QString name = tr("Add Item at %1 s")
Chris@184 920 .arg(RealTime::frame2RealTime
Chris@184 921 (alignedStart,
Chris@184 922 getMainModel()->getSampleRate())
Chris@184 923 .toText(false).c_str());
Chris@184 924
Chris@184 925 Layer *layer = pane->getSelectedLayer();
Chris@184 926 if (!layer) return;
Chris@184 927
Chris@184 928 RegionModel *rm = dynamic_cast<RegionModel *>(layer->getModel());
Chris@184 929 if (rm) {
Chris@184 930 RegionModel::Point point(alignedStart,
Chris@185 931 rm->getValueMaximum() + 1,
Chris@184 932 alignedDuration,
Chris@184 933 "");
Chris@184 934 RegionModel::EditCommand *command =
Chris@184 935 new RegionModel::EditCommand(rm, tr("Add Point"));
Chris@184 936 command->addPoint(point);
Chris@184 937 command->setName(name);
Chris@184 938 c = command->finish();
Chris@184 939 }
Chris@184 940
Chris@184 941 if (c) {
Chris@184 942 CommandHistory::getInstance()->addCommand(c, false);
Chris@184 943 return;
Chris@184 944 }
Chris@184 945
Chris@184 946 NoteModel *nm = dynamic_cast<NoteModel *>(layer->getModel());
Chris@184 947 if (nm) {
Chris@184 948 NoteModel::Point point(alignedStart,
Chris@184 949 rm->getValueMinimum(),
Chris@184 950 alignedDuration,
Chris@184 951 1.f,
Chris@184 952 "");
Chris@184 953 NoteModel::EditCommand *command =
Chris@184 954 new NoteModel::EditCommand(nm, tr("Add Point"));
Chris@184 955 command->addPoint(point);
Chris@184 956 command->setName(name);
Chris@184 957 c = command->finish();
Chris@184 958 }
Chris@184 959
Chris@184 960 if (c) {
Chris@184 961 CommandHistory::getInstance()->addCommand(c, false);
Chris@184 962 return;
Chris@184 963 }
Chris@184 964 }
Chris@184 965
Chris@184 966 void
Chris@45 967 MainWindowBase::renumberInstants()
Chris@45 968 {
Chris@45 969 Pane *pane = m_paneStack->getCurrentPane();
Chris@45 970 if (!pane) return;
Chris@45 971
Chris@45 972 Layer *layer = dynamic_cast<TimeInstantLayer *>(pane->getSelectedLayer());
Chris@45 973 if (!layer) return;
Chris@45 974
Chris@45 975 MultiSelection ms(m_viewManager->getSelection());
Chris@45 976
Chris@45 977 Model *model = layer->getModel();
Chris@45 978 SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *>
Chris@45 979 (model);
Chris@45 980 if (!sodm) return;
Chris@45 981
Chris@45 982 if (!m_labeller) return;
Chris@45 983
Chris@45 984 Labeller labeller(*m_labeller);
Chris@45 985 labeller.setSampleRate(sodm->getSampleRate());
Chris@45 986
Chris@45 987 // This uses a command
Chris@45 988
Chris@45 989 labeller.labelAll<SparseOneDimensionalModel::Point>(*sodm, &ms);
Chris@45 990 }
Chris@45 991
Chris@45 992 MainWindowBase::FileOpenStatus
Chris@45 993 MainWindowBase::open(QString fileOrUrl, AudioFileOpenMode mode)
Chris@45 994 {
Chris@134 995 ProgressDialog dialog(tr("Opening file or URL..."), true, 2000, this);
Chris@134 996 connect(&dialog, SIGNAL(showing()), this, SIGNAL(hideSplash()));
Chris@109 997 return open(FileSource(fileOrUrl, &dialog), mode);
Chris@45 998 }
Chris@45 999
Chris@45 1000 MainWindowBase::FileOpenStatus
Chris@45 1001 MainWindowBase::open(FileSource source, AudioFileOpenMode mode)
Chris@45 1002 {
Chris@45 1003 FileOpenStatus status;
Chris@45 1004
Chris@45 1005 if (!source.isAvailable()) return FileOpenFailed;
Chris@45 1006 source.waitForData();
Chris@45 1007
Chris@45 1008 bool canImportLayer = (getMainModel() != 0 &&
Chris@45 1009 m_paneStack != 0 &&
Chris@45 1010 m_paneStack->getCurrentPane() != 0);
Chris@45 1011
Chris@152 1012 bool rdf = (source.getExtension().toLower() == "rdf" ||
Chris@152 1013 source.getExtension().toLower() == "n3" ||
Chris@152 1014 source.getExtension().toLower() == "ttl");
Chris@152 1015
Chris@152 1016 bool audio = AudioFileReaderFactory::getKnownExtensions().contains
Chris@152 1017 (source.getExtension().toLower());
Chris@145 1018
Chris@145 1019 bool rdfSession = false;
Chris@145 1020 if (rdf) {
Chris@145 1021 RDFImporter::RDFDocumentType rdfType =
Chris@145 1022 RDFImporter::identifyDocumentType
Chris@145 1023 (QUrl::fromLocalFile(source.getLocalFilename()).toString());
Chris@148 1024 // std::cerr << "RDF type: " << (int)rdfType << std::endl;
Chris@145 1025 if (rdfType == RDFImporter::AudioRefAndAnnotations ||
Chris@145 1026 rdfType == RDFImporter::AudioRef) {
Chris@145 1027 rdfSession = true;
Chris@145 1028 } else if (rdfType == RDFImporter::NotRDF) {
Chris@145 1029 rdf = false;
Chris@145 1030 }
Chris@145 1031 }
Chris@145 1032
Chris@145 1033 if (rdf) {
Chris@145 1034 if (rdfSession) {
Chris@147 1035 bool cancel = false;
Chris@147 1036 if (!canImportLayer || shouldCreateNewSessionForRDFAudio(&cancel)) {
Chris@145 1037 return openSession(source);
Chris@147 1038 } else if (cancel) {
Chris@147 1039 return FileOpenCancelled;
Chris@145 1040 } else {
Chris@145 1041 return openLayer(source);
Chris@145 1042 }
Chris@145 1043 } else {
Chris@145 1044 if ((status = openSession(source)) != FileOpenFailed) {
Chris@145 1045 return status;
Chris@145 1046 } else if (!canImportLayer) {
Chris@145 1047 return FileOpenWrongMode;
Chris@145 1048 } else if ((status = openLayer(source)) != FileOpenFailed) {
Chris@145 1049 return status;
Chris@145 1050 } else {
Chris@145 1051 return FileOpenFailed;
Chris@145 1052 }
Chris@145 1053 }
Chris@145 1054 }
Chris@145 1055
Chris@152 1056 if (audio && (status = openAudio(source, mode)) != FileOpenFailed) {
Chris@45 1057 return status;
Chris@45 1058 } else if ((status = openSession(source)) != FileOpenFailed) {
Chris@45 1059 return status;
Chris@45 1060 } else if ((status = openPlaylist(source, mode)) != FileOpenFailed) {
Chris@45 1061 return status;
Chris@45 1062 } else if (!canImportLayer) {
Chris@45 1063 return FileOpenWrongMode;
Chris@45 1064 } else if ((status = openImage(source)) != FileOpenFailed) {
Chris@45 1065 return status;
Chris@45 1066 } else if ((status = openLayer(source)) != FileOpenFailed) {
Chris@45 1067 return status;
Chris@45 1068 } else {
Chris@45 1069 return FileOpenFailed;
Chris@45 1070 }
Chris@45 1071 }
Chris@45 1072
Chris@45 1073 MainWindowBase::FileOpenStatus
dan@210 1074 MainWindowBase::openAudio(FileSource source, AudioFileOpenMode mode, QString templateName)
Chris@45 1075 {
Chris@132 1076 // std::cerr << "MainWindowBase::openAudio(" << source.getLocation().toStdString() << ")" << std::endl;
Chris@45 1077
Chris@220 1078 if (templateName == "") templateName = "testtemplate";
Chris@220 1079
Chris@45 1080 if (!source.isAvailable()) return FileOpenFailed;
Chris@45 1081 source.waitForData();
Chris@45 1082
Chris@45 1083 m_openingAudioFile = true;
Chris@45 1084
Chris@45 1085 size_t rate = 0;
Chris@45 1086
Chris@45 1087 if (Preferences::getInstance()->getResampleOnLoad()) {
Chris@45 1088 rate = m_playSource->getSourceSampleRate();
Chris@45 1089 }
Chris@45 1090
Chris@45 1091 WaveFileModel *newModel = new WaveFileModel(source, rate);
Chris@45 1092
Chris@45 1093 if (!newModel->isOK()) {
Chris@45 1094 delete newModel;
Chris@45 1095 m_openingAudioFile = false;
Chris@45 1096 return FileOpenFailed;
Chris@45 1097 }
Chris@45 1098
Chris@132 1099 // std::cerr << "mode = " << mode << std::endl;
Chris@45 1100
Chris@45 1101 if (mode == AskUser) {
Chris@45 1102 if (getMainModel()) {
Chris@45 1103
Chris@147 1104 QSettings settings;
Chris@147 1105 settings.beginGroup("MainWindow");
Chris@221 1106 int lastMode = settings.value("lastaudioopenmode", 0).toBool();
Chris@147 1107 settings.endGroup();
Chris@221 1108 int imode = 0;
Chris@45 1109
Chris@45 1110 QStringList items;
Chris@221 1111 items << tr("Close the current session and start a new one")
Chris@221 1112 << tr("Replace the main audio file in this session")
Chris@221 1113 << tr("Add the audio file to this session");
Chris@45 1114
Chris@45 1115 bool ok = false;
Chris@45 1116 QString item = ListInputDialog::getItem
Chris@45 1117 (this, tr("Select target for import"),
Chris@221 1118 tr("<b>Select a target for import</b><p>You already have an audio file loaded.<br>What would you like to do with the new audio file?"),
Chris@221 1119 items, lastMode, &ok);
Chris@45 1120
Chris@45 1121 if (!ok || item.isEmpty()) {
Chris@45 1122 delete newModel;
Chris@45 1123 m_openingAudioFile = false;
Chris@45 1124 return FileOpenCancelled;
Chris@45 1125 }
Chris@45 1126
Chris@221 1127 for (int i = 0; i < items.size(); ++i) {
Chris@221 1128 if (item == items[i]) imode = i;
Chris@221 1129 }
Chris@221 1130
Chris@147 1131 settings.beginGroup("MainWindow");
Chris@221 1132 settings.setValue("lastaudioopenmode", imode);
Chris@147 1133 settings.endGroup();
Chris@45 1134
Chris@221 1135 mode = (AudioFileOpenMode)imode;
Chris@45 1136
Chris@45 1137 } else {
Chris@221 1138 // no main model: make a new session
Chris@221 1139 mode = ReplaceSession;
Chris@45 1140 }
Chris@45 1141 }
Chris@45 1142
Chris@45 1143 if (mode == ReplaceCurrentPane) {
Chris@45 1144
Chris@45 1145 Pane *pane = m_paneStack->getCurrentPane();
Chris@45 1146 if (pane) {
Chris@45 1147 if (getMainModel()) {
Chris@45 1148 View::ModelSet models(pane->getModels());
Chris@45 1149 if (models.find(getMainModel()) != models.end()) {
Chris@221 1150 // Current pane contains main model: replace that
Chris@45 1151 mode = ReplaceMainModel;
Chris@45 1152 }
Chris@221 1153 // Otherwise the current pane has a non-default model,
Chris@221 1154 // which we will deal with later
Chris@45 1155 } else {
Chris@221 1156 // We have no main model, so start a new session with
Chris@221 1157 // optional template
Chris@221 1158 mode = ReplaceSession;
Chris@45 1159 }
Chris@45 1160 } else {
Chris@221 1161 // We seem to have no current pane! Oh well
Chris@45 1162 mode = CreateAdditionalModel;
Chris@45 1163 }
Chris@45 1164 }
Chris@45 1165
Chris@45 1166 if (mode == CreateAdditionalModel && !getMainModel()) {
Chris@221 1167 mode = ReplaceSession;
Chris@221 1168 }
Chris@221 1169
Chris@221 1170 bool loadedTemplate = false;
Chris@221 1171
Chris@221 1172 if (mode == ReplaceSession) {
Chris@221 1173
Chris@221 1174 if (templateName.length() != 0) {
Chris@221 1175 QString tplPath = "file::templates/" + templateName + ".xml";
Chris@221 1176 std::cerr << "SV looking for template " << tplPath.toStdString() << std::endl;
Chris@221 1177 FileOpenStatus tplStatus = openSessionFile(tplPath);
Chris@221 1178 if (tplStatus != FileOpenFailed) {
Chris@221 1179 loadedTemplate = true;
Chris@221 1180 }
Chris@221 1181 }
Chris@221 1182
Chris@221 1183 if (!loadedTemplate) {
Chris@221 1184 closeSession();
Chris@221 1185 createDocument();
Chris@221 1186 }
Chris@221 1187
Chris@45 1188 mode = ReplaceMainModel;
Chris@45 1189 }
Chris@45 1190
Chris@164 1191 emit activity(tr("Import audio file \"%1\"").arg(source.getLocation()));
Chris@164 1192
Chris@45 1193 if (mode == ReplaceMainModel) {
Chris@45 1194
Chris@45 1195 Model *prevMain = getMainModel();
Chris@45 1196 if (prevMain) {
Chris@45 1197 m_playSource->removeModel(prevMain);
Chris@108 1198 PlayParameterRepository::getInstance()->removePlayable(prevMain);
Chris@45 1199 }
Chris@108 1200 PlayParameterRepository::getInstance()->addPlayable(newModel);
Chris@45 1201
Chris@45 1202 m_document->setMainModel(newModel);
Chris@45 1203
Chris@45 1204 setupMenus();
Chris@45 1205
dan@210 1206 if (loadedTemplate || (m_sessionFile == "")) {
Chris@45 1207 //!!! shouldn't be dealing directly with title from here -- call a method
Chris@57 1208 setWindowTitle(tr("%1: %2")
Chris@57 1209 .arg(QApplication::applicationName())
Chris@45 1210 .arg(source.getLocation()));
Chris@45 1211 CommandHistory::getInstance()->clear();
Chris@45 1212 CommandHistory::getInstance()->documentSaved();
Chris@45 1213 m_documentModified = false;
Chris@45 1214 } else {
Chris@57 1215 setWindowTitle(tr("%1: %2 [%3]")
Chris@57 1216 .arg(QApplication::applicationName())
Chris@45 1217 .arg(QFileInfo(m_sessionFile).fileName())
Chris@45 1218 .arg(source.getLocation()));
Chris@45 1219 if (m_documentModified) {
Chris@45 1220 m_documentModified = false;
Chris@45 1221 documentModified(); // so as to restore "(modified)" window title
Chris@45 1222 }
Chris@45 1223 }
Chris@45 1224
Chris@45 1225 if (!source.isRemote()) m_audioFile = source.getLocalFilename();
Chris@45 1226
Chris@45 1227 } else if (mode == CreateAdditionalModel) {
Chris@45 1228
Chris@45 1229 CommandHistory::getInstance()->startCompoundOperation
Chris@219 1230 (tr("Import \"%1\"").arg(source.getBasename()), true);
Chris@45 1231
Chris@45 1232 m_document->addImportedModel(newModel);
Chris@45 1233
Chris@45 1234 AddPaneCommand *command = new AddPaneCommand(this);
Chris@45 1235 CommandHistory::getInstance()->addCommand(command);
Chris@45 1236
Chris@45 1237 Pane *pane = command->getPane();
Chris@45 1238
Chris@47 1239 if (m_timeRulerLayer) {
Chris@47 1240 m_document->addLayerToView(pane, m_timeRulerLayer);
Chris@47 1241 }
Chris@45 1242
Chris@45 1243 Layer *newLayer = m_document->createImportedLayer(newModel);
Chris@45 1244
Chris@45 1245 if (newLayer) {
Chris@45 1246 m_document->addLayerToView(pane, newLayer);
Chris@45 1247 }
Chris@45 1248
Chris@45 1249 CommandHistory::getInstance()->endCompoundOperation();
Chris@45 1250
Chris@45 1251 } else if (mode == ReplaceCurrentPane) {
Chris@45 1252
Chris@45 1253 // We know there is a current pane, otherwise we would have
Chris@45 1254 // reset the mode to CreateAdditionalModel above; and we know
Chris@45 1255 // the current pane does not contain the main model, otherwise
Chris@45 1256 // we would have reset it to ReplaceMainModel. But we don't
Chris@45 1257 // know whether the pane contains a waveform model at all.
Chris@45 1258
Chris@45 1259 Pane *pane = m_paneStack->getCurrentPane();
Chris@45 1260 Layer *replace = 0;
Chris@45 1261
Chris@45 1262 for (int i = 0; i < pane->getLayerCount(); ++i) {
Chris@45 1263 Layer *layer = pane->getLayer(i);
Chris@45 1264 if (dynamic_cast<WaveformLayer *>(layer)) {
Chris@45 1265 replace = layer;
Chris@45 1266 break;
Chris@45 1267 }
Chris@45 1268 }
Chris@45 1269
Chris@45 1270 CommandHistory::getInstance()->startCompoundOperation
Chris@219 1271 (tr("Import \"%1\"").arg(source.getBasename()), true);
Chris@45 1272
Chris@45 1273 m_document->addImportedModel(newModel);
Chris@45 1274
Chris@45 1275 if (replace) {
Chris@45 1276 m_document->removeLayerFromView(pane, replace);
Chris@45 1277 }
Chris@45 1278
Chris@45 1279 Layer *newLayer = m_document->createImportedLayer(newModel);
Chris@45 1280
Chris@45 1281 if (newLayer) {
Chris@45 1282 m_document->addLayerToView(pane, newLayer);
Chris@45 1283 }
Chris@45 1284
Chris@45 1285 CommandHistory::getInstance()->endCompoundOperation();
Chris@45 1286 }
Chris@45 1287
Chris@45 1288 updateMenuStates();
Chris@45 1289 m_recentFiles.addFile(source.getLocation());
Chris@45 1290 if (!source.isRemote()) {
Chris@45 1291 // for file dialog
Chris@45 1292 registerLastOpenedFilePath(FileFinder::AudioFile,
Chris@45 1293 source.getLocalFilename());
Chris@45 1294 }
Chris@45 1295 m_openingAudioFile = false;
Chris@45 1296
Chris@45 1297 currentPaneChanged(m_paneStack->getCurrentPane());
Chris@45 1298
Chris@45 1299 return FileOpenSucceeded;
Chris@45 1300 }
Chris@45 1301
Chris@45 1302 MainWindowBase::FileOpenStatus
Chris@45 1303 MainWindowBase::openPlaylist(FileSource source, AudioFileOpenMode mode)
Chris@45 1304 {
Chris@135 1305 std::cerr << "MainWindowBase::openPlaylist(" << source.getLocation().toStdString() << ")" << std::endl;
Chris@135 1306
Chris@45 1307 std::set<QString> extensions;
Chris@45 1308 PlaylistFileReader::getSupportedExtensions(extensions);
Chris@152 1309 QString extension = source.getExtension().toLower();
Chris@45 1310 if (extensions.find(extension) == extensions.end()) return FileOpenFailed;
Chris@45 1311
Chris@45 1312 if (!source.isAvailable()) return FileOpenFailed;
Chris@45 1313 source.waitForData();
Chris@45 1314
Chris@45 1315 PlaylistFileReader reader(source.getLocalFilename());
Chris@45 1316 if (!reader.isOK()) return FileOpenFailed;
Chris@45 1317
Chris@45 1318 PlaylistFileReader::Playlist playlist = reader.load();
Chris@45 1319
Chris@45 1320 bool someSuccess = false;
Chris@45 1321
Chris@45 1322 for (PlaylistFileReader::Playlist::const_iterator i = playlist.begin();
Chris@45 1323 i != playlist.end(); ++i) {
Chris@45 1324
Chris@134 1325 ProgressDialog dialog(tr("Opening playlist..."), true, 2000, this);
Chris@134 1326 connect(&dialog, SIGNAL(showing()), this, SIGNAL(hideSplash()));
Chris@109 1327 FileOpenStatus status = openAudio(FileSource(*i, &dialog), mode);
Chris@45 1328
Chris@45 1329 if (status == FileOpenCancelled) {
Chris@45 1330 return FileOpenCancelled;
Chris@45 1331 }
Chris@45 1332
Chris@45 1333 if (status == FileOpenSucceeded) {
Chris@45 1334 someSuccess = true;
Chris@45 1335 mode = CreateAdditionalModel;
Chris@45 1336 }
Chris@45 1337 }
Chris@45 1338
Chris@45 1339 if (someSuccess) return FileOpenSucceeded;
Chris@45 1340 else return FileOpenFailed;
Chris@45 1341 }
Chris@45 1342
Chris@45 1343 MainWindowBase::FileOpenStatus
Chris@45 1344 MainWindowBase::openLayer(FileSource source)
Chris@45 1345 {
Chris@135 1346 std::cerr << "MainWindowBase::openLayer(" << source.getLocation().toStdString() << ")" << std::endl;
Chris@135 1347
Chris@45 1348 Pane *pane = m_paneStack->getCurrentPane();
Chris@45 1349
Chris@45 1350 if (!pane) {
Chris@45 1351 // shouldn't happen, as the menu action should have been disabled
Chris@45 1352 std::cerr << "WARNING: MainWindowBase::openLayer: no current pane" << std::endl;
Chris@45 1353 return FileOpenWrongMode;
Chris@45 1354 }
Chris@45 1355
Chris@45 1356 if (!getMainModel()) {
Chris@45 1357 // shouldn't happen, as the menu action should have been disabled
Chris@45 1358 std::cerr << "WARNING: MainWindowBase::openLayer: No main model -- hence no default sample rate available" << std::endl;
Chris@45 1359 return FileOpenWrongMode;
Chris@45 1360 }
Chris@45 1361
Chris@45 1362 if (!source.isAvailable()) return FileOpenFailed;
Chris@45 1363 source.waitForData();
Chris@45 1364
Chris@45 1365 QString path = source.getLocalFilename();
Chris@45 1366
Chris@145 1367 RDFImporter::RDFDocumentType rdfType =
Chris@145 1368 RDFImporter::identifyDocumentType(QUrl::fromLocalFile(path).toString());
Chris@145 1369
Chris@148 1370 // std::cerr << "RDF type: (in layer) " << (int) rdfType << std::endl;
Chris@148 1371
Chris@145 1372 if (rdfType != RDFImporter::NotRDF) {
Chris@145 1373
Chris@145 1374 return openLayersFromRDF(source);
Chris@134 1375
Chris@152 1376 } else if (source.getExtension().toLower() == "svl" ||
Chris@152 1377 (source.getExtension().toLower() == "xml" &&
Chris@140 1378 (SVFileReader::identifyXmlFile(source.getLocalFilename())
Chris@140 1379 == SVFileReader::SVLayerFile))) {
Chris@45 1380
Chris@45 1381 PaneCallback callback(this);
Chris@45 1382 QFile file(path);
Chris@45 1383
Chris@45 1384 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
Chris@45 1385 std::cerr << "ERROR: MainWindowBase::openLayer("
Chris@45 1386 << source.getLocation().toStdString()
Chris@45 1387 << "): Failed to open file for reading" << std::endl;
Chris@45 1388 return FileOpenFailed;
Chris@45 1389 }
Chris@45 1390
Chris@45 1391 SVFileReader reader(m_document, callback, source.getLocation());
Chris@79 1392 connect
Chris@79 1393 (&reader, SIGNAL(modelRegenerationFailed(QString, QString, QString)),
Chris@79 1394 this, SLOT(modelRegenerationFailed(QString, QString, QString)));
Chris@79 1395 connect
Chris@79 1396 (&reader, SIGNAL(modelRegenerationWarning(QString, QString, QString)),
Chris@79 1397 this, SLOT(modelRegenerationWarning(QString, QString, QString)));
Chris@45 1398 reader.setCurrentPane(pane);
Chris@45 1399
Chris@45 1400 QXmlInputSource inputSource(&file);
Chris@45 1401 reader.parse(inputSource);
Chris@45 1402
Chris@45 1403 if (!reader.isOK()) {
Chris@45 1404 std::cerr << "ERROR: MainWindowBase::openLayer("
Chris@45 1405 << source.getLocation().toStdString()
Chris@45 1406 << "): Failed to read XML file: "
Chris@45 1407 << reader.getErrorString().toStdString() << std::endl;
Chris@45 1408 return FileOpenFailed;
Chris@45 1409 }
Chris@45 1410
Chris@164 1411 emit activity(tr("Import layer XML file \"%1\"").arg(source.getLocation()));
Chris@164 1412
Chris@45 1413 m_recentFiles.addFile(source.getLocation());
Chris@45 1414
Chris@45 1415 if (!source.isRemote()) {
Chris@45 1416 registerLastOpenedFilePath(FileFinder::LayerFile, path); // for file dialog
Chris@45 1417 }
Chris@45 1418
Chris@75 1419 return FileOpenSucceeded;
Chris@75 1420
Chris@45 1421 } else {
Chris@45 1422
Chris@45 1423 try {
Chris@45 1424
Chris@109 1425 MIDIFileImportDialog midiDlg(this);
Chris@109 1426
Chris@109 1427 Model *model = DataFileReaderFactory::loadNonCSV
Chris@109 1428 (path, &midiDlg, getMainModel()->getSampleRate());
Chris@45 1429
Chris@109 1430 if (!model) {
Chris@196 1431 CSVFormat format(path);
Chris@196 1432 format.setSampleRate(getMainModel()->getSampleRate());
Chris@196 1433 CSVFormatDialog *dialog = new CSVFormatDialog(this, format);
Chris@109 1434 if (dialog->exec() == QDialog::Accepted) {
Chris@109 1435 model = DataFileReaderFactory::loadCSV
Chris@109 1436 (path, dialog->getFormat(),
Chris@109 1437 getMainModel()->getSampleRate());
Chris@109 1438 }
Chris@109 1439 }
Chris@109 1440
Chris@45 1441 if (model) {
Chris@45 1442
Chris@45 1443 std::cerr << "MainWindowBase::openLayer: Have model" << std::endl;
Chris@45 1444
Chris@164 1445 emit activity(tr("Import MIDI file \"%1\"").arg(source.getLocation()));
Chris@164 1446
Chris@45 1447 Layer *newLayer = m_document->createImportedLayer(model);
Chris@45 1448
Chris@45 1449 if (newLayer) {
Chris@45 1450
Chris@45 1451 m_document->addLayerToView(pane, newLayer);
Chris@88 1452 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@88 1453
Chris@45 1454 m_recentFiles.addFile(source.getLocation());
Chris@45 1455
Chris@45 1456 if (!source.isRemote()) {
Chris@45 1457 registerLastOpenedFilePath
Chris@45 1458 (FileFinder::LayerFile,
Chris@45 1459 path); // for file dialog
Chris@45 1460 }
Chris@88 1461
Chris@45 1462 return FileOpenSucceeded;
Chris@45 1463 }
Chris@45 1464 }
Chris@45 1465 } catch (DataFileReaderFactory::Exception e) {
Chris@45 1466 if (e == DataFileReaderFactory::ImportCancelled) {
Chris@45 1467 return FileOpenCancelled;
Chris@45 1468 }
Chris@45 1469 }
Chris@45 1470 }
Chris@45 1471
Chris@45 1472 return FileOpenFailed;
Chris@45 1473 }
Chris@45 1474
Chris@45 1475 MainWindowBase::FileOpenStatus
Chris@45 1476 MainWindowBase::openImage(FileSource source)
Chris@45 1477 {
Chris@135 1478 std::cerr << "MainWindowBase::openImage(" << source.getLocation().toStdString() << ")" << std::endl;
Chris@135 1479
Chris@45 1480 Pane *pane = m_paneStack->getCurrentPane();
Chris@45 1481
Chris@45 1482 if (!pane) {
Chris@45 1483 // shouldn't happen, as the menu action should have been disabled
Chris@45 1484 std::cerr << "WARNING: MainWindowBase::openImage: no current pane" << std::endl;
Chris@45 1485 return FileOpenWrongMode;
Chris@45 1486 }
Chris@45 1487
Chris@45 1488 if (!m_document->getMainModel()) {
Chris@45 1489 return FileOpenWrongMode;
Chris@45 1490 }
Chris@45 1491
Chris@45 1492 bool newLayer = false;
Chris@45 1493
Chris@45 1494 ImageLayer *il = dynamic_cast<ImageLayer *>(pane->getSelectedLayer());
Chris@45 1495 if (!il) {
Chris@45 1496 for (int i = pane->getLayerCount()-1; i >= 0; --i) {
Chris@45 1497 il = dynamic_cast<ImageLayer *>(pane->getLayer(i));
Chris@45 1498 if (il) break;
Chris@45 1499 }
Chris@45 1500 }
Chris@45 1501 if (!il) {
Chris@45 1502 il = dynamic_cast<ImageLayer *>
Chris@45 1503 (m_document->createEmptyLayer(LayerFactory::Image));
Chris@45 1504 if (!il) return FileOpenFailed;
Chris@45 1505 newLayer = true;
Chris@45 1506 }
Chris@45 1507
Chris@45 1508 // We don't put the image file in Recent Files
Chris@45 1509
Chris@45 1510 std::cerr << "openImage: trying location \"" << source.getLocation().toStdString() << "\" in image layer" << std::endl;
Chris@45 1511
Chris@45 1512 if (!il->addImage(m_viewManager->getGlobalCentreFrame(), source.getLocation())) {
Chris@45 1513 if (newLayer) {
Chris@52 1514 m_document->deleteLayer(il); // also releases its model
Chris@45 1515 }
Chris@45 1516 return FileOpenFailed;
Chris@45 1517 } else {
Chris@45 1518 if (newLayer) {
Chris@45 1519 m_document->addLayerToView(pane, il);
Chris@45 1520 }
Chris@45 1521 m_paneStack->setCurrentLayer(pane, il);
Chris@45 1522 }
Chris@45 1523
Chris@45 1524 return FileOpenSucceeded;
Chris@45 1525 }
Chris@45 1526
Chris@45 1527 MainWindowBase::FileOpenStatus
Chris@45 1528 MainWindowBase::openSessionFile(QString fileOrUrl)
Chris@45 1529 {
Chris@134 1530 ProgressDialog dialog(tr("Opening session..."), true, 2000, this);
Chris@134 1531 connect(&dialog, SIGNAL(showing()), this, SIGNAL(hideSplash()));
Chris@109 1532 return openSession(FileSource(fileOrUrl, &dialog));
Chris@45 1533 }
Chris@45 1534
Chris@45 1535 MainWindowBase::FileOpenStatus
Chris@45 1536 MainWindowBase::openSession(FileSource source)
Chris@45 1537 {
Chris@135 1538 std::cerr << "MainWindowBase::openSession(" << source.getLocation().toStdString() << ")" << std::endl;
Chris@135 1539
Chris@45 1540 if (!source.isAvailable()) return FileOpenFailed;
Chris@145 1541 source.waitForData();
Chris@141 1542
Chris@152 1543 if (source.getExtension().toLower() != "sv") {
Chris@145 1544
Chris@145 1545 RDFImporter::RDFDocumentType rdfType =
Chris@145 1546 RDFImporter::identifyDocumentType
Chris@145 1547 (QUrl::fromLocalFile(source.getLocalFilename()).toString());
Chris@145 1548
Chris@148 1549 // std::cerr << "RDF type: " << (int)rdfType << std::endl;
Chris@148 1550
Chris@145 1551 if (rdfType == RDFImporter::AudioRefAndAnnotations ||
Chris@145 1552 rdfType == RDFImporter::AudioRef) {
Chris@145 1553 return openSessionFromRDF(source);
Chris@145 1554 } else if (rdfType != RDFImporter::NotRDF) {
Chris@145 1555 return FileOpenFailed;
Chris@145 1556 }
Chris@145 1557
Chris@152 1558 if (source.getExtension().toLower() == "xml") {
Chris@140 1559 if (SVFileReader::identifyXmlFile(source.getLocalFilename()) ==
Chris@140 1560 SVFileReader::SVSessionFile) {
Chris@140 1561 std::cerr << "This XML file looks like a session file, attempting to open it as a session" << std::endl;
Chris@140 1562 } else {
Chris@140 1563 return FileOpenFailed;
Chris@140 1564 }
Chris@140 1565 } else {
Chris@140 1566 return FileOpenFailed;
Chris@140 1567 }
Chris@140 1568 }
Chris@45 1569
Chris@140 1570 QXmlInputSource *inputSource = 0;
Chris@140 1571 BZipFileDevice *bzFile = 0;
Chris@140 1572 QFile *rawFile = 0;
Chris@140 1573
Chris@152 1574 if (source.getExtension().toLower() == "sv") {
Chris@140 1575 bzFile = new BZipFileDevice(source.getLocalFilename());
Chris@140 1576 if (!bzFile->open(QIODevice::ReadOnly)) {
Chris@140 1577 delete bzFile;
Chris@140 1578 return FileOpenFailed;
Chris@140 1579 }
Chris@140 1580 inputSource = new QXmlInputSource(bzFile);
Chris@140 1581 } else {
Chris@140 1582 rawFile = new QFile(source.getLocalFilename());
Chris@140 1583 inputSource = new QXmlInputSource(rawFile);
Chris@140 1584 }
Chris@140 1585
Chris@140 1586 if (!checkSaveModified()) {
Chris@140 1587 if (bzFile) bzFile->close();
Chris@140 1588 delete inputSource;
Chris@140 1589 delete bzFile;
Chris@140 1590 delete rawFile;
Chris@140 1591 return FileOpenCancelled;
Chris@140 1592 }
Chris@45 1593
Chris@45 1594 QString error;
Chris@45 1595 closeSession();
Chris@45 1596 createDocument();
Chris@45 1597
Chris@45 1598 PaneCallback callback(this);
Chris@45 1599 m_viewManager->clearSelections();
Chris@45 1600
Chris@45 1601 SVFileReader reader(m_document, callback, source.getLocation());
Chris@79 1602 connect
Chris@79 1603 (&reader, SIGNAL(modelRegenerationFailed(QString, QString, QString)),
Chris@79 1604 this, SLOT(modelRegenerationFailed(QString, QString, QString)));
Chris@79 1605 connect
Chris@79 1606 (&reader, SIGNAL(modelRegenerationWarning(QString, QString, QString)),
Chris@79 1607 this, SLOT(modelRegenerationWarning(QString, QString, QString)));
Chris@140 1608
Chris@140 1609 reader.parse(*inputSource);
Chris@45 1610
Chris@45 1611 if (!reader.isOK()) {
Chris@45 1612 error = tr("SV XML file read error:\n%1").arg(reader.getErrorString());
Chris@45 1613 }
Chris@45 1614
Chris@140 1615 if (bzFile) bzFile->close();
Chris@140 1616
Chris@140 1617 delete inputSource;
Chris@140 1618 delete bzFile;
Chris@140 1619 delete rawFile;
Chris@45 1620
Chris@45 1621 bool ok = (error == "");
Chris@45 1622
Chris@45 1623 if (ok) {
Chris@45 1624
Chris@164 1625 emit activity(tr("Import session file \"%1\"").arg(source.getLocation()));
Chris@164 1626
Chris@57 1627 setWindowTitle(tr("%1: %2")
Chris@57 1628 .arg(QApplication::applicationName())
Chris@45 1629 .arg(source.getLocation()));
Chris@45 1630
Chris@45 1631 if (!source.isRemote()) m_sessionFile = source.getLocalFilename();
Chris@45 1632
Chris@45 1633 setupMenus();
Chris@45 1634
Chris@45 1635 CommandHistory::getInstance()->clear();
Chris@45 1636 CommandHistory::getInstance()->documentSaved();
Chris@45 1637 m_documentModified = false;
Chris@45 1638 updateMenuStates();
Chris@45 1639
Chris@45 1640 m_recentFiles.addFile(source.getLocation());
Chris@45 1641
Chris@45 1642 if (!source.isRemote()) {
Chris@45 1643 // for file dialog
Chris@45 1644 registerLastOpenedFilePath(FileFinder::SessionFile,
Chris@45 1645 source.getLocalFilename());
Chris@45 1646 }
Chris@45 1647
Chris@45 1648 } else {
Chris@57 1649 setWindowTitle(QApplication::applicationName());
Chris@45 1650 }
Chris@45 1651
Chris@45 1652 return ok ? FileOpenSucceeded : FileOpenFailed;
Chris@45 1653 }
Chris@45 1654
Chris@141 1655 MainWindowBase::FileOpenStatus
Chris@141 1656 MainWindowBase::openSessionFromRDF(FileSource source)
Chris@141 1657 {
Chris@141 1658 std::cerr << "MainWindowBase::openSessionFromRDF(" << source.getLocation().toStdString() << ")" << std::endl;
Chris@141 1659
Chris@141 1660 if (!source.isAvailable()) return FileOpenFailed;
Chris@141 1661 source.waitForData();
Chris@141 1662
Chris@145 1663 if (!checkSaveModified()) {
Chris@145 1664 return FileOpenCancelled;
Chris@141 1665 }
Chris@143 1666
Chris@145 1667 closeSession();
Chris@145 1668 createDocument();
Chris@145 1669
Chris@145 1670 FileOpenStatus status = openLayersFromRDF(source);
Chris@141 1671
Chris@141 1672 setupMenus();
Chris@141 1673
Chris@141 1674 setWindowTitle(tr("%1: %2")
Chris@141 1675 .arg(QApplication::applicationName())
Chris@141 1676 .arg(source.getLocation()));
Chris@141 1677 CommandHistory::getInstance()->clear();
Chris@141 1678 CommandHistory::getInstance()->documentSaved();
Chris@141 1679 m_documentModified = false;
Chris@145 1680
Chris@145 1681 return status;
Chris@145 1682 }
Chris@145 1683
Chris@145 1684 MainWindowBase::FileOpenStatus
Chris@145 1685 MainWindowBase::openLayersFromRDF(FileSource source)
Chris@145 1686 {
Chris@145 1687 size_t rate = 0;
Chris@145 1688
Chris@186 1689 std::cerr << "MainWindowBase::openLayersFromRDF" << std::endl;
Chris@186 1690
Chris@145 1691 ProgressDialog dialog(tr("Importing from RDF..."), true, 2000, this);
Chris@145 1692 connect(&dialog, SIGNAL(showing()), this, SIGNAL(hideSplash()));
Chris@145 1693
Chris@145 1694 if (getMainModel()) {
Chris@145 1695 rate = getMainModel()->getSampleRate();
Chris@145 1696 } else if (Preferences::getInstance()->getResampleOnLoad()) {
Chris@145 1697 rate = m_playSource->getSourceSampleRate();
Chris@145 1698 }
Chris@145 1699
Chris@145 1700 RDFImporter importer
Chris@145 1701 (QUrl::fromLocalFile(source.getLocalFilename()).toString(), rate);
Chris@145 1702
Chris@145 1703 if (!importer.isOK()) {
Chris@147 1704 if (importer.getErrorString() != "") {
Chris@147 1705 QMessageBox::critical
Chris@147 1706 (this, tr("Failed to import RDF"),
Chris@147 1707 tr("<b>Failed to import RDF</b><p>Importing data from RDF document at \"%1\" failed: %2</p>")
Chris@147 1708 .arg(source.getLocation()).arg(importer.getErrorString()));
Chris@147 1709 }
Chris@145 1710 return FileOpenFailed;
Chris@145 1711 }
Chris@145 1712
Chris@145 1713 std::vector<Model *> models = importer.getDataModels(&dialog);
Chris@145 1714
Chris@145 1715 dialog.setMessage(tr("Importing from RDF..."));
Chris@145 1716
Chris@145 1717 if (models.empty()) {
Chris@186 1718 QMessageBox::critical
Chris@186 1719 (this, tr("Failed to import RDF"),
Chris@186 1720 tr("<b>Failed to import RDF</b><p>No suitable data models found for import from RDF document at \"%1\"</p>").arg(source.getLocation()));
Chris@145 1721 return FileOpenFailed;
Chris@145 1722 }
Chris@145 1723
Chris@164 1724 emit activity(tr("Import RDF document \"%1\"").arg(source.getLocation()));
Chris@164 1725
Chris@145 1726 std::set<Model *> added;
Chris@145 1727
Chris@221 1728 for (int i = 0; i < (int)models.size(); ++i) {
Chris@145 1729
Chris@145 1730 Model *m = models[i];
Chris@145 1731 WaveFileModel *w = dynamic_cast<WaveFileModel *>(m);
Chris@145 1732
Chris@145 1733 if (w) {
Chris@145 1734
Chris@145 1735 Pane *pane = addPaneToStack();
Chris@145 1736 Layer *layer = 0;
Chris@145 1737
Chris@145 1738 if (m_timeRulerLayer) {
Chris@145 1739 m_document->addLayerToView(pane, m_timeRulerLayer);
Chris@145 1740 }
Chris@145 1741
Chris@145 1742 if (!getMainModel()) {
Chris@145 1743 m_document->setMainModel(w);
Chris@145 1744 layer = m_document->createMainModelLayer(LayerFactory::Waveform);
Chris@145 1745 } else {
Chris@145 1746 layer = m_document->createImportedLayer(w);
Chris@145 1747 }
Chris@145 1748
Chris@145 1749 m_document->addLayerToView(pane, layer);
Chris@145 1750
Chris@145 1751 added.insert(w);
Chris@145 1752
Chris@221 1753 for (int j = 0; j < (int)models.size(); ++j) {
Chris@145 1754
Chris@145 1755 Model *dm = models[j];
Chris@145 1756
Chris@145 1757 if (dm == m) continue;
Chris@145 1758 if (dm->getSourceModel() != m) continue;
Chris@145 1759
Chris@145 1760 layer = m_document->createImportedLayer(dm);
Chris@145 1761
Chris@145 1762 if (layer->isLayerOpaque() ||
Chris@145 1763 dynamic_cast<Colour3DPlotLayer *>(layer)) {
Chris@145 1764
Chris@156 1765 // these always go in a new pane, with nothing
Chris@156 1766 // else going in the same pane
Chris@156 1767
Chris@145 1768 Pane *singleLayerPane = addPaneToStack();
Chris@145 1769 if (m_timeRulerLayer) {
Chris@145 1770 m_document->addLayerToView(singleLayerPane, m_timeRulerLayer);
Chris@145 1771 }
Chris@145 1772 m_document->addLayerToView(singleLayerPane, layer);
Chris@145 1773
Chris@156 1774 } else if (layer->getLayerColourSignificance() ==
Chris@156 1775 Layer::ColourHasMeaningfulValue) {
Chris@156 1776
Chris@156 1777 // these can go in a pane with something else, but
Chris@156 1778 // only if none of the something elses also have
Chris@156 1779 // this quality
Chris@156 1780
Chris@156 1781 bool needNewPane = false;
Chris@156 1782 for (int i = 0; i < pane->getLayerCount(); ++i) {
Chris@156 1783 Layer *otherLayer = pane->getLayer(i);
Chris@156 1784 if (otherLayer &&
Chris@156 1785 (otherLayer->getLayerColourSignificance() ==
Chris@156 1786 Layer::ColourHasMeaningfulValue)) {
Chris@156 1787 needNewPane = true;
Chris@156 1788 break;
Chris@156 1789 }
Chris@156 1790 }
Chris@156 1791 if (needNewPane) {
Chris@156 1792 pane = addPaneToStack();
Chris@156 1793 }
Chris@156 1794
Chris@156 1795 m_document->addLayerToView(pane, layer);
Chris@156 1796
Chris@145 1797 } else {
Chris@145 1798
Chris@145 1799 if (pane->getLayerCount() > 4) {
Chris@145 1800 pane = addPaneToStack();
Chris@145 1801 }
Chris@145 1802
Chris@145 1803 m_document->addLayerToView(pane, layer);
Chris@145 1804 }
Chris@145 1805
Chris@145 1806 added.insert(dm);
Chris@145 1807 }
Chris@145 1808 }
Chris@145 1809 }
Chris@145 1810
Chris@221 1811 for (int i = 0; i < (int)models.size(); ++i) {
Chris@145 1812
Chris@145 1813 Model *m = models[i];
Chris@145 1814
Chris@145 1815 if (added.find(m) == added.end()) {
Chris@145 1816
Chris@145 1817 Layer *layer = m_document->createImportedLayer(m);
Chris@145 1818 if (!layer) return FileOpenFailed;
Chris@145 1819
Chris@145 1820 Pane *singleLayerPane = addPaneToStack();
Chris@145 1821 if (m_timeRulerLayer) {
Chris@145 1822 m_document->addLayerToView(singleLayerPane, m_timeRulerLayer);
Chris@145 1823 }
Chris@145 1824 m_document->addLayerToView(singleLayerPane, layer);
Chris@145 1825 }
Chris@145 1826 }
Chris@145 1827
Chris@145 1828 m_recentFiles.addFile(source.getLocation());
Chris@145 1829 return FileOpenSucceeded;
Chris@141 1830 }
Chris@141 1831
Chris@45 1832 void
Chris@45 1833 MainWindowBase::createPlayTarget()
Chris@45 1834 {
Chris@45 1835 if (m_playTarget) return;
Chris@45 1836
Chris@126 1837 QSettings settings;
Chris@126 1838 settings.beginGroup("Preferences");
Chris@126 1839 QString targetName = settings.value("audio-target", "").toString();
Chris@126 1840 settings.endGroup();
Chris@126 1841
Chris@126 1842 AudioTargetFactory *factory = AudioTargetFactory::getInstance();
Chris@126 1843
Chris@126 1844 factory->setDefaultCallbackTarget(targetName);
Chris@126 1845 m_playTarget = factory->createCallbackTarget(m_playSource);
Chris@126 1846
Chris@45 1847 if (!m_playTarget) {
Chris@104 1848 emit hideSplash();
Chris@126 1849
Chris@126 1850 if (factory->isAutoCallbackTarget(targetName)) {
Chris@128 1851 QMessageBox::warning
Chris@45 1852 (this, tr("Couldn't open audio device"),
Chris@126 1853 tr("<b>No audio available</b><p>Could not open an audio device for playback.<p>Automatic audio device detection failed. Audio playback will not be available during this session.</p>"),
Chris@45 1854 QMessageBox::Ok);
Chris@126 1855 } else {
Chris@126 1856 QMessageBox::warning
Chris@126 1857 (this, tr("Couldn't open audio device"),
Chris@126 1858 tr("<b>No audio available</b><p>Failed to open your preferred audio device (\"%1\").<p>Audio playback will not be available during this session.</p>")
Chris@126 1859 .arg(factory->getCallbackTargetDescription(targetName)),
Chris@126 1860 QMessageBox::Ok);
Chris@126 1861 }
Chris@45 1862 }
Chris@45 1863 }
Chris@45 1864
Chris@45 1865 WaveFileModel *
Chris@45 1866 MainWindowBase::getMainModel()
Chris@45 1867 {
Chris@45 1868 if (!m_document) return 0;
Chris@45 1869 return m_document->getMainModel();
Chris@45 1870 }
Chris@45 1871
Chris@45 1872 const WaveFileModel *
Chris@45 1873 MainWindowBase::getMainModel() const
Chris@45 1874 {
Chris@45 1875 if (!m_document) return 0;
Chris@45 1876 return m_document->getMainModel();
Chris@45 1877 }
Chris@45 1878
Chris@45 1879 void
Chris@45 1880 MainWindowBase::createDocument()
Chris@45 1881 {
Chris@45 1882 m_document = new Document;
Chris@45 1883
Chris@45 1884 connect(m_document, SIGNAL(layerAdded(Layer *)),
Chris@45 1885 this, SLOT(layerAdded(Layer *)));
Chris@45 1886 connect(m_document, SIGNAL(layerRemoved(Layer *)),
Chris@45 1887 this, SLOT(layerRemoved(Layer *)));
Chris@45 1888 connect(m_document, SIGNAL(layerAboutToBeDeleted(Layer *)),
Chris@45 1889 this, SLOT(layerAboutToBeDeleted(Layer *)));
Chris@45 1890 connect(m_document, SIGNAL(layerInAView(Layer *, bool)),
Chris@45 1891 this, SLOT(layerInAView(Layer *, bool)));
Chris@45 1892
Chris@45 1893 connect(m_document, SIGNAL(modelAdded(Model *)),
Chris@45 1894 this, SLOT(modelAdded(Model *)));
Chris@45 1895 connect(m_document, SIGNAL(mainModelChanged(WaveFileModel *)),
Chris@45 1896 this, SLOT(mainModelChanged(WaveFileModel *)));
Chris@45 1897 connect(m_document, SIGNAL(modelAboutToBeDeleted(Model *)),
Chris@45 1898 this, SLOT(modelAboutToBeDeleted(Model *)));
Chris@45 1899
Chris@78 1900 connect(m_document, SIGNAL(modelGenerationFailed(QString, QString)),
Chris@78 1901 this, SLOT(modelGenerationFailed(QString, QString)));
Chris@78 1902 connect(m_document, SIGNAL(modelRegenerationWarning(QString, QString, QString)),
Chris@78 1903 this, SLOT(modelRegenerationWarning(QString, QString, QString)));
Chris@78 1904 connect(m_document, SIGNAL(modelGenerationFailed(QString, QString)),
Chris@78 1905 this, SLOT(modelGenerationFailed(QString, QString)));
Chris@78 1906 connect(m_document, SIGNAL(modelRegenerationWarning(QString, QString, QString)),
Chris@78 1907 this, SLOT(modelRegenerationWarning(QString, QString, QString)));
Chris@78 1908 connect(m_document, SIGNAL(alignmentFailed(QString, QString)),
Chris@78 1909 this, SLOT(alignmentFailed(QString, QString)));
Chris@160 1910
Chris@160 1911 emit replacedDocument();
Chris@45 1912 }
Chris@45 1913
Chris@45 1914 bool
Chris@45 1915 MainWindowBase::saveSessionFile(QString path)
Chris@45 1916 {
Chris@217 1917 try {
Chris@217 1918
Chris@217 1919 TempWriteFile temp(path);
Chris@217 1920
Chris@217 1921 BZipFileDevice bzFile(temp.getTemporaryFilename());
Chris@217 1922 if (!bzFile.open(QIODevice::WriteOnly)) {
Chris@217 1923 std::cerr << "Failed to open session file \""
Chris@217 1924 << temp.getTemporaryFilename().toStdString()
Chris@217 1925 << "\" for writing: "
Chris@217 1926 << bzFile.errorString().toStdString() << std::endl;
Chris@217 1927 return false;
Chris@217 1928 }
Chris@217 1929
Chris@217 1930 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
Chris@217 1931
Chris@217 1932 QTextStream out(&bzFile);
Chris@217 1933 toXml(out);
Chris@217 1934 out.flush();
Chris@217 1935
Chris@217 1936 QApplication::restoreOverrideCursor();
Chris@217 1937
Chris@217 1938 if (!bzFile.isOK()) {
Chris@217 1939 QMessageBox::critical(this, tr("Failed to write file"),
Chris@217 1940 tr("<b>Save failed</b><p>Failed to write to file \"%1\": %2")
Chris@217 1941 .arg(path).arg(bzFile.errorString()));
Chris@217 1942 bzFile.close();
Chris@217 1943 return false;
Chris@217 1944 }
Chris@217 1945
Chris@217 1946 bzFile.close();
Chris@217 1947 temp.moveToTarget();
Chris@217 1948 return true;
Chris@217 1949
Chris@217 1950 } catch (FileOperationFailed &f) {
Chris@217 1951
Chris@217 1952 QMessageBox::critical(this, tr("Failed to write file"),
Chris@217 1953 tr("<b>Save failed</b><p>Failed to write to file \"%1\": %2")
Chris@217 1954 .arg(path).arg(f.what()));
Chris@45 1955 return false;
Chris@45 1956 }
Chris@45 1957 }
Chris@45 1958
Chris@45 1959 void
Chris@45 1960 MainWindowBase::toXml(QTextStream &out)
Chris@45 1961 {
Chris@45 1962 QString indent(" ");
Chris@45 1963
Chris@45 1964 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
Chris@45 1965 out << "<!DOCTYPE sonic-visualiser>\n";
Chris@45 1966 out << "<sv>\n";
Chris@45 1967
Chris@45 1968 m_document->toXml(out, "", "");
Chris@45 1969
Chris@45 1970 out << "<display>\n";
Chris@45 1971
Chris@45 1972 out << QString(" <window width=\"%1\" height=\"%2\"/>\n")
Chris@45 1973 .arg(width()).arg(height());
Chris@45 1974
Chris@45 1975 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@45 1976
Chris@45 1977 Pane *pane = m_paneStack->getPane(i);
Chris@45 1978
Chris@45 1979 if (pane) {
Chris@45 1980 pane->toXml(out, indent);
Chris@45 1981 }
Chris@45 1982 }
Chris@45 1983
Chris@45 1984 out << "</display>\n";
Chris@45 1985
Chris@45 1986 m_viewManager->getSelection().toXml(out);
Chris@45 1987
Chris@45 1988 out << "</sv>\n";
Chris@45 1989 }
Chris@45 1990
Chris@45 1991 Pane *
Chris@45 1992 MainWindowBase::addPaneToStack()
Chris@45 1993 {
Chris@45 1994 AddPaneCommand *command = new AddPaneCommand(this);
Chris@45 1995 CommandHistory::getInstance()->addCommand(command);
Chris@57 1996 Pane *pane = command->getPane();
Chris@57 1997 return pane;
Chris@45 1998 }
Chris@45 1999
Chris@45 2000 void
Chris@45 2001 MainWindowBase::zoomIn()
Chris@45 2002 {
Chris@45 2003 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 2004 if (currentPane) currentPane->zoom(true);
Chris@45 2005 }
Chris@45 2006
Chris@45 2007 void
Chris@45 2008 MainWindowBase::zoomOut()
Chris@45 2009 {
Chris@45 2010 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 2011 if (currentPane) currentPane->zoom(false);
Chris@45 2012 }
Chris@45 2013
Chris@45 2014 void
Chris@45 2015 MainWindowBase::zoomToFit()
Chris@45 2016 {
Chris@45 2017 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 2018 if (!currentPane) return;
Chris@45 2019
Chris@45 2020 Model *model = getMainModel();
Chris@45 2021 if (!model) return;
Chris@45 2022
Chris@45 2023 size_t start = model->getStartFrame();
Chris@45 2024 size_t end = model->getEndFrame();
Chris@60 2025 if (m_playSource) end = std::max(end, m_playSource->getPlayEndFrame());
Chris@45 2026 size_t pixels = currentPane->width();
Chris@45 2027
Chris@45 2028 size_t sw = currentPane->getVerticalScaleWidth();
Chris@45 2029 if (pixels > sw * 2) pixels -= sw * 2;
Chris@45 2030 else pixels = 1;
Chris@45 2031 if (pixels > 4) pixels -= 4;
Chris@45 2032
Chris@45 2033 size_t zoomLevel = (end - start) / pixels;
Chris@150 2034 if (zoomLevel < 1) zoomLevel = 1;
Chris@45 2035
Chris@45 2036 currentPane->setZoomLevel(zoomLevel);
Chris@45 2037 currentPane->setCentreFrame((start + end) / 2);
Chris@45 2038 }
Chris@45 2039
Chris@45 2040 void
Chris@45 2041 MainWindowBase::zoomDefault()
Chris@45 2042 {
Chris@45 2043 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 2044 if (currentPane) currentPane->setZoomLevel(1024);
Chris@45 2045 }
Chris@45 2046
Chris@45 2047 void
Chris@45 2048 MainWindowBase::scrollLeft()
Chris@45 2049 {
Chris@45 2050 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 2051 if (currentPane) currentPane->scroll(false, false);
Chris@45 2052 }
Chris@45 2053
Chris@45 2054 void
Chris@45 2055 MainWindowBase::jumpLeft()
Chris@45 2056 {
Chris@45 2057 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 2058 if (currentPane) currentPane->scroll(false, true);
Chris@45 2059 }
Chris@45 2060
Chris@45 2061 void
Chris@162 2062 MainWindowBase::peekLeft()
Chris@162 2063 {
Chris@162 2064 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@162 2065 if (currentPane) currentPane->scroll(false, false, false);
Chris@162 2066 }
Chris@162 2067
Chris@162 2068 void
Chris@45 2069 MainWindowBase::scrollRight()
Chris@45 2070 {
Chris@45 2071 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 2072 if (currentPane) currentPane->scroll(true, false);
Chris@45 2073 }
Chris@45 2074
Chris@45 2075 void
Chris@45 2076 MainWindowBase::jumpRight()
Chris@45 2077 {
Chris@45 2078 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 2079 if (currentPane) currentPane->scroll(true, true);
Chris@45 2080 }
Chris@45 2081
Chris@45 2082 void
Chris@162 2083 MainWindowBase::peekRight()
Chris@162 2084 {
Chris@162 2085 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@162 2086 if (currentPane) currentPane->scroll(true, false, false);
Chris@162 2087 }
Chris@162 2088
Chris@162 2089 void
Chris@45 2090 MainWindowBase::showNoOverlays()
Chris@45 2091 {
Chris@45 2092 m_viewManager->setOverlayMode(ViewManager::NoOverlays);
Chris@45 2093 }
Chris@45 2094
Chris@45 2095 void
Chris@45 2096 MainWindowBase::showMinimalOverlays()
Chris@45 2097 {
Chris@45 2098 m_viewManager->setOverlayMode(ViewManager::MinimalOverlays);
Chris@45 2099 }
Chris@45 2100
Chris@45 2101 void
Chris@45 2102 MainWindowBase::showStandardOverlays()
Chris@45 2103 {
Chris@45 2104 m_viewManager->setOverlayMode(ViewManager::StandardOverlays);
Chris@45 2105 }
Chris@45 2106
Chris@45 2107 void
Chris@45 2108 MainWindowBase::showAllOverlays()
Chris@45 2109 {
Chris@45 2110 m_viewManager->setOverlayMode(ViewManager::AllOverlays);
Chris@45 2111 }
Chris@45 2112
Chris@45 2113 void
Chris@211 2114 MainWindowBase::toggleTimeRulers()
Chris@211 2115 {
Chris@211 2116 bool haveRulers = false;
Chris@211 2117 bool someHidden = false;
Chris@211 2118
Chris@211 2119 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@211 2120
Chris@211 2121 Pane *pane = m_paneStack->getPane(i);
Chris@211 2122 if (!pane) continue;
Chris@211 2123
Chris@211 2124 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@211 2125
Chris@211 2126 Layer *layer = pane->getLayer(j);
Chris@211 2127 if (!dynamic_cast<TimeRulerLayer *>(layer)) continue;
Chris@211 2128
Chris@211 2129 haveRulers = true;
Chris@211 2130 if (layer->isLayerDormant(pane)) someHidden = true;
Chris@211 2131 }
Chris@211 2132 }
Chris@211 2133
Chris@211 2134 if (haveRulers) {
Chris@211 2135
Chris@211 2136 bool show = someHidden;
Chris@211 2137
Chris@211 2138 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@211 2139
Chris@211 2140 Pane *pane = m_paneStack->getPane(i);
Chris@211 2141 if (!pane) continue;
Chris@211 2142
Chris@211 2143 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@211 2144
Chris@211 2145 Layer *layer = pane->getLayer(j);
Chris@211 2146 if (!dynamic_cast<TimeRulerLayer *>(layer)) continue;
Chris@211 2147
Chris@211 2148 layer->showLayer(pane, show);
Chris@211 2149 }
Chris@211 2150 }
Chris@211 2151 }
Chris@211 2152 }
Chris@211 2153
Chris@211 2154 void
Chris@45 2155 MainWindowBase::toggleZoomWheels()
Chris@45 2156 {
Chris@45 2157 if (m_viewManager->getZoomWheelsEnabled()) {
Chris@45 2158 m_viewManager->setZoomWheelsEnabled(false);
Chris@45 2159 } else {
Chris@45 2160 m_viewManager->setZoomWheelsEnabled(true);
Chris@45 2161 }
Chris@45 2162 }
Chris@45 2163
Chris@45 2164 void
Chris@45 2165 MainWindowBase::togglePropertyBoxes()
Chris@45 2166 {
Chris@45 2167 if (m_paneStack->getLayoutStyle() == PaneStack::NoPropertyStacks) {
Chris@45 2168 if (Preferences::getInstance()->getPropertyBoxLayout() ==
Chris@45 2169 Preferences::VerticallyStacked) {
Chris@45 2170 m_paneStack->setLayoutStyle(PaneStack::PropertyStackPerPaneLayout);
Chris@45 2171 } else {
Chris@45 2172 m_paneStack->setLayoutStyle(PaneStack::SinglePropertyStackLayout);
Chris@45 2173 }
Chris@45 2174 } else {
Chris@45 2175 m_paneStack->setLayoutStyle(PaneStack::NoPropertyStacks);
Chris@45 2176 }
Chris@45 2177 }
Chris@45 2178
Chris@45 2179 void
Chris@45 2180 MainWindowBase::toggleStatusBar()
Chris@45 2181 {
Chris@45 2182 QSettings settings;
Chris@45 2183 settings.beginGroup("MainWindow");
Chris@45 2184 bool sb = settings.value("showstatusbar", true).toBool();
Chris@45 2185
Chris@45 2186 if (sb) {
Chris@45 2187 statusBar()->hide();
Chris@45 2188 } else {
Chris@45 2189 statusBar()->show();
Chris@45 2190 }
Chris@45 2191
Chris@45 2192 settings.setValue("showstatusbar", !sb);
Chris@45 2193
Chris@45 2194 settings.endGroup();
Chris@45 2195 }
Chris@45 2196
Chris@45 2197 void
Chris@45 2198 MainWindowBase::preferenceChanged(PropertyContainer::PropertyName name)
Chris@45 2199 {
Chris@45 2200 if (name == "Property Box Layout") {
Chris@45 2201 if (m_paneStack->getLayoutStyle() != PaneStack::NoPropertyStacks) {
Chris@45 2202 if (Preferences::getInstance()->getPropertyBoxLayout() ==
Chris@45 2203 Preferences::VerticallyStacked) {
Chris@45 2204 m_paneStack->setLayoutStyle(PaneStack::PropertyStackPerPaneLayout);
Chris@45 2205 } else {
Chris@45 2206 m_paneStack->setLayoutStyle(PaneStack::SinglePropertyStackLayout);
Chris@45 2207 }
Chris@45 2208 }
Chris@45 2209 } else if (name == "Background Mode" && m_viewManager) {
Chris@45 2210 Preferences::BackgroundMode mode =
Chris@45 2211 Preferences::getInstance()->getBackgroundMode();
Chris@45 2212 if (mode == Preferences::BackgroundFromTheme) {
Chris@45 2213 m_viewManager->setGlobalDarkBackground(m_initialDarkBackground);
Chris@45 2214 } else if (mode == Preferences::DarkBackground) {
Chris@45 2215 m_viewManager->setGlobalDarkBackground(true);
Chris@45 2216 } else {
Chris@45 2217 m_viewManager->setGlobalDarkBackground(false);
Chris@45 2218 }
Chris@45 2219 }
Chris@45 2220 }
Chris@45 2221
Chris@45 2222 void
Chris@45 2223 MainWindowBase::play()
Chris@45 2224 {
Chris@45 2225 if (m_playSource->isPlaying()) {
Chris@45 2226 stop();
Chris@45 2227 } else {
Chris@45 2228 playbackFrameChanged(m_viewManager->getPlaybackFrame());
Chris@45 2229 m_playSource->play(m_viewManager->getPlaybackFrame());
Chris@45 2230 }
Chris@45 2231 }
Chris@45 2232
Chris@45 2233 void
Chris@45 2234 MainWindowBase::ffwd()
Chris@45 2235 {
Chris@45 2236 if (!getMainModel()) return;
Chris@45 2237
Chris@45 2238 int frame = m_viewManager->getPlaybackFrame();
Chris@45 2239 ++frame;
Chris@45 2240
Chris@85 2241 Pane *pane = m_paneStack->getCurrentPane();
Chris@45 2242 Layer *layer = getSnapLayer();
Chris@45 2243 size_t sr = getMainModel()->getSampleRate();
Chris@45 2244
Chris@45 2245 if (!layer) {
Chris@45 2246
Chris@45 2247 frame = RealTime::realTime2Frame
Chris@45 2248 (RealTime::frame2RealTime(frame, sr) + RealTime(2, 0), sr);
Chris@45 2249 if (frame > int(getMainModel()->getEndFrame())) {
Chris@45 2250 frame = getMainModel()->getEndFrame();
Chris@45 2251 }
Chris@45 2252
Chris@45 2253 } else {
Chris@45 2254
Chris@45 2255 size_t resolution = 0;
Chris@166 2256 if (pane) frame = pane->alignFromReference(frame);
Chris@85 2257 if (layer->snapToFeatureFrame(m_paneStack->getCurrentPane(),
Chris@85 2258 frame, resolution, Layer::SnapRight)) {
Chris@85 2259 if (pane) frame = pane->alignToReference(frame);
Chris@85 2260 } else {
Chris@45 2261 frame = getMainModel()->getEndFrame();
Chris@45 2262 }
Chris@45 2263 }
Chris@45 2264
Chris@45 2265 if (frame < 0) frame = 0;
Chris@45 2266
Chris@45 2267 if (m_viewManager->getPlaySelectionMode()) {
Chris@45 2268 frame = m_viewManager->constrainFrameToSelection(size_t(frame));
Chris@45 2269 }
Chris@45 2270
Chris@45 2271 m_viewManager->setPlaybackFrame(frame);
Chris@166 2272
Chris@166 2273 if (frame == getMainModel()->getEndFrame() &&
Chris@166 2274 m_playSource &&
Chris@166 2275 m_playSource->isPlaying() &&
Chris@166 2276 !m_viewManager->getPlayLoopMode()) {
Chris@166 2277 stop();
Chris@166 2278 }
Chris@45 2279 }
Chris@45 2280
Chris@45 2281 void
Chris@45 2282 MainWindowBase::ffwdEnd()
Chris@45 2283 {
Chris@45 2284 if (!getMainModel()) return;
Chris@45 2285
Chris@139 2286 if (m_playSource &&
Chris@139 2287 m_playSource->isPlaying() &&
Chris@139 2288 !m_viewManager->getPlayLoopMode()) {
Chris@139 2289 stop();
Chris@139 2290 }
Chris@139 2291
Chris@45 2292 size_t frame = getMainModel()->getEndFrame();
Chris@45 2293
Chris@45 2294 if (m_viewManager->getPlaySelectionMode()) {
Chris@45 2295 frame = m_viewManager->constrainFrameToSelection(frame);
Chris@45 2296 }
Chris@45 2297
Chris@45 2298 m_viewManager->setPlaybackFrame(frame);
Chris@45 2299 }
Chris@45 2300
Chris@45 2301 void
Chris@166 2302 MainWindowBase::ffwdSimilar()
Chris@166 2303 {
Chris@166 2304 if (!getMainModel()) return;
Chris@166 2305
Chris@166 2306 Layer *layer = getSnapLayer();
Chris@166 2307 if (!layer) { ffwd(); return; }
Chris@166 2308
Chris@166 2309 Pane *pane = m_paneStack->getCurrentPane();
Chris@166 2310 size_t sr = getMainModel()->getSampleRate();
Chris@166 2311
Chris@166 2312 int frame = m_viewManager->getPlaybackFrame();
Chris@166 2313
Chris@166 2314 size_t resolution = 0;
Chris@166 2315 if (pane) frame = pane->alignFromReference(frame);
Chris@166 2316 if (layer->snapToSimilarFeature(m_paneStack->getCurrentPane(),
Chris@166 2317 frame, resolution, Layer::SnapRight)) {
Chris@166 2318 if (pane) frame = pane->alignToReference(frame);
Chris@166 2319 } else {
Chris@166 2320 frame = getMainModel()->getEndFrame();
Chris@166 2321 }
Chris@166 2322
Chris@166 2323 if (frame < 0) frame = 0;
Chris@166 2324
Chris@166 2325 if (m_viewManager->getPlaySelectionMode()) {
Chris@166 2326 frame = m_viewManager->constrainFrameToSelection(size_t(frame));
Chris@166 2327 }
Chris@166 2328
Chris@166 2329 m_viewManager->setPlaybackFrame(frame);
Chris@166 2330
Chris@166 2331 if (frame == getMainModel()->getEndFrame() &&
Chris@166 2332 m_playSource &&
Chris@166 2333 m_playSource->isPlaying() &&
Chris@166 2334 !m_viewManager->getPlayLoopMode()) {
Chris@166 2335 stop();
Chris@166 2336 }
Chris@166 2337 }
Chris@166 2338
Chris@166 2339 void
Chris@45 2340 MainWindowBase::rewind()
Chris@45 2341 {
Chris@45 2342 if (!getMainModel()) return;
Chris@45 2343
Chris@45 2344 int frame = m_viewManager->getPlaybackFrame();
Chris@45 2345 if (frame > 0) --frame;
Chris@45 2346
Chris@85 2347 Pane *pane = m_paneStack->getCurrentPane();
Chris@45 2348 Layer *layer = getSnapLayer();
Chris@45 2349 size_t sr = getMainModel()->getSampleRate();
Chris@45 2350
Chris@45 2351 // when rewinding during playback, we want to allow a period
Chris@45 2352 // following a rewind target point at which the rewind will go to
Chris@45 2353 // the prior point instead of the immediately neighbouring one
Chris@45 2354 if (m_playSource && m_playSource->isPlaying()) {
Chris@45 2355 RealTime ct = RealTime::frame2RealTime(frame, sr);
Chris@45 2356 ct = ct - RealTime::fromSeconds(0.25);
Chris@45 2357 if (ct < RealTime::zeroTime) ct = RealTime::zeroTime;
Chris@45 2358 frame = RealTime::realTime2Frame(ct, sr);
Chris@45 2359 }
Chris@45 2360
Chris@45 2361 if (!layer) {
Chris@45 2362
Chris@45 2363 frame = RealTime::realTime2Frame
Chris@45 2364 (RealTime::frame2RealTime(frame, sr) - RealTime(2, 0), sr);
Chris@45 2365 if (frame < int(getMainModel()->getStartFrame())) {
Chris@45 2366 frame = getMainModel()->getStartFrame();
Chris@45 2367 }
Chris@45 2368
Chris@45 2369 } else {
Chris@45 2370
Chris@45 2371 size_t resolution = 0;
Chris@166 2372 if (pane) frame = pane->alignFromReference(frame);
Chris@85 2373 if (layer->snapToFeatureFrame(m_paneStack->getCurrentPane(),
Chris@85 2374 frame, resolution, Layer::SnapLeft)) {
Chris@85 2375 if (pane) frame = pane->alignToReference(frame);
Chris@85 2376 } else {
Chris@45 2377 frame = getMainModel()->getStartFrame();
Chris@45 2378 }
Chris@45 2379 }
Chris@45 2380
Chris@45 2381 if (frame < 0) frame = 0;
Chris@45 2382
Chris@45 2383 if (m_viewManager->getPlaySelectionMode()) {
Chris@45 2384 frame = m_viewManager->constrainFrameToSelection(size_t(frame));
Chris@45 2385 }
Chris@45 2386
Chris@45 2387 m_viewManager->setPlaybackFrame(frame);
Chris@45 2388 }
Chris@45 2389
Chris@45 2390 void
Chris@45 2391 MainWindowBase::rewindStart()
Chris@45 2392 {
Chris@45 2393 if (!getMainModel()) return;
Chris@45 2394
Chris@45 2395 size_t frame = getMainModel()->getStartFrame();
Chris@45 2396
Chris@45 2397 if (m_viewManager->getPlaySelectionMode()) {
Chris@45 2398 frame = m_viewManager->constrainFrameToSelection(frame);
Chris@45 2399 }
Chris@45 2400
Chris@45 2401 m_viewManager->setPlaybackFrame(frame);
Chris@45 2402 }
Chris@45 2403
Chris@166 2404 void
Chris@166 2405 MainWindowBase::rewindSimilar()
Chris@166 2406 {
Chris@166 2407 if (!getMainModel()) return;
Chris@166 2408
Chris@166 2409 Layer *layer = getSnapLayer();
Chris@166 2410 if (!layer) { rewind(); return; }
Chris@166 2411
Chris@166 2412 Pane *pane = m_paneStack->getCurrentPane();
Chris@166 2413 size_t sr = getMainModel()->getSampleRate();
Chris@166 2414
Chris@166 2415 int frame = m_viewManager->getPlaybackFrame();
Chris@166 2416
Chris@166 2417 size_t resolution = 0;
Chris@166 2418 if (pane) frame = pane->alignFromReference(frame);
Chris@166 2419 if (layer->snapToSimilarFeature(m_paneStack->getCurrentPane(),
Chris@166 2420 frame, resolution, Layer::SnapLeft)) {
Chris@166 2421 if (pane) frame = pane->alignToReference(frame);
Chris@166 2422 } else {
Chris@166 2423 frame = getMainModel()->getStartFrame();
Chris@166 2424 }
Chris@166 2425
Chris@166 2426 if (frame < 0) frame = 0;
Chris@166 2427
Chris@166 2428 if (m_viewManager->getPlaySelectionMode()) {
Chris@166 2429 frame = m_viewManager->constrainFrameToSelection(size_t(frame));
Chris@166 2430 }
Chris@166 2431
Chris@166 2432 m_viewManager->setPlaybackFrame(frame);
Chris@166 2433 }
Chris@166 2434
Chris@45 2435 Layer *
Chris@45 2436 MainWindowBase::getSnapLayer() const
Chris@45 2437 {
Chris@45 2438 Pane *pane = m_paneStack->getCurrentPane();
Chris@45 2439 if (!pane) return 0;
Chris@45 2440
Chris@45 2441 Layer *layer = pane->getSelectedLayer();
Chris@45 2442
Chris@45 2443 if (!dynamic_cast<TimeInstantLayer *>(layer) &&
Chris@45 2444 !dynamic_cast<TimeValueLayer *>(layer) &&
Chris@194 2445 !dynamic_cast<RegionLayer *>(layer) &&
Chris@45 2446 !dynamic_cast<TimeRulerLayer *>(layer)) {
Chris@45 2447
Chris@45 2448 layer = 0;
Chris@45 2449
Chris@45 2450 for (int i = pane->getLayerCount(); i > 0; --i) {
Chris@45 2451 Layer *l = pane->getLayer(i-1);
Chris@45 2452 if (dynamic_cast<TimeRulerLayer *>(l)) {
Chris@45 2453 layer = l;
Chris@45 2454 break;
Chris@45 2455 }
Chris@45 2456 }
Chris@45 2457 }
Chris@45 2458
Chris@45 2459 return layer;
Chris@45 2460 }
Chris@45 2461
Chris@45 2462 void
Chris@45 2463 MainWindowBase::stop()
Chris@45 2464 {
Chris@45 2465 m_playSource->stop();
Chris@45 2466
Chris@45 2467 if (m_paneStack && m_paneStack->getCurrentPane()) {
Chris@45 2468 updateVisibleRangeDisplay(m_paneStack->getCurrentPane());
Chris@45 2469 } else {
Chris@45 2470 m_myStatusMessage = "";
Chris@45 2471 statusBar()->showMessage("");
Chris@45 2472 }
Chris@45 2473 }
Chris@45 2474
Chris@45 2475 MainWindowBase::AddPaneCommand::AddPaneCommand(MainWindowBase *mw) :
Chris@45 2476 m_mw(mw),
Chris@45 2477 m_pane(0),
Chris@45 2478 m_prevCurrentPane(0),
Chris@45 2479 m_added(false)
Chris@45 2480 {
Chris@45 2481 }
Chris@45 2482
Chris@45 2483 MainWindowBase::AddPaneCommand::~AddPaneCommand()
Chris@45 2484 {
Chris@45 2485 if (m_pane && !m_added) {
Chris@45 2486 m_mw->m_paneStack->deletePane(m_pane);
Chris@45 2487 }
Chris@45 2488 }
Chris@45 2489
Chris@45 2490 QString
Chris@45 2491 MainWindowBase::AddPaneCommand::getName() const
Chris@45 2492 {
Chris@45 2493 return tr("Add Pane");
Chris@45 2494 }
Chris@45 2495
Chris@45 2496 void
Chris@45 2497 MainWindowBase::AddPaneCommand::execute()
Chris@45 2498 {
Chris@45 2499 if (!m_pane) {
Chris@45 2500 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
Chris@45 2501 m_pane = m_mw->m_paneStack->addPane();
Chris@45 2502
Chris@45 2503 connect(m_pane, SIGNAL(contextHelpChanged(const QString &)),
Chris@45 2504 m_mw, SLOT(contextHelpChanged(const QString &)));
Chris@45 2505 } else {
Chris@45 2506 m_mw->m_paneStack->showPane(m_pane);
Chris@45 2507 }
Chris@45 2508
Chris@45 2509 m_mw->m_paneStack->setCurrentPane(m_pane);
Chris@45 2510 m_added = true;
Chris@45 2511 }
Chris@45 2512
Chris@45 2513 void
Chris@45 2514 MainWindowBase::AddPaneCommand::unexecute()
Chris@45 2515 {
Chris@45 2516 m_mw->m_paneStack->hidePane(m_pane);
Chris@45 2517 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
Chris@45 2518 m_added = false;
Chris@45 2519 }
Chris@45 2520
Chris@45 2521 MainWindowBase::RemovePaneCommand::RemovePaneCommand(MainWindowBase *mw, Pane *pane) :
Chris@45 2522 m_mw(mw),
Chris@45 2523 m_pane(pane),
Chris@45 2524 m_added(true)
Chris@45 2525 {
Chris@45 2526 }
Chris@45 2527
Chris@45 2528 MainWindowBase::RemovePaneCommand::~RemovePaneCommand()
Chris@45 2529 {
Chris@45 2530 if (m_pane && !m_added) {
Chris@45 2531 m_mw->m_paneStack->deletePane(m_pane);
Chris@45 2532 }
Chris@45 2533 }
Chris@45 2534
Chris@45 2535 QString
Chris@45 2536 MainWindowBase::RemovePaneCommand::getName() const
Chris@45 2537 {
Chris@45 2538 return tr("Remove Pane");
Chris@45 2539 }
Chris@45 2540
Chris@45 2541 void
Chris@45 2542 MainWindowBase::RemovePaneCommand::execute()
Chris@45 2543 {
Chris@45 2544 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
Chris@45 2545 m_mw->m_paneStack->hidePane(m_pane);
Chris@45 2546 m_added = false;
Chris@45 2547 }
Chris@45 2548
Chris@45 2549 void
Chris@45 2550 MainWindowBase::RemovePaneCommand::unexecute()
Chris@45 2551 {
Chris@45 2552 m_mw->m_paneStack->showPane(m_pane);
Chris@45 2553 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
Chris@45 2554 m_added = true;
Chris@45 2555 }
Chris@45 2556
Chris@45 2557 void
Chris@45 2558 MainWindowBase::deleteCurrentPane()
Chris@45 2559 {
Chris@45 2560 CommandHistory::getInstance()->startCompoundOperation
Chris@45 2561 (tr("Delete Pane"), true);
Chris@45 2562
Chris@45 2563 Pane *pane = m_paneStack->getCurrentPane();
Chris@45 2564 if (pane) {
Chris@45 2565 while (pane->getLayerCount() > 0) {
Chris@45 2566 Layer *layer = pane->getLayer(0);
Chris@45 2567 if (layer) {
Chris@45 2568 m_document->removeLayerFromView(pane, layer);
Chris@45 2569 } else {
Chris@45 2570 break;
Chris@45 2571 }
Chris@45 2572 }
Chris@45 2573
Chris@45 2574 RemovePaneCommand *command = new RemovePaneCommand(this, pane);
Chris@45 2575 CommandHistory::getInstance()->addCommand(command);
Chris@45 2576 }
Chris@45 2577
Chris@45 2578 CommandHistory::getInstance()->endCompoundOperation();
Chris@45 2579
Chris@45 2580 updateMenuStates();
Chris@45 2581 }
Chris@45 2582
Chris@45 2583 void
Chris@45 2584 MainWindowBase::deleteCurrentLayer()
Chris@45 2585 {
Chris@45 2586 Pane *pane = m_paneStack->getCurrentPane();
Chris@45 2587 if (pane) {
Chris@45 2588 Layer *layer = pane->getSelectedLayer();
Chris@45 2589 if (layer) {
Chris@45 2590 m_document->removeLayerFromView(pane, layer);
Chris@45 2591 }
Chris@45 2592 }
Chris@45 2593 updateMenuStates();
Chris@45 2594 }
Chris@45 2595
Chris@45 2596 void
Chris@123 2597 MainWindowBase::editCurrentLayer()
Chris@123 2598 {
Chris@123 2599 Layer *layer = 0;
Chris@123 2600 Pane *pane = m_paneStack->getCurrentPane();
Chris@123 2601 if (pane) layer = pane->getSelectedLayer();
Chris@123 2602 if (!layer) return;
Chris@123 2603
Chris@123 2604 Model *model = layer->getModel();
Chris@123 2605 if (!model) return;
Chris@123 2606
Chris@124 2607 TabularModel *tabular = dynamic_cast<TabularModel *>(model);
Chris@124 2608 if (!tabular) {
Chris@124 2609 //!!! how to prevent this function from being active if not
Chris@124 2610 //appropriate model type? or will we ultimately support
Chris@124 2611 //tabular display for all editable models?
Chris@124 2612 std::cerr << "NOTE: Not a tabular model" << std::endl;
Chris@124 2613 return;
Chris@124 2614 }
Chris@124 2615
Chris@123 2616 if (m_layerDataDialogMap.find(layer) != m_layerDataDialogMap.end()) {
Chris@126 2617 if (!m_layerDataDialogMap[layer].isNull()) {
Chris@126 2618 m_layerDataDialogMap[layer]->show();
Chris@126 2619 m_layerDataDialogMap[layer]->raise();
Chris@126 2620 return;
Chris@126 2621 }
Chris@123 2622 }
Chris@123 2623
Chris@125 2624 QString title = layer->getLayerPresentationName();
Chris@125 2625
Chris@125 2626 ModelDataTableDialog *dialog = new ModelDataTableDialog(tabular, title, this);
Chris@128 2627 dialog->setAttribute(Qt::WA_DeleteOnClose);
Chris@128 2628
Chris@128 2629 connectLayerEditDialog(dialog);
Chris@123 2630
Chris@128 2631 m_layerDataDialogMap[layer] = dialog;
Chris@128 2632 m_viewDataDialogMap[pane].insert(dialog);
Chris@128 2633
Chris@128 2634 dialog->show();
Chris@128 2635 }
Chris@128 2636
Chris@128 2637 void
Chris@128 2638 MainWindowBase::connectLayerEditDialog(ModelDataTableDialog *dialog)
Chris@128 2639 {
Chris@123 2640 connect(m_viewManager,
Chris@123 2641 SIGNAL(globalCentreFrameChanged(unsigned long)),
Chris@123 2642 dialog,
Chris@127 2643 SLOT(userScrolledToFrame(unsigned long)));
Chris@127 2644
Chris@127 2645 connect(m_viewManager,
Chris@127 2646 SIGNAL(playbackFrameChanged(unsigned long)),
Chris@127 2647 dialog,
Chris@127 2648 SLOT(playbackScrolledToFrame(unsigned long)));
Chris@127 2649
Chris@123 2650 connect(dialog,
Chris@123 2651 SIGNAL(scrollToFrame(unsigned long)),
Chris@123 2652 m_viewManager,
Chris@123 2653 SLOT(setGlobalCentreFrame(unsigned long)));
Chris@129 2654
Chris@129 2655 connect(dialog,
Chris@129 2656 SIGNAL(scrollToFrame(unsigned long)),
Chris@129 2657 m_viewManager,
Chris@129 2658 SLOT(setPlaybackFrame(unsigned long)));
Chris@128 2659 }
Chris@123 2660
Chris@123 2661 void
Chris@73 2662 MainWindowBase::previousPane()
Chris@73 2663 {
Chris@73 2664 if (!m_paneStack) return;
Chris@73 2665
Chris@73 2666 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@73 2667 if (!currentPane) return;
Chris@73 2668
Chris@73 2669 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@73 2670 if (m_paneStack->getPane(i) == currentPane) {
Chris@73 2671 if (i == 0) return;
Chris@73 2672 m_paneStack->setCurrentPane(m_paneStack->getPane(i-1));
Chris@73 2673 updateMenuStates();
Chris@73 2674 return;
Chris@73 2675 }
Chris@73 2676 }
Chris@73 2677 }
Chris@73 2678
Chris@73 2679 void
Chris@73 2680 MainWindowBase::nextPane()
Chris@73 2681 {
Chris@73 2682 if (!m_paneStack) return;
Chris@73 2683
Chris@73 2684 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@73 2685 if (!currentPane) return;
Chris@73 2686
Chris@73 2687 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@73 2688 if (m_paneStack->getPane(i) == currentPane) {
Chris@73 2689 if (i == m_paneStack->getPaneCount()-1) return;
Chris@73 2690 m_paneStack->setCurrentPane(m_paneStack->getPane(i+1));
Chris@73 2691 updateMenuStates();
Chris@73 2692 return;
Chris@73 2693 }
Chris@73 2694 }
Chris@73 2695 }
Chris@73 2696
Chris@73 2697 void
Chris@73 2698 MainWindowBase::previousLayer()
Chris@73 2699 {
Chris@73 2700 //!!! Not right -- pane lists layers in stacking order
Chris@73 2701
Chris@73 2702 if (!m_paneStack) return;
Chris@73 2703
Chris@73 2704 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@73 2705 if (!currentPane) return;
Chris@73 2706
Chris@73 2707 Layer *currentLayer = currentPane->getSelectedLayer();
Chris@73 2708 if (!currentLayer) return;
Chris@73 2709
Chris@73 2710 for (int i = 0; i < currentPane->getLayerCount(); ++i) {
Chris@73 2711 if (currentPane->getLayer(i) == currentLayer) {
Chris@73 2712 if (i == 0) return;
Chris@73 2713 m_paneStack->setCurrentLayer(currentPane,
Chris@73 2714 currentPane->getLayer(i-1));
Chris@73 2715 updateMenuStates();
Chris@73 2716 return;
Chris@73 2717 }
Chris@73 2718 }
Chris@73 2719 }
Chris@73 2720
Chris@73 2721 void
Chris@73 2722 MainWindowBase::nextLayer()
Chris@73 2723 {
Chris@73 2724 //!!! Not right -- pane lists layers in stacking order
Chris@73 2725
Chris@73 2726 if (!m_paneStack) return;
Chris@73 2727
Chris@73 2728 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@73 2729 if (!currentPane) return;
Chris@73 2730
Chris@73 2731 Layer *currentLayer = currentPane->getSelectedLayer();
Chris@73 2732 if (!currentLayer) return;
Chris@73 2733
Chris@73 2734 for (int i = 0; i < currentPane->getLayerCount(); ++i) {
Chris@73 2735 if (currentPane->getLayer(i) == currentLayer) {
Chris@73 2736 if (i == currentPane->getLayerCount()-1) return;
Chris@73 2737 m_paneStack->setCurrentLayer(currentPane,
Chris@73 2738 currentPane->getLayer(i+1));
Chris@73 2739 updateMenuStates();
Chris@73 2740 return;
Chris@73 2741 }
Chris@73 2742 }
Chris@73 2743 }
Chris@73 2744
Chris@73 2745 void
Chris@45 2746 MainWindowBase::playbackFrameChanged(unsigned long frame)
Chris@45 2747 {
Chris@45 2748 if (!(m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
Chris@45 2749
Chris@187 2750 updatePositionStatusDisplays();
Chris@187 2751
Chris@45 2752 RealTime now = RealTime::frame2RealTime
Chris@45 2753 (frame, getMainModel()->getSampleRate());
Chris@45 2754
Chris@45 2755 if (now.sec == m_lastPlayStatusSec) return;
Chris@45 2756
Chris@45 2757 RealTime then = RealTime::frame2RealTime
Chris@45 2758 (m_playSource->getPlayEndFrame(), getMainModel()->getSampleRate());
Chris@45 2759
Chris@45 2760 QString nowStr;
Chris@45 2761 QString thenStr;
Chris@45 2762 QString remainingStr;
Chris@45 2763
Chris@45 2764 if (then.sec > 10) {
Chris@45 2765 nowStr = now.toSecText().c_str();
Chris@45 2766 thenStr = then.toSecText().c_str();
Chris@45 2767 remainingStr = (then - now).toSecText().c_str();
Chris@45 2768 m_lastPlayStatusSec = now.sec;
Chris@45 2769 } else {
Chris@45 2770 nowStr = now.toText(true).c_str();
Chris@45 2771 thenStr = then.toText(true).c_str();
Chris@45 2772 remainingStr = (then - now).toText(true).c_str();
Chris@45 2773 }
Chris@45 2774
Chris@45 2775 m_myStatusMessage = tr("Playing: %1 of %2 (%3 remaining)")
Chris@45 2776 .arg(nowStr).arg(thenStr).arg(remainingStr);
Chris@45 2777
Chris@45 2778 statusBar()->showMessage(m_myStatusMessage);
Chris@45 2779 }
Chris@45 2780
Chris@45 2781 void
Chris@45 2782 MainWindowBase::globalCentreFrameChanged(unsigned long )
Chris@45 2783 {
Chris@45 2784 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
Chris@45 2785 Pane *p = 0;
Chris@45 2786 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
Chris@45 2787 if (!p->getFollowGlobalPan()) return;
Chris@45 2788 updateVisibleRangeDisplay(p);
Chris@45 2789 }
Chris@45 2790
Chris@45 2791 void
Chris@123 2792 MainWindowBase::viewCentreFrameChanged(View *v, unsigned long frame)
Chris@45 2793 {
Chris@130 2794 // std::cerr << "MainWindowBase::viewCentreFrameChanged(" << v << "," << frame << ")" << std::endl;
Chris@123 2795
Chris@123 2796 if (m_viewDataDialogMap.find(v) != m_viewDataDialogMap.end()) {
Chris@123 2797 for (DataDialogSet::iterator i = m_viewDataDialogMap[v].begin();
Chris@123 2798 i != m_viewDataDialogMap[v].end(); ++i) {
Chris@127 2799 (*i)->userScrolledToFrame(frame);
Chris@123 2800 }
Chris@123 2801 }
Chris@45 2802 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
Chris@45 2803 Pane *p = 0;
Chris@45 2804 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
Chris@45 2805 if (v == p) updateVisibleRangeDisplay(p);
Chris@45 2806 }
Chris@45 2807
Chris@45 2808 void
Chris@45 2809 MainWindowBase::viewZoomLevelChanged(View *v, unsigned long , bool )
Chris@45 2810 {
Chris@45 2811 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
Chris@45 2812 Pane *p = 0;
Chris@45 2813 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
Chris@45 2814 if (v == p) updateVisibleRangeDisplay(p);
Chris@45 2815 }
Chris@45 2816
Chris@45 2817 void
Chris@45 2818 MainWindowBase::layerAdded(Layer *)
Chris@45 2819 {
Chris@45 2820 // std::cerr << "MainWindowBase::layerAdded(" << layer << ")" << std::endl;
Chris@45 2821 updateMenuStates();
Chris@45 2822 }
Chris@45 2823
Chris@45 2824 void
Chris@45 2825 MainWindowBase::layerRemoved(Layer *)
Chris@45 2826 {
Chris@45 2827 // std::cerr << "MainWindowBase::layerRemoved(" << layer << ")" << std::endl;
Chris@45 2828 updateMenuStates();
Chris@45 2829 }
Chris@45 2830
Chris@45 2831 void
Chris@45 2832 MainWindowBase::layerAboutToBeDeleted(Layer *layer)
Chris@45 2833 {
Chris@132 2834 // std::cerr << "MainWindowBase::layerAboutToBeDeleted(" << layer << ")" << std::endl;
Chris@123 2835
Chris@128 2836 removeLayerEditDialog(layer);
Chris@123 2837
Chris@47 2838 if (m_timeRulerLayer && (layer == m_timeRulerLayer)) {
Chris@45 2839 // std::cerr << "(this is the time ruler layer)" << std::endl;
Chris@45 2840 m_timeRulerLayer = 0;
Chris@45 2841 }
Chris@45 2842 }
Chris@45 2843
Chris@45 2844 void
Chris@45 2845 MainWindowBase::layerInAView(Layer *layer, bool inAView)
Chris@45 2846 {
Chris@132 2847 // std::cerr << "MainWindowBase::layerInAView(" << layer << "," << inAView << ")" << std::endl;
Chris@128 2848
Chris@128 2849 if (!inAView) removeLayerEditDialog(layer);
Chris@45 2850
Chris@45 2851 // Check whether we need to add or remove model from play source
Chris@45 2852 Model *model = layer->getModel();
Chris@45 2853 if (model) {
Chris@45 2854 if (inAView) {
Chris@45 2855 m_playSource->addModel(model);
Chris@45 2856 } else {
Chris@45 2857 bool found = false;
Chris@45 2858 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@45 2859 Pane *pane = m_paneStack->getPane(i);
Chris@45 2860 if (!pane) continue;
Chris@45 2861 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@45 2862 Layer *pl = pane->getLayer(j);
Chris@183 2863 if (pl &&
Chris@183 2864 !dynamic_cast<TimeRulerLayer *>(pl) &&
Chris@183 2865 (pl->getModel() == model)) {
Chris@45 2866 found = true;
Chris@45 2867 break;
Chris@45 2868 }
Chris@45 2869 }
Chris@45 2870 if (found) break;
Chris@45 2871 }
Chris@173 2872 if (!found) {
Chris@173 2873 m_playSource->removeModel(model);
Chris@173 2874 }
Chris@45 2875 }
Chris@45 2876 }
Chris@45 2877
Chris@45 2878 updateMenuStates();
Chris@45 2879 }
Chris@45 2880
Chris@45 2881 void
Chris@128 2882 MainWindowBase::removeLayerEditDialog(Layer *layer)
Chris@128 2883 {
Chris@128 2884 if (m_layerDataDialogMap.find(layer) != m_layerDataDialogMap.end()) {
Chris@128 2885
Chris@128 2886 ModelDataTableDialog *dialog = m_layerDataDialogMap[layer];
Chris@128 2887
Chris@128 2888 for (ViewDataDialogMap::iterator vi = m_viewDataDialogMap.begin();
Chris@128 2889 vi != m_viewDataDialogMap.end(); ++vi) {
Chris@128 2890 vi->second.erase(dialog);
Chris@128 2891 }
Chris@128 2892
Chris@128 2893 m_layerDataDialogMap.erase(layer);
Chris@128 2894 delete dialog;
Chris@128 2895 }
Chris@128 2896 }
Chris@128 2897
Chris@128 2898 void
Chris@45 2899 MainWindowBase::modelAdded(Model *model)
Chris@45 2900 {
Chris@45 2901 // std::cerr << "MainWindowBase::modelAdded(" << model << ")" << std::endl;
Chris@45 2902 m_playSource->addModel(model);
Chris@45 2903 }
Chris@45 2904
Chris@45 2905 void
Chris@45 2906 MainWindowBase::mainModelChanged(WaveFileModel *model)
Chris@45 2907 {
Chris@45 2908 // std::cerr << "MainWindowBase::mainModelChanged(" << model << ")" << std::endl;
Chris@45 2909 updateDescriptionLabel();
Chris@45 2910 if (model) m_viewManager->setMainModelSampleRate(model->getSampleRate());
Chris@45 2911 if (model && !m_playTarget && m_audioOutput) createPlayTarget();
Chris@45 2912 }
Chris@45 2913
Chris@45 2914 void
Chris@45 2915 MainWindowBase::modelAboutToBeDeleted(Model *model)
Chris@45 2916 {
Chris@45 2917 // std::cerr << "MainWindowBase::modelAboutToBeDeleted(" << model << ")" << std::endl;
Chris@45 2918 if (model == m_viewManager->getPlaybackModel()) {
Chris@45 2919 m_viewManager->setPlaybackModel(0);
Chris@45 2920 }
Chris@45 2921 m_playSource->removeModel(model);
Chris@45 2922 FFTDataServer::modelAboutToBeDeleted(model);
Chris@45 2923 }
Chris@45 2924
Chris@45 2925 void
Chris@55 2926 MainWindowBase::paneDeleteButtonClicked(Pane *pane)
Chris@55 2927 {
Chris@55 2928 bool found = false;
Chris@55 2929 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@55 2930 if (m_paneStack->getPane(i) == pane) {
Chris@55 2931 found = true;
Chris@55 2932 break;
Chris@55 2933 }
Chris@55 2934 }
Chris@55 2935 if (!found) {
Chris@55 2936 std::cerr << "MainWindowBase::paneDeleteButtonClicked: Unknown pane "
Chris@55 2937 << pane << std::endl;
Chris@55 2938 return;
Chris@55 2939 }
Chris@55 2940
Chris@55 2941 CommandHistory::getInstance()->startCompoundOperation
Chris@55 2942 (tr("Delete Pane"), true);
Chris@55 2943
Chris@55 2944 while (pane->getLayerCount() > 0) {
Chris@55 2945 Layer *layer = pane->getLayer(0);
Chris@55 2946 if (layer) {
Chris@55 2947 m_document->removeLayerFromView(pane, layer);
Chris@55 2948 } else {
Chris@55 2949 break;
Chris@55 2950 }
Chris@55 2951 }
Chris@55 2952
Chris@55 2953 RemovePaneCommand *command = new RemovePaneCommand(this, pane);
Chris@55 2954 CommandHistory::getInstance()->addCommand(command);
Chris@55 2955
Chris@55 2956 CommandHistory::getInstance()->endCompoundOperation();
Chris@55 2957
Chris@55 2958 updateMenuStates();
Chris@55 2959 }
Chris@55 2960
Chris@55 2961 void
Chris@45 2962 MainWindowBase::pollOSC()
Chris@45 2963 {
Chris@45 2964 if (!m_oscQueue || m_oscQueue->isEmpty()) return;
Chris@45 2965 std::cerr << "MainWindowBase::pollOSC: have " << m_oscQueue->getMessagesAvailable() << " messages" << std::endl;
Chris@45 2966
Chris@45 2967 if (m_openingAudioFile) return;
Chris@45 2968
Chris@45 2969 OSCMessage message = m_oscQueue->readMessage();
Chris@45 2970
Chris@45 2971 if (message.getTarget() != 0) {
Chris@45 2972 return; //!!! for now -- this class is target 0, others not handled yet
Chris@45 2973 }
Chris@45 2974
Chris@45 2975 handleOSCMessage(message);
Chris@45 2976 }
Chris@45 2977
Chris@45 2978 void
Chris@45 2979 MainWindowBase::inProgressSelectionChanged()
Chris@45 2980 {
Chris@45 2981 Pane *currentPane = 0;
Chris@45 2982 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
Chris@45 2983 if (currentPane) updateVisibleRangeDisplay(currentPane);
Chris@45 2984 }
Chris@45 2985
Chris@45 2986 void
Chris@45 2987 MainWindowBase::contextHelpChanged(const QString &s)
Chris@45 2988 {
Chris@45 2989 if (s == "" && m_myStatusMessage != "") {
Chris@45 2990 statusBar()->showMessage(m_myStatusMessage);
Chris@45 2991 return;
Chris@45 2992 }
Chris@45 2993 statusBar()->showMessage(s);
Chris@45 2994 }
Chris@45 2995
Chris@45 2996 void
Chris@45 2997 MainWindowBase::openHelpUrl(QString url)
Chris@45 2998 {
Chris@45 2999 // This method mostly lifted from Qt Assistant source code
Chris@45 3000
Chris@45 3001 QProcess *process = new QProcess(this);
Chris@45 3002 connect(process, SIGNAL(finished(int)), process, SLOT(deleteLater()));
Chris@45 3003
Chris@45 3004 QStringList args;
Chris@45 3005
Chris@45 3006 #ifdef Q_OS_MAC
Chris@45 3007 args.append(url);
Chris@45 3008 process->start("open", args);
Chris@45 3009 #else
Chris@45 3010 #ifdef Q_OS_WIN32
Chris@45 3011
Chris@45 3012 QString pf(getenv("ProgramFiles"));
Chris@45 3013 QString command = pf + QString("\\Internet Explorer\\IEXPLORE.EXE");
Chris@45 3014
Chris@45 3015 args.append(url);
Chris@45 3016 process->start(command, args);
Chris@45 3017
Chris@45 3018 #else
Chris@45 3019 #ifdef Q_WS_X11
Chris@45 3020 if (!qgetenv("KDE_FULL_SESSION").isEmpty()) {
Chris@45 3021 args.append("exec");
Chris@45 3022 args.append(url);
Chris@45 3023 process->start("kfmclient", args);
Chris@45 3024 } else if (!qgetenv("BROWSER").isEmpty()) {
Chris@45 3025 args.append(url);
Chris@45 3026 process->start(qgetenv("BROWSER"), args);
Chris@45 3027 } else {
Chris@45 3028 args.append(url);
Chris@45 3029 process->start("firefox", args);
Chris@45 3030 }
Chris@45 3031 #endif
Chris@45 3032 #endif
Chris@45 3033 #endif
Chris@45 3034 }
Chris@45 3035
Chris@180 3036