annotate main/MainWindow.cpp @ 1460:8ca62b402846 3.0-integration

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