annotate framework/MainWindowBase.cpp @ 222:ed5804224121 templating

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