annotate framework/MainWindowBase.cpp @ 217:64dfa7d6171d sv_v1.8

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