annotate framework/MainWindowBase.cpp @ 538:287fce13a1ae subdivide-instants

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