annotate framework/MainWindowBase.cpp @ 469:85e7d2418d9a 3.0-integration

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