annotate main/MainWindow.cpp @ 118:b4110b17bca8

* Fix #1672407 confused by plugin-named files in cwd (or home?) * Fix #1491848 crash when loading new file while transform plugin runs * Fix #1502287 Background remains black after spectrogram layer deleted * Fix #1604477 Replacing the main audio file silences secondary audio file * Fix failure to initialise property box layout to last preference on startup * Fix resample/wrong-rate display in Pane, ensure that right rate is chosen if all current models have an acceptable rate even if previous main model had a different one * Fix "global zoom" broken in previous commit * Some fixes to spectrogram cache area updating (makes spectrogram appear more quickly, previously it had a tendency to refresh with empty space) * Fixes to colour 3d plot normalization
author Chris Cannam
date Thu, 08 Mar 2007 16:53:08 +0000
parents 8089a394829a
children 3fff180a254b
rev   line source
Chris@0 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@0 4 Sonic Visualiser
Chris@0 5 An audio file viewer and annotation editor.
Chris@0 6 Centre for Digital Music, Queen Mary, University of London.
Chris@77 7 This file copyright 2006 Chris Cannam and QMUL.
Chris@0 8
Chris@0 9 This program is free software; you can redistribute it and/or
Chris@0 10 modify it under the terms of the GNU General Public License as
Chris@0 11 published by the Free Software Foundation; either version 2 of the
Chris@0 12 License, or (at your option) any later version. See the file
Chris@0 13 COPYING included with this distribution for more information.
Chris@0 14 */
Chris@0 15
Chris@1 16 #include "version.h"
Chris@0 17
Chris@0 18 #include "MainWindow.h"
Chris@1 19 #include "document/Document.h"
Chris@0 20 #include "PreferencesDialog.h"
Chris@0 21
Chris@1 22 #include "view/Pane.h"
Chris@1 23 #include "view/PaneStack.h"
Chris@1 24 #include "data/model/WaveFileModel.h"
Chris@1 25 #include "data/model/SparseOneDimensionalModel.h"
Chris@1 26 #include "view/ViewManager.h"
Chris@0 27 #include "base/Preferences.h"
Chris@0 28 #include "layer/WaveformLayer.h"
Chris@0 29 #include "layer/TimeRulerLayer.h"
Chris@0 30 #include "layer/TimeInstantLayer.h"
Chris@0 31 #include "layer/TimeValueLayer.h"
Chris@0 32 #include "layer/Colour3DPlotLayer.h"
Chris@95 33 #include "layer/SliceLayer.h"
Chris@95 34 #include "layer/SliceableLayer.h"
Chris@0 35 #include "widgets/Fader.h"
Chris@65 36 #include "view/Overview.h"
Chris@0 37 #include "widgets/PropertyBox.h"
Chris@0 38 #include "widgets/PropertyStack.h"
Chris@0 39 #include "widgets/AudioDial.h"
Chris@0 40 #include "widgets/LayerTree.h"
Chris@0 41 #include "widgets/ListInputDialog.h"
Chris@36 42 #include "widgets/SubdividingMenu.h"
Chris@90 43 #include "widgets/NotifyingPushButton.h"
Chris@0 44 #include "audioio/AudioCallbackPlaySource.h"
Chris@0 45 #include "audioio/AudioCallbackPlayTarget.h"
Chris@0 46 #include "audioio/AudioTargetFactory.h"
Chris@59 47 #include "audioio/PlaySpeedRangeMapper.h"
Chris@1 48 #include "data/fileio/AudioFileReaderFactory.h"
Chris@1 49 #include "data/fileio/DataFileReaderFactory.h"
Chris@1 50 #include "data/fileio/WavFileWriter.h"
Chris@1 51 #include "data/fileio/CSVFileWriter.h"
Chris@1 52 #include "data/fileio/BZipFileDevice.h"
Chris@85 53 #include "data/fileio/RemoteFile.h"
Chris@91 54 #include "data/fft/FFTDataServer.h"
Chris@1 55 #include "base/RecentFiles.h"
Chris@0 56 #include "transform/TransformFactory.h"
Chris@0 57 #include "base/PlayParameterRepository.h"
Chris@0 58 #include "base/XmlExportable.h"
Chris@0 59 #include "base/CommandHistory.h"
Chris@0 60 #include "base/Profiler.h"
Chris@0 61 #include "base/Clipboard.h"
Chris@69 62 #include "osc/OSCQueue.h"
Chris@0 63
Chris@0 64 // For version information
Chris@0 65 #include "vamp/vamp.h"
Chris@0 66 #include "vamp-sdk/PluginBase.h"
Chris@0 67 #include "plugin/api/ladspa.h"
Chris@0 68 #include "plugin/api/dssi.h"
Chris@0 69
Chris@0 70 #include <QApplication>
Chris@0 71 #include <QMessageBox>
Chris@0 72 #include <QGridLayout>
Chris@0 73 #include <QLabel>
Chris@0 74 #include <QAction>
Chris@0 75 #include <QMenuBar>
Chris@0 76 #include <QToolBar>
Chris@0 77 #include <QInputDialog>
Chris@0 78 #include <QStatusBar>
Chris@0 79 #include <QTreeView>
Chris@0 80 #include <QFile>
Chris@88 81 #include <QFileInfo>
Chris@88 82 #include <QDir>
Chris@0 83 #include <QTextStream>
Chris@0 84 #include <QProcess>
Chris@7 85 #include <QShortcut>
Chris@5 86 #include <QSettings>
Chris@11 87 #include <QDateTime>
Chris@11 88 #include <QProcess>
Chris@16 89 #include <QCheckBox>
Chris@55 90 #include <QRegExp>
Chris@0 91
Chris@0 92 #include <iostream>
Chris@0 93 #include <cstdio>
Chris@0 94 #include <errno.h>
Chris@0 95
Chris@0 96 using std::cerr;
Chris@0 97 using std::endl;
Chris@0 98
Chris@33 99 using std::vector;
Chris@33 100 using std::map;
Chris@33 101 using std::set;
Chris@33 102
Chris@0 103
Chris@70 104 MainWindow::MainWindow(bool withAudioOutput, bool withOSCSupport) :
Chris@0 105 m_document(0),
Chris@0 106 m_paneStack(0),
Chris@0 107 m_viewManager(0),
Chris@65 108 m_overview(0),
Chris@0 109 m_timeRulerLayer(0),
Chris@46 110 m_audioOutput(withAudioOutput),
Chris@0 111 m_playSource(0),
Chris@0 112 m_playTarget(0),
Chris@70 113 m_oscQueue(withOSCSupport ? new OSCQueue() : 0),
Chris@81 114 m_recentFiles("RecentFiles", 20),
Chris@49 115 m_recentTransforms("RecentTransforms", 20),
Chris@0 116 m_mainMenusCreated(false),
Chris@0 117 m_paneMenu(0),
Chris@0 118 m_layerMenu(0),
Chris@34 119 m_transformsMenu(0),
Chris@0 120 m_existingLayersMenu(0),
Chris@95 121 m_sliceMenu(0),
Chris@34 122 m_recentFilesMenu(0),
Chris@34 123 m_recentTransformsMenu(0),
Chris@0 124 m_rightButtonMenu(0),
Chris@0 125 m_rightButtonLayerMenu(0),
Chris@34 126 m_rightButtonTransformsMenu(0),
Chris@0 127 m_documentModified(false),
Chris@70 128 m_openingAudioFile(false),
Chris@70 129 m_abandoning(false),
Chris@0 130 m_preferencesDialog(0)
Chris@0 131 {
Chris@0 132 setWindowTitle(tr("Sonic Visualiser"));
Chris@0 133
Chris@0 134 UnitDatabase::getInstance()->registerUnit("Hz");
Chris@0 135 UnitDatabase::getInstance()->registerUnit("dB");
Chris@0 136
Chris@0 137 connect(CommandHistory::getInstance(), SIGNAL(commandExecuted()),
Chris@0 138 this, SLOT(documentModified()));
Chris@0 139 connect(CommandHistory::getInstance(), SIGNAL(documentRestored()),
Chris@0 140 this, SLOT(documentRestored()));
Chris@0 141
Chris@0 142 QFrame *frame = new QFrame;
Chris@0 143 setCentralWidget(frame);
Chris@0 144
Chris@0 145 QGridLayout *layout = new QGridLayout;
Chris@0 146
Chris@0 147 m_viewManager = new ViewManager();
Chris@0 148 connect(m_viewManager, SIGNAL(selectionChanged()),
Chris@0 149 this, SLOT(updateMenuStates()));
Chris@117 150 connect(m_viewManager, SIGNAL(inProgressSelectionChanged()),
Chris@117 151 this, SLOT(inProgressSelectionChanged()));
Chris@0 152
Chris@0 153 m_descriptionLabel = new QLabel;
Chris@0 154
Chris@0 155 m_paneStack = new PaneStack(frame, m_viewManager);
Chris@0 156 connect(m_paneStack, SIGNAL(currentPaneChanged(Pane *)),
Chris@0 157 this, SLOT(currentPaneChanged(Pane *)));
Chris@0 158 connect(m_paneStack, SIGNAL(currentLayerChanged(Pane *, Layer *)),
Chris@0 159 this, SLOT(currentLayerChanged(Pane *, Layer *)));
Chris@0 160 connect(m_paneStack, SIGNAL(rightButtonMenuRequested(Pane *, QPoint)),
Chris@0 161 this, SLOT(rightButtonMenuRequested(Pane *, QPoint)));
Chris@73 162 connect(m_paneStack, SIGNAL(propertyStacksResized()),
Chris@73 163 this, SLOT(propertyStacksResized()));
Chris@90 164 connect(m_paneStack, SIGNAL(contextHelpChanged(const QString &)),
Chris@116 165 this, SLOT(contextHelpChanged(const QString &)));
Chris@0 166
Chris@65 167 m_overview = new Overview(frame);
Chris@65 168 m_overview->setViewManager(m_viewManager);
Chris@65 169 m_overview->setFixedHeight(40);
Chris@90 170 connect(m_overview, SIGNAL(contextHelpChanged(const QString &)),
Chris@116 171 this, SLOT(contextHelpChanged(const QString &)));
Chris@0 172
Chris@0 173 m_panLayer = new WaveformLayer;
Chris@0 174 m_panLayer->setChannelMode(WaveformLayer::MergeChannels);
Chris@0 175 // m_panLayer->setScale(WaveformLayer::MeterScale);
Chris@39 176 // m_panLayer->setAutoNormalize(true);
Chris@0 177 m_panLayer->setBaseColour(Qt::darkGreen);
Chris@0 178 m_panLayer->setAggressiveCacheing(true);
Chris@65 179 m_overview->addLayer(m_panLayer);
Chris@0 180
Chris@0 181 m_playSource = new AudioCallbackPlaySource(m_viewManager);
Chris@0 182
Chris@0 183 connect(m_playSource, SIGNAL(sampleRateMismatch(size_t, size_t, bool)),
Chris@0 184 this, SLOT(sampleRateMismatch(size_t, size_t, bool)));
Chris@42 185 connect(m_playSource, SIGNAL(audioOverloadPluginDisabled()),
Chris@42 186 this, SLOT(audioOverloadPluginDisabled()));
Chris@0 187
Chris@0 188 m_fader = new Fader(frame, false);
Chris@90 189 connect(m_fader, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
Chris@90 190 connect(m_fader, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
Chris@0 191
Chris@0 192 m_playSpeed = new AudioDial(frame);
Chris@12 193 m_playSpeed->setMinimum(0);
Chris@48 194 m_playSpeed->setMaximum(200);
Chris@25 195 m_playSpeed->setValue(100);
Chris@0 196 m_playSpeed->setFixedWidth(24);
Chris@0 197 m_playSpeed->setFixedHeight(24);
Chris@0 198 m_playSpeed->setNotchesVisible(true);
Chris@25 199 m_playSpeed->setPageStep(10);
Chris@60 200 m_playSpeed->setObjectName(tr("Playback Speedup"));
Chris@25 201 m_playSpeed->setDefaultValue(100);
Chris@59 202 m_playSpeed->setRangeMapper(new PlaySpeedRangeMapper(0, 200));
Chris@60 203 m_playSpeed->setShowToolTip(true);
Chris@0 204 connect(m_playSpeed, SIGNAL(valueChanged(int)),
Chris@0 205 this, SLOT(playSpeedChanged(int)));
Chris@90 206 connect(m_playSpeed, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
Chris@90 207 connect(m_playSpeed, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
Chris@90 208
Chris@90 209 m_playSharpen = new NotifyingPushButton(frame);
Chris@17 210 m_playSharpen->setToolTip(tr("Sharpen percussive transients"));
Chris@26 211 m_playSharpen->setFixedSize(20, 20);
Chris@26 212 // m_playSharpen->setFlat(true);
Chris@16 213 m_playSharpen->setEnabled(false);
Chris@26 214 m_playSharpen->setCheckable(true);
Chris@26 215 m_playSharpen->setChecked(false);
Chris@26 216 m_playSharpen->setIcon(QIcon(":icons/sharpen.png"));
Chris@26 217 connect(m_playSharpen, SIGNAL(clicked()), this, SLOT(playSharpenToggled()));
Chris@90 218 connect(m_playSharpen, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
Chris@90 219 connect(m_playSharpen, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
Chris@90 220
Chris@90 221 m_playMono = new NotifyingPushButton(frame);
Chris@26 222 m_playMono->setToolTip(tr("Run time stretcher in mono only"));
Chris@26 223 m_playMono->setFixedSize(20, 20);
Chris@26 224 // m_playMono->setFlat(true);
Chris@26 225 m_playMono->setEnabled(false);
Chris@26 226 m_playMono->setCheckable(true);
Chris@26 227 m_playMono->setChecked(false);
Chris@26 228 m_playMono->setIcon(QIcon(":icons/mono.png"));
Chris@26 229 connect(m_playMono, SIGNAL(clicked()), this, SLOT(playMonoToggled()));
Chris@90 230 connect(m_playMono, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
Chris@90 231 connect(m_playMono, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
Chris@21 232
Chris@21 233 QSettings settings;
Chris@21 234 settings.beginGroup("MainWindow");
Chris@24 235 m_playSharpen->setChecked(settings.value("playsharpen", true).toBool());
Chris@26 236 m_playMono->setChecked(settings.value("playmono", false).toBool());
Chris@21 237 settings.endGroup();
Chris@21 238
Chris@26 239 layout->addWidget(m_paneStack, 0, 0, 1, 5);
Chris@65 240 layout->addWidget(m_overview, 1, 0);
Chris@0 241 layout->addWidget(m_fader, 1, 1);
Chris@0 242 layout->addWidget(m_playSpeed, 1, 2);
Chris@16 243 layout->addWidget(m_playSharpen, 1, 3);
Chris@26 244 layout->addWidget(m_playMono, 1, 4);
Chris@16 245
Chris@16 246 layout->setColumnStretch(0, 10);
Chris@16 247
Chris@0 248 frame->setLayout(layout);
Chris@0 249
Chris@0 250 connect(m_viewManager, SIGNAL(outputLevelsChanged(float, float)),
Chris@0 251 this, SLOT(outputLevelsChanged(float, float)));
Chris@0 252
Chris@116 253 connect(m_viewManager, SIGNAL(playbackFrameChanged(unsigned long)),
Chris@116 254 this, SLOT(playbackFrameChanged(unsigned long)));
Chris@116 255
Chris@116 256 connect(m_viewManager, SIGNAL(globalCentreFrameChanged(unsigned long)),
Chris@116 257 this, SLOT(globalCentreFrameChanged(unsigned long)));
Chris@116 258
Chris@116 259 connect(m_viewManager, SIGNAL(viewCentreFrameChanged(View *, unsigned long)),
Chris@116 260 this, SLOT(viewCentreFrameChanged(View *, unsigned long)));
Chris@116 261
Chris@116 262 connect(m_viewManager, SIGNAL(viewZoomLevelChanged(View *, unsigned long, bool)),
Chris@116 263 this, SLOT(viewZoomLevelChanged(View *, unsigned long, bool)));
Chris@116 264
Chris@0 265 connect(Preferences::getInstance(),
Chris@0 266 SIGNAL(propertyChanged(PropertyContainer::PropertyName)),
Chris@0 267 this,
Chris@0 268 SLOT(preferenceChanged(PropertyContainer::PropertyName)));
Chris@0 269
Chris@98 270 // preferenceChanged("Property Box Layout");
Chris@98 271
Chris@70 272 if (m_oscQueue && m_oscQueue->isOK()) {
Chris@69 273 connect(m_oscQueue, SIGNAL(messagesAvailable()), this, SLOT(pollOSC()));
Chris@69 274 QTimer *oscTimer = new QTimer(this);
Chris@69 275 connect(oscTimer, SIGNAL(timeout()), this, SLOT(pollOSC()));
Chris@69 276 oscTimer->start(1000);
Chris@69 277 }
Chris@69 278
Chris@0 279 setupMenus();
Chris@0 280 setupToolbars();
Chris@0 281
Chris@90 282 statusBar();
Chris@0 283
Chris@0 284 newSession();
Chris@0 285 }
Chris@0 286
Chris@0 287 MainWindow::~MainWindow()
Chris@0 288 {
Chris@118 289 std::cerr << "MainWindow::~MainWindow()" << std::endl;
Chris@118 290
Chris@70 291 if (!m_abandoning) {
Chris@70 292 closeSession();
Chris@70 293 }
Chris@0 294 delete m_playTarget;
Chris@0 295 delete m_playSource;
Chris@0 296 delete m_viewManager;
Chris@69 297 delete m_oscQueue;
Chris@0 298 Profiles::getInstance()->dump();
Chris@0 299 }
Chris@0 300
Chris@81 301 QString
Chris@88 302 MainWindow::getOpenFileName(FileFinder::FileType type)
Chris@81 303 {
Chris@88 304 FileFinder *ff = FileFinder::getInstance();
Chris@81 305 switch (type) {
Chris@88 306 case FileFinder::SessionFile:
Chris@88 307 return ff->getOpenFileName(type, m_sessionFile);
Chris@88 308 case FileFinder::AudioFile:
Chris@88 309 return ff->getOpenFileName(type, m_audioFile);
Chris@88 310 case FileFinder::LayerFile:
Chris@88 311 return ff->getOpenFileName(type, m_sessionFile);
Chris@88 312 case FileFinder::SessionOrAudioFile:
Chris@88 313 return ff->getOpenFileName(type, m_sessionFile);
Chris@88 314 case FileFinder::AnyFile:
Chris@88 315 if (getMainModel() != 0 &&
Chris@88 316 m_paneStack != 0 &&
Chris@88 317 m_paneStack->getCurrentPane() != 0) { // can import a layer
Chris@88 318 return ff->getOpenFileName(FileFinder::AnyFile, m_sessionFile);
Chris@81 319 } else {
Chris@88 320 return ff->getOpenFileName(FileFinder::SessionOrAudioFile,
Chris@88 321 m_sessionFile);
Chris@81 322 }
Chris@81 323 }
Chris@88 324 return "";
Chris@88 325 }
Chris@88 326
Chris@88 327 QString
Chris@88 328 MainWindow::getSaveFileName(FileFinder::FileType type)
Chris@88 329 {
Chris@88 330 FileFinder *ff = FileFinder::getInstance();
Chris@88 331 switch (type) {
Chris@88 332 case FileFinder::SessionFile:
Chris@88 333 return ff->getSaveFileName(type, m_sessionFile);
Chris@88 334 case FileFinder::AudioFile:
Chris@88 335 return ff->getSaveFileName(type, m_audioFile);
Chris@88 336 case FileFinder::LayerFile:
Chris@88 337 return ff->getSaveFileName(type, m_sessionFile);
Chris@88 338 case FileFinder::SessionOrAudioFile:
Chris@88 339 return ff->getSaveFileName(type, m_sessionFile);
Chris@88 340 case FileFinder::AnyFile:
Chris@88 341 return ff->getSaveFileName(type, m_sessionFile);
Chris@81 342 }
Chris@88 343 return "";
Chris@81 344 }
Chris@81 345
Chris@88 346 void
Chris@88 347 MainWindow::registerLastOpenedFilePath(FileFinder::FileType type, QString path)
Chris@81 348 {
Chris@88 349 FileFinder *ff = FileFinder::getInstance();
Chris@88 350 ff->registerLastOpenedFilePath(type, path);
Chris@81 351 }
Chris@81 352
Chris@81 353 void
Chris@0 354 MainWindow::setupMenus()
Chris@0 355 {
Chris@0 356 if (!m_mainMenusCreated) {
Chris@0 357 m_rightButtonMenu = new QMenu();
Chris@104 358
Chris@104 359 // No -- we don't want tear-off enabled on the right-button
Chris@104 360 // menu. If it is enabled, then simply right-clicking and
Chris@104 361 // releasing will pop up the menu, activate the tear-off, and
Chris@104 362 // leave the torn-off menu window in front of the main window.
Chris@104 363 // That isn't desirable. I'm not sure it ever would be, in a
Chris@104 364 // context menu -- perhaps technically a Qt bug?
Chris@104 365 // m_rightButtonMenu->setTearOffEnabled(true);
Chris@0 366 }
Chris@0 367
Chris@0 368 if (m_rightButtonLayerMenu) {
Chris@0 369 m_rightButtonLayerMenu->clear();
Chris@0 370 } else {
Chris@0 371 m_rightButtonLayerMenu = m_rightButtonMenu->addMenu(tr("&Layer"));
Chris@97 372 m_rightButtonLayerMenu->setTearOffEnabled(true);
Chris@0 373 m_rightButtonMenu->addSeparator();
Chris@0 374 }
Chris@0 375
Chris@34 376 if (m_rightButtonTransformsMenu) {
Chris@34 377 m_rightButtonTransformsMenu->clear();
Chris@34 378 } else {
Chris@34 379 m_rightButtonTransformsMenu = m_rightButtonMenu->addMenu(tr("&Transform"));
Chris@97 380 m_rightButtonTransformsMenu->setTearOffEnabled(true);
Chris@34 381 m_rightButtonMenu->addSeparator();
Chris@34 382 }
Chris@34 383
Chris@0 384 if (!m_mainMenusCreated) {
Chris@0 385 CommandHistory::getInstance()->registerMenu(m_rightButtonMenu);
Chris@0 386 m_rightButtonMenu->addSeparator();
Chris@66 387 }
Chris@66 388
Chris@66 389 setupFileMenu();
Chris@66 390 setupEditMenu();
Chris@66 391 setupViewMenu();
Chris@66 392 setupPaneAndLayerMenus();
Chris@66 393 setupTransformsMenu();
Chris@66 394 setupHelpMenu();
Chris@66 395
Chris@66 396 m_mainMenusCreated = true;
Chris@66 397 }
Chris@66 398
Chris@66 399 void
Chris@66 400 MainWindow::setupFileMenu()
Chris@66 401 {
Chris@66 402 if (m_mainMenusCreated) return;
Chris@66 403
Chris@66 404 QMenu *menu = menuBar()->addMenu(tr("&File"));
Chris@97 405 menu->setTearOffEnabled(true);
Chris@66 406 QToolBar *toolbar = addToolBar(tr("File Toolbar"));
Chris@66 407
Chris@66 408 QIcon icon(":icons/filenew.png");
Chris@66 409 icon.addFile(":icons/filenew-22.png");
Chris@66 410 QAction *action = new QAction(icon, tr("&New Session"), this);
Chris@66 411 action->setShortcut(tr("Ctrl+N"));
Chris@90 412 action->setStatusTip(tr("Abandon the current Sonic Visualiser session and start a new one"));
Chris@66 413 connect(action, SIGNAL(triggered()), this, SLOT(newSession()));
Chris@66 414 menu->addAction(action);
Chris@66 415 toolbar->addAction(action);
Chris@0 416
Chris@66 417 icon = QIcon(":icons/fileopen.png");
Chris@66 418 icon.addFile(":icons/fileopen-22.png");
Chris@66 419
Chris@66 420 action = new QAction(icon, tr("&Open Session..."), this);
Chris@66 421 action->setShortcut(tr("Ctrl+O"));
Chris@66 422 action->setStatusTip(tr("Open a previously saved Sonic Visualiser session file"));
Chris@66 423 connect(action, SIGNAL(triggered()), this, SLOT(openSession()));
Chris@66 424 menu->addAction(action);
Chris@66 425
Chris@66 426 action = new QAction(icon, tr("&Open..."), this);
Chris@66 427 action->setStatusTip(tr("Open a session file, audio file, or layer"));
Chris@66 428 connect(action, SIGNAL(triggered()), this, SLOT(openSomething()));
Chris@66 429 toolbar->addAction(action);
Chris@66 430
Chris@66 431 icon = QIcon(":icons/filesave.png");
Chris@66 432 icon.addFile(":icons/filesave-22.png");
Chris@66 433 action = new QAction(icon, tr("&Save Session"), this);
Chris@66 434 action->setShortcut(tr("Ctrl+S"));
Chris@66 435 action->setStatusTip(tr("Save the current session into a Sonic Visualiser session file"));
Chris@66 436 connect(action, SIGNAL(triggered()), this, SLOT(saveSession()));
Chris@66 437 connect(this, SIGNAL(canSave(bool)), action, SLOT(setEnabled(bool)));
Chris@66 438 menu->addAction(action);
Chris@66 439 toolbar->addAction(action);
Chris@0 440
Chris@66 441 icon = QIcon(":icons/filesaveas.png");
Chris@66 442 icon.addFile(":icons/filesaveas-22.png");
Chris@66 443 action = new QAction(icon, tr("Save Session &As..."), this);
Chris@66 444 action->setStatusTip(tr("Save the current session into a new Sonic Visualiser session file"));
Chris@66 445 connect(action, SIGNAL(triggered()), this, SLOT(saveSessionAs()));
Chris@66 446 menu->addAction(action);
Chris@66 447 toolbar->addAction(action);
Chris@66 448
Chris@66 449 menu->addSeparator();
Chris@66 450
Chris@66 451 action = new QAction(tr("&Import Audio File..."), this);
Chris@66 452 action->setShortcut(tr("Ctrl+I"));
Chris@66 453 action->setStatusTip(tr("Import an existing audio file"));
Chris@66 454 connect(action, SIGNAL(triggered()), this, SLOT(importAudio()));
Chris@66 455 menu->addAction(action);
Chris@66 456
Chris@66 457 action = new QAction(tr("Import Secondary Audio File..."), this);
Chris@66 458 action->setShortcut(tr("Ctrl+Shift+I"));
Chris@66 459 action->setStatusTip(tr("Import an extra audio file as a separate layer"));
Chris@66 460 connect(action, SIGNAL(triggered()), this, SLOT(importMoreAudio()));
Chris@66 461 connect(this, SIGNAL(canImportMoreAudio(bool)), action, SLOT(setEnabled(bool)));
Chris@66 462 menu->addAction(action);
Chris@66 463
Chris@66 464 action = new QAction(tr("&Export Audio File..."), this);
Chris@66 465 action->setStatusTip(tr("Export selection as an audio file"));
Chris@66 466 connect(action, SIGNAL(triggered()), this, SLOT(exportAudio()));
Chris@66 467 connect(this, SIGNAL(canExportAudio(bool)), action, SLOT(setEnabled(bool)));
Chris@66 468 menu->addAction(action);
Chris@66 469
Chris@66 470 menu->addSeparator();
Chris@66 471
Chris@66 472 action = new QAction(tr("Import Annotation &Layer..."), this);
Chris@66 473 action->setShortcut(tr("Ctrl+L"));
Chris@66 474 action->setStatusTip(tr("Import layer data from an existing file"));
Chris@66 475 connect(action, SIGNAL(triggered()), this, SLOT(importLayer()));
Chris@66 476 connect(this, SIGNAL(canImportLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@66 477 menu->addAction(action);
Chris@66 478
Chris@66 479 action = new QAction(tr("Export Annotation Layer..."), this);
Chris@66 480 action->setStatusTip(tr("Export layer data to a file"));
Chris@66 481 connect(action, SIGNAL(triggered()), this, SLOT(exportLayer()));
Chris@66 482 connect(this, SIGNAL(canExportLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@66 483 menu->addAction(action);
Chris@66 484
Chris@66 485 menu->addSeparator();
Chris@86 486
Chris@86 487 action = new QAction(tr("Open Lo&cation..."), this);
Chris@86 488 action->setShortcut(tr("Ctrl+Shift+O"));
Chris@86 489 action->setStatusTip(tr("Open or import a file from a remote URL"));
Chris@86 490 connect(action, SIGNAL(triggered()), this, SLOT(openLocation()));
Chris@86 491 menu->addAction(action);
Chris@86 492
Chris@86 493 menu->addSeparator();
Chris@86 494
Chris@66 495 m_recentFilesMenu = menu->addMenu(tr("&Recent Files"));
Chris@97 496 m_recentFilesMenu->setTearOffEnabled(true);
Chris@66 497 setupRecentFilesMenu();
Chris@66 498 connect(&m_recentFiles, SIGNAL(recentChanged()),
Chris@66 499 this, SLOT(setupRecentFilesMenu()));
Chris@66 500
Chris@66 501 menu->addSeparator();
Chris@66 502 action = new QAction(tr("&Preferences..."), this);
Chris@66 503 action->setStatusTip(tr("Adjust the application preferences"));
Chris@66 504 connect(action, SIGNAL(triggered()), this, SLOT(preferences()));
Chris@66 505 menu->addAction(action);
Chris@0 506
Chris@66 507 /*!!!
Chris@66 508 menu->addSeparator();
Chris@0 509
Chris@66 510 action = new QAction(tr("Play / Pause"), this);
Chris@66 511 action->setShortcut(tr("Space"));
Chris@66 512 action->setStatusTip(tr("Start or stop playback from the current position"));
Chris@66 513 connect(action, SIGNAL(triggered()), this, SLOT(play()));
Chris@66 514 menu->addAction(action);
Chris@66 515 */
Chris@66 516
Chris@66 517 menu->addSeparator();
Chris@66 518 action = new QAction(QIcon(":/icons/exit.png"),
Chris@66 519 tr("&Quit"), this);
Chris@66 520 action->setShortcut(tr("Ctrl+Q"));
Chris@90 521 action->setStatusTip(tr("Exit Sonic Visualiser"));
Chris@66 522 connect(action, SIGNAL(triggered()), this, SLOT(close()));
Chris@66 523 menu->addAction(action);
Chris@66 524 }
Chris@66 525
Chris@66 526 void
Chris@66 527 MainWindow::setupEditMenu()
Chris@66 528 {
Chris@66 529 if (m_mainMenusCreated) return;
Chris@66 530
Chris@66 531 QMenu *menu = menuBar()->addMenu(tr("&Edit"));
Chris@97 532 menu->setTearOffEnabled(true);
Chris@66 533 CommandHistory::getInstance()->registerMenu(menu);
Chris@66 534
Chris@66 535 menu->addSeparator();
Chris@66 536
Chris@66 537 QAction *action = new QAction(QIcon(":/icons/editcut.png"),
Chris@66 538 tr("Cu&t"), this);
Chris@66 539 action->setShortcut(tr("Ctrl+X"));
Chris@90 540 action->setStatusTip(tr("Cut the selection from the current layer to the clipboard"));
Chris@66 541 connect(action, SIGNAL(triggered()), this, SLOT(cut()));
Chris@66 542 connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@66 543 menu->addAction(action);
Chris@66 544 m_rightButtonMenu->addAction(action);
Chris@66 545
Chris@66 546 action = new QAction(QIcon(":/icons/editcopy.png"),
Chris@66 547 tr("&Copy"), this);
Chris@66 548 action->setShortcut(tr("Ctrl+C"));
Chris@90 549 action->setStatusTip(tr("Copy the selection from the current layer to the clipboard"));
Chris@66 550 connect(action, SIGNAL(triggered()), this, SLOT(copy()));
Chris@66 551 connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@66 552 menu->addAction(action);
Chris@66 553 m_rightButtonMenu->addAction(action);
Chris@66 554
Chris@66 555 action = new QAction(QIcon(":/icons/editpaste.png"),
Chris@66 556 tr("&Paste"), this);
Chris@66 557 action->setShortcut(tr("Ctrl+V"));
Chris@90 558 action->setStatusTip(tr("Paste from the clipboard to the current layer"));
Chris@66 559 connect(action, SIGNAL(triggered()), this, SLOT(paste()));
Chris@66 560 connect(this, SIGNAL(canPaste(bool)), action, SLOT(setEnabled(bool)));
Chris@66 561 menu->addAction(action);
Chris@66 562 m_rightButtonMenu->addAction(action);
Chris@66 563
Chris@66 564 action = new QAction(tr("&Delete Selected Items"), this);
Chris@66 565 action->setShortcut(tr("Del"));
Chris@90 566 action->setStatusTip(tr("Delete the selection from the current layer"));
Chris@66 567 connect(action, SIGNAL(triggered()), this, SLOT(deleteSelected()));
Chris@66 568 connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@66 569 menu->addAction(action);
Chris@66 570 m_rightButtonMenu->addAction(action);
Chris@66 571
Chris@66 572 menu->addSeparator();
Chris@66 573 m_rightButtonMenu->addSeparator();
Chris@0 574
Chris@66 575 action = new QAction(tr("Select &All"), this);
Chris@66 576 action->setShortcut(tr("Ctrl+A"));
Chris@90 577 action->setStatusTip(tr("Select the whole duration of the current session"));
Chris@66 578 connect(action, SIGNAL(triggered()), this, SLOT(selectAll()));
Chris@66 579 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
Chris@66 580 menu->addAction(action);
Chris@66 581 m_rightButtonMenu->addAction(action);
Chris@0 582
Chris@66 583 action = new QAction(tr("Select &Visible Range"), this);
Chris@66 584 action->setShortcut(tr("Ctrl+Shift+A"));
Chris@90 585 action->setStatusTip(tr("Select the time range corresponding to the current window width"));
Chris@66 586 connect(action, SIGNAL(triggered()), this, SLOT(selectVisible()));
Chris@66 587 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
Chris@66 588 menu->addAction(action);
Chris@0 589
Chris@66 590 action = new QAction(tr("Select to &Start"), this);
Chris@66 591 action->setShortcut(tr("Shift+Left"));
Chris@90 592 action->setStatusTip(tr("Select from the start of the session to the current playback position"));
Chris@66 593 connect(action, SIGNAL(triggered()), this, SLOT(selectToStart()));
Chris@66 594 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
Chris@66 595 menu->addAction(action);
Chris@0 596
Chris@66 597 action = new QAction(tr("Select to &End"), this);
Chris@66 598 action->setShortcut(tr("Shift+Right"));
Chris@90 599 action->setStatusTip(tr("Select from the current playback position to the end of the session"));
Chris@66 600 connect(action, SIGNAL(triggered()), this, SLOT(selectToEnd()));
Chris@66 601 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
Chris@66 602 menu->addAction(action);
Chris@66 603
Chris@66 604 action = new QAction(tr("C&lear Selection"), this);
Chris@66 605 action->setShortcut(tr("Esc"));
Chris@90 606 action->setStatusTip(tr("Clear the selection"));
Chris@66 607 connect(action, SIGNAL(triggered()), this, SLOT(clearSelection()));
Chris@66 608 connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@66 609 menu->addAction(action);
Chris@66 610 m_rightButtonMenu->addAction(action);
Chris@66 611
Chris@66 612 menu->addSeparator();
Chris@66 613
Chris@66 614 action = new QAction(tr("&Insert Instant at Playback Position"), this);
Chris@66 615 action->setShortcut(tr("Enter"));
Chris@90 616 action->setStatusTip(tr("Insert a new time instant at the current playback position, in a new layer if necessary"));
Chris@66 617 connect(action, SIGNAL(triggered()), this, SLOT(insertInstant()));
Chris@66 618 connect(this, SIGNAL(canInsertInstant(bool)), action, SLOT(setEnabled(bool)));
Chris@66 619 menu->addAction(action);
Chris@66 620
Chris@81 621 action = new QAction(tr("Insert Instants at Selection &Boundaries"), this);
Chris@81 622 action->setShortcut(tr("Shift+Enter"));
Chris@90 623 action->setStatusTip(tr("Insert new time instants at the start and end of the current selection, in a new layer if necessary"));
Chris@81 624 connect(action, SIGNAL(triggered()), this, SLOT(insertInstantsAtBoundaries()));
Chris@81 625 connect(this, SIGNAL(canInsertInstantsAtBoundaries(bool)), action, SLOT(setEnabled(bool)));
Chris@81 626 menu->addAction(action);
Chris@81 627
Chris@66 628 // Laptop shortcut (no keypad Enter key)
Chris@66 629 connect(new QShortcut(tr(";"), this), SIGNAL(activated()),
Chris@66 630 this, SLOT(insertInstant()));
Chris@66 631 }
Chris@66 632
Chris@66 633 void
Chris@66 634 MainWindow::setupViewMenu()
Chris@66 635 {
Chris@66 636 if (m_mainMenusCreated) return;
Chris@66 637
Chris@90 638 QAction *action = 0;
Chris@90 639
Chris@66 640 QMenu *menu = menuBar()->addMenu(tr("&View"));
Chris@97 641 menu->setTearOffEnabled(true);
Chris@66 642 action = new QAction(tr("Scroll &Left"), this);
Chris@66 643 action->setShortcut(tr("Left"));
Chris@66 644 action->setStatusTip(tr("Scroll the current pane to the left"));
Chris@66 645 connect(action, SIGNAL(triggered()), this, SLOT(scrollLeft()));
Chris@66 646 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@66 647 menu->addAction(action);
Chris@0 648
Chris@66 649 action = new QAction(tr("Scroll &Right"), this);
Chris@66 650 action->setShortcut(tr("Right"));
Chris@66 651 action->setStatusTip(tr("Scroll the current pane to the right"));
Chris@66 652 connect(action, SIGNAL(triggered()), this, SLOT(scrollRight()));
Chris@66 653 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@66 654 menu->addAction(action);
Chris@0 655
Chris@90 656 action = new QAction(tr("&Jump Left"), this);
Chris@66 657 action->setShortcut(tr("Ctrl+Left"));
Chris@66 658 action->setStatusTip(tr("Scroll the current pane a big step to the left"));
Chris@66 659 connect(action, SIGNAL(triggered()), this, SLOT(jumpLeft()));
Chris@66 660 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@66 661 menu->addAction(action);
Chris@0 662
Chris@90 663 action = new QAction(tr("J&ump Right"), this);
Chris@66 664 action->setShortcut(tr("Ctrl+Right"));
Chris@66 665 action->setStatusTip(tr("Scroll the current pane a big step to the right"));
Chris@66 666 connect(action, SIGNAL(triggered()), this, SLOT(jumpRight()));
Chris@66 667 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@66 668 menu->addAction(action);
Chris@66 669
Chris@66 670 menu->addSeparator();
Chris@66 671
Chris@66 672 action = new QAction(QIcon(":/icons/zoom-in.png"),
Chris@66 673 tr("Zoom &In"), this);
Chris@66 674 action->setShortcut(tr("Up"));
Chris@66 675 action->setStatusTip(tr("Increase the zoom level"));
Chris@66 676 connect(action, SIGNAL(triggered()), this, SLOT(zoomIn()));
Chris@66 677 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@66 678 menu->addAction(action);
Chris@0 679
Chris@66 680 action = new QAction(QIcon(":/icons/zoom-out.png"),
Chris@66 681 tr("Zoom &Out"), this);
Chris@66 682 action->setShortcut(tr("Down"));
Chris@66 683 action->setStatusTip(tr("Decrease the zoom level"));
Chris@66 684 connect(action, SIGNAL(triggered()), this, SLOT(zoomOut()));
Chris@66 685 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@66 686 menu->addAction(action);
Chris@0 687
Chris@66 688 action = new QAction(tr("Restore &Default Zoom"), this);
Chris@90 689 action->setStatusTip(tr("Restore the zoom level to the default"));
Chris@66 690 connect(action, SIGNAL(triggered()), this, SLOT(zoomDefault()));
Chris@66 691 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@66 692 menu->addAction(action);
Chris@66 693
Chris@66 694 action = new QAction(tr("Zoom to &Fit"), this);
Chris@66 695 action->setStatusTip(tr("Zoom to show the whole file"));
Chris@66 696 connect(action, SIGNAL(triggered()), this, SLOT(zoomToFit()));
Chris@66 697 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@66 698 menu->addAction(action);
Chris@90 699
Chris@90 700 menu->addSeparator();
Chris@90 701
Chris@90 702 QActionGroup *overlayGroup = new QActionGroup(this);
Chris@90 703
Chris@90 704 action = new QAction(tr("Show &No Overlays"), this);
Chris@90 705 action->setShortcut(tr("0"));
Chris@90 706 action->setStatusTip(tr("Hide centre indicator, frame times, layer names and scale"));
Chris@90 707 connect(action, SIGNAL(triggered()), this, SLOT(showNoOverlays()));
Chris@90 708 action->setCheckable(true);
Chris@90 709 action->setChecked(false);
Chris@90 710 overlayGroup->addAction(action);
Chris@90 711 menu->addAction(action);
Chris@90 712
Chris@90 713 action = new QAction(tr("Show &Minimal Overlays"), this);
Chris@90 714 action->setShortcut(tr("9"));
Chris@90 715 action->setStatusTip(tr("Show centre indicator only"));
Chris@90 716 connect(action, SIGNAL(triggered()), this, SLOT(showMinimalOverlays()));
Chris@90 717 action->setCheckable(true);
Chris@90 718 action->setChecked(false);
Chris@90 719 overlayGroup->addAction(action);
Chris@90 720 menu->addAction(action);
Chris@90 721
Chris@90 722 action = new QAction(tr("Show &Standard Overlays"), this);
Chris@90 723 action->setShortcut(tr("8"));
Chris@90 724 action->setStatusTip(tr("Show centre indicator, frame times and scale"));
Chris@90 725 connect(action, SIGNAL(triggered()), this, SLOT(showStandardOverlays()));
Chris@90 726 action->setCheckable(true);
Chris@90 727 action->setChecked(true);
Chris@90 728 overlayGroup->addAction(action);
Chris@90 729 menu->addAction(action);
Chris@90 730
Chris@90 731 action = new QAction(tr("Show &All Overlays"), this);
Chris@90 732 action->setShortcut(tr("7"));
Chris@90 733 action->setStatusTip(tr("Show all texts and scale"));
Chris@90 734 connect(action, SIGNAL(triggered()), this, SLOT(showAllOverlays()));
Chris@90 735 action->setCheckable(true);
Chris@90 736 action->setChecked(false);
Chris@90 737 overlayGroup->addAction(action);
Chris@90 738 menu->addAction(action);
Chris@7 739
Chris@72 740 menu->addSeparator();
Chris@72 741
Chris@66 742 action = new QAction(tr("Show &Zoom Wheels"), this);
Chris@66 743 action->setShortcut(tr("Z"));
Chris@66 744 action->setStatusTip(tr("Show thumbwheels for zooming horizontally and vertically"));
Chris@66 745 connect(action, SIGNAL(triggered()), this, SLOT(toggleZoomWheels()));
Chris@66 746 action->setCheckable(true);
Chris@66 747 action->setChecked(m_viewManager->getZoomWheelsEnabled());
Chris@66 748 menu->addAction(action);
Chris@72 749
Chris@72 750 action = new QAction(tr("Show Property Bo&xes"), this);
Chris@72 751 action->setShortcut(tr("X"));
Chris@72 752 action->setStatusTip(tr("Show the layer property boxes at the side of the main window"));
Chris@72 753 connect(action, SIGNAL(triggered()), this, SLOT(togglePropertyBoxes()));
Chris@72 754 action->setCheckable(true);
Chris@72 755 action->setChecked(true);
Chris@72 756 menu->addAction(action);
Chris@0 757
Chris@90 758 action = new QAction(tr("Show Status &Bar"), this);
Chris@90 759 action->setStatusTip(tr("Show context help information in the status bar at the bottom of the window"));
Chris@90 760 connect(action, SIGNAL(triggered()), this, SLOT(toggleStatusBar()));
Chris@90 761 action->setCheckable(true);
Chris@90 762 action->setChecked(true);
Chris@90 763 menu->addAction(action);
Chris@90 764
Chris@90 765 QSettings settings;
Chris@90 766 settings.beginGroup("MainWindow");
Chris@90 767 bool sb = settings.value("showstatusbar", true).toBool();
Chris@90 768 if (!sb) {
Chris@90 769 action->setChecked(false);
Chris@90 770 statusBar()->hide();
Chris@90 771 }
Chris@90 772 settings.endGroup();
Chris@90 773
Chris@0 774 /*!!! This one doesn't work properly yet
Chris@90 775
Chris@66 776 menu->addSeparator();
Chris@66 777
Chris@90 778 action = new QAction(tr("Show La&yer Hierarchy"), this);
Chris@66 779 action->setShortcut(tr("Alt+L"));
Chris@90 780 action->setStatusTip(tr("Open a window displaying the hierarchy of panes and layers in this session"));
Chris@66 781 connect(action, SIGNAL(triggered()), this, SLOT(showLayerTree()));
Chris@66 782 menu->addAction(action);
Chris@90 783 */
Chris@66 784 }
Chris@66 785
Chris@66 786 void
Chris@66 787 MainWindow::setupPaneAndLayerMenus()
Chris@66 788 {
Chris@0 789 if (m_paneMenu) {
Chris@0 790 m_paneActions.clear();
Chris@0 791 m_paneMenu->clear();
Chris@0 792 } else {
Chris@0 793 m_paneMenu = menuBar()->addMenu(tr("&Pane"));
Chris@97 794 m_paneMenu->setTearOffEnabled(true);
Chris@0 795 }
Chris@0 796
Chris@0 797 if (m_layerMenu) {
Chris@0 798 m_layerActions.clear();
Chris@0 799 m_layerMenu->clear();
Chris@0 800 } else {
Chris@0 801 m_layerMenu = menuBar()->addMenu(tr("&Layer"));
Chris@97 802 m_layerMenu->setTearOffEnabled(true);
Chris@0 803 }
Chris@0 804
Chris@66 805 QMenu *menu = m_paneMenu;
Chris@66 806
Chris@66 807 QAction *action = new QAction(QIcon(":/icons/pane.png"), tr("Add &New Pane"), this);
Chris@66 808 action->setShortcut(tr("Alt+N"));
Chris@66 809 action->setStatusTip(tr("Add a new pane containing only a time ruler"));
Chris@66 810 connect(action, SIGNAL(triggered()), this, SLOT(addPane()));
Chris@66 811 connect(this, SIGNAL(canAddPane(bool)), action, SLOT(setEnabled(bool)));
Chris@66 812 m_paneActions[action] = PaneConfiguration(LayerFactory::TimeRuler);
Chris@66 813 menu->addAction(action);
Chris@66 814
Chris@66 815 menu->addSeparator();
Chris@66 816
Chris@66 817 menu = m_layerMenu;
Chris@66 818
Chris@66 819 // menu->addSeparator();
Chris@66 820
Chris@66 821 LayerFactory::LayerTypeSet emptyLayerTypes =
Chris@66 822 LayerFactory::getInstance()->getValidEmptyLayerTypes();
Chris@66 823
Chris@66 824 for (LayerFactory::LayerTypeSet::iterator i = emptyLayerTypes.begin();
Chris@66 825 i != emptyLayerTypes.end(); ++i) {
Chris@66 826
Chris@66 827 QIcon icon;
Chris@66 828 QString mainText, tipText, channelText;
Chris@66 829 LayerFactory::LayerType type = *i;
Chris@66 830 QString name = LayerFactory::getInstance()->getLayerPresentationName(type);
Chris@66 831
Chris@66 832 icon = QIcon(QString(":/icons/%1.png")
Chris@66 833 .arg(LayerFactory::getInstance()->getLayerIconName(type)));
Chris@66 834
Chris@66 835 mainText = tr("Add New %1 Layer").arg(name);
Chris@66 836 tipText = tr("Add a new empty layer of type %1").arg(name);
Chris@66 837
Chris@66 838 action = new QAction(icon, mainText, this);
Chris@66 839 action->setStatusTip(tipText);
Chris@66 840
Chris@66 841 if (type == LayerFactory::Text) {
Chris@66 842 action->setShortcut(tr("Alt+T"));
Chris@66 843 }
Chris@66 844
Chris@66 845 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@66 846 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@66 847 m_layerActions[action] = type;
Chris@66 848 menu->addAction(action);
Chris@66 849 m_rightButtonLayerMenu->addAction(action);
Chris@66 850 }
Chris@66 851
Chris@66 852 m_rightButtonLayerMenu->addSeparator();
Chris@66 853 menu->addSeparator();
Chris@66 854
Chris@66 855 LayerFactory::LayerType backgroundTypes[] = {
Chris@66 856 LayerFactory::Waveform,
Chris@66 857 LayerFactory::Spectrogram,
Chris@66 858 LayerFactory::MelodicRangeSpectrogram,
Chris@66 859 LayerFactory::PeakFrequencySpectrogram,
Chris@66 860 LayerFactory::Spectrum
Chris@66 861 };
Chris@66 862
Chris@66 863 std::vector<Model *> models;
Chris@66 864 if (m_document) models = m_document->getTransformInputModels(); //!!! not well named for this!
Chris@66 865 bool plural = (models.size() > 1);
Chris@66 866 if (models.empty()) {
Chris@67 867 models.push_back(getMainModel()); // probably 0
Chris@66 868 }
Chris@66 869
Chris@66 870 for (unsigned int i = 0;
Chris@66 871 i < sizeof(backgroundTypes)/sizeof(backgroundTypes[0]); ++i) {
Chris@66 872
Chris@66 873 for (int menuType = 0; menuType <= 1; ++menuType) { // pane, layer
Chris@66 874
Chris@66 875 if (menuType == 0) menu = m_paneMenu;
Chris@66 876 else menu = m_layerMenu;
Chris@66 877
Chris@66 878 QMenu *submenu = 0;
Chris@66 879
Chris@66 880 QIcon icon;
Chris@66 881 QString mainText, shortcutText, tipText, channelText;
Chris@66 882 LayerFactory::LayerType type = backgroundTypes[i];
Chris@66 883 bool mono = true;
Chris@66 884
Chris@66 885 switch (type) {
Chris@66 886
Chris@66 887 case LayerFactory::Waveform:
Chris@66 888 icon = QIcon(":/icons/waveform.png");
Chris@66 889 mainText = tr("Add &Waveform");
Chris@66 890 if (menuType == 0) {
Chris@66 891 shortcutText = tr("Alt+W");
Chris@66 892 tipText = tr("Add a new pane showing a waveform view");
Chris@66 893 } else {
Chris@66 894 tipText = tr("Add a new layer showing a waveform view");
Chris@66 895 }
Chris@66 896 mono = false;
Chris@66 897 break;
Chris@66 898
Chris@66 899 case LayerFactory::Spectrogram:
Chris@67 900 icon = QIcon(":/icons/spectrogram.png");
Chris@66 901 mainText = tr("Add &Spectrogram");
Chris@66 902 if (menuType == 0) {
Chris@66 903 shortcutText = tr("Alt+S");
Chris@90 904 tipText = tr("Add a new pane showing a spectrogram");
Chris@66 905 } else {
Chris@90 906 tipText = tr("Add a new layer showing a spectrogram");
Chris@66 907 }
Chris@66 908 break;
Chris@66 909
Chris@66 910 case LayerFactory::MelodicRangeSpectrogram:
Chris@67 911 icon = QIcon(":/icons/spectrogram.png");
Chris@66 912 mainText = tr("Add &Melodic Range Spectrogram");
Chris@66 913 if (menuType == 0) {
Chris@66 914 shortcutText = tr("Alt+M");
Chris@90 915 tipText = tr("Add a new pane showing a spectrogram set up for an overview of note pitches");
Chris@66 916 } else {
Chris@90 917 tipText = tr("Add a new layer showing a spectrogram set up for an overview of note pitches");
Chris@66 918 }
Chris@66 919 break;
Chris@66 920
Chris@66 921 case LayerFactory::PeakFrequencySpectrogram:
Chris@67 922 icon = QIcon(":/icons/spectrogram.png");
Chris@66 923 mainText = tr("Add &Peak Frequency Spectrogram");
Chris@66 924 if (menuType == 0) {
Chris@66 925 shortcutText = tr("Alt+P");
Chris@66 926 tipText = tr("Add a new pane showing a spectrogram set up for tracking frequencies");
Chris@66 927 } else {
Chris@66 928 tipText = tr("Add a new layer showing a spectrogram set up for tracking frequencies");
Chris@66 929 }
Chris@66 930 break;
Chris@66 931
Chris@66 932 case LayerFactory::Spectrum:
Chris@67 933 icon = QIcon(":/icons/spectrum.png");
Chris@66 934 mainText = tr("Add Spectr&um");
Chris@66 935 if (menuType == 0) {
Chris@66 936 shortcutText = tr("Alt+U");
Chris@66 937 tipText = tr("Add a new pane showing a frequency spectrum");
Chris@66 938 } else {
Chris@66 939 tipText = tr("Add a new layer showing a frequency spectrum");
Chris@66 940 }
Chris@66 941 break;
Chris@66 942
Chris@66 943 default: break;
Chris@66 944 }
Chris@66 945
Chris@66 946 std::vector<Model *> candidateModels;
Chris@66 947 if (menuType == 0) {
Chris@66 948 candidateModels = models;
Chris@66 949 } else {
Chris@66 950 candidateModels.push_back(0);
Chris@66 951 }
Chris@66 952
Chris@66 953 for (std::vector<Model *>::iterator mi =
Chris@66 954 candidateModels.begin();
Chris@66 955 mi != candidateModels.end(); ++mi) {
Chris@66 956
Chris@66 957 Model *model = *mi;
Chris@66 958
Chris@66 959 int channels = 0;
Chris@66 960 if (model) {
Chris@66 961 DenseTimeValueModel *dtvm =
Chris@66 962 dynamic_cast<DenseTimeValueModel *>(model);
Chris@66 963 if (dtvm) channels = dtvm->getChannelCount();
Chris@66 964 }
Chris@66 965 if (channels < 1 && getMainModel()) {
Chris@66 966 channels = getMainModel()->getChannelCount();
Chris@66 967 }
Chris@66 968 if (channels < 1) channels = 1;
Chris@66 969
Chris@66 970 for (int c = 0; c <= channels; ++c) {
Chris@66 971
Chris@66 972 if (c == 1 && channels == 1) continue;
Chris@66 973 bool isDefault = (c == 0);
Chris@66 974 bool isOnly = (isDefault && (channels == 1));
Chris@66 975
Chris@66 976 if (menuType == 1) {
Chris@66 977 if (isDefault) isOnly = true;
Chris@66 978 else continue;
Chris@66 979 }
Chris@66 980
Chris@66 981 if (isOnly && (!plural || menuType == 1)) {
Chris@66 982
Chris@67 983 if (type != LayerFactory::Waveform) {
Chris@67 984 action = new QAction(mainText, this);
Chris@67 985 } else {
Chris@67 986 action = new QAction(icon, mainText, this);
Chris@67 987 }
Chris@67 988
Chris@66 989 action->setShortcut(shortcutText);
Chris@66 990 action->setStatusTip(tipText);
Chris@66 991 if (menuType == 0) {
Chris@66 992 connect(action, SIGNAL(triggered()),
Chris@66 993 this, SLOT(addPane()));
Chris@66 994 connect(this, SIGNAL(canAddPane(bool)),
Chris@66 995 action, SLOT(setEnabled(bool)));
Chris@66 996 m_paneActions[action] = PaneConfiguration(type);
Chris@66 997 } else {
Chris@66 998 connect(action, SIGNAL(triggered()),
Chris@66 999 this, SLOT(addLayer()));
Chris@66 1000 connect(this, SIGNAL(canAddLayer(bool)),
Chris@66 1001 action, SLOT(setEnabled(bool)));
Chris@66 1002 m_layerActions[action] = type;
Chris@66 1003 }
Chris@66 1004 menu->addAction(action);
Chris@66 1005
Chris@66 1006 } else {
Chris@66 1007
Chris@66 1008 if (!submenu) {
Chris@66 1009 submenu = menu->addMenu(mainText);
Chris@97 1010 submenu->setTearOffEnabled(true);
Chris@67 1011 } else if (isDefault) {
Chris@67 1012 submenu->addSeparator();
Chris@66 1013 }
Chris@66 1014
Chris@66 1015 QString actionText;
Chris@66 1016 if (c == 0) {
Chris@66 1017 if (mono) {
Chris@66 1018 actionText = tr("&All Channels Mixed");
Chris@66 1019 } else {
Chris@66 1020 actionText = tr("&All Channels");
Chris@66 1021 }
Chris@66 1022 } else {
Chris@66 1023 actionText = tr("Channel &%1").arg(c);
Chris@66 1024 }
Chris@66 1025
Chris@66 1026 if (model) {
Chris@66 1027 actionText = tr("%1: %2")
Chris@66 1028 .arg(model->objectName())
Chris@66 1029 .arg(actionText);
Chris@66 1030 }
Chris@67 1031
Chris@67 1032 if (isDefault) {
Chris@67 1033 action = new QAction(icon, actionText, this);
Chris@67 1034 if (!model || model == getMainModel()) {
Chris@67 1035 action->setShortcut(shortcutText);
Chris@67 1036 }
Chris@67 1037 } else {
Chris@67 1038 action = new QAction(actionText, this);
Chris@67 1039 }
Chris@67 1040
Chris@66 1041 action->setStatusTip(tipText);
Chris@66 1042
Chris@66 1043 if (menuType == 0) {
Chris@66 1044 connect(action, SIGNAL(triggered()),
Chris@66 1045 this, SLOT(addPane()));
Chris@66 1046 connect(this, SIGNAL(canAddPane(bool)),
Chris@66 1047 action, SLOT(setEnabled(bool)));
Chris@66 1048 m_paneActions[action] =
Chris@66 1049 PaneConfiguration(type, model, c - 1);
Chris@66 1050 } else {
Chris@66 1051 connect(action, SIGNAL(triggered()),
Chris@66 1052 this, SLOT(addLayer()));
Chris@66 1053 connect(this, SIGNAL(canAddLayer(bool)),
Chris@66 1054 action, SLOT(setEnabled(bool)));
Chris@66 1055 m_layerActions[action] = type;
Chris@66 1056 }
Chris@66 1057
Chris@66 1058 submenu->addAction(action);
Chris@66 1059 }
Chris@66 1060 }
Chris@66 1061 }
Chris@66 1062 }
Chris@66 1063 }
Chris@66 1064
Chris@66 1065 menu = m_paneMenu;
Chris@66 1066
Chris@66 1067 menu->addSeparator();
Chris@66 1068
Chris@66 1069 action = new QAction(QIcon(":/icons/editdelete.png"), tr("&Delete Pane"), this);
Chris@66 1070 action->setShortcut(tr("Alt+D"));
Chris@90 1071 action->setStatusTip(tr("Delete the currently active pane"));
Chris@66 1072 connect(action, SIGNAL(triggered()), this, SLOT(deleteCurrentPane()));
Chris@66 1073 connect(this, SIGNAL(canDeleteCurrentPane(bool)), action, SLOT(setEnabled(bool)));
Chris@66 1074 menu->addAction(action);
Chris@66 1075
Chris@66 1076 menu = m_layerMenu;
Chris@66 1077
Chris@66 1078 action = new QAction(QIcon(":/icons/timeruler.png"), tr("Add &Time Ruler"), this);
Chris@66 1079 action->setStatusTip(tr("Add a new layer showing a time ruler"));
Chris@66 1080 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@66 1081 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@66 1082 m_layerActions[action] = LayerFactory::TimeRuler;
Chris@66 1083 menu->addAction(action);
Chris@66 1084
Chris@66 1085 menu->addSeparator();
Chris@66 1086
Chris@66 1087 m_existingLayersMenu = menu->addMenu(tr("Add &Existing Layer"));
Chris@97 1088 m_existingLayersMenu->setTearOffEnabled(true);
Chris@66 1089 m_rightButtonLayerMenu->addMenu(m_existingLayersMenu);
Chris@95 1090
Chris@95 1091 m_sliceMenu = menu->addMenu(tr("Add S&lice of Layer"));
Chris@97 1092 m_sliceMenu->setTearOffEnabled(true);
Chris@95 1093 m_rightButtonLayerMenu->addMenu(m_sliceMenu);
Chris@95 1094
Chris@95 1095 setupExistingLayersMenus();
Chris@66 1096
Chris@66 1097 m_rightButtonLayerMenu->addSeparator();
Chris@66 1098 menu->addSeparator();
Chris@66 1099
Chris@66 1100 action = new QAction(tr("&Rename Layer..."), this);
Chris@66 1101 action->setShortcut(tr("Alt+R"));
Chris@66 1102 action->setStatusTip(tr("Rename the currently active layer"));
Chris@66 1103 connect(action, SIGNAL(triggered()), this, SLOT(renameCurrentLayer()));
Chris@66 1104 connect(this, SIGNAL(canRenameLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@66 1105 menu->addAction(action);
Chris@66 1106 m_rightButtonLayerMenu->addAction(action);
Chris@66 1107
Chris@66 1108 action = new QAction(QIcon(":/icons/editdelete.png"), tr("&Delete Layer"), this);
Chris@66 1109 action->setShortcut(tr("Alt+Shift+D"));
Chris@66 1110 action->setStatusTip(tr("Delete the currently active layer"));
Chris@66 1111 connect(action, SIGNAL(triggered()), this, SLOT(deleteCurrentLayer()));
Chris@66 1112 connect(this, SIGNAL(canDeleteCurrentLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@66 1113 menu->addAction(action);
Chris@66 1114 m_rightButtonLayerMenu->addAction(action);
Chris@66 1115 }
Chris@66 1116
Chris@66 1117 void
Chris@66 1118 MainWindow::setupTransformsMenu()
Chris@66 1119 {
Chris@34 1120 if (m_transformsMenu) {
Chris@34 1121 m_transformActions.clear();
Chris@34 1122 m_transformActionsReverse.clear();
Chris@34 1123 m_transformsMenu->clear();
Chris@34 1124 } else {
Chris@97 1125 m_transformsMenu = menuBar()->addMenu(tr("&Transform"));
Chris@97 1126 m_transformsMenu->setTearOffEnabled(true);
Chris@97 1127 }
Chris@34 1128
Chris@0 1129 TransformFactory::TransformList transforms =
Chris@0 1130 TransformFactory::getInstance()->getAllTransforms();
Chris@0 1131
Chris@33 1132 vector<QString> types =
Chris@0 1133 TransformFactory::getInstance()->getAllTransformTypes();
Chris@0 1134
Chris@37 1135 map<QString, map<QString, SubdividingMenu *> > categoryMenus;
Chris@37 1136 map<QString, map<QString, SubdividingMenu *> > makerMenus;
Chris@33 1137
Chris@36 1138 map<QString, SubdividingMenu *> byPluginNameMenus;
Chris@33 1139 map<QString, map<QString, QMenu *> > pluginNameMenus;
Chris@33 1140
Chris@37 1141 set<SubdividingMenu *> pendingMenus;
Chris@37 1142
Chris@34 1143 m_recentTransformsMenu = m_transformsMenu->addMenu(tr("&Recent Transforms"));
Chris@97 1144 m_recentTransformsMenu->setTearOffEnabled(true);
Chris@34 1145 m_rightButtonTransformsMenu->addMenu(m_recentTransformsMenu);
Chris@34 1146 connect(&m_recentTransforms, SIGNAL(recentChanged()),
Chris@34 1147 this, SLOT(setupRecentTransformsMenu()));
Chris@34 1148
Chris@34 1149 m_transformsMenu->addSeparator();
Chris@34 1150 m_rightButtonTransformsMenu->addSeparator();
Chris@34 1151
Chris@33 1152 for (vector<QString>::iterator i = types.begin(); i != types.end(); ++i) {
Chris@33 1153
Chris@33 1154 if (i != types.begin()) {
Chris@34 1155 m_transformsMenu->addSeparator();
Chris@34 1156 m_rightButtonTransformsMenu->addSeparator();
Chris@33 1157 }
Chris@33 1158
Chris@33 1159 QString byCategoryLabel = tr("%1 by Category").arg(*i);
Chris@37 1160 SubdividingMenu *byCategoryMenu = new SubdividingMenu(byCategoryLabel,
Chris@37 1161 20, 40);
Chris@97 1162 byCategoryMenu->setTearOffEnabled(true);
Chris@37 1163 m_transformsMenu->addMenu(byCategoryMenu);
Chris@34 1164 m_rightButtonTransformsMenu->addMenu(byCategoryMenu);
Chris@37 1165 pendingMenus.insert(byCategoryMenu);
Chris@33 1166
Chris@33 1167 vector<QString> categories =
Chris@33 1168 TransformFactory::getInstance()->getTransformCategories(*i);
Chris@33 1169
Chris@33 1170 for (vector<QString>::iterator j = categories.begin();
Chris@33 1171 j != categories.end(); ++j) {
Chris@33 1172
Chris@33 1173 QString category = *j;
Chris@33 1174 if (category == "") category = tr("Unclassified");
Chris@33 1175
Chris@33 1176 if (categories.size() < 2) {
Chris@33 1177 categoryMenus[*i][category] = byCategoryMenu;
Chris@33 1178 continue;
Chris@33 1179 }
Chris@33 1180
Chris@33 1181 QStringList components = category.split(" > ");
Chris@33 1182 QString key;
Chris@33 1183
Chris@33 1184 for (QStringList::iterator k = components.begin();
Chris@33 1185 k != components.end(); ++k) {
Chris@33 1186
Chris@33 1187 QString parentKey = key;
Chris@33 1188 if (key != "") key += " > ";
Chris@33 1189 key += *k;
Chris@33 1190
Chris@33 1191 if (categoryMenus[*i].find(key) == categoryMenus[*i].end()) {
Chris@37 1192 SubdividingMenu *m = new SubdividingMenu(*k, 20, 40);
Chris@97 1193 m->setTearOffEnabled(true);
Chris@37 1194 pendingMenus.insert(m);
Chris@37 1195 categoryMenus[*i][key] = m;
Chris@33 1196 if (parentKey == "") {
Chris@37 1197 byCategoryMenu->addMenu(m);
Chris@33 1198 } else {
Chris@37 1199 categoryMenus[*i][parentKey]->addMenu(m);
Chris@33 1200 }
Chris@33 1201 }
Chris@33 1202 }
Chris@33 1203 }
Chris@33 1204
Chris@34 1205 QString byPluginNameLabel = tr("%1 by Plugin Name").arg(*i);
Chris@36 1206 byPluginNameMenus[*i] = new SubdividingMenu(byPluginNameLabel);
Chris@97 1207 byPluginNameMenus[*i]->setTearOffEnabled(true);
Chris@36 1208 m_transformsMenu->addMenu(byPluginNameMenus[*i]);
Chris@34 1209 m_rightButtonTransformsMenu->addMenu(byPluginNameMenus[*i]);
Chris@37 1210 pendingMenus.insert(byPluginNameMenus[*i]);
Chris@34 1211
Chris@33 1212 QString byMakerLabel = tr("%1 by Maker").arg(*i);
Chris@37 1213 SubdividingMenu *byMakerMenu = new SubdividingMenu(byMakerLabel, 20, 40);
Chris@97 1214 byMakerMenu->setTearOffEnabled(true);
Chris@37 1215 m_transformsMenu->addMenu(byMakerMenu);
Chris@34 1216 m_rightButtonTransformsMenu->addMenu(byMakerMenu);
Chris@37 1217 pendingMenus.insert(byMakerMenu);
Chris@33 1218
Chris@33 1219 vector<QString> makers =
Chris@33 1220 TransformFactory::getInstance()->getTransformMakers(*i);
Chris@37 1221
Chris@33 1222 for (vector<QString>::iterator j = makers.begin();
Chris@33 1223 j != makers.end(); ++j) {
Chris@33 1224
Chris@33 1225 QString maker = *j;
Chris@33 1226 if (maker == "") maker = tr("Unknown");
Chris@55 1227 maker.replace(QRegExp(tr(" [\\(<].*$")), "");
Chris@55 1228
Chris@37 1229 makerMenus[*i][maker] = new SubdividingMenu(maker, 30, 40);
Chris@97 1230 makerMenus[*i][maker]->setTearOffEnabled(true);
Chris@37 1231 byMakerMenu->addMenu(makerMenus[*i][maker]);
Chris@37 1232 pendingMenus.insert(makerMenus[*i][maker]);
Chris@33 1233 }
Chris@0 1234 }
Chris@0 1235
Chris@0 1236 for (unsigned int i = 0; i < transforms.size(); ++i) {
Chris@0 1237
Chris@107 1238 QString name = transforms[i].name;
Chris@107 1239 if (name == "") name = transforms[i].identifier;
Chris@107 1240
Chris@107 1241 // std::cerr << "Plugin Name: " << name.toStdString() << std::endl;
Chris@80 1242
Chris@33 1243 QString type = transforms[i].type;
Chris@33 1244
Chris@33 1245 QString category = transforms[i].category;
Chris@33 1246 if (category == "") category = tr("Unclassified");
Chris@33 1247
Chris@33 1248 QString maker = transforms[i].maker;
Chris@33 1249 if (maker == "") maker = tr("Unknown");
Chris@55 1250 maker.replace(QRegExp(tr(" [\\(<].*$")), "");
Chris@33 1251
Chris@107 1252 QString pluginName = name.section(": ", 0, 0);
Chris@107 1253 QString output = name.section(": ", 1);
Chris@107 1254
Chris@107 1255 QAction *action = new QAction(tr("%1...").arg(name), this);
Chris@0 1256 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@107 1257 m_transformActions[action] = transforms[i].identifier;
Chris@107 1258 m_transformActionsReverse[transforms[i].identifier] = action;
Chris@0 1259 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@33 1260
Chris@108 1261 action->setStatusTip(transforms[i].description);
Chris@90 1262
Chris@33 1263 if (categoryMenus[type].find(category) == categoryMenus[type].end()) {
Chris@33 1264 std::cerr << "WARNING: MainWindow::setupMenus: Internal error: "
Chris@33 1265 << "No category menu for transform \""
Chris@107 1266 << name.toStdString() << "\" (category = \""
Chris@33 1267 << category.toStdString() << "\")" << std::endl;
Chris@33 1268 } else {
Chris@33 1269 categoryMenus[type][category]->addAction(action);
Chris@33 1270 }
Chris@33 1271
Chris@33 1272 if (makerMenus[type].find(maker) == makerMenus[type].end()) {
Chris@33 1273 std::cerr << "WARNING: MainWindow::setupMenus: Internal error: "
Chris@33 1274 << "No maker menu for transform \""
Chris@107 1275 << name.toStdString() << "\" (maker = \""
Chris@33 1276 << maker.toStdString() << "\")" << std::endl;
Chris@33 1277 } else {
Chris@80 1278 makerMenus[type][maker]->addAction(action);
Chris@33 1279 }
Chris@33 1280
Chris@33 1281 action = new QAction(tr("%1...").arg(output == "" ? pluginName : output), this);
Chris@33 1282 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@107 1283 m_transformActions[action] = transforms[i].identifier;
Chris@33 1284 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@108 1285 action->setStatusTip(transforms[i].description);
Chris@33 1286
Chris@34 1287 // cerr << "Transform: \"" << name.toStdString() << "\": plugin name \"" << pluginName.toStdString() << "\"" << endl;
Chris@34 1288
Chris@33 1289 if (pluginNameMenus[type].find(pluginName) ==
Chris@33 1290 pluginNameMenus[type].end()) {
Chris@33 1291
Chris@36 1292 SubdividingMenu *parentMenu = byPluginNameMenus[type];
Chris@97 1293 parentMenu->setTearOffEnabled(true);
Chris@34 1294
Chris@33 1295 if (output == "") {
Chris@36 1296 parentMenu->addAction(pluginName, action);
Chris@33 1297 } else {
Chris@34 1298 pluginNameMenus[type][pluginName] =
Chris@34 1299 parentMenu->addMenu(pluginName);
Chris@33 1300 connect(this, SIGNAL(canAddLayer(bool)),
Chris@33 1301 pluginNameMenus[type][pluginName],
Chris@33 1302 SLOT(setEnabled(bool)));
Chris@33 1303 }
Chris@33 1304 }
Chris@33 1305
Chris@33 1306 if (pluginNameMenus[type].find(pluginName) !=
Chris@33 1307 pluginNameMenus[type].end()) {
Chris@33 1308 pluginNameMenus[type][pluginName]->addAction(action);
Chris@33 1309 }
Chris@0 1310 }
Chris@0 1311
Chris@37 1312 for (set<SubdividingMenu *>::iterator i = pendingMenus.begin();
Chris@37 1313 i != pendingMenus.end(); ++i) {
Chris@37 1314 (*i)->entriesAdded();
Chris@37 1315 }
Chris@37 1316
Chris@34 1317 setupRecentTransformsMenu();
Chris@66 1318 }
Chris@66 1319
Chris@66 1320 void
Chris@66 1321 MainWindow::setupHelpMenu()
Chris@66 1322 {
Chris@66 1323 if (m_mainMenusCreated) return;
Chris@66 1324
Chris@66 1325 QMenu *menu = menuBar()->addMenu(tr("&Help"));
Chris@97 1326 menu->setTearOffEnabled(true);
Chris@66 1327
Chris@66 1328 QAction *action = new QAction(tr("&Help Reference"), this);
Chris@66 1329 action->setStatusTip(tr("Open the Sonic Visualiser reference manual"));
Chris@66 1330 connect(action, SIGNAL(triggered()), this, SLOT(help()));
Chris@0 1331 menu->addAction(action);
Chris@0 1332
Chris@66 1333 action = new QAction(tr("Sonic Visualiser on the &Web"), this);
Chris@66 1334 action->setStatusTip(tr("Open the Sonic Visualiser website"));
Chris@66 1335 connect(action, SIGNAL(triggered()), this, SLOT(website()));
Chris@0 1336 menu->addAction(action);
Chris@66 1337
Chris@66 1338 action = new QAction(tr("&About Sonic Visualiser"), this);
Chris@66 1339 action->setStatusTip(tr("Show information about Sonic Visualiser"));
Chris@66 1340 connect(action, SIGNAL(triggered()), this, SLOT(about()));
Chris@0 1341 menu->addAction(action);
Chris@0 1342 }
Chris@0 1343
Chris@0 1344 void
Chris@0 1345 MainWindow::setupRecentFilesMenu()
Chris@0 1346 {
Chris@0 1347 m_recentFilesMenu->clear();
Chris@34 1348 vector<QString> files = m_recentFiles.getRecent();
Chris@0 1349 for (size_t i = 0; i < files.size(); ++i) {
Chris@0 1350 QAction *action = new QAction(files[i], this);
Chris@0 1351 connect(action, SIGNAL(triggered()), this, SLOT(openRecentFile()));
Chris@0 1352 m_recentFilesMenu->addAction(action);
Chris@0 1353 }
Chris@0 1354 }
Chris@0 1355
Chris@0 1356 void
Chris@34 1357 MainWindow::setupRecentTransformsMenu()
Chris@34 1358 {
Chris@34 1359 m_recentTransformsMenu->clear();
Chris@34 1360 vector<QString> transforms = m_recentTransforms.getRecent();
Chris@34 1361 for (size_t i = 0; i < transforms.size(); ++i) {
Chris@34 1362 TransformActionReverseMap::iterator ti =
Chris@34 1363 m_transformActionsReverse.find(transforms[i]);
Chris@34 1364 if (ti == m_transformActionsReverse.end()) {
Chris@34 1365 std::cerr << "WARNING: MainWindow::setupRecentTransformsMenu: "
Chris@34 1366 << "Unknown transform \"" << transforms[i].toStdString()
Chris@34 1367 << "\" in recent transforms list" << std::endl;
Chris@34 1368 continue;
Chris@34 1369 }
Chris@34 1370 m_recentTransformsMenu->addAction(ti->second);
Chris@34 1371 }
Chris@34 1372 }
Chris@34 1373
Chris@34 1374 void
Chris@95 1375 MainWindow::setupExistingLayersMenus()
Chris@0 1376 {
Chris@0 1377 if (!m_existingLayersMenu) return; // should have been created by setupMenus
Chris@0 1378
Chris@0 1379 // std::cerr << "MainWindow::setupExistingLayersMenu" << std::endl;
Chris@0 1380
Chris@0 1381 m_existingLayersMenu->clear();
Chris@0 1382 m_existingLayerActions.clear();
Chris@0 1383
Chris@95 1384 m_sliceMenu->clear();
Chris@95 1385 m_sliceActions.clear();
Chris@95 1386
Chris@33 1387 vector<Layer *> orderedLayers;
Chris@33 1388 set<Layer *> observedLayers;
Chris@95 1389 set<Layer *> sliceableLayers;
Chris@95 1390
Chris@95 1391 LayerFactory *factory = LayerFactory::getInstance();
Chris@0 1392
Chris@0 1393 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@0 1394
Chris@0 1395 Pane *pane = m_paneStack->getPane(i);
Chris@0 1396 if (!pane) continue;
Chris@0 1397
Chris@0 1398 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@0 1399
Chris@0 1400 Layer *layer = pane->getLayer(j);
Chris@0 1401 if (!layer) continue;
Chris@0 1402 if (observedLayers.find(layer) != observedLayers.end()) {
Chris@0 1403 std::cerr << "found duplicate layer " << layer << std::endl;
Chris@0 1404 continue;
Chris@0 1405 }
Chris@0 1406
Chris@0 1407 // std::cerr << "found new layer " << layer << " (name = "
Chris@0 1408 // << layer->getLayerPresentationName().toStdString() << ")" << std::endl;
Chris@0 1409
Chris@0 1410 orderedLayers.push_back(layer);
Chris@0 1411 observedLayers.insert(layer);
Chris@95 1412
Chris@95 1413 if (factory->isLayerSliceable(layer)) {
Chris@95 1414 sliceableLayers.insert(layer);
Chris@95 1415 }
Chris@0 1416 }
Chris@0 1417 }
Chris@0 1418
Chris@33 1419 map<QString, int> observedNames;
Chris@0 1420
Chris@0 1421 for (int i = 0; i < orderedLayers.size(); ++i) {
Chris@0 1422
Chris@95 1423 Layer *layer = orderedLayers[i];
Chris@95 1424
Chris@95 1425 QString name = layer->getLayerPresentationName();
Chris@0 1426 int n = ++observedNames[name];
Chris@0 1427 if (n > 1) name = QString("%1 <%2>").arg(name).arg(n);
Chris@0 1428
Chris@95 1429 QIcon icon = QIcon(QString(":/icons/%1.png")
Chris@95 1430 .arg(factory->getLayerIconName
Chris@95 1431 (factory->getLayerType(layer))));
Chris@95 1432
Chris@95 1433 QAction *action = new QAction(icon, name, this);
Chris@0 1434 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@0 1435 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@95 1436 m_existingLayerActions[action] = layer;
Chris@0 1437
Chris@0 1438 m_existingLayersMenu->addAction(action);
Chris@95 1439
Chris@95 1440 if (sliceableLayers.find(layer) != sliceableLayers.end()) {
Chris@95 1441 action = new QAction(icon, name, this);
Chris@95 1442 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@95 1443 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@95 1444 m_sliceActions[action] = layer;
Chris@95 1445 m_sliceMenu->addAction(action);
Chris@95 1446 }
Chris@0 1447 }
Chris@95 1448
Chris@95 1449 m_sliceMenu->setEnabled(!m_sliceActions.empty());
Chris@0 1450 }
Chris@0 1451
Chris@0 1452 void
Chris@0 1453 MainWindow::setupToolbars()
Chris@0 1454 {
Chris@0 1455 QToolBar *toolbar = addToolBar(tr("Transport Toolbar"));
Chris@0 1456
Chris@0 1457 QAction *action = toolbar->addAction(QIcon(":/icons/rewind-start.png"),
Chris@0 1458 tr("Rewind to Start"));
Chris@0 1459 action->setShortcut(tr("Home"));
Chris@0 1460 action->setStatusTip(tr("Rewind to the start"));
Chris@0 1461 connect(action, SIGNAL(triggered()), this, SLOT(rewindStart()));
Chris@0 1462 connect(this, SIGNAL(canPlay(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1463
Chris@0 1464 action = toolbar->addAction(QIcon(":/icons/rewind.png"),
Chris@0 1465 tr("Rewind"));
Chris@0 1466 action->setShortcut(tr("PageUp"));
Chris@0 1467 action->setStatusTip(tr("Rewind to the previous time instant in the current layer"));
Chris@0 1468 connect(action, SIGNAL(triggered()), this, SLOT(rewind()));
Chris@0 1469 connect(this, SIGNAL(canRewind(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1470
Chris@0 1471 action = toolbar->addAction(QIcon(":/icons/playpause.png"),
Chris@0 1472 tr("Play / Pause"));
Chris@0 1473 action->setCheckable(true);
Chris@0 1474 action->setShortcut(tr("Space"));
Chris@0 1475 action->setStatusTip(tr("Start or stop playback from the current position"));
Chris@0 1476 connect(action, SIGNAL(triggered()), this, SLOT(play()));
Chris@0 1477 connect(m_playSource, SIGNAL(playStatusChanged(bool)),
Chris@0 1478 action, SLOT(setChecked(bool)));
Chris@0 1479 connect(this, SIGNAL(canPlay(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1480
Chris@0 1481 action = toolbar->addAction(QIcon(":/icons/ffwd.png"),
Chris@0 1482 tr("Fast Forward"));
Chris@0 1483 action->setShortcut(tr("PageDown"));
Chris@0 1484 action->setStatusTip(tr("Fast forward to the next time instant in the current layer"));
Chris@0 1485 connect(action, SIGNAL(triggered()), this, SLOT(ffwd()));
Chris@0 1486 connect(this, SIGNAL(canFfwd(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1487
Chris@0 1488 action = toolbar->addAction(QIcon(":/icons/ffwd-end.png"),
Chris@0 1489 tr("Fast Forward to End"));
Chris@0 1490 action->setShortcut(tr("End"));
Chris@0 1491 action->setStatusTip(tr("Fast-forward to the end"));
Chris@0 1492 connect(action, SIGNAL(triggered()), this, SLOT(ffwdEnd()));
Chris@0 1493 connect(this, SIGNAL(canPlay(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1494
Chris@0 1495 toolbar = addToolBar(tr("Play Mode Toolbar"));
Chris@0 1496
Chris@0 1497 action = toolbar->addAction(QIcon(":/icons/playselection.png"),
Chris@0 1498 tr("Constrain Playback to Selection"));
Chris@0 1499 action->setCheckable(true);
Chris@0 1500 action->setChecked(m_viewManager->getPlaySelectionMode());
Chris@0 1501 action->setShortcut(tr("s"));
Chris@0 1502 action->setStatusTip(tr("Constrain playback to the selected area"));
Chris@69 1503 connect(m_viewManager, SIGNAL(playSelectionModeChanged(bool)),
Chris@69 1504 action, SLOT(setChecked(bool)));
Chris@0 1505 connect(action, SIGNAL(triggered()), this, SLOT(playSelectionToggled()));
Chris@0 1506 connect(this, SIGNAL(canPlaySelection(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1507
Chris@0 1508 action = toolbar->addAction(QIcon(":/icons/playloop.png"),
Chris@0 1509 tr("Loop Playback"));
Chris@0 1510 action->setCheckable(true);
Chris@0 1511 action->setChecked(m_viewManager->getPlayLoopMode());
Chris@0 1512 action->setShortcut(tr("l"));
Chris@0 1513 action->setStatusTip(tr("Loop playback"));
Chris@69 1514 connect(m_viewManager, SIGNAL(playLoopModeChanged(bool)),
Chris@69 1515 action, SLOT(setChecked(bool)));
Chris@0 1516 connect(action, SIGNAL(triggered()), this, SLOT(playLoopToggled()));
Chris@0 1517 connect(this, SIGNAL(canPlay(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1518
Chris@0 1519 toolbar = addToolBar(tr("Edit Toolbar"));
Chris@0 1520 CommandHistory::getInstance()->registerToolbar(toolbar);
Chris@0 1521
Chris@0 1522 toolbar = addToolBar(tr("Tools Toolbar"));
Chris@0 1523 QActionGroup *group = new QActionGroup(this);
Chris@0 1524
Chris@0 1525 action = toolbar->addAction(QIcon(":/icons/navigate.png"),
Chris@0 1526 tr("Navigate"));
Chris@0 1527 action->setCheckable(true);
Chris@0 1528 action->setChecked(true);
Chris@0 1529 action->setShortcut(tr("1"));
Chris@90 1530 action->setStatusTip(tr("Navigate"));
Chris@0 1531 connect(action, SIGNAL(triggered()), this, SLOT(toolNavigateSelected()));
Chris@0 1532 group->addAction(action);
Chris@0 1533 m_toolActions[ViewManager::NavigateMode] = action;
Chris@0 1534
Chris@0 1535 action = toolbar->addAction(QIcon(":/icons/select.png"),
Chris@0 1536 tr("Select"));
Chris@0 1537 action->setCheckable(true);
Chris@0 1538 action->setShortcut(tr("2"));
Chris@90 1539 action->setStatusTip(tr("Select ranges"));
Chris@0 1540 connect(action, SIGNAL(triggered()), this, SLOT(toolSelectSelected()));
Chris@0 1541 group->addAction(action);
Chris@0 1542 m_toolActions[ViewManager::SelectMode] = action;
Chris@0 1543
Chris@0 1544 action = toolbar->addAction(QIcon(":/icons/move.png"),
Chris@0 1545 tr("Edit"));
Chris@0 1546 action->setCheckable(true);
Chris@0 1547 action->setShortcut(tr("3"));
Chris@90 1548 action->setStatusTip(tr("Edit items in layer"));
Chris@0 1549 connect(action, SIGNAL(triggered()), this, SLOT(toolEditSelected()));
Chris@0 1550 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1551 group->addAction(action);
Chris@0 1552 m_toolActions[ViewManager::EditMode] = action;
Chris@0 1553
Chris@0 1554 action = toolbar->addAction(QIcon(":/icons/draw.png"),
Chris@0 1555 tr("Draw"));
Chris@0 1556 action->setCheckable(true);
Chris@0 1557 action->setShortcut(tr("4"));
Chris@90 1558 action->setStatusTip(tr("Draw new items in layer"));
Chris@0 1559 connect(action, SIGNAL(triggered()), this, SLOT(toolDrawSelected()));
Chris@0 1560 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1561 group->addAction(action);
Chris@0 1562 m_toolActions[ViewManager::DrawMode] = action;
Chris@0 1563
Chris@0 1564 // action = toolbar->addAction(QIcon(":/icons/text.png"),
Chris@0 1565 // tr("Text"));
Chris@0 1566 // action->setCheckable(true);
Chris@0 1567 // action->setShortcut(tr("5"));
Chris@0 1568 // connect(action, SIGNAL(triggered()), this, SLOT(toolTextSelected()));
Chris@0 1569 // group->addAction(action);
Chris@0 1570 // m_toolActions[ViewManager::TextMode] = action;
Chris@0 1571
Chris@0 1572 toolNavigateSelected();
Chris@0 1573 }
Chris@0 1574
Chris@0 1575 void
Chris@0 1576 MainWindow::updateMenuStates()
Chris@0 1577 {
Chris@117 1578 Pane *currentPane = 0;
Chris@117 1579 Layer *currentLayer = 0;
Chris@117 1580
Chris@117 1581 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
Chris@117 1582 if (currentPane) currentLayer = currentPane->getSelectedLayer();
Chris@117 1583
Chris@0 1584 bool haveCurrentPane =
Chris@117 1585 (currentPane != 0);
Chris@0 1586 bool haveCurrentLayer =
Chris@117 1587 (haveCurrentPane &&
Chris@117 1588 (currentLayer != 0));
Chris@0 1589 bool haveMainModel =
Chris@0 1590 (getMainModel() != 0);
Chris@0 1591 bool havePlayTarget =
Chris@0 1592 (m_playTarget != 0);
Chris@0 1593 bool haveSelection =
Chris@0 1594 (m_viewManager &&
Chris@0 1595 !m_viewManager->getSelections().empty());
Chris@0 1596 bool haveCurrentEditableLayer =
Chris@0 1597 (haveCurrentLayer &&
Chris@117 1598 currentLayer->isLayerEditable());
Chris@0 1599 bool haveCurrentTimeInstantsLayer =
Chris@0 1600 (haveCurrentLayer &&
Chris@117 1601 dynamic_cast<TimeInstantLayer *>(currentLayer));
Chris@0 1602 bool haveCurrentTimeValueLayer =
Chris@0 1603 (haveCurrentLayer &&
Chris@117 1604 dynamic_cast<TimeValueLayer *>(currentLayer));
Chris@0 1605 bool haveCurrentColour3DPlot =
Chris@0 1606 (haveCurrentLayer &&
Chris@117 1607 dynamic_cast<Colour3DPlotLayer *>(currentLayer));
Chris@0 1608 bool haveClipboardContents =
Chris@0 1609 (m_viewManager &&
Chris@0 1610 !m_viewManager->getClipboard().empty());
Chris@0 1611
Chris@0 1612 emit canAddPane(haveMainModel);
Chris@0 1613 emit canDeleteCurrentPane(haveCurrentPane);
Chris@0 1614 emit canZoom(haveMainModel && haveCurrentPane);
Chris@0 1615 emit canScroll(haveMainModel && haveCurrentPane);
Chris@0 1616 emit canAddLayer(haveMainModel && haveCurrentPane);
Chris@0 1617 emit canImportMoreAudio(haveMainModel);
Chris@0 1618 emit canImportLayer(haveMainModel && haveCurrentPane);
Chris@0 1619 emit canExportAudio(haveMainModel);
Chris@0 1620 emit canExportLayer(haveMainModel &&
Chris@0 1621 (haveCurrentEditableLayer || haveCurrentColour3DPlot));
Chris@0 1622 emit canDeleteCurrentLayer(haveCurrentLayer);
Chris@0 1623 emit canRenameLayer(haveCurrentLayer);
Chris@0 1624 emit canEditLayer(haveCurrentEditableLayer);
Chris@0 1625 emit canSelect(haveMainModel && haveCurrentPane);
Chris@0 1626 emit canPlay(/*!!! haveMainModel && */ havePlayTarget);
Chris@0 1627 emit canFfwd(haveCurrentTimeInstantsLayer || haveCurrentTimeValueLayer);
Chris@0 1628 emit canRewind(haveCurrentTimeInstantsLayer || haveCurrentTimeValueLayer);
Chris@0 1629 emit canPaste(haveCurrentEditableLayer && haveClipboardContents);
Chris@0 1630 emit canInsertInstant(haveCurrentPane);
Chris@81 1631 emit canInsertInstantsAtBoundaries(haveCurrentPane && haveSelection);
Chris@0 1632 emit canPlaySelection(haveMainModel && havePlayTarget && haveSelection);
Chris@0 1633 emit canClearSelection(haveSelection);
Chris@0 1634 emit canEditSelection(haveSelection && haveCurrentEditableLayer);
Chris@0 1635 emit canSave(m_sessionFile != "" && m_documentModified);
Chris@0 1636 }
Chris@0 1637
Chris@0 1638 void
Chris@0 1639 MainWindow::updateDescriptionLabel()
Chris@0 1640 {
Chris@0 1641 if (!getMainModel()) {
Chris@0 1642 m_descriptionLabel->setText(tr("No audio file loaded."));
Chris@0 1643 return;
Chris@0 1644 }
Chris@0 1645
Chris@0 1646 QString description;
Chris@0 1647
Chris@0 1648 size_t ssr = getMainModel()->getSampleRate();
Chris@0 1649 size_t tsr = ssr;
Chris@0 1650 if (m_playSource) tsr = m_playSource->getTargetSampleRate();
Chris@0 1651
Chris@0 1652 if (ssr != tsr) {
Chris@0 1653 description = tr("%1Hz (resampling to %2Hz)").arg(ssr).arg(tsr);
Chris@0 1654 } else {
Chris@0 1655 description = QString("%1Hz").arg(ssr);
Chris@0 1656 }
Chris@0 1657
Chris@0 1658 description = QString("%1 - %2")
Chris@0 1659 .arg(RealTime::frame2RealTime(getMainModel()->getEndFrame(), ssr)
Chris@0 1660 .toText(false).c_str())
Chris@0 1661 .arg(description);
Chris@0 1662
Chris@0 1663 m_descriptionLabel->setText(description);
Chris@0 1664 }
Chris@0 1665
Chris@0 1666 void
Chris@0 1667 MainWindow::documentModified()
Chris@0 1668 {
Chris@0 1669 // std::cerr << "MainWindow::documentModified" << std::endl;
Chris@0 1670
Chris@0 1671 if (!m_documentModified) {
Chris@0 1672 setWindowTitle(tr("%1 (modified)").arg(windowTitle()));
Chris@0 1673 }
Chris@0 1674
Chris@0 1675 m_documentModified = true;
Chris@0 1676 updateMenuStates();
Chris@0 1677 }
Chris@0 1678
Chris@0 1679 void
Chris@0 1680 MainWindow::documentRestored()
Chris@0 1681 {
Chris@0 1682 // std::cerr << "MainWindow::documentRestored" << std::endl;
Chris@0 1683
Chris@0 1684 if (m_documentModified) {
Chris@0 1685 QString wt(windowTitle());
Chris@0 1686 wt.replace(tr(" (modified)"), "");
Chris@0 1687 setWindowTitle(wt);
Chris@0 1688 }
Chris@0 1689
Chris@0 1690 m_documentModified = false;
Chris@0 1691 updateMenuStates();
Chris@0 1692 }
Chris@0 1693
Chris@0 1694 void
Chris@0 1695 MainWindow::playLoopToggled()
Chris@0 1696 {
Chris@0 1697 QAction *action = dynamic_cast<QAction *>(sender());
Chris@0 1698
Chris@0 1699 if (action) {
Chris@0 1700 m_viewManager->setPlayLoopMode(action->isChecked());
Chris@0 1701 } else {
Chris@0 1702 m_viewManager->setPlayLoopMode(!m_viewManager->getPlayLoopMode());
Chris@0 1703 }
Chris@0 1704 }
Chris@0 1705
Chris@0 1706 void
Chris@0 1707 MainWindow::playSelectionToggled()
Chris@0 1708 {
Chris@0 1709 QAction *action = dynamic_cast<QAction *>(sender());
Chris@0 1710
Chris@0 1711 if (action) {
Chris@0 1712 m_viewManager->setPlaySelectionMode(action->isChecked());
Chris@0 1713 } else {
Chris@0 1714 m_viewManager->setPlaySelectionMode(!m_viewManager->getPlaySelectionMode());
Chris@0 1715 }
Chris@0 1716 }
Chris@0 1717
Chris@0 1718 void
Chris@116 1719 MainWindow::currentPaneChanged(Pane *p)
Chris@0 1720 {
Chris@0 1721 updateMenuStates();
Chris@116 1722 updateVisibleRangeDisplay(p);
Chris@0 1723 }
Chris@0 1724
Chris@0 1725 void
Chris@116 1726 MainWindow::currentLayerChanged(Pane *p, Layer *)
Chris@0 1727 {
Chris@0 1728 updateMenuStates();
Chris@116 1729 updateVisibleRangeDisplay(p);
Chris@0 1730 }
Chris@0 1731
Chris@0 1732 void
Chris@0 1733 MainWindow::toolNavigateSelected()
Chris@0 1734 {
Chris@0 1735 m_viewManager->setToolMode(ViewManager::NavigateMode);
Chris@0 1736 }
Chris@0 1737
Chris@0 1738 void
Chris@0 1739 MainWindow::toolSelectSelected()
Chris@0 1740 {
Chris@0 1741 m_viewManager->setToolMode(ViewManager::SelectMode);
Chris@0 1742 }
Chris@0 1743
Chris@0 1744 void
Chris@0 1745 MainWindow::toolEditSelected()
Chris@0 1746 {
Chris@0 1747 m_viewManager->setToolMode(ViewManager::EditMode);
Chris@0 1748 }
Chris@0 1749
Chris@0 1750 void
Chris@0 1751 MainWindow::toolDrawSelected()
Chris@0 1752 {
Chris@0 1753 m_viewManager->setToolMode(ViewManager::DrawMode);
Chris@0 1754 }
Chris@0 1755
Chris@0 1756 //void
Chris@0 1757 //MainWindow::toolTextSelected()
Chris@0 1758 //{
Chris@0 1759 // m_viewManager->setToolMode(ViewManager::TextMode);
Chris@0 1760 //}
Chris@0 1761
Chris@0 1762 void
Chris@0 1763 MainWindow::selectAll()
Chris@0 1764 {
Chris@0 1765 if (!getMainModel()) return;
Chris@0 1766 m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(),
Chris@0 1767 getMainModel()->getEndFrame()));
Chris@0 1768 }
Chris@0 1769
Chris@0 1770 void
Chris@0 1771 MainWindow::selectToStart()
Chris@0 1772 {
Chris@0 1773 if (!getMainModel()) return;
Chris@0 1774 m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(),
Chris@0 1775 m_viewManager->getGlobalCentreFrame()));
Chris@0 1776 }
Chris@0 1777
Chris@0 1778 void
Chris@0 1779 MainWindow::selectToEnd()
Chris@0 1780 {
Chris@0 1781 if (!getMainModel()) return;
Chris@0 1782 m_viewManager->setSelection(Selection(m_viewManager->getGlobalCentreFrame(),
Chris@0 1783 getMainModel()->getEndFrame()));
Chris@0 1784 }
Chris@0 1785
Chris@0 1786 void
Chris@0 1787 MainWindow::selectVisible()
Chris@0 1788 {
Chris@0 1789 Model *model = getMainModel();
Chris@0 1790 if (!model) return;
Chris@0 1791
Chris@0 1792 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 1793 if (!currentPane) return;
Chris@0 1794
Chris@0 1795 size_t startFrame, endFrame;
Chris@0 1796
Chris@0 1797 if (currentPane->getStartFrame() < 0) startFrame = 0;
Chris@0 1798 else startFrame = currentPane->getStartFrame();
Chris@0 1799
Chris@0 1800 if (currentPane->getEndFrame() > model->getEndFrame()) endFrame = model->getEndFrame();
Chris@0 1801 else endFrame = currentPane->getEndFrame();
Chris@0 1802
Chris@0 1803 m_viewManager->setSelection(Selection(startFrame, endFrame));
Chris@0 1804 }
Chris@0 1805
Chris@0 1806 void
Chris@0 1807 MainWindow::clearSelection()
Chris@0 1808 {
Chris@0 1809 m_viewManager->clearSelections();
Chris@0 1810 }
Chris@0 1811
Chris@0 1812 void
Chris@0 1813 MainWindow::cut()
Chris@0 1814 {
Chris@0 1815 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 1816 if (!currentPane) return;
Chris@0 1817
Chris@0 1818 Layer *layer = currentPane->getSelectedLayer();
Chris@0 1819 if (!layer) return;
Chris@0 1820
Chris@0 1821 Clipboard &clipboard = m_viewManager->getClipboard();
Chris@0 1822 clipboard.clear();
Chris@0 1823
Chris@0 1824 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@0 1825
Chris@0 1826 CommandHistory::getInstance()->startCompoundOperation(tr("Cut"), true);
Chris@0 1827
Chris@0 1828 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@0 1829 i != selections.end(); ++i) {
Chris@0 1830 layer->copy(*i, clipboard);
Chris@0 1831 layer->deleteSelection(*i);
Chris@0 1832 }
Chris@0 1833
Chris@0 1834 CommandHistory::getInstance()->endCompoundOperation();
Chris@0 1835 }
Chris@0 1836
Chris@0 1837 void
Chris@0 1838 MainWindow::copy()
Chris@0 1839 {
Chris@0 1840 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 1841 if (!currentPane) return;
Chris@0 1842
Chris@0 1843 Layer *layer = currentPane->getSelectedLayer();
Chris@0 1844 if (!layer) return;
Chris@0 1845
Chris@0 1846 Clipboard &clipboard = m_viewManager->getClipboard();
Chris@0 1847 clipboard.clear();
Chris@0 1848
Chris@0 1849 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@0 1850
Chris@0 1851 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@0 1852 i != selections.end(); ++i) {
Chris@0 1853 layer->copy(*i, clipboard);
Chris@0 1854 }
Chris@0 1855 }
Chris@0 1856
Chris@0 1857 void
Chris@0 1858 MainWindow::paste()
Chris@0 1859 {
Chris@0 1860 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 1861 if (!currentPane) return;
Chris@0 1862
Chris@0 1863 //!!! if we have no current layer, we should create one of the most
Chris@0 1864 // appropriate type
Chris@0 1865
Chris@0 1866 Layer *layer = currentPane->getSelectedLayer();
Chris@0 1867 if (!layer) return;
Chris@0 1868
Chris@0 1869 Clipboard &clipboard = m_viewManager->getClipboard();
Chris@0 1870 Clipboard::PointList contents = clipboard.getPoints();
Chris@0 1871 /*
Chris@0 1872 long minFrame = 0;
Chris@0 1873 bool have = false;
Chris@0 1874 for (int i = 0; i < contents.size(); ++i) {
Chris@0 1875 if (!contents[i].haveFrame()) continue;
Chris@0 1876 if (!have || contents[i].getFrame() < minFrame) {
Chris@0 1877 minFrame = contents[i].getFrame();
Chris@0 1878 have = true;
Chris@0 1879 }
Chris@0 1880 }
Chris@0 1881
Chris@0 1882 long frameOffset = long(m_viewManager->getGlobalCentreFrame()) - minFrame;
Chris@0 1883
Chris@0 1884 layer->paste(clipboard, frameOffset);
Chris@0 1885 */
Chris@0 1886 layer->paste(clipboard, 0, true);
Chris@0 1887 }
Chris@0 1888
Chris@0 1889 void
Chris@0 1890 MainWindow::deleteSelected()
Chris@0 1891 {
Chris@0 1892 if (m_paneStack->getCurrentPane() &&
Chris@0 1893 m_paneStack->getCurrentPane()->getSelectedLayer()) {
Chris@0 1894
Chris@0 1895 MultiSelection::SelectionList selections =
Chris@0 1896 m_viewManager->getSelections();
Chris@0 1897
Chris@0 1898 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@0 1899 i != selections.end(); ++i) {
Chris@0 1900
Chris@0 1901 m_paneStack->getCurrentPane()->getSelectedLayer()->deleteSelection(*i);
Chris@0 1902 }
Chris@0 1903 }
Chris@0 1904 }
Chris@0 1905
Chris@0 1906 void
Chris@0 1907 MainWindow::insertInstant()
Chris@0 1908 {
Chris@0 1909 int frame = m_viewManager->getPlaybackFrame();
Chris@81 1910 insertInstantAt(frame);
Chris@81 1911 }
Chris@81 1912
Chris@81 1913 void
Chris@81 1914 MainWindow::insertInstantsAtBoundaries()
Chris@81 1915 {
Chris@81 1916 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@81 1917 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@81 1918 i != selections.end(); ++i) {
Chris@81 1919 size_t start = i->getStartFrame();
Chris@81 1920 size_t end = i->getEndFrame();
Chris@81 1921 if (start != end) {
Chris@81 1922 insertInstantAt(i->getStartFrame());
Chris@81 1923 insertInstantAt(i->getEndFrame());
Chris@81 1924 }
Chris@81 1925 }
Chris@81 1926 }
Chris@81 1927
Chris@81 1928 void
Chris@81 1929 MainWindow::insertInstantAt(size_t frame)
Chris@81 1930 {
Chris@0 1931 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 1932 if (!pane) {
Chris@0 1933 return;
Chris@0 1934 }
Chris@0 1935
Chris@0 1936 Layer *layer = dynamic_cast<TimeInstantLayer *>
Chris@0 1937 (pane->getSelectedLayer());
Chris@0 1938
Chris@0 1939 if (!layer) {
Chris@0 1940 for (int i = pane->getLayerCount(); i > 0; --i) {
Chris@0 1941 layer = dynamic_cast<TimeInstantLayer *>(pane->getLayer(i - 1));
Chris@0 1942 if (layer) break;
Chris@0 1943 }
Chris@0 1944
Chris@0 1945 if (!layer) {
Chris@0 1946 CommandHistory::getInstance()->startCompoundOperation
Chris@0 1947 (tr("Add Point"), true);
Chris@0 1948 layer = m_document->createEmptyLayer(LayerFactory::TimeInstants);
Chris@0 1949 if (layer) {
Chris@0 1950 m_document->addLayerToView(pane, layer);
Chris@0 1951 m_paneStack->setCurrentLayer(pane, layer);
Chris@0 1952 }
Chris@0 1953 CommandHistory::getInstance()->endCompoundOperation();
Chris@0 1954 }
Chris@0 1955 }
Chris@0 1956
Chris@0 1957 if (layer) {
Chris@0 1958
Chris@0 1959 Model *model = layer->getModel();
Chris@0 1960 SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *>
Chris@0 1961 (model);
Chris@0 1962
Chris@0 1963 if (sodm) {
Chris@0 1964 SparseOneDimensionalModel::Point point
Chris@0 1965 (frame, QString("%1").arg(sodm->getPointCount() + 1));
Chris@0 1966 CommandHistory::getInstance()->addCommand
Chris@0 1967 (new SparseOneDimensionalModel::AddPointCommand(sodm, point,
Chris@0 1968 tr("Add Points")),
Chris@0 1969 true, true); // bundled
Chris@0 1970 }
Chris@0 1971 }
Chris@0 1972 }
Chris@0 1973
Chris@0 1974 void
Chris@0 1975 MainWindow::importAudio()
Chris@0 1976 {
Chris@88 1977 QString path = getOpenFileName(FileFinder::AudioFile);
Chris@0 1978
Chris@0 1979 if (path != "") {
Chris@82 1980 if (openAudioFile(path, ReplaceMainModel) == FileOpenFailed) {
Chris@0 1981 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 1982 tr("Audio file \"%1\" could not be opened").arg(path));
Chris@0 1983 }
Chris@0 1984 }
Chris@0 1985 }
Chris@0 1986
Chris@0 1987 void
Chris@0 1988 MainWindow::importMoreAudio()
Chris@0 1989 {
Chris@88 1990 QString path = getOpenFileName(FileFinder::AudioFile);
Chris@0 1991
Chris@0 1992 if (path != "") {
Chris@82 1993 if (openAudioFile(path, CreateAdditionalModel) == FileOpenFailed) {
Chris@0 1994 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 1995 tr("Audio file \"%1\" could not be opened").arg(path));
Chris@0 1996 }
Chris@0 1997 }
Chris@0 1998 }
Chris@0 1999
Chris@0 2000 void
Chris@0 2001 MainWindow::exportAudio()
Chris@0 2002 {
Chris@0 2003 if (!getMainModel()) return;
Chris@0 2004
Chris@88 2005 QString path = getSaveFileName(FileFinder::AudioFile);
Chris@0 2006
Chris@0 2007 if (path == "") return;
Chris@0 2008
Chris@0 2009 bool ok = false;
Chris@0 2010 QString error;
Chris@0 2011
Chris@0 2012 MultiSelection ms = m_viewManager->getSelection();
Chris@0 2013 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@0 2014
Chris@0 2015 bool multiple = false;
Chris@0 2016
Chris@38 2017 MultiSelection *selectionToWrite = 0;
Chris@38 2018
Chris@38 2019 if (selections.size() == 1) {
Chris@0 2020
Chris@0 2021 QStringList items;
Chris@0 2022 items << tr("Export the selected region only")
Chris@0 2023 << tr("Export the whole audio file");
Chris@0 2024
Chris@0 2025 bool ok = false;
Chris@0 2026 QString item = ListInputDialog::getItem
Chris@0 2027 (this, tr("Select region to export"),
Chris@0 2028 tr("Which region from the original audio file do you want to export?"),
Chris@0 2029 items, 0, &ok);
Chris@0 2030
Chris@0 2031 if (!ok || item.isEmpty()) return;
Chris@0 2032
Chris@38 2033 if (item == items[0]) selectionToWrite = &ms;
Chris@38 2034
Chris@38 2035 } else if (selections.size() > 1) {
Chris@0 2036
Chris@0 2037 QStringList items;
Chris@0 2038 items << tr("Export the selected regions into a single audio file")
Chris@0 2039 << tr("Export the selected regions into separate files")
Chris@0 2040 << tr("Export the whole audio file");
Chris@0 2041
Chris@0 2042 QString item = ListInputDialog::getItem
Chris@0 2043 (this, tr("Select region to export"),
Chris@0 2044 tr("Multiple regions of the original audio file are selected.\nWhat do you want to export?"),
Chris@0 2045 items, 0, &ok);
Chris@0 2046
Chris@0 2047 if (!ok || item.isEmpty()) return;
Chris@0 2048
Chris@0 2049 if (item == items[0]) {
Chris@0 2050
Chris@38 2051 selectionToWrite = &ms;
Chris@38 2052
Chris@38 2053 } else if (item == items[1]) {
Chris@0 2054
Chris@0 2055 multiple = true;
Chris@0 2056
Chris@0 2057 int n = 1;
Chris@0 2058 QString base = path;
Chris@0 2059 base.replace(".wav", "");
Chris@0 2060
Chris@0 2061 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@0 2062 i != selections.end(); ++i) {
Chris@0 2063
Chris@0 2064 MultiSelection subms;
Chris@0 2065 subms.setSelection(*i);
Chris@0 2066
Chris@0 2067 QString subpath = QString("%1.%2.wav").arg(base).arg(n);
Chris@0 2068 ++n;
Chris@0 2069
Chris@0 2070 if (QFileInfo(subpath).exists()) {
Chris@0 2071 error = tr("Fragment file %1 already exists, aborting").arg(subpath);
Chris@0 2072 break;
Chris@0 2073 }
Chris@0 2074
Chris@38 2075 WavFileWriter subwriter(subpath,
Chris@38 2076 getMainModel()->getSampleRate(),
Chris@38 2077 getMainModel()->getChannelCount());
Chris@38 2078 subwriter.writeModel(getMainModel(), &subms);
Chris@0 2079 ok = subwriter.isOK();
Chris@0 2080
Chris@0 2081 if (!ok) {
Chris@0 2082 error = subwriter.getError();
Chris@0 2083 break;
Chris@0 2084 }
Chris@0 2085 }
Chris@0 2086 }
Chris@0 2087 }
Chris@0 2088
Chris@38 2089 if (!multiple) {
Chris@38 2090 WavFileWriter writer(path,
Chris@38 2091 getMainModel()->getSampleRate(),
Chris@38 2092 getMainModel()->getChannelCount());
Chris@38 2093 writer.writeModel(getMainModel(), selectionToWrite);
Chris@38 2094 ok = writer.isOK();
Chris@38 2095 error = writer.getError();
Chris@0 2096 }
Chris@0 2097
Chris@0 2098 if (ok) {
Chris@0 2099 if (!multiple) {
Chris@34 2100 m_recentFiles.addFile(path);
Chris@0 2101 }
Chris@0 2102 } else {
Chris@0 2103 QMessageBox::critical(this, tr("Failed to write file"), error);
Chris@0 2104 }
Chris@0 2105 }
Chris@0 2106
Chris@0 2107 void
Chris@0 2108 MainWindow::importLayer()
Chris@0 2109 {
Chris@0 2110 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 2111
Chris@0 2112 if (!pane) {
Chris@0 2113 // shouldn't happen, as the menu action should have been disabled
Chris@0 2114 std::cerr << "WARNING: MainWindow::importLayer: no current pane" << std::endl;
Chris@0 2115 return;
Chris@0 2116 }
Chris@0 2117
Chris@0 2118 if (!getMainModel()) {
Chris@0 2119 // shouldn't happen, as the menu action should have been disabled
Chris@0 2120 std::cerr << "WARNING: MainWindow::importLayer: No main model -- hence no default sample rate available" << std::endl;
Chris@0 2121 return;
Chris@0 2122 }
Chris@0 2123
Chris@88 2124 QString path = getOpenFileName(FileFinder::LayerFile);
Chris@0 2125
Chris@0 2126 if (path != "") {
Chris@0 2127
Chris@82 2128 if (openLayerFile(path) == FileOpenFailed) {
Chris@0 2129 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 2130 tr("File %1 could not be opened.").arg(path));
Chris@0 2131 return;
Chris@0 2132 }
Chris@0 2133 }
Chris@0 2134 }
Chris@0 2135
Chris@82 2136 MainWindow::FileOpenStatus
Chris@0 2137 MainWindow::openLayerFile(QString path)
Chris@0 2138 {
Chris@86 2139 return openLayerFile(path, path);
Chris@86 2140 }
Chris@86 2141
Chris@86 2142 MainWindow::FileOpenStatus
Chris@86 2143 MainWindow::openLayerFile(QString path, QString location)
Chris@86 2144 {
Chris@0 2145 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 2146
Chris@0 2147 if (!pane) {
Chris@0 2148 // shouldn't happen, as the menu action should have been disabled
Chris@0 2149 std::cerr << "WARNING: MainWindow::openLayerFile: no current pane" << std::endl;
Chris@82 2150 return FileOpenFailed;
Chris@0 2151 }
Chris@0 2152
Chris@0 2153 if (!getMainModel()) {
Chris@0 2154 // shouldn't happen, as the menu action should have been disabled
Chris@0 2155 std::cerr << "WARNING: MainWindow::openLayerFile: No main model -- hence no default sample rate available" << std::endl;
Chris@82 2156 return FileOpenFailed;
Chris@0 2157 }
Chris@0 2158
Chris@86 2159 bool realFile = (location == path);
Chris@86 2160
Chris@0 2161 if (path.endsWith(".svl") || path.endsWith(".xml")) {
Chris@0 2162
Chris@0 2163 PaneCallback callback(this);
Chris@0 2164 QFile file(path);
Chris@0 2165
Chris@0 2166 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
Chris@0 2167 std::cerr << "ERROR: MainWindow::openLayerFile("
Chris@86 2168 << location.toStdString()
Chris@0 2169 << "): Failed to open file for reading" << std::endl;
Chris@82 2170 return FileOpenFailed;
Chris@0 2171 }
Chris@0 2172
Chris@87 2173 SVFileReader reader(m_document, callback, location);
Chris@0 2174 reader.setCurrentPane(pane);
Chris@0 2175
Chris@0 2176 QXmlInputSource inputSource(&file);
Chris@0 2177 reader.parse(inputSource);
Chris@0 2178
Chris@0 2179 if (!reader.isOK()) {
Chris@0 2180 std::cerr << "ERROR: MainWindow::openLayerFile("
Chris@86 2181 << location.toStdString()
Chris@0 2182 << "): Failed to read XML file: "
Chris@0 2183 << reader.getErrorString().toStdString() << std::endl;
Chris@82 2184 return FileOpenFailed;
Chris@0 2185 }
Chris@0 2186
Chris@86 2187 m_recentFiles.addFile(location);
Chris@86 2188
Chris@86 2189 if (realFile) {
Chris@88 2190 registerLastOpenedFilePath(FileFinder::LayerFile, path); // for file dialog
Chris@86 2191 }
Chris@86 2192
Chris@82 2193 return FileOpenSucceeded;
Chris@0 2194
Chris@0 2195 } else {
Chris@0 2196
Chris@0 2197 Model *model = DataFileReaderFactory::load(path, getMainModel()->getSampleRate());
Chris@0 2198
Chris@0 2199 if (model) {
Chris@86 2200
Chris@0 2201 Layer *newLayer = m_document->createImportedLayer(model);
Chris@86 2202
Chris@0 2203 if (newLayer) {
Chris@86 2204
Chris@0 2205 m_document->addLayerToView(pane, newLayer);
Chris@86 2206 m_recentFiles.addFile(location);
Chris@86 2207
Chris@86 2208 if (realFile) {
Chris@88 2209 registerLastOpenedFilePath(FileFinder::LayerFile, path); // for file dialog
Chris@86 2210 }
Chris@86 2211
Chris@82 2212 return FileOpenSucceeded;
Chris@0 2213 }
Chris@0 2214 }
Chris@0 2215 }
Chris@0 2216
Chris@82 2217 return FileOpenFailed;
Chris@0 2218 }
Chris@0 2219
Chris@0 2220 void
Chris@0 2221 MainWindow::exportLayer()
Chris@0 2222 {
Chris@0 2223 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 2224 if (!pane) return;
Chris@0 2225
Chris@0 2226 Layer *layer = pane->getSelectedLayer();
Chris@0 2227 if (!layer) return;
Chris@0 2228
Chris@0 2229 Model *model = layer->getModel();
Chris@0 2230 if (!model) return;
Chris@0 2231
Chris@88 2232 QString path = getSaveFileName(FileFinder::LayerFile);
Chris@0 2233
Chris@0 2234 if (path == "") return;
Chris@0 2235
Chris@0 2236 if (QFileInfo(path).suffix() == "") path += ".svl";
Chris@0 2237
Chris@0 2238 QString error;
Chris@0 2239
Chris@0 2240 if (path.endsWith(".xml") || path.endsWith(".svl")) {
Chris@0 2241
Chris@0 2242 QFile file(path);
Chris@0 2243 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
Chris@0 2244 error = tr("Failed to open file %1 for writing").arg(path);
Chris@0 2245 } else {
Chris@0 2246 QTextStream out(&file);
Chris@0 2247 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
Chris@0 2248 << "<!DOCTYPE sonic-visualiser>\n"
Chris@0 2249 << "<sv>\n"
Chris@0 2250 << " <data>\n";
Chris@0 2251
Chris@0 2252 model->toXml(out, " ");
Chris@0 2253
Chris@0 2254 out << " </data>\n"
Chris@0 2255 << " <display>\n";
Chris@0 2256
Chris@0 2257 layer->toXml(out, " ");
Chris@0 2258
Chris@0 2259 out << " </display>\n"
Chris@0 2260 << "</sv>\n";
Chris@0 2261 }
Chris@0 2262
Chris@0 2263 } else {
Chris@0 2264
Chris@0 2265 CSVFileWriter writer(path, model,
Chris@0 2266 (path.endsWith(".csv") ? "," : "\t"));
Chris@0 2267 writer.write();
Chris@0 2268
Chris@0 2269 if (!writer.isOK()) {
Chris@0 2270 error = writer.getError();
Chris@0 2271 }
Chris@0 2272 }
Chris@0 2273
Chris@0 2274 if (error != "") {
Chris@0 2275 QMessageBox::critical(this, tr("Failed to write file"), error);
Chris@0 2276 } else {
Chris@34 2277 m_recentFiles.addFile(path);
Chris@0 2278 }
Chris@0 2279 }
Chris@0 2280
Chris@82 2281 MainWindow::FileOpenStatus
Chris@0 2282 MainWindow::openAudioFile(QString path, AudioFileOpenMode mode)
Chris@0 2283 {
Chris@86 2284 return openAudioFile(path, path, mode);
Chris@86 2285 }
Chris@86 2286
Chris@86 2287 MainWindow::FileOpenStatus
Chris@86 2288 MainWindow::openAudioFile(QString path, QString location, AudioFileOpenMode mode)
Chris@86 2289 {
Chris@0 2290 if (!(QFileInfo(path).exists() &&
Chris@0 2291 QFileInfo(path).isFile() &&
Chris@0 2292 QFileInfo(path).isReadable())) {
Chris@82 2293 return FileOpenFailed;
Chris@0 2294 }
Chris@0 2295
Chris@70 2296 m_openingAudioFile = true;
Chris@70 2297
Chris@88 2298 WaveFileModel *newModel = new WaveFileModel(path, location);
Chris@0 2299
Chris@0 2300 if (!newModel->isOK()) {
Chris@0 2301 delete newModel;
Chris@70 2302 m_openingAudioFile = false;
Chris@82 2303 return FileOpenFailed;
Chris@0 2304 }
Chris@0 2305
Chris@0 2306 bool setAsMain = true;
Chris@0 2307 static bool prevSetAsMain = true;
Chris@0 2308
Chris@86 2309 bool realFile = (location == path);
Chris@86 2310
Chris@0 2311 if (mode == CreateAdditionalModel) setAsMain = false;
Chris@0 2312 else if (mode == AskUser) {
Chris@0 2313 if (m_document->getMainModel()) {
Chris@0 2314
Chris@0 2315 QStringList items;
Chris@0 2316 items << tr("Replace the existing main waveform")
Chris@0 2317 << tr("Load this file into a new waveform pane");
Chris@0 2318
Chris@0 2319 bool ok = false;
Chris@0 2320 QString item = ListInputDialog::getItem
Chris@0 2321 (this, tr("Select target for import"),
Chris@0 2322 tr("You already have an audio waveform loaded.\nWhat would you like to do with the new audio file?"),
Chris@0 2323 items, prevSetAsMain ? 0 : 1, &ok);
Chris@0 2324
Chris@0 2325 if (!ok || item.isEmpty()) {
Chris@0 2326 delete newModel;
Chris@70 2327 m_openingAudioFile = false;
Chris@82 2328 return FileOpenCancelled;
Chris@0 2329 }
Chris@0 2330
Chris@0 2331 setAsMain = (item == items[0]);
Chris@0 2332 prevSetAsMain = setAsMain;
Chris@0 2333 }
Chris@0 2334 }
Chris@0 2335
Chris@0 2336 if (setAsMain) {
Chris@0 2337
Chris@0 2338 Model *prevMain = getMainModel();
Chris@118 2339 if (prevMain) {
Chris@118 2340 m_playSource->removeModel(prevMain);
Chris@118 2341 PlayParameterRepository::getInstance()->removeModel(prevMain);
Chris@118 2342 }
Chris@118 2343
Chris@118 2344 PlayParameterRepository::getInstance()->addModel(newModel);
Chris@0 2345
Chris@0 2346 m_document->setMainModel(newModel);
Chris@0 2347 setupMenus();
Chris@0 2348
Chris@0 2349 if (m_sessionFile == "") {
Chris@0 2350 setWindowTitle(tr("Sonic Visualiser: %1")
Chris@86 2351 .arg(QFileInfo(location).fileName()));
Chris@0 2352 CommandHistory::getInstance()->clear();
Chris@0 2353 CommandHistory::getInstance()->documentSaved();
Chris@0 2354 m_documentModified = false;
Chris@0 2355 } else {
Chris@0 2356 setWindowTitle(tr("Sonic Visualiser: %1 [%2]")
Chris@0 2357 .arg(QFileInfo(m_sessionFile).fileName())
Chris@86 2358 .arg(QFileInfo(location).fileName()));
Chris@0 2359 if (m_documentModified) {
Chris@0 2360 m_documentModified = false;
Chris@0 2361 documentModified(); // so as to restore "(modified)" window title
Chris@0 2362 }
Chris@0 2363 }
Chris@0 2364
Chris@86 2365 if (realFile) m_audioFile = path;
Chris@0 2366
Chris@0 2367 } else { // !setAsMain
Chris@0 2368
Chris@0 2369 CommandHistory::getInstance()->startCompoundOperation
Chris@86 2370 (tr("Import \"%1\"").arg(QFileInfo(location).fileName()), true);
Chris@0 2371
Chris@0 2372 m_document->addImportedModel(newModel);
Chris@0 2373
Chris@0 2374 AddPaneCommand *command = new AddPaneCommand(this);
Chris@0 2375 CommandHistory::getInstance()->addCommand(command);
Chris@0 2376
Chris@0 2377 Pane *pane = command->getPane();
Chris@0 2378
Chris@0 2379 if (!m_timeRulerLayer) {
Chris@0 2380 m_timeRulerLayer = m_document->createMainModelLayer
Chris@0 2381 (LayerFactory::TimeRuler);
Chris@0 2382 }
Chris@0 2383
Chris@0 2384 m_document->addLayerToView(pane, m_timeRulerLayer);
Chris@0 2385
Chris@0 2386 Layer *newLayer = m_document->createImportedLayer(newModel);
Chris@0 2387
Chris@0 2388 if (newLayer) {
Chris@0 2389 m_document->addLayerToView(pane, newLayer);
Chris@0 2390 }
Chris@0 2391
Chris@0 2392 CommandHistory::getInstance()->endCompoundOperation();
Chris@0 2393 }
Chris@0 2394
Chris@0 2395 updateMenuStates();
Chris@86 2396 m_recentFiles.addFile(location);
Chris@86 2397 if (realFile) {
Chris@88 2398 registerLastOpenedFilePath(FileFinder::AudioFile, path); // for file dialog
Chris@86 2399 }
Chris@70 2400 m_openingAudioFile = false;
Chris@0 2401
Chris@82 2402 return FileOpenSucceeded;
Chris@0 2403 }
Chris@0 2404
Chris@0 2405 void
Chris@0 2406 MainWindow::createPlayTarget()
Chris@0 2407 {
Chris@0 2408 if (m_playTarget) return;
Chris@0 2409
Chris@0 2410 m_playTarget = AudioTargetFactory::createCallbackTarget(m_playSource);
Chris@0 2411 if (!m_playTarget) {
Chris@0 2412 QMessageBox::warning
Chris@0 2413 (this, tr("Couldn't open audio device"),
Chris@0 2414 tr("Could not open an audio device for playback.\nAudio playback will not be available during this session.\n"),
Chris@0 2415 QMessageBox::Ok, 0);
Chris@0 2416 }
Chris@0 2417 connect(m_fader, SIGNAL(valueChanged(float)),
Chris@0 2418 m_playTarget, SLOT(setOutputGain(float)));
Chris@0 2419 }
Chris@0 2420
Chris@0 2421 WaveFileModel *
Chris@0 2422 MainWindow::getMainModel()
Chris@0 2423 {
Chris@0 2424 if (!m_document) return 0;
Chris@0 2425 return m_document->getMainModel();
Chris@0 2426 }
Chris@0 2427
Chris@116 2428 const WaveFileModel *
Chris@116 2429 MainWindow::getMainModel() const
Chris@116 2430 {
Chris@116 2431 if (!m_document) return 0;
Chris@116 2432 return m_document->getMainModel();
Chris@116 2433 }
Chris@116 2434
Chris@0 2435 void
Chris@0 2436 MainWindow::newSession()
Chris@0 2437 {
Chris@0 2438 if (!checkSaveModified()) return;
Chris@0 2439
Chris@0 2440 closeSession();
Chris@0 2441 createDocument();
Chris@0 2442
Chris@0 2443 Pane *pane = m_paneStack->addPane();
Chris@0 2444
Chris@90 2445 connect(pane, SIGNAL(contextHelpChanged(const QString &)),
Chris@116 2446 this, SLOT(contextHelpChanged(const QString &)));
Chris@90 2447
Chris@0 2448 if (!m_timeRulerLayer) {
Chris@0 2449 m_timeRulerLayer = m_document->createMainModelLayer
Chris@0 2450 (LayerFactory::TimeRuler);
Chris@0 2451 }
Chris@0 2452
Chris@0 2453 m_document->addLayerToView(pane, m_timeRulerLayer);
Chris@0 2454
Chris@0 2455 Layer *waveform = m_document->createMainModelLayer(LayerFactory::Waveform);
Chris@0 2456 m_document->addLayerToView(pane, waveform);
Chris@0 2457
Chris@65 2458 m_overview->registerView(pane);
Chris@0 2459
Chris@0 2460 CommandHistory::getInstance()->clear();
Chris@0 2461 CommandHistory::getInstance()->documentSaved();
Chris@0 2462 documentRestored();
Chris@0 2463 updateMenuStates();
Chris@0 2464 }
Chris@0 2465
Chris@0 2466 void
Chris@0 2467 MainWindow::createDocument()
Chris@0 2468 {
Chris@0 2469 m_document = new Document;
Chris@0 2470
Chris@0 2471 connect(m_document, SIGNAL(layerAdded(Layer *)),
Chris@0 2472 this, SLOT(layerAdded(Layer *)));
Chris@0 2473 connect(m_document, SIGNAL(layerRemoved(Layer *)),
Chris@0 2474 this, SLOT(layerRemoved(Layer *)));
Chris@0 2475 connect(m_document, SIGNAL(layerAboutToBeDeleted(Layer *)),
Chris@0 2476 this, SLOT(layerAboutToBeDeleted(Layer *)));
Chris@0 2477 connect(m_document, SIGNAL(layerInAView(Layer *, bool)),
Chris@0 2478 this, SLOT(layerInAView(Layer *, bool)));
Chris@0 2479
Chris@0 2480 connect(m_document, SIGNAL(modelAdded(Model *)),
Chris@0 2481 this, SLOT(modelAdded(Model *)));
Chris@0 2482 connect(m_document, SIGNAL(mainModelChanged(WaveFileModel *)),
Chris@0 2483 this, SLOT(mainModelChanged(WaveFileModel *)));
Chris@0 2484 connect(m_document, SIGNAL(modelAboutToBeDeleted(Model *)),
Chris@0 2485 this, SLOT(modelAboutToBeDeleted(Model *)));
Chris@0 2486
Chris@0 2487 connect(m_document, SIGNAL(modelGenerationFailed(QString)),
Chris@0 2488 this, SLOT(modelGenerationFailed(QString)));
Chris@63 2489 connect(m_document, SIGNAL(modelRegenerationFailed(QString, QString)),
Chris@63 2490 this, SLOT(modelRegenerationFailed(QString, QString)));
Chris@0 2491 }
Chris@0 2492
Chris@0 2493 void
Chris@0 2494 MainWindow::closeSession()
Chris@0 2495 {
Chris@0 2496 if (!checkSaveModified()) return;
Chris@0 2497
Chris@0 2498 while (m_paneStack->getPaneCount() > 0) {
Chris@0 2499
Chris@0 2500 Pane *pane = m_paneStack->getPane(m_paneStack->getPaneCount() - 1);
Chris@0 2501
Chris@0 2502 while (pane->getLayerCount() > 0) {
Chris@0 2503 m_document->removeLayerFromView
Chris@0 2504 (pane, pane->getLayer(pane->getLayerCount() - 1));
Chris@0 2505 }
Chris@0 2506
Chris@65 2507 m_overview->unregisterView(pane);
Chris@0 2508 m_paneStack->deletePane(pane);
Chris@0 2509 }
Chris@0 2510
Chris@0 2511 while (m_paneStack->getHiddenPaneCount() > 0) {
Chris@0 2512
Chris@0 2513 Pane *pane = m_paneStack->getHiddenPane
Chris@0 2514 (m_paneStack->getHiddenPaneCount() - 1);
Chris@0 2515
Chris@0 2516 while (pane->getLayerCount() > 0) {
Chris@0 2517 m_document->removeLayerFromView
Chris@0 2518 (pane, pane->getLayer(pane->getLayerCount() - 1));
Chris@0 2519 }
Chris@0 2520
Chris@65 2521 m_overview->unregisterView(pane);
Chris@0 2522 m_paneStack->deletePane(pane);
Chris@0 2523 }
Chris@0 2524
Chris@0 2525 delete m_document;
Chris@0 2526 m_document = 0;
Chris@0 2527 m_viewManager->clearSelections();
Chris@0 2528 m_timeRulerLayer = 0; // document owned this
Chris@0 2529
Chris@0 2530 m_sessionFile = "";
Chris@0 2531 setWindowTitle(tr("Sonic Visualiser"));
Chris@0 2532
Chris@0 2533 CommandHistory::getInstance()->clear();
Chris@0 2534 CommandHistory::getInstance()->documentSaved();
Chris@0 2535 documentRestored();
Chris@0 2536 }
Chris@0 2537
Chris@0 2538 void
Chris@0 2539 MainWindow::openSession()
Chris@0 2540 {
Chris@0 2541 if (!checkSaveModified()) return;
Chris@0 2542
Chris@0 2543 QString orig = m_audioFile;
Chris@0 2544 if (orig == "") orig = ".";
Chris@0 2545 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 2546
Chris@88 2547 QString path = getOpenFileName(FileFinder::SessionFile);
Chris@0 2548
Chris@0 2549 if (path.isEmpty()) return;
Chris@0 2550
Chris@82 2551 if (openSessionFile(path) == FileOpenFailed) {
Chris@0 2552 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 2553 tr("Session file \"%1\" could not be opened").arg(path));
Chris@0 2554 }
Chris@0 2555 }
Chris@0 2556
Chris@0 2557 void
Chris@0 2558 MainWindow::openSomething()
Chris@0 2559 {
Chris@0 2560 QString orig = m_audioFile;
Chris@0 2561 if (orig == "") orig = ".";
Chris@0 2562 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 2563
Chris@0 2564 bool canImportLayer = (getMainModel() != 0 &&
Chris@0 2565 m_paneStack != 0 &&
Chris@0 2566 m_paneStack->getCurrentPane() != 0);
Chris@0 2567
Chris@88 2568 QString path = getOpenFileName(FileFinder::AnyFile);
Chris@0 2569
Chris@0 2570 if (path.isEmpty()) return;
Chris@0 2571
Chris@0 2572 if (path.endsWith(".sv")) {
Chris@0 2573
Chris@0 2574 if (!checkSaveModified()) return;
Chris@0 2575
Chris@82 2576 if (openSessionFile(path) == FileOpenFailed) {
Chris@0 2577 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 2578 tr("Session file \"%1\" could not be opened").arg(path));
Chris@0 2579 }
Chris@0 2580
Chris@0 2581 } else {
Chris@0 2582
Chris@82 2583 if (openAudioFile(path, AskUser) == FileOpenFailed) {
Chris@82 2584
Chris@82 2585 if (!canImportLayer || (openLayerFile(path) == FileOpenFailed)) {
Chris@0 2586
Chris@0 2587 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 2588 tr("File \"%1\" could not be opened").arg(path));
Chris@0 2589 }
Chris@0 2590 }
Chris@0 2591 }
Chris@0 2592 }
Chris@0 2593
Chris@0 2594 void
Chris@86 2595 MainWindow::openLocation()
Chris@86 2596 {
Chris@103 2597 QSettings settings;
Chris@103 2598 settings.beginGroup("MainWindow");
Chris@103 2599 QString lastLocation = settings.value("lastremote", "").toString();
Chris@103 2600
Chris@86 2601 bool ok = false;
Chris@86 2602 QString text = QInputDialog::getText
Chris@86 2603 (this, tr("Open Location"),
Chris@86 2604 tr("Please enter the URL of the location to open:"),
Chris@103 2605 QLineEdit::Normal, lastLocation, &ok);
Chris@103 2606
Chris@103 2607 if (!ok) return;
Chris@103 2608
Chris@103 2609 settings.setValue("lastremote", text);
Chris@103 2610
Chris@103 2611 if (text.isEmpty()) return;
Chris@86 2612
Chris@86 2613 if (openURL(QUrl(text)) == FileOpenFailed) {
Chris@86 2614 QMessageBox::critical(this, tr("Failed to open location"),
Chris@86 2615 tr("URL \"%1\" could not be opened").arg(text));
Chris@86 2616 }
Chris@86 2617 }
Chris@86 2618
Chris@86 2619 void
Chris@0 2620 MainWindow::openRecentFile()
Chris@0 2621 {
Chris@0 2622 QObject *obj = sender();
Chris@0 2623 QAction *action = dynamic_cast<QAction *>(obj);
Chris@0 2624
Chris@0 2625 if (!action) {
Chris@0 2626 std::cerr << "WARNING: MainWindow::openRecentFile: sender is not an action"
Chris@0 2627 << std::endl;
Chris@0 2628 return;
Chris@0 2629 }
Chris@0 2630
Chris@0 2631 QString path = action->text();
Chris@0 2632 if (path == "") return;
Chris@0 2633
Chris@86 2634 QUrl url(path);
Chris@86 2635 if (RemoteFile::canHandleScheme(url)) {
Chris@86 2636 openURL(url);
Chris@86 2637 return;
Chris@86 2638 }
Chris@86 2639
Chris@0 2640 if (path.endsWith("sv")) {
Chris@0 2641
Chris@103 2642 if (!checkSaveModified()) return;
Chris@0 2643
Chris@82 2644 if (openSessionFile(path) == FileOpenFailed) {
Chris@0 2645 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 2646 tr("Session file \"%1\" could not be opened").arg(path));
Chris@0 2647 }
Chris@0 2648
Chris@0 2649 } else {
Chris@0 2650
Chris@82 2651 if (openAudioFile(path, AskUser) == FileOpenFailed) {
Chris@0 2652
Chris@0 2653 bool canImportLayer = (getMainModel() != 0 &&
Chris@0 2654 m_paneStack != 0 &&
Chris@0 2655 m_paneStack->getCurrentPane() != 0);
Chris@0 2656
Chris@82 2657 if (!canImportLayer || (openLayerFile(path) == FileOpenFailed)) {
Chris@0 2658
Chris@0 2659 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 2660 tr("File \"%1\" could not be opened").arg(path));
Chris@0 2661 }
Chris@0 2662 }
Chris@0 2663 }
Chris@0 2664 }
Chris@0 2665
Chris@82 2666 MainWindow::FileOpenStatus
Chris@85 2667 MainWindow::openURL(QUrl url)
Chris@85 2668 {
Chris@85 2669 if (url.scheme().toLower() == "file") {
Chris@85 2670 return openSomeFile(url.toLocalFile());
Chris@86 2671 } else if (!RemoteFile::canHandleScheme(url)) {
Chris@85 2672 QMessageBox::critical(this, tr("Unsupported scheme in URL"),
Chris@85 2673 tr("The URL scheme \"%1\" is not supported")
Chris@85 2674 .arg(url.scheme()));
Chris@85 2675 return FileOpenFailed;
Chris@85 2676 } else {
Chris@85 2677 RemoteFile rf(url);
Chris@85 2678 rf.wait();
Chris@85 2679 if (!rf.isOK()) {
Chris@85 2680 QMessageBox::critical(this, tr("File download failed"),
Chris@85 2681 tr("Failed to download URL \"%1\": %2")
Chris@85 2682 .arg(url.toString()).arg(rf.getErrorString()));
Chris@85 2683 return FileOpenFailed;
Chris@85 2684 }
Chris@88 2685 FileOpenStatus status;
Chris@88 2686 if ((status = openSomeFile(rf.getLocalFilename(), url.toString())) !=
Chris@88 2687 FileOpenSucceeded) {
Chris@88 2688 rf.deleteLocalFile();
Chris@88 2689 }
Chris@88 2690 return status;
Chris@85 2691 }
Chris@85 2692 }
Chris@85 2693
Chris@85 2694 MainWindow::FileOpenStatus
Chris@54 2695 MainWindow::openSomeFile(QString path, AudioFileOpenMode mode)
Chris@0 2696 {
Chris@86 2697 return openSomeFile(path, path, mode);
Chris@86 2698 }
Chris@86 2699
Chris@86 2700 MainWindow::FileOpenStatus
Chris@86 2701 MainWindow::openSomeFile(QString path, QString location,
Chris@86 2702 AudioFileOpenMode mode)
Chris@86 2703 {
Chris@82 2704 FileOpenStatus status;
Chris@82 2705
Chris@85 2706 bool canImportLayer = (getMainModel() != 0 &&
Chris@85 2707 m_paneStack != 0 &&
Chris@85 2708 m_paneStack->getCurrentPane() != 0);
Chris@85 2709
Chris@86 2710 if ((status = openAudioFile(path, location, mode)) != FileOpenFailed) {
Chris@82 2711 return status;
Chris@86 2712 } else if ((status = openSessionFile(path, location)) != FileOpenFailed) {
Chris@82 2713 return status;
Chris@85 2714 } else if (!canImportLayer) {
Chris@85 2715 return FileOpenFailed;
Chris@86 2716 } else if ((status = openLayerFile(path, location)) != FileOpenFailed) {
Chris@85 2717 return status;
Chris@0 2718 } else {
Chris@82 2719 return FileOpenFailed;
Chris@0 2720 }
Chris@0 2721 }
Chris@0 2722
Chris@82 2723 MainWindow::FileOpenStatus
Chris@0 2724 MainWindow::openSessionFile(QString path)
Chris@0 2725 {
Chris@86 2726 return openSessionFile(path, path);
Chris@86 2727 }
Chris@86 2728
Chris@86 2729 MainWindow::FileOpenStatus
Chris@86 2730 MainWindow::openSessionFile(QString path, QString location)
Chris@86 2731 {
Chris@0 2732 BZipFileDevice bzFile(path);
Chris@0 2733 if (!bzFile.open(QIODevice::ReadOnly)) {
Chris@86 2734 std::cerr << "Failed to open session file \"" << location.toStdString()
Chris@0 2735 << "\": " << bzFile.errorString().toStdString() << std::endl;
Chris@82 2736 return FileOpenFailed;
Chris@0 2737 }
Chris@0 2738
Chris@103 2739 if (!checkSaveModified()) return FileOpenCancelled;
Chris@103 2740
Chris@0 2741 QString error;
Chris@0 2742 closeSession();
Chris@0 2743 createDocument();
Chris@0 2744
Chris@0 2745 PaneCallback callback(this);
Chris@0 2746 m_viewManager->clearSelections();
Chris@0 2747
Chris@87 2748 SVFileReader reader(m_document, callback, location);
Chris@0 2749 QXmlInputSource inputSource(&bzFile);
Chris@0 2750 reader.parse(inputSource);
Chris@0 2751
Chris@0 2752 if (!reader.isOK()) {
Chris@0 2753 error = tr("SV XML file read error:\n%1").arg(reader.getErrorString());
Chris@0 2754 }
Chris@0 2755
Chris@0 2756 bzFile.close();
Chris@0 2757
Chris@0 2758 bool ok = (error == "");
Chris@86 2759
Chris@86 2760 bool realFile = (location == path);
Chris@0 2761
Chris@0 2762 if (ok) {
Chris@86 2763
Chris@0 2764 setWindowTitle(tr("Sonic Visualiser: %1")
Chris@86 2765 .arg(QFileInfo(location).fileName()));
Chris@86 2766
Chris@86 2767 if (realFile) m_sessionFile = path;
Chris@86 2768
Chris@0 2769 setupMenus();
Chris@0 2770 CommandHistory::getInstance()->clear();
Chris@0 2771 CommandHistory::getInstance()->documentSaved();
Chris@0 2772 m_documentModified = false;
Chris@0 2773 updateMenuStates();
Chris@86 2774
Chris@86 2775 m_recentFiles.addFile(location);
Chris@86 2776
Chris@86 2777 if (realFile) {
Chris@88 2778 registerLastOpenedFilePath(FileFinder::SessionFile, path); // for file dialog
Chris@86 2779 }
Chris@86 2780
Chris@0 2781 } else {
Chris@0 2782 setWindowTitle(tr("Sonic Visualiser"));
Chris@0 2783 }
Chris@0 2784
Chris@82 2785 return ok ? FileOpenSucceeded : FileOpenFailed;
Chris@0 2786 }
Chris@0 2787
Chris@0 2788 void
Chris@0 2789 MainWindow::closeEvent(QCloseEvent *e)
Chris@0 2790 {
Chris@118 2791 std::cerr << "MainWindow::closeEvent" << std::endl;
Chris@118 2792
Chris@70 2793 if (!m_abandoning && !checkSaveModified()) {
Chris@118 2794 std::cerr << "Ignoring close event" << std::endl;
Chris@0 2795 e->ignore();
Chris@0 2796 return;
Chris@0 2797 }
Chris@0 2798
Chris@5 2799 QSettings settings;
Chris@5 2800 settings.beginGroup("MainWindow");
Chris@5 2801 settings.setValue("size", size());
Chris@5 2802 settings.setValue("position", pos());
Chris@5 2803 settings.endGroup();
Chris@5 2804
Chris@0 2805 e->accept();
Chris@0 2806 return;
Chris@0 2807 }
Chris@0 2808
Chris@0 2809 bool
Chris@11 2810 MainWindow::commitData(bool mayAskUser)
Chris@11 2811 {
Chris@11 2812 if (mayAskUser) {
Chris@11 2813 return checkSaveModified();
Chris@11 2814 } else {
Chris@11 2815 if (!m_documentModified) return true;
Chris@11 2816
Chris@11 2817 // If we can't check with the user first, then we can't save
Chris@11 2818 // to the original session file (even if we have it) -- have
Chris@11 2819 // to use a temporary file
Chris@11 2820
Chris@11 2821 QString svDirBase = ".sv1";
Chris@11 2822 QString svDir = QDir::home().filePath(svDirBase);
Chris@11 2823
Chris@11 2824 if (!QFileInfo(svDir).exists()) {
Chris@11 2825 if (!QDir::home().mkdir(svDirBase)) return false;
Chris@11 2826 } else {
Chris@11 2827 if (!QFileInfo(svDir).isDir()) return false;
Chris@11 2828 }
Chris@11 2829
Chris@11 2830 // This name doesn't have to be unguessable
Chris@93 2831 #ifndef _WIN32
Chris@11 2832 QString fname = QString("tmp-%1-%2.sv")
Chris@11 2833 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"))
Chris@11 2834 .arg(QProcess().pid());
Chris@93 2835 #else
Chris@93 2836 QString fname = QString("tmp-%1.sv")
Chris@93 2837 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"));
Chris@93 2838 #endif
Chris@11 2839 QString fpath = QDir(svDir).filePath(fname);
Chris@11 2840 if (saveSessionFile(fpath)) {
Chris@34 2841 m_recentFiles.addFile(fpath);
Chris@11 2842 return true;
Chris@11 2843 } else {
Chris@11 2844 return false;
Chris@11 2845 }
Chris@11 2846 }
Chris@11 2847 }
Chris@11 2848
Chris@11 2849 bool
Chris@0 2850 MainWindow::checkSaveModified()
Chris@0 2851 {
Chris@0 2852 // Called before some destructive operation (e.g. new session,
Chris@0 2853 // exit program). Return true if we can safely proceed, false to
Chris@0 2854 // cancel.
Chris@0 2855
Chris@0 2856 if (!m_documentModified) return true;
Chris@0 2857
Chris@0 2858 int button =
Chris@0 2859 QMessageBox::warning(this,
Chris@0 2860 tr("Session modified"),
Chris@0 2861 tr("The current session has been modified.\nDo you want to save it?"),
Chris@0 2862 QMessageBox::Yes,
Chris@0 2863 QMessageBox::No,
Chris@0 2864 QMessageBox::Cancel);
Chris@0 2865
Chris@0 2866 if (button == QMessageBox::Yes) {
Chris@0 2867 saveSession();
Chris@0 2868 if (m_documentModified) { // save failed -- don't proceed!
Chris@0 2869 return false;
Chris@0 2870 } else {
Chris@0 2871 return true; // saved, so it's safe to continue now
Chris@0 2872 }
Chris@0 2873 } else if (button == QMessageBox::No) {
Chris@0 2874 m_documentModified = false; // so we know to abandon it
Chris@0 2875 return true;
Chris@0 2876 }
Chris@0 2877
Chris@0 2878 // else cancel
Chris@0 2879 return false;
Chris@0 2880 }
Chris@0 2881
Chris@0 2882 void
Chris@0 2883 MainWindow::saveSession()
Chris@0 2884 {
Chris@0 2885 if (m_sessionFile != "") {
Chris@0 2886 if (!saveSessionFile(m_sessionFile)) {
Chris@0 2887 QMessageBox::critical(this, tr("Failed to save file"),
Chris@0 2888 tr("Session file \"%1\" could not be saved.").arg(m_sessionFile));
Chris@0 2889 } else {
Chris@0 2890 CommandHistory::getInstance()->documentSaved();
Chris@0 2891 documentRestored();
Chris@0 2892 }
Chris@0 2893 } else {
Chris@0 2894 saveSessionAs();
Chris@0 2895 }
Chris@0 2896 }
Chris@0 2897
Chris@0 2898 void
Chris@0 2899 MainWindow::saveSessionAs()
Chris@0 2900 {
Chris@0 2901 QString orig = m_audioFile;
Chris@0 2902 if (orig == "") orig = ".";
Chris@0 2903 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 2904
Chris@88 2905 QString path = getSaveFileName(FileFinder::SessionFile);
Chris@81 2906
Chris@81 2907 if (path == "") return;
Chris@0 2908
Chris@0 2909 if (!saveSessionFile(path)) {
Chris@0 2910 QMessageBox::critical(this, tr("Failed to save file"),
Chris@79 2911 tr("Session file \"%1\" could not be saved.").arg(path));
Chris@0 2912 } else {
Chris@0 2913 setWindowTitle(tr("Sonic Visualiser: %1")
Chris@0 2914 .arg(QFileInfo(path).fileName()));
Chris@0 2915 m_sessionFile = path;
Chris@0 2916 CommandHistory::getInstance()->documentSaved();
Chris@0 2917 documentRestored();
Chris@34 2918 m_recentFiles.addFile(path);
Chris@0 2919 }
Chris@0 2920 }
Chris@0 2921
Chris@0 2922 bool
Chris@0 2923 MainWindow::saveSessionFile(QString path)
Chris@0 2924 {
Chris@0 2925 BZipFileDevice bzFile(path);
Chris@0 2926 if (!bzFile.open(QIODevice::WriteOnly)) {
Chris@0 2927 std::cerr << "Failed to open session file \"" << path.toStdString()
Chris@0 2928 << "\" for writing: "
Chris@0 2929 << bzFile.errorString().toStdString() << std::endl;
Chris@0 2930 return false;
Chris@0 2931 }
Chris@0 2932
Chris@0 2933 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
Chris@0 2934
Chris@0 2935 QTextStream out(&bzFile);
Chris@0 2936 toXml(out);
Chris@0 2937 out.flush();
Chris@0 2938
Chris@0 2939 QApplication::restoreOverrideCursor();
Chris@0 2940
Chris@84 2941 if (!bzFile.isOK()) {
Chris@0 2942 QMessageBox::critical(this, tr("Failed to write file"),
Chris@0 2943 tr("Failed to write to file \"%1\": %2")
Chris@0 2944 .arg(path).arg(bzFile.errorString()));
Chris@0 2945 bzFile.close();
Chris@0 2946 return false;
Chris@0 2947 }
Chris@0 2948
Chris@0 2949 bzFile.close();
Chris@0 2950 return true;
Chris@0 2951 }
Chris@0 2952
Chris@0 2953 void
Chris@0 2954 MainWindow::toXml(QTextStream &out)
Chris@0 2955 {
Chris@0 2956 QString indent(" ");
Chris@0 2957
Chris@0 2958 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
Chris@0 2959 out << "<!DOCTYPE sonic-visualiser>\n";
Chris@0 2960 out << "<sv>\n";
Chris@0 2961
Chris@0 2962 m_document->toXml(out, "", "");
Chris@0 2963
Chris@0 2964 out << "<display>\n";
Chris@0 2965
Chris@0 2966 out << QString(" <window width=\"%1\" height=\"%2\"/>\n")
Chris@0 2967 .arg(width()).arg(height());
Chris@0 2968
Chris@0 2969 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@0 2970
Chris@0 2971 Pane *pane = m_paneStack->getPane(i);
Chris@0 2972
Chris@0 2973 if (pane) {
Chris@0 2974 pane->toXml(out, indent);
Chris@0 2975 }
Chris@0 2976 }
Chris@0 2977
Chris@0 2978 out << "</display>\n";
Chris@0 2979
Chris@0 2980 m_viewManager->getSelection().toXml(out);
Chris@0 2981
Chris@0 2982 out << "</sv>\n";
Chris@0 2983 }
Chris@0 2984
Chris@0 2985 Pane *
Chris@0 2986 MainWindow::addPaneToStack()
Chris@0 2987 {
Chris@0 2988 AddPaneCommand *command = new AddPaneCommand(this);
Chris@0 2989 CommandHistory::getInstance()->addCommand(command);
Chris@0 2990 return command->getPane();
Chris@0 2991 }
Chris@0 2992
Chris@0 2993 void
Chris@0 2994 MainWindow::zoomIn()
Chris@0 2995 {
Chris@0 2996 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 2997 if (currentPane) currentPane->zoom(true);
Chris@0 2998 }
Chris@0 2999
Chris@0 3000 void
Chris@0 3001 MainWindow::zoomOut()
Chris@0 3002 {
Chris@0 3003 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 3004 if (currentPane) currentPane->zoom(false);
Chris@0 3005 }
Chris@0 3006
Chris@0 3007 void
Chris@0 3008 MainWindow::zoomToFit()
Chris@0 3009 {
Chris@0 3010 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 3011 if (!currentPane) return;
Chris@0 3012
Chris@0 3013 Model *model = getMainModel();
Chris@0 3014 if (!model) return;
Chris@0 3015
Chris@0 3016 size_t start = model->getStartFrame();
Chris@0 3017 size_t end = model->getEndFrame();
Chris@0 3018 size_t pixels = currentPane->width();
Chris@0 3019 size_t zoomLevel = (end - start) / pixels;
Chris@0 3020
Chris@0 3021 currentPane->setZoomLevel(zoomLevel);
Chris@0 3022 currentPane->setStartFrame(start);
Chris@0 3023 }
Chris@0 3024
Chris@0 3025 void
Chris@0 3026 MainWindow::zoomDefault()
Chris@0 3027 {
Chris@0 3028 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 3029 if (currentPane) currentPane->setZoomLevel(1024);
Chris@0 3030 }
Chris@0 3031
Chris@0 3032 void
Chris@0 3033 MainWindow::scrollLeft()
Chris@0 3034 {
Chris@0 3035 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 3036 if (currentPane) currentPane->scroll(false, false);
Chris@0 3037 }
Chris@0 3038
Chris@0 3039 void
Chris@0 3040 MainWindow::jumpLeft()
Chris@0 3041 {
Chris@0 3042 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 3043 if (currentPane) currentPane->scroll(false, true);
Chris@0 3044 }
Chris@0 3045
Chris@0 3046 void
Chris@0 3047 MainWindow::scrollRight()
Chris@0 3048 {
Chris@0 3049 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 3050 if (currentPane) currentPane->scroll(true, false);
Chris@0 3051 }
Chris@0 3052
Chris@0 3053 void
Chris@0 3054 MainWindow::jumpRight()
Chris@0 3055 {
Chris@0 3056 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 3057 if (currentPane) currentPane->scroll(true, true);
Chris@0 3058 }
Chris@0 3059
Chris@0 3060 void
Chris@0 3061 MainWindow::showNoOverlays()
Chris@0 3062 {
Chris@0 3063 m_viewManager->setOverlayMode(ViewManager::NoOverlays);
Chris@0 3064 }
Chris@0 3065
Chris@0 3066 void
Chris@90 3067 MainWindow::showMinimalOverlays()
Chris@0 3068 {
Chris@90 3069 m_viewManager->setOverlayMode(ViewManager::MinimalOverlays);
Chris@0 3070 }
Chris@0 3071
Chris@0 3072 void
Chris@90 3073 MainWindow::showStandardOverlays()
Chris@90 3074 {
Chris@90 3075 m_viewManager->setOverlayMode(ViewManager::StandardOverlays);
Chris@90 3076 }
Chris@90 3077
Chris@90 3078 void
Chris@90 3079 MainWindow::showAllOverlays()
Chris@0 3080 {
Chris@0 3081 m_viewManager->setOverlayMode(ViewManager::AllOverlays);
Chris@0 3082 }
Chris@0 3083
Chris@0 3084 void
Chris@7 3085 MainWindow::toggleZoomWheels()
Chris@7 3086 {
Chris@7 3087 if (m_viewManager->getZoomWheelsEnabled()) {
Chris@7 3088 m_viewManager->setZoomWheelsEnabled(false);
Chris@7 3089 } else {
Chris@7 3090 m_viewManager->setZoomWheelsEnabled(true);
Chris@7 3091 }
Chris@7 3092 }
Chris@7 3093
Chris@7 3094 void
Chris@72 3095 MainWindow::togglePropertyBoxes()
Chris@72 3096 {
Chris@72 3097 if (m_paneStack->getLayoutStyle() == PaneStack::NoPropertyStacks) {
Chris@72 3098 if (Preferences::getInstance()->getPropertyBoxLayout() ==
Chris@72 3099 Preferences::VerticallyStacked) {
Chris@72 3100 m_paneStack->setLayoutStyle(PaneStack::PropertyStackPerPaneLayout);
Chris@72 3101 } else {
Chris@72 3102 m_paneStack->setLayoutStyle(PaneStack::SinglePropertyStackLayout);
Chris@72 3103 }
Chris@72 3104 } else {
Chris@72 3105 m_paneStack->setLayoutStyle(PaneStack::NoPropertyStacks);
Chris@72 3106 }
Chris@72 3107 }
Chris@72 3108
Chris@72 3109 void
Chris@90 3110 MainWindow::toggleStatusBar()
Chris@90 3111 {
Chris@90 3112 QSettings settings;
Chris@90 3113 settings.beginGroup("MainWindow");
Chris@90 3114 bool sb = settings.value("showstatusbar", true).toBool();
Chris@90 3115
Chris@90 3116 if (sb) {
Chris@90 3117 statusBar()->hide();
Chris@90 3118 } else {
Chris@90 3119 statusBar()->show();
Chris@90 3120 }
Chris@90 3121
Chris@90 3122 settings.setValue("showstatusbar", !sb);
Chris@90 3123
Chris@90 3124 settings.endGroup();
Chris@90 3125 }
Chris@90 3126
Chris@90 3127 void
Chris@72 3128 MainWindow::preferenceChanged(PropertyContainer::PropertyName name)
Chris@72 3129 {
Chris@72 3130 if (name == "Property Box Layout") {
Chris@72 3131 if (m_paneStack->getLayoutStyle() != PaneStack::NoPropertyStacks) {
Chris@72 3132 if (Preferences::getInstance()->getPropertyBoxLayout() ==
Chris@72 3133 Preferences::VerticallyStacked) {
Chris@72 3134 m_paneStack->setLayoutStyle(PaneStack::PropertyStackPerPaneLayout);
Chris@72 3135 } else {
Chris@72 3136 m_paneStack->setLayoutStyle(PaneStack::SinglePropertyStackLayout);
Chris@72 3137 }
Chris@72 3138 }
Chris@72 3139 }
Chris@72 3140 }
Chris@72 3141
Chris@72 3142 void
Chris@0 3143 MainWindow::play()
Chris@0 3144 {
Chris@0 3145 if (m_playSource->isPlaying()) {
Chris@116 3146 stop();
Chris@0 3147 } else {
Chris@116 3148 playbackFrameChanged(m_viewManager->getPlaybackFrame());
Chris@0 3149 m_playSource->play(m_viewManager->getPlaybackFrame());
Chris@0 3150 }
Chris@0 3151 }
Chris@0 3152
Chris@0 3153 void
Chris@0 3154 MainWindow::ffwd()
Chris@0 3155 {
Chris@0 3156 if (!getMainModel()) return;
Chris@0 3157
Chris@0 3158 int frame = m_viewManager->getPlaybackFrame();
Chris@0 3159 ++frame;
Chris@0 3160
Chris@0 3161 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 3162 if (!pane) return;
Chris@0 3163
Chris@0 3164 Layer *layer = pane->getSelectedLayer();
Chris@0 3165
Chris@0 3166 if (!dynamic_cast<TimeInstantLayer *>(layer) &&
Chris@0 3167 !dynamic_cast<TimeValueLayer *>(layer)) return;
Chris@0 3168
Chris@0 3169 size_t resolution = 0;
Chris@0 3170 if (!layer->snapToFeatureFrame(pane, frame, resolution, Layer::SnapRight)) {
Chris@0 3171 frame = getMainModel()->getEndFrame();
Chris@0 3172 }
Chris@0 3173
Chris@0 3174 m_viewManager->setPlaybackFrame(frame);
Chris@0 3175 }
Chris@0 3176
Chris@0 3177 void
Chris@0 3178 MainWindow::ffwdEnd()
Chris@0 3179 {
Chris@0 3180 if (!getMainModel()) return;
Chris@0 3181 m_viewManager->setPlaybackFrame(getMainModel()->getEndFrame());
Chris@0 3182 }
Chris@0 3183
Chris@0 3184 void
Chris@0 3185 MainWindow::rewind()
Chris@0 3186 {
Chris@0 3187 if (!getMainModel()) return;
Chris@0 3188
Chris@0 3189 int frame = m_viewManager->getPlaybackFrame();
Chris@0 3190 if (frame > 0) --frame;
Chris@0 3191
Chris@0 3192 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 3193 if (!pane) return;
Chris@0 3194
Chris@0 3195 Layer *layer = pane->getSelectedLayer();
Chris@0 3196
Chris@0 3197 if (!dynamic_cast<TimeInstantLayer *>(layer) &&
Chris@0 3198 !dynamic_cast<TimeValueLayer *>(layer)) return;
Chris@0 3199
Chris@0 3200 size_t resolution = 0;
Chris@0 3201 if (!layer->snapToFeatureFrame(pane, frame, resolution, Layer::SnapLeft)) {
Chris@0 3202 frame = getMainModel()->getEndFrame();
Chris@0 3203 }
Chris@0 3204
Chris@0 3205 m_viewManager->setPlaybackFrame(frame);
Chris@0 3206 }
Chris@0 3207
Chris@0 3208 void
Chris@0 3209 MainWindow::rewindStart()
Chris@0 3210 {
Chris@0 3211 if (!getMainModel()) return;
Chris@0 3212 m_viewManager->setPlaybackFrame(getMainModel()->getStartFrame());
Chris@0 3213 }
Chris@0 3214
Chris@0 3215 void
Chris@0 3216 MainWindow::stop()
Chris@0 3217 {
Chris@0 3218 m_playSource->stop();
Chris@116 3219
Chris@116 3220 if (m_paneStack && m_paneStack->getCurrentPane()) {
Chris@116 3221 updateVisibleRangeDisplay(m_paneStack->getCurrentPane());
Chris@116 3222 } else {
Chris@116 3223 m_myStatusMessage = "";
Chris@116 3224 statusBar()->showMessage("");
Chris@116 3225 }
Chris@0 3226 }
Chris@0 3227
Chris@0 3228 void
Chris@0 3229 MainWindow::addPane()
Chris@0 3230 {
Chris@0 3231 QObject *s = sender();
Chris@0 3232 QAction *action = dynamic_cast<QAction *>(s);
Chris@0 3233
Chris@0 3234 if (!action) {
Chris@0 3235 std::cerr << "WARNING: MainWindow::addPane: sender is not an action"
Chris@0 3236 << std::endl;
Chris@0 3237 return;
Chris@0 3238 }
Chris@0 3239
Chris@0 3240 PaneActionMap::iterator i = m_paneActions.find(action);
Chris@0 3241
Chris@0 3242 if (i == m_paneActions.end()) {
Chris@0 3243 std::cerr << "WARNING: MainWindow::addPane: unknown action "
Chris@0 3244 << action->objectName().toStdString() << std::endl;
Chris@0 3245 return;
Chris@0 3246 }
Chris@0 3247
Chris@69 3248 addPane(i->second, action->text());
Chris@69 3249 }
Chris@69 3250
Chris@69 3251 void
Chris@69 3252 MainWindow::addPane(const PaneConfiguration &configuration, QString text)
Chris@69 3253 {
Chris@69 3254 CommandHistory::getInstance()->startCompoundOperation(text, true);
Chris@0 3255
Chris@0 3256 AddPaneCommand *command = new AddPaneCommand(this);
Chris@0 3257 CommandHistory::getInstance()->addCommand(command);
Chris@0 3258
Chris@0 3259 Pane *pane = command->getPane();
Chris@0 3260
Chris@69 3261 if (configuration.layer == LayerFactory::Spectrum) {
Chris@109 3262 pane->setPlaybackFollow(PlaybackScrollContinuous);
Chris@110 3263 pane->setFollowGlobalZoom(false);
Chris@112 3264 pane->setZoomLevel(512);
Chris@7 3265 }
Chris@7 3266
Chris@69 3267 if (configuration.layer != LayerFactory::TimeRuler &&
Chris@69 3268 configuration.layer != LayerFactory::Spectrum) {
Chris@8 3269
Chris@0 3270 if (!m_timeRulerLayer) {
Chris@0 3271 // std::cerr << "no time ruler layer, creating one" << std::endl;
Chris@0 3272 m_timeRulerLayer = m_document->createMainModelLayer
Chris@0 3273 (LayerFactory::TimeRuler);
Chris@0 3274 }
Chris@0 3275
Chris@0 3276 // std::cerr << "adding time ruler layer " << m_timeRulerLayer << std::endl;
Chris@0 3277
Chris@0 3278 m_document->addLayerToView(pane, m_timeRulerLayer);
Chris@0 3279 }
Chris@0 3280
Chris@69 3281 Layer *newLayer = m_document->createLayer(configuration.layer);
Chris@69 3282
Chris@69 3283 Model *suggestedModel = configuration.sourceModel;
Chris@66 3284 Model *model = 0;
Chris@66 3285
Chris@66 3286 if (suggestedModel) {
Chris@66 3287
Chris@66 3288 // check its validity
Chris@66 3289 std::vector<Model *> inputModels = m_document->getTransformInputModels();
Chris@66 3290 for (size_t j = 0; j < inputModels.size(); ++j) {
Chris@66 3291 if (inputModels[j] == suggestedModel) {
Chris@66 3292 model = suggestedModel;
Chris@66 3293 break;
Chris@66 3294 }
Chris@66 3295 }
Chris@66 3296
Chris@66 3297 if (!model) {
Chris@66 3298 std::cerr << "WARNING: Model " << (void *)suggestedModel
Chris@66 3299 << " appears in pane action map, but is not reported "
Chris@66 3300 << "by document as a valid transform source" << std::endl;
Chris@66 3301 }
Chris@66 3302 }
Chris@66 3303
Chris@66 3304 if (!model) model = m_document->getMainModel();
Chris@66 3305
Chris@66 3306 m_document->setModel(newLayer, model);
Chris@66 3307
Chris@69 3308 m_document->setChannel(newLayer, configuration.channel);
Chris@0 3309 m_document->addLayerToView(pane, newLayer);
Chris@0 3310
Chris@0 3311 m_paneStack->setCurrentPane(pane);
Chris@70 3312 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 3313
Chris@73 3314 std::cerr << "MainWindow::addPane: global centre frame is "
Chris@73 3315 << m_viewManager->getGlobalCentreFrame() << std::endl;
Chris@73 3316 pane->setCentreFrame(m_viewManager->getGlobalCentreFrame());
Chris@73 3317
Chris@0 3318 CommandHistory::getInstance()->endCompoundOperation();
Chris@0 3319
Chris@0 3320 updateMenuStates();
Chris@0 3321 }
Chris@0 3322
Chris@0 3323 MainWindow::AddPaneCommand::AddPaneCommand(MainWindow *mw) :
Chris@0 3324 m_mw(mw),
Chris@0 3325 m_pane(0),
Chris@0 3326 m_prevCurrentPane(0),
Chris@0 3327 m_added(false)
Chris@0 3328 {
Chris@0 3329 }
Chris@0 3330
Chris@0 3331 MainWindow::AddPaneCommand::~AddPaneCommand()
Chris@0 3332 {
Chris@0 3333 if (m_pane && !m_added) {
Chris@0 3334 m_mw->m_paneStack->deletePane(m_pane);
Chris@0 3335 }
Chris@0 3336 }
Chris@0 3337
Chris@0 3338 QString
Chris@0 3339 MainWindow::AddPaneCommand::getName() const
Chris@0 3340 {
Chris@0 3341 return tr("Add Pane");
Chris@0 3342 }
Chris@0 3343
Chris@0 3344 void
Chris@0 3345 MainWindow::AddPaneCommand::execute()
Chris@0 3346 {
Chris@0 3347 if (!m_pane) {
Chris@0 3348 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
Chris@0 3349 m_pane = m_mw->m_paneStack->addPane();
Chris@90 3350
Chris@90 3351 connect(m_pane, SIGNAL(contextHelpChanged(const QString &)),
Chris@116 3352 m_mw, SLOT(contextHelpChanged(const QString &)));
Chris@0 3353 } else {
Chris@0 3354 m_mw->m_paneStack->showPane(m_pane);
Chris@0 3355 }
Chris@0 3356
Chris@0 3357 m_mw->m_paneStack->setCurrentPane(m_pane);
Chris@65 3358 m_mw->m_overview->registerView(m_pane);
Chris@0 3359 m_added = true;
Chris@0 3360 }
Chris@0 3361
Chris@0 3362 void
Chris@0 3363 MainWindow::AddPaneCommand::unexecute()
Chris@0 3364 {
Chris@0 3365 m_mw->m_paneStack->hidePane(m_pane);
Chris@0 3366 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
Chris@65 3367 m_mw->m_overview->unregisterView(m_pane);
Chris@0 3368 m_added = false;
Chris@0 3369 }
Chris@0 3370
Chris@0 3371 MainWindow::RemovePaneCommand::RemovePaneCommand(MainWindow *mw, Pane *pane) :
Chris@0 3372 m_mw(mw),
Chris@0 3373 m_pane(pane),
Chris@0 3374 m_added(true)
Chris@0 3375 {
Chris@0 3376 }
Chris@0 3377
Chris@0 3378 MainWindow::RemovePaneCommand::~RemovePaneCommand()
Chris@0 3379 {
Chris@0 3380 if (m_pane && !m_added) {
Chris@0 3381 m_mw->m_paneStack->deletePane(m_pane);
Chris@0 3382 }
Chris@0 3383 }
Chris@0 3384
Chris@0 3385 QString
Chris@0 3386 MainWindow::RemovePaneCommand::getName() const
Chris@0 3387 {
Chris@0 3388 return tr("Remove Pane");
Chris@0 3389 }
Chris@0 3390
Chris@0 3391 void
Chris@0 3392 MainWindow::RemovePaneCommand::execute()
Chris@0 3393 {
Chris@0 3394 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
Chris@0 3395 m_mw->m_paneStack->hidePane(m_pane);
Chris@65 3396 m_mw->m_overview->unregisterView(m_pane);
Chris@0 3397 m_added = false;
Chris@0 3398 }
Chris@0 3399
Chris@0 3400 void
Chris@0 3401 MainWindow::RemovePaneCommand::unexecute()
Chris@0 3402 {
Chris@0 3403 m_mw->m_paneStack->showPane(m_pane);
Chris@0 3404 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
Chris@65 3405 m_mw->m_overview->registerView(m_pane);
Chris@0 3406 m_added = true;
Chris@0 3407 }
Chris@0 3408
Chris@0 3409 void
Chris@0 3410 MainWindow::addLayer()
Chris@0 3411 {
Chris@0 3412 QObject *s = sender();
Chris@0 3413 QAction *action = dynamic_cast<QAction *>(s);
Chris@0 3414
Chris@0 3415 if (!action) {
Chris@0 3416 std::cerr << "WARNING: MainWindow::addLayer: sender is not an action"
Chris@0 3417 << std::endl;
Chris@0 3418 return;
Chris@0 3419 }
Chris@0 3420
Chris@0 3421 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 3422
Chris@0 3423 if (!pane) {
Chris@0 3424 std::cerr << "WARNING: MainWindow::addLayer: no current pane" << std::endl;
Chris@0 3425 return;
Chris@0 3426 }
Chris@0 3427
Chris@0 3428 ExistingLayerActionMap::iterator ei = m_existingLayerActions.find(action);
Chris@0 3429
Chris@0 3430 if (ei != m_existingLayerActions.end()) {
Chris@0 3431 Layer *newLayer = ei->second;
Chris@0 3432 m_document->addLayerToView(pane, newLayer);
Chris@0 3433 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 3434 return;
Chris@0 3435 }
Chris@0 3436
Chris@95 3437 ei = m_sliceActions.find(action);
Chris@95 3438
Chris@95 3439 if (ei != m_sliceActions.end()) {
Chris@95 3440 Layer *newLayer = m_document->createLayer(LayerFactory::Slice);
Chris@95 3441 // document->setModel(newLayer, ei->second->getModel());
Chris@95 3442 SliceableLayer *source = dynamic_cast<SliceableLayer *>(ei->second);
Chris@95 3443 SliceLayer *dest = dynamic_cast<SliceLayer *>(newLayer);
Chris@95 3444 if (source && dest) {
Chris@95 3445 dest->setSliceableModel(source->getSliceableModel());
Chris@95 3446 connect(source, SIGNAL(sliceableModelReplaced(const Model *, const Model *)),
Chris@95 3447 dest, SLOT(sliceableModelReplaced(const Model *, const Model *)));
Chris@95 3448 connect(m_document, SIGNAL(modelAboutToBeDeleted(Model *)),
Chris@95 3449 dest, SLOT(modelAboutToBeDeleted(Model *)));
Chris@95 3450 }
Chris@95 3451 m_document->addLayerToView(pane, newLayer);
Chris@95 3452 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@95 3453 return;
Chris@95 3454 }
Chris@95 3455
Chris@34 3456 TransformActionMap::iterator i = m_transformActions.find(action);
Chris@34 3457
Chris@34 3458 if (i == m_transformActions.end()) {
Chris@0 3459
Chris@0 3460 LayerActionMap::iterator i = m_layerActions.find(action);
Chris@0 3461
Chris@0 3462 if (i == m_layerActions.end()) {
Chris@0 3463 std::cerr << "WARNING: MainWindow::addLayer: unknown action "
Chris@0 3464 << action->objectName().toStdString() << std::endl;
Chris@0 3465 return;
Chris@0 3466 }
Chris@0 3467
Chris@0 3468 LayerFactory::LayerType type = i->second;
Chris@0 3469
Chris@0 3470 LayerFactory::LayerTypeSet emptyTypes =
Chris@0 3471 LayerFactory::getInstance()->getValidEmptyLayerTypes();
Chris@0 3472
Chris@0 3473 Layer *newLayer;
Chris@0 3474
Chris@0 3475 if (emptyTypes.find(type) != emptyTypes.end()) {
Chris@0 3476
Chris@0 3477 newLayer = m_document->createEmptyLayer(type);
Chris@0 3478 m_toolActions[ViewManager::DrawMode]->trigger();
Chris@0 3479
Chris@0 3480 } else {
Chris@0 3481
Chris@0 3482 newLayer = m_document->createMainModelLayer(type);
Chris@0 3483 }
Chris@0 3484
Chris@0 3485 m_document->addLayerToView(pane, newLayer);
Chris@0 3486 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 3487
Chris@0 3488 return;
Chris@0 3489 }
Chris@0 3490
Chris@107 3491 TransformId transform = i->second;
Chris@0 3492 TransformFactory *factory = TransformFactory::getInstance();
Chris@0 3493
Chris@0 3494 QString configurationXml;
Chris@0 3495
Chris@0 3496 int channel = -1;
Chris@0 3497 // pick up the default channel from any existing layers on the same pane
Chris@0 3498 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@0 3499 int c = LayerFactory::getInstance()->getChannel(pane->getLayer(j));
Chris@0 3500 if (c != -1) {
Chris@0 3501 channel = c;
Chris@0 3502 break;
Chris@0 3503 }
Chris@0 3504 }
Chris@0 3505
Chris@33 3506 // We always ask for configuration, even if the plugin isn't
Chris@33 3507 // supposed to be configurable, because we need to let the user
Chris@33 3508 // change the execution context (block size etc).
Chris@0 3509
Chris@27 3510 PluginTransform::ExecutionContext context(channel);
Chris@27 3511
Chris@66 3512 std::vector<Model *> candidateInputModels =
Chris@66 3513 m_document->getTransformInputModels();
Chris@53 3514
Chris@54 3515 Model *inputModel = factory->getConfigurationForTransform(transform,
Chris@54 3516 candidateInputModels,
Chris@54 3517 context,
Chris@54 3518 configurationXml,
Chris@54 3519 m_playSource);
Chris@54 3520 if (!inputModel) return;
Chris@54 3521
Chris@54 3522 std::cerr << "Input model is " << inputModel << " \"" << inputModel->objectName().toStdString() << std::endl;
Chris@0 3523
Chris@0 3524 Layer *newLayer = m_document->createDerivedLayer(transform,
Chris@54 3525 inputModel,
Chris@27 3526 context,
Chris@0 3527 configurationXml);
Chris@0 3528
Chris@0 3529 if (newLayer) {
Chris@0 3530 m_document->addLayerToView(pane, newLayer);
Chris@27 3531 m_document->setChannel(newLayer, context.channel);
Chris@34 3532 m_recentTransforms.add(transform);
Chris@70 3533 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 3534 }
Chris@0 3535
Chris@0 3536 updateMenuStates();
Chris@0 3537 }
Chris@0 3538
Chris@0 3539 void
Chris@0 3540 MainWindow::deleteCurrentPane()
Chris@0 3541 {
Chris@0 3542 CommandHistory::getInstance()->startCompoundOperation
Chris@0 3543 (tr("Delete Pane"), true);
Chris@0 3544
Chris@0 3545 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 3546 if (pane) {
Chris@0 3547 while (pane->getLayerCount() > 0) {
Chris@0 3548 Layer *layer = pane->getLayer(0);
Chris@0 3549 if (layer) {
Chris@0 3550 m_document->removeLayerFromView(pane, layer);
Chris@0 3551 } else {
Chris@0 3552 break;
Chris@0 3553 }
Chris@0 3554 }
Chris@0 3555
Chris@0 3556 RemovePaneCommand *command = new RemovePaneCommand(this, pane);
Chris@0 3557 CommandHistory::getInstance()->addCommand(command);
Chris@0 3558 }
Chris@0 3559
Chris@0 3560 CommandHistory::getInstance()->endCompoundOperation();
Chris@0 3561
Chris@0 3562 updateMenuStates();
Chris@0 3563 }
Chris@0 3564
Chris@0 3565 void
Chris@0 3566 MainWindow::deleteCurrentLayer()
Chris@0 3567 {
Chris@0 3568 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 3569 if (pane) {
Chris@0 3570 Layer *layer = pane->getSelectedLayer();
Chris@0 3571 if (layer) {
Chris@0 3572 m_document->removeLayerFromView(pane, layer);
Chris@0 3573 }
Chris@0 3574 }
Chris@0 3575 updateMenuStates();
Chris@0 3576 }
Chris@0 3577
Chris@0 3578 void
Chris@0 3579 MainWindow::renameCurrentLayer()
Chris@0 3580 {
Chris@0 3581 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 3582 if (pane) {
Chris@0 3583 Layer *layer = pane->getSelectedLayer();
Chris@0 3584 if (layer) {
Chris@0 3585 bool ok = false;
Chris@0 3586 QString newName = QInputDialog::getText
Chris@0 3587 (this, tr("Rename Layer"),
Chris@0 3588 tr("New name for this layer:"),
Chris@0 3589 QLineEdit::Normal, layer->objectName(), &ok);
Chris@0 3590 if (ok) {
Chris@0 3591 layer->setObjectName(newName);
Chris@95 3592 setupExistingLayersMenus();
Chris@0 3593 }
Chris@0 3594 }
Chris@0 3595 }
Chris@0 3596 }
Chris@0 3597
Chris@0 3598 void
Chris@59 3599 MainWindow::playSpeedChanged(int position)
Chris@0 3600 {
Chris@59 3601 PlaySpeedRangeMapper mapper(0, 200);
Chris@60 3602
Chris@60 3603 float percent = m_playSpeed->mappedValue();
Chris@60 3604
Chris@60 3605 float factor = mapper.getFactorForValue(percent);
Chris@60 3606
Chris@60 3607 // float factor = mapper.getFactorForPosition(position);
Chris@60 3608 // float percent = mapper.getValueForPosition(position);
Chris@60 3609
Chris@60 3610 std::cerr << "speed = " << position << " percent = " << percent << " factor = " << factor << std::endl;
Chris@60 3611
Chris@60 3612 //!!! bool slow = (position < 100);
Chris@59 3613 bool something = (position != 100);
Chris@60 3614 /*!!!
Chris@59 3615 int pc = lrintf(percent);
Chris@21 3616
Chris@21 3617 m_playSpeed->setToolTip(tr("Playback speed: %1%2%")
Chris@60 3618 .arg(!slow ? "+" : "")
Chris@21 3619 .arg(pc));
Chris@60 3620 */
Chris@25 3621 m_playSharpen->setEnabled(something);
Chris@26 3622 m_playMono->setEnabled(something);
Chris@25 3623 bool sharpen = (something && m_playSharpen->isChecked());
Chris@26 3624 bool mono = (something && m_playMono->isChecked());
Chris@26 3625 m_playSource->setTimeStretch(factor, sharpen, mono);
Chris@16 3626 }
Chris@16 3627
Chris@16 3628 void
Chris@16 3629 MainWindow::playSharpenToggled()
Chris@16 3630 {
Chris@21 3631 QSettings settings;
Chris@21 3632 settings.beginGroup("MainWindow");
Chris@21 3633 settings.setValue("playsharpen", m_playSharpen->isChecked());
Chris@21 3634 settings.endGroup();
Chris@21 3635
Chris@16 3636 playSpeedChanged(m_playSpeed->value());
Chris@0 3637 }
Chris@0 3638
Chris@0 3639 void
Chris@26 3640 MainWindow::playMonoToggled()
Chris@26 3641 {
Chris@26 3642 QSettings settings;
Chris@26 3643 settings.beginGroup("MainWindow");
Chris@26 3644 settings.setValue("playmono", m_playMono->isChecked());
Chris@26 3645 settings.endGroup();
Chris@26 3646
Chris@26 3647 playSpeedChanged(m_playSpeed->value());
Chris@26 3648 }
Chris@26 3649
Chris@26 3650 void
Chris@116 3651 MainWindow::playbackFrameChanged(unsigned long frame)
Chris@116 3652 {
Chris@116 3653 if (!(m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
Chris@116 3654
Chris@116 3655 RealTime now = RealTime::frame2RealTime
Chris@116 3656 (frame, getMainModel()->getSampleRate());
Chris@116 3657
Chris@116 3658 if (now.sec == m_lastPlayStatusSec) return;
Chris@116 3659
Chris@116 3660 RealTime then = RealTime::frame2RealTime
Chris@116 3661 (m_playSource->getPlayEndFrame(), getMainModel()->getSampleRate());
Chris@116 3662
Chris@116 3663 QString nowStr;
Chris@116 3664 QString thenStr;
Chris@116 3665 QString remainingStr;
Chris@116 3666
Chris@116 3667 if (then.sec > 10) {
Chris@116 3668 nowStr = now.toSecText().c_str();
Chris@116 3669 thenStr = then.toSecText().c_str();
Chris@116 3670 remainingStr = (then - now).toSecText().c_str();
Chris@116 3671 m_lastPlayStatusSec = now.sec;
Chris@116 3672 } else {
Chris@116 3673 nowStr = now.toText(true).c_str();
Chris@116 3674 thenStr = then.toText(true).c_str();
Chris@116 3675 remainingStr = (then - now).toText(true).c_str();
Chris@116 3676 }
Chris@116 3677
Chris@116 3678 m_myStatusMessage = tr("Playing: %1 of %2 (%3 remaining)")
Chris@116 3679 .arg(nowStr).arg(thenStr).arg(remainingStr);
Chris@116 3680
Chris@116 3681 statusBar()->showMessage(m_myStatusMessage);
Chris@116 3682 }
Chris@116 3683
Chris@116 3684 void
Chris@116 3685 MainWindow::globalCentreFrameChanged(unsigned long frame)
Chris@116 3686 {
Chris@116 3687 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
Chris@116 3688 Pane *p = 0;
Chris@116 3689 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
Chris@116 3690 if (!p->getFollowGlobalPan()) return;
Chris@116 3691 updateVisibleRangeDisplay(p);
Chris@116 3692 }
Chris@116 3693
Chris@116 3694 void
Chris@116 3695 MainWindow::viewCentreFrameChanged(View *v, unsigned long frame)
Chris@116 3696 {
Chris@116 3697 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
Chris@116 3698 Pane *p = 0;
Chris@116 3699 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
Chris@116 3700 if (v == p) updateVisibleRangeDisplay(p);
Chris@116 3701 }
Chris@116 3702
Chris@116 3703 void
Chris@116 3704 MainWindow::viewZoomLevelChanged(View *v, unsigned long zoom, bool locked)
Chris@116 3705 {
Chris@116 3706 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
Chris@116 3707 Pane *p = 0;
Chris@116 3708 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
Chris@116 3709 if (v == p) updateVisibleRangeDisplay(p);
Chris@116 3710 }
Chris@116 3711
Chris@116 3712 void
Chris@116 3713 MainWindow::updateVisibleRangeDisplay(Pane *p) const
Chris@116 3714 {
Chris@116 3715 if (!getMainModel() || !p) {
Chris@116 3716 return;
Chris@116 3717 }
Chris@116 3718
Chris@117 3719 bool haveSelection = false;
Chris@117 3720 size_t startFrame = 0, endFrame = 0;
Chris@117 3721
Chris@117 3722 if (m_viewManager && m_viewManager->haveInProgressSelection()) {
Chris@117 3723
Chris@117 3724 bool exclusive = false;
Chris@117 3725 Selection s = m_viewManager->getInProgressSelection(exclusive);
Chris@117 3726
Chris@117 3727 if (!s.isEmpty()) {
Chris@117 3728 haveSelection = true;
Chris@117 3729 startFrame = s.getStartFrame();
Chris@117 3730 endFrame = s.getEndFrame();
Chris@117 3731 }
Chris@117 3732 }
Chris@117 3733
Chris@117 3734 if (!haveSelection) {
Chris@117 3735 startFrame = p->getFirstVisibleFrame();
Chris@117 3736 endFrame = p->getLastVisibleFrame();
Chris@117 3737 }
Chris@117 3738
Chris@116 3739 RealTime start = RealTime::frame2RealTime
Chris@117 3740 (startFrame, getMainModel()->getSampleRate());
Chris@116 3741
Chris@116 3742 RealTime end = RealTime::frame2RealTime
Chris@117 3743 (endFrame, getMainModel()->getSampleRate());
Chris@116 3744
Chris@116 3745 RealTime duration = end - start;
Chris@116 3746
Chris@116 3747 QString startStr, endStr, durationStr;
Chris@116 3748 startStr = start.toText(true).c_str();
Chris@116 3749 endStr = end.toText(true).c_str();
Chris@116 3750 durationStr = duration.toText(true).c_str();
Chris@116 3751
Chris@117 3752 if (haveSelection) {
Chris@117 3753 m_myStatusMessage = tr("Selection: %1 to %2 (duration %3)")
Chris@117 3754 .arg(startStr).arg(endStr).arg(durationStr);
Chris@117 3755 } else {
Chris@117 3756 m_myStatusMessage = tr("Visible: %1 to %2 (duration %3)")
Chris@117 3757 .arg(startStr).arg(endStr).arg(durationStr);
Chris@117 3758 }
Chris@116 3759
Chris@116 3760 statusBar()->showMessage(m_myStatusMessage);
Chris@116 3761 }
Chris@116 3762
Chris@116 3763 void
Chris@0 3764 MainWindow::outputLevelsChanged(float left, float right)
Chris@0 3765 {
Chris@0 3766 m_fader->setPeakLeft(left);
Chris@0 3767 m_fader->setPeakRight(right);
Chris@0 3768 }
Chris@0 3769
Chris@0 3770 void
Chris@0 3771 MainWindow::sampleRateMismatch(size_t requested, size_t actual,
Chris@0 3772 bool willResample)
Chris@0 3773 {
Chris@0 3774 if (!willResample) {
Chris@0 3775 //!!! more helpful message needed
Chris@0 3776 QMessageBox::information
Chris@0 3777 (this, tr("Sample rate mismatch"),
Chris@118 3778 tr("The sample rate of this audio file (%1 Hz) does not match\nthe current playback rate (%2 Hz).\n\nThe file will play at the wrong speed and pitch.")
Chris@0 3779 .arg(requested).arg(actual));
Chris@0 3780 }
Chris@0 3781
Chris@0 3782 updateDescriptionLabel();
Chris@0 3783 }
Chris@0 3784
Chris@0 3785 void
Chris@42 3786 MainWindow::audioOverloadPluginDisabled()
Chris@42 3787 {
Chris@42 3788 QMessageBox::information
Chris@42 3789 (this, tr("Audio processing overload"),
Chris@42 3790 tr("Audio effects plugin auditioning has been disabled\ndue to a processing overload."));
Chris@42 3791 }
Chris@42 3792
Chris@42 3793 void
Chris@0 3794 MainWindow::layerAdded(Layer *layer)
Chris@0 3795 {
Chris@0 3796 // std::cerr << "MainWindow::layerAdded(" << layer << ")" << std::endl;
Chris@0 3797 // setupExistingLayersMenu();
Chris@0 3798 updateMenuStates();
Chris@0 3799 }
Chris@0 3800
Chris@0 3801 void
Chris@0 3802 MainWindow::layerRemoved(Layer *layer)
Chris@0 3803 {
Chris@0 3804 // std::cerr << "MainWindow::layerRemoved(" << layer << ")" << std::endl;
Chris@95 3805 setupExistingLayersMenus();
Chris@0 3806 updateMenuStates();
Chris@0 3807 }
Chris@0 3808
Chris@0 3809 void
Chris@0 3810 MainWindow::layerAboutToBeDeleted(Layer *layer)
Chris@0 3811 {
Chris@0 3812 // std::cerr << "MainWindow::layerAboutToBeDeleted(" << layer << ")" << std::endl;
Chris@0 3813 if (layer == m_timeRulerLayer) {
Chris@0 3814 // std::cerr << "(this is the time ruler layer)" << std::endl;
Chris@0 3815 m_timeRulerLayer = 0;
Chris@0 3816 }
Chris@0 3817 }
Chris@0 3818
Chris@0 3819 void
Chris@0 3820 MainWindow::layerInAView(Layer *layer, bool inAView)
Chris@0 3821 {
Chris@0 3822 // std::cerr << "MainWindow::layerInAView(" << layer << "," << inAView << ")" << std::endl;
Chris@0 3823
Chris@0 3824 // Check whether we need to add or remove model from play source
Chris@0 3825 Model *model = layer->getModel();
Chris@0 3826 if (model) {
Chris@0 3827 if (inAView) {
Chris@0 3828 m_playSource->addModel(model);
Chris@0 3829 } else {
Chris@0 3830 bool found = false;
Chris@0 3831 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@0 3832 Pane *pane = m_paneStack->getPane(i);
Chris@0 3833 if (!pane) continue;
Chris@0 3834 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@0 3835 Layer *pl = pane->getLayer(j);
Chris@0 3836 if (pl && pl->getModel() == model) {
Chris@0 3837 found = true;
Chris@0 3838 break;
Chris@0 3839 }
Chris@0 3840 }
Chris@0 3841 if (found) break;
Chris@0 3842 }
Chris@0 3843 if (!found) m_playSource->removeModel(model);
Chris@0 3844 }
Chris@0 3845 }
Chris@0 3846
Chris@95 3847 setupExistingLayersMenus();
Chris@0 3848 updateMenuStates();
Chris@0 3849 }
Chris@0 3850
Chris@0 3851 void
Chris@0 3852 MainWindow::modelAdded(Model *model)
Chris@0 3853 {
Chris@0 3854 // std::cerr << "MainWindow::modelAdded(" << model << ")" << std::endl;
Chris@0 3855 m_playSource->addModel(model);
Chris@66 3856 if (dynamic_cast<DenseTimeValueModel *>(model)) {
Chris@66 3857 setupPaneAndLayerMenus();
Chris@66 3858 }
Chris@0 3859 }
Chris@0 3860
Chris@0 3861 void
Chris@0 3862 MainWindow::mainModelChanged(WaveFileModel *model)
Chris@0 3863 {
Chris@0 3864 // std::cerr << "MainWindow::mainModelChanged(" << model << ")" << std::endl;
Chris@0 3865 updateDescriptionLabel();
Chris@0 3866 m_panLayer->setModel(model);
Chris@0 3867 if (model) m_viewManager->setMainModelSampleRate(model->getSampleRate());
Chris@46 3868 if (model && !m_playTarget && m_audioOutput) createPlayTarget();
Chris@0 3869 }
Chris@0 3870
Chris@0 3871 void
Chris@0 3872 MainWindow::modelAboutToBeDeleted(Model *model)
Chris@0 3873 {
Chris@0 3874 // std::cerr << "MainWindow::modelAboutToBeDeleted(" << model << ")" << std::endl;
Chris@0 3875 m_playSource->removeModel(model);
Chris@91 3876 FFTDataServer::modelAboutToBeDeleted(model);
Chris@0 3877 }
Chris@0 3878
Chris@0 3879 void
Chris@0 3880 MainWindow::modelGenerationFailed(QString transformName)
Chris@0 3881 {
Chris@0 3882 QMessageBox::warning
Chris@0 3883 (this,
Chris@0 3884 tr("Failed to generate layer"),
Chris@34 3885 tr("Failed to generate a derived layer.\n\nThe layer transform \"%1\" failed.\n\nThis probably means that a plugin failed to initialise, perhaps because it\nrejected the processing block size that was requested.")
Chris@0 3886 .arg(transformName),
Chris@0 3887 QMessageBox::Ok, 0);
Chris@0 3888 }
Chris@0 3889
Chris@0 3890 void
Chris@0 3891 MainWindow::modelRegenerationFailed(QString layerName, QString transformName)
Chris@0 3892 {
Chris@0 3893 QMessageBox::warning
Chris@0 3894 (this,
Chris@0 3895 tr("Failed to regenerate layer"),
Chris@34 3896 tr("Failed to regenerate derived layer \"%1\".\n\nThe layer transform \"%2\" failed to run.\n\nThis probably means the layer used a plugin that is not currently available.")
Chris@0 3897 .arg(layerName).arg(transformName),
Chris@0 3898 QMessageBox::Ok, 0);
Chris@0 3899 }
Chris@0 3900
Chris@0 3901 void
Chris@0 3902 MainWindow::rightButtonMenuRequested(Pane *pane, QPoint position)
Chris@0 3903 {
Chris@0 3904 // std::cerr << "MainWindow::rightButtonMenuRequested(" << pane << ", " << position.x() << ", " << position.y() << ")" << std::endl;
Chris@0 3905 m_paneStack->setCurrentPane(pane);
Chris@0 3906 m_rightButtonMenu->popup(position);
Chris@0 3907 }
Chris@0 3908
Chris@0 3909 void
Chris@73 3910 MainWindow::propertyStacksResized()
Chris@73 3911 {
Chris@73 3912 /*
Chris@73 3913 std::cerr << "MainWindow::propertyStacksResized" << std::endl;
Chris@73 3914 Pane *pane = m_paneStack->getCurrentPane();
Chris@73 3915 if (pane && m_overview) {
Chris@73 3916 std::cerr << "Fixed width: " << pane->width() << std::endl;
Chris@73 3917 m_overview->setFixedWidth(pane->width());
Chris@73 3918 }
Chris@73 3919 */
Chris@73 3920 }
Chris@73 3921
Chris@73 3922 void
Chris@0 3923 MainWindow::showLayerTree()
Chris@0 3924 {
Chris@0 3925 QTreeView *view = new QTreeView();
Chris@0 3926 LayerTreeModel *tree = new LayerTreeModel(m_paneStack);
Chris@0 3927 view->expand(tree->index(0, 0, QModelIndex()));
Chris@0 3928 view->setModel(tree);
Chris@0 3929 view->show();
Chris@0 3930 }
Chris@0 3931
Chris@0 3932 void
Chris@69 3933 MainWindow::pollOSC()
Chris@69 3934 {
Chris@70 3935 if (!m_oscQueue || m_oscQueue->isEmpty()) return;
Chris@69 3936 std::cerr << "MainWindow::pollOSC: have " << m_oscQueue->getMessagesAvailable() << " messages" << std::endl;
Chris@69 3937
Chris@70 3938 if (m_openingAudioFile) return;
Chris@70 3939
Chris@69 3940 OSCMessage message = m_oscQueue->readMessage();
Chris@69 3941
Chris@69 3942 if (message.getTarget() != 0) {
Chris@69 3943 return; //!!! for now -- this class is target 0, others not handled yet
Chris@69 3944 }
Chris@69 3945
Chris@69 3946 handleOSCMessage(message);
Chris@69 3947 }
Chris@69 3948
Chris@69 3949 void
Chris@69 3950 MainWindow::handleOSCMessage(const OSCMessage &message)
Chris@69 3951 {
Chris@70 3952 std::cerr << "MainWindow::handleOSCMessage: thread id = "
Chris@70 3953 << QThread::currentThreadId() << std::endl;
Chris@70 3954
Chris@69 3955 // This large function should really be abstracted out.
Chris@69 3956
Chris@69 3957 if (message.getMethod() == "open") {
Chris@69 3958
Chris@69 3959 if (message.getArgCount() == 1 &&
Chris@69 3960 message.getArg(0).canConvert(QVariant::String)) {
Chris@69 3961 QString path = message.getArg(0).toString();
Chris@82 3962 if (openSomeFile(path, ReplaceMainModel) != FileOpenSucceeded) {
Chris@69 3963 std::cerr << "MainWindow::handleOSCMessage: File open failed for path \""
Chris@69 3964 << path.toStdString() << "\"" << std::endl;
Chris@69 3965 }
Chris@69 3966 //!!! we really need to spin here and not return until the
Chris@69 3967 // file has been completely decoded...
Chris@69 3968 }
Chris@69 3969
Chris@69 3970 } else if (message.getMethod() == "openadditional") {
Chris@69 3971
Chris@69 3972 if (message.getArgCount() == 1 &&
Chris@69 3973 message.getArg(0).canConvert(QVariant::String)) {
Chris@69 3974 QString path = message.getArg(0).toString();
Chris@82 3975 if (openSomeFile(path, CreateAdditionalModel) != FileOpenSucceeded) {
Chris@69 3976 std::cerr << "MainWindow::handleOSCMessage: File open failed for path \""
Chris@69 3977 << path.toStdString() << "\"" << std::endl;
Chris@69 3978 }
Chris@69 3979 }
Chris@69 3980
Chris@69 3981 } else if (message.getMethod() == "recent" ||
Chris@69 3982 message.getMethod() == "last") {
Chris@69 3983
Chris@69 3984 int n = 0;
Chris@69 3985 if (message.getMethod() == "recent" &&
Chris@69 3986 message.getArgCount() == 1 &&
Chris@69 3987 message.getArg(0).canConvert(QVariant::Int)) {
Chris@69 3988 n = message.getArg(0).toInt() - 1;
Chris@69 3989 }
Chris@69 3990 std::vector<QString> recent = m_recentFiles.getRecent();
Chris@69 3991 if (n >= 0 && n < recent.size()) {
Chris@82 3992 if (openSomeFile(recent[n], ReplaceMainModel) != FileOpenSucceeded) {
Chris@69 3993 std::cerr << "MainWindow::handleOSCMessage: File open failed for path \""
Chris@69 3994 << recent[n].toStdString() << "\"" << std::endl;
Chris@69 3995 }
Chris@69 3996 }
Chris@69 3997
Chris@69 3998 } else if (message.getMethod() == "save") {
Chris@69 3999
Chris@69 4000 QString path;
Chris@69 4001 if (message.getArgCount() == 1 &&
Chris@69 4002 message.getArg(0).canConvert(QVariant::String)) {
Chris@69 4003 path = message.getArg(0).toString();
Chris@69 4004 if (QFileInfo(path).exists()) {
Chris@69 4005 std::cerr << "MainWindow::handleOSCMessage: Refusing to overwrite existing file in save" << std::endl;
Chris@69 4006 } else {
Chris@69 4007 saveSessionFile(path);
Chris@69 4008 }
Chris@69 4009 }
Chris@69 4010
Chris@69 4011 } else if (message.getMethod() == "export") {
Chris@69 4012
Chris@69 4013 QString path;
Chris@69 4014 if (getMainModel()) {
Chris@69 4015 if (message.getArgCount() == 1 &&
Chris@69 4016 message.getArg(0).canConvert(QVariant::String)) {
Chris@69 4017 path = message.getArg(0).toString();
Chris@69 4018 if (QFileInfo(path).exists()) {
Chris@69 4019 std::cerr << "MainWindow::handleOSCMessage: Refusing to overwrite existing file in export" << std::endl;
Chris@69 4020 } else {
Chris@69 4021 WavFileWriter writer(path,
Chris@69 4022 getMainModel()->getSampleRate(),
Chris@69 4023 getMainModel()->getChannelCount());
Chris@69 4024 MultiSelection ms = m_viewManager->getSelection();
Chris@69 4025 if (!ms.getSelections().empty()) {
Chris@69 4026 writer.writeModel(getMainModel(), &ms);
Chris@69 4027 } else {
Chris@69 4028 writer.writeModel(getMainModel());
Chris@69 4029 }
Chris@69 4030 }
Chris@69 4031 }
Chris@69 4032 }
Chris@69 4033
Chris@69 4034 } else if (message.getMethod() == "jump" ||
Chris@69 4035 message.getMethod() == "play") {
Chris@69 4036
Chris@69 4037 if (getMainModel()) {
Chris@69 4038
Chris@69 4039 unsigned long frame = m_viewManager->getPlaybackFrame();
Chris@69 4040 bool selection = false;
Chris@69 4041 bool play = (message.getMethod() == "play");
Chris@69 4042
Chris@69 4043 if (message.getArgCount() == 1) {
Chris@69 4044
Chris@69 4045 if (message.getArg(0).canConvert(QVariant::String) &&
Chris@69 4046 message.getArg(0).toString() == "selection") {
Chris@69 4047
Chris@69 4048 selection = true;
Chris@69 4049
Chris@69 4050 } else if (message.getArg(0).canConvert(QVariant::String) &&
Chris@69 4051 message.getArg(0).toString() == "end") {
Chris@69 4052
Chris@69 4053 frame = getMainModel()->getEndFrame();
Chris@69 4054
Chris@69 4055 } else if (message.getArg(0).canConvert(QVariant::Double)) {
Chris@69 4056
Chris@69 4057 double time = message.getArg(0).toDouble();
Chris@69 4058 if (time < 0.0) time = 0.0;
Chris@69 4059
Chris@69 4060 frame = lrint(time * getMainModel()->getSampleRate());
Chris@69 4061 }
Chris@69 4062 }
Chris@69 4063
Chris@69 4064 if (frame > getMainModel()->getEndFrame()) {
Chris@69 4065 frame = getMainModel()->getEndFrame();
Chris@69 4066 }
Chris@69 4067
Chris@69 4068 if (play) {
Chris@69 4069 m_viewManager->setPlaySelectionMode(selection);
Chris@69 4070 }
Chris@69 4071
Chris@69 4072 if (selection) {
Chris@69 4073 MultiSelection::SelectionList sl = m_viewManager->getSelections();
Chris@69 4074 if (!sl.empty()) {
Chris@69 4075 frame = sl.begin()->getStartFrame();
Chris@69 4076 }
Chris@69 4077 }
Chris@69 4078
Chris@69 4079 m_viewManager->setPlaybackFrame(frame);
Chris@69 4080
Chris@69 4081 if (play && !m_playSource->isPlaying()) {
Chris@69 4082 m_playSource->play(frame);
Chris@69 4083 }
Chris@69 4084 }
Chris@69 4085
Chris@69 4086 } else if (message.getMethod() == "stop") {
Chris@69 4087
Chris@69 4088 if (m_playSource->isPlaying()) m_playSource->stop();
Chris@69 4089
Chris@69 4090 } else if (message.getMethod() == "loop") {
Chris@69 4091
Chris@69 4092 if (message.getArgCount() == 1 &&
Chris@69 4093 message.getArg(0).canConvert(QVariant::String)) {
Chris@69 4094
Chris@69 4095 QString str = message.getArg(0).toString();
Chris@69 4096 if (str == "on") {
Chris@69 4097 m_viewManager->setPlayLoopMode(true);
Chris@69 4098 } else if (str == "off") {
Chris@69 4099 m_viewManager->setPlayLoopMode(false);
Chris@69 4100 }
Chris@69 4101 }
Chris@69 4102
Chris@69 4103 } else if (message.getMethod() == "select" ||
Chris@69 4104 message.getMethod() == "addselect") {
Chris@69 4105
Chris@69 4106 if (getMainModel()) {
Chris@69 4107
Chris@73 4108 int f0 = getMainModel()->getStartFrame();
Chris@73 4109 int f1 = getMainModel()->getEndFrame();
Chris@69 4110
Chris@69 4111 bool done = false;
Chris@69 4112
Chris@69 4113 if (message.getArgCount() == 2 &&
Chris@69 4114 message.getArg(0).canConvert(QVariant::Double) &&
Chris@69 4115 message.getArg(1).canConvert(QVariant::Double)) {
Chris@69 4116
Chris@69 4117 double t0 = message.getArg(0).toDouble();
Chris@69 4118 double t1 = message.getArg(1).toDouble();
Chris@69 4119 if (t1 < t0) { double temp = t0; t0 = t1; t1 = temp; }
Chris@69 4120 if (t0 < 0.0) t0 = 0.0;
Chris@69 4121 if (t1 < 0.0) t1 = 0.0;
Chris@69 4122
Chris@69 4123 f0 = lrint(t0 * getMainModel()->getSampleRate());
Chris@69 4124 f1 = lrint(t1 * getMainModel()->getSampleRate());
Chris@73 4125
Chris@73 4126 Pane *pane = m_paneStack->getCurrentPane();
Chris@73 4127 Layer *layer = 0;
Chris@73 4128 if (pane) layer = pane->getSelectedLayer();
Chris@73 4129 if (layer) {
Chris@73 4130 size_t resolution;
Chris@73 4131 layer->snapToFeatureFrame(pane, f0, resolution,
Chris@73 4132 Layer::SnapLeft);
Chris@73 4133 layer->snapToFeatureFrame(pane, f1, resolution,
Chris@73 4134 Layer::SnapRight);
Chris@73 4135 }
Chris@69 4136
Chris@69 4137 } else if (message.getArgCount() == 1 &&
Chris@69 4138 message.getArg(0).canConvert(QVariant::String)) {
Chris@69 4139
Chris@69 4140 QString str = message.getArg(0).toString();
Chris@69 4141 if (str == "none") {
Chris@69 4142 m_viewManager->clearSelections();
Chris@69 4143 done = true;
Chris@69 4144 }
Chris@69 4145 }
Chris@69 4146
Chris@69 4147 if (!done) {
Chris@69 4148 if (message.getMethod() == "select") {
Chris@69 4149 m_viewManager->setSelection(Selection(f0, f1));
Chris@69 4150 } else {
Chris@69 4151 m_viewManager->addSelection(Selection(f0, f1));
Chris@69 4152 }
Chris@69 4153 }
Chris@69 4154 }
Chris@69 4155
Chris@69 4156 } else if (message.getMethod() == "add") {
Chris@69 4157
Chris@69 4158 if (getMainModel()) {
Chris@69 4159
Chris@69 4160 if (message.getArgCount() >= 1 &&
Chris@69 4161 message.getArg(0).canConvert(QVariant::String)) {
Chris@69 4162
Chris@69 4163 int channel = -1;
Chris@69 4164 if (message.getArgCount() == 2 &&
Chris@69 4165 message.getArg(0).canConvert(QVariant::Int)) {
Chris@69 4166 channel = message.getArg(0).toInt();
Chris@69 4167 if (channel < -1 ||
Chris@69 4168 channel > getMainModel()->getChannelCount()) {
Chris@69 4169 std::cerr << "WARNING: MainWindow::handleOSCMessage: channel "
Chris@69 4170 << channel << " out of range" << std::endl;
Chris@69 4171 channel = -1;
Chris@69 4172 }
Chris@69 4173 }
Chris@69 4174
Chris@69 4175 QString str = message.getArg(0).toString();
Chris@69 4176
Chris@69 4177 LayerFactory::LayerType type =
Chris@69 4178 LayerFactory::getInstance()->getLayerTypeForName(str);
Chris@69 4179
Chris@69 4180 if (type == LayerFactory::UnknownLayer) {
Chris@69 4181 std::cerr << "WARNING: MainWindow::handleOSCMessage: unknown layer "
Chris@69 4182 << "type " << str.toStdString() << std::endl;
Chris@69 4183 } else {
Chris@69 4184
Chris@69 4185 PaneConfiguration configuration(type,
Chris@69 4186 getMainModel(),
Chris@69 4187 channel);
Chris@69 4188
Chris@69 4189 addPane(configuration,
Chris@69 4190 tr("Add %1 Pane")
Chris@69 4191 .arg(LayerFactory::getInstance()->
Chris@69 4192 getLayerPresentationName(type)));
Chris@69 4193 }
Chris@69 4194 }
Chris@69 4195 }
Chris@69 4196
Chris@69 4197 } else if (message.getMethod() == "undo") {
Chris@69 4198
Chris@69 4199 CommandHistory::getInstance()->undo();
Chris@69 4200
Chris@69 4201 } else if (message.getMethod() == "redo") {
Chris@69 4202
Chris@69 4203 CommandHistory::getInstance()->redo();
Chris@69 4204
Chris@69 4205 } else if (message.getMethod() == "set") {
Chris@69 4206
Chris@70 4207 if (message.getArgCount() == 2 &&
Chris@69 4208 message.getArg(0).canConvert(QVariant::String) &&
Chris@69 4209 message.getArg(1).canConvert(QVariant::Double)) {
Chris@69 4210
Chris@69 4211 QString property = message.getArg(0).toString();
Chris@69 4212 float value = (float)message.getArg(1).toDouble();
Chris@69 4213
Chris@69 4214 if (property == "gain") {
Chris@69 4215 if (value < 0.0) value = 0.0;
Chris@69 4216 m_fader->setValue(value);
Chris@69 4217 if (m_playTarget) m_playTarget->setOutputGain(value);
Chris@69 4218 } else if (property == "speedup") {
Chris@69 4219 m_playSpeed->setMappedValue(value);
Chris@69 4220 } else if (property == "overlays") {
Chris@69 4221 if (value < 0.5) {
Chris@69 4222 m_viewManager->setOverlayMode(ViewManager::NoOverlays);
Chris@69 4223 } else if (value < 1.5) {
Chris@90 4224 m_viewManager->setOverlayMode(ViewManager::MinimalOverlays);
Chris@90 4225 } else if (value < 2.5) {
Chris@90 4226 m_viewManager->setOverlayMode(ViewManager::StandardOverlays);
Chris@69 4227 } else {
Chris@69 4228 m_viewManager->setOverlayMode(ViewManager::AllOverlays);
Chris@69 4229 }
Chris@70 4230 } else if (property == "zoomwheels") {
Chris@70 4231 m_viewManager->setZoomWheelsEnabled(value > 0.5);
Chris@72 4232 } else if (property == "propertyboxes") {
Chris@72 4233 bool toggle = ((value < 0.5) !=
Chris@72 4234 (m_paneStack->getLayoutStyle() == PaneStack::NoPropertyStacks));
Chris@72 4235 if (toggle) togglePropertyBoxes();
Chris@70 4236 }
Chris@70 4237
Chris@70 4238 } else {
Chris@70 4239 PropertyContainer *container = 0;
Chris@70 4240 Pane *pane = m_paneStack->getCurrentPane();
Chris@70 4241 if (pane &&
Chris@70 4242 message.getArgCount() == 3 &&
Chris@70 4243 message.getArg(0).canConvert(QVariant::String) &&
Chris@70 4244 message.getArg(1).canConvert(QVariant::String) &&
Chris@70 4245 message.getArg(2).canConvert(QVariant::String)) {
Chris@70 4246 if (message.getArg(0).toString() == "pane") {
Chris@70 4247 container = pane->getPropertyContainer(0);
Chris@70 4248 } else if (message.getArg(0).toString() == "layer") {
Chris@70 4249 container = pane->getSelectedLayer();
Chris@70 4250 }
Chris@70 4251 }
Chris@70 4252 if (container) {
Chris@70 4253 QString nameString = message.getArg(1).toString();
Chris@70 4254 QString valueString = message.getArg(2).toString();
Chris@70 4255 container->setPropertyWithCommand(nameString, valueString);
Chris@69 4256 }
Chris@69 4257 }
Chris@69 4258
Chris@69 4259 } else if (message.getMethod() == "setcurrent") {
Chris@69 4260
Chris@69 4261 int paneIndex = -1, layerIndex = -1;
Chris@69 4262 bool wantLayer = false;
Chris@69 4263
Chris@69 4264 if (message.getArgCount() >= 1 &&
Chris@69 4265 message.getArg(0).canConvert(QVariant::Int)) {
Chris@69 4266
Chris@69 4267 paneIndex = message.getArg(0).toInt() - 1;
Chris@69 4268
Chris@69 4269 if (message.getArgCount() >= 2 &&
Chris@69 4270 message.getArg(1).canConvert(QVariant::Int)) {
Chris@69 4271 wantLayer = true;
Chris@69 4272 layerIndex = message.getArg(1).toInt() - 1;
Chris@69 4273 }
Chris@69 4274 }
Chris@69 4275
Chris@69 4276 if (paneIndex >= 0 && paneIndex < m_paneStack->getPaneCount()) {
Chris@69 4277 Pane *pane = m_paneStack->getPane(paneIndex);
Chris@70 4278 m_paneStack->setCurrentPane(pane);
Chris@69 4279 if (layerIndex >= 0 && layerIndex < pane->getLayerCount()) {
Chris@69 4280 Layer *layer = pane->getLayer(layerIndex);
Chris@69 4281 m_paneStack->setCurrentLayer(pane, layer);
Chris@69 4282 } else if (wantLayer && layerIndex == -1) {
Chris@69 4283 m_paneStack->setCurrentLayer(pane, 0);
Chris@69 4284 }
Chris@69 4285 }
Chris@69 4286
Chris@69 4287 } else if (message.getMethod() == "delete") {
Chris@69 4288
Chris@69 4289 if (message.getArgCount() == 1 &&
Chris@69 4290 message.getArg(0).canConvert(QVariant::String)) {
Chris@69 4291
Chris@69 4292 QString target = message.getArg(0).toString();
Chris@69 4293
Chris@69 4294 if (target == "pane") {
Chris@69 4295
Chris@69 4296 deleteCurrentPane();
Chris@69 4297
Chris@69 4298 } else if (target == "layer") {
Chris@69 4299
Chris@69 4300 deleteCurrentLayer();
Chris@69 4301
Chris@69 4302 } else {
Chris@69 4303
Chris@69 4304 std::cerr << "WARNING: MainWindow::handleOSCMessage: Unknown delete target " << target.toStdString() << std::endl;
Chris@69 4305 }
Chris@69 4306 }
Chris@69 4307
Chris@69 4308 } else if (message.getMethod() == "zoom") {
Chris@69 4309
Chris@69 4310 if (message.getArgCount() == 1) {
Chris@69 4311 if (message.getArg(0).canConvert(QVariant::String) &&
Chris@69 4312 message.getArg(0).toString() == "in") {
Chris@69 4313 zoomIn();
Chris@69 4314 } else if (message.getArg(0).canConvert(QVariant::String) &&
Chris@69 4315 message.getArg(0).toString() == "out") {
Chris@69 4316 zoomOut();
Chris@69 4317 } else if (message.getArg(0).canConvert(QVariant::String) &&
Chris@69 4318 message.getArg(0).toString() == "default") {
Chris@69 4319 zoomDefault();
Chris@69 4320 } else if (message.getArg(0).canConvert(QVariant::Double)) {
Chris@69 4321 double level = message.getArg(0).toDouble();
Chris@69 4322 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@69 4323 if (level < 1.0) level = 1.0;
Chris@69 4324 if (currentPane) currentPane->setZoomLevel(lrint(level));
Chris@69 4325 }
Chris@69 4326 }
Chris@69 4327
Chris@73 4328 } else if (message.getMethod() == "zoomvertical") {
Chris@73 4329
Chris@73 4330 Pane *pane = m_paneStack->getCurrentPane();
Chris@73 4331 Layer *layer = 0;
Chris@73 4332 if (pane && pane->getLayerCount() > 0) {
Chris@73 4333 layer = pane->getLayer(pane->getLayerCount() - 1);
Chris@73 4334 }
Chris@73 4335 int defaultStep = 0;
Chris@73 4336 int steps = 0;
Chris@73 4337 if (layer) {
Chris@73 4338 steps = layer->getVerticalZoomSteps(defaultStep);
Chris@73 4339 if (message.getArgCount() == 1 && steps > 0) {
Chris@73 4340 if (message.getArg(0).canConvert(QVariant::String) &&
Chris@73 4341 message.getArg(0).toString() == "in") {
Chris@73 4342 int step = layer->getCurrentVerticalZoomStep() + 1;
Chris@73 4343 if (step < steps) layer->setVerticalZoomStep(step);
Chris@73 4344 } else if (message.getArg(0).canConvert(QVariant::String) &&
Chris@73 4345 message.getArg(0).toString() == "out") {
Chris@73 4346 int step = layer->getCurrentVerticalZoomStep() - 1;
Chris@73 4347 if (step >= 0) layer->setVerticalZoomStep(step);
Chris@73 4348 } else if (message.getArg(0).canConvert(QVariant::String) &&
Chris@73 4349 message.getArg(0).toString() == "default") {
Chris@73 4350 layer->setVerticalZoomStep(defaultStep);
Chris@73 4351 }
Chris@73 4352 } else if (message.getArgCount() == 2) {
Chris@73 4353 if (message.getArg(0).canConvert(QVariant::Double) &&
Chris@73 4354 message.getArg(1).canConvert(QVariant::Double)) {
Chris@73 4355 double min = message.getArg(0).toDouble();
Chris@73 4356 double max = message.getArg(1).toDouble();
Chris@73 4357 layer->setDisplayExtents(min, max);
Chris@73 4358 }
Chris@73 4359 }
Chris@73 4360 }
Chris@73 4361
Chris@70 4362 } else if (message.getMethod() == "quit") {
Chris@70 4363
Chris@70 4364 m_abandoning = true;
Chris@70 4365 close();
Chris@70 4366
Chris@70 4367 } else if (message.getMethod() == "resize") {
Chris@70 4368
Chris@70 4369 if (message.getArgCount() == 2) {
Chris@70 4370
Chris@70 4371 int width = 0, height = 0;
Chris@70 4372
Chris@70 4373 if (message.getArg(1).canConvert(QVariant::Int)) {
Chris@70 4374
Chris@70 4375 height = message.getArg(1).toInt();
Chris@70 4376
Chris@70 4377 if (message.getArg(0).canConvert(QVariant::String) &&
Chris@70 4378 message.getArg(0).toString() == "pane") {
Chris@70 4379
Chris@70 4380 Pane *pane = m_paneStack->getCurrentPane();
Chris@70 4381 if (pane) pane->resize(pane->width(), height);
Chris@70 4382
Chris@70 4383 } else if (message.getArg(0).canConvert(QVariant::Int)) {
Chris@70 4384
Chris@70 4385 width = message.getArg(0).toInt();
Chris@70 4386 resize(width, height);
Chris@70 4387 }
Chris@70 4388 }
Chris@70 4389 }
Chris@70 4390
Chris@70 4391 } else if (message.getMethod() == "transform") {
Chris@70 4392
Chris@70 4393 Pane *pane = m_paneStack->getCurrentPane();
Chris@70 4394
Chris@70 4395 if (getMainModel() &&
Chris@70 4396 pane &&
Chris@70 4397 message.getArgCount() == 1 &&
Chris@70 4398 message.getArg(0).canConvert(QVariant::String)) {
Chris@70 4399
Chris@107 4400 TransformId transform = message.getArg(0).toString();
Chris@70 4401
Chris@70 4402 Layer *newLayer = m_document->createDerivedLayer
Chris@70 4403 (transform,
Chris@70 4404 getMainModel(),
Chris@73 4405 TransformFactory::getInstance()->getDefaultContextForTransform
Chris@73 4406 (transform, getMainModel()),
Chris@70 4407 "");
Chris@70 4408
Chris@70 4409 if (newLayer) {
Chris@70 4410 m_document->addLayerToView(pane, newLayer);
Chris@70 4411 m_recentTransforms.add(transform);
Chris@70 4412 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@70 4413 }
Chris@70 4414 }
Chris@70 4415
Chris@69 4416 } else {
Chris@69 4417 std::cerr << "WARNING: MainWindow::handleOSCMessage: Unknown or unsupported "
Chris@69 4418 << "method \"" << message.getMethod().toStdString()
Chris@69 4419 << "\"" << std::endl;
Chris@69 4420 }
Chris@69 4421
Chris@69 4422 }
Chris@69 4423
Chris@69 4424 void
Chris@0 4425 MainWindow::preferences()
Chris@0 4426 {
Chris@0 4427 if (!m_preferencesDialog.isNull()) {
Chris@0 4428 m_preferencesDialog->show();
Chris@0 4429 m_preferencesDialog->raise();
Chris@0 4430 return;
Chris@0 4431 }
Chris@0 4432
Chris@0 4433 m_preferencesDialog = new PreferencesDialog(this);
Chris@0 4434
Chris@0 4435 // DeleteOnClose is safe here, because m_preferencesDialog is a
Chris@0 4436 // QPointer that will be zeroed when the dialog is deleted. We
Chris@0 4437 // use it in preference to leaving the dialog lying around because
Chris@0 4438 // if you Cancel the dialog, it resets the preferences state
Chris@0 4439 // without resetting its own widgets, so its state will be
Chris@0 4440 // incorrect when next shown unless we construct it afresh
Chris@0 4441 m_preferencesDialog->setAttribute(Qt::WA_DeleteOnClose);
Chris@0 4442
Chris@0 4443 m_preferencesDialog->show();
Chris@0 4444 }
Chris@0 4445
Chris@0 4446 void
Chris@90 4447 MainWindow::mouseEnteredWidget()
Chris@90 4448 {
Chris@90 4449 QWidget *w = dynamic_cast<QWidget *>(sender());
Chris@90 4450 if (!w) return;
Chris@90 4451
Chris@90 4452 if (w == m_fader) {
Chris@116 4453 contextHelpChanged(tr("Adjust the master playback level"));
Chris@90 4454 } else if (w == m_playSpeed) {
Chris@116 4455 contextHelpChanged(tr("Adjust the master playback speed"));
Chris@90 4456 } else if (w == m_playSharpen && w->isEnabled()) {
Chris@116 4457 contextHelpChanged(tr("Toggle transient sharpening for playback time scaling"));
Chris@90 4458 } else if (w == m_playMono && w->isEnabled()) {
Chris@116 4459 contextHelpChanged(tr("Toggle mono mode for playback time scaling"));
Chris@90 4460 }
Chris@90 4461 }
Chris@90 4462
Chris@90 4463 void
Chris@90 4464 MainWindow::mouseLeftWidget()
Chris@90 4465 {
Chris@116 4466 contextHelpChanged("");
Chris@116 4467 }
Chris@116 4468
Chris@116 4469 void
Chris@117 4470 MainWindow::inProgressSelectionChanged()
Chris@117 4471 {
Chris@117 4472 Pane *currentPane = 0;
Chris@117 4473 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
Chris@117 4474 if (currentPane) updateVisibleRangeDisplay(currentPane);
Chris@117 4475 }
Chris@117 4476
Chris@117 4477 void
Chris@116 4478 MainWindow::contextHelpChanged(const QString &s)
Chris@116 4479 {
Chris@116 4480 if (s == "" && m_myStatusMessage != "") {
Chris@116 4481 statusBar()->showMessage(m_myStatusMessage);
Chris@116 4482 return;
Chris@116 4483 }
Chris@116 4484 statusBar()->showMessage(s);
Chris@90 4485 }
Chris@90 4486
Chris@90 4487 void
Chris@0 4488 MainWindow::website()
Chris@0 4489 {
Chris@0 4490 openHelpUrl(tr("http://www.sonicvisualiser.org/"));
Chris@0 4491 }
Chris@0 4492
Chris@0 4493 void
Chris@0 4494 MainWindow::help()
Chris@0 4495 {
Chris@0 4496 openHelpUrl(tr("http://www.sonicvisualiser.org/doc/reference/en/"));
Chris@0 4497 }
Chris@0 4498
Chris@0 4499 void
Chris@0 4500 MainWindow::openHelpUrl(QString url)
Chris@0 4501 {
Chris@0 4502 // This method mostly lifted from Qt Assistant source code
Chris@0 4503
Chris@0 4504 QProcess *process = new QProcess(this);
Chris@0 4505 connect(process, SIGNAL(finished(int)), process, SLOT(deleteLater()));
Chris@0 4506
Chris@0 4507 QStringList args;
Chris@0 4508
Chris@0 4509 #ifdef Q_OS_MAC
Chris@0 4510 args.append(url);
Chris@0 4511 process->start("open", args);
Chris@0 4512 #else
Chris@0 4513 #ifdef Q_OS_WIN32
Chris@0 4514
Chris@0 4515 QString pf(getenv("ProgramFiles"));
Chris@0 4516 QString command = pf + QString("\\Internet Explorer\\IEXPLORE.EXE");
Chris@0 4517
Chris@0 4518 args.append(url);
Chris@0 4519 process->start(command, args);
Chris@0 4520
Chris@0 4521 #else
Chris@0 4522 #ifdef Q_WS_X11
Chris@0 4523 if (!qgetenv("KDE_FULL_SESSION").isEmpty()) {
Chris@0 4524 args.append("exec");
Chris@0 4525 args.append(url);
Chris@0 4526 process->start("kfmclient", args);
Chris@0 4527 } else if (!qgetenv("BROWSER").isEmpty()) {
Chris@0 4528 args.append(url);
Chris@0 4529 process->start(qgetenv("BROWSER"), args);
Chris@0 4530 } else {
Chris@0 4531 args.append(url);
Chris@0 4532 process->start("firefox", args);
Chris@0 4533 }
Chris@0 4534 #endif
Chris@0 4535 #endif
Chris@0 4536 #endif
Chris@0 4537 }
Chris@0 4538
Chris@0 4539 void
Chris@0 4540 MainWindow::about()
Chris@0 4541 {
Chris@0 4542 bool debug = false;
Chris@0 4543 QString version = "(unknown version)";
Chris@0 4544
Chris@0 4545 #ifdef BUILD_DEBUG
Chris@0 4546 debug = true;
Chris@0 4547 #endif
Chris@0 4548 #ifdef SV_VERSION
Chris@0 4549 #ifdef SVNREV
Chris@0 4550 version = tr("Release %1 : Revision %2").arg(SV_VERSION).arg(SVNREV);
Chris@0 4551 #else
Chris@0 4552 version = tr("Release %1").arg(SV_VERSION);
Chris@0 4553 #endif
Chris@0 4554 #else
Chris@0 4555 #ifdef SVNREV
Chris@0 4556 version = tr("Unreleased : Revision %1").arg(SVNREV);
Chris@0 4557 #endif
Chris@0 4558 #endif
Chris@0 4559
Chris@0 4560 QString aboutText;
Chris@0 4561
Chris@0 4562 aboutText += tr("<h3>About Sonic Visualiser</h3>");
Chris@90 4563 aboutText += tr("<p>Sonic Visualiser is a program for viewing and exploring audio data for<br>semantic music analysis and annotation.</p>");
Chris@111 4564 aboutText += tr("<p>%1 : %2 configuration</p>")
Chris@0 4565 .arg(version)
Chris@0 4566 .arg(debug ? tr("Debug") : tr("Release"));
Chris@0 4567
Chris@0 4568 #ifdef BUILD_STATIC
Chris@0 4569 aboutText += tr("<p>Statically linked");
Chris@0 4570 #ifndef QT_SHARED
Chris@0 4571 aboutText += tr("<br>With Qt (v%1) &copy; Trolltech AS").arg(QT_VERSION_STR);
Chris@0 4572 #endif
Chris@0 4573 #ifdef HAVE_JACK
Chris@93 4574 #ifdef JACK_VERSION
Chris@0 4575 aboutText += tr("<br>With JACK audio output (v%1) &copy; Paul Davis and Jack O'Quin").arg(JACK_VERSION);
Chris@93 4576 #else
Chris@93 4577 aboutText += tr("<br>With JACK audio output &copy; Paul Davis and Jack O'Quin");
Chris@93 4578 #endif
Chris@0 4579 #endif
Chris@0 4580 #ifdef HAVE_PORTAUDIO
Chris@0 4581 aboutText += tr("<br>With PortAudio audio output &copy; Ross Bencina and Phil Burk");
Chris@0 4582 #endif
Chris@0 4583 #ifdef HAVE_OGGZ
Chris@93 4584 #ifdef OGGZ_VERSION
Chris@0 4585 aboutText += tr("<br>With Ogg file decoder (oggz v%1, fishsound v%2) &copy; CSIRO Australia").arg(OGGZ_VERSION).arg(FISHSOUND_VERSION);
Chris@93 4586 #else
Chris@93 4587 aboutText += tr("<br>With Ogg file decoder &copy; CSIRO Australia");
Chris@93 4588 #endif
Chris@0 4589 #endif
Chris@0 4590 #ifdef HAVE_MAD
Chris@93 4591 #ifdef MAD_VERSION
Chris@0 4592 aboutText += tr("<br>With MAD mp3 decoder (v%1) &copy; Underbit Technologies Inc").arg(MAD_VERSION);
Chris@93 4593 #else
Chris@93 4594 aboutText += tr("<br>With MAD mp3 decoder &copy; Underbit Technologies Inc");
Chris@93 4595 #endif
Chris@0 4596 #endif
Chris@0 4597 #ifdef HAVE_SAMPLERATE
Chris@93 4598 #ifdef SAMPLERATE_VERSION
Chris@0 4599 aboutText += tr("<br>With libsamplerate (v%1) &copy; Erik de Castro Lopo").arg(SAMPLERATE_VERSION);
Chris@93 4600 #else
Chris@93 4601 aboutText += tr("<br>With libsamplerate &copy; Erik de Castro Lopo");
Chris@93 4602 #endif
Chris@0 4603 #endif
Chris@0 4604 #ifdef HAVE_SNDFILE
Chris@93 4605 #ifdef SNDFILE_VERSION
Chris@0 4606 aboutText += tr("<br>With libsndfile (v%1) &copy; Erik de Castro Lopo").arg(SNDFILE_VERSION);
Chris@93 4607 #else
Chris@93 4608 aboutText += tr("<br>With libsndfile &copy; Erik de Castro Lopo");
Chris@93 4609 #endif
Chris@0 4610 #endif
Chris@0 4611 #ifdef HAVE_FFTW3
Chris@93 4612 #ifdef FFTW3_VERSION
Chris@0 4613 aboutText += tr("<br>With FFTW3 (v%1) &copy; Matteo Frigo and MIT").arg(FFTW3_VERSION);
Chris@93 4614 #else
Chris@93 4615 aboutText += tr("<br>With FFTW3 &copy; Matteo Frigo and MIT");
Chris@93 4616 #endif
Chris@0 4617 #endif
Chris@0 4618 #ifdef HAVE_VAMP
Chris@114 4619 aboutText += tr("<br>With Vamp plugin support (API v%1, host SDK v%2) &copy; Chris Cannam").arg(VAMP_API_VERSION).arg(VAMP_SDK_VERSION);
Chris@0 4620 #endif
Chris@0 4621 aboutText += tr("<br>With LADSPA plugin support (API v%1) &copy; Richard Furse, Paul Davis, Stefan Westerfeld").arg(LADSPA_VERSION);
Chris@0 4622 aboutText += tr("<br>With DSSI plugin support (API v%1) &copy; Chris Cannam, Steve Harris, Sean Bolton").arg(DSSI_VERSION);
Chris@69 4623 #ifdef HAVE_LIBLO
Chris@93 4624 #ifdef LIBLO_VERSION
Chris@69 4625 aboutText += tr("<br>With liblo Lite OSC library (v%1) &copy; Steve Harris").arg(LIBLO_VERSION);
Chris@93 4626 #else
Chris@93 4627 aboutText += tr("<br>With liblo Lite OSC library &copy; Steve Harris").arg(LIBLO_VERSION);
Chris@93 4628 #endif
Chris@70 4629 if (m_oscQueue && m_oscQueue->isOK()) {
Chris@69 4630 aboutText += tr("<p>The OSC URL for this instance is: \"%1\"").arg(m_oscQueue->getOSCURL());
Chris@69 4631 }
Chris@69 4632 #endif
Chris@0 4633 aboutText += "</p>";
Chris@0 4634 #endif
Chris@0 4635
Chris@0 4636 aboutText +=
Chris@90 4637 "<p>Sonic Visualiser Copyright &copy; 2005 - 2007 Chris Cannam and<br>"
Chris@90 4638 "Queen Mary, University of London.</p>"
Chris@0 4639 "<p>This program is free software; you can redistribute it and/or<br>"
Chris@0 4640 "modify it under the terms of the GNU General Public License as<br>"
Chris@0 4641 "published by the Free Software Foundation; either version 2 of the<br>"
Chris@0 4642 "License, or (at your option) any later version.<br>See the file "
Chris@0 4643 "COPYING included with this distribution for more information.</p>";
Chris@0 4644
Chris@0 4645 QMessageBox::about(this, tr("About Sonic Visualiser"), aboutText);
Chris@0 4646 }
Chris@0 4647