annotate main/MainWindow.cpp @ 492:ab3bcd06b5c2 fullscreen

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