annotate framework/MainWindowBase.cpp @ 129:df5f16b3c925

* Fix two problems reported by Matthias in the data editor window: - highlighted row was incorrect (it was highlighting the row for the next item after the current position, not the one before it as it should be) - making a row current moved the centre frame of the view, but did not change the playback position as it should do
author Chris Cannam
date Thu, 26 Jun 2008 12:41:23 +0000
parents 09e6016c5436
children 4c9c04645685
rev   line source
Chris@45 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@45 2
Chris@45 3 /*
Chris@45 4 Sonic Visualiser
Chris@45 5 An audio file viewer and annotation editor.
Chris@45 6 Centre for Digital Music, Queen Mary, University of London.
Chris@45 7 This file copyright 2006-2007 Chris Cannam and QMUL.
Chris@45 8
Chris@45 9 This program is free software; you can redistribute it and/or
Chris@45 10 modify it under the terms of the GNU General Public License as
Chris@45 11 published by the Free Software Foundation; either version 2 of the
Chris@45 12 License, or (at your option) any later version. See the file
Chris@45 13 COPYING included with this distribution for more information.
Chris@45 14 */
Chris@45 15
Chris@45 16 #include "MainWindowBase.h"
Chris@46 17 #include "Document.h"
Chris@45 18
Chris@45 19
Chris@45 20 #include "view/Pane.h"
Chris@45 21 #include "view/PaneStack.h"
Chris@45 22 #include "data/model/WaveFileModel.h"
Chris@45 23 #include "data/model/SparseOneDimensionalModel.h"
Chris@45 24 #include "data/model/NoteModel.h"
Chris@45 25 #include "data/model/Labeller.h"
Chris@124 26 #include "data/model/TabularModel.h"
Chris@45 27 #include "view/ViewManager.h"
Chris@45 28
Chris@45 29 #include "layer/WaveformLayer.h"
Chris@45 30 #include "layer/TimeRulerLayer.h"
Chris@45 31 #include "layer/TimeInstantLayer.h"
Chris@45 32 #include "layer/TimeValueLayer.h"
Chris@45 33 #include "layer/Colour3DPlotLayer.h"
Chris@45 34 #include "layer/SliceLayer.h"
Chris@45 35 #include "layer/SliceableLayer.h"
Chris@45 36 #include "layer/ImageLayer.h"
Chris@45 37
Chris@45 38 #include "widgets/ListInputDialog.h"
Chris@105 39 #include "widgets/CommandHistory.h"
Chris@109 40 #include "widgets/ProgressDialog.h"
Chris@109 41 #include "widgets/MIDIFileImportDialog.h"
Chris@109 42 #include "widgets/CSVFormatDialog.h"
Chris@123 43 #include "widgets/ModelDataTableDialog.h"
Chris@45 44
Chris@45 45 #include "audioio/AudioCallbackPlaySource.h"
Chris@45 46 #include "audioio/AudioCallbackPlayTarget.h"
Chris@45 47 #include "audioio/AudioTargetFactory.h"
Chris@45 48 #include "audioio/PlaySpeedRangeMapper.h"
Chris@45 49 #include "data/fileio/DataFileReaderFactory.h"
Chris@45 50 #include "data/fileio/PlaylistFileReader.h"
Chris@45 51 #include "data/fileio/WavFileWriter.h"
Chris@45 52 #include "data/fileio/CSVFileWriter.h"
Chris@45 53 #include "data/fileio/MIDIFileWriter.h"
Chris@45 54 #include "data/fileio/BZipFileDevice.h"
Chris@45 55 #include "data/fileio/FileSource.h"
Chris@45 56
Chris@45 57 #include "data/fft/FFTDataServer.h"
Chris@45 58
Chris@45 59 #include "base/RecentFiles.h"
Chris@45 60
Chris@45 61 #include "base/PlayParameterRepository.h"
Chris@45 62 #include "base/XmlExportable.h"
Chris@45 63 #include "base/Profiler.h"
Chris@45 64 #include "base/Preferences.h"
Chris@45 65
Chris@45 66 #include "data/osc/OSCQueue.h"
Chris@45 67
Chris@45 68 #include <QApplication>
Chris@45 69 #include <QMessageBox>
Chris@45 70 #include <QGridLayout>
Chris@45 71 #include <QLabel>
Chris@45 72 #include <QAction>
Chris@45 73 #include <QMenuBar>
Chris@45 74 #include <QToolBar>
Chris@45 75 #include <QInputDialog>
Chris@45 76 #include <QStatusBar>
Chris@45 77 #include <QTreeView>
Chris@45 78 #include <QFile>
Chris@45 79 #include <QFileInfo>
Chris@45 80 #include <QDir>
Chris@45 81 #include <QTextStream>
Chris@45 82 #include <QProcess>
Chris@45 83 #include <QShortcut>
Chris@45 84 #include <QSettings>
Chris@45 85 #include <QDateTime>
Chris@45 86 #include <QProcess>
Chris@45 87 #include <QCheckBox>
Chris@45 88 #include <QRegExp>
Chris@45 89 #include <QScrollArea>
Chris@45 90
Chris@45 91 #include <iostream>
Chris@45 92 #include <cstdio>
Chris@45 93 #include <errno.h>
Chris@45 94
Chris@45 95 using std::cerr;
Chris@45 96 using std::endl;
Chris@45 97
Chris@45 98 using std::vector;
Chris@45 99 using std::map;
Chris@45 100 using std::set;
Chris@45 101
Chris@45 102
Chris@45 103 MainWindowBase::MainWindowBase(bool withAudioOutput, bool withOSCSupport) :
Chris@45 104 m_document(0),
Chris@45 105 m_paneStack(0),
Chris@45 106 m_viewManager(0),
Chris@45 107 m_timeRulerLayer(0),
Chris@45 108 m_audioOutput(withAudioOutput),
Chris@45 109 m_playSource(0),
Chris@45 110 m_playTarget(0),
Chris@113 111 m_oscQueue(0),
Chris@113 112 m_oscQueueStarter(0),
Chris@45 113 m_recentFiles("RecentFiles", 20),
Chris@54 114 m_recentTransforms("RecentTransforms", 20),
Chris@45 115 m_documentModified(false),
Chris@45 116 m_openingAudioFile(false),
Chris@45 117 m_abandoning(false),
Chris@121 118 m_labeller(0),
Chris@121 119 m_lastPlayStatusSec(0)
Chris@45 120 {
Chris@113 121 Profiler profiler("MainWindowBase::MainWindowBase");
Chris@113 122
Chris@45 123 connect(CommandHistory::getInstance(), SIGNAL(commandExecuted()),
Chris@45 124 this, SLOT(documentModified()));
Chris@45 125 connect(CommandHistory::getInstance(), SIGNAL(documentRestored()),
Chris@45 126 this, SLOT(documentRestored()));
Chris@45 127
Chris@45 128 m_viewManager = new ViewManager();
Chris@45 129 connect(m_viewManager, SIGNAL(selectionChanged()),
Chris@45 130 this, SLOT(updateMenuStates()));
Chris@45 131 connect(m_viewManager, SIGNAL(inProgressSelectionChanged()),
Chris@45 132 this, SLOT(inProgressSelectionChanged()));
Chris@45 133
Chris@105 134 // set a sensible default font size for views -- cannot do this
Chris@105 135 // in Preferences, which is in base and not supposed to use QtGui
Chris@105 136 int viewFontSize = QApplication::font().pointSize() * 0.9;
Chris@105 137 QSettings settings;
Chris@105 138 settings.beginGroup("Preferences");
Chris@105 139 viewFontSize = settings.value("view-font-size", viewFontSize).toInt();
Chris@105 140 settings.setValue("view-font-size", viewFontSize);
Chris@105 141 settings.endGroup();
Chris@105 142
Chris@45 143 Preferences::BackgroundMode mode =
Chris@45 144 Preferences::getInstance()->getBackgroundMode();
Chris@45 145 m_initialDarkBackground = m_viewManager->getGlobalDarkBackground();
Chris@45 146 if (mode != Preferences::BackgroundFromTheme) {
Chris@45 147 m_viewManager->setGlobalDarkBackground
Chris@45 148 (mode == Preferences::DarkBackground);
Chris@45 149 }
Chris@45 150
Chris@45 151 m_paneStack = new PaneStack(0, m_viewManager);
Chris@45 152 connect(m_paneStack, SIGNAL(currentPaneChanged(Pane *)),
Chris@45 153 this, SLOT(currentPaneChanged(Pane *)));
Chris@45 154 connect(m_paneStack, SIGNAL(currentLayerChanged(Pane *, Layer *)),
Chris@45 155 this, SLOT(currentLayerChanged(Pane *, Layer *)));
Chris@45 156 connect(m_paneStack, SIGNAL(rightButtonMenuRequested(Pane *, QPoint)),
Chris@45 157 this, SLOT(rightButtonMenuRequested(Pane *, QPoint)));
Chris@45 158 connect(m_paneStack, SIGNAL(contextHelpChanged(const QString &)),
Chris@45 159 this, SLOT(contextHelpChanged(const QString &)));
Chris@45 160 connect(m_paneStack, SIGNAL(paneAdded(Pane *)),
Chris@45 161 this, SLOT(paneAdded(Pane *)));
Chris@45 162 connect(m_paneStack, SIGNAL(paneHidden(Pane *)),
Chris@45 163 this, SLOT(paneHidden(Pane *)));
Chris@45 164 connect(m_paneStack, SIGNAL(paneAboutToBeDeleted(Pane *)),
Chris@45 165 this, SLOT(paneAboutToBeDeleted(Pane *)));
Chris@45 166 connect(m_paneStack, SIGNAL(dropAccepted(Pane *, QStringList)),
Chris@45 167 this, SLOT(paneDropAccepted(Pane *, QStringList)));
Chris@45 168 connect(m_paneStack, SIGNAL(dropAccepted(Pane *, QString)),
Chris@45 169 this, SLOT(paneDropAccepted(Pane *, QString)));
Chris@55 170 connect(m_paneStack, SIGNAL(paneDeleteButtonClicked(Pane *)),
Chris@55 171 this, SLOT(paneDeleteButtonClicked(Pane *)));
Chris@45 172
Chris@57 173 m_playSource = new AudioCallbackPlaySource(m_viewManager,
Chris@57 174 QApplication::applicationName());
Chris@45 175
Chris@45 176 connect(m_playSource, SIGNAL(sampleRateMismatch(size_t, size_t, bool)),
Chris@45 177 this, SLOT(sampleRateMismatch(size_t, size_t, bool)));
Chris@45 178 connect(m_playSource, SIGNAL(audioOverloadPluginDisabled()),
Chris@45 179 this, SLOT(audioOverloadPluginDisabled()));
Chris@45 180
Chris@45 181 connect(m_viewManager, SIGNAL(outputLevelsChanged(float, float)),
Chris@45 182 this, SLOT(outputLevelsChanged(float, float)));
Chris@45 183
Chris@45 184 connect(m_viewManager, SIGNAL(playbackFrameChanged(unsigned long)),
Chris@45 185 this, SLOT(playbackFrameChanged(unsigned long)));
Chris@45 186
Chris@45 187 connect(m_viewManager, SIGNAL(globalCentreFrameChanged(unsigned long)),
Chris@45 188 this, SLOT(globalCentreFrameChanged(unsigned long)));
Chris@45 189
Chris@45 190 connect(m_viewManager, SIGNAL(viewCentreFrameChanged(View *, unsigned long)),
Chris@45 191 this, SLOT(viewCentreFrameChanged(View *, unsigned long)));
Chris@45 192
Chris@45 193 connect(m_viewManager, SIGNAL(viewZoomLevelChanged(View *, unsigned long, bool)),
Chris@45 194 this, SLOT(viewZoomLevelChanged(View *, unsigned long, bool)));
Chris@45 195
Chris@45 196 connect(Preferences::getInstance(),
Chris@45 197 SIGNAL(propertyChanged(PropertyContainer::PropertyName)),
Chris@45 198 this,
Chris@45 199 SLOT(preferenceChanged(PropertyContainer::PropertyName)));
Chris@45 200
Chris@45 201 Labeller::ValueType labellerType = Labeller::ValueFromTwoLevelCounter;
Chris@45 202 settings.beginGroup("MainWindow");
Chris@45 203 labellerType = (Labeller::ValueType)
Chris@45 204 settings.value("labellertype", (int)labellerType).toInt();
Chris@45 205 int cycle = settings.value("labellercycle", 4).toInt();
Chris@45 206 settings.endGroup();
Chris@45 207
Chris@45 208 m_labeller = new Labeller(labellerType);
Chris@45 209 m_labeller->setCounterCycleSize(cycle);
Chris@113 210
Chris@113 211 if (withOSCSupport) {
Chris@113 212 m_oscQueueStarter = new OSCQueueStarter(this);
Chris@113 213 connect(m_oscQueueStarter, SIGNAL(finished()), this, SLOT(oscReady()));
Chris@113 214 m_oscQueueStarter->start();
Chris@113 215 }
Chris@45 216 }
Chris@45 217
Chris@45 218 MainWindowBase::~MainWindowBase()
Chris@45 219 {
Chris@70 220 if (m_playTarget) m_playTarget->shutdown();
Chris@70 221 // delete m_playTarget;
Chris@45 222 delete m_playSource;
Chris@45 223 delete m_viewManager;
Chris@45 224 delete m_oscQueue;
Chris@45 225 Profiles::getInstance()->dump();
Chris@45 226 }
Chris@45 227
Chris@113 228 void
Chris@113 229 MainWindowBase::oscReady()
Chris@113 230 {
Chris@113 231 if (m_oscQueue && m_oscQueue->isOK()) {
Chris@113 232 connect(m_oscQueue, SIGNAL(messagesAvailable()), this, SLOT(pollOSC()));
Chris@113 233 QTimer *oscTimer = new QTimer(this);
Chris@113 234 connect(oscTimer, SIGNAL(timeout()), this, SLOT(pollOSC()));
Chris@113 235 oscTimer->start(1000);
Chris@113 236 std::cerr << "Finished setting up OSC interface" << std::endl;
Chris@113 237 }
Chris@113 238 }
Chris@113 239
Chris@45 240 QString
Chris@45 241 MainWindowBase::getOpenFileName(FileFinder::FileType type)
Chris@45 242 {
Chris@45 243 FileFinder *ff = FileFinder::getInstance();
Chris@45 244 switch (type) {
Chris@45 245 case FileFinder::SessionFile:
Chris@45 246 return ff->getOpenFileName(type, m_sessionFile);
Chris@45 247 case FileFinder::AudioFile:
Chris@45 248 return ff->getOpenFileName(type, m_audioFile);
Chris@45 249 case FileFinder::LayerFile:
Chris@45 250 return ff->getOpenFileName(type, m_sessionFile);
Chris@45 251 case FileFinder::LayerFileNoMidi:
Chris@45 252 return ff->getOpenFileName(type, m_sessionFile);
Chris@45 253 case FileFinder::SessionOrAudioFile:
Chris@45 254 return ff->getOpenFileName(type, m_sessionFile);
Chris@45 255 case FileFinder::ImageFile:
Chris@45 256 return ff->getOpenFileName(type, m_sessionFile);
Chris@45 257 case FileFinder::AnyFile:
Chris@45 258 if (getMainModel() != 0 &&
Chris@45 259 m_paneStack != 0 &&
Chris@45 260 m_paneStack->getCurrentPane() != 0) { // can import a layer
Chris@45 261 return ff->getOpenFileName(FileFinder::AnyFile, m_sessionFile);
Chris@45 262 } else {
Chris@45 263 return ff->getOpenFileName(FileFinder::SessionOrAudioFile,
Chris@45 264 m_sessionFile);
Chris@45 265 }
Chris@45 266 }
Chris@45 267 return "";
Chris@45 268 }
Chris@45 269
Chris@45 270 QString
Chris@45 271 MainWindowBase::getSaveFileName(FileFinder::FileType type)
Chris@45 272 {
Chris@45 273 FileFinder *ff = FileFinder::getInstance();
Chris@45 274 switch (type) {
Chris@45 275 case FileFinder::SessionFile:
Chris@45 276 return ff->getSaveFileName(type, m_sessionFile);
Chris@45 277 case FileFinder::AudioFile:
Chris@45 278 return ff->getSaveFileName(type, m_audioFile);
Chris@45 279 case FileFinder::LayerFile:
Chris@45 280 return ff->getSaveFileName(type, m_sessionFile);
Chris@45 281 case FileFinder::LayerFileNoMidi:
Chris@45 282 return ff->getSaveFileName(type, m_sessionFile);
Chris@45 283 case FileFinder::SessionOrAudioFile:
Chris@45 284 return ff->getSaveFileName(type, m_sessionFile);
Chris@45 285 case FileFinder::ImageFile:
Chris@45 286 return ff->getSaveFileName(type, m_sessionFile);
Chris@45 287 case FileFinder::AnyFile:
Chris@45 288 return ff->getSaveFileName(type, m_sessionFile);
Chris@45 289 }
Chris@45 290 return "";
Chris@45 291 }
Chris@45 292
Chris@45 293 void
Chris@45 294 MainWindowBase::registerLastOpenedFilePath(FileFinder::FileType type, QString path)
Chris@45 295 {
Chris@45 296 FileFinder *ff = FileFinder::getInstance();
Chris@45 297 ff->registerLastOpenedFilePath(type, path);
Chris@45 298 }
Chris@45 299
Chris@45 300 void
Chris@45 301 MainWindowBase::updateMenuStates()
Chris@45 302 {
Chris@45 303 Pane *currentPane = 0;
Chris@45 304 Layer *currentLayer = 0;
Chris@45 305
Chris@45 306 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
Chris@45 307 if (currentPane) currentLayer = currentPane->getSelectedLayer();
Chris@45 308
Chris@73 309 bool havePrevPane = false, haveNextPane = false;
Chris@73 310 bool havePrevLayer = false, haveNextLayer = false;
Chris@73 311
Chris@73 312 if (currentPane) {
Chris@73 313 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@73 314 if (m_paneStack->getPane(i) == currentPane) {
Chris@73 315 if (i > 0) havePrevPane = true;
Chris@73 316 if (i < m_paneStack->getPaneCount()-1) haveNextPane = true;
Chris@73 317 break;
Chris@73 318 }
Chris@73 319 }
Chris@73 320 if (currentLayer) {
Chris@73 321 for (int i = 0; i < currentPane->getLayerCount(); ++i) {
Chris@73 322 if (currentPane->getLayer(i) == currentLayer) {
Chris@73 323 if (i > 0) havePrevLayer = true;
Chris@73 324 if (i < currentPane->getLayerCount()-1) haveNextLayer = true;
Chris@73 325 break;
Chris@73 326 }
Chris@73 327 }
Chris@73 328 }
Chris@73 329 }
Chris@73 330
Chris@45 331 bool haveCurrentPane =
Chris@45 332 (currentPane != 0);
Chris@45 333 bool haveCurrentLayer =
Chris@45 334 (haveCurrentPane &&
Chris@45 335 (currentLayer != 0));
Chris@45 336 bool haveMainModel =
Chris@45 337 (getMainModel() != 0);
Chris@45 338 bool havePlayTarget =
Chris@45 339 (m_playTarget != 0);
Chris@45 340 bool haveSelection =
Chris@45 341 (m_viewManager &&
Chris@45 342 !m_viewManager->getSelections().empty());
Chris@45 343 bool haveCurrentEditableLayer =
Chris@45 344 (haveCurrentLayer &&
Chris@45 345 currentLayer->isLayerEditable());
Chris@45 346 bool haveCurrentTimeInstantsLayer =
Chris@45 347 (haveCurrentLayer &&
Chris@45 348 dynamic_cast<TimeInstantLayer *>(currentLayer));
Chris@45 349 bool haveCurrentColour3DPlot =
Chris@45 350 (haveCurrentLayer &&
Chris@45 351 dynamic_cast<Colour3DPlotLayer *>(currentLayer));
Chris@45 352 bool haveClipboardContents =
Chris@45 353 (m_viewManager &&
Chris@45 354 !m_viewManager->getClipboard().empty());
Chris@45 355
Chris@45 356 emit canAddPane(haveMainModel);
Chris@45 357 emit canDeleteCurrentPane(haveCurrentPane);
Chris@45 358 emit canZoom(haveMainModel && haveCurrentPane);
Chris@45 359 emit canScroll(haveMainModel && haveCurrentPane);
Chris@45 360 emit canAddLayer(haveMainModel && haveCurrentPane);
Chris@45 361 emit canImportMoreAudio(haveMainModel);
Chris@45 362 emit canImportLayer(haveMainModel && haveCurrentPane);
Chris@45 363 emit canExportAudio(haveMainModel);
Chris@45 364 emit canExportLayer(haveMainModel &&
Chris@45 365 (haveCurrentEditableLayer || haveCurrentColour3DPlot));
Chris@45 366 emit canExportImage(haveMainModel && haveCurrentPane);
Chris@45 367 emit canDeleteCurrentLayer(haveCurrentLayer);
Chris@45 368 emit canRenameLayer(haveCurrentLayer);
Chris@45 369 emit canEditLayer(haveCurrentEditableLayer);
Chris@45 370 emit canMeasureLayer(haveCurrentLayer);
Chris@45 371 emit canSelect(haveMainModel && haveCurrentPane);
Chris@45 372 emit canPlay(havePlayTarget);
Chris@45 373 emit canFfwd(true);
Chris@45 374 emit canRewind(true);
Chris@87 375 emit canPaste(haveClipboardContents);
Chris@45 376 emit canInsertInstant(haveCurrentPane);
Chris@45 377 emit canInsertInstantsAtBoundaries(haveCurrentPane && haveSelection);
Chris@45 378 emit canRenumberInstants(haveCurrentTimeInstantsLayer && haveSelection);
Chris@45 379 emit canPlaySelection(haveMainModel && havePlayTarget && haveSelection);
Chris@45 380 emit canClearSelection(haveSelection);
Chris@45 381 emit canEditSelection(haveSelection && haveCurrentEditableLayer);
Chris@45 382 emit canSave(m_sessionFile != "" && m_documentModified);
Chris@73 383 emit canSelectPreviousPane(havePrevPane);
Chris@73 384 emit canSelectNextPane(haveNextPane);
Chris@73 385 emit canSelectPreviousLayer(havePrevLayer);
Chris@73 386 emit canSelectNextLayer(haveNextLayer);
Chris@45 387 }
Chris@45 388
Chris@45 389 void
Chris@45 390 MainWindowBase::documentModified()
Chris@45 391 {
Chris@45 392 // std::cerr << "MainWindowBase::documentModified" << std::endl;
Chris@45 393
Chris@45 394 if (!m_documentModified) {
Chris@45 395 //!!! this in subclass implementation?
Chris@45 396 setWindowTitle(tr("%1 (modified)").arg(windowTitle()));
Chris@45 397 }
Chris@45 398
Chris@45 399 m_documentModified = true;
Chris@45 400 updateMenuStates();
Chris@45 401 }
Chris@45 402
Chris@45 403 void
Chris@45 404 MainWindowBase::documentRestored()
Chris@45 405 {
Chris@45 406 // std::cerr << "MainWindowBase::documentRestored" << std::endl;
Chris@45 407
Chris@45 408 if (m_documentModified) {
Chris@45 409 //!!! this in subclass implementation?
Chris@45 410 QString wt(windowTitle());
Chris@45 411 wt.replace(tr(" (modified)"), "");
Chris@45 412 setWindowTitle(wt);
Chris@45 413 }
Chris@45 414
Chris@45 415 m_documentModified = false;
Chris@45 416 updateMenuStates();
Chris@45 417 }
Chris@45 418
Chris@45 419 void
Chris@45 420 MainWindowBase::playLoopToggled()
Chris@45 421 {
Chris@45 422 QAction *action = dynamic_cast<QAction *>(sender());
Chris@45 423
Chris@45 424 if (action) {
Chris@45 425 m_viewManager->setPlayLoopMode(action->isChecked());
Chris@45 426 } else {
Chris@45 427 m_viewManager->setPlayLoopMode(!m_viewManager->getPlayLoopMode());
Chris@45 428 }
Chris@45 429 }
Chris@45 430
Chris@45 431 void
Chris@45 432 MainWindowBase::playSelectionToggled()
Chris@45 433 {
Chris@45 434 QAction *action = dynamic_cast<QAction *>(sender());
Chris@45 435
Chris@45 436 if (action) {
Chris@45 437 m_viewManager->setPlaySelectionMode(action->isChecked());
Chris@45 438 } else {
Chris@45 439 m_viewManager->setPlaySelectionMode(!m_viewManager->getPlaySelectionMode());
Chris@45 440 }
Chris@45 441 }
Chris@45 442
Chris@45 443 void
Chris@45 444 MainWindowBase::playSoloToggled()
Chris@45 445 {
Chris@45 446 QAction *action = dynamic_cast<QAction *>(sender());
Chris@45 447
Chris@45 448 if (action) {
Chris@45 449 m_viewManager->setPlaySoloMode(action->isChecked());
Chris@45 450 } else {
Chris@45 451 m_viewManager->setPlaySoloMode(!m_viewManager->getPlaySoloMode());
Chris@45 452 }
Chris@45 453
Chris@45 454 if (m_viewManager->getPlaySoloMode()) {
Chris@45 455 currentPaneChanged(m_paneStack->getCurrentPane());
Chris@45 456 } else {
Chris@45 457 m_viewManager->setPlaybackModel(0);
Chris@45 458 if (m_playSource) {
Chris@45 459 m_playSource->clearSoloModelSet();
Chris@45 460 }
Chris@45 461 }
Chris@45 462 }
Chris@45 463
Chris@45 464 void
Chris@45 465 MainWindowBase::currentPaneChanged(Pane *p)
Chris@45 466 {
Chris@45 467 updateMenuStates();
Chris@45 468 updateVisibleRangeDisplay(p);
Chris@45 469
Chris@45 470 if (!p) return;
Chris@45 471
Chris@45 472 if (!(m_viewManager &&
Chris@45 473 m_playSource &&
Chris@45 474 m_viewManager->getPlaySoloMode())) {
Chris@45 475 if (m_viewManager) m_viewManager->setPlaybackModel(0);
Chris@45 476 return;
Chris@45 477 }
Chris@45 478
Chris@45 479 Model *prevPlaybackModel = m_viewManager->getPlaybackModel();
Chris@60 480
Chris@93 481 // What we want here is not the currently playing frame (unless we
Chris@93 482 // are about to clear out the audio playback buffers -- which may
Chris@93 483 // or may not be possible, depending on the audio driver). What
Chris@93 484 // we want is the frame that was last committed to the soundcard
Chris@93 485 // buffers, as the audio driver will continue playing up to that
Chris@93 486 // frame before switching to whichever one we decide we want to
Chris@93 487 // switch to, regardless of our efforts.
Chris@93 488
Chris@93 489 int frame = m_playSource->getCurrentBufferedFrame();
Chris@93 490
Chris@93 491 // std::cerr << "currentPaneChanged: current frame (in ref model) = " << frame << std::endl;
Chris@45 492
Chris@45 493 View::ModelSet soloModels = p->getModels();
Chris@45 494
Chris@57 495 View::ModelSet sources;
Chris@57 496 for (View::ModelSet::iterator mi = soloModels.begin();
Chris@57 497 mi != soloModels.end(); ++mi) {
Chris@57 498 if (*mi && (*mi)->getSourceModel()) {
Chris@57 499 sources.insert((*mi)->getSourceModel());
Chris@57 500 }
Chris@57 501 }
Chris@57 502 for (View::ModelSet::iterator mi = sources.begin();
Chris@57 503 mi != sources.end(); ++mi) {
Chris@57 504 soloModels.insert(*mi);
Chris@57 505 }
Chris@57 506
Chris@60 507 //!!! Need an "atomic" way of telling the play source that the
Chris@60 508 //playback model has changed, and changing it on ViewManager --
Chris@60 509 //the play source should be making the setPlaybackModel call to
Chris@60 510 //ViewManager
Chris@60 511
Chris@45 512 for (View::ModelSet::iterator mi = soloModels.begin();
Chris@45 513 mi != soloModels.end(); ++mi) {
Chris@45 514 if (dynamic_cast<RangeSummarisableTimeValueModel *>(*mi)) {
Chris@45 515 m_viewManager->setPlaybackModel(*mi);
Chris@45 516 }
Chris@45 517 }
Chris@45 518
Chris@45 519 RangeSummarisableTimeValueModel *a =
Chris@45 520 dynamic_cast<RangeSummarisableTimeValueModel *>(prevPlaybackModel);
Chris@45 521 RangeSummarisableTimeValueModel *b =
Chris@45 522 dynamic_cast<RangeSummarisableTimeValueModel *>(m_viewManager->
Chris@45 523 getPlaybackModel());
Chris@45 524
Chris@45 525 m_playSource->setSoloModelSet(soloModels);
Chris@45 526
Chris@45 527 if (a && b && (a != b)) {
Chris@60 528 if (m_playSource->isPlaying()) m_playSource->play(frame);
Chris@45 529 }
Chris@45 530 }
Chris@45 531
Chris@45 532 void
Chris@45 533 MainWindowBase::currentLayerChanged(Pane *p, Layer *)
Chris@45 534 {
Chris@45 535 updateMenuStates();
Chris@45 536 updateVisibleRangeDisplay(p);
Chris@45 537 }
Chris@45 538
Chris@45 539 void
Chris@45 540 MainWindowBase::selectAll()
Chris@45 541 {
Chris@45 542 if (!getMainModel()) return;
Chris@45 543 m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(),
Chris@45 544 getMainModel()->getEndFrame()));
Chris@45 545 }
Chris@45 546
Chris@45 547 void
Chris@45 548 MainWindowBase::selectToStart()
Chris@45 549 {
Chris@45 550 if (!getMainModel()) return;
Chris@45 551 m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(),
Chris@45 552 m_viewManager->getGlobalCentreFrame()));
Chris@45 553 }
Chris@45 554
Chris@45 555 void
Chris@45 556 MainWindowBase::selectToEnd()
Chris@45 557 {
Chris@45 558 if (!getMainModel()) return;
Chris@45 559 m_viewManager->setSelection(Selection(m_viewManager->getGlobalCentreFrame(),
Chris@45 560 getMainModel()->getEndFrame()));
Chris@45 561 }
Chris@45 562
Chris@45 563 void
Chris@45 564 MainWindowBase::selectVisible()
Chris@45 565 {
Chris@45 566 Model *model = getMainModel();
Chris@45 567 if (!model) return;
Chris@45 568
Chris@45 569 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 570 if (!currentPane) return;
Chris@45 571
Chris@45 572 size_t startFrame, endFrame;
Chris@45 573
Chris@45 574 if (currentPane->getStartFrame() < 0) startFrame = 0;
Chris@45 575 else startFrame = currentPane->getStartFrame();
Chris@45 576
Chris@45 577 if (currentPane->getEndFrame() > model->getEndFrame()) endFrame = model->getEndFrame();
Chris@45 578 else endFrame = currentPane->getEndFrame();
Chris@45 579
Chris@45 580 m_viewManager->setSelection(Selection(startFrame, endFrame));
Chris@45 581 }
Chris@45 582
Chris@45 583 void
Chris@45 584 MainWindowBase::clearSelection()
Chris@45 585 {
Chris@45 586 m_viewManager->clearSelections();
Chris@45 587 }
Chris@45 588
Chris@45 589 void
Chris@45 590 MainWindowBase::cut()
Chris@45 591 {
Chris@45 592 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 593 if (!currentPane) return;
Chris@45 594
Chris@45 595 Layer *layer = currentPane->getSelectedLayer();
Chris@45 596 if (!layer) return;
Chris@45 597
Chris@45 598 Clipboard &clipboard = m_viewManager->getClipboard();
Chris@45 599 clipboard.clear();
Chris@45 600
Chris@45 601 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@45 602
Chris@45 603 CommandHistory::getInstance()->startCompoundOperation(tr("Cut"), true);
Chris@45 604
Chris@45 605 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@45 606 i != selections.end(); ++i) {
Chris@86 607 layer->copy(currentPane, *i, clipboard);
Chris@45 608 layer->deleteSelection(*i);
Chris@45 609 }
Chris@45 610
Chris@45 611 CommandHistory::getInstance()->endCompoundOperation();
Chris@45 612 }
Chris@45 613
Chris@45 614 void
Chris@45 615 MainWindowBase::copy()
Chris@45 616 {
Chris@45 617 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 618 if (!currentPane) return;
Chris@45 619
Chris@45 620 Layer *layer = currentPane->getSelectedLayer();
Chris@45 621 if (!layer) return;
Chris@45 622
Chris@45 623 Clipboard &clipboard = m_viewManager->getClipboard();
Chris@45 624 clipboard.clear();
Chris@45 625
Chris@45 626 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@45 627
Chris@45 628 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@45 629 i != selections.end(); ++i) {
Chris@86 630 layer->copy(currentPane, *i, clipboard);
Chris@45 631 }
Chris@45 632 }
Chris@45 633
Chris@45 634 void
Chris@45 635 MainWindowBase::paste()
Chris@45 636 {
Chris@45 637 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 638 if (!currentPane) return;
Chris@45 639
Chris@45 640 Layer *layer = currentPane->getSelectedLayer();
Chris@45 641
Chris@45 642 Clipboard &clipboard = m_viewManager->getClipboard();
Chris@87 643 // Clipboard::PointList contents = clipboard.getPoints();
Chris@87 644
Chris@98 645 bool inCompound = false;
Chris@87 646
Chris@87 647 if (!layer || !layer->isLayerEditable()) {
Chris@87 648
Chris@87 649 CommandHistory::getInstance()->startCompoundOperation
Chris@87 650 (tr("Paste"), true);
Chris@87 651
Chris@87 652 // no suitable current layer: create one of the most
Chris@87 653 // appropriate sort
Chris@87 654 LayerFactory::LayerType type =
Chris@87 655 LayerFactory::getInstance()->getLayerTypeForClipboardContents(clipboard);
Chris@87 656 layer = m_document->createEmptyLayer(type);
Chris@87 657
Chris@87 658 if (!layer) {
Chris@87 659 CommandHistory::getInstance()->endCompoundOperation();
Chris@87 660 return;
Chris@45 661 }
Chris@87 662
Chris@87 663 m_document->addLayerToView(currentPane, layer);
Chris@87 664 m_paneStack->setCurrentLayer(currentPane, layer);
Chris@87 665
Chris@87 666 inCompound = true;
Chris@45 667 }
Chris@45 668
Chris@87 669 layer->paste(currentPane, clipboard, 0, true);
Chris@45 670
Chris@87 671 if (inCompound) CommandHistory::getInstance()->endCompoundOperation();
Chris@45 672 }
Chris@45 673
Chris@45 674 void
Chris@45 675 MainWindowBase::deleteSelected()
Chris@45 676 {
Chris@45 677 if (m_paneStack->getCurrentPane() &&
Chris@45 678 m_paneStack->getCurrentPane()->getSelectedLayer()) {
Chris@45 679
Chris@45 680 Layer *layer = m_paneStack->getCurrentPane()->getSelectedLayer();
Chris@45 681
Chris@45 682 if (m_viewManager &&
Chris@45 683 (m_viewManager->getToolMode() == ViewManager::MeasureMode)) {
Chris@45 684
Chris@45 685 layer->deleteCurrentMeasureRect();
Chris@45 686
Chris@45 687 } else {
Chris@45 688
Chris@45 689 MultiSelection::SelectionList selections =
Chris@45 690 m_viewManager->getSelections();
Chris@45 691
Chris@45 692 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@45 693 i != selections.end(); ++i) {
Chris@45 694 layer->deleteSelection(*i);
Chris@45 695 }
Chris@45 696 }
Chris@45 697 }
Chris@45 698 }
Chris@45 699
Chris@45 700 void
Chris@45 701 MainWindowBase::insertInstant()
Chris@45 702 {
Chris@45 703 int frame = m_viewManager->getPlaybackFrame();
Chris@45 704 insertInstantAt(frame);
Chris@45 705 }
Chris@45 706
Chris@45 707 void
Chris@45 708 MainWindowBase::insertInstantsAtBoundaries()
Chris@45 709 {
Chris@45 710 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@45 711 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@45 712 i != selections.end(); ++i) {
Chris@45 713 size_t start = i->getStartFrame();
Chris@45 714 size_t end = i->getEndFrame();
Chris@45 715 if (start != end) {
Chris@45 716 insertInstantAt(i->getStartFrame());
Chris@45 717 insertInstantAt(i->getEndFrame());
Chris@45 718 }
Chris@45 719 }
Chris@45 720 }
Chris@45 721
Chris@45 722 void
Chris@45 723 MainWindowBase::insertInstantAt(size_t frame)
Chris@45 724 {
Chris@45 725 Pane *pane = m_paneStack->getCurrentPane();
Chris@45 726 if (!pane) {
Chris@45 727 return;
Chris@45 728 }
Chris@45 729
Chris@74 730 frame = pane->alignFromReference(frame);
Chris@74 731
Chris@45 732 Layer *layer = dynamic_cast<TimeInstantLayer *>
Chris@45 733 (pane->getSelectedLayer());
Chris@45 734
Chris@45 735 if (!layer) {
Chris@45 736 for (int i = pane->getLayerCount(); i > 0; --i) {
Chris@45 737 layer = dynamic_cast<TimeInstantLayer *>(pane->getLayer(i - 1));
Chris@45 738 if (layer) break;
Chris@45 739 }
Chris@45 740
Chris@45 741 if (!layer) {
Chris@45 742 CommandHistory::getInstance()->startCompoundOperation
Chris@45 743 (tr("Add Point"), true);
Chris@45 744 layer = m_document->createEmptyLayer(LayerFactory::TimeInstants);
Chris@45 745 if (layer) {
Chris@45 746 m_document->addLayerToView(pane, layer);
Chris@45 747 m_paneStack->setCurrentLayer(pane, layer);
Chris@45 748 }
Chris@45 749 CommandHistory::getInstance()->endCompoundOperation();
Chris@45 750 }
Chris@45 751 }
Chris@45 752
Chris@45 753 if (layer) {
Chris@45 754
Chris@45 755 Model *model = layer->getModel();
Chris@45 756 SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *>
Chris@45 757 (model);
Chris@45 758
Chris@45 759 if (sodm) {
Chris@45 760 SparseOneDimensionalModel::Point point(frame, "");
Chris@45 761
Chris@45 762 SparseOneDimensionalModel::Point prevPoint(0);
Chris@45 763 bool havePrevPoint = false;
Chris@45 764
Chris@45 765 SparseOneDimensionalModel::EditCommand *command =
Chris@45 766 new SparseOneDimensionalModel::EditCommand(sodm, tr("Add Point"));
Chris@45 767
Chris@74 768 if (m_labeller->requiresPrevPoint()) {
Chris@45 769
Chris@45 770 SparseOneDimensionalModel::PointList prevPoints =
Chris@45 771 sodm->getPreviousPoints(frame);
Chris@45 772
Chris@45 773 if (!prevPoints.empty()) {
Chris@45 774 prevPoint = *prevPoints.begin();
Chris@45 775 havePrevPoint = true;
Chris@45 776 }
Chris@45 777 }
Chris@45 778
Chris@45 779 if (m_labeller) {
Chris@45 780
Chris@45 781 m_labeller->setSampleRate(sodm->getSampleRate());
Chris@45 782
Chris@74 783 if (m_labeller->actingOnPrevPoint()) {
Chris@45 784 command->deletePoint(prevPoint);
Chris@45 785 }
Chris@45 786
Chris@45 787 m_labeller->label<SparseOneDimensionalModel::Point>
Chris@45 788 (point, havePrevPoint ? &prevPoint : 0);
Chris@45 789
Chris@74 790 if (m_labeller->actingOnPrevPoint()) {
Chris@45 791 command->addPoint(prevPoint);
Chris@45 792 }
Chris@45 793 }
Chris@45 794
Chris@45 795 command->addPoint(point);
Chris@45 796
Chris@45 797 command->setName(tr("Add Point at %1 s")
Chris@45 798 .arg(RealTime::frame2RealTime
Chris@45 799 (frame,
Chris@45 800 sodm->getSampleRate())
Chris@45 801 .toText(false).c_str()));
Chris@45 802
Chris@108 803 Command *c = command->finish();
Chris@108 804 if (c) CommandHistory::getInstance()->addCommand(c, false);
Chris@45 805 }
Chris@45 806 }
Chris@45 807 }
Chris@45 808
Chris@45 809 void
Chris@45 810 MainWindowBase::renumberInstants()
Chris@45 811 {
Chris@45 812 Pane *pane = m_paneStack->getCurrentPane();
Chris@45 813 if (!pane) return;
Chris@45 814
Chris@45 815 Layer *layer = dynamic_cast<TimeInstantLayer *>(pane->getSelectedLayer());
Chris@45 816 if (!layer) return;
Chris@45 817
Chris@45 818 MultiSelection ms(m_viewManager->getSelection());
Chris@45 819
Chris@45 820 Model *model = layer->getModel();
Chris@45 821 SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *>
Chris@45 822 (model);
Chris@45 823 if (!sodm) return;
Chris@45 824
Chris@45 825 if (!m_labeller) return;
Chris@45 826
Chris@45 827 Labeller labeller(*m_labeller);
Chris@45 828 labeller.setSampleRate(sodm->getSampleRate());
Chris@45 829
Chris@45 830 // This uses a command
Chris@45 831
Chris@45 832 labeller.labelAll<SparseOneDimensionalModel::Point>(*sodm, &ms);
Chris@45 833 }
Chris@45 834
Chris@45 835 MainWindowBase::FileOpenStatus
Chris@45 836 MainWindowBase::open(QString fileOrUrl, AudioFileOpenMode mode)
Chris@45 837 {
Chris@109 838 ProgressDialog dialog(tr("Opening file or URL..."), true, 2000);
Chris@109 839 return open(FileSource(fileOrUrl, &dialog), mode);
Chris@45 840 }
Chris@45 841
Chris@45 842 MainWindowBase::FileOpenStatus
Chris@45 843 MainWindowBase::open(FileSource source, AudioFileOpenMode mode)
Chris@45 844 {
Chris@45 845 FileOpenStatus status;
Chris@45 846
Chris@45 847 if (!source.isAvailable()) return FileOpenFailed;
Chris@45 848 source.waitForData();
Chris@45 849
Chris@45 850 bool canImportLayer = (getMainModel() != 0 &&
Chris@45 851 m_paneStack != 0 &&
Chris@45 852 m_paneStack->getCurrentPane() != 0);
Chris@45 853
Chris@45 854 if ((status = openAudio(source, mode)) != FileOpenFailed) {
Chris@45 855 return status;
Chris@45 856 } else if ((status = openSession(source)) != FileOpenFailed) {
Chris@45 857 return status;
Chris@45 858 } else if ((status = openPlaylist(source, mode)) != FileOpenFailed) {
Chris@45 859 return status;
Chris@45 860 } else if (!canImportLayer) {
Chris@45 861 return FileOpenWrongMode;
Chris@45 862 } else if ((status = openImage(source)) != FileOpenFailed) {
Chris@45 863 return status;
Chris@45 864 } else if ((status = openLayer(source)) != FileOpenFailed) {
Chris@45 865 return status;
Chris@45 866 } else {
Chris@45 867 return FileOpenFailed;
Chris@45 868 }
Chris@45 869 }
Chris@45 870
Chris@45 871 MainWindowBase::FileOpenStatus
Chris@45 872 MainWindowBase::openAudio(FileSource source, AudioFileOpenMode mode)
Chris@45 873 {
Chris@45 874 std::cerr << "MainWindowBase::openAudio(" << source.getLocation().toStdString() << ")" << std::endl;
Chris@45 875
Chris@45 876 if (!source.isAvailable()) return FileOpenFailed;
Chris@45 877 source.waitForData();
Chris@45 878
Chris@45 879 m_openingAudioFile = true;
Chris@45 880
Chris@45 881 size_t rate = 0;
Chris@45 882
Chris@45 883 if (Preferences::getInstance()->getResampleOnLoad()) {
Chris@45 884 rate = m_playSource->getSourceSampleRate();
Chris@45 885 }
Chris@45 886
Chris@45 887 WaveFileModel *newModel = new WaveFileModel(source, rate);
Chris@45 888
Chris@45 889 if (!newModel->isOK()) {
Chris@45 890 delete newModel;
Chris@45 891 m_openingAudioFile = false;
Chris@45 892 return FileOpenFailed;
Chris@45 893 }
Chris@45 894
Chris@45 895 std::cerr << "mode = " << mode << std::endl;
Chris@45 896
Chris@45 897 if (mode == AskUser) {
Chris@45 898 if (getMainModel()) {
Chris@45 899
Chris@45 900 static bool prevSetAsMain = true;
Chris@45 901 bool setAsMain = true;
Chris@45 902
Chris@45 903 QStringList items;
Chris@45 904 items << tr("Replace the existing main waveform")
Chris@45 905 << tr("Load this file into a new waveform pane");
Chris@45 906
Chris@45 907 bool ok = false;
Chris@45 908 QString item = ListInputDialog::getItem
Chris@45 909 (this, tr("Select target for import"),
Chris@45 910 tr("You already have an audio waveform loaded.\nWhat would you like to do with the new audio file?"),
Chris@45 911 items, prevSetAsMain ? 0 : 1, &ok);
Chris@45 912
Chris@45 913 if (!ok || item.isEmpty()) {
Chris@45 914 delete newModel;
Chris@45 915 m_openingAudioFile = false;
Chris@45 916 return FileOpenCancelled;
Chris@45 917 }
Chris@45 918
Chris@45 919 setAsMain = (item == items[0]);
Chris@45 920 prevSetAsMain = setAsMain;
Chris@45 921
Chris@45 922 if (setAsMain) mode = ReplaceMainModel;
Chris@45 923 else mode = CreateAdditionalModel;
Chris@45 924
Chris@45 925 } else {
Chris@45 926 mode = ReplaceMainModel;
Chris@45 927 }
Chris@45 928 }
Chris@45 929
Chris@45 930 if (mode == ReplaceCurrentPane) {
Chris@45 931
Chris@45 932 Pane *pane = m_paneStack->getCurrentPane();
Chris@45 933 if (pane) {
Chris@45 934 if (getMainModel()) {
Chris@45 935 View::ModelSet models(pane->getModels());
Chris@45 936 if (models.find(getMainModel()) != models.end()) {
Chris@45 937 mode = ReplaceMainModel;
Chris@45 938 }
Chris@45 939 } else {
Chris@45 940 mode = ReplaceMainModel;
Chris@45 941 }
Chris@45 942 } else {
Chris@45 943 mode = CreateAdditionalModel;
Chris@45 944 }
Chris@45 945 }
Chris@45 946
Chris@45 947 if (mode == CreateAdditionalModel && !getMainModel()) {
Chris@45 948 mode = ReplaceMainModel;
Chris@45 949 }
Chris@45 950
Chris@45 951 if (mode == ReplaceMainModel) {
Chris@45 952
Chris@45 953 Model *prevMain = getMainModel();
Chris@45 954 if (prevMain) {
Chris@45 955 m_playSource->removeModel(prevMain);
Chris@108 956 PlayParameterRepository::getInstance()->removePlayable(prevMain);
Chris@45 957 }
Chris@108 958 PlayParameterRepository::getInstance()->addPlayable(newModel);
Chris@45 959
Chris@45 960 m_document->setMainModel(newModel);
Chris@45 961
Chris@45 962 setupMenus();
Chris@45 963
Chris@45 964 if (m_sessionFile == "") {
Chris@45 965 //!!! shouldn't be dealing directly with title from here -- call a method
Chris@57 966 setWindowTitle(tr("%1: %2")
Chris@57 967 .arg(QApplication::applicationName())
Chris@45 968 .arg(source.getLocation()));
Chris@45 969 CommandHistory::getInstance()->clear();
Chris@45 970 CommandHistory::getInstance()->documentSaved();
Chris@45 971 m_documentModified = false;
Chris@45 972 } else {
Chris@57 973 setWindowTitle(tr("%1: %2 [%3]")
Chris@57 974 .arg(QApplication::applicationName())
Chris@45 975 .arg(QFileInfo(m_sessionFile).fileName())
Chris@45 976 .arg(source.getLocation()));
Chris@45 977 if (m_documentModified) {
Chris@45 978 m_documentModified = false;
Chris@45 979 documentModified(); // so as to restore "(modified)" window title
Chris@45 980 }
Chris@45 981 }
Chris@45 982
Chris@45 983 if (!source.isRemote()) m_audioFile = source.getLocalFilename();
Chris@45 984
Chris@45 985 } else if (mode == CreateAdditionalModel) {
Chris@45 986
Chris@45 987 CommandHistory::getInstance()->startCompoundOperation
Chris@45 988 (tr("Import \"%1\"").arg(source.getLocation()), true);
Chris@45 989
Chris@45 990 m_document->addImportedModel(newModel);
Chris@45 991
Chris@45 992 AddPaneCommand *command = new AddPaneCommand(this);
Chris@45 993 CommandHistory::getInstance()->addCommand(command);
Chris@45 994
Chris@45 995 Pane *pane = command->getPane();
Chris@45 996
Chris@47 997 if (m_timeRulerLayer) {
Chris@47 998 m_document->addLayerToView(pane, m_timeRulerLayer);
Chris@47 999 }
Chris@45 1000
Chris@45 1001 Layer *newLayer = m_document->createImportedLayer(newModel);
Chris@45 1002
Chris@45 1003 if (newLayer) {
Chris@45 1004 m_document->addLayerToView(pane, newLayer);
Chris@45 1005 }
Chris@45 1006
Chris@45 1007 CommandHistory::getInstance()->endCompoundOperation();
Chris@45 1008
Chris@45 1009 } else if (mode == ReplaceCurrentPane) {
Chris@45 1010
Chris@45 1011 // We know there is a current pane, otherwise we would have
Chris@45 1012 // reset the mode to CreateAdditionalModel above; and we know
Chris@45 1013 // the current pane does not contain the main model, otherwise
Chris@45 1014 // we would have reset it to ReplaceMainModel. But we don't
Chris@45 1015 // know whether the pane contains a waveform model at all.
Chris@45 1016
Chris@45 1017 Pane *pane = m_paneStack->getCurrentPane();
Chris@45 1018 Layer *replace = 0;
Chris@45 1019
Chris@45 1020 for (int i = 0; i < pane->getLayerCount(); ++i) {
Chris@45 1021 Layer *layer = pane->getLayer(i);
Chris@45 1022 if (dynamic_cast<WaveformLayer *>(layer)) {
Chris@45 1023 replace = layer;
Chris@45 1024 break;
Chris@45 1025 }
Chris@45 1026 }
Chris@45 1027
Chris@45 1028 CommandHistory::getInstance()->startCompoundOperation
Chris@45 1029 (tr("Import \"%1\"").arg(source.getLocation()), true);
Chris@45 1030
Chris@45 1031 m_document->addImportedModel(newModel);
Chris@45 1032
Chris@45 1033 if (replace) {
Chris@45 1034 m_document->removeLayerFromView(pane, replace);
Chris@45 1035 }
Chris@45 1036
Chris@45 1037 Layer *newLayer = m_document->createImportedLayer(newModel);
Chris@45 1038
Chris@45 1039 if (newLayer) {
Chris@45 1040 m_document->addLayerToView(pane, newLayer);
Chris@45 1041 }
Chris@45 1042
Chris@45 1043 CommandHistory::getInstance()->endCompoundOperation();
Chris@45 1044 }
Chris@45 1045
Chris@45 1046 updateMenuStates();
Chris@45 1047 m_recentFiles.addFile(source.getLocation());
Chris@45 1048 if (!source.isRemote()) {
Chris@45 1049 // for file dialog
Chris@45 1050 registerLastOpenedFilePath(FileFinder::AudioFile,
Chris@45 1051 source.getLocalFilename());
Chris@45 1052 }
Chris@45 1053 m_openingAudioFile = false;
Chris@45 1054
Chris@45 1055 currentPaneChanged(m_paneStack->getCurrentPane());
Chris@45 1056
Chris@45 1057 return FileOpenSucceeded;
Chris@45 1058 }
Chris@45 1059
Chris@45 1060 MainWindowBase::FileOpenStatus
Chris@45 1061 MainWindowBase::openPlaylist(FileSource source, AudioFileOpenMode mode)
Chris@45 1062 {
Chris@45 1063 std::set<QString> extensions;
Chris@45 1064 PlaylistFileReader::getSupportedExtensions(extensions);
Chris@45 1065 QString extension = source.getExtension();
Chris@45 1066 if (extensions.find(extension) == extensions.end()) return FileOpenFailed;
Chris@45 1067
Chris@45 1068 if (!source.isAvailable()) return FileOpenFailed;
Chris@45 1069 source.waitForData();
Chris@45 1070
Chris@45 1071 PlaylistFileReader reader(source.getLocalFilename());
Chris@45 1072 if (!reader.isOK()) return FileOpenFailed;
Chris@45 1073
Chris@45 1074 PlaylistFileReader::Playlist playlist = reader.load();
Chris@45 1075
Chris@45 1076 bool someSuccess = false;
Chris@45 1077
Chris@45 1078 for (PlaylistFileReader::Playlist::const_iterator i = playlist.begin();
Chris@45 1079 i != playlist.end(); ++i) {
Chris@45 1080
Chris@109 1081 ProgressDialog dialog(tr("Opening playlist..."), true, 2000);
Chris@109 1082 FileOpenStatus status = openAudio(FileSource(*i, &dialog), mode);
Chris@45 1083
Chris@45 1084 if (status == FileOpenCancelled) {
Chris@45 1085 return FileOpenCancelled;
Chris@45 1086 }
Chris@45 1087
Chris@45 1088 if (status == FileOpenSucceeded) {
Chris@45 1089 someSuccess = true;
Chris@45 1090 mode = CreateAdditionalModel;
Chris@45 1091 }
Chris@45 1092 }
Chris@45 1093
Chris@45 1094 if (someSuccess) return FileOpenSucceeded;
Chris@45 1095 else return FileOpenFailed;
Chris@45 1096 }
Chris@45 1097
Chris@45 1098 MainWindowBase::FileOpenStatus
Chris@45 1099 MainWindowBase::openLayer(FileSource source)
Chris@45 1100 {
Chris@45 1101 Pane *pane = m_paneStack->getCurrentPane();
Chris@45 1102
Chris@45 1103 if (!pane) {
Chris@45 1104 // shouldn't happen, as the menu action should have been disabled
Chris@45 1105 std::cerr << "WARNING: MainWindowBase::openLayer: no current pane" << std::endl;
Chris@45 1106 return FileOpenWrongMode;
Chris@45 1107 }
Chris@45 1108
Chris@45 1109 if (!getMainModel()) {
Chris@45 1110 // shouldn't happen, as the menu action should have been disabled
Chris@45 1111 std::cerr << "WARNING: MainWindowBase::openLayer: No main model -- hence no default sample rate available" << std::endl;
Chris@45 1112 return FileOpenWrongMode;
Chris@45 1113 }
Chris@45 1114
Chris@45 1115 if (!source.isAvailable()) return FileOpenFailed;
Chris@45 1116 source.waitForData();
Chris@45 1117
Chris@45 1118 QString path = source.getLocalFilename();
Chris@45 1119
Chris@45 1120 if (source.getExtension() == "svl" || source.getExtension() == "xml") {
Chris@45 1121
Chris@45 1122 PaneCallback callback(this);
Chris@45 1123 QFile file(path);
Chris@45 1124
Chris@45 1125 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
Chris@45 1126 std::cerr << "ERROR: MainWindowBase::openLayer("
Chris@45 1127 << source.getLocation().toStdString()
Chris@45 1128 << "): Failed to open file for reading" << std::endl;
Chris@45 1129 return FileOpenFailed;
Chris@45 1130 }
Chris@45 1131
Chris@45 1132 SVFileReader reader(m_document, callback, source.getLocation());
Chris@79 1133 connect
Chris@79 1134 (&reader, SIGNAL(modelRegenerationFailed(QString, QString, QString)),
Chris@79 1135 this, SLOT(modelRegenerationFailed(QString, QString, QString)));
Chris@79 1136 connect
Chris@79 1137 (&reader, SIGNAL(modelRegenerationWarning(QString, QString, QString)),
Chris@79 1138 this, SLOT(modelRegenerationWarning(QString, QString, QString)));
Chris@45 1139 reader.setCurrentPane(pane);
Chris@45 1140
Chris@45 1141 QXmlInputSource inputSource(&file);
Chris@45 1142 reader.parse(inputSource);
Chris@45 1143
Chris@45 1144 if (!reader.isOK()) {
Chris@45 1145 std::cerr << "ERROR: MainWindowBase::openLayer("
Chris@45 1146 << source.getLocation().toStdString()
Chris@45 1147 << "): Failed to read XML file: "
Chris@45 1148 << reader.getErrorString().toStdString() << std::endl;
Chris@45 1149 return FileOpenFailed;
Chris@45 1150 }
Chris@45 1151
Chris@45 1152 m_recentFiles.addFile(source.getLocation());
Chris@45 1153
Chris@45 1154 if (!source.isRemote()) {
Chris@45 1155 registerLastOpenedFilePath(FileFinder::LayerFile, path); // for file dialog
Chris@45 1156 }
Chris@45 1157
Chris@75 1158 return FileOpenSucceeded;
Chris@75 1159
Chris@45 1160 } else {
Chris@45 1161
Chris@45 1162 try {
Chris@45 1163
Chris@109 1164 MIDIFileImportDialog midiDlg(this);
Chris@109 1165
Chris@109 1166 Model *model = DataFileReaderFactory::loadNonCSV
Chris@109 1167 (path, &midiDlg, getMainModel()->getSampleRate());
Chris@45 1168
Chris@109 1169 if (!model) {
Chris@109 1170 CSVFormatDialog *dialog = new CSVFormatDialog
Chris@109 1171 (this, CSVFormat(path), getMainModel()->getSampleRate());
Chris@109 1172 if (dialog->exec() == QDialog::Accepted) {
Chris@109 1173 model = DataFileReaderFactory::loadCSV
Chris@109 1174 (path, dialog->getFormat(),
Chris@109 1175 getMainModel()->getSampleRate());
Chris@109 1176 }
Chris@109 1177 }
Chris@109 1178
Chris@45 1179 if (model) {
Chris@45 1180
Chris@45 1181 std::cerr << "MainWindowBase::openLayer: Have model" << std::endl;
Chris@45 1182
Chris@45 1183 Layer *newLayer = m_document->createImportedLayer(model);
Chris@45 1184
Chris@45 1185 if (newLayer) {
Chris@45 1186
Chris@45 1187 m_document->addLayerToView(pane, newLayer);
Chris@88 1188 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@88 1189
Chris@45 1190 m_recentFiles.addFile(source.getLocation());
Chris@45 1191
Chris@45 1192 if (!source.isRemote()) {
Chris@45 1193 registerLastOpenedFilePath
Chris@45 1194 (FileFinder::LayerFile,
Chris@45 1195 path); // for file dialog
Chris@45 1196 }
Chris@88 1197
Chris@45 1198 return FileOpenSucceeded;
Chris@45 1199 }
Chris@45 1200 }
Chris@45 1201 } catch (DataFileReaderFactory::Exception e) {
Chris@45 1202 if (e == DataFileReaderFactory::ImportCancelled) {
Chris@45 1203 return FileOpenCancelled;
Chris@45 1204 }
Chris@45 1205 }
Chris@45 1206 }
Chris@45 1207
Chris@45 1208 return FileOpenFailed;
Chris@45 1209 }
Chris@45 1210
Chris@45 1211 MainWindowBase::FileOpenStatus
Chris@45 1212 MainWindowBase::openImage(FileSource source)
Chris@45 1213 {
Chris@45 1214 Pane *pane = m_paneStack->getCurrentPane();
Chris@45 1215
Chris@45 1216 if (!pane) {
Chris@45 1217 // shouldn't happen, as the menu action should have been disabled
Chris@45 1218 std::cerr << "WARNING: MainWindowBase::openImage: no current pane" << std::endl;
Chris@45 1219 return FileOpenWrongMode;
Chris@45 1220 }
Chris@45 1221
Chris@45 1222 if (!m_document->getMainModel()) {
Chris@45 1223 return FileOpenWrongMode;
Chris@45 1224 }
Chris@45 1225
Chris@45 1226 bool newLayer = false;
Chris@45 1227
Chris@45 1228 ImageLayer *il = dynamic_cast<ImageLayer *>(pane->getSelectedLayer());
Chris@45 1229 if (!il) {
Chris@45 1230 for (int i = pane->getLayerCount()-1; i >= 0; --i) {
Chris@45 1231 il = dynamic_cast<ImageLayer *>(pane->getLayer(i));
Chris@45 1232 if (il) break;
Chris@45 1233 }
Chris@45 1234 }
Chris@45 1235 if (!il) {
Chris@45 1236 il = dynamic_cast<ImageLayer *>
Chris@45 1237 (m_document->createEmptyLayer(LayerFactory::Image));
Chris@45 1238 if (!il) return FileOpenFailed;
Chris@45 1239 newLayer = true;
Chris@45 1240 }
Chris@45 1241
Chris@45 1242 // We don't put the image file in Recent Files
Chris@45 1243
Chris@45 1244 std::cerr << "openImage: trying location \"" << source.getLocation().toStdString() << "\" in image layer" << std::endl;
Chris@45 1245
Chris@45 1246 if (!il->addImage(m_viewManager->getGlobalCentreFrame(), source.getLocation())) {
Chris@45 1247 if (newLayer) {
Chris@52 1248 m_document->deleteLayer(il); // also releases its model
Chris@45 1249 }
Chris@45 1250 return FileOpenFailed;
Chris@45 1251 } else {
Chris@45 1252 if (newLayer) {
Chris@45 1253 m_document->addLayerToView(pane, il);
Chris@45 1254 }
Chris@45 1255 m_paneStack->setCurrentLayer(pane, il);
Chris@45 1256 }
Chris@45 1257
Chris@45 1258 return FileOpenSucceeded;
Chris@45 1259 }
Chris@45 1260
Chris@45 1261 MainWindowBase::FileOpenStatus
Chris@45 1262 MainWindowBase::openSessionFile(QString fileOrUrl)
Chris@45 1263 {
Chris@109 1264 ProgressDialog dialog(tr("Opening session..."), true, 2000);
Chris@109 1265 return openSession(FileSource(fileOrUrl, &dialog));
Chris@45 1266 }
Chris@45 1267
Chris@45 1268 MainWindowBase::FileOpenStatus
Chris@45 1269 MainWindowBase::openSession(FileSource source)
Chris@45 1270 {
Chris@45 1271 if (!source.isAvailable()) return FileOpenFailed;
Chris@45 1272 if (source.getExtension() != "sv") return FileOpenFailed;
Chris@45 1273 source.waitForData();
Chris@45 1274
Chris@45 1275 BZipFileDevice bzFile(source.getLocalFilename());
Chris@45 1276 if (!bzFile.open(QIODevice::ReadOnly)) return FileOpenFailed;
Chris@45 1277
Chris@45 1278 if (!checkSaveModified()) return FileOpenCancelled;
Chris@45 1279
Chris@45 1280 QString error;
Chris@45 1281 closeSession();
Chris@45 1282 createDocument();
Chris@45 1283
Chris@45 1284 PaneCallback callback(this);
Chris@45 1285 m_viewManager->clearSelections();
Chris@45 1286
Chris@45 1287 SVFileReader reader(m_document, callback, source.getLocation());
Chris@79 1288 connect
Chris@79 1289 (&reader, SIGNAL(modelRegenerationFailed(QString, QString, QString)),
Chris@79 1290 this, SLOT(modelRegenerationFailed(QString, QString, QString)));
Chris@79 1291 connect
Chris@79 1292 (&reader, SIGNAL(modelRegenerationWarning(QString, QString, QString)),
Chris@79 1293 this, SLOT(modelRegenerationWarning(QString, QString, QString)));
Chris@45 1294 QXmlInputSource inputSource(&bzFile);
Chris@45 1295 reader.parse(inputSource);
Chris@45 1296
Chris@45 1297 if (!reader.isOK()) {
Chris@45 1298 error = tr("SV XML file read error:\n%1").arg(reader.getErrorString());
Chris@45 1299 }
Chris@45 1300
Chris@45 1301 bzFile.close();
Chris@45 1302
Chris@45 1303 bool ok = (error == "");
Chris@45 1304
Chris@45 1305 if (ok) {
Chris@45 1306
Chris@57 1307 setWindowTitle(tr("%1: %2")
Chris@57 1308 .arg(QApplication::applicationName())
Chris@45 1309 .arg(source.getLocation()));
Chris@45 1310
Chris@45 1311 if (!source.isRemote()) m_sessionFile = source.getLocalFilename();
Chris@45 1312
Chris@45 1313 setupMenus();
Chris@45 1314
Chris@45 1315 CommandHistory::getInstance()->clear();
Chris@45 1316 CommandHistory::getInstance()->documentSaved();
Chris@45 1317 m_documentModified = false;
Chris@45 1318 updateMenuStates();
Chris@45 1319
Chris@45 1320 m_recentFiles.addFile(source.getLocation());
Chris@45 1321
Chris@45 1322 if (!source.isRemote()) {
Chris@45 1323 // for file dialog
Chris@45 1324 registerLastOpenedFilePath(FileFinder::SessionFile,
Chris@45 1325 source.getLocalFilename());
Chris@45 1326 }
Chris@45 1327
Chris@45 1328 } else {
Chris@57 1329 setWindowTitle(QApplication::applicationName());
Chris@45 1330 }
Chris@45 1331
Chris@45 1332 return ok ? FileOpenSucceeded : FileOpenFailed;
Chris@45 1333 }
Chris@45 1334
Chris@45 1335 void
Chris@45 1336 MainWindowBase::createPlayTarget()
Chris@45 1337 {
Chris@45 1338 if (m_playTarget) return;
Chris@45 1339
Chris@126 1340 QSettings settings;
Chris@126 1341 settings.beginGroup("Preferences");
Chris@126 1342 QString targetName = settings.value("audio-target", "").toString();
Chris@126 1343 settings.endGroup();
Chris@126 1344
Chris@126 1345 AudioTargetFactory *factory = AudioTargetFactory::getInstance();
Chris@126 1346
Chris@126 1347 factory->setDefaultCallbackTarget(targetName);
Chris@126 1348 m_playTarget = factory->createCallbackTarget(m_playSource);
Chris@126 1349
Chris@45 1350 if (!m_playTarget) {
Chris@104 1351 emit hideSplash();
Chris@126 1352
Chris@126 1353 if (factory->isAutoCallbackTarget(targetName)) {
Chris@128 1354 QMessageBox::warning
Chris@45 1355 (this, tr("Couldn't open audio device"),
Chris@126 1356 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 1357 QMessageBox::Ok);
Chris@126 1358 } else {
Chris@126 1359 QMessageBox::warning
Chris@126 1360 (this, tr("Couldn't open audio device"),
Chris@126 1361 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 1362 .arg(factory->getCallbackTargetDescription(targetName)),
Chris@126 1363 QMessageBox::Ok);
Chris@126 1364 }
Chris@45 1365 }
Chris@45 1366 }
Chris@45 1367
Chris@45 1368 WaveFileModel *
Chris@45 1369 MainWindowBase::getMainModel()
Chris@45 1370 {
Chris@45 1371 if (!m_document) return 0;
Chris@45 1372 return m_document->getMainModel();
Chris@45 1373 }
Chris@45 1374
Chris@45 1375 const WaveFileModel *
Chris@45 1376 MainWindowBase::getMainModel() const
Chris@45 1377 {
Chris@45 1378 if (!m_document) return 0;
Chris@45 1379 return m_document->getMainModel();
Chris@45 1380 }
Chris@45 1381
Chris@45 1382 void
Chris@45 1383 MainWindowBase::createDocument()
Chris@45 1384 {
Chris@45 1385 m_document = new Document;
Chris@45 1386
Chris@45 1387 connect(m_document, SIGNAL(layerAdded(Layer *)),
Chris@45 1388 this, SLOT(layerAdded(Layer *)));
Chris@45 1389 connect(m_document, SIGNAL(layerRemoved(Layer *)),
Chris@45 1390 this, SLOT(layerRemoved(Layer *)));
Chris@45 1391 connect(m_document, SIGNAL(layerAboutToBeDeleted(Layer *)),
Chris@45 1392 this, SLOT(layerAboutToBeDeleted(Layer *)));
Chris@45 1393 connect(m_document, SIGNAL(layerInAView(Layer *, bool)),
Chris@45 1394 this, SLOT(layerInAView(Layer *, bool)));
Chris@45 1395
Chris@45 1396 connect(m_document, SIGNAL(modelAdded(Model *)),
Chris@45 1397 this, SLOT(modelAdded(Model *)));
Chris@45 1398 connect(m_document, SIGNAL(mainModelChanged(WaveFileModel *)),
Chris@45 1399 this, SLOT(mainModelChanged(WaveFileModel *)));
Chris@45 1400 connect(m_document, SIGNAL(modelAboutToBeDeleted(Model *)),
Chris@45 1401 this, SLOT(modelAboutToBeDeleted(Model *)));
Chris@45 1402
Chris@78 1403 connect(m_document, SIGNAL(modelGenerationFailed(QString, QString)),
Chris@78 1404 this, SLOT(modelGenerationFailed(QString, QString)));
Chris@78 1405 connect(m_document, SIGNAL(modelRegenerationWarning(QString, QString, QString)),
Chris@78 1406 this, SLOT(modelRegenerationWarning(QString, QString, QString)));
Chris@78 1407 connect(m_document, SIGNAL(modelGenerationFailed(QString, QString)),
Chris@78 1408 this, SLOT(modelGenerationFailed(QString, QString)));
Chris@78 1409 connect(m_document, SIGNAL(modelRegenerationWarning(QString, QString, QString)),
Chris@78 1410 this, SLOT(modelRegenerationWarning(QString, QString, QString)));
Chris@78 1411 connect(m_document, SIGNAL(alignmentFailed(QString, QString)),
Chris@78 1412 this, SLOT(alignmentFailed(QString, QString)));
Chris@45 1413 }
Chris@45 1414
Chris@45 1415 bool
Chris@45 1416 MainWindowBase::saveSessionFile(QString path)
Chris@45 1417 {
Chris@45 1418 BZipFileDevice bzFile(path);
Chris@45 1419 if (!bzFile.open(QIODevice::WriteOnly)) {
Chris@45 1420 std::cerr << "Failed to open session file \"" << path.toStdString()
Chris@45 1421 << "\" for writing: "
Chris@45 1422 << bzFile.errorString().toStdString() << std::endl;
Chris@45 1423 return false;
Chris@45 1424 }
Chris@45 1425
Chris@45 1426 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
Chris@45 1427
Chris@45 1428 QTextStream out(&bzFile);
Chris@45 1429 toXml(out);
Chris@45 1430 out.flush();
Chris@45 1431
Chris@45 1432 QApplication::restoreOverrideCursor();
Chris@45 1433
Chris@45 1434 if (!bzFile.isOK()) {
Chris@45 1435 QMessageBox::critical(this, tr("Failed to write file"),
Chris@45 1436 tr("<b>Save failed</b><p>Failed to write to file \"%1\": %2")
Chris@45 1437 .arg(path).arg(bzFile.errorString()));
Chris@45 1438 bzFile.close();
Chris@45 1439 return false;
Chris@45 1440 }
Chris@45 1441
Chris@45 1442 bzFile.close();
Chris@45 1443 return true;
Chris@45 1444 }
Chris@45 1445
Chris@45 1446 void
Chris@45 1447 MainWindowBase::toXml(QTextStream &out)
Chris@45 1448 {
Chris@45 1449 QString indent(" ");
Chris@45 1450
Chris@45 1451 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
Chris@45 1452 out << "<!DOCTYPE sonic-visualiser>\n";
Chris@45 1453 out << "<sv>\n";
Chris@45 1454
Chris@45 1455 m_document->toXml(out, "", "");
Chris@45 1456
Chris@45 1457 out << "<display>\n";
Chris@45 1458
Chris@45 1459 out << QString(" <window width=\"%1\" height=\"%2\"/>\n")
Chris@45 1460 .arg(width()).arg(height());
Chris@45 1461
Chris@45 1462 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@45 1463
Chris@45 1464 Pane *pane = m_paneStack->getPane(i);
Chris@45 1465
Chris@45 1466 if (pane) {
Chris@45 1467 pane->toXml(out, indent);
Chris@45 1468 }
Chris@45 1469 }
Chris@45 1470
Chris@45 1471 out << "</display>\n";
Chris@45 1472
Chris@45 1473 m_viewManager->getSelection().toXml(out);
Chris@45 1474
Chris@45 1475 out << "</sv>\n";
Chris@45 1476 }
Chris@45 1477
Chris@45 1478 Pane *
Chris@45 1479 MainWindowBase::addPaneToStack()
Chris@45 1480 {
Chris@45 1481 AddPaneCommand *command = new AddPaneCommand(this);
Chris@45 1482 CommandHistory::getInstance()->addCommand(command);
Chris@57 1483 Pane *pane = command->getPane();
Chris@57 1484 return pane;
Chris@45 1485 }
Chris@45 1486
Chris@45 1487 void
Chris@45 1488 MainWindowBase::zoomIn()
Chris@45 1489 {
Chris@45 1490 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 1491 if (currentPane) currentPane->zoom(true);
Chris@45 1492 }
Chris@45 1493
Chris@45 1494 void
Chris@45 1495 MainWindowBase::zoomOut()
Chris@45 1496 {
Chris@45 1497 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 1498 if (currentPane) currentPane->zoom(false);
Chris@45 1499 }
Chris@45 1500
Chris@45 1501 void
Chris@45 1502 MainWindowBase::zoomToFit()
Chris@45 1503 {
Chris@45 1504 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 1505 if (!currentPane) return;
Chris@45 1506
Chris@45 1507 Model *model = getMainModel();
Chris@45 1508 if (!model) return;
Chris@45 1509
Chris@45 1510 size_t start = model->getStartFrame();
Chris@45 1511 size_t end = model->getEndFrame();
Chris@60 1512 if (m_playSource) end = std::max(end, m_playSource->getPlayEndFrame());
Chris@45 1513 size_t pixels = currentPane->width();
Chris@45 1514
Chris@45 1515 size_t sw = currentPane->getVerticalScaleWidth();
Chris@45 1516 if (pixels > sw * 2) pixels -= sw * 2;
Chris@45 1517 else pixels = 1;
Chris@45 1518 if (pixels > 4) pixels -= 4;
Chris@45 1519
Chris@45 1520 size_t zoomLevel = (end - start) / pixels;
Chris@45 1521
Chris@45 1522 currentPane->setZoomLevel(zoomLevel);
Chris@45 1523 currentPane->setCentreFrame((start + end) / 2);
Chris@45 1524 }
Chris@45 1525
Chris@45 1526 void
Chris@45 1527 MainWindowBase::zoomDefault()
Chris@45 1528 {
Chris@45 1529 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 1530 if (currentPane) currentPane->setZoomLevel(1024);
Chris@45 1531 }
Chris@45 1532
Chris@45 1533 void
Chris@45 1534 MainWindowBase::scrollLeft()
Chris@45 1535 {
Chris@45 1536 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 1537 if (currentPane) currentPane->scroll(false, false);
Chris@45 1538 }
Chris@45 1539
Chris@45 1540 void
Chris@45 1541 MainWindowBase::jumpLeft()
Chris@45 1542 {
Chris@45 1543 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 1544 if (currentPane) currentPane->scroll(false, true);
Chris@45 1545 }
Chris@45 1546
Chris@45 1547 void
Chris@45 1548 MainWindowBase::scrollRight()
Chris@45 1549 {
Chris@45 1550 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 1551 if (currentPane) currentPane->scroll(true, false);
Chris@45 1552 }
Chris@45 1553
Chris@45 1554 void
Chris@45 1555 MainWindowBase::jumpRight()
Chris@45 1556 {
Chris@45 1557 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@45 1558 if (currentPane) currentPane->scroll(true, true);
Chris@45 1559 }
Chris@45 1560
Chris@45 1561 void
Chris@45 1562 MainWindowBase::showNoOverlays()
Chris@45 1563 {
Chris@45 1564 m_viewManager->setOverlayMode(ViewManager::NoOverlays);
Chris@45 1565 }
Chris@45 1566
Chris@45 1567 void
Chris@45 1568 MainWindowBase::showMinimalOverlays()
Chris@45 1569 {
Chris@45 1570 m_viewManager->setOverlayMode(ViewManager::MinimalOverlays);
Chris@45 1571 }
Chris@45 1572
Chris@45 1573 void
Chris@45 1574 MainWindowBase::showStandardOverlays()
Chris@45 1575 {
Chris@45 1576 m_viewManager->setOverlayMode(ViewManager::StandardOverlays);
Chris@45 1577 }
Chris@45 1578
Chris@45 1579 void
Chris@45 1580 MainWindowBase::showAllOverlays()
Chris@45 1581 {
Chris@45 1582 m_viewManager->setOverlayMode(ViewManager::AllOverlays);
Chris@45 1583 }
Chris@45 1584
Chris@45 1585 void
Chris@45 1586 MainWindowBase::toggleZoomWheels()
Chris@45 1587 {
Chris@45 1588 if (m_viewManager->getZoomWheelsEnabled()) {
Chris@45 1589 m_viewManager->setZoomWheelsEnabled(false);
Chris@45 1590 } else {
Chris@45 1591 m_viewManager->setZoomWheelsEnabled(true);
Chris@45 1592 }
Chris@45 1593 }
Chris@45 1594
Chris@45 1595 void
Chris@45 1596 MainWindowBase::togglePropertyBoxes()
Chris@45 1597 {
Chris@45 1598 if (m_paneStack->getLayoutStyle() == PaneStack::NoPropertyStacks) {
Chris@45 1599 if (Preferences::getInstance()->getPropertyBoxLayout() ==
Chris@45 1600 Preferences::VerticallyStacked) {
Chris@45 1601 m_paneStack->setLayoutStyle(PaneStack::PropertyStackPerPaneLayout);
Chris@45 1602 } else {
Chris@45 1603 m_paneStack->setLayoutStyle(PaneStack::SinglePropertyStackLayout);
Chris@45 1604 }
Chris@45 1605 } else {
Chris@45 1606 m_paneStack->setLayoutStyle(PaneStack::NoPropertyStacks);
Chris@45 1607 }
Chris@45 1608 }
Chris@45 1609
Chris@45 1610 void
Chris@45 1611 MainWindowBase::toggleStatusBar()
Chris@45 1612 {
Chris@45 1613 QSettings settings;
Chris@45 1614 settings.beginGroup("MainWindow");
Chris@45 1615 bool sb = settings.value("showstatusbar", true).toBool();
Chris@45 1616
Chris@45 1617 if (sb) {
Chris@45 1618 statusBar()->hide();
Chris@45 1619 } else {
Chris@45 1620 statusBar()->show();
Chris@45 1621 }
Chris@45 1622
Chris@45 1623 settings.setValue("showstatusbar", !sb);
Chris@45 1624
Chris@45 1625 settings.endGroup();
Chris@45 1626 }
Chris@45 1627
Chris@45 1628 void
Chris@45 1629 MainWindowBase::preferenceChanged(PropertyContainer::PropertyName name)
Chris@45 1630 {
Chris@45 1631 if (name == "Property Box Layout") {
Chris@45 1632 if (m_paneStack->getLayoutStyle() != PaneStack::NoPropertyStacks) {
Chris@45 1633 if (Preferences::getInstance()->getPropertyBoxLayout() ==
Chris@45 1634 Preferences::VerticallyStacked) {
Chris@45 1635 m_paneStack->setLayoutStyle(PaneStack::PropertyStackPerPaneLayout);
Chris@45 1636 } else {
Chris@45 1637 m_paneStack->setLayoutStyle(PaneStack::SinglePropertyStackLayout);
Chris@45 1638 }
Chris@45 1639 }
Chris@45 1640 } else if (name == "Background Mode" && m_viewManager) {
Chris@45 1641 Preferences::BackgroundMode mode =
Chris@45 1642 Preferences::getInstance()->getBackgroundMode();
Chris@45 1643 if (mode == Preferences::BackgroundFromTheme) {
Chris@45 1644 m_viewManager->setGlobalDarkBackground(m_initialDarkBackground);
Chris@45 1645 } else if (mode == Preferences::DarkBackground) {
Chris@45 1646 m_viewManager->setGlobalDarkBackground(true);
Chris@45 1647 } else {
Chris@45 1648 m_viewManager->setGlobalDarkBackground(false);
Chris@45 1649 }
Chris@45 1650 }
Chris@45 1651 }
Chris@45 1652
Chris@45 1653 void
Chris@45 1654 MainWindowBase::play()
Chris@45 1655 {
Chris@45 1656 if (m_playSource->isPlaying()) {
Chris@45 1657 stop();
Chris@45 1658 } else {
Chris@45 1659 playbackFrameChanged(m_viewManager->getPlaybackFrame());
Chris@45 1660 m_playSource->play(m_viewManager->getPlaybackFrame());
Chris@45 1661 }
Chris@45 1662 }
Chris@45 1663
Chris@45 1664 void
Chris@45 1665 MainWindowBase::ffwd()
Chris@45 1666 {
Chris@45 1667 if (!getMainModel()) return;
Chris@45 1668
Chris@45 1669 int frame = m_viewManager->getPlaybackFrame();
Chris@45 1670 ++frame;
Chris@45 1671
Chris@85 1672 Pane *pane = m_paneStack->getCurrentPane();
Chris@45 1673 Layer *layer = getSnapLayer();
Chris@45 1674 size_t sr = getMainModel()->getSampleRate();
Chris@45 1675
Chris@45 1676 if (!layer) {
Chris@45 1677
Chris@45 1678 frame = RealTime::realTime2Frame
Chris@45 1679 (RealTime::frame2RealTime(frame, sr) + RealTime(2, 0), sr);
Chris@45 1680 if (frame > int(getMainModel()->getEndFrame())) {
Chris@45 1681 frame = getMainModel()->getEndFrame();
Chris@45 1682 }
Chris@45 1683
Chris@45 1684 } else {
Chris@45 1685
Chris@45 1686 size_t resolution = 0;
Chris@85 1687 if (layer->snapToFeatureFrame(m_paneStack->getCurrentPane(),
Chris@85 1688 frame, resolution, Layer::SnapRight)) {
Chris@85 1689 if (pane) frame = pane->alignToReference(frame);
Chris@85 1690 } else {
Chris@45 1691 frame = getMainModel()->getEndFrame();
Chris@45 1692 }
Chris@45 1693 }
Chris@45 1694
Chris@45 1695 if (frame < 0) frame = 0;
Chris@45 1696
Chris@45 1697 if (m_viewManager->getPlaySelectionMode()) {
Chris@45 1698 frame = m_viewManager->constrainFrameToSelection(size_t(frame));
Chris@45 1699 }
Chris@45 1700
Chris@45 1701 m_viewManager->setPlaybackFrame(frame);
Chris@45 1702 }
Chris@45 1703
Chris@45 1704 void
Chris@45 1705 MainWindowBase::ffwdEnd()
Chris@45 1706 {
Chris@45 1707 if (!getMainModel()) return;
Chris@45 1708
Chris@45 1709 size_t frame = getMainModel()->getEndFrame();
Chris@45 1710
Chris@45 1711 if (m_viewManager->getPlaySelectionMode()) {
Chris@45 1712 frame = m_viewManager->constrainFrameToSelection(frame);
Chris@45 1713 }
Chris@45 1714
Chris@45 1715 m_viewManager->setPlaybackFrame(frame);
Chris@45 1716 }
Chris@45 1717
Chris@45 1718 void
Chris@45 1719 MainWindowBase::rewind()
Chris@45 1720 {
Chris@45 1721 if (!getMainModel()) return;
Chris@45 1722
Chris@45 1723 int frame = m_viewManager->getPlaybackFrame();
Chris@45 1724 if (frame > 0) --frame;
Chris@45 1725
Chris@85 1726 Pane *pane = m_paneStack->getCurrentPane();
Chris@45 1727 Layer *layer = getSnapLayer();
Chris@45 1728 size_t sr = getMainModel()->getSampleRate();
Chris@45 1729
Chris@45 1730 // when rewinding during playback, we want to allow a period
Chris@45 1731 // following a rewind target point at which the rewind will go to
Chris@45 1732 // the prior point instead of the immediately neighbouring one
Chris@45 1733 if (m_playSource && m_playSource->isPlaying()) {
Chris@45 1734 RealTime ct = RealTime::frame2RealTime(frame, sr);
Chris@45 1735 ct = ct - RealTime::fromSeconds(0.25);
Chris@45 1736 if (ct < RealTime::zeroTime) ct = RealTime::zeroTime;
Chris@45 1737 // std::cerr << "rewind: frame " << frame << " -> ";
Chris@45 1738 frame = RealTime::realTime2Frame(ct, sr);
Chris@45 1739 // std::cerr << frame << std::endl;
Chris@45 1740 }
Chris@45 1741
Chris@45 1742 if (!layer) {
Chris@45 1743
Chris@45 1744 frame = RealTime::realTime2Frame
Chris@45 1745 (RealTime::frame2RealTime(frame, sr) - RealTime(2, 0), sr);
Chris@45 1746 if (frame < int(getMainModel()->getStartFrame())) {
Chris@45 1747 frame = getMainModel()->getStartFrame();
Chris@45 1748 }
Chris@45 1749
Chris@45 1750 } else {
Chris@45 1751
Chris@45 1752 size_t resolution = 0;
Chris@85 1753 if (layer->snapToFeatureFrame(m_paneStack->getCurrentPane(),
Chris@85 1754 frame, resolution, Layer::SnapLeft)) {
Chris@85 1755
Chris@85 1756 if (pane) frame = pane->alignToReference(frame);
Chris@85 1757 } else {
Chris@45 1758 frame = getMainModel()->getStartFrame();
Chris@45 1759 }
Chris@45 1760 }
Chris@45 1761
Chris@45 1762 if (frame < 0) frame = 0;
Chris@45 1763
Chris@45 1764 if (m_viewManager->getPlaySelectionMode()) {
Chris@45 1765 frame = m_viewManager->constrainFrameToSelection(size_t(frame));
Chris@45 1766 }
Chris@45 1767
Chris@45 1768 m_viewManager->setPlaybackFrame(frame);
Chris@45 1769 }
Chris@45 1770
Chris@45 1771 void
Chris@45 1772 MainWindowBase::rewindStart()
Chris@45 1773 {
Chris@45 1774 if (!getMainModel()) return;
Chris@45 1775
Chris@45 1776 size_t frame = getMainModel()->getStartFrame();
Chris@45 1777
Chris@45 1778 if (m_viewManager->getPlaySelectionMode()) {
Chris@45 1779 frame = m_viewManager->constrainFrameToSelection(frame);
Chris@45 1780 }
Chris@45 1781
Chris@45 1782 m_viewManager->setPlaybackFrame(frame);
Chris@45 1783 }
Chris@45 1784
Chris@45 1785 Layer *
Chris@45 1786 MainWindowBase::getSnapLayer() const
Chris@45 1787 {
Chris@45 1788 Pane *pane = m_paneStack->getCurrentPane();
Chris@45 1789 if (!pane) return 0;
Chris@45 1790
Chris@45 1791 Layer *layer = pane->getSelectedLayer();
Chris@45 1792
Chris@45 1793 if (!dynamic_cast<TimeInstantLayer *>(layer) &&
Chris@45 1794 !dynamic_cast<TimeValueLayer *>(layer) &&
Chris@45 1795 !dynamic_cast<TimeRulerLayer *>(layer)) {
Chris@45 1796
Chris@45 1797 layer = 0;
Chris@45 1798
Chris@45 1799 for (int i = pane->getLayerCount(); i > 0; --i) {
Chris@45 1800 Layer *l = pane->getLayer(i-1);
Chris@45 1801 if (dynamic_cast<TimeRulerLayer *>(l)) {
Chris@45 1802 layer = l;
Chris@45 1803 break;
Chris@45 1804 }
Chris@45 1805 }
Chris@45 1806 }
Chris@45 1807
Chris@45 1808 return layer;
Chris@45 1809 }
Chris@45 1810
Chris@45 1811 void
Chris@45 1812 MainWindowBase::stop()
Chris@45 1813 {
Chris@45 1814 m_playSource->stop();
Chris@45 1815
Chris@45 1816 if (m_paneStack && m_paneStack->getCurrentPane()) {
Chris@45 1817 updateVisibleRangeDisplay(m_paneStack->getCurrentPane());
Chris@45 1818 } else {
Chris@45 1819 m_myStatusMessage = "";
Chris@45 1820 statusBar()->showMessage("");
Chris@45 1821 }
Chris@45 1822 }
Chris@45 1823
Chris@45 1824 MainWindowBase::AddPaneCommand::AddPaneCommand(MainWindowBase *mw) :
Chris@45 1825 m_mw(mw),
Chris@45 1826 m_pane(0),
Chris@45 1827 m_prevCurrentPane(0),
Chris@45 1828 m_added(false)
Chris@45 1829 {
Chris@45 1830 }
Chris@45 1831
Chris@45 1832 MainWindowBase::AddPaneCommand::~AddPaneCommand()
Chris@45 1833 {
Chris@45 1834 if (m_pane && !m_added) {
Chris@45 1835 m_mw->m_paneStack->deletePane(m_pane);
Chris@45 1836 }
Chris@45 1837 }
Chris@45 1838
Chris@45 1839 QString
Chris@45 1840 MainWindowBase::AddPaneCommand::getName() const
Chris@45 1841 {
Chris@45 1842 return tr("Add Pane");
Chris@45 1843 }
Chris@45 1844
Chris@45 1845 void
Chris@45 1846 MainWindowBase::AddPaneCommand::execute()
Chris@45 1847 {
Chris@45 1848 if (!m_pane) {
Chris@45 1849 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
Chris@45 1850 m_pane = m_mw->m_paneStack->addPane();
Chris@45 1851
Chris@45 1852 connect(m_pane, SIGNAL(contextHelpChanged(const QString &)),
Chris@45 1853 m_mw, SLOT(contextHelpChanged(const QString &)));
Chris@45 1854 } else {
Chris@45 1855 m_mw->m_paneStack->showPane(m_pane);
Chris@45 1856 }
Chris@45 1857
Chris@45 1858 m_mw->m_paneStack->setCurrentPane(m_pane);
Chris@45 1859 m_added = true;
Chris@45 1860 }
Chris@45 1861
Chris@45 1862 void
Chris@45 1863 MainWindowBase::AddPaneCommand::unexecute()
Chris@45 1864 {
Chris@45 1865 m_mw->m_paneStack->hidePane(m_pane);
Chris@45 1866 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
Chris@45 1867 m_added = false;
Chris@45 1868 }
Chris@45 1869
Chris@45 1870 MainWindowBase::RemovePaneCommand::RemovePaneCommand(MainWindowBase *mw, Pane *pane) :
Chris@45 1871 m_mw(mw),
Chris@45 1872 m_pane(pane),
Chris@45 1873 m_added(true)
Chris@45 1874 {
Chris@45 1875 }
Chris@45 1876
Chris@45 1877 MainWindowBase::RemovePaneCommand::~RemovePaneCommand()
Chris@45 1878 {
Chris@45 1879 if (m_pane && !m_added) {
Chris@45 1880 m_mw->m_paneStack->deletePane(m_pane);
Chris@45 1881 }
Chris@45 1882 }
Chris@45 1883
Chris@45 1884 QString
Chris@45 1885 MainWindowBase::RemovePaneCommand::getName() const
Chris@45 1886 {
Chris@45 1887 return tr("Remove Pane");
Chris@45 1888 }
Chris@45 1889
Chris@45 1890 void
Chris@45 1891 MainWindowBase::RemovePaneCommand::execute()
Chris@45 1892 {
Chris@45 1893 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
Chris@45 1894 m_mw->m_paneStack->hidePane(m_pane);
Chris@45 1895 m_added = false;
Chris@45 1896 }
Chris@45 1897
Chris@45 1898 void
Chris@45 1899 MainWindowBase::RemovePaneCommand::unexecute()
Chris@45 1900 {
Chris@45 1901 m_mw->m_paneStack->showPane(m_pane);
Chris@45 1902 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
Chris@45 1903 m_added = true;
Chris@45 1904 }
Chris@45 1905
Chris@45 1906 void
Chris@45 1907 MainWindowBase::deleteCurrentPane()
Chris@45 1908 {
Chris@45 1909 CommandHistory::getInstance()->startCompoundOperation
Chris@45 1910 (tr("Delete Pane"), true);
Chris@45 1911
Chris@45 1912 Pane *pane = m_paneStack->getCurrentPane();
Chris@45 1913 if (pane) {
Chris@45 1914 while (pane->getLayerCount() > 0) {
Chris@45 1915 Layer *layer = pane->getLayer(0);
Chris@45 1916 if (layer) {
Chris@45 1917 m_document->removeLayerFromView(pane, layer);
Chris@45 1918 } else {
Chris@45 1919 break;
Chris@45 1920 }
Chris@45 1921 }
Chris@45 1922
Chris@45 1923 RemovePaneCommand *command = new RemovePaneCommand(this, pane);
Chris@45 1924 CommandHistory::getInstance()->addCommand(command);
Chris@45 1925 }
Chris@45 1926
Chris@45 1927 CommandHistory::getInstance()->endCompoundOperation();
Chris@45 1928
Chris@45 1929 updateMenuStates();
Chris@45 1930 }
Chris@45 1931
Chris@45 1932 void
Chris@45 1933 MainWindowBase::deleteCurrentLayer()
Chris@45 1934 {
Chris@45 1935 Pane *pane = m_paneStack->getCurrentPane();
Chris@45 1936 if (pane) {
Chris@45 1937 Layer *layer = pane->getSelectedLayer();
Chris@45 1938 if (layer) {
Chris@45 1939 m_document->removeLayerFromView(pane, layer);
Chris@45 1940 }
Chris@45 1941 }
Chris@45 1942 updateMenuStates();
Chris@45 1943 }
Chris@45 1944
Chris@45 1945 void
Chris@123 1946 MainWindowBase::editCurrentLayer()
Chris@123 1947 {
Chris@123 1948 Layer *layer = 0;
Chris@123 1949 Pane *pane = m_paneStack->getCurrentPane();
Chris@123 1950 if (pane) layer = pane->getSelectedLayer();
Chris@123 1951 if (!layer) return;
Chris@123 1952
Chris@123 1953 Model *model = layer->getModel();
Chris@123 1954 if (!model) return;
Chris@123 1955
Chris@124 1956 TabularModel *tabular = dynamic_cast<TabularModel *>(model);
Chris@124 1957 if (!tabular) {
Chris@124 1958 //!!! how to prevent this function from being active if not
Chris@124 1959 //appropriate model type? or will we ultimately support
Chris@124 1960 //tabular display for all editable models?
Chris@124 1961 std::cerr << "NOTE: Not a tabular model" << std::endl;
Chris@124 1962 return;
Chris@124 1963 }
Chris@124 1964
Chris@123 1965 if (m_layerDataDialogMap.find(layer) != m_layerDataDialogMap.end()) {
Chris@126 1966 if (!m_layerDataDialogMap[layer].isNull()) {
Chris@126 1967 m_layerDataDialogMap[layer]->show();
Chris@126 1968 m_layerDataDialogMap[layer]->raise();
Chris@126 1969 return;
Chris@126 1970 }
Chris@123 1971 }
Chris@123 1972
Chris@125 1973 QString title = layer->getLayerPresentationName();
Chris@125 1974
Chris@125 1975 ModelDataTableDialog *dialog = new ModelDataTableDialog(tabular, title, this);
Chris@128 1976 dialog->setAttribute(Qt::WA_DeleteOnClose);
Chris@128 1977
Chris@128 1978 connectLayerEditDialog(dialog);
Chris@123 1979
Chris@128 1980 m_layerDataDialogMap[layer] = dialog;
Chris@128 1981 m_viewDataDialogMap[pane].insert(dialog);
Chris@128 1982
Chris@128 1983 dialog->show();
Chris@128 1984 }
Chris@128 1985
Chris@128 1986 void
Chris@128 1987 MainWindowBase::connectLayerEditDialog(ModelDataTableDialog *dialog)
Chris@128 1988 {
Chris@123 1989 connect(m_viewManager,
Chris@123 1990 SIGNAL(globalCentreFrameChanged(unsigned long)),
Chris@123 1991 dialog,
Chris@127 1992 SLOT(userScrolledToFrame(unsigned long)));
Chris@127 1993
Chris@127 1994 connect(m_viewManager,
Chris@127 1995 SIGNAL(playbackFrameChanged(unsigned long)),
Chris@127 1996 dialog,
Chris@127 1997 SLOT(playbackScrolledToFrame(unsigned long)));
Chris@127 1998
Chris@123 1999 connect(dialog,
Chris@123 2000 SIGNAL(scrollToFrame(unsigned long)),
Chris@123 2001 m_viewManager,
Chris@123 2002 SLOT(setGlobalCentreFrame(unsigned long)));
Chris@129 2003
Chris@129 2004 connect(dialog,
Chris@129 2005 SIGNAL(scrollToFrame(unsigned long)),
Chris@129 2006 m_viewManager,
Chris@129 2007 SLOT(setPlaybackFrame(unsigned long)));
Chris@128 2008 }
Chris@123 2009
Chris@123 2010 void
Chris@73 2011 MainWindowBase::previousPane()
Chris@73 2012 {
Chris@73 2013 if (!m_paneStack) return;
Chris@73 2014
Chris@73 2015 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@73 2016 if (!currentPane) return;
Chris@73 2017
Chris@73 2018 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@73 2019 if (m_paneStack->getPane(i) == currentPane) {
Chris@73 2020 if (i == 0) return;
Chris@73 2021 m_paneStack->setCurrentPane(m_paneStack->getPane(i-1));
Chris@73 2022 updateMenuStates();
Chris@73 2023 return;
Chris@73 2024 }
Chris@73 2025 }
Chris@73 2026 }
Chris@73 2027
Chris@73 2028 void
Chris@73 2029 MainWindowBase::nextPane()
Chris@73 2030 {
Chris@73 2031 if (!m_paneStack) return;
Chris@73 2032
Chris@73 2033 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@73 2034 if (!currentPane) return;
Chris@73 2035
Chris@73 2036 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@73 2037 if (m_paneStack->getPane(i) == currentPane) {
Chris@73 2038 if (i == m_paneStack->getPaneCount()-1) return;
Chris@73 2039 m_paneStack->setCurrentPane(m_paneStack->getPane(i+1));
Chris@73 2040 updateMenuStates();
Chris@73 2041 return;
Chris@73 2042 }
Chris@73 2043 }
Chris@73 2044 }
Chris@73 2045
Chris@73 2046 void
Chris@73 2047 MainWindowBase::previousLayer()
Chris@73 2048 {
Chris@73 2049 //!!! Not right -- pane lists layers in stacking order
Chris@73 2050
Chris@73 2051 if (!m_paneStack) return;
Chris@73 2052
Chris@73 2053 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@73 2054 if (!currentPane) return;
Chris@73 2055
Chris@73 2056 Layer *currentLayer = currentPane->getSelectedLayer();
Chris@73 2057 if (!currentLayer) return;
Chris@73 2058
Chris@73 2059 for (int i = 0; i < currentPane->getLayerCount(); ++i) {
Chris@73 2060 if (currentPane->getLayer(i) == currentLayer) {
Chris@73 2061 if (i == 0) return;
Chris@73 2062 m_paneStack->setCurrentLayer(currentPane,
Chris@73 2063 currentPane->getLayer(i-1));
Chris@73 2064 updateMenuStates();
Chris@73 2065 return;
Chris@73 2066 }
Chris@73 2067 }
Chris@73 2068 }
Chris@73 2069
Chris@73 2070 void
Chris@73 2071 MainWindowBase::nextLayer()
Chris@73 2072 {
Chris@73 2073 //!!! Not right -- pane lists layers in stacking order
Chris@73 2074
Chris@73 2075 if (!m_paneStack) return;
Chris@73 2076
Chris@73 2077 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@73 2078 if (!currentPane) return;
Chris@73 2079
Chris@73 2080 Layer *currentLayer = currentPane->getSelectedLayer();
Chris@73 2081 if (!currentLayer) return;
Chris@73 2082
Chris@73 2083 for (int i = 0; i < currentPane->getLayerCount(); ++i) {
Chris@73 2084 if (currentPane->getLayer(i) == currentLayer) {
Chris@73 2085 if (i == currentPane->getLayerCount()-1) return;
Chris@73 2086 m_paneStack->setCurrentLayer(currentPane,
Chris@73 2087 currentPane->getLayer(i+1));
Chris@73 2088 updateMenuStates();
Chris@73 2089 return;
Chris@73 2090 }
Chris@73 2091 }
Chris@73 2092 }
Chris@73 2093
Chris@73 2094 void
Chris@45 2095 MainWindowBase::playbackFrameChanged(unsigned long frame)
Chris@45 2096 {
Chris@45 2097 if (!(m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
Chris@45 2098
Chris@45 2099 RealTime now = RealTime::frame2RealTime
Chris@45 2100 (frame, getMainModel()->getSampleRate());
Chris@45 2101
Chris@45 2102 if (now.sec == m_lastPlayStatusSec) return;
Chris@45 2103
Chris@45 2104 RealTime then = RealTime::frame2RealTime
Chris@45 2105 (m_playSource->getPlayEndFrame(), getMainModel()->getSampleRate());
Chris@45 2106
Chris@45 2107 QString nowStr;
Chris@45 2108 QString thenStr;
Chris@45 2109 QString remainingStr;
Chris@45 2110
Chris@45 2111 if (then.sec > 10) {
Chris@45 2112 nowStr = now.toSecText().c_str();
Chris@45 2113 thenStr = then.toSecText().c_str();
Chris@45 2114 remainingStr = (then - now).toSecText().c_str();
Chris@45 2115 m_lastPlayStatusSec = now.sec;
Chris@45 2116 } else {
Chris@45 2117 nowStr = now.toText(true).c_str();
Chris@45 2118 thenStr = then.toText(true).c_str();
Chris@45 2119 remainingStr = (then - now).toText(true).c_str();
Chris@45 2120 }
Chris@45 2121
Chris@45 2122 m_myStatusMessage = tr("Playing: %1 of %2 (%3 remaining)")
Chris@45 2123 .arg(nowStr).arg(thenStr).arg(remainingStr);
Chris@45 2124
Chris@45 2125 statusBar()->showMessage(m_myStatusMessage);
Chris@45 2126 }
Chris@45 2127
Chris@45 2128 void
Chris@45 2129 MainWindowBase::globalCentreFrameChanged(unsigned long )
Chris@45 2130 {
Chris@45 2131 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
Chris@45 2132 Pane *p = 0;
Chris@45 2133 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
Chris@45 2134 if (!p->getFollowGlobalPan()) return;
Chris@45 2135 updateVisibleRangeDisplay(p);
Chris@45 2136 }
Chris@45 2137
Chris@45 2138 void
Chris@123 2139 MainWindowBase::viewCentreFrameChanged(View *v, unsigned long frame)
Chris@45 2140 {
Chris@123 2141 std::cerr << "MainWindowBase::viewCentreFrameChanged(" << v << "," << frame << ")" << std::endl;
Chris@123 2142
Chris@123 2143 if (m_viewDataDialogMap.find(v) != m_viewDataDialogMap.end()) {
Chris@123 2144 for (DataDialogSet::iterator i = m_viewDataDialogMap[v].begin();
Chris@123 2145 i != m_viewDataDialogMap[v].end(); ++i) {
Chris@127 2146 (*i)->userScrolledToFrame(frame);
Chris@123 2147 }
Chris@123 2148 }
Chris@45 2149 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
Chris@45 2150 Pane *p = 0;
Chris@45 2151 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
Chris@45 2152 if (v == p) updateVisibleRangeDisplay(p);
Chris@45 2153 }
Chris@45 2154
Chris@45 2155 void
Chris@45 2156 MainWindowBase::viewZoomLevelChanged(View *v, unsigned long , bool )
Chris@45 2157 {
Chris@45 2158 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
Chris@45 2159 Pane *p = 0;
Chris@45 2160 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
Chris@45 2161 if (v == p) updateVisibleRangeDisplay(p);
Chris@45 2162 }
Chris@45 2163
Chris@45 2164 void
Chris@45 2165 MainWindowBase::layerAdded(Layer *)
Chris@45 2166 {
Chris@45 2167 // std::cerr << "MainWindowBase::layerAdded(" << layer << ")" << std::endl;
Chris@45 2168 updateMenuStates();
Chris@45 2169 }
Chris@45 2170
Chris@45 2171 void
Chris@45 2172 MainWindowBase::layerRemoved(Layer *)
Chris@45 2173 {
Chris@45 2174 // std::cerr << "MainWindowBase::layerRemoved(" << layer << ")" << std::endl;
Chris@45 2175 updateMenuStates();
Chris@45 2176 }
Chris@45 2177
Chris@45 2178 void
Chris@45 2179 MainWindowBase::layerAboutToBeDeleted(Layer *layer)
Chris@45 2180 {
Chris@128 2181 std::cerr << "MainWindowBase::layerAboutToBeDeleted(" << layer << ")" << std::endl;
Chris@123 2182
Chris@128 2183 removeLayerEditDialog(layer);
Chris@123 2184
Chris@47 2185 if (m_timeRulerLayer && (layer == m_timeRulerLayer)) {
Chris@45 2186 // std::cerr << "(this is the time ruler layer)" << std::endl;
Chris@45 2187 m_timeRulerLayer = 0;
Chris@45 2188 }
Chris@45 2189 }
Chris@45 2190
Chris@45 2191 void
Chris@45 2192 MainWindowBase::layerInAView(Layer *layer, bool inAView)
Chris@45 2193 {
Chris@128 2194 std::cerr << "MainWindowBase::layerInAView(" << layer << "," << inAView << ")" << std::endl;
Chris@128 2195
Chris@128 2196 if (!inAView) removeLayerEditDialog(layer);
Chris@45 2197
Chris@45 2198 // Check whether we need to add or remove model from play source
Chris@45 2199 Model *model = layer->getModel();
Chris@45 2200 if (model) {
Chris@45 2201 if (inAView) {
Chris@45 2202 m_playSource->addModel(model);
Chris@45 2203 } else {
Chris@45 2204 bool found = false;
Chris@45 2205 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@45 2206 Pane *pane = m_paneStack->getPane(i);
Chris@45 2207 if (!pane) continue;
Chris@45 2208 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@45 2209 Layer *pl = pane->getLayer(j);
Chris@45 2210 if (pl && pl->getModel() == model) {
Chris@45 2211 found = true;
Chris@45 2212 break;
Chris@45 2213 }
Chris@45 2214 }
Chris@45 2215 if (found) break;
Chris@45 2216 }
Chris@45 2217 if (!found) m_playSource->removeModel(model);
Chris@45 2218 }
Chris@45 2219 }
Chris@45 2220
Chris@45 2221 updateMenuStates();
Chris@45 2222 }
Chris@45 2223
Chris@45 2224 void
Chris@128 2225 MainWindowBase::removeLayerEditDialog(Layer *layer)
Chris@128 2226 {
Chris@128 2227 if (m_layerDataDialogMap.find(layer) != m_layerDataDialogMap.end()) {
Chris@128 2228
Chris@128 2229 ModelDataTableDialog *dialog = m_layerDataDialogMap[layer];
Chris@128 2230
Chris@128 2231 for (ViewDataDialogMap::iterator vi = m_viewDataDialogMap.begin();
Chris@128 2232 vi != m_viewDataDialogMap.end(); ++vi) {
Chris@128 2233 vi->second.erase(dialog);
Chris@128 2234 }
Chris@128 2235
Chris@128 2236 m_layerDataDialogMap.erase(layer);
Chris@128 2237 delete dialog;
Chris@128 2238 }
Chris@128 2239 }
Chris@128 2240
Chris@128 2241 void
Chris@45 2242 MainWindowBase::modelAdded(Model *model)
Chris@45 2243 {
Chris@45 2244 // std::cerr << "MainWindowBase::modelAdded(" << model << ")" << std::endl;
Chris@45 2245 m_playSource->addModel(model);
Chris@45 2246 }
Chris@45 2247
Chris@45 2248 void
Chris@45 2249 MainWindowBase::mainModelChanged(WaveFileModel *model)
Chris@45 2250 {
Chris@45 2251 // std::cerr << "MainWindowBase::mainModelChanged(" << model << ")" << std::endl;
Chris@45 2252 updateDescriptionLabel();
Chris@45 2253 if (model) m_viewManager->setMainModelSampleRate(model->getSampleRate());
Chris@45 2254 if (model && !m_playTarget && m_audioOutput) createPlayTarget();
Chris@45 2255 }
Chris@45 2256
Chris@45 2257 void
Chris@45 2258 MainWindowBase::modelAboutToBeDeleted(Model *model)
Chris@45 2259 {
Chris@45 2260 // std::cerr << "MainWindowBase::modelAboutToBeDeleted(" << model << ")" << std::endl;
Chris@45 2261 if (model == m_viewManager->getPlaybackModel()) {
Chris@45 2262 m_viewManager->setPlaybackModel(0);
Chris@45 2263 }
Chris@45 2264 m_playSource->removeModel(model);
Chris@45 2265 FFTDataServer::modelAboutToBeDeleted(model);
Chris@45 2266 }
Chris@45 2267
Chris@45 2268 void
Chris@55 2269 MainWindowBase::paneDeleteButtonClicked(Pane *pane)
Chris@55 2270 {
Chris@55 2271 bool found = false;
Chris@55 2272 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@55 2273 if (m_paneStack->getPane(i) == pane) {
Chris@55 2274 found = true;
Chris@55 2275 break;
Chris@55 2276 }
Chris@55 2277 }
Chris@55 2278 if (!found) {
Chris@55 2279 std::cerr << "MainWindowBase::paneDeleteButtonClicked: Unknown pane "
Chris@55 2280 << pane << std::endl;
Chris@55 2281 return;
Chris@55 2282 }
Chris@55 2283
Chris@55 2284 CommandHistory::getInstance()->startCompoundOperation
Chris@55 2285 (tr("Delete Pane"), true);
Chris@55 2286
Chris@55 2287 while (pane->getLayerCount() > 0) {
Chris@55 2288 Layer *layer = pane->getLayer(0);
Chris@55 2289 if (layer) {
Chris@55 2290 m_document->removeLayerFromView(pane, layer);
Chris@55 2291 } else {
Chris@55 2292 break;
Chris@55 2293 }
Chris@55 2294 }
Chris@55 2295
Chris@55 2296 RemovePaneCommand *command = new RemovePaneCommand(this, pane);
Chris@55 2297 CommandHistory::getInstance()->addCommand(command);
Chris@55 2298
Chris@55 2299 CommandHistory::getInstance()->endCompoundOperation();
Chris@55 2300
Chris@55 2301 updateMenuStates();
Chris@55 2302 }
Chris@55 2303
Chris@55 2304 void
Chris@45 2305 MainWindowBase::pollOSC()
Chris@45 2306 {
Chris@45 2307 if (!m_oscQueue || m_oscQueue->isEmpty()) return;
Chris@45 2308 std::cerr << "MainWindowBase::pollOSC: have " << m_oscQueue->getMessagesAvailable() << " messages" << std::endl;
Chris@45 2309
Chris@45 2310 if (m_openingAudioFile) return;
Chris@45 2311
Chris@45 2312 OSCMessage message = m_oscQueue->readMessage();
Chris@45 2313
Chris@45 2314 if (message.getTarget() != 0) {
Chris@45 2315 return; //!!! for now -- this class is target 0, others not handled yet
Chris@45 2316 }
Chris@45 2317
Chris@45 2318 handleOSCMessage(message);
Chris@45 2319 }
Chris@45 2320
Chris@45 2321 void
Chris@45 2322 MainWindowBase::inProgressSelectionChanged()
Chris@45 2323 {
Chris@45 2324 Pane *currentPane = 0;
Chris@45 2325 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
Chris@45 2326 if (currentPane) updateVisibleRangeDisplay(currentPane);
Chris@45 2327 }
Chris@45 2328
Chris@45 2329 void
Chris@45 2330 MainWindowBase::contextHelpChanged(const QString &s)
Chris@45 2331 {
Chris@45 2332 if (s == "" && m_myStatusMessage != "") {
Chris@45 2333 statusBar()->showMessage(m_myStatusMessage);
Chris@45 2334 return;
Chris@45 2335 }
Chris@45 2336 statusBar()->showMessage(s);
Chris@45 2337 }
Chris@45 2338
Chris@45 2339 void
Chris@45 2340 MainWindowBase::openHelpUrl(QString url)
Chris@45 2341 {
Chris@45 2342 // This method mostly lifted from Qt Assistant source code
Chris@45 2343
Chris@45 2344 QProcess *process = new QProcess(this);
Chris@45 2345 connect(process, SIGNAL(finished(int)), process, SLOT(deleteLater()));
Chris@45 2346
Chris@45 2347 QStringList args;
Chris@45 2348
Chris@45 2349 #ifdef Q_OS_MAC
Chris@45 2350 args.append(url);
Chris@45 2351 process->start("open", args);
Chris@45 2352 #else
Chris@45 2353 #ifdef Q_OS_WIN32
Chris@45 2354
Chris@45 2355 QString pf(getenv("ProgramFiles"));
Chris@45 2356 QString command = pf + QString("\\Internet Explorer\\IEXPLORE.EXE");
Chris@45 2357
Chris@45 2358 args.append(url);
Chris@45 2359 process->start(command, args);
Chris@45 2360
Chris@45 2361 #else
Chris@45 2362 #ifdef Q_WS_X11
Chris@45 2363 if (!qgetenv("KDE_FULL_SESSION").isEmpty()) {
Chris@45 2364 args.append("exec");
Chris@45 2365 args.append(url);
Chris@45 2366 process->start("kfmclient", args);
Chris@45 2367 } else if (!qgetenv("BROWSER").isEmpty()) {
Chris@45 2368 args.append(url);
Chris@45 2369 process->start(qgetenv("BROWSER"), args);
Chris@45 2370 } else {
Chris@45 2371 args.append(url);
Chris@45 2372 process->start("firefox", args);
Chris@45 2373 }
Chris@45 2374 #endif
Chris@45 2375 #endif
Chris@45 2376 #endif
Chris@45 2377 }
Chris@45 2378