annotate main/MainWindow.cpp @ 1779:b660b2fa8411 streaming-csv-writer

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