annotate main/MainWindow.cpp @ 437:9de86c1b980e

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