annotate main/MainWindow.cpp @ 177:5bde373ad5ca

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