annotate main/MainWindow.cpp @ 655:b02f4c61d9f0 with-dependencies

Close this branch; the good stuff is now back in default
author Chris Cannam
date Tue, 05 Nov 2013 11:58:03 +0000
parents c0a20cd1a9ff
children 2484381b53a1
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@624 3097 settings.setValue("maximised", isMaximized());
Chris@624 3098 if (!isMaximized()) {
Chris@624 3099 settings.setValue("size", size());
Chris@624 3100 settings.setValue("position", pos());
Chris@624 3101 }
Chris@5 3102 settings.endGroup();
Chris@5 3103
Chris@163 3104 if (m_preferencesDialog &&
Chris@163 3105 m_preferencesDialog->isVisible()) {
Chris@164 3106 closeSession(); // otherwise we'll have to wait for prefs changes
Chris@163 3107 m_preferencesDialog->applicationClosing(false);
Chris@163 3108 }
Chris@163 3109
Chris@200 3110 closeSession();
Chris@200 3111
Chris@0 3112 e->accept();
Chris@489 3113
Chris@0 3114 return;
Chris@0 3115 }
Chris@0 3116
Chris@0 3117 bool
Chris@11 3118 MainWindow::commitData(bool mayAskUser)
Chris@11 3119 {
Chris@11 3120 if (mayAskUser) {
Chris@163 3121 bool rv = checkSaveModified();
Chris@163 3122 if (rv) {
Chris@163 3123 if (m_preferencesDialog &&
Chris@163 3124 m_preferencesDialog->isVisible()) {
Chris@163 3125 m_preferencesDialog->applicationClosing(false);
Chris@163 3126 }
Chris@163 3127 }
Chris@163 3128 return rv;
Chris@11 3129 } else {
Chris@163 3130 if (m_preferencesDialog &&
Chris@163 3131 m_preferencesDialog->isVisible()) {
Chris@163 3132 m_preferencesDialog->applicationClosing(true);
Chris@163 3133 }
Chris@11 3134 if (!m_documentModified) return true;
Chris@11 3135
Chris@11 3136 // If we can't check with the user first, then we can't save
Chris@11 3137 // to the original session file (even if we have it) -- have
Chris@11 3138 // to use a temporary file
Chris@11 3139
Chris@11 3140 QString svDirBase = ".sv1";
Chris@11 3141 QString svDir = QDir::home().filePath(svDirBase);
Chris@11 3142
Chris@11 3143 if (!QFileInfo(svDir).exists()) {
Chris@11 3144 if (!QDir::home().mkdir(svDirBase)) return false;
Chris@11 3145 } else {
Chris@11 3146 if (!QFileInfo(svDir).isDir()) return false;
Chris@11 3147 }
Chris@11 3148
Chris@11 3149 // This name doesn't have to be unguessable
Chris@93 3150 #ifndef _WIN32
Chris@11 3151 QString fname = QString("tmp-%1-%2.sv")
Chris@11 3152 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"))
Chris@11 3153 .arg(QProcess().pid());
Chris@93 3154 #else
Chris@93 3155 QString fname = QString("tmp-%1.sv")
Chris@93 3156 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"));
Chris@93 3157 #endif
Chris@11 3158 QString fpath = QDir(svDir).filePath(fname);
Chris@11 3159 if (saveSessionFile(fpath)) {
Chris@34 3160 m_recentFiles.addFile(fpath);
Chris@310 3161 emit activity(tr("Export image to \"%1\"").arg(fpath));
Chris@11 3162 return true;
Chris@11 3163 } else {
Chris@11 3164 return false;
Chris@11 3165 }
Chris@11 3166 }
Chris@11 3167 }
Chris@11 3168
Chris@11 3169 bool
Chris@0 3170 MainWindow::checkSaveModified()
Chris@0 3171 {
Chris@0 3172 // Called before some destructive operation (e.g. new session,
Chris@0 3173 // exit program). Return true if we can safely proceed, false to
Chris@0 3174 // cancel.
Chris@0 3175
Chris@0 3176 if (!m_documentModified) return true;
Chris@0 3177
Chris@247 3178 emit hideSplash();
Chris@247 3179
Chris@0 3180 int button =
Chris@0 3181 QMessageBox::warning(this,
Chris@0 3182 tr("Session modified"),
Chris@207 3183 tr("<b>Session modified</b><p>The current session has been modified.<br>Do you want to save it?"),
Chris@165 3184 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
Chris@165 3185 QMessageBox::Yes);
Chris@0 3186
Chris@0 3187 if (button == QMessageBox::Yes) {
Chris@0 3188 saveSession();
Chris@0 3189 if (m_documentModified) { // save failed -- don't proceed!
Chris@0 3190 return false;
Chris@0 3191 } else {
Chris@0 3192 return true; // saved, so it's safe to continue now
Chris@0 3193 }
Chris@0 3194 } else if (button == QMessageBox::No) {
Chris@0 3195 m_documentModified = false; // so we know to abandon it
Chris@0 3196 return true;
Chris@0 3197 }
Chris@0 3198
Chris@0 3199 // else cancel
Chris@0 3200 return false;
Chris@0 3201 }
Chris@0 3202
Chris@290 3203 bool
Chris@294 3204 MainWindow::shouldCreateNewSessionForRDFAudio(bool *cancel)
Chris@290 3205 {
Chris@294 3206 //!!! This is very similar to part of MainWindowBase::openAudio --
Chris@294 3207 //!!! make them a bit more uniform
Chris@294 3208
Chris@294 3209 QSettings settings;
Chris@294 3210 settings.beginGroup("MainWindow");
Chris@294 3211 bool prevNewSession = settings.value("newsessionforrdfaudio", true).toBool();
Chris@294 3212 settings.endGroup();
Chris@294 3213 bool newSession = true;
Chris@294 3214
Chris@294 3215 QStringList items;
Chris@294 3216 items << tr("Close the current session and create a new one")
Chris@294 3217 << tr("Add this data to the current session");
Chris@294 3218
Chris@294 3219 bool ok = false;
Chris@294 3220 QString item = ListInputDialog::getItem
Chris@294 3221 (this, tr("Select target for import"),
Chris@294 3222 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 3223 items, prevNewSession ? 0 : 1, &ok);
Chris@294 3224
Chris@294 3225 if (!ok || item.isEmpty()) {
Chris@294 3226 *cancel = true;
Chris@290 3227 return false;
Chris@290 3228 }
Chris@294 3229
Chris@294 3230 newSession = (item == items[0]);
Chris@294 3231 settings.beginGroup("MainWindow");
Chris@294 3232 settings.setValue("newsessionforrdfaudio", newSession);
Chris@294 3233 settings.endGroup();
Chris@294 3234
Chris@294 3235 if (newSession) return true;
Chris@294 3236 else return false;
Chris@290 3237 }
Chris@290 3238
Chris@0 3239 void
Chris@0 3240 MainWindow::saveSession()
Chris@0 3241 {
Chris@0 3242 if (m_sessionFile != "") {
Chris@0 3243 if (!saveSessionFile(m_sessionFile)) {
Chris@0 3244 QMessageBox::critical(this, tr("Failed to save file"),
Chris@193 3245 tr("<b>Save failed</b><p>Session file \"%1\" could not be saved.").arg(m_sessionFile));
Chris@0 3246 } else {
Chris@0 3247 CommandHistory::getInstance()->documentSaved();
Chris@0 3248 documentRestored();
Chris@0 3249 }
Chris@0 3250 } else {
Chris@0 3251 saveSessionAs();
Chris@0 3252 }
Chris@0 3253 }
Chris@0 3254
Chris@0 3255 void
Chris@0 3256 MainWindow::saveSessionAs()
Chris@0 3257 {
Chris@0 3258 QString orig = m_audioFile;
Chris@0 3259 if (orig == "") orig = ".";
Chris@0 3260 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 3261
Chris@88 3262 QString path = getSaveFileName(FileFinder::SessionFile);
Chris@81 3263
Chris@81 3264 if (path == "") return;
Chris@0 3265
Chris@0 3266 if (!saveSessionFile(path)) {
Chris@0 3267 QMessageBox::critical(this, tr("Failed to save file"),
Chris@193 3268 tr("<b>Save failed</b><p>Session file \"%1\" could not be saved.").arg(path));
Chris@0 3269 } else {
Chris@518 3270 setWindowTitle(tr("%1: %1")
Chris@518 3271 .arg(QApplication::applicationName())
Chris@0 3272 .arg(QFileInfo(path).fileName()));
Chris@0 3273 m_sessionFile = path;
Chris@0 3274 CommandHistory::getInstance()->documentSaved();
Chris@0 3275 documentRestored();
Chris@34 3276 m_recentFiles.addFile(path);
Chris@310 3277 emit activity(tr("Save session as \"%1\"").arg(path));
Chris@0 3278 }
Chris@0 3279 }
Chris@0 3280
Chris@90 3281 void
Chris@72 3282 MainWindow::preferenceChanged(PropertyContainer::PropertyName name)
Chris@72 3283 {
Chris@200 3284 MainWindowBase::preferenceChanged(name);
Chris@200 3285
Chris@200 3286 if (name == "Background Mode" && m_viewManager) {
Chris@180 3287 if (m_viewManager->getGlobalDarkBackground()) {
Chris@180 3288 m_panLayer->setBaseColour
Chris@180 3289 (ColourDatabase::getInstance()->getColourIndex(tr("Bright Green")));
Chris@180 3290 } else {
Chris@180 3291 m_panLayer->setBaseColour
Chris@180 3292 (ColourDatabase::getInstance()->getColourIndex(tr("Green")));
Chris@180 3293 }
Chris@200 3294 }
Chris@0 3295 }
Chris@0 3296
Chris@0 3297 void
Chris@239 3298 MainWindow::propertyStacksResized(int width)
Chris@239 3299 {
Chris@438 3300 // SVDEBUG << "MainWindow::propertyStacksResized(" << width << ")" << endl;
Chris@239 3301
Chris@239 3302 if (!m_playControlsSpacer) return;
Chris@239 3303
Chris@239 3304 int spacerWidth = width - m_playControlsWidth - 4;
Chris@239 3305
Chris@438 3306 // SVDEBUG << "resizing spacer from " << m_playControlsSpacer->width() << " to " << spacerWidth << endl;
Chris@239 3307
Chris@239 3308 m_playControlsSpacer->setFixedSize(QSize(spacerWidth, 2));
Chris@239 3309 }
Chris@239 3310
Chris@239 3311 void
Chris@0 3312 MainWindow::addPane()
Chris@0 3313 {
Chris@0 3314 QObject *s = sender();
Chris@0 3315 QAction *action = dynamic_cast<QAction *>(s);
Chris@0 3316
Chris@0 3317 if (!action) {
Chris@0 3318 std::cerr << "WARNING: MainWindow::addPane: sender is not an action"
Chris@0 3319 << std::endl;
Chris@0 3320 return;
Chris@0 3321 }
Chris@0 3322
Chris@0 3323 PaneActionMap::iterator i = m_paneActions.find(action);
Chris@0 3324
Chris@0 3325 if (i == m_paneActions.end()) {
Chris@0 3326 std::cerr << "WARNING: MainWindow::addPane: unknown action "
Chris@432 3327 << action->objectName() << std::endl;
Chris@0 3328 return;
Chris@0 3329 }
Chris@0 3330
Chris@69 3331 addPane(i->second, action->text());
Chris@69 3332 }
Chris@69 3333
Chris@69 3334 void
Chris@232 3335 MainWindow::addPane(const LayerConfiguration &configuration, QString text)
Chris@69 3336 {
Chris@69 3337 CommandHistory::getInstance()->startCompoundOperation(text, true);
Chris@0 3338
Chris@0 3339 AddPaneCommand *command = new AddPaneCommand(this);
Chris@0 3340 CommandHistory::getInstance()->addCommand(command);
Chris@0 3341
Chris@0 3342 Pane *pane = command->getPane();
Chris@0 3343
Chris@69 3344 if (configuration.layer == LayerFactory::Spectrum) {
Chris@109 3345 pane->setPlaybackFollow(PlaybackScrollContinuous);
Chris@110 3346 pane->setFollowGlobalZoom(false);
Chris@112 3347 pane->setZoomLevel(512);
Chris@7 3348 }
Chris@7 3349
Chris@69 3350 if (configuration.layer != LayerFactory::TimeRuler &&
Chris@69 3351 configuration.layer != LayerFactory::Spectrum) {
Chris@8 3352
Chris@0 3353 if (!m_timeRulerLayer) {
Chris@0 3354 // std::cerr << "no time ruler layer, creating one" << std::endl;
Chris@0 3355 m_timeRulerLayer = m_document->createMainModelLayer
Chris@0 3356 (LayerFactory::TimeRuler);
Chris@0 3357 }
Chris@0 3358
Chris@438 3359 // SVDEBUG << "adding time ruler layer " << m_timeRulerLayer << endl;
Chris@0 3360
Chris@0 3361 m_document->addLayerToView(pane, m_timeRulerLayer);
Chris@0 3362 }
Chris@0 3363
Chris@69 3364 Layer *newLayer = m_document->createLayer(configuration.layer);
Chris@69 3365
Chris@69 3366 Model *suggestedModel = configuration.sourceModel;
Chris@66 3367 Model *model = 0;
Chris@66 3368
Chris@66 3369 if (suggestedModel) {
Chris@66 3370
Chris@66 3371 // check its validity
Chris@224 3372 std::vector<Model *> inputModels = m_document->getTransformInputModels();
Chris@66 3373 for (size_t j = 0; j < inputModels.size(); ++j) {
Chris@66 3374 if (inputModels[j] == suggestedModel) {
Chris@66 3375 model = suggestedModel;
Chris@66 3376 break;
Chris@66 3377 }
Chris@66 3378 }
Chris@66 3379
Chris@66 3380 if (!model) {
Chris@66 3381 std::cerr << "WARNING: Model " << (void *)suggestedModel
Chris@66 3382 << " appears in pane action map, but is not reported "
Chris@66 3383 << "by document as a valid transform source" << std::endl;
Chris@66 3384 }
Chris@66 3385 }
Chris@66 3386
Chris@346 3387 if (!model) {
Chris@346 3388 model = m_document->getMainModel();
Chris@346 3389 }
Chris@66 3390
Chris@66 3391 m_document->setModel(newLayer, model);
Chris@66 3392
Chris@69 3393 m_document->setChannel(newLayer, configuration.channel);
Chris@0 3394 m_document->addLayerToView(pane, newLayer);
Chris@0 3395
Chris@0 3396 m_paneStack->setCurrentPane(pane);
Chris@70 3397 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 3398
Chris@438 3399 // SVDEBUG << "MainWindow::addPane: global centre frame is "
Chris@433 3400 // << m_viewManager->getGlobalCentreFrame() << endl;
Chris@130 3401 // pane->setCentreFrame(m_viewManager->getGlobalCentreFrame());
Chris@73 3402
Chris@0 3403 CommandHistory::getInstance()->endCompoundOperation();
Chris@0 3404
Chris@0 3405 updateMenuStates();
Chris@0 3406 }
Chris@0 3407
Chris@0 3408 void
Chris@0 3409 MainWindow::addLayer()
Chris@0 3410 {
Chris@0 3411 QObject *s = sender();
Chris@0 3412 QAction *action = dynamic_cast<QAction *>(s);
Chris@0 3413
Chris@0 3414 if (!action) {
Chris@0 3415 std::cerr << "WARNING: MainWindow::addLayer: sender is not an action"
Chris@0 3416 << std::endl;
Chris@0 3417 return;
Chris@0 3418 }
Chris@0 3419
Chris@0 3420 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 3421
Chris@0 3422 if (!pane) {
Chris@0 3423 std::cerr << "WARNING: MainWindow::addLayer: no current pane" << std::endl;
Chris@0 3424 return;
Chris@0 3425 }
Chris@0 3426
Chris@0 3427 ExistingLayerActionMap::iterator ei = m_existingLayerActions.find(action);
Chris@0 3428
Chris@0 3429 if (ei != m_existingLayerActions.end()) {
Chris@0 3430 Layer *newLayer = ei->second;
Chris@0 3431 m_document->addLayerToView(pane, newLayer);
Chris@0 3432 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 3433 return;
Chris@0 3434 }
Chris@0 3435
Chris@95 3436 ei = m_sliceActions.find(action);
Chris@95 3437
Chris@95 3438 if (ei != m_sliceActions.end()) {
Chris@95 3439 Layer *newLayer = m_document->createLayer(LayerFactory::Slice);
Chris@95 3440 // document->setModel(newLayer, ei->second->getModel());
Chris@95 3441 SliceableLayer *source = dynamic_cast<SliceableLayer *>(ei->second);
Chris@95 3442 SliceLayer *dest = dynamic_cast<SliceLayer *>(newLayer);
Chris@95 3443 if (source && dest) {
Chris@205 3444 //!!!???
Chris@95 3445 dest->setSliceableModel(source->getSliceableModel());
Chris@95 3446 connect(source, SIGNAL(sliceableModelReplaced(const Model *, const Model *)),
Chris@95 3447 dest, SLOT(sliceableModelReplaced(const Model *, const Model *)));
Chris@95 3448 connect(m_document, SIGNAL(modelAboutToBeDeleted(Model *)),
Chris@95 3449 dest, SLOT(modelAboutToBeDeleted(Model *)));
Chris@95 3450 }
Chris@95 3451 m_document->addLayerToView(pane, newLayer);
Chris@95 3452 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@95 3453 return;
Chris@95 3454 }
Chris@95 3455
Chris@211 3456 TransformActionMap::iterator i = m_transformActions.find(action);
Chris@34 3457
Chris@34 3458 if (i == m_transformActions.end()) {
Chris@0 3459
Chris@0 3460 LayerActionMap::iterator i = m_layerActions.find(action);
Chris@0 3461
Chris@0 3462 if (i == m_layerActions.end()) {
Chris@0 3463 std::cerr << "WARNING: MainWindow::addLayer: unknown action "
Chris@432 3464 << action->objectName() << std::endl;
Chris@0 3465 return;
Chris@0 3466 }
Chris@0 3467
Chris@232 3468 LayerFactory::LayerType type = i->second.layer;
Chris@0 3469
Chris@0 3470 LayerFactory::LayerTypeSet emptyTypes =
Chris@0 3471 LayerFactory::getInstance()->getValidEmptyLayerTypes();
Chris@0 3472
Chris@499 3473 Layer *newLayer = 0;
Chris@0 3474
Chris@0 3475 if (emptyTypes.find(type) != emptyTypes.end()) {
Chris@0 3476
Chris@0 3477 newLayer = m_document->createEmptyLayer(type);
Chris@217 3478 if (newLayer) {
Chris@217 3479 m_toolActions[ViewManager::DrawMode]->trigger();
Chris@217 3480 }
Chris@0 3481
Chris@0 3482 } else {
Chris@0 3483
Chris@346 3484 Model *model = i->second.sourceModel;
Chris@346 3485
Chris@415 3486 cerr << "model = "<< model << endl;
Chris@415 3487
Chris@346 3488 if (!model) {
Chris@346 3489 if (type == LayerFactory::TimeRuler) {
Chris@346 3490 newLayer = m_document->createMainModelLayer(type);
Chris@346 3491 } else {
Chris@346 3492 // if model is unspecified and this is not a
Chris@415 3493 // time-ruler layer, use any plausible model from
Chris@415 3494 // the current pane -- this is the case for
Chris@415 3495 // right-button menu layer additions
Chris@415 3496 Pane::ModelSet ms = pane->getModels();
Chris@415 3497 foreach (Model *m, ms) {
Chris@415 3498 RangeSummarisableTimeValueModel *r =
Chris@415 3499 dynamic_cast<RangeSummarisableTimeValueModel *>(m);
Chris@415 3500 if (r) model = m;
Chris@346 3501 }
Chris@346 3502 if (!model) model = getMainModel();
Chris@346 3503 }
Chris@346 3504 }
Chris@346 3505
Chris@346 3506 if (model) {
Chris@238 3507 newLayer = m_document->createLayer(type);
Chris@346 3508 if (m_document->isKnownModel(model)) {
Chris@238 3509 m_document->setChannel(newLayer, i->second.channel);
Chris@346 3510 m_document->setModel(newLayer, model);
Chris@238 3511 } else {
Chris@238 3512 std::cerr << "WARNING: MainWindow::addLayer: unknown model "
Chris@346 3513 << model
Chris@238 3514 << " (\""
Chris@346 3515 << (model ? model->objectName().toStdString() : "")
Chris@238 3516 << "\") in layer action map"
Chris@238 3517 << std::endl;
Chris@238 3518 }
Chris@232 3519 }
Chris@238 3520 }
Chris@0 3521
Chris@217 3522 if (newLayer) {
Chris@217 3523 m_document->addLayerToView(pane, newLayer);
Chris@217 3524 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@217 3525 }
Chris@0 3526
Chris@0 3527 return;
Chris@0 3528 }
Chris@0 3529
Chris@224 3530 //!!! want to do something like this, but it's not supported in
Chris@224 3531 //ModelTransformerFactory yet
Chris@224 3532 /*
Chris@0 3533 int channel = -1;
Chris@0 3534 // pick up the default channel from any existing layers on the same pane
Chris@0 3535 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@0 3536 int c = LayerFactory::getInstance()->getChannel(pane->getLayer(j));
Chris@0 3537 if (c != -1) {
Chris@0 3538 channel = c;
Chris@0 3539 break;
Chris@0 3540 }
Chris@0 3541 }
Chris@224 3542 */
Chris@0 3543
Chris@33 3544 // We always ask for configuration, even if the plugin isn't
Chris@33 3545 // supposed to be configurable, because we need to let the user
Chris@33 3546 // change the execution context (block size etc).
Chris@0 3547
Chris@224 3548 QString transformId = i->second;
Chris@274 3549
Chris@274 3550 addLayer(transformId);
Chris@274 3551 }
Chris@274 3552
Chris@274 3553 void
Chris@274 3554 MainWindow::addLayer(QString transformId)
Chris@274 3555 {
Chris@274 3556 Pane *pane = m_paneStack->getCurrentPane();
Chris@274 3557 if (!pane) {
Chris@274 3558 std::cerr << "WARNING: MainWindow::addLayer: no current pane" << std::endl;
Chris@274 3559 return;
Chris@274 3560 }
Chris@274 3561
Chris@224 3562 Transform transform = TransformFactory::getInstance()->
Chris@224 3563 getDefaultTransformFor(transformId);
Chris@27 3564
Chris@66 3565 std::vector<Model *> candidateInputModels =
Chris@224 3566 m_document->getTransformInputModels();
Chris@53 3567
Chris@219 3568 Model *defaultInputModel = 0;
Chris@219 3569 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@219 3570 Layer *layer = pane->getLayer(j);
Chris@219 3571 if (!layer) continue;
Chris@243 3572 if (LayerFactory::getInstance()->getLayerType(layer) !=
Chris@243 3573 LayerFactory::Waveform &&
Chris@243 3574 !layer->isLayerOpaque()) continue;
Chris@219 3575 Model *model = layer->getModel();
Chris@219 3576 if (!model) continue;
Chris@219 3577 for (size_t k = 0; k < candidateInputModels.size(); ++k) {
Chris@219 3578 if (candidateInputModels[k] == model) {
Chris@219 3579 defaultInputModel = model;
Chris@219 3580 break;
Chris@219 3581 }
Chris@219 3582 }
Chris@219 3583 if (defaultInputModel) break;
Chris@219 3584 }
Chris@219 3585
Chris@184 3586 size_t startFrame = 0, duration = 0;
Chris@184 3587 size_t endFrame = 0;
Chris@184 3588 m_viewManager->getSelection().getExtents(startFrame, endFrame);
Chris@184 3589 if (endFrame > startFrame) duration = endFrame - startFrame;
Chris@184 3590 else startFrame = 0;
Chris@184 3591
Chris@357 3592 TransformUserConfigurator configurator;
Chris@357 3593
Chris@224 3594 ModelTransformer::Input input = ModelTransformerFactory::getInstance()->
Chris@224 3595 getConfigurationForTransform
Chris@211 3596 (transform,
Chris@211 3597 candidateInputModels,
Chris@219 3598 defaultInputModel,
Chris@211 3599 m_playSource,
Chris@211 3600 startFrame,
Chris@357 3601 duration,
Chris@357 3602 &configurator);
Chris@211 3603
Chris@224 3604 if (!input.getModel()) return;
Chris@224 3605
Chris@438 3606 // SVDEBUG << "MainWindow::addLayer: Input model is " << input.getModel() << " \"" << input.getModel()->objectName() << "\"" << endl << "transform:" << endl << transform.toXmlString() << endl;
Chris@224 3607
Chris@224 3608 Layer *newLayer = m_document->createDerivedLayer(transform, input);
Chris@0 3609
Chris@0 3610 if (newLayer) {
Chris@0 3611 m_document->addLayerToView(pane, newLayer);
Chris@224 3612 m_document->setChannel(newLayer, input.getChannel());
Chris@224 3613 m_recentTransforms.add(transformId);
Chris@70 3614 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 3615 }
Chris@0 3616
Chris@0 3617 updateMenuStates();
Chris@0 3618 }
Chris@0 3619
Chris@0 3620 void
Chris@0 3621 MainWindow::renameCurrentLayer()
Chris@0 3622 {
Chris@0 3623 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 3624 if (pane) {
Chris@0 3625 Layer *layer = pane->getSelectedLayer();
Chris@0 3626 if (layer) {
Chris@0 3627 bool ok = false;
Chris@0 3628 QString newName = QInputDialog::getText
Chris@0 3629 (this, tr("Rename Layer"),
Chris@0 3630 tr("New name for this layer:"),
Chris@0 3631 QLineEdit::Normal, layer->objectName(), &ok);
Chris@0 3632 if (ok) {
Chris@239 3633 layer->setPresentationName(newName);
Chris@95 3634 setupExistingLayersMenus();
Chris@0 3635 }
Chris@0 3636 }
Chris@0 3637 }
Chris@0 3638 }
Chris@0 3639
Chris@0 3640 void
Chris@272 3641 MainWindow::findTransform()
Chris@272 3642 {
Chris@274 3643 TransformFinder *finder = new TransformFinder(this);
Chris@274 3644 if (!finder->exec()) {
Chris@274 3645 delete finder;
Chris@274 3646 return;
Chris@273 3647 }
Chris@274 3648 TransformId transform = finder->getTransform();
Chris@274 3649 delete finder;
Chris@287 3650
Chris@287 3651 if (getMainModel() != 0 && m_paneStack->getCurrentPane() != 0) {
Chris@287 3652 addLayer(transform);
Chris@287 3653 }
Chris@272 3654 }
Chris@272 3655
Chris@272 3656 void
Chris@207 3657 MainWindow::playSoloToggled()
Chris@207 3658 {
Chris@207 3659 MainWindowBase::playSoloToggled();
Chris@207 3660 m_soloModified = true;
Chris@207 3661 }
Chris@207 3662
Chris@207 3663 void
Chris@206 3664 MainWindow::alignToggled()
Chris@206 3665 {
Chris@206 3666 QAction *action = dynamic_cast<QAction *>(sender());
Chris@206 3667
Chris@207 3668 if (!m_viewManager) return;
Chris@207 3669
Chris@206 3670 if (action) {
Chris@206 3671 m_viewManager->setAlignMode(action->isChecked());
Chris@206 3672 } else {
Chris@206 3673 m_viewManager->setAlignMode(!m_viewManager->getAlignMode());
Chris@206 3674 }
Chris@206 3675
Chris@206 3676 if (m_viewManager->getAlignMode()) {
Chris@207 3677 m_prevSolo = m_soloAction->isChecked();
Chris@208 3678 if (!m_soloAction->isChecked()) {
Chris@208 3679 m_soloAction->setChecked(true);
Chris@208 3680 MainWindowBase::playSoloToggled();
Chris@208 3681 }
Chris@207 3682 m_soloModified = false;
Chris@207 3683 emit canChangeSolo(false);
Chris@206 3684 m_document->alignModels();
Chris@206 3685 m_document->setAutoAlignment(true);
Chris@206 3686 } else {
Chris@207 3687 if (!m_soloModified) {
Chris@208 3688 if (m_soloAction->isChecked() != m_prevSolo) {
Chris@208 3689 m_soloAction->setChecked(m_prevSolo);
Chris@208 3690 MainWindowBase::playSoloToggled();
Chris@208 3691 }
Chris@207 3692 }
Chris@207 3693 emit canChangeSolo(true);
Chris@206 3694 m_document->setAutoAlignment(false);
Chris@206 3695 }
Chris@206 3696
Chris@206 3697 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@206 3698
Chris@206 3699 Pane *pane = m_paneStack->getPane(i);
Chris@206 3700 if (!pane) continue;
Chris@206 3701
Chris@206 3702 pane->update();
Chris@206 3703 }
Chris@206 3704 }
Chris@206 3705
Chris@206 3706 void
Chris@59 3707 MainWindow::playSpeedChanged(int position)
Chris@0 3708 {
Chris@59 3709 PlaySpeedRangeMapper mapper(0, 200);
Chris@60 3710
Chris@60 3711 float percent = m_playSpeed->mappedValue();
Chris@60 3712 float factor = mapper.getFactorForValue(percent);
Chris@60 3713
Chris@267 3714 // std::cerr << "speed = " << position << " percent = " << percent << " factor = " << factor << std::endl;
Chris@60 3715
Chris@59 3716 bool something = (position != 100);
Chris@155 3717
Chris@59 3718 int pc = lrintf(percent);
Chris@21 3719
Chris@155 3720 if (!something) {
Chris@155 3721 contextHelpChanged(tr("Playback speed: Normal"));
Chris@155 3722 } else {
Chris@155 3723 contextHelpChanged(tr("Playback speed: %1%2%")
Chris@155 3724 .arg(position > 100 ? "+" : "")
Chris@155 3725 .arg(pc));
Chris@155 3726 }
Chris@155 3727
Chris@240 3728 m_playSource->setTimeStretch(factor);
Chris@155 3729
Chris@155 3730 updateMenuStates();
Chris@16 3731 }
Chris@16 3732
Chris@26 3733 void
Chris@155 3734 MainWindow::speedUpPlayback()
Chris@155 3735 {
Chris@155 3736 int value = m_playSpeed->value();
Chris@155 3737 value = value + m_playSpeed->pageStep();
Chris@155 3738 if (value > m_playSpeed->maximum()) value = m_playSpeed->maximum();
Chris@155 3739 m_playSpeed->setValue(value);
Chris@155 3740 }
Chris@155 3741
Chris@155 3742 void
Chris@155 3743 MainWindow::slowDownPlayback()
Chris@155 3744 {
Chris@155 3745 int value = m_playSpeed->value();
Chris@155 3746 value = value - m_playSpeed->pageStep();
Chris@155 3747 if (value < m_playSpeed->minimum()) value = m_playSpeed->minimum();
Chris@155 3748 m_playSpeed->setValue(value);
Chris@155 3749 }
Chris@155 3750
Chris@155 3751 void
Chris@155 3752 MainWindow::restoreNormalPlayback()
Chris@155 3753 {
Chris@155 3754 m_playSpeed->setValue(m_playSpeed->defaultValue());
Chris@155 3755 }
Chris@155 3756
Chris@155 3757 void
Chris@227 3758 MainWindow::currentPaneChanged(Pane *pane)
Chris@227 3759 {
Chris@228 3760 MainWindowBase::currentPaneChanged(pane);
Chris@228 3761
Chris@227 3762 if (!pane || !m_panLayer) return;
Chris@227 3763 for (int i = pane->getLayerCount(); i > 0; ) {
Chris@227 3764 --i;
Chris@227 3765 Layer *layer = pane->getLayer(i);
Chris@227 3766 if (LayerFactory::getInstance()->getLayerType(layer) ==
Chris@227 3767 LayerFactory::Waveform) {
Chris@227 3768 RangeSummarisableTimeValueModel *tvm =
Chris@227 3769 dynamic_cast<RangeSummarisableTimeValueModel *>(layer->getModel());
Chris@227 3770 if (tvm) {
Chris@227 3771 m_panLayer->setModel(tvm);
Chris@227 3772 return;
Chris@227 3773 }
Chris@227 3774 }
Chris@227 3775 }
Chris@227 3776 }
Chris@227 3777
Chris@227 3778 void
Chris@116 3779 MainWindow::updateVisibleRangeDisplay(Pane *p) const
Chris@116 3780 {
Chris@116 3781 if (!getMainModel() || !p) {
Chris@116 3782 return;
Chris@116 3783 }
Chris@116 3784
Chris@117 3785 bool haveSelection = false;
Chris@117 3786 size_t startFrame = 0, endFrame = 0;
Chris@117 3787
Chris@117 3788 if (m_viewManager && m_viewManager->haveInProgressSelection()) {
Chris@117 3789
Chris@117 3790 bool exclusive = false;
Chris@117 3791 Selection s = m_viewManager->getInProgressSelection(exclusive);
Chris@117 3792
Chris@117 3793 if (!s.isEmpty()) {
Chris@117 3794 haveSelection = true;
Chris@117 3795 startFrame = s.getStartFrame();
Chris@117 3796 endFrame = s.getEndFrame();
Chris@117 3797 }
Chris@117 3798 }
Chris@117 3799
Chris@117 3800 if (!haveSelection) {
Chris@117 3801 startFrame = p->getFirstVisibleFrame();
Chris@117 3802 endFrame = p->getLastVisibleFrame();
Chris@117 3803 }
Chris@117 3804
Chris@116 3805 RealTime start = RealTime::frame2RealTime
Chris@117 3806 (startFrame, getMainModel()->getSampleRate());
Chris@116 3807
Chris@116 3808 RealTime end = RealTime::frame2RealTime
Chris@117 3809 (endFrame, getMainModel()->getSampleRate());
Chris@116 3810
Chris@116 3811 RealTime duration = end - start;
Chris@116 3812
Chris@116 3813 QString startStr, endStr, durationStr;
Chris@116 3814 startStr = start.toText(true).c_str();
Chris@116 3815 endStr = end.toText(true).c_str();
Chris@116 3816 durationStr = duration.toText(true).c_str();
Chris@116 3817
Chris@117 3818 if (haveSelection) {
Chris@117 3819 m_myStatusMessage = tr("Selection: %1 to %2 (duration %3)")
Chris@117 3820 .arg(startStr).arg(endStr).arg(durationStr);
Chris@117 3821 } else {
Chris@117 3822 m_myStatusMessage = tr("Visible: %1 to %2 (duration %3)")
Chris@117 3823 .arg(startStr).arg(endStr).arg(durationStr);
Chris@117 3824 }
Chris@116 3825
Chris@116 3826 statusBar()->showMessage(m_myStatusMessage);
Chris@340 3827
Chris@340 3828 updatePositionStatusDisplays();
Chris@340 3829 }
Chris@340 3830
Chris@340 3831 void
Chris@340 3832 MainWindow::updatePositionStatusDisplays() const
Chris@340 3833 {
Chris@340 3834 if (!statusBar()->isVisible()) return;
Chris@340 3835
Chris@340 3836 Pane *pane = 0;
Chris@340 3837 size_t frame = m_viewManager->getPlaybackFrame();
Chris@340 3838
Chris@340 3839 if (m_paneStack) pane = m_paneStack->getCurrentPane();
Chris@340 3840 if (!pane) return;
Chris@340 3841
Chris@340 3842 int layers = pane->getLayerCount();
Chris@340 3843 if (layers == 0) m_currentLabel->setText("");
Chris@340 3844
Chris@340 3845 for (int i = layers-1; i >= 0; --i) {
Chris@340 3846 Layer *layer = pane->getLayer(i);
Chris@340 3847 if (!layer) continue;
Chris@340 3848 if (!layer->isLayerEditable()) continue;
Chris@340 3849 QString label = layer->getLabelPreceding
Chris@340 3850 (pane->alignFromReference(frame));
Chris@340 3851 m_currentLabel->setText(label);
Chris@340 3852 break;
Chris@340 3853 }
Chris@116 3854 }
Chris@116 3855
Chris@116 3856 void
Chris@0 3857 MainWindow::outputLevelsChanged(float left, float right)
Chris@0 3858 {
Chris@0 3859 m_fader->setPeakLeft(left);
Chris@0 3860 m_fader->setPeakRight(right);
Chris@0 3861 }
Chris@0 3862
Chris@0 3863 void
Chris@0 3864 MainWindow::sampleRateMismatch(size_t requested, size_t actual,
Chris@0 3865 bool willResample)
Chris@0 3866 {
Chris@0 3867 if (!willResample) {
Chris@247 3868 emit hideSplash();
Chris@0 3869 QMessageBox::information
Chris@0 3870 (this, tr("Sample rate mismatch"),
Chris@193 3871 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 3872 .arg(requested).arg(actual));
Chris@0 3873 }
Chris@0 3874
Chris@0 3875 updateDescriptionLabel();
Chris@0 3876 }
Chris@0 3877
Chris@0 3878 void
Chris@42 3879 MainWindow::audioOverloadPluginDisabled()
Chris@42 3880 {
Chris@42 3881 QMessageBox::information
Chris@42 3882 (this, tr("Audio processing overload"),
Chris@193 3883 tr("<b>Overloaded</b><p>Audio effects plugin auditioning has been disabled due to a processing overload."));
Chris@42 3884 }
Chris@42 3885
Chris@42 3886 void
Chris@266 3887 MainWindow::audioTimeStretchMultiChannelDisabled()
Chris@266 3888 {
Chris@266 3889 static bool shownOnce = false;
Chris@266 3890 if (shownOnce) return;
Chris@266 3891 QMessageBox::information
Chris@266 3892 (this, tr("Audio processing overload"),
Chris@266 3893 tr("<b>Overloaded</b><p>Audio playback speed processing has been reduced to a single channel, due to a processing overload."));
Chris@266 3894 shownOnce = true;
Chris@266 3895 }
Chris@266 3896
Chris@266 3897 void
Chris@304 3898 MainWindow::midiEventsAvailable()
Chris@304 3899 {
Chris@307 3900 Pane *currentPane = 0;
Chris@307 3901 NoteLayer *currentNoteLayer = 0;
Chris@309 3902 TimeValueLayer *currentTimeValueLayer = 0;
Chris@307 3903
Chris@307 3904 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
Chris@307 3905 if (currentPane) {
Chris@307 3906 currentNoteLayer = dynamic_cast<NoteLayer *>
Chris@307 3907 (currentPane->getSelectedLayer());
Chris@309 3908 currentTimeValueLayer = dynamic_cast<TimeValueLayer *>
Chris@309 3909 (currentPane->getSelectedLayer());
Chris@307 3910 }
Chris@307 3911
Chris@305 3912 // This is called through a serialised signal/slot invocation
Chris@305 3913 // (across threads). It could happen quite some time after the
Chris@305 3914 // event was actually received, which is why event timestamping
Chris@305 3915 // happens in the MIDI input class and not here.
Chris@307 3916
Chris@305 3917 while (m_midiInput->getEventsAvailable() > 0) {
Chris@308 3918
Chris@305 3919 MIDIEvent ev(m_midiInput->readEvent());
Chris@307 3920
Chris@309 3921 size_t frame = currentPane->alignFromReference(ev.getTime());
Chris@309 3922
Chris@308 3923 bool noteOn = (ev.getMessageType() == MIDIConstants::MIDI_NOTE_ON &&
Chris@308 3924 ev.getVelocity() > 0);
Chris@308 3925
Chris@308 3926 bool noteOff = (ev.getMessageType() == MIDIConstants::MIDI_NOTE_OFF ||
Chris@308 3927 (ev.getMessageType() == MIDIConstants::MIDI_NOTE_ON &&
Chris@308 3928 ev.getVelocity() == 0));
Chris@308 3929
Chris@307 3930 if (currentNoteLayer) {
Chris@307 3931
Chris@310 3932 if (!m_playSource || !m_playSource->isPlaying()) continue;
Chris@310 3933
Chris@308 3934 if (noteOn) {
Chris@307 3935
Chris@309 3936 currentNoteLayer->addNoteOn(frame,
Chris@307 3937 ev.getPitch(),
Chris@307 3938 ev.getVelocity());
Chris@307 3939
Chris@308 3940 } else if (noteOff) {
Chris@307 3941
Chris@309 3942 currentNoteLayer->addNoteOff(frame,
Chris@307 3943 ev.getPitch());
Chris@307 3944
Chris@307 3945 }
Chris@307 3946
Chris@309 3947 continue;
Chris@309 3948 }
Chris@309 3949
Chris@309 3950 if (currentTimeValueLayer) {
Chris@308 3951
Chris@308 3952 if (!noteOn) continue;
Chris@310 3953
Chris@310 3954 if (!m_playSource || !m_playSource->isPlaying()) continue;
Chris@310 3955
Chris@309 3956 Model *model = static_cast<Layer *>(currentTimeValueLayer)->getModel();
Chris@309 3957 SparseTimeValueModel *tvm =
Chris@309 3958 dynamic_cast<SparseTimeValueModel *>(model);
Chris@309 3959 if (tvm) {
Chris@309 3960 SparseTimeValueModel::Point point(frame, ev.getPitch() % 12, "");
Chris@309 3961 SparseTimeValueModel::AddPointCommand *command =
Chris@309 3962 new SparseTimeValueModel::AddPointCommand
Chris@309 3963 (tvm, point, tr("Add Point"));
Chris@309 3964 CommandHistory::getInstance()->addCommand(command);
Chris@309 3965 }
Chris@309 3966 continue;
Chris@309 3967
Chris@305 3968 }
Chris@309 3969
Chris@309 3970 if (!noteOn) continue;
Chris@309 3971 insertInstantAt(ev.getTime());
Chris@304 3972 }
Chris@304 3973 }
Chris@304 3974
Chris@304 3975 void
Chris@305 3976 MainWindow::playStatusChanged(bool playing)
Chris@305 3977 {
Chris@307 3978 Pane *currentPane = 0;
Chris@307 3979 NoteLayer *currentNoteLayer = 0;
Chris@307 3980
Chris@307 3981 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
Chris@307 3982 if (currentPane) {
Chris@307 3983 currentNoteLayer = dynamic_cast<NoteLayer *>(currentPane->getSelectedLayer());
Chris@307 3984 }
Chris@307 3985
Chris@307 3986 if (currentNoteLayer) {
Chris@307 3987 currentNoteLayer->abandonNoteOns();
Chris@307 3988 }
Chris@305 3989 }
Chris@305 3990
Chris@305 3991 void
Chris@200 3992 MainWindow::layerRemoved(Layer *layer)
Chris@0 3993 {
Chris@95 3994 setupExistingLayersMenus();
Chris@200 3995 MainWindowBase::layerRemoved(layer);
Chris@0 3996 }
Chris@0 3997
Chris@0 3998 void
Chris@0 3999 MainWindow::layerInAView(Layer *layer, bool inAView)
Chris@0 4000 {
Chris@95 4001 setupExistingLayersMenus();
Chris@200 4002 MainWindowBase::layerInAView(layer, inAView);
Chris@0 4003 }
Chris@0 4004
Chris@0 4005 void
Chris@0 4006 MainWindow::modelAdded(Model *model)
Chris@0 4007 {
Chris@200 4008 MainWindowBase::modelAdded(model);
Chris@66 4009 if (dynamic_cast<DenseTimeValueModel *>(model)) {
Chris@66 4010 setupPaneAndLayerMenus();
Chris@66 4011 }
Chris@0 4012 }
Chris@0 4013
Chris@0 4014 void
Chris@0 4015 MainWindow::mainModelChanged(WaveFileModel *model)
Chris@0 4016 {
Chris@0 4017 m_panLayer->setModel(model);
Chris@200 4018
Chris@200 4019 MainWindowBase::mainModelChanged(model);
Chris@200 4020
Chris@200 4021 if (m_playTarget) {
Chris@200 4022 connect(m_fader, SIGNAL(valueChanged(float)),
Chris@200 4023 m_playTarget, SLOT(setOutputGain(float)));
Chris@200 4024 }
Chris@0 4025 }
Chris@0 4026
Chris@0 4027 void
Chris@200 4028 MainWindow::setInstantsNumbering()
Chris@0 4029 {
Chris@200 4030 QAction *a = dynamic_cast<QAction *>(sender());
Chris@200 4031 if (!a) return;
Chris@200 4032
Chris@200 4033 int type = m_numberingActions[a];
Chris@200 4034
Chris@200 4035 if (m_labeller) m_labeller->setType(Labeller::ValueType(type));
Chris@200 4036
Chris@200 4037 QSettings settings;
Chris@200 4038 settings.beginGroup("MainWindow");
Chris@200 4039 settings.setValue("labellertype", type);
Chris@200 4040 settings.endGroup();
Chris@200 4041 }
Chris@200 4042
Chris@200 4043 void
Chris@200 4044 MainWindow::setInstantsCounterCycle()
Chris@200 4045 {
Chris@200 4046 QAction *a = dynamic_cast<QAction *>(sender());
Chris@200 4047 if (!a) return;
Chris@200 4048
Chris@200 4049 int cycle = a->text().toInt();
Chris@200 4050 if (cycle == 0) return;
Chris@200 4051
Chris@200 4052 if (m_labeller) m_labeller->setCounterCycleSize(cycle);
Chris@200 4053
Chris@200 4054 QSettings settings;
Chris@200 4055 settings.beginGroup("MainWindow");
Chris@200 4056 settings.setValue("labellercycle", cycle);
Chris@200 4057 settings.endGroup();
Chris@200 4058 }
Chris@200 4059
Chris@200 4060 void
Chris@597 4061 MainWindow::setInstantsCounters()
Chris@200 4062 {
Chris@200 4063 LabelCounterInputDialog dialog(m_labeller, this);
Chris@241 4064 dialog.setWindowTitle(tr("Reset Counters"));
Chris@200 4065 dialog.exec();
Chris@0 4066 }
Chris@0 4067
Chris@0 4068 void
Chris@597 4069 MainWindow::resetInstantsCounters()
Chris@597 4070 {
Chris@597 4071 if (m_labeller) m_labeller->resetCounters();
Chris@597 4072 }
Chris@597 4073
Chris@597 4074 void
Chris@233 4075 MainWindow::modelGenerationFailed(QString transformName, QString message)
Chris@233 4076 {
Chris@247 4077 emit hideSplash();
Chris@247 4078
Chris@233 4079 if (message != "") {
Chris@233 4080
Chris@233 4081 QMessageBox::warning
Chris@233 4082 (this,
Chris@233 4083 tr("Failed to generate layer"),
Chris@233 4084 tr("<b>Layer generation failed</b><p>Failed to generate derived layer.<p>The layer transform \"%1\" failed:<p>%2")
Chris@233 4085 .arg(transformName).arg(message),
Chris@233 4086 QMessageBox::Ok);
Chris@233 4087 } else {
Chris@233 4088 QMessageBox::warning
Chris@233 4089 (this,
Chris@233 4090 tr("Failed to generate layer"),
Chris@233 4091 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 4092 .arg(transformName),
Chris@233 4093 QMessageBox::Ok);
Chris@233 4094 }
Chris@233 4095 }
Chris@233 4096
Chris@233 4097 void
Chris@233 4098 MainWindow::modelGenerationWarning(QString transformName, QString message)
Chris@233 4099 {
Chris@247 4100 emit hideSplash();
Chris@247 4101
Chris@233 4102 QMessageBox::warning
Chris@233 4103 (this, tr("Warning"), message, QMessageBox::Ok);
Chris@233 4104 }
Chris@233 4105
Chris@233 4106 void
Chris@233 4107 MainWindow::modelRegenerationFailed(QString layerName,
Chris@233 4108 QString transformName, QString message)
Chris@233 4109 {
Chris@247 4110 emit hideSplash();
Chris@247 4111
Chris@233 4112 if (message != "") {
Chris@233 4113
Chris@233 4114 QMessageBox::warning
Chris@233 4115 (this,
Chris@233 4116 tr("Failed to regenerate layer"),
Chris@233 4117 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 4118 .arg(layerName).arg(transformName).arg(message),
Chris@233 4119 QMessageBox::Ok);
Chris@233 4120 } else {
Chris@233 4121 QMessageBox::warning
Chris@233 4122 (this,
Chris@233 4123 tr("Failed to regenerate layer"),
Chris@233 4124 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 4125 .arg(layerName).arg(transformName),
Chris@233 4126 QMessageBox::Ok);
Chris@233 4127 }
Chris@233 4128 }
Chris@233 4129
Chris@233 4130 void
Chris@233 4131 MainWindow::modelRegenerationWarning(QString layerName,
Chris@233 4132 QString transformName, QString message)
Chris@233 4133 {
Chris@247 4134 emit hideSplash();
Chris@247 4135
Chris@233 4136 QMessageBox::warning
Chris@233 4137 (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 4138 }
Chris@233 4139
Chris@233 4140 void
Chris@233 4141 MainWindow::alignmentFailed(QString transformName, QString message)
Chris@0 4142 {
Chris@247 4143 emit hideSplash();
Chris@247 4144
Chris@0 4145 QMessageBox::warning
Chris@0 4146 (this,
Chris@233 4147 tr("Failed to calculate alignment"),
Chris@233 4148 tr("<b>Alignment calculation failed</b><p>Failed to calculate an audio alignment using transform \"%1\":<p>%2")
Chris@233 4149 .arg(transformName).arg(message),
Chris@165 4150 QMessageBox::Ok);
Chris@0 4151 }
Chris@0 4152
Chris@0 4153 void
Chris@0 4154 MainWindow::rightButtonMenuRequested(Pane *pane, QPoint position)
Chris@0 4155 {
Chris@438 4156 // SVDEBUG << "MainWindow::rightButtonMenuRequested(" << pane << ", " << position.x() << ", " << position.y() << ")" << endl;
Chris@0 4157 m_paneStack->setCurrentPane(pane);
Chris@0 4158 m_rightButtonMenu->popup(position);
Chris@0 4159 }
Chris@0 4160
Chris@0 4161 void
Chris@0 4162 MainWindow::showLayerTree()
Chris@0 4163 {
Chris@219 4164 if (!m_layerTreeDialog.isNull()) {
Chris@219 4165 m_layerTreeDialog->show();
Chris@219 4166 m_layerTreeDialog->raise();
Chris@177 4167 return;
Chris@177 4168 }
Chris@177 4169
Chris@219 4170 m_layerTreeDialog = new LayerTreeDialog(m_paneStack);
Chris@232 4171 m_layerTreeDialog->setAttribute(Qt::WA_DeleteOnClose); // see below
Chris@219 4172 m_layerTreeDialog->show();
Chris@0 4173 }
Chris@0 4174
Chris@0 4175 void
Chris@306 4176 MainWindow::showActivityLog()
Chris@306 4177 {
Chris@306 4178 m_activityLog->show();
Chris@306 4179 m_activityLog->raise();
Chris@306 4180 m_activityLog->scrollToEnd();
Chris@306 4181 }
Chris@306 4182
Chris@306 4183 void
Chris@0 4184 MainWindow::preferences()
Chris@0 4185 {
Chris@436 4186 bool goToTemplateTab =
Chris@436 4187 (sender() && sender()->objectName() == "set_default_template");
Chris@436 4188
Chris@0 4189 if (!m_preferencesDialog.isNull()) {
Chris@0 4190 m_preferencesDialog->show();
Chris@0 4191 m_preferencesDialog->raise();
Chris@436 4192 if (goToTemplateTab) {
Chris@436 4193 m_preferencesDialog->switchToTab(PreferencesDialog::TemplateTab);
Chris@436 4194 }
Chris@0 4195 return;
Chris@0 4196 }
Chris@0 4197
Chris@0 4198 m_preferencesDialog = new PreferencesDialog(this);
Chris@0 4199
Chris@0 4200 // DeleteOnClose is safe here, because m_preferencesDialog is a
Chris@0 4201 // QPointer that will be zeroed when the dialog is deleted. We
Chris@0 4202 // use it in preference to leaving the dialog lying around because
Chris@0 4203 // if you Cancel the dialog, it resets the preferences state
Chris@0 4204 // without resetting its own widgets, so its state will be
Chris@0 4205 // incorrect when next shown unless we construct it afresh
Chris@0 4206 m_preferencesDialog->setAttribute(Qt::WA_DeleteOnClose);
Chris@0 4207
Chris@0 4208 m_preferencesDialog->show();
Chris@436 4209 if (goToTemplateTab) {
Chris@436 4210 m_preferencesDialog->switchToTab(PreferencesDialog::TemplateTab);
Chris@436 4211 }
Chris@0 4212 }
Chris@0 4213
Chris@0 4214 void
Chris@90 4215 MainWindow::mouseEnteredWidget()
Chris@90 4216 {
Chris@90 4217 QWidget *w = dynamic_cast<QWidget *>(sender());
Chris@90 4218 if (!w) return;
Chris@90 4219
Chris@90 4220 if (w == m_fader) {
Chris@116 4221 contextHelpChanged(tr("Adjust the master playback level"));
Chris@90 4222 } else if (w == m_playSpeed) {
Chris@116 4223 contextHelpChanged(tr("Adjust the master playback speed"));
Chris@90 4224 }
Chris@90 4225 }
Chris@90 4226
Chris@90 4227 void
Chris@90 4228 MainWindow::mouseLeftWidget()
Chris@90 4229 {
Chris@116 4230 contextHelpChanged("");
Chris@116 4231 }
Chris@116 4232
Chris@116 4233 void
Chris@0 4234 MainWindow::website()
Chris@0 4235 {
Chris@0 4236 openHelpUrl(tr("http://www.sonicvisualiser.org/"));
Chris@0 4237 }
Chris@0 4238
Chris@0 4239 void
Chris@0 4240 MainWindow::help()
Chris@0 4241 {
Chris@318 4242 openHelpUrl(tr("http://www.sonicvisualiser.org/doc/reference/%1/en/").arg(SV_VERSION));
Chris@0 4243 }
Chris@0 4244
Chris@0 4245 void
Chris@0 4246 MainWindow::about()
Chris@0 4247 {
Chris@0 4248 bool debug = false;
Chris@0 4249 QString version = "(unknown version)";
Chris@0 4250
Chris@0 4251 #ifdef BUILD_DEBUG
Chris@0 4252 debug = true;
Chris@285 4253 #endif // BUILD_DEBUG
Chris@0 4254 #ifdef SV_VERSION
Chris@0 4255 #ifdef SVNREV
Chris@0 4256 version = tr("Release %1 : Revision %2").arg(SV_VERSION).arg(SVNREV);
Chris@285 4257 #else // !SVNREV
Chris@0 4258 version = tr("Release %1").arg(SV_VERSION);
Chris@285 4259 #endif // SVNREV
Chris@285 4260 #else // !SV_VERSION
Chris@0 4261 #ifdef SVNREV
Chris@0 4262 version = tr("Unreleased : Revision %1").arg(SVNREV);
Chris@285 4263 #endif // SVNREV
Chris@285 4264 #endif // SV_VERSION
Chris@0 4265
Chris@0 4266 QString aboutText;
Chris@0 4267
Chris@0 4268 aboutText += tr("<h3>About Sonic Visualiser</h3>");
Chris@285 4269 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 4270 aboutText += tr("<p><small>%1 : %2 configuration</small></p>")
Chris@0 4271 .arg(version)
Chris@0 4272 .arg(debug ? tr("Debug") : tr("Release"));
Chris@0 4273
Chris@285 4274 aboutText += "<small>";
Chris@285 4275
Chris@285 4276 aboutText += tr("With Qt v%1 &copy; Nokia Corporation").arg(QT_VERSION_STR);
Chris@285 4277
Chris@0 4278 #ifdef HAVE_JACK
Chris@93 4279 #ifdef JACK_VERSION
Chris@285 4280 aboutText += tr("<br>With JACK audio output library v%1 &copy; Paul Davis and Jack O'Quin").arg(JACK_VERSION);
Chris@285 4281 #else // !JACK_VERSION
Chris@257 4282 aboutText += tr("<br>With JACK audio output library &copy; Paul Davis and Jack O'Quin");
Chris@285 4283 #endif // JACK_VERSION
Chris@285 4284 #endif // HAVE_JACK
Chris@0 4285 #ifdef HAVE_PORTAUDIO
Chris@257 4286 aboutText += tr("<br>With PortAudio audio output library &copy; Ross Bencina and Phil Burk");
Chris@285 4287 #endif // HAVE_PORTAUDIO
Chris@257 4288 #ifdef HAVE_LIBPULSE
Chris@285 4289 #ifdef LIBPULSE_VERSION
Chris@285 4290 aboutText += tr("<br>With PulseAudio audio output library v%1 &copy; Lennart Poettering and Pierre Ossman").arg(LIBPULSE_VERSION);
Chris@285 4291 #else // !LIBPULSE_VERSION
Chris@257 4292 aboutText += tr("<br>With PulseAudio audio output library &copy; Lennart Poettering and Pierre Ossman");
Chris@285 4293 #endif // LIBPULSE_VERSION
Chris@285 4294 #endif // HAVE_LIBPULSE
Chris@0 4295 #ifdef HAVE_OGGZ
Chris@93 4296 #ifdef OGGZ_VERSION
Chris@0 4297 aboutText += tr("<br>With Ogg file decoder (oggz v%1, fishsound v%2) &copy; CSIRO Australia").arg(OGGZ_VERSION).arg(FISHSOUND_VERSION);
Chris@285 4298 #else // !OGGZ_VERSION
Chris@93 4299 aboutText += tr("<br>With Ogg file decoder &copy; CSIRO Australia");
Chris@285 4300 #endif // OGGZ_VERSION
Chris@285 4301 #endif // HAVE_OGGZ
Chris@0 4302 #ifdef HAVE_MAD
Chris@93 4303 #ifdef MAD_VERSION
Chris@285 4304 aboutText += tr("<br>With MAD mp3 decoder v%1 &copy; Underbit Technologies Inc").arg(MAD_VERSION);
Chris@285 4305 #else // !MAD_VERSION
Chris@93 4306 aboutText += tr("<br>With MAD mp3 decoder &copy; Underbit Technologies Inc");
Chris@285 4307 #endif // MAD_VERSION
Chris@285 4308 #endif // HAVE_MAD
Chris@0 4309 #ifdef HAVE_SAMPLERATE
Chris@93 4310 #ifdef SAMPLERATE_VERSION
Chris@285 4311 aboutText += tr("<br>With libsamplerate v%1 &copy; Erik de Castro Lopo").arg(SAMPLERATE_VERSION);
Chris@285 4312 #else // !SAMPLERATE_VERSION
Chris@93 4313 aboutText += tr("<br>With libsamplerate &copy; Erik de Castro Lopo");
Chris@285 4314 #endif // SAMPLERATE_VERSION
Chris@285 4315 #endif // HAVE_SAMPLERATE
Chris@0 4316 #ifdef HAVE_SNDFILE
Chris@93 4317 #ifdef SNDFILE_VERSION
Chris@285 4318 aboutText += tr("<br>With libsndfile v%1 &copy; Erik de Castro Lopo").arg(SNDFILE_VERSION);
Chris@285 4319 #else // !SNDFILE_VERSION
Chris@93 4320 aboutText += tr("<br>With libsndfile &copy; Erik de Castro Lopo");
Chris@285 4321 #endif // SNDFILE_VERSION
Chris@285 4322 #endif // HAVE_SNDFILE
Chris@127 4323 #ifdef HAVE_FFTW3F
Chris@93 4324 #ifdef FFTW3_VERSION
Chris@285 4325 aboutText += tr("<br>With FFTW3 v%1 &copy; Matteo Frigo and MIT").arg(FFTW3_VERSION);
Chris@285 4326 #else // !FFTW3_VERSION
Chris@93 4327 aboutText += tr("<br>With FFTW3 &copy; Matteo Frigo and MIT");
Chris@285 4328 #endif // FFTW3_VERSION
Chris@285 4329 #endif // HAVE_FFTW3F
Chris@267 4330 #ifdef HAVE_RUBBERBAND
Chris@267 4331 #ifdef RUBBERBAND_VERSION
Chris@285 4332 aboutText += tr("<br>With Rubber Band v%1 &copy; Chris Cannam").arg(RUBBERBAND_VERSION);
Chris@285 4333 #else // !RUBBERBAND_VERSION
Chris@267 4334 aboutText += tr("<br>With Rubber Band &copy; Chris Cannam");
Chris@285 4335 #endif // RUBBERBAND_VERSION
Chris@285 4336 #endif // HAVE_RUBBERBAND
Chris@0 4337 #ifdef HAVE_VAMP
Chris@114 4338 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 4339 #endif // !HAVE_VAMP
Chris@0 4340 aboutText += tr("<br>With LADSPA plugin support (API v%1) &copy; Richard Furse, Paul Davis, Stefan Westerfeld").arg(LADSPA_VERSION);
Chris@0 4341 aboutText += tr("<br>With DSSI plugin support (API v%1) &copy; Chris Cannam, Steve Harris, Sean Bolton").arg(DSSI_VERSION);
Chris@285 4342 #ifdef REDLAND_VERSION
Chris@285 4343 aboutText += tr("<br>With Redland RDF datastore v%1 &copy; Dave Beckett and the University of Bristol").arg(REDLAND_VERSION);
Chris@285 4344 #else // !REDLAND_VERSION
Chris@285 4345 aboutText += tr("<br>With Redland RDF datastore &copy; Dave Beckett and the University of Bristol");
Chris@285 4346 #endif // REDLAND_VERSION
Chris@523 4347 aboutText += tr("<br>With Serd and Sord RDF parser and store &copy; David Robillard");
Chris@523 4348 aboutText += tr("<br>With Dataquay Qt/RDF library &copy; Chris Cannam");
Chris@285 4349
Chris@300 4350 aboutText += tr("<br>With RtMidi &copy; Gary P. Scavone");
Chris@300 4351
Chris@69 4352 #ifdef HAVE_LIBLO
Chris@93 4353 #ifdef LIBLO_VERSION
Chris@285 4354 aboutText += tr("<br>With liblo Lite OSC library v%1 &copy; Steve Harris").arg(LIBLO_VERSION);
Chris@285 4355 #else // !LIBLO_VERSION
Chris@327 4356 aboutText += tr("<br>With liblo Lite OSC library &copy; Steve Harris");
Chris@285 4357 #endif // LIBLO_VERSION
Chris@285 4358
Chris@285 4359 if (m_oscQueue && m_oscQueue->isOK()) {
Chris@285 4360 aboutText += tr("</small><p><small>The OSC URL for this instance is: \"%1\"").arg(m_oscQueue->getOSCURL());
Chris@285 4361 }
Chris@285 4362
Chris@285 4363 aboutText += "</small></p>";
Chris@285 4364 #endif // HAVE_LIBLO
Chris@285 4365
Chris@285 4366 #ifndef BUILD_STATIC
Chris@285 4367 aboutText.replace(tr("With "), tr("Using "));
Chris@93 4368 #endif
Chris@0 4369
Chris@0 4370 aboutText +=
Chris@523 4371 "<p><small>Sonic Visualiser Copyright &copy; 2005&ndash;2013 Chris Cannam and "
Chris@285 4372 "Queen Mary, University of London.</small></p>"
Chris@285 4373 "<p><small>This program is free software; you can redistribute it and/or "
Chris@231 4374 "modify it under the terms of the GNU General Public License as "
Chris@231 4375 "published by the Free Software Foundation; either version 2 of the "
Chris@0 4376 "License, or (at your option) any later version.<br>See the file "
Chris@285 4377 "COPYING included with this distribution for more information.</small></p>";
Chris@0 4378
Chris@0 4379 QMessageBox::about(this, tr("About Sonic Visualiser"), aboutText);
Chris@0 4380 }
Chris@0 4381
Chris@162 4382 void
Chris@162 4383 MainWindow::keyReference()
Chris@162 4384 {
Chris@162 4385 m_keyReference->show();
Chris@162 4386 }
Chris@162 4387
Chris@333 4388 void
Chris@333 4389 MainWindow::newerVersionAvailable(QString version)
Chris@333 4390 {
Chris@334 4391 QSettings settings;
Chris@334 4392 settings.beginGroup("NewerVersionWarning");
Chris@334 4393 QString tag = QString("version-%1-available-show").arg(version);
Chris@334 4394 if (settings.value(tag, true).toBool()) {
Chris@334 4395 QString title(tr("Newer version available"));
Chris@334 4396 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 4397 QMessageBox::information(this, title, text);
Chris@334 4398 settings.setValue(tag, false);
Chris@334 4399 }
Chris@334 4400 settings.endGroup();
Chris@333 4401 }
Chris@333 4402
Chris@333 4403