annotate main/MainWindow.cpp @ 448:54f3f0f29c95 toggle

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