annotate main/MainWindow.cpp @ 392:58b7e3893963

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