annotate main/MainWindow.cpp @ 493:3a85461ab9a7 fullscreen

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