annotate main/MainWindow.cpp @ 703:049a9418cc27

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