annotate main/MainWindow.cpp @ 2474:266d2fc815f4 audio-source-refactor

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