annotate main/MainWindow.cpp @ 1516:47a18e281a93 3.0-integration

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