annotate main/MainWindow.cpp @ 705:44fcce228d02 tony_integration

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