annotate main/MainWindow.cpp @ 2490:588947e96515 sensible-delimited-data-strings

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