annotate main/MainWindow.cpp @ 458:a94be56cf98f toggle

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