annotate main/MainWindow.cpp @ 1948:c49588dc7c96

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