annotate framework/MainWindowBase.cpp @ 352:1d8cb0d92f4b

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