annotate main/MainWindow.cpp @ 1450:c8b03c666185 3.0-integration

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