annotate main/MainWindow.cpp @ 2314:4fbbf470bb5e

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