annotate main/MainWindow.cpp @ 302:2fe08e403a9b

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