annotate framework/MainWindowBase.cpp @ 220:0b1886cee2cf templating

Merge from default branch
author Chris Cannam
date Wed, 27 Apr 2011 11:33:48 +0100
parents 85e59c901de9
children e06a0124c662
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@215 693 offset = long(pos) - firstEventFrame;
Chris@215 694 } else if (firstEventFrame < pos) {
Chris@215 695 offset = pos - firstEventFrame;
Chris@215 696 } else {
Chris@215 697 offset = -(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@147 1106 bool prevSetAsMain = settings.value("newsessionforaudio", true).toBool();
Chris@147 1107 settings.endGroup();
Chris@45 1108 bool setAsMain = true;
Chris@45 1109
Chris@45 1110 QStringList items;
Chris@45 1111 items << tr("Replace the existing main waveform")
Chris@45 1112 << tr("Load this file into a new waveform pane");
Chris@45 1113
Chris@45 1114 bool ok = false;
Chris@45 1115 QString item = ListInputDialog::getItem
Chris@45 1116 (this, tr("Select target for import"),
Chris@155 1117 tr("<b>Select a target for import</b><p>You already have an audio waveform loaded.<br>What would you like to do with the new audio file?"),
Chris@45 1118 items, prevSetAsMain ? 0 : 1, &ok);
Chris@45 1119
Chris@45 1120 if (!ok || item.isEmpty()) {
Chris@45 1121 delete newModel;
Chris@45 1122 m_openingAudioFile = false;
Chris@45 1123 return FileOpenCancelled;
Chris@45 1124 }
Chris@45 1125
Chris@45 1126 setAsMain = (item == items[0]);
Chris@147 1127 settings.beginGroup("MainWindow");
Chris@147 1128 settings.setValue("newsessionforaudio", setAsMain);
Chris@147 1129 settings.endGroup();
Chris@45 1130
Chris@45 1131 if (setAsMain) mode = ReplaceMainModel;
Chris@45 1132 else mode = CreateAdditionalModel;
Chris@45 1133
Chris@45 1134 } else {
Chris@45 1135 mode = ReplaceMainModel;
Chris@45 1136 }
Chris@45 1137 }
Chris@45 1138
Chris@45 1139 if (mode == ReplaceCurrentPane) {
Chris@45 1140
Chris@45 1141 Pane *pane = m_paneStack->getCurrentPane();
Chris@45 1142 if (pane) {
Chris@45 1143 if (getMainModel()) {
Chris@45 1144 View::ModelSet models(pane->getModels());
Chris@45 1145 if (models.find(getMainModel()) != models.end()) {
Chris@45 1146 mode = ReplaceMainModel;
Chris@45 1147 }
Chris@45 1148 } else {
Chris@45 1149 mode = ReplaceMainModel;
Chris@45 1150 }
Chris@45 1151 } else {
Chris@45 1152 mode = CreateAdditionalModel;
Chris@45 1153 }
Chris@45 1154 }
Chris@45 1155
Chris@45 1156 if (mode == CreateAdditionalModel && !getMainModel()) {
Chris@45 1157 mode = ReplaceMainModel;
Chris@45 1158 }
Chris@45 1159
dan@210 1160 bool loadedTemplate = false;
dan@210 1161 if ((mode == ReplaceMainModel) && (templateName.length() != 0)) {
dan@210 1162 QString tplPath = "file::templates/" + templateName + ".xml";
dan@210 1163 std::cerr << "SV looking for template " << tplPath.toStdString() << std::endl;
dan@210 1164 FileOpenStatus tplStatus = openSessionFile(tplPath);
dan@210 1165 if(tplStatus != FileOpenFailed) {
dan@210 1166 loadedTemplate = true;
dan@210 1167 mode = ReplaceMainModel;
dan@210 1168 }
dan@210 1169 }
dan@210 1170
Chris@164 1171 emit activity(tr("Import audio file \"%1\"").arg(source.getLocation()));
Chris@164 1172
Chris@45 1173 if (mode == ReplaceMainModel) {
Chris@45 1174
Chris@45 1175 Model *prevMain = getMainModel();
Chris@45 1176 if (prevMain) {
Chris@45 1177 m_playSource->removeModel(prevMain);
Chris@108 1178 PlayParameterRepository::getInstance()->removePlayable(prevMain);
Chris@45 1179 }
Chris@108 1180 PlayParameterRepository::getInstance()->addPlayable(newModel);
Chris@45 1181
Chris@45 1182 m_document->setMainModel(newModel);
Chris@45 1183
Chris@45 1184 setupMenus();
Chris@45 1185
dan@210 1186 if (loadedTemplate || (m_sessionFile == "")) {
Chris@45 1187 //!!! shouldn't be dealing directly with title from here -- call a method
Chris@57 1188 setWindowTitle(tr("%1: %2")
Chris@57 1189 .arg(QApplication::applicationName())
Chris@45 1190 .arg(source.getLocation()));
Chris@45 1191 CommandHistory::getInstance()->clear();
Chris@45 1192 CommandHistory::getInstance()->documentSaved();
Chris@45 1193 m_documentModified = false;
Chris@45 1194 } else {
Chris@57 1195 setWindowTitle(tr("%1: %2 [%3]")
Chris@57 1196 .arg(QApplication::applicationName())
Chris@45 1197 .arg(QFileInfo(m_sessionFile).fileName())
Chris@45 1198 .arg(source.getLocation()));
Chris@45 1199 if (m_documentModified) {
Chris@45 1200 m_documentModified = false;
Chris@45 1201 documentModified(); // so as to restore "(modified)" window title
Chris@45 1202 }
Chris@45 1203 }
Chris@45 1204
Chris@45 1205 if (!source.isRemote()) m_audioFile = source.getLocalFilename();
Chris@45 1206
Chris@45 1207 } else if (mode == CreateAdditionalModel) {
Chris@45 1208
Chris@45 1209 CommandHistory::getInstance()->startCompoundOperation
Chris@219 1210 (tr("Import \"%1\"").arg(source.getBasename()), true);
Chris@45 1211
Chris@45 1212 m_document->addImportedModel(newModel);
Chris@45 1213
Chris@45 1214 AddPaneCommand *command = new AddPaneCommand(this);
Chris@45 1215 CommandHistory::getInstance()->addCommand(command);
Chris@45 1216
Chris@45 1217 Pane *pane = command->getPane();
Chris@45 1218
Chris@47 1219 if (m_timeRulerLayer) {
Chris@47 1220 m_document->addLayerToView(pane, m_timeRulerLayer);
Chris@47 1221 }
Chris@45 1222
Chris@45 1223 Layer *newLayer = m_document->createImportedLayer(newModel);
Chris@45 1224
Chris@45 1225 if (newLayer) {
Chris@45 1226 m_document->addLayerToView(pane, newLayer);
Chris@45 1227 }
Chris@45 1228
Chris@45 1229 CommandHistory::getInstance()->endCompoundOperation();
Chris@45 1230
Chris@45 1231 } else if (mode == ReplaceCurrentPane) {
Chris@45 1232
Chris@45 1233 // We know there is a current pane, otherwise we would have
Chris@45 1234 // reset the mode to CreateAdditionalModel above; and we know
Chris@45 1235 // the current pane does not contain the main model, otherwise
Chris@45 1236 // we would have reset it to ReplaceMainModel. But we don't
Chris@45 1237 // know whether the pane contains a waveform model at all.
Chris@45 1238
Chris@45 1239 Pane *pane = m_paneStack->getCurrentPane();
Chris@45 1240 Layer *replace = 0;
Chris@45 1241
Chris@45 1242 for (int i = 0; i < pane->getLayerCount(); ++i) {
Chris@45 1243 Layer *layer = pane->getLayer(i);
Chris@45 1244 if (dynamic_cast<WaveformLayer *>(layer)) {
Chris@45 1245 replace = layer;
Chris@45 1246 break;
Chris@45 1247 }
Chris@45 1248 }
Chris@45 1249
Chris@45 1250 CommandHistory::getInstance()->startCompoundOperation
Chris@219 1251 (tr("Import \"%1\"").arg(source.getBasename()), true);
Chris@45 1252
Chris@45 1253 m_document->addImportedModel(newModel);
Chris@45 1254
Chris@45 1255 if (replace) {
Chris@45 1256 m_document->removeLayerFromView(pane, replace);
Chris@45 1257 }
Chris@45 1258
Chris@45 1259 Layer *newLayer = m_document->createImportedLayer(newModel);
Chris@45 1260
Chris@45 1261 if (newLayer) {
Chris@45 1262 m_document->addLayerToView(pane, newLayer);
Chris@45 1263 }
Chris@45 1264
Chris@45 1265 CommandHistory::getInstance()->endCompoundOperation();
Chris@45 1266 }
Chris@45 1267
Chris@45 1268 updateMenuStates();
Chris@45 1269 m_recentFiles.addFile(source.getLocation());
Chris@45 1270 if (!source.isRemote()) {
Chris@45 1271 // for file dialog
Chris@45 1272 registerLastOpenedFilePath(FileFinder::AudioFile,
Chris@45 1273 source.getLocalFilename());
Chris@45 1274 }
Chris@45 1275 m_openingAudioFile = false;
Chris@45 1276
Chris@45 1277 currentPaneChanged(m_paneStack->getCurrentPane());
Chris@45 1278
Chris@45 1279 return FileOpenSucceeded;
Chris@45 1280 }
Chris@45 1281
Chris@45 1282 MainWindowBase::FileOpenStatus
Chris@45 1283 MainWindowBase::openPlaylist(FileSource source, AudioFileOpenMode mode)
Chris@45 1284 {
Chris@135 1285 std::cerr << "MainWindowBase::openPlaylist(" << source.getLocation().toStdString() << ")" << std::endl;
Chris@135 1286
Chris@45 1287 std::set<QString> extensions;
Chris@45 1288 PlaylistFileReader::getSupportedExtensions(extensions);
Chris@152 1289 QString extension = source.getExtension().toLower();
Chris@45 1290 if (extensions.find(extension) == extensions.end()) return FileOpenFailed;
Chris@45 1291
Chris@45 1292 if (!source.isAvailable()) return FileOpenFailed;
Chris@45 1293 source.waitForData();
Chris@45 1294
Chris@45 1295 PlaylistFileReader reader(source.getLocalFilename());
Chris@45 1296 if (!reader.isOK()) return FileOpenFailed;
Chris@45 1297
Chris@45 1298 PlaylistFileReader::Playlist playlist = reader.load();
Chris@45 1299
Chris@45 1300 bool someSuccess = false;
Chris@45 1301
Chris@45 1302 for (PlaylistFileReader::Playlist::const_iterator i = playlist.begin();
Chris@45 1303 i != playlist.end(); ++i) {
Chris@45 1304
Chris@134 1305 ProgressDialog dialog(tr("Opening playlist..."), true, 2000, this);
Chris@134 1306 connect(&dialog, SIGNAL(showing()), this, SIGNAL(hideSplash()));
Chris@109 1307 FileOpenStatus status = openAudio(FileSource(*i, &dialog), mode);
Chris@45 1308
Chris@45 1309 if (status == FileOpenCancelled) {
Chris@45 1310 return FileOpenCancelled;
Chris@45 1311 }
Chris@45 1312
Chris@45 1313 if (status == FileOpenSucceeded) {
Chris@45 1314 someSuccess = true;
Chris@45 1315 mode = CreateAdditionalModel;
Chris@45 1316 }
Chris@45 1317 }
Chris@45 1318
Chris@45 1319 if (someSuccess) return FileOpenSucceeded;
Chris@45 1320 else return FileOpenFailed;
Chris@45 1321 }
Chris@45 1322
Chris@45 1323 MainWindowBase::FileOpenStatus
Chris@45 1324 MainWindowBase::openLayer(FileSource source)
Chris@45 1325 {
Chris@135 1326 std::cerr << "MainWindowBase::openLayer(" << source.getLocation().toStdString() << ")" << std::endl;
Chris@135 1327
Chris@45 1328 Pane *pane = m_paneStack->getCurrentPane();
Chris@45 1329
Chris@45 1330 if (!pane) {
Chris@45 1331 // shouldn't happen, as the menu action should have been disabled
Chris@45 1332 std::cerr << "WARNING: MainWindowBase::openLayer: no current pane" << std::endl;
Chris@45 1333 return FileOpenWrongMode;
Chris@45 1334 }
Chris@45 1335
Chris@45 1336 if (!getMainModel()) {
Chris@45 1337 // shouldn't happen, as the menu action should have been disabled
Chris@45 1338 std::cerr << "WARNING: MainWindowBase::openLayer: No main model -- hence no default sample rate available" << std::endl;
Chris@45 1339 return FileOpenWrongMode;
Chris@45 1340 }
Chris@45 1341
Chris@45 1342 if (!source.isAvailable()) return FileOpenFailed;
Chris@45 1343 source.waitForData();
Chris@45 1344
Chris@45 1345 QString path = source.getLocalFilename();
Chris@45 1346
Chris@145 1347 RDFImporter::RDFDocumentType rdfType =
Chris@145 1348 RDFImporter::identifyDocumentType(QUrl::fromLocalFile(path).toString());
Chris@145 1349
Chris@148 1350 // std::cerr << "RDF type: (in layer) " << (int) rdfType << std::endl;
Chris@148 1351
Chris@145 1352 if (rdfType != RDFImporter::NotRDF) {
Chris@145 1353
Chris@145 1354 return openLayersFromRDF(source);
Chris@134 1355
Chris@152 1356 } else if (source.getExtension().toLower() == "svl" ||
Chris@152 1357 (source.getExtension().toLower() == "xml" &&
Chris@140 1358 (SVFileReader::identifyXmlFile(source.getLocalFilename())
Chris@140 1359 == SVFileReader::SVLayerFile))) {
Chris@45 1360
Chris@45 1361 PaneCallback callback(this);
Chris@45 1362 QFile file(path);
Chris@45 1363
Chris@45 1364 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
Chris@45 1365 std::cerr << "ERROR: MainWindowBase::openLayer("
Chris@45 1366 << source.getLocation().toStdString()
Chris@45 1367 << "): Failed to open file for reading" << std::endl;
Chris@45 1368 return FileOpenFailed;
Chris@45 1369 }
Chris@45 1370
Chris@45 1371 SVFileReader reader(m_document, callback, source.getLocation());
Chris@79 1372 connect
Chris@79 1373 (&reader, SIGNAL(modelRegenerationFailed(QString, QString, QString)),
Chris@79 1374 this, SLOT(modelRegenerationFailed(QString, QString, QString)));
Chris@79 1375 connect
Chris@79 1376 (&reader, SIGNAL(modelRegenerationWarning(QString, QString, QString)),
Chris@79 1377 this, SLOT(modelRegenerationWarning(QString, QString, QString)));
Chris@45 1378 reader.setCurrentPane(pane);
Chris@45 1379
Chris@45 1380 QXmlInputSource inputSource(&file);
Chris@45 1381 reader.parse(inputSource);
Chris@45 1382
Chris@45 1383 if (!reader.isOK()) {
Chris@45 1384 std::cerr << "ERROR: MainWindowBase::openLayer("
Chris@45 1385 << source.getLocation().toStdString()
Chris@45 1386 << "): Failed to read XML file: "
Chris@45 1387 << reader.getErrorString().toStdString() << std::endl;
Chris@45 1388 return FileOpenFailed;
Chris@45 1389 }
Chris@45 1390
Chris@164 1391 emit activity(tr("Import layer XML file \"%1\"").arg(source.getLocation()));
Chris@164 1392
Chris@45 1393 m_recentFiles.addFile(source.getLocation());
Chris@45 1394
Chris@45 1395 if (!source.isRemote()) {
Chris@45 1396 registerLastOpenedFilePath(FileFinder::LayerFile, path); // for file dialog
Chris@45 1397 }
Chris@45 1398
Chris@75 1399 return FileOpenSucceeded;
Chris@75 1400
Chris@45 1401 } else {
Chris@45 1402
Chris@45 1403 try {
Chris@45 1404
Chris@109 1405 MIDIFileImportDialog midiDlg(this);
Chris@109 1406
Chris@109 1407 Model *model = DataFileReaderFactory::loadNonCSV
Chris@109 1408 (path, &midiDlg, getMainModel()->getSampleRate());
Chris@45 1409
Chris@109 1410 if (!model) {
Chris@196 1411 CSVFormat format(path);
Chris@196 1412 format.setSampleRate(getMainModel()->getSampleRate());
Chris@196 1413 CSVFormatDialog *dialog = new CSVFormatDialog(this, format);
Chris@109 1414 if (dialog->exec() == QDialog::Accepted) {
Chris@109 1415 model = DataFileReaderFactory::loadCSV
Chris@109 1416 (path, dialog->getFormat(),
Chris@109 1417 getMainModel()->getSampleRate());
Chris@109 1418 }
Chris@109 1419 }
Chris@109 1420
Chris@45 1421 if (model) {
Chris@45 1422
Chris@45 1423 std::cerr << "MainWindowBase::openLayer: Have model" << std::endl;
Chris@45 1424
Chris@164 1425 emit activity(tr("Import MIDI file \"%1\"").arg(source.getLocation()));
Chris@164 1426
Chris@45 1427 Layer *newLayer = m_document->createImportedLayer(model);
Chris@45 1428
Chris@45 1429 if (newLayer) {
Chris@45 1430
Chris@45 1431 m_document->addLayerToView(pane, newLayer);
Chris@88 1432 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@88 1433
Chris@45 1434 m_recentFiles.addFile(source.getLocation());
Chris@45 1435
Chris@45 1436 if (!source.isRemote()) {
Chris@45 1437 registerLastOpenedFilePath
Chris@45 1438 (FileFinder::LayerFile,
Chris@45 1439 path); // for file dialog
Chris@45 1440 }
Chris@88 1441
Chris@45 1442 return FileOpenSucceeded;
Chris@45 1443 }
Chris@45 1444 }
Chris@45 1445 } catch (DataFileReaderFactory::Exception e) {
Chris@45 1446 if (e == DataFileReaderFactory::ImportCancelled) {
Chris@45 1447 return FileOpenCancelled;
Chris@45 1448 }
Chris@45 1449 }
Chris@45 1450 }
Chris@45 1451
Chris@45 1452 return FileOpenFailed;
Chris@45 1453 }
Chris@45 1454
Chris@45 1455 MainWindowBase::FileOpenStatus
Chris@45 1456 MainWindowBase::openImage(FileSource source)
Chris@45 1457 {
Chris@135 1458 std::cerr << "MainWindowBase::openImage(" << source.getLocation().toStdString() << ")" << std::endl;
Chris@135 1459
Chris@45 1460 Pane *pane = m_paneStack->getCurrentPane();
Chris@45 1461
Chris@45 1462 if (!pane) {
Chris@45 1463 // shouldn't happen, as the menu action should have been disabled
Chris@45 1464 std::cerr << "WARNING: MainWindowBase::openImage: no current pane" << std::endl;
Chris@45 1465 return FileOpenWrongMode;
Chris@45 1466 }
Chris@45 1467
Chris@45 1468 if (!m_document->getMainModel()) {
Chris@45 1469 return FileOpenWrongMode;
Chris@45 1470 }
Chris@45 1471
Chris@45 1472 bool newLayer = false;
Chris@45 1473
Chris@45 1474 ImageLayer *il = dynamic_cast<ImageLayer *>(pane->getSelectedLayer());
Chris@45 1475 if (!il) {
Chris@45 1476 for (int i = pane->getLayerCount()-1; i >= 0; --i) {
Chris@45 1477 il = dynamic_cast<ImageLayer *>(pane->getLayer(i));
Chris@45 1478 if (il) break;
Chris@45 1479 }
Chris@45 1480 }
Chris@45 1481 if (!il) {
Chris@45 1482 il = dynamic_cast<ImageLayer *>
Chris@45 1483 (m_document->createEmptyLayer(LayerFactory::Image));
Chris@45 1484 if (!il) return FileOpenFailed;
Chris@45 1485 newLayer = true;
Chris@45 1486 }
Chris@45 1487
Chris@45 1488 // We don't put the image file in Recent Files
Chris@45 1489
Chris@45 1490 std::cerr << "openImage: trying location \"" << source.getLocation().toStdString() << "\" in image layer" << std::endl;
Chris@45 1491
Chris@45 1492 if (!il->addImage(m_viewManager->getGlobalCentreFrame(), source.getLocation())) {
Chris@45 1493 if (newLayer) {
Chris@52 1494 m_document->deleteLayer(il); // also releases its model
Chris@45 1495 }
Chris@45 1496 return FileOpenFailed;
Chris@45 1497 } else {
Chris@45 1498 if (newLayer) {
Chris@45 1499 m_document->addLayerToView(pane, il);
Chris@45 1500 }
Chris@45 1501 m_paneStack->setCurrentLayer(pane, il);
Chris@45 1502 }
Chris@45 1503
Chris@45 1504 return FileOpenSucceeded;
Chris@45 1505 }
Chris@45 1506
Chris@45 1507 MainWindowBase::FileOpenStatus
Chris@45 1508 MainWindowBase::openSessionFile(QString fileOrUrl)
Chris@45 1509 {
Chris@134 1510 ProgressDialog dialog(tr("Opening session..."), true, 2000, this);
Chris@134 1511 connect(&dialog, SIGNAL(showing()), this, SIGNAL(hideSplash()));
Chris@109 1512 return openSession(FileSource(fileOrUrl, &dialog));
Chris@45 1513 }
Chris@45 1514
Chris@45 1515 MainWindowBase::FileOpenStatus
Chris@45 1516 MainWindowBase::openSession(FileSource source)
Chris@45 1517 {
Chris@135 1518 std::cerr << "MainWindowBase::openSession(" << source.getLocation().toStdString() << ")" << std::endl;
Chris@135 1519
Chris@45 1520 if (!source.isAvailable()) return FileOpenFailed;
Chris@145 1521 source.waitForData();
Chris@141 1522
Chris@152 1523 if (source.getExtension().toLower() != "sv") {
Chris@145 1524
Chris@145 1525 RDFImporter::RDFDocumentType rdfType =
Chris@145 1526 RDFImporter::identifyDocumentType
Chris@145 1527 (QUrl::fromLocalFile(source.getLocalFilename()).toString());
Chris@145 1528
Chris@148 1529 // std::cerr << "RDF type: " << (int)rdfType << std::endl;
Chris@148 1530
Chris@145 1531 if (rdfType == RDFImporter::AudioRefAndAnnotations ||
Chris@145 1532 rdfType == RDFImporter::AudioRef) {
Chris@145 1533 return openSessionFromRDF(source);
Chris@145 1534 } else if (rdfType != RDFImporter::NotRDF) {
Chris@145 1535 return FileOpenFailed;
Chris@145 1536 }
Chris@145 1537
Chris@152 1538 if (source.getExtension().toLower() == "xml") {
Chris@140 1539 if (SVFileReader::identifyXmlFile(source.getLocalFilename()) ==
Chris@140 1540 SVFileReader::SVSessionFile) {
Chris@140 1541 std::cerr << "This XML file looks like a session file, attempting to open it as a session" << std::endl;
Chris@140 1542 } else {
Chris@140 1543 return FileOpenFailed;
Chris@140 1544 }
Chris@140 1545 } else {
Chris@140 1546 return FileOpenFailed;
Chris@140 1547 }
Chris@140 1548 }
Chris@45 1549
Chris@140 1550 QXmlInputSource *inputSource = 0;
Chris@140 1551 BZipFileDevice *bzFile = 0;
Chris@140 1552 QFile *rawFile = 0;
Chris@140 1553
Chris@152 1554 if (source.getExtension().toLower() == "sv") {
Chris@140 1555 bzFile = new BZipFileDevice(source.getLocalFilename());
Chris@140 1556 if (!bzFile->open(QIODevice::ReadOnly)) {
Chris@140 1557 delete bzFile;
Chris@140 1558 return FileOpenFailed;
Chris@140 1559 }
Chris@140 1560 inputSource = new QXmlInputSource(bzFile);
Chris@140 1561 } else {
Chris@140 1562 rawFile = new QFile(source.getLocalFilename());
Chris@140 1563 inputSource = new QXmlInputSource(rawFile);
Chris@140 1564 }
Chris@140 1565
Chris@140 1566 if (!checkSaveModified()) {
Chris@140 1567 if (bzFile) bzFile->close();
Chris@140 1568 delete inputSource;
Chris@140 1569 delete bzFile;
Chris@140 1570 delete rawFile;
Chris@140 1571 return FileOpenCancelled;
Chris@140 1572 }
Chris@45 1573
Chris@45 1574 QString error;
Chris@45 1575 closeSession();
Chris@45 1576 createDocument();
Chris@45 1577
Chris@45 1578 PaneCallback callback(this);
Chris@45 1579 m_viewManager->clearSelections();
Chris@45 1580
Chris@45 1581 SVFileReader reader(m_document, callback, source.getLocation());
Chris@79 1582 connect
Chris@79 1583 (&reader, SIGNAL(modelRegenerationFailed(QString, QString, QString)),
Chris@79 1584 this, SLOT(modelRegenerationFailed(QString, QString, QString)));
Chris@79 1585 connect
Chris@79 1586 (&reader, SIGNAL(modelRegenerationWarning(QString, QString, QString)),
Chris@79 1587 this, SLOT(modelRegenerationWarning(QString, QString, QString)));
Chris@140 1588
Chris@140 1589 reader.parse(*inputSource);
Chris@45 1590
Chris@45 1591 if (!reader.isOK()) {
Chris@45 1592 error = tr("SV XML file read error:\n%1").arg(reader.getErrorString());
Chris@45 1593 }
Chris@45 1594
Chris@140 1595 if (bzFile) bzFile->close();
Chris@140 1596
Chris@140 1597 delete inputSource;
Chris@140 1598 delete bzFile;
Chris@140 1599 delete rawFile;
Chris@45 1600
Chris@45 1601 bool ok = (error == "");
Chris@45 1602
Chris@45 1603 if (ok) {
Chris@45 1604
Chris@164 1605 emit activity(tr("Import session file \"%1\"").arg(source.getLocation()));
Chris@164 1606
Chris@57 1607 setWindowTitle(tr("%1: %2")
Chris@57 1608 .arg(QApplication::applicationName())
Chris@45 1609 .arg(source.getLocation()));
Chris@45 1610
Chris@45 1611 if (!source.isRemote()) m_sessionFile = source.getLocalFilename();
Chris@45 1612
Chris@45 1613 setupMenus();
Chris@45 1614
Chris@45 1615 CommandHistory::getInstance()->clear();
Chris@45 1616 CommandHistory::getInstance()->documentSaved();
Chris@45 1617 m_documentModified = false;
Chris@45 1618 updateMenuStates();
Chris@45 1619
Chris@45 1620 m_recentFiles.addFile(source.getLocation());
Chris@45 1621
Chris@45 1622 if (!source.isRemote()) {
Chris@45 1623 // for file dialog
Chris@45 1624 registerLastOpenedFilePath(FileFinder::SessionFile,
Chris@45 1625 source.getLocalFilename());
Chris@45 1626 }
Chris@45 1627
Chris@45 1628 } else {
Chris@57 1629 setWindowTitle(QApplication::applicationName());
Chris@45 1630 }
Chris@45 1631
Chris@45 1632 return ok ? FileOpenSucceeded : FileOpenFailed;
Chris@45 1633 }
Chris@45 1634
Chris@141 1635 MainWindowBase::FileOpenStatus
Chris@141 1636 MainWindowBase::openSessionFromRDF(FileSource source)
Chris@141 1637 {
Chris@141 1638 std::cerr << "MainWindowBase::openSessionFromRDF(" << source.getLocation().toStdString() << ")" << std::endl;
Chris@141 1639
Chris@141 1640 if (!source.isAvailable()) return FileOpenFailed;
Chris@141 1641 source.waitForData();
Chris@141 1642
Chris@145 1643 if (!checkSaveModified()) {
Chris@145 1644 return FileOpenCancelled;
Chris@141 1645 }
Chris@143 1646
Chris@145 1647 closeSession();
Chris@145 1648 createDocument();
Chris@145 1649
Chris@145 1650 FileOpenStatus status = openLayersFromRDF(source);
Chris@141 1651
Chris@141 1652 setupMenus();
Chris@141 1653
Chris@141 1654 setWindowTitle(tr("%1: %2")
Chris@141 1655 .arg(QApplication::applicationName())
Chris@141 1656 .arg(source.getLocation()));
Chris@141 1657 CommandHistory::getInstance()->clear();
Chris@141 1658 CommandHistory::getInstance()->documentSaved();
Chris@141 1659 m_documentModified = false;
Chris@145 1660
Chris@145 1661 return status;
Chris@145 1662 }
Chris@145 1663
Chris@145 1664 MainWindowBase::FileOpenStatus
Chris@145 1665 MainWindowBase::openLayersFromRDF(FileSource source)
Chris@145 1666 {
Chris@145 1667 size_t rate = 0;
Chris@145 1668
Chris@186 1669 std::cerr << "MainWindowBase::openLayersFromRDF" << std::endl;
Chris@186 1670
Chris@145 1671 ProgressDialog dialog(tr("Importing from RDF..."), true, 2000, this);
Chris@145 1672 connect(&dialog, SIGNAL(showing()), this, SIGNAL(hideSplash()));
Chris@145 1673
Chris@145 1674 if (getMainModel()) {
Chris@145 1675 rate = getMainModel()->getSampleRate();
Chris@145 1676 } else if (Preferences::getInstance()->getResampleOnLoad()) {
Chris@145 1677 rate = m_playSource->getSourceSampleRate();
Chris@145 1678 }
Chris@145 1679
Chris@145 1680 RDFImporter importer
Chris@145 1681 (QUrl::fromLocalFile(source.getLocalFilename()).toString(), rate);
Chris@145 1682
Chris@145 1683 if (!importer.isOK()) {
Chris@147 1684 if (importer.getErrorString() != "") {
Chris@147 1685 QMessageBox::critical
Chris@147 1686 (this, tr("Failed to import RDF"),
Chris@147 1687 tr("<b>Failed to import RDF</b><p>Importing data from RDF document at \"%1\" failed: %2</p>")
Chris@147 1688 .arg(source.getLocation()).arg(importer.getErrorString()));
Chris@147 1689 }
Chris@145 1690 return FileOpenFailed;
Chris@145 1691 }
Chris@145 1692
Chris@145 1693 std::vector<Model *> models = importer.getDataModels(&dialog);
Chris@145 1694
Chris@145 1695 dialog.setMessage(tr("Importing from RDF..."));
Chris@145 1696
Chris@145 1697 if (models.empty()) {
Chris@186 1698 QMessageBox::critical
Chris@186 1699 (this, tr("Failed to import RDF"),
Chris@186 1700 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 1701 return FileOpenFailed;
Chris@145 1702 }
Chris@145 1703
Chris@164 1704 emit activity(tr("Import RDF document \"%1\"").arg(source.getLocation()));
Chris@164 1705
Chris@145 1706 std::set<Model *> added;
Chris@145 1707
Chris@145 1708 for (int i = 0; i < models.size(); ++i) {
Chris@145 1709
Chris@145 1710 Model *m = models[i];
Chris@145 1711 WaveFileModel *w = dynamic_cast<WaveFileModel *>(m);
Chris@145 1712
Chris@145 1713 if (w) {
Chris@145 1714
Chris@145 1715 Pane *pane = addPaneToStack();
Chris@145 1716 Layer *layer = 0;
Chris@145 1717
Chris@145 1718 if (m_timeRulerLayer) {
Chris@145 1719 m_document->addLayerToView(pane, m_timeRulerLayer);
Chris@145 1720 }
Chris@145 1721
Chris@145 1722 if (!getMainModel()) {
Chris@145 1723 m_document->setMainModel(w);
Chris@145 1724 layer = m_document->createMainModelLayer(LayerFactory::Waveform);
Chris@145 1725 } else {
Chris@145 1726 layer = m_document->createImportedLayer(w);
Chris@145 1727 }
Chris@145 1728
Chris@145 1729 m_document->addLayerToView(pane, layer);
Chris@145 1730
Chris@145 1731 added.insert(w);
Chris@145 1732
Chris@145 1733 for (int j = 0; j < models.size(); ++j) {
Chris@145 1734
Chris@145 1735 Model *dm = models[j];
Chris@145 1736
Chris@145 1737 if (dm == m) continue;
Chris@145 1738 if (dm->getSourceModel() != m) continue;
Chris@145 1739
Chris@145 1740 layer = m_document->createImportedLayer(dm);
Chris@145 1741
Chris@145 1742 if (layer->isLayerOpaque() ||
Chris@145 1743 dynamic_cast<Colour3DPlotLayer *>(layer)) {
Chris@145 1744
Chris@156 1745 // these always go in a new pane, with nothing
Chris@156 1746 // else going in the same pane
Chris@156 1747
Chris@145 1748 Pane *singleLayerPane = addPaneToStack();
Chris@145 1749 if (m_timeRulerLayer) {
Chris@145 1750 m_document->addLayerToView(singleLayerPane, m_timeRulerLayer);
Chris@145 1751 }
Chris@145 1752 m_document->addLayerToView(singleLayerPane, layer);
Chris@145 1753
Chris@156 1754 } else if (layer->getLayerColourSignificance() ==
Chris@156 1755 Layer::ColourHasMeaningfulValue) {
Chris@156 1756
Chris@156 1757 // these can go in a pane with something else, but
Chris@156 1758 // only if none of the something elses also have
Chris@156 1759 // this quality
Chris@156 1760
Chris@156 1761 bool needNewPane = false;
Chris@156 1762 for (int i = 0; i < pane->getLayerCount(); ++i) {
Chris@156 1763 Layer *otherLayer = pane->getLayer(i);
Chris@156 1764 if (otherLayer &&
Chris@156 1765 (otherLayer->getLayerColourSignificance() ==
Chris@156 1766 Layer::ColourHasMeaningfulValue)) {
Chris@156 1767 needNewPane = true;
Chris@156 1768 break;
Chris@156 1769 }
Chris@156 1770 }
Chris@156 1771 if (needNewPane) {
Chris@156 1772 pane = addPaneToStack();
Chris@156 1773 }
Chris@156 1774
Chris@156 1775 m_document->addLayerToView(pane, layer);
Chris@156 1776
Chris@145 1777 } else {
Chris@145 1778
Chris@145 1779 if (pane->getLayerCount() > 4) {
Chris@145 1780 pane = addPaneToStack();
Chris@145 1781 }
Chris@145 1782
Chris@145 1783 m_document->addLayerToView(pane, layer);
Chris@145 1784 }
Chris@145 1785
Chris@145 1786 added.insert(dm);
Chris@145 1787 }
Chris@145 1788 }
Chris@145 1789 }
Chris@145 1790
Chris@145 1791 for (int i = 0; i < models.size(); ++i) {
Chris@145 1792
Chris@145 1793 Model *m = models[i];
Chris@145 1794
Chris@145 1795 if (added.find(m) == added.end()) {
Chris@145 1796
Chris@145 1797 Layer *layer = m_document->createImportedLayer(m);
Chris@145 1798 if (!layer) return FileOpenFailed;
Chris@145 1799
Chris@145 1800 Pane *singleLayerPane = addPaneToStack();
Chris@145 1801 if (m_timeRulerLayer) {
Chris@145 1802 m_document->addLayerToView(singleLayerPane, m_timeRulerLayer);
Chris@145 1803 }
Chris@145 1804 m_document->addLayerToView(singleLayerPane, layer);
Chris@145 1805 }
Chris@145 1806 }
Chris@145 1807
Chris@145 1808 m_recentFiles.addFile(source.getLocation());
Chris@145 1809 return FileOpenSucceeded;
Chris@141 1810 }
Chris@141 1811
Chris@45 1812 void
Chris@45 1813 MainWindowBase::createPlayTarget()
Chris@45 1814 {
Chris@45 1815 if (m_playTarget) return;
Chris@45 1816
Chris@126 1817 QSettings settings;
Chris@126 1818 settings.beginGroup("Preferences");
Chris@126 1819 QString targetName = settings.value("audio-target", "").toString();
Chris@126 1820 settings.endGroup();
Chris@126 1821
Chris@126 1822 AudioTargetFactory *factory = AudioTargetFactory::getInstance();
Chris@126 1823
Chris@126 1824 factory->setDefaultCallbackTarget(targetName);
Chris@126 1825 m_playTarget = factory->createCallbackTarget(m_playSource);
Chris@126 1826
Chris@45 1827 if (!m_playTarget) {
Chris@104 1828 emit hideSplash();
Chris@126 1829
Chris@126 1830 if (factory->isAutoCallbackTarget(targetName)) {
Chris@128 1831 QMessageBox::warning
Chris@45 1832 (this, tr("Couldn't open audio device"),
Chris@126 1833 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 1834 QMessageBox::Ok);
Chris@126 1835 } else {
Chris@126 1836 QMessageBox::warning
Chris@126 1837 (this, tr("Couldn't open audio device"),
Chris@126 1838 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 1839 .arg(factory->getCallbackTargetDescription(targetName)),
Chris@126 1840 QMessageBox::Ok);
Chris@126 1841 }
Chris@45 1842 }
Chris@45 1843 }
Chris@45 1844
Chris@45 1845 WaveFileModel *
Chris@45 1846 MainWindowBase::getMainModel()
Chris@45 1847 {
Chris@45 1848 if (!m_document) return 0;
Chris@45 1849 return m_document->getMainModel();
Chris@45 1850 }
Chris@45 1851
Chris@45 1852 const WaveFileModel *
Chris@45 1853 MainWindowBase::getMainModel() const
Chris@45 1854 {
Chris@45 1855 if (!m_document) return 0;
Chris@45 1856 return m_document->getMainModel();
Chris@45 1857 }
Chris@45 1858
Chris@45 1859 void
Chris@45 1860 MainWindowBase::createDocument()
Chris@45 1861 {
Chris@45 1862 m_document = new Document;
Chris@45 1863
Chris@45 1864 connect(m_document, SIGNAL(layerAdded(Layer *)),
Chris@45 1865 this, SLOT(layerAdded(Layer *)));
Chris@45 1866 connect(m_document, SIGNAL(layerRemoved(Layer *)),
Chris@45 1867 this, SLOT(layerRemoved(Layer *)));
Chris@45 1868 connect(m_document, SIGNAL(layerAboutToBeDeleted(Layer *)),
Chris@45 1869 this, SLOT(layerAboutToBeDeleted(Layer *)));
Chris@45 1870 connect(m_document, SIGNAL(layerInAView(Layer *, bool)),
Chris@45 1871 this, SLOT(layerInAView(Layer *, bool)));
Chris@45 1872
Chris@45 1873 connect(m_document, SIGNAL(modelAdded(Model *)),
Chris@45 1874 this, SLOT(modelAdded(Model *)));
Chris@45 1875 connect(m_document, SIGNAL(mainModelChanged(WaveFileModel *)),
Chris@45 1876 this, SLOT(mainModelChanged(WaveFileModel *)));
Chris@45 1877 connect(m_document, SIGNAL(modelAboutToBeDeleted(Model *)),
Chris@45 1878 this, SLOT(modelAboutToBeDeleted(Model *)));
Chris@45 1879
Chris@78 1880 connect(m_document, SIGNAL(modelGenerationFailed(QString, QString)),
Chris@78 1881 this, SLOT(modelGenerationFailed(QString, QString)));
Chris@78 1882 connect(m_document, SIGNAL(modelRegenerationWarning(QString, QString, QString)),
Chris@78 1883 this, SLOT(modelRegenerationWarning(QString, QString, QString)));
Chris@78 1884 connect(m_document, SIGNAL(modelGenerationFailed(QString, QString)),
Chris@78 1885 this, SLOT(modelGenerationFailed(QString, QString)));
Chris@78 1886 connect(m_document, SIGNAL(modelRegenerationWarning(QString, QString, QString)),
Chris@78 1887 this, SLOT(modelRegenerationWarning(QString, QString, QString)));
Chris@78 1888 connect(m_document, SIGNAL(alignmentFailed(QString, QString)),
Chris@78 1889 this, SLOT(alignmentFailed(QString, QString)));
Chris@160 1890
Chris@160 1891 emit replacedDocument();
Chris@45 1892 }
Chris@45 1893
Chris@45 1894 bool
Chris@45 1895 MainWindowBase::saveSessionFile(QString path)
Chris@45 1896 {
Chris@217 1897 try {
Chris@217 1898
Chris@217 1899 TempWriteFile temp(path);
Chris@217 1900
Chris@217 1901 BZipFileDevice bzFile(temp.getTemporaryFilename());
Chris@217 1902 if (!bzFile.open(QIODevice::WriteOnly)) {
Chris@217 1903 std::cerr << "Failed to open session file \""
Chris@217 1904 << temp.getTemporaryFilename().toStdString()
Chris@217 1905 << "\" for writing: "
Chris@217 1906 << bzFile.errorString().toStdString() << std::endl;
Chris@217 1907 return false;
Chris@217 1908 }
Chris@217 1909
Chris@217 1910 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
Chris@217 1911
Chris@217 1912 QTextStream out(&bzFile);
Chris@217 1913 toXml(out);
Chris@217 1914 out.flush();
Chris@217 1915
Chris@217 1916 QApplication::restoreOverrideCursor();
Chris@217 1917
Chris@217 1918 if (!bzFile.isOK()) {
Chris@217 1919 QMessageBox::critical(this, tr("Failed to write file"),
Chris@217 1920 tr("<b>Save failed</b><p>Failed to write to file \"%1\": %2")
Chris@217 1921 .arg(path).arg(bzFile.errorString()));
Chris@217 1922 bzFile.close();
Chris@217 1923 return false;
Chris@217 1924 }
Chris@217 1925
Chris@217 1926 bzFile.close();
Chris@217 1927 temp.moveToTarget();
Chris@217 1928 return true;
Chris@217 1929
Chris@217 1930 } catch (FileOperationFailed &f) {
Chris@217 1931
Chris@217 1932 QMessageBox::critical(this, tr("Failed to write file"),
Chris@217 1933 tr("<b>Save failed</b><p>Failed to write to file \"%1\": %2")
Chris@217 1934 .arg(path).arg(f.what()));
Chris@45 1935 return false;
Chris@45 1936 }
Chris@45 1937 }
Chris@45 1938
Chris@45 1939 void
Chris@45 1940 MainWindowBase::toXml(QTextStream &out)
Chris@45 1941 {
Chris@45 1942 QString indent(" ");
Chris@45 1943
Chris@45 1944 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
Chris@45 1945 out << "<!DOCTYPE sonic-visualiser>\n";
Chris@45 1946 out << "<sv>\n";
Chris@45 1947
Chris@45 1948 m_document->toXml(out, "", "");
Chris@45 1949
Chris@45 1950 out << "<display>\n";
Chris@45 1951
Chris@45 1952 out << QString(" <window width=\"%1\" height=\"%2\"/>\n")
Chris@45 1953 .arg(width()).arg(height());
Chris@45 1954
Chris@45 1955 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@45 1956
Chris@45 1957 Pane *pane = m_paneStack->getPane(i);
Chris@45 1958
Chris@45 1959 if (pane) {
Chris@45 1960 pane->toXml(out, indent);
Chris@45 1961 }
Chris@45 1962 }
Chris@45 1963
Chris@45 1964 out << "</display>\n";
Chris@45 1965
Chris@45 1966 m_viewManager->getSelection().toXml(out);
Chris@45 1967
Chris@45 1968 out << "</sv>\n";
Chris@45 1969 }
Chris@45 1970
Chris@45 1971 Pane *
Chris@45 1972 MainWindowBase::addPaneToStack()
Chris@45 1973 {
Chris@45 1974 AddPaneCommand *command = new AddPaneCommand(this);
Chris@45 1975 CommandHistory::getInstance()->addCommand(command);
Chris@57 1976 Pane *pane = command->getPane();
Chris@57 1977 return pane;
Chris@45 1978 }
Chris@45 1979
Chris@45 1980 void
Chris@45 1981 MainWindowBase::zoomIn()
Chris@45 1982 {
Chris@45 1983 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 1984 if (currentPane) currentPane->zoom(true);
Chris@45 1985 }
Chris@45 1986
Chris@45 1987 void
Chris@45 1988 MainWindowBase::zoomOut()
Chris@45 1989 {
Chris@45 1990 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 1991 if (currentPane) currentPane->zoom(false);
Chris@45 1992 }
Chris@45 1993
Chris@45 1994 void
Chris@45 1995 MainWindowBase::zoomToFit()
Chris@45 1996 {
Chris@45 1997 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 1998 if (!currentPane) return;
Chris@45 1999
Chris@45 2000 Model *model = getMainModel();
Chris@45 2001 if (!model) return;
Chris@45 2002
Chris@45 2003 size_t start = model->getStartFrame();
Chris@45 2004 size_t end = model->getEndFrame();
Chris@60 2005 if (m_playSource) end = std::max(end, m_playSource->getPlayEndFrame());
Chris@45 2006 size_t pixels = currentPane->width();
Chris@45 2007
Chris@45 2008 size_t sw = currentPane->getVerticalScaleWidth();
Chris@45 2009 if (pixels > sw * 2) pixels -= sw * 2;
Chris@45 2010 else pixels = 1;
Chris@45 2011 if (pixels > 4) pixels -= 4;
Chris@45 2012
Chris@45 2013 size_t zoomLevel = (end - start) / pixels;
Chris@150 2014 if (zoomLevel < 1) zoomLevel = 1;
Chris@45 2015
Chris@45 2016 currentPane->setZoomLevel(zoomLevel);
Chris@45 2017 currentPane->setCentreFrame((start + end) / 2);
Chris@45 2018 }
Chris@45 2019
Chris@45 2020 void
Chris@45 2021 MainWindowBase::zoomDefault()
Chris@45 2022 {
Chris@45 2023 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 2024 if (currentPane) currentPane->setZoomLevel(1024);
Chris@45 2025 }
Chris@45 2026
Chris@45 2027 void
Chris@45 2028 MainWindowBase::scrollLeft()
Chris@45 2029 {
Chris@45 2030 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 2031 if (currentPane) currentPane->scroll(false, false);
Chris@45 2032 }
Chris@45 2033
Chris@45 2034 void
Chris@45 2035 MainWindowBase::jumpLeft()
Chris@45 2036 {
Chris@45 2037 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 2038 if (currentPane) currentPane->scroll(false, true);
Chris@45 2039 }
Chris@45 2040
Chris@45 2041 void
Chris@162 2042 MainWindowBase::peekLeft()
Chris@162 2043 {
Chris@162 2044 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@162 2045 if (currentPane) currentPane->scroll(false, false, false);
Chris@162 2046 }
Chris@162 2047
Chris@162 2048 void
Chris@45 2049 MainWindowBase::scrollRight()
Chris@45 2050 {
Chris@45 2051 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 2052 if (currentPane) currentPane->scroll(true, false);
Chris@45 2053 }
Chris@45 2054
Chris@45 2055 void
Chris@45 2056 MainWindowBase::jumpRight()
Chris@45 2057 {
Chris@45 2058 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 2059 if (currentPane) currentPane->scroll(true, true);
Chris@45 2060 }
Chris@45 2061
Chris@45 2062 void
Chris@162 2063 MainWindowBase::peekRight()
Chris@162 2064 {
Chris@162 2065 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@162 2066 if (currentPane) currentPane->scroll(true, false, false);
Chris@162 2067 }
Chris@162 2068
Chris@162 2069 void
Chris@45 2070 MainWindowBase::showNoOverlays()
Chris@45 2071 {
Chris@45 2072 m_viewManager->setOverlayMode(ViewManager::NoOverlays);
Chris@45 2073 }
Chris@45 2074
Chris@45 2075 void
Chris@45 2076 MainWindowBase::showMinimalOverlays()
Chris@45 2077 {
Chris@45 2078 m_viewManager->setOverlayMode(ViewManager::MinimalOverlays);
Chris@45 2079 }
Chris@45 2080
Chris@45 2081 void
Chris@45 2082 MainWindowBase::showStandardOverlays()
Chris@45 2083 {
Chris@45 2084 m_viewManager->setOverlayMode(ViewManager::StandardOverlays);
Chris@45 2085 }
Chris@45 2086
Chris@45 2087 void
Chris@45 2088 MainWindowBase::showAllOverlays()
Chris@45 2089 {
Chris@45 2090 m_viewManager->setOverlayMode(ViewManager::AllOverlays);
Chris@45 2091 }
Chris@45 2092
Chris@45 2093 void
Chris@211 2094 MainWindowBase::toggleTimeRulers()
Chris@211 2095 {
Chris@211 2096 bool haveRulers = false;
Chris@211 2097 bool someHidden = false;
Chris@211 2098
Chris@211 2099 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@211 2100
Chris@211 2101 Pane *pane = m_paneStack->getPane(i);
Chris@211 2102 if (!pane) continue;
Chris@211 2103
Chris@211 2104 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@211 2105
Chris@211 2106 Layer *layer = pane->getLayer(j);
Chris@211 2107 if (!dynamic_cast<TimeRulerLayer *>(layer)) continue;
Chris@211 2108
Chris@211 2109 haveRulers = true;
Chris@211 2110 if (layer->isLayerDormant(pane)) someHidden = true;
Chris@211 2111 }
Chris@211 2112 }
Chris@211 2113
Chris@211 2114 if (haveRulers) {
Chris@211 2115
Chris@211 2116 bool show = someHidden;
Chris@211 2117
Chris@211 2118 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@211 2119
Chris@211 2120 Pane *pane = m_paneStack->getPane(i);
Chris@211 2121 if (!pane) continue;
Chris@211 2122
Chris@211 2123 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@211 2124
Chris@211 2125 Layer *layer = pane->getLayer(j);
Chris@211 2126 if (!dynamic_cast<TimeRulerLayer *>(layer)) continue;
Chris@211 2127
Chris@211 2128 layer->showLayer(pane, show);
Chris@211 2129 }
Chris@211 2130 }
Chris@211 2131 }
Chris@211 2132 }
Chris@211 2133
Chris@211 2134 void
Chris@45 2135 MainWindowBase::toggleZoomWheels()
Chris@45 2136 {
Chris@45 2137 if (m_viewManager->getZoomWheelsEnabled()) {
Chris@45 2138 m_viewManager->setZoomWheelsEnabled(false);
Chris@45 2139 } else {
Chris@45 2140 m_viewManager->setZoomWheelsEnabled(true);
Chris@45 2141 }
Chris@45 2142 }
Chris@45 2143
Chris@45 2144 void
Chris@45 2145 MainWindowBase::togglePropertyBoxes()
Chris@45 2146 {
Chris@45 2147 if (m_paneStack->getLayoutStyle() == PaneStack::NoPropertyStacks) {
Chris@45 2148 if (Preferences::getInstance()->getPropertyBoxLayout() ==
Chris@45 2149 Preferences::VerticallyStacked) {
Chris@45 2150 m_paneStack->setLayoutStyle(PaneStack::PropertyStackPerPaneLayout);
Chris@45 2151 } else {
Chris@45 2152 m_paneStack->setLayoutStyle(PaneStack::SinglePropertyStackLayout);
Chris@45 2153 }
Chris@45 2154 } else {
Chris@45 2155 m_paneStack->setLayoutStyle(PaneStack::NoPropertyStacks);
Chris@45 2156 }
Chris@45 2157 }
Chris@45 2158
Chris@45 2159 void
Chris@45 2160 MainWindowBase::toggleStatusBar()
Chris@45 2161 {
Chris@45 2162 QSettings settings;
Chris@45 2163 settings.beginGroup("MainWindow");
Chris@45 2164 bool sb = settings.value("showstatusbar", true).toBool();
Chris@45 2165
Chris@45 2166 if (sb) {
Chris@45 2167 statusBar()->hide();
Chris@45 2168 } else {
Chris@45 2169 statusBar()->show();
Chris@45 2170 }
Chris@45 2171
Chris@45 2172 settings.setValue("showstatusbar", !sb);
Chris@45 2173
Chris@45 2174 settings.endGroup();
Chris@45 2175 }
Chris@45 2176
Chris@45 2177 void
Chris@45 2178 MainWindowBase::preferenceChanged(PropertyContainer::PropertyName name)
Chris@45 2179 {
Chris@45 2180 if (name == "Property Box Layout") {
Chris@45 2181 if (m_paneStack->getLayoutStyle() != PaneStack::NoPropertyStacks) {
Chris@45 2182 if (Preferences::getInstance()->getPropertyBoxLayout() ==
Chris@45 2183 Preferences::VerticallyStacked) {
Chris@45 2184 m_paneStack->setLayoutStyle(PaneStack::PropertyStackPerPaneLayout);
Chris@45 2185 } else {
Chris@45 2186 m_paneStack->setLayoutStyle(PaneStack::SinglePropertyStackLayout);
Chris@45 2187 }
Chris@45 2188 }
Chris@45 2189 } else if (name == "Background Mode" && m_viewManager) {
Chris@45 2190 Preferences::BackgroundMode mode =
Chris@45 2191 Preferences::getInstance()->getBackgroundMode();
Chris@45 2192 if (mode == Preferences::BackgroundFromTheme) {
Chris@45 2193 m_viewManager->setGlobalDarkBackground(m_initialDarkBackground);
Chris@45 2194 } else if (mode == Preferences::DarkBackground) {
Chris@45 2195 m_viewManager->setGlobalDarkBackground(true);
Chris@45 2196 } else {
Chris@45 2197 m_viewManager->setGlobalDarkBackground(false);
Chris@45 2198 }
Chris@45 2199 }
Chris@45 2200 }
Chris@45 2201
Chris@45 2202 void
Chris@45 2203 MainWindowBase::play()
Chris@45 2204 {
Chris@45 2205 if (m_playSource->isPlaying()) {
Chris@45 2206 stop();
Chris@45 2207 } else {
Chris@45 2208 playbackFrameChanged(m_viewManager->getPlaybackFrame());
Chris@45 2209 m_playSource->play(m_viewManager->getPlaybackFrame());
Chris@45 2210 }
Chris@45 2211 }
Chris@45 2212
Chris@45 2213 void
Chris@45 2214 MainWindowBase::ffwd()
Chris@45 2215 {
Chris@45 2216 if (!getMainModel()) return;
Chris@45 2217
Chris@45 2218 int frame = m_viewManager->getPlaybackFrame();
Chris@45 2219 ++frame;
Chris@45 2220
Chris@85 2221 Pane *pane = m_paneStack->getCurrentPane();
Chris@45 2222 Layer *layer = getSnapLayer();
Chris@45 2223 size_t sr = getMainModel()->getSampleRate();
Chris@45 2224
Chris@45 2225 if (!layer) {
Chris@45 2226
Chris@45 2227 frame = RealTime::realTime2Frame
Chris@45 2228 (RealTime::frame2RealTime(frame, sr) + RealTime(2, 0), sr);
Chris@45 2229 if (frame > int(getMainModel()->getEndFrame())) {
Chris@45 2230 frame = getMainModel()->getEndFrame();
Chris@45 2231 }
Chris@45 2232
Chris@45 2233 } else {
Chris@45 2234
Chris@45 2235 size_t resolution = 0;
Chris@166 2236 if (pane) frame = pane->alignFromReference(frame);
Chris@85 2237 if (layer->snapToFeatureFrame(m_paneStack->getCurrentPane(),
Chris@85 2238 frame, resolution, Layer::SnapRight)) {
Chris@85 2239 if (pane) frame = pane->alignToReference(frame);
Chris@85 2240 } else {
Chris@45 2241 frame = getMainModel()->getEndFrame();
Chris@45 2242 }
Chris@45 2243 }
Chris@45 2244
Chris@45 2245 if (frame < 0) frame = 0;
Chris@45 2246
Chris@45 2247 if (m_viewManager->getPlaySelectionMode()) {
Chris@45 2248 frame = m_viewManager->constrainFrameToSelection(size_t(frame));
Chris@45 2249 }
Chris@45 2250
Chris@45 2251 m_viewManager->setPlaybackFrame(frame);
Chris@166 2252
Chris@166 2253 if (frame == getMainModel()->getEndFrame() &&
Chris@166 2254 m_playSource &&
Chris@166 2255 m_playSource->isPlaying() &&
Chris@166 2256 !m_viewManager->getPlayLoopMode()) {
Chris@166 2257 stop();
Chris@166 2258 }
Chris@45 2259 }
Chris@45 2260
Chris@45 2261 void
Chris@45 2262 MainWindowBase::ffwdEnd()
Chris@45 2263 {
Chris@45 2264 if (!getMainModel()) return;
Chris@45 2265
Chris@139 2266 if (m_playSource &&
Chris@139 2267 m_playSource->isPlaying() &&
Chris@139 2268 !m_viewManager->getPlayLoopMode()) {
Chris@139 2269 stop();
Chris@139 2270 }
Chris@139 2271
Chris@45 2272 size_t frame = getMainModel()->getEndFrame();
Chris@45 2273
Chris@45 2274 if (m_viewManager->getPlaySelectionMode()) {
Chris@45 2275 frame = m_viewManager->constrainFrameToSelection(frame);
Chris@45 2276 }
Chris@45 2277
Chris@45 2278 m_viewManager->setPlaybackFrame(frame);
Chris@45 2279 }
Chris@45 2280
Chris@45 2281 void
Chris@166 2282 MainWindowBase::ffwdSimilar()
Chris@166 2283 {
Chris@166 2284 if (!getMainModel()) return;
Chris@166 2285
Chris@166 2286 Layer *layer = getSnapLayer();
Chris@166 2287 if (!layer) { ffwd(); return; }
Chris@166 2288
Chris@166 2289 Pane *pane = m_paneStack->getCurrentPane();
Chris@166 2290 size_t sr = getMainModel()->getSampleRate();
Chris@166 2291
Chris@166 2292 int frame = m_viewManager->getPlaybackFrame();
Chris@166 2293
Chris@166 2294 size_t resolution = 0;
Chris@166 2295 if (pane) frame = pane->alignFromReference(frame);
Chris@166 2296 if (layer->snapToSimilarFeature(m_paneStack->getCurrentPane(),
Chris@166 2297 frame, resolution, Layer::SnapRight)) {
Chris@166 2298 if (pane) frame = pane->alignToReference(frame);
Chris@166 2299 } else {
Chris@166 2300 frame = getMainModel()->getEndFrame();
Chris@166 2301 }
Chris@166 2302
Chris@166 2303 if (frame < 0) frame = 0;
Chris@166 2304
Chris@166 2305 if (m_viewManager->getPlaySelectionMode()) {
Chris@166 2306 frame = m_viewManager->constrainFrameToSelection(size_t(frame));
Chris@166 2307 }
Chris@166 2308
Chris@166 2309 m_viewManager->setPlaybackFrame(frame);
Chris@166 2310
Chris@166 2311 if (frame == getMainModel()->getEndFrame() &&
Chris@166 2312 m_playSource &&
Chris@166 2313 m_playSource->isPlaying() &&
Chris@166 2314 !m_viewManager->getPlayLoopMode()) {
Chris@166 2315 stop();
Chris@166 2316 }
Chris@166 2317 }
Chris@166 2318
Chris@166 2319 void
Chris@45 2320 MainWindowBase::rewind()
Chris@45 2321 {
Chris@45 2322 if (!getMainModel()) return;
Chris@45 2323
Chris@45 2324 int frame = m_viewManager->getPlaybackFrame();
Chris@45 2325 if (frame > 0) --frame;
Chris@45 2326
Chris@85 2327 Pane *pane = m_paneStack->getCurrentPane();
Chris@45 2328 Layer *layer = getSnapLayer();
Chris@45 2329 size_t sr = getMainModel()->getSampleRate();
Chris@45 2330
Chris@45 2331 // when rewinding during playback, we want to allow a period
Chris@45 2332 // following a rewind target point at which the rewind will go to
Chris@45 2333 // the prior point instead of the immediately neighbouring one
Chris@45 2334 if (m_playSource && m_playSource->isPlaying()) {
Chris@45 2335 RealTime ct = RealTime::frame2RealTime(frame, sr);
Chris@45 2336 ct = ct - RealTime::fromSeconds(0.25);
Chris@45 2337 if (ct < RealTime::zeroTime) ct = RealTime::zeroTime;
Chris@45 2338 frame = RealTime::realTime2Frame(ct, sr);
Chris@45 2339 }
Chris@45 2340
Chris@45 2341 if (!layer) {
Chris@45 2342
Chris@45 2343 frame = RealTime::realTime2Frame
Chris@45 2344 (RealTime::frame2RealTime(frame, sr) - RealTime(2, 0), sr);
Chris@45 2345 if (frame < int(getMainModel()->getStartFrame())) {
Chris@45 2346 frame = getMainModel()->getStartFrame();
Chris@45 2347 }
Chris@45 2348
Chris@45 2349 } else {
Chris@45 2350
Chris@45 2351 size_t resolution = 0;
Chris@166 2352 if (pane) frame = pane->alignFromReference(frame);
Chris@85 2353 if (layer->snapToFeatureFrame(m_paneStack->getCurrentPane(),
Chris@85 2354 frame, resolution, Layer::SnapLeft)) {
Chris@85 2355 if (pane) frame = pane->alignToReference(frame);
Chris@85 2356 } else {
Chris@45 2357 frame = getMainModel()->getStartFrame();
Chris@45 2358 }
Chris@45 2359 }
Chris@45 2360
Chris@45 2361 if (frame < 0) frame = 0;
Chris@45 2362
Chris@45 2363 if (m_viewManager->getPlaySelectionMode()) {
Chris@45 2364 frame = m_viewManager->constrainFrameToSelection(size_t(frame));
Chris@45 2365 }
Chris@45 2366
Chris@45 2367 m_viewManager->setPlaybackFrame(frame);
Chris@45 2368 }
Chris@45 2369
Chris@45 2370 void
Chris@45 2371 MainWindowBase::rewindStart()
Chris@45 2372 {
Chris@45 2373 if (!getMainModel()) return;
Chris@45 2374
Chris@45 2375 size_t frame = getMainModel()->getStartFrame();
Chris@45 2376
Chris@45 2377 if (m_viewManager->getPlaySelectionMode()) {
Chris@45 2378 frame = m_viewManager->constrainFrameToSelection(frame);
Chris@45 2379 }
Chris@45 2380
Chris@45 2381 m_viewManager->setPlaybackFrame(frame);
Chris@45 2382 }
Chris@45 2383
Chris@166 2384 void
Chris@166 2385 MainWindowBase::rewindSimilar()
Chris@166 2386 {
Chris@166 2387 if (!getMainModel()) return;
Chris@166 2388
Chris@166 2389 Layer *layer = getSnapLayer();
Chris@166 2390 if (!layer) { rewind(); return; }
Chris@166 2391
Chris@166 2392 Pane *pane = m_paneStack->getCurrentPane();
Chris@166 2393 size_t sr = getMainModel()->getSampleRate();
Chris@166 2394
Chris@166 2395 int frame = m_viewManager->getPlaybackFrame();
Chris@166 2396
Chris@166 2397 size_t resolution = 0;
Chris@166 2398 if (pane) frame = pane->alignFromReference(frame);
Chris@166 2399 if (layer->snapToSimilarFeature(m_paneStack->getCurrentPane(),
Chris@166 2400 frame, resolution, Layer::SnapLeft)) {
Chris@166 2401 if (pane) frame = pane->alignToReference(frame);
Chris@166 2402 } else {
Chris@166 2403 frame = getMainModel()->getStartFrame();
Chris@166 2404 }
Chris@166 2405
Chris@166 2406 if (frame < 0) frame = 0;
Chris@166 2407
Chris@166 2408 if (m_viewManager->getPlaySelectionMode()) {
Chris@166 2409 frame = m_viewManager->constrainFrameToSelection(size_t(frame));
Chris@166 2410 }
Chris@166 2411
Chris@166 2412 m_viewManager->setPlaybackFrame(frame);
Chris@166 2413 }
Chris@166 2414
Chris@45 2415 Layer *
Chris@45 2416 MainWindowBase::getSnapLayer() const
Chris@45 2417 {
Chris@45 2418 Pane *pane = m_paneStack->getCurrentPane();
Chris@45 2419 if (!pane) return 0;
Chris@45 2420
Chris@45 2421 Layer *layer = pane->getSelectedLayer();
Chris@45 2422
Chris@45 2423 if (!dynamic_cast<TimeInstantLayer *>(layer) &&
Chris@45 2424 !dynamic_cast<TimeValueLayer *>(layer) &&
Chris@194 2425 !dynamic_cast<RegionLayer *>(layer) &&
Chris@45 2426 !dynamic_cast<TimeRulerLayer *>(layer)) {
Chris@45 2427
Chris@45 2428 layer = 0;
Chris@45 2429
Chris@45 2430 for (int i = pane->getLayerCount(); i > 0; --i) {
Chris@45 2431 Layer *l = pane->getLayer(i-1);
Chris@45 2432 if (dynamic_cast<TimeRulerLayer *>(l)) {
Chris@45 2433 layer = l;
Chris@45 2434 break;
Chris@45 2435 }
Chris@45 2436 }
Chris@45 2437 }
Chris@45 2438
Chris@45 2439 return layer;
Chris@45 2440 }
Chris@45 2441
Chris@45 2442 void
Chris@45 2443 MainWindowBase::stop()
Chris@45 2444 {
Chris@45 2445 m_playSource->stop();
Chris@45 2446
Chris@45 2447 if (m_paneStack && m_paneStack->getCurrentPane()) {
Chris@45 2448 updateVisibleRangeDisplay(m_paneStack->getCurrentPane());
Chris@45 2449 } else {
Chris@45 2450 m_myStatusMessage = "";
Chris@45 2451 statusBar()->showMessage("");
Chris@45 2452 }
Chris@45 2453 }
Chris@45 2454
Chris@45 2455 MainWindowBase::AddPaneCommand::AddPaneCommand(MainWindowBase *mw) :
Chris@45 2456 m_mw(mw),
Chris@45 2457 m_pane(0),
Chris@45 2458 m_prevCurrentPane(0),
Chris@45 2459 m_added(false)
Chris@45 2460 {
Chris@45 2461 }
Chris@45 2462
Chris@45 2463 MainWindowBase::AddPaneCommand::~AddPaneCommand()
Chris@45 2464 {
Chris@45 2465 if (m_pane && !m_added) {
Chris@45 2466 m_mw->m_paneStack->deletePane(m_pane);
Chris@45 2467 }
Chris@45 2468 }
Chris@45 2469
Chris@45 2470 QString
Chris@45 2471 MainWindowBase::AddPaneCommand::getName() const
Chris@45 2472 {
Chris@45 2473 return tr("Add Pane");
Chris@45 2474 }
Chris@45 2475
Chris@45 2476 void
Chris@45 2477 MainWindowBase::AddPaneCommand::execute()
Chris@45 2478 {
Chris@45 2479 if (!m_pane) {
Chris@45 2480 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
Chris@45 2481 m_pane = m_mw->m_paneStack->addPane();
Chris@45 2482
Chris@45 2483 connect(m_pane, SIGNAL(contextHelpChanged(const QString &)),
Chris@45 2484 m_mw, SLOT(contextHelpChanged(const QString &)));
Chris@45 2485 } else {
Chris@45 2486 m_mw->m_paneStack->showPane(m_pane);
Chris@45 2487 }
Chris@45 2488
Chris@45 2489 m_mw->m_paneStack->setCurrentPane(m_pane);
Chris@45 2490 m_added = true;
Chris@45 2491 }
Chris@45 2492
Chris@45 2493 void
Chris@45 2494 MainWindowBase::AddPaneCommand::unexecute()
Chris@45 2495 {
Chris@45 2496 m_mw->m_paneStack->hidePane(m_pane);
Chris@45 2497 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
Chris@45 2498 m_added = false;
Chris@45 2499 }
Chris@45 2500
Chris@45 2501 MainWindowBase::RemovePaneCommand::RemovePaneCommand(MainWindowBase *mw, Pane *pane) :
Chris@45 2502 m_mw(mw),
Chris@45 2503 m_pane(pane),
Chris@45 2504 m_added(true)
Chris@45 2505 {
Chris@45 2506 }
Chris@45 2507
Chris@45 2508 MainWindowBase::RemovePaneCommand::~RemovePaneCommand()
Chris@45 2509 {
Chris@45 2510 if (m_pane && !m_added) {
Chris@45 2511 m_mw->m_paneStack->deletePane(m_pane);
Chris@45 2512 }
Chris@45 2513 }
Chris@45 2514
Chris@45 2515 QString
Chris@45 2516 MainWindowBase::RemovePaneCommand::getName() const
Chris@45 2517 {
Chris@45 2518 return tr("Remove Pane");
Chris@45 2519 }
Chris@45 2520
Chris@45 2521 void
Chris@45 2522 MainWindowBase::RemovePaneCommand::execute()
Chris@45 2523 {
Chris@45 2524 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
Chris@45 2525 m_mw->m_paneStack->hidePane(m_pane);
Chris@45 2526 m_added = false;
Chris@45 2527 }
Chris@45 2528
Chris@45 2529 void
Chris@45 2530 MainWindowBase::RemovePaneCommand::unexecute()
Chris@45 2531 {
Chris@45 2532 m_mw->m_paneStack->showPane(m_pane);
Chris@45 2533 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
Chris@45 2534 m_added = true;
Chris@45 2535 }
Chris@45 2536
Chris@45 2537 void
Chris@45 2538 MainWindowBase::deleteCurrentPane()
Chris@45 2539 {
Chris@45 2540 CommandHistory::getInstance()->startCompoundOperation
Chris@45 2541 (tr("Delete Pane"), true);
Chris@45 2542
Chris@45 2543 Pane *pane = m_paneStack->getCurrentPane();
Chris@45 2544 if (pane) {
Chris@45 2545 while (pane->getLayerCount() > 0) {
Chris@45 2546 Layer *layer = pane->getLayer(0);
Chris@45 2547 if (layer) {
Chris@45 2548 m_document->removeLayerFromView(pane, layer);
Chris@45 2549 } else {
Chris@45 2550 break;
Chris@45 2551 }
Chris@45 2552 }
Chris@45 2553
Chris@45 2554 RemovePaneCommand *command = new RemovePaneCommand(this, pane);
Chris@45 2555 CommandHistory::getInstance()->addCommand(command);
Chris@45 2556 }
Chris@45 2557
Chris@45 2558 CommandHistory::getInstance()->endCompoundOperation();
Chris@45 2559
Chris@45 2560 updateMenuStates();
Chris@45 2561 }
Chris@45 2562
Chris@45 2563 void
Chris@45 2564 MainWindowBase::deleteCurrentLayer()
Chris@45 2565 {
Chris@45 2566 Pane *pane = m_paneStack->getCurrentPane();
Chris@45 2567 if (pane) {
Chris@45 2568 Layer *layer = pane->getSelectedLayer();
Chris@45 2569 if (layer) {
Chris@45 2570 m_document->removeLayerFromView(pane, layer);
Chris@45 2571 }
Chris@45 2572 }
Chris@45 2573 updateMenuStates();
Chris@45 2574 }
Chris@45 2575
Chris@45 2576 void
Chris@123 2577 MainWindowBase::editCurrentLayer()
Chris@123 2578 {
Chris@123 2579 Layer *layer = 0;
Chris@123 2580 Pane *pane = m_paneStack->getCurrentPane();
Chris@123 2581 if (pane) layer = pane->getSelectedLayer();
Chris@123 2582 if (!layer) return;
Chris@123 2583
Chris@123 2584 Model *model = layer->getModel();
Chris@123 2585 if (!model) return;
Chris@123 2586
Chris@124 2587 TabularModel *tabular = dynamic_cast<TabularModel *>(model);
Chris@124 2588 if (!tabular) {
Chris@124 2589 //!!! how to prevent this function from being active if not
Chris@124 2590 //appropriate model type? or will we ultimately support
Chris@124 2591 //tabular display for all editable models?
Chris@124 2592 std::cerr << "NOTE: Not a tabular model" << std::endl;
Chris@124 2593 return;
Chris@124 2594 }
Chris@124 2595
Chris@123 2596 if (m_layerDataDialogMap.find(layer) != m_layerDataDialogMap.end()) {
Chris@126 2597 if (!m_layerDataDialogMap[layer].isNull()) {
Chris@126 2598 m_layerDataDialogMap[layer]->show();
Chris@126 2599 m_layerDataDialogMap[layer]->raise();
Chris@126 2600 return;
Chris@126 2601 }
Chris@123 2602 }
Chris@123 2603
Chris@125 2604 QString title = layer->getLayerPresentationName();
Chris@125 2605
Chris@125 2606 ModelDataTableDialog *dialog = new ModelDataTableDialog(tabular, title, this);
Chris@128 2607 dialog->setAttribute(Qt::WA_DeleteOnClose);
Chris@128 2608
Chris@128 2609 connectLayerEditDialog(dialog);
Chris@123 2610
Chris@128 2611 m_layerDataDialogMap[layer] = dialog;
Chris@128 2612 m_viewDataDialogMap[pane].insert(dialog);
Chris@128 2613
Chris@128 2614 dialog->show();
Chris@128 2615 }
Chris@128 2616
Chris@128 2617 void
Chris@128 2618 MainWindowBase::connectLayerEditDialog(ModelDataTableDialog *dialog)
Chris@128 2619 {
Chris@123 2620 connect(m_viewManager,
Chris@123 2621 SIGNAL(globalCentreFrameChanged(unsigned long)),
Chris@123 2622 dialog,
Chris@127 2623 SLOT(userScrolledToFrame(unsigned long)));
Chris@127 2624
Chris@127 2625 connect(m_viewManager,
Chris@127 2626 SIGNAL(playbackFrameChanged(unsigned long)),
Chris@127 2627 dialog,
Chris@127 2628 SLOT(playbackScrolledToFrame(unsigned long)));
Chris@127 2629
Chris@123 2630 connect(dialog,
Chris@123 2631 SIGNAL(scrollToFrame(unsigned long)),
Chris@123 2632 m_viewManager,
Chris@123 2633 SLOT(setGlobalCentreFrame(unsigned long)));
Chris@129 2634
Chris@129 2635 connect(dialog,
Chris@129 2636 SIGNAL(scrollToFrame(unsigned long)),
Chris@129 2637 m_viewManager,
Chris@129 2638 SLOT(setPlaybackFrame(unsigned long)));
Chris@128 2639 }
Chris@123 2640
Chris@123 2641 void
Chris@73 2642 MainWindowBase::previousPane()
Chris@73 2643 {
Chris@73 2644 if (!m_paneStack) return;
Chris@73 2645
Chris@73 2646 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@73 2647 if (!currentPane) return;
Chris@73 2648
Chris@73 2649 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@73 2650 if (m_paneStack->getPane(i) == currentPane) {
Chris@73 2651 if (i == 0) return;
Chris@73 2652 m_paneStack->setCurrentPane(m_paneStack->getPane(i-1));
Chris@73 2653 updateMenuStates();
Chris@73 2654 return;
Chris@73 2655 }
Chris@73 2656 }
Chris@73 2657 }
Chris@73 2658
Chris@73 2659 void
Chris@73 2660 MainWindowBase::nextPane()
Chris@73 2661 {
Chris@73 2662 if (!m_paneStack) return;
Chris@73 2663
Chris@73 2664 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@73 2665 if (!currentPane) return;
Chris@73 2666
Chris@73 2667 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@73 2668 if (m_paneStack->getPane(i) == currentPane) {
Chris@73 2669 if (i == m_paneStack->getPaneCount()-1) return;
Chris@73 2670 m_paneStack->setCurrentPane(m_paneStack->getPane(i+1));
Chris@73 2671 updateMenuStates();
Chris@73 2672 return;
Chris@73 2673 }
Chris@73 2674 }
Chris@73 2675 }
Chris@73 2676
Chris@73 2677 void
Chris@73 2678 MainWindowBase::previousLayer()
Chris@73 2679 {
Chris@73 2680 //!!! Not right -- pane lists layers in stacking order
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 Layer *currentLayer = currentPane->getSelectedLayer();
Chris@73 2688 if (!currentLayer) return;
Chris@73 2689
Chris@73 2690 for (int i = 0; i < currentPane->getLayerCount(); ++i) {
Chris@73 2691 if (currentPane->getLayer(i) == currentLayer) {
Chris@73 2692 if (i == 0) return;
Chris@73 2693 m_paneStack->setCurrentLayer(currentPane,
Chris@73 2694 currentPane->getLayer(i-1));
Chris@73 2695 updateMenuStates();
Chris@73 2696 return;
Chris@73 2697 }
Chris@73 2698 }
Chris@73 2699 }
Chris@73 2700
Chris@73 2701 void
Chris@73 2702 MainWindowBase::nextLayer()
Chris@73 2703 {
Chris@73 2704 //!!! Not right -- pane lists layers in stacking order
Chris@73 2705
Chris@73 2706 if (!m_paneStack) return;
Chris@73 2707
Chris@73 2708 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@73 2709 if (!currentPane) return;
Chris@73 2710
Chris@73 2711 Layer *currentLayer = currentPane->getSelectedLayer();
Chris@73 2712 if (!currentLayer) return;
Chris@73 2713
Chris@73 2714 for (int i = 0; i < currentPane->getLayerCount(); ++i) {
Chris@73 2715 if (currentPane->getLayer(i) == currentLayer) {
Chris@73 2716 if (i == currentPane->getLayerCount()-1) return;
Chris@73 2717 m_paneStack->setCurrentLayer(currentPane,
Chris@73 2718 currentPane->getLayer(i+1));
Chris@73 2719 updateMenuStates();
Chris@73 2720 return;
Chris@73 2721 }
Chris@73 2722 }
Chris@73 2723 }
Chris@73 2724
Chris@73 2725 void
Chris@45 2726 MainWindowBase::playbackFrameChanged(unsigned long frame)
Chris@45 2727 {
Chris@45 2728 if (!(m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
Chris@45 2729
Chris@187 2730 updatePositionStatusDisplays();
Chris@187 2731
Chris@45 2732 RealTime now = RealTime::frame2RealTime
Chris@45 2733 (frame, getMainModel()->getSampleRate());
Chris@45 2734
Chris@45 2735 if (now.sec == m_lastPlayStatusSec) return;
Chris@45 2736
Chris@45 2737 RealTime then = RealTime::frame2RealTime
Chris@45 2738 (m_playSource->getPlayEndFrame(), getMainModel()->getSampleRate());
Chris@45 2739
Chris@45 2740 QString nowStr;
Chris@45 2741 QString thenStr;
Chris@45 2742 QString remainingStr;
Chris@45 2743
Chris@45 2744 if (then.sec > 10) {
Chris@45 2745 nowStr = now.toSecText().c_str();
Chris@45 2746 thenStr = then.toSecText().c_str();
Chris@45 2747 remainingStr = (then - now).toSecText().c_str();
Chris@45 2748 m_lastPlayStatusSec = now.sec;
Chris@45 2749 } else {
Chris@45 2750 nowStr = now.toText(true).c_str();
Chris@45 2751 thenStr = then.toText(true).c_str();
Chris@45 2752 remainingStr = (then - now).toText(true).c_str();
Chris@45 2753 }
Chris@45 2754
Chris@45 2755 m_myStatusMessage = tr("Playing: %1 of %2 (%3 remaining)")
Chris@45 2756 .arg(nowStr).arg(thenStr).arg(remainingStr);
Chris@45 2757
Chris@45 2758 statusBar()->showMessage(m_myStatusMessage);
Chris@45 2759 }
Chris@45 2760
Chris@45 2761 void
Chris@45 2762 MainWindowBase::globalCentreFrameChanged(unsigned long )
Chris@45 2763 {
Chris@45 2764 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
Chris@45 2765 Pane *p = 0;
Chris@45 2766 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
Chris@45 2767 if (!p->getFollowGlobalPan()) return;
Chris@45 2768 updateVisibleRangeDisplay(p);
Chris@45 2769 }
Chris@45 2770
Chris@45 2771 void
Chris@123 2772 MainWindowBase::viewCentreFrameChanged(View *v, unsigned long frame)
Chris@45 2773 {
Chris@130 2774 // std::cerr << "MainWindowBase::viewCentreFrameChanged(" << v << "," << frame << ")" << std::endl;
Chris@123 2775
Chris@123 2776 if (m_viewDataDialogMap.find(v) != m_viewDataDialogMap.end()) {
Chris@123 2777 for (DataDialogSet::iterator i = m_viewDataDialogMap[v].begin();
Chris@123 2778 i != m_viewDataDialogMap[v].end(); ++i) {
Chris@127 2779 (*i)->userScrolledToFrame(frame);
Chris@123 2780 }
Chris@123 2781 }
Chris@45 2782 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
Chris@45 2783 Pane *p = 0;
Chris@45 2784 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
Chris@45 2785 if (v == p) updateVisibleRangeDisplay(p);
Chris@45 2786 }
Chris@45 2787
Chris@45 2788 void
Chris@45 2789 MainWindowBase::viewZoomLevelChanged(View *v, unsigned long , bool )
Chris@45 2790 {
Chris@45 2791 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
Chris@45 2792 Pane *p = 0;
Chris@45 2793 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
Chris@45 2794 if (v == p) updateVisibleRangeDisplay(p);
Chris@45 2795 }
Chris@45 2796
Chris@45 2797 void
Chris@45 2798 MainWindowBase::layerAdded(Layer *)
Chris@45 2799 {
Chris@45 2800 // std::cerr << "MainWindowBase::layerAdded(" << layer << ")" << std::endl;
Chris@45 2801 updateMenuStates();
Chris@45 2802 }
Chris@45 2803
Chris@45 2804 void
Chris@45 2805 MainWindowBase::layerRemoved(Layer *)
Chris@45 2806 {
Chris@45 2807 // std::cerr << "MainWindowBase::layerRemoved(" << layer << ")" << std::endl;
Chris@45 2808 updateMenuStates();
Chris@45 2809 }
Chris@45 2810
Chris@45 2811 void
Chris@45 2812 MainWindowBase::layerAboutToBeDeleted(Layer *layer)
Chris@45 2813 {
Chris@132 2814 // std::cerr << "MainWindowBase::layerAboutToBeDeleted(" << layer << ")" << std::endl;
Chris@123 2815
Chris@128 2816 removeLayerEditDialog(layer);
Chris@123 2817
Chris@47 2818 if (m_timeRulerLayer && (layer == m_timeRulerLayer)) {
Chris@45 2819 // std::cerr << "(this is the time ruler layer)" << std::endl;
Chris@45 2820 m_timeRulerLayer = 0;
Chris@45 2821 }
Chris@45 2822 }
Chris@45 2823
Chris@45 2824 void
Chris@45 2825 MainWindowBase::layerInAView(Layer *layer, bool inAView)
Chris@45 2826 {
Chris@132 2827 // std::cerr << "MainWindowBase::layerInAView(" << layer << "," << inAView << ")" << std::endl;
Chris@128 2828
Chris@128 2829 if (!inAView) removeLayerEditDialog(layer);
Chris@45 2830
Chris@45 2831 // Check whether we need to add or remove model from play source
Chris@45 2832 Model *model = layer->getModel();
Chris@45 2833 if (model) {
Chris@45 2834 if (inAView) {
Chris@45 2835 m_playSource->addModel(model);
Chris@45 2836 } else {
Chris@45 2837 bool found = false;
Chris@45 2838 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@45 2839 Pane *pane = m_paneStack->getPane(i);
Chris@45 2840 if (!pane) continue;
Chris@45 2841 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@45 2842 Layer *pl = pane->getLayer(j);
Chris@183 2843 if (pl &&
Chris@183 2844 !dynamic_cast<TimeRulerLayer *>(pl) &&
Chris@183 2845 (pl->getModel() == model)) {
Chris@45 2846 found = true;
Chris@45 2847 break;
Chris@45 2848 }
Chris@45 2849 }
Chris@45 2850 if (found) break;
Chris@45 2851 }
Chris@173 2852 if (!found) {
Chris@173 2853 m_playSource->removeModel(model);
Chris@173 2854 }
Chris@45 2855 }
Chris@45 2856 }
Chris@45 2857
Chris@45 2858 updateMenuStates();
Chris@45 2859 }
Chris@45 2860
Chris@45 2861 void
Chris@128 2862 MainWindowBase::removeLayerEditDialog(Layer *layer)
Chris@128 2863 {
Chris@128 2864 if (m_layerDataDialogMap.find(layer) != m_layerDataDialogMap.end()) {
Chris@128 2865
Chris@128 2866 ModelDataTableDialog *dialog = m_layerDataDialogMap[layer];
Chris@128 2867
Chris@128 2868 for (ViewDataDialogMap::iterator vi = m_viewDataDialogMap.begin();
Chris@128 2869 vi != m_viewDataDialogMap.end(); ++vi) {
Chris@128 2870 vi->second.erase(dialog);
Chris@128 2871 }
Chris@128 2872
Chris@128 2873 m_layerDataDialogMap.erase(layer);
Chris@128 2874 delete dialog;
Chris@128 2875 }
Chris@128 2876 }
Chris@128 2877
Chris@128 2878 void
Chris@45 2879 MainWindowBase::modelAdded(Model *model)
Chris@45 2880 {
Chris@45 2881 // std::cerr << "MainWindowBase::modelAdded(" << model << ")" << std::endl;
Chris@45 2882 m_playSource->addModel(model);
Chris@45 2883 }
Chris@45 2884
Chris@45 2885 void
Chris@45 2886 MainWindowBase::mainModelChanged(WaveFileModel *model)
Chris@45 2887 {
Chris@45 2888 // std::cerr << "MainWindowBase::mainModelChanged(" << model << ")" << std::endl;
Chris@45 2889 updateDescriptionLabel();
Chris@45 2890 if (model) m_viewManager->setMainModelSampleRate(model->getSampleRate());
Chris@45 2891 if (model && !m_playTarget && m_audioOutput) createPlayTarget();
Chris@45 2892 }
Chris@45 2893
Chris@45 2894 void
Chris@45 2895 MainWindowBase::modelAboutToBeDeleted(Model *model)
Chris@45 2896 {
Chris@45 2897 // std::cerr << "MainWindowBase::modelAboutToBeDeleted(" << model << ")" << std::endl;
Chris@45 2898 if (model == m_viewManager->getPlaybackModel()) {
Chris@45 2899 m_viewManager->setPlaybackModel(0);
Chris@45 2900 }
Chris@45 2901 m_playSource->removeModel(model);
Chris@45 2902 FFTDataServer::modelAboutToBeDeleted(model);
Chris@45 2903 }
Chris@45 2904
Chris@45 2905 void
Chris@55 2906 MainWindowBase::paneDeleteButtonClicked(Pane *pane)
Chris@55 2907 {
Chris@55 2908 bool found = false;
Chris@55 2909 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@55 2910 if (m_paneStack->getPane(i) == pane) {
Chris@55 2911 found = true;
Chris@55 2912 break;
Chris@55 2913 }
Chris@55 2914 }
Chris@55 2915 if (!found) {
Chris@55 2916 std::cerr << "MainWindowBase::paneDeleteButtonClicked: Unknown pane "
Chris@55 2917 << pane << std::endl;
Chris@55 2918 return;
Chris@55 2919 }
Chris@55 2920
Chris@55 2921 CommandHistory::getInstance()->startCompoundOperation
Chris@55 2922 (tr("Delete Pane"), true);
Chris@55 2923
Chris@55 2924 while (pane->getLayerCount() > 0) {
Chris@55 2925 Layer *layer = pane->getLayer(0);
Chris@55 2926 if (layer) {
Chris@55 2927 m_document->removeLayerFromView(pane, layer);
Chris@55 2928 } else {
Chris@55 2929 break;
Chris@55 2930 }
Chris@55 2931 }
Chris@55 2932
Chris@55 2933 RemovePaneCommand *command = new RemovePaneCommand(this, pane);
Chris@55 2934 CommandHistory::getInstance()->addCommand(command);
Chris@55 2935
Chris@55 2936 CommandHistory::getInstance()->endCompoundOperation();
Chris@55 2937
Chris@55 2938 updateMenuStates();
Chris@55 2939 }
Chris@55 2940
Chris@55 2941 void
Chris@45 2942 MainWindowBase::pollOSC()
Chris@45 2943 {
Chris@45 2944 if (!m_oscQueue || m_oscQueue->isEmpty()) return;
Chris@45 2945 std::cerr << "MainWindowBase::pollOSC: have " << m_oscQueue->getMessagesAvailable() << " messages" << std::endl;
Chris@45 2946
Chris@45 2947 if (m_openingAudioFile) return;
Chris@45 2948
Chris@45 2949 OSCMessage message = m_oscQueue->readMessage();
Chris@45 2950
Chris@45 2951 if (message.getTarget() != 0) {
Chris@45 2952 return; //!!! for now -- this class is target 0, others not handled yet
Chris@45 2953 }
Chris@45 2954
Chris@45 2955 handleOSCMessage(message);
Chris@45 2956 }
Chris@45 2957
Chris@45 2958 void
Chris@45 2959 MainWindowBase::inProgressSelectionChanged()
Chris@45 2960 {
Chris@45 2961 Pane *currentPane = 0;
Chris@45 2962 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
Chris@45 2963 if (currentPane) updateVisibleRangeDisplay(currentPane);
Chris@45 2964 }
Chris@45 2965
Chris@45 2966 void
Chris@45 2967 MainWindowBase::contextHelpChanged(const QString &s)
Chris@45 2968 {
Chris@45 2969 if (s == "" && m_myStatusMessage != "") {
Chris@45 2970 statusBar()->showMessage(m_myStatusMessage);
Chris@45 2971 return;
Chris@45 2972 }
Chris@45 2973 statusBar()->showMessage(s);
Chris@45 2974 }
Chris@45 2975
Chris@45 2976 void
Chris@45 2977 MainWindowBase::openHelpUrl(QString url)
Chris@45 2978 {
Chris@45 2979 // This method mostly lifted from Qt Assistant source code
Chris@45 2980
Chris@45 2981 QProcess *process = new QProcess(this);
Chris@45 2982 connect(process, SIGNAL(finished(int)), process, SLOT(deleteLater()));
Chris@45 2983
Chris@45 2984 QStringList args;
Chris@45 2985
Chris@45 2986 #ifdef Q_OS_MAC
Chris@45 2987 args.append(url);
Chris@45 2988 process->start("open", args);
Chris@45 2989 #else
Chris@45 2990 #ifdef Q_OS_WIN32
Chris@45 2991
Chris@45 2992 QString pf(getenv("ProgramFiles"));
Chris@45 2993 QString command = pf + QString("\\Internet Explorer\\IEXPLORE.EXE");
Chris@45 2994
Chris@45 2995 args.append(url);
Chris@45 2996 process->start(command, args);
Chris@45 2997
Chris@45 2998 #else
Chris@45 2999 #ifdef Q_WS_X11
Chris@45 3000 if (!qgetenv("KDE_FULL_SESSION").isEmpty()) {
Chris@45 3001 args.append("exec");
Chris@45 3002 args.append(url);
Chris@45 3003 process->start("kfmclient", args);
Chris@45 3004 } else if (!qgetenv("BROWSER").isEmpty()) {
Chris@45 3005 args.append(url);
Chris@45 3006 process->start(qgetenv("BROWSER"), args);
Chris@45 3007 } else {
Chris@45 3008 args.append(url);
Chris@45 3009 process->start("firefox", args);
Chris@45 3010 }
Chris@45 3011 #endif
Chris@45 3012 #endif
Chris@45 3013 #endif
Chris@45 3014 }
Chris@45 3015
Chris@180 3016