annotate main/MainWindow.cpp @ 431:ee927c1b7941 templating

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