annotate main/MainWindow.cpp @ 776:70397c0a78f0

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