annotate main/MainWindow.cpp @ 1986:bb9cf19e0b67 import-audio-data

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