annotate main/MainWindow.cpp @ 991:dbc5cec06702 simple-fft-model

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