annotate framework/MainWindowBase.cpp @ 429:a9141963b580 alignment_view

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