annotate main/MainWindow.cpp @ 728:b959148258a4

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