annotate main/MainWindow.cpp @ 367:726e1c1382f3 macness

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