annotate main/MainWindow.cpp @ 412:44741262c2e0 sv_v1.8_osx_deploy

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