annotate main/MainWindow.cpp @ 1047:2aaeb77609cf recording

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