annotate main/MainWindow.cpp @ 1386:05d35ce6ea72 levelpanwidget

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