annotate main/MainWindow.cpp @ 303:5d691489a84f

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