annotate main/MainWindow.cpp @ 1782:95248f6b9b1d

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