annotate main/MainWindow.cpp @ 657:1938702bb3bf

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