annotate main/MainWindow.cpp @ 1079:7e1dbbff314f

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