annotate main/MainWindow.cpp @ 622:2093255c8203

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