annotate framework/MainWindowBase.cpp @ 377:3c724eac1798

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