annotate framework/MainWindowBase.cpp @ 366:0876ea394902 warnfix_no_size_t

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