annotate main/MainWindow.cpp @ 715:d1c5444be23d tony_integration

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