annotate framework/MainWindowBase.cpp @ 484:01aeda073720 tony-2.0-integration

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