annotate main/MainWindow.cpp @ 491:9137b619b652 fullscreen

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