annotate main/MainWindow.cpp @ 951:61703996628d scalable-icons

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