annotate main/MainWindow.cpp @ 1565:ed8850c991f1

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