annotate main/MainWindow.cpp @ 665:17fe7e0c23a1

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