annotate framework/MainWindowBase.cpp @ 384:ad33fdc4ad92 tonioni

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