annotate main/MainWindow.cpp @ 1062:9918aaf0b790 3.0-integration

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