annotate main/MainWindow.cpp @ 462:083182cde1c7 toggle

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