annotate framework/MainWindowBase.cpp @ 379:6a84102c006a

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