annotate framework/MainWindowBase.cpp @ 591:77d33ed8e753

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