annotate main/MainWindow.cpp @ 346:92c09ced49ed

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