annotate framework/MainWindowBase.cpp @ 475:f93820d36cb0 recording

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