annotate main/MainWindow.cpp @ 273:9070db6244a2

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