annotate main/MainWindow.cpp @ 1630:6b2e781b0154

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