annotate framework/MainWindowBase.cpp @ 392:75af0658be84

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