annotate main/MainWindow.cpp @ 1053:2f8018eb1573 3.0-integration

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