annotate framework/MainWindowBase.cpp @ 337:1e3af7f4fa86 tony_integration

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