annotate main/MainWindow.cpp @ 1082:b2c45b831ea8 3.0-integration

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