annotate main/MainWindow.cpp @ 470:e612c3844887

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