annotate main/MainWindow.cpp @ 434:db0c86c4e5e9 templating

Merge from the default branch
author Chris Cannam
date Tue, 17 May 2011 13:33:15 +0100
parents ee927c1b7941 5f22e0bbe4ba
children 586eb6764a2b
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@415 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@66 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@428 2419 model->getChannelCount(),
Chris@428 2420 WavFileWriter::WriteToTemporary);
Chris@320 2421 subwriter.writeModel(model, &subms);
Chris@0 2422 ok = subwriter.isOK();
Chris@0 2423
Chris@0 2424 if (!ok) {
Chris@0 2425 error = subwriter.getError();
Chris@0 2426 break;
Chris@0 2427 }
Chris@0 2428 }
Chris@0 2429 }
Chris@0 2430 }
Chris@0 2431
Chris@38 2432 if (!multiple) {
Chris@38 2433 WavFileWriter writer(path,
Chris@320 2434 model->getSampleRate(),
Chris@428 2435 model->getChannelCount(),
Chris@428 2436 WavFileWriter::WriteToTemporary);
Chris@320 2437 writer.writeModel(model, selectionToWrite);
Chris@38 2438 ok = writer.isOK();
Chris@38 2439 error = writer.getError();
Chris@0 2440 }
Chris@0 2441
Chris@0 2442 if (ok) {
Chris@310 2443 if (multiple) {
Chris@310 2444 emit activity(tr("Export multiple audio files"));
Chris@310 2445 } else {
Chris@310 2446 emit activity(tr("Export audio to \"%1\"").arg(path));
Chris@34 2447 m_recentFiles.addFile(path);
Chris@0 2448 }
Chris@0 2449 } else {
Chris@0 2450 QMessageBox::critical(this, tr("Failed to write file"), error);
Chris@0 2451 }
Chris@0 2452 }
Chris@0 2453
Chris@0 2454 void
Chris@0 2455 MainWindow::importLayer()
Chris@0 2456 {
Chris@0 2457 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 2458
Chris@0 2459 if (!pane) {
Chris@0 2460 // shouldn't happen, as the menu action should have been disabled
Chris@0 2461 std::cerr << "WARNING: MainWindow::importLayer: no current pane" << std::endl;
Chris@0 2462 return;
Chris@0 2463 }
Chris@0 2464
Chris@0 2465 if (!getMainModel()) {
Chris@0 2466 // shouldn't happen, as the menu action should have been disabled
Chris@0 2467 std::cerr << "WARNING: MainWindow::importLayer: No main model -- hence no default sample rate available" << std::endl;
Chris@0 2468 return;
Chris@0 2469 }
Chris@0 2470
Chris@88 2471 QString path = getOpenFileName(FileFinder::LayerFile);
Chris@0 2472
Chris@0 2473 if (path != "") {
Chris@0 2474
Chris@197 2475 FileOpenStatus status = openLayer(path);
Chris@193 2476
Chris@193 2477 if (status == FileOpenFailed) {
Chris@247 2478 emit hideSplash();
Chris@0 2479 QMessageBox::critical(this, tr("Failed to open file"),
Chris@193 2480 tr("<b>File open failed</b><p>Layer file %1 could not be opened.").arg(path));
Chris@0 2481 return;
Chris@193 2482 } else if (status == FileOpenWrongMode) {
Chris@247 2483 emit hideSplash();
Chris@193 2484 QMessageBox::critical(this, tr("Failed to open file"),
Chris@294 2485 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 2486 }
Chris@0 2487 }
Chris@0 2488 }
Chris@0 2489
Chris@0 2490 void
Chris@0 2491 MainWindow::exportLayer()
Chris@0 2492 {
Chris@0 2493 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 2494 if (!pane) return;
Chris@0 2495
Chris@0 2496 Layer *layer = pane->getSelectedLayer();
Chris@0 2497 if (!layer) return;
Chris@0 2498
Chris@0 2499 Model *model = layer->getModel();
Chris@0 2500 if (!model) return;
Chris@0 2501
Chris@185 2502 FileFinder::FileType type = FileFinder::LayerFileNoMidi;
Chris@185 2503
Chris@185 2504 if (dynamic_cast<NoteModel *>(model)) type = FileFinder::LayerFile;
Chris@185 2505
Chris@185 2506 QString path = getSaveFileName(type);
Chris@0 2507
Chris@0 2508 if (path == "") return;
Chris@0 2509
Chris@0 2510 if (QFileInfo(path).suffix() == "") path += ".svl";
Chris@0 2511
Chris@185 2512 QString suffix = QFileInfo(path).suffix().toLower();
Chris@185 2513
Chris@0 2514 QString error;
Chris@0 2515
Chris@185 2516 if (suffix == "xml" || suffix == "svl") {
Chris@0 2517
Chris@0 2518 QFile file(path);
Chris@0 2519 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
Chris@0 2520 error = tr("Failed to open file %1 for writing").arg(path);
Chris@0 2521 } else {
Chris@0 2522 QTextStream out(&file);
Chris@0 2523 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
Chris@0 2524 << "<!DOCTYPE sonic-visualiser>\n"
Chris@0 2525 << "<sv>\n"
Chris@0 2526 << " <data>\n";
Chris@0 2527
Chris@0 2528 model->toXml(out, " ");
Chris@0 2529
Chris@0 2530 out << " </data>\n"
Chris@0 2531 << " <display>\n";
Chris@0 2532
Chris@0 2533 layer->toXml(out, " ");
Chris@0 2534
Chris@0 2535 out << " </display>\n"
Chris@0 2536 << "</sv>\n";
Chris@0 2537 }
Chris@0 2538
Chris@185 2539 } else if (suffix == "mid" || suffix == "midi") {
Chris@185 2540
Chris@185 2541 NoteModel *nm = dynamic_cast<NoteModel *>(model);
Chris@185 2542
Chris@185 2543 if (!nm) {
Chris@185 2544 error = tr("Can't export non-note layers to MIDI");
Chris@185 2545 } else {
Chris@185 2546 MIDIFileWriter writer(path, nm);
Chris@185 2547 writer.write();
Chris@185 2548 if (!writer.isOK()) {
Chris@185 2549 error = writer.getError();
Chris@185 2550 }
Chris@185 2551 }
Chris@185 2552
Chris@291 2553 } else if (suffix == "ttl" || suffix == "n3") {
Chris@291 2554
Chris@291 2555 RDFExporter exporter(path, model);
Chris@291 2556 exporter.write();
Chris@291 2557 if (!exporter.isOK()) {
Chris@291 2558 error = exporter.getError();
Chris@291 2559 }
Chris@291 2560
Chris@0 2561 } else {
Chris@0 2562
Chris@0 2563 CSVFileWriter writer(path, model,
Chris@185 2564 ((suffix == "csv") ? "," : "\t"));
Chris@0 2565 writer.write();
Chris@0 2566
Chris@0 2567 if (!writer.isOK()) {
Chris@0 2568 error = writer.getError();
Chris@0 2569 }
Chris@0 2570 }
Chris@0 2571
Chris@0 2572 if (error != "") {
Chris@0 2573 QMessageBox::critical(this, tr("Failed to write file"), error);
Chris@0 2574 } else {
Chris@34 2575 m_recentFiles.addFile(path);
Chris@310 2576 emit activity(tr("Export layer to \"%1\"").arg(path));
Chris@0 2577 }
Chris@0 2578 }
Chris@0 2579
Chris@121 2580 void
Chris@121 2581 MainWindow::exportImage()
Chris@121 2582 {
Chris@121 2583 Pane *pane = m_paneStack->getCurrentPane();
Chris@121 2584 if (!pane) return;
Chris@121 2585
Chris@121 2586 QString path = getSaveFileName(FileFinder::ImageFile);
Chris@121 2587
Chris@121 2588 if (path == "") return;
Chris@121 2589
Chris@121 2590 if (QFileInfo(path).suffix() == "") path += ".png";
Chris@121 2591
Chris@123 2592 bool haveSelection = m_viewManager && !m_viewManager->getSelections().empty();
Chris@123 2593
Chris@123 2594 QSize total, visible, selected;
Chris@123 2595 total = pane->getImageSize();
Chris@123 2596 visible = pane->getImageSize(pane->getFirstVisibleFrame(),
Chris@123 2597 pane->getLastVisibleFrame());
Chris@123 2598
Chris@123 2599 size_t sf0 = 0, sf1 = 0;
Chris@123 2600
Chris@123 2601 if (haveSelection) {
Chris@123 2602 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@123 2603 sf0 = selections.begin()->getStartFrame();
Chris@123 2604 MultiSelection::SelectionList::iterator e = selections.end();
Chris@123 2605 --e;
Chris@123 2606 sf1 = e->getEndFrame();
Chris@123 2607 selected = pane->getImageSize(sf0, sf1);
Chris@123 2608 }
Chris@123 2609
Chris@123 2610 QStringList items;
Chris@125 2611 items << tr("Export the whole pane (%1x%2 pixels)")
Chris@123 2612 .arg(total.width()).arg(total.height());
Chris@123 2613 items << tr("Export the visible area only (%1x%2 pixels)")
Chris@123 2614 .arg(visible.width()).arg(visible.height());
Chris@123 2615 if (haveSelection) {
Chris@123 2616 items << tr("Export the selection extent (%1x%2 pixels)")
Chris@123 2617 .arg(selected.width()).arg(selected.height());
Chris@124 2618 } else {
Chris@124 2619 items << tr("Export the selection extent");
Chris@123 2620 }
Chris@123 2621
Chris@123 2622 QSettings settings;
Chris@123 2623 settings.beginGroup("MainWindow");
Chris@123 2624 int deflt = settings.value("lastimageexportregion", 0).toInt();
Chris@123 2625 if (deflt == 2 && !haveSelection) deflt = 1;
Chris@124 2626 if (deflt == 0 && total.width() > 32767) deflt = 1;
Chris@124 2627
Chris@124 2628 ListInputDialog *lid = new ListInputDialog
Chris@123 2629 (this, tr("Select region to export"),
Chris@123 2630 tr("Which region of the current pane do you want to export as an image?"),
Chris@124 2631 items, deflt);
Chris@124 2632
Chris@124 2633 if (!haveSelection) {
Chris@124 2634 lid->setItemAvailability(2, false);
Chris@124 2635 }
Chris@124 2636 if (total.width() > 32767) { // appears to be the limit of a QImage
Chris@124 2637 lid->setItemAvailability(0, false);
Chris@124 2638 lid->setFootnote(tr("Note: the whole pane is too wide to be exported as a single image."));
Chris@124 2639 }
Chris@124 2640
Chris@124 2641 bool ok = lid->exec();
Chris@124 2642 QString item = lid->getCurrentString();
Chris@124 2643 delete lid;
Chris@123 2644
Chris@123 2645 if (!ok || item.isEmpty()) return;
Chris@123 2646
Chris@123 2647 settings.setValue("lastimageexportregion", deflt);
Chris@123 2648
Chris@123 2649 QImage *image = 0;
Chris@123 2650
Chris@123 2651 if (item == items[0]) {
Chris@123 2652 image = pane->toNewImage();
Chris@123 2653 } else if (item == items[1]) {
Chris@123 2654 image = pane->toNewImage(pane->getFirstVisibleFrame(),
Chris@123 2655 pane->getLastVisibleFrame());
Chris@123 2656 } else if (haveSelection) {
Chris@123 2657 image = pane->toNewImage(sf0, sf1);
Chris@123 2658 }
Chris@123 2659
Chris@121 2660 if (!image) return;
Chris@121 2661
Chris@121 2662 if (!image->save(path, "PNG")) {
Chris@121 2663 QMessageBox::critical(this, tr("Failed to save image file"),
Chris@121 2664 tr("Failed to save image file %1").arg(path));
Chris@121 2665 }
Chris@121 2666
Chris@121 2667 delete image;
Chris@121 2668 }
Chris@121 2669
Chris@0 2670 void
Chris@0 2671 MainWindow::newSession()
Chris@0 2672 {
Chris@0 2673 if (!checkSaveModified()) return;
Chris@0 2674
Chris@0 2675 closeSession();
Chris@0 2676 createDocument();
Chris@0 2677
Chris@0 2678 Pane *pane = m_paneStack->addPane();
Chris@0 2679
Chris@90 2680 connect(pane, SIGNAL(contextHelpChanged(const QString &)),
Chris@116 2681 this, SLOT(contextHelpChanged(const QString &)));
Chris@90 2682
Chris@0 2683 if (!m_timeRulerLayer) {
Chris@0 2684 m_timeRulerLayer = m_document->createMainModelLayer
Chris@0 2685 (LayerFactory::TimeRuler);
Chris@0 2686 }
Chris@0 2687
Chris@0 2688 m_document->addLayerToView(pane, m_timeRulerLayer);
Chris@0 2689
Chris@0 2690 Layer *waveform = m_document->createMainModelLayer(LayerFactory::Waveform);
Chris@0 2691 m_document->addLayerToView(pane, waveform);
Chris@0 2692
Chris@65 2693 m_overview->registerView(pane);
Chris@0 2694
Chris@0 2695 CommandHistory::getInstance()->clear();
Chris@0 2696 CommandHistory::getInstance()->documentSaved();
Chris@0 2697 documentRestored();
Chris@0 2698 updateMenuStates();
Chris@0 2699 }
Chris@0 2700
Chris@0 2701 void
Chris@303 2702 MainWindow::documentReplaced()
Chris@303 2703 {
Chris@303 2704 if (m_document) {
Chris@303 2705 connect(m_document, SIGNAL(activity(QString)),
Chris@303 2706 m_activityLog, SLOT(activityHappened(QString)));
Chris@303 2707 }
Chris@303 2708 }
Chris@303 2709
Chris@303 2710 void
Chris@0 2711 MainWindow::closeSession()
Chris@0 2712 {
Chris@0 2713 if (!checkSaveModified()) return;
Chris@0 2714
Chris@0 2715 while (m_paneStack->getPaneCount() > 0) {
Chris@0 2716
Chris@0 2717 Pane *pane = m_paneStack->getPane(m_paneStack->getPaneCount() - 1);
Chris@0 2718
Chris@0 2719 while (pane->getLayerCount() > 0) {
Chris@0 2720 m_document->removeLayerFromView
Chris@0 2721 (pane, pane->getLayer(pane->getLayerCount() - 1));
Chris@0 2722 }
Chris@0 2723
Chris@65 2724 m_overview->unregisterView(pane);
Chris@0 2725 m_paneStack->deletePane(pane);
Chris@0 2726 }
Chris@0 2727
Chris@0 2728 while (m_paneStack->getHiddenPaneCount() > 0) {
Chris@0 2729
Chris@0 2730 Pane *pane = m_paneStack->getHiddenPane
Chris@0 2731 (m_paneStack->getHiddenPaneCount() - 1);
Chris@0 2732
Chris@0 2733 while (pane->getLayerCount() > 0) {
Chris@0 2734 m_document->removeLayerFromView
Chris@0 2735 (pane, pane->getLayer(pane->getLayerCount() - 1));
Chris@0 2736 }
Chris@0 2737
Chris@65 2738 m_overview->unregisterView(pane);
Chris@0 2739 m_paneStack->deletePane(pane);
Chris@0 2740 }
Chris@0 2741
Chris@0 2742 delete m_document;
Chris@0 2743 m_document = 0;
Chris@0 2744 m_viewManager->clearSelections();
Chris@0 2745 m_timeRulerLayer = 0; // document owned this
Chris@0 2746
Chris@0 2747 m_sessionFile = "";
Chris@0 2748 setWindowTitle(tr("Sonic Visualiser"));
Chris@0 2749
Chris@0 2750 CommandHistory::getInstance()->clear();
Chris@0 2751 CommandHistory::getInstance()->documentSaved();
Chris@0 2752 documentRestored();
Chris@0 2753 }
Chris@0 2754
Chris@0 2755 void
Chris@0 2756 MainWindow::openSession()
Chris@0 2757 {
Chris@0 2758 if (!checkSaveModified()) return;
Chris@0 2759
Chris@0 2760 QString orig = m_audioFile;
Chris@0 2761 if (orig == "") orig = ".";
Chris@0 2762 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 2763
Chris@88 2764 QString path = getOpenFileName(FileFinder::SessionFile);
Chris@0 2765
Chris@0 2766 if (path.isEmpty()) return;
Chris@0 2767
Chris@200 2768 if (openSessionFile(path) == FileOpenFailed) {
Chris@247 2769 emit hideSplash();
Chris@0 2770 QMessageBox::critical(this, tr("Failed to open file"),
Chris@193 2771 tr("<b>File open failed</b><p>Session file \"%1\" could not be opened").arg(path));
Chris@0 2772 }
Chris@0 2773 }
Chris@0 2774
Chris@0 2775 void
Chris@0 2776 MainWindow::openSomething()
Chris@0 2777 {
Chris@0 2778 QString orig = m_audioFile;
Chris@0 2779 if (orig == "") orig = ".";
Chris@0 2780 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 2781
Chris@88 2782 QString path = getOpenFileName(FileFinder::AnyFile);
Chris@0 2783
Chris@0 2784 if (path.isEmpty()) return;
Chris@0 2785
Chris@422 2786 FileOpenStatus status = open(path, ReplaceSession);
Chris@193 2787
Chris@193 2788 if (status == FileOpenFailed) {
Chris@247 2789 emit hideSplash();
Chris@193 2790 QMessageBox::critical(this, tr("Failed to open file"),
Chris@193 2791 tr("<b>File open failed</b><p>File \"%1\" could not be opened").arg(path));
Chris@193 2792 } else if (status == FileOpenWrongMode) {
Chris@247 2793 emit hideSplash();
Chris@193 2794 QMessageBox::critical(this, tr("Failed to open file"),
Chris@294 2795 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 2796 }
Chris@0 2797 }
Chris@0 2798
Chris@0 2799 void
Chris@86 2800 MainWindow::openLocation()
Chris@86 2801 {
Chris@103 2802 QSettings settings;
Chris@103 2803 settings.beginGroup("MainWindow");
Chris@103 2804 QString lastLocation = settings.value("lastremote", "").toString();
Chris@103 2805
Chris@86 2806 bool ok = false;
Chris@86 2807 QString text = QInputDialog::getText
Chris@86 2808 (this, tr("Open Location"),
Chris@86 2809 tr("Please enter the URL of the location to open:"),
Chris@103 2810 QLineEdit::Normal, lastLocation, &ok);
Chris@103 2811
Chris@103 2812 if (!ok) return;
Chris@103 2813
Chris@103 2814 settings.setValue("lastremote", text);
Chris@103 2815
Chris@103 2816 if (text.isEmpty()) return;
Chris@86 2817
Chris@419 2818 FileOpenStatus status = open(text, AskUser);
Chris@193 2819
Chris@193 2820 if (status == FileOpenFailed) {
Chris@247 2821 emit hideSplash();
Chris@86 2822 QMessageBox::critical(this, tr("Failed to open location"),
Chris@193 2823 tr("<b>Open failed</b><p>URL \"%1\" could not be opened").arg(text));
Chris@193 2824 } else if (status == FileOpenWrongMode) {
Chris@247 2825 emit hideSplash();
Chris@193 2826 QMessageBox::critical(this, tr("Failed to open location"),
Chris@294 2827 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 2828 }
Chris@86 2829 }
Chris@86 2830
Chris@86 2831 void
Chris@0 2832 MainWindow::openRecentFile()
Chris@0 2833 {
Chris@0 2834 QObject *obj = sender();
Chris@0 2835 QAction *action = dynamic_cast<QAction *>(obj);
Chris@0 2836
Chris@0 2837 if (!action) {
Chris@0 2838 std::cerr << "WARNING: MainWindow::openRecentFile: sender is not an action"
Chris@0 2839 << std::endl;
Chris@0 2840 return;
Chris@0 2841 }
Chris@0 2842
Chris@0 2843 QString path = action->text();
Chris@0 2844 if (path == "") return;
Chris@0 2845
Chris@422 2846 FileOpenStatus status = open(path, ReplaceSession);
Chris@193 2847
Chris@193 2848 if (status == FileOpenFailed) {
Chris@247 2849 emit hideSplash();
Chris@193 2850 QMessageBox::critical(this, tr("Failed to open location"),
Chris@193 2851 tr("<b>Open failed</b><p>File or URL \"%1\" could not be opened").arg(path));
Chris@193 2852 } else if (status == FileOpenWrongMode) {
Chris@247 2853 emit hideSplash();
Chris@193 2854 QMessageBox::critical(this, tr("Failed to open location"),
Chris@294 2855 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 2856 }
Chris@0 2857 }
Chris@0 2858
Chris@0 2859 void
Chris@423 2860 MainWindow::changeTemplate()
Chris@423 2861 {
Chris@425 2862 QObject *s = sender();
Chris@425 2863 QAction *action = qobject_cast<QAction *>(s);
Chris@425 2864
Chris@425 2865 if (!action) {
Chris@425 2866 std::cerr << "WARNING: MainWindow::changeTemplate: sender is not an action"
Chris@425 2867 << std::endl;
Chris@425 2868 return;
Chris@425 2869 }
Chris@425 2870
Chris@425 2871 QString n = action->objectName();
Chris@425 2872 if (n == "") n = action->text();
Chris@425 2873
Chris@425 2874 if (n == "") {
Chris@425 2875 std::cerr << "WARNING: MainWindow::changeTemplate: sender has no name"
Chris@425 2876 << std::endl;
Chris@425 2877 return;
Chris@425 2878 }
Chris@425 2879
Chris@425 2880 setDefaultSessionTemplate(n);
Chris@427 2881
Chris@427 2882 QSettings settings;
Chris@427 2883 settings.beginGroup("MainWindow");
Chris@427 2884 settings.setValue("sessiontemplate", n);
Chris@427 2885 settings.endGroup();
Chris@425 2886 }
Chris@425 2887
Chris@425 2888 void
Chris@425 2889 MainWindow::saveSessionAsTemplate()
Chris@425 2890 {
Chris@425 2891 QString name = QInputDialog::getText
Chris@425 2892 (this, tr("Enter template name"),
Chris@425 2893 tr("Please enter a name for the saved template:"));
Chris@425 2894 if (name == "") return;
Chris@425 2895
Chris@431 2896 name.replace(QRegExp("[^\\w\\s\\.\"'-]"), "_");
Chris@426 2897
Chris@426 2898 ResourceFinder rf;
Chris@426 2899 QString dir = rf.getResourceSaveDir("templates");
Chris@431 2900 QString filename = QString("%1/%2.svt").arg(dir).arg(name);
Chris@431 2901 if (QFile(filename).exists()) {
Chris@431 2902 if (QMessageBox::warning(this,
Chris@431 2903 tr("Template file exists"),
Chris@431 2904 tr("<b>Template file exists</b><p>The template \"%1\" already exists.<br>Overwrite it?").arg(name),
Chris@431 2905 QMessageBox::Ok | QMessageBox::Cancel,
Chris@431 2906 QMessageBox::Cancel) != QMessageBox::Ok) {
Chris@431 2907 return;
Chris@431 2908 }
Chris@431 2909 }
Chris@431 2910
Chris@431 2911 saveSessionTemplate(filename);
Chris@425 2912 }
Chris@425 2913
Chris@425 2914 void
Chris@425 2915 MainWindow::manageSavedTemplates()
Chris@425 2916 {
Chris@425 2917 ResourceFinder rf;
Chris@425 2918 QDesktopServices::openUrl("file:" + rf.getResourceSaveDir("templates"));
Chris@423 2919 }
Chris@423 2920
Chris@423 2921 void
Chris@200 2922 MainWindow::paneAdded(Pane *pane)
Chris@200 2923 {
Chris@200 2924 if (m_overview) m_overview->registerView(pane);
Chris@200 2925 }
Chris@200 2926
Chris@200 2927 void
Chris@200 2928 MainWindow::paneHidden(Pane *pane)
Chris@200 2929 {
Chris@200 2930 if (m_overview) m_overview->unregisterView(pane);
Chris@200 2931 }
Chris@200 2932
Chris@200 2933 void
Chris@200 2934 MainWindow::paneAboutToBeDeleted(Pane *pane)
Chris@200 2935 {
Chris@200 2936 if (m_overview) m_overview->unregisterView(pane);
Chris@200 2937 }
Chris@200 2938
Chris@200 2939 void
Chris@193 2940 MainWindow::paneDropAccepted(Pane *pane, QStringList uriList)
Chris@193 2941 {
Chris@193 2942 if (pane) m_paneStack->setCurrentPane(pane);
Chris@193 2943
Chris@193 2944 for (QStringList::iterator i = uriList.begin(); i != uriList.end(); ++i) {
Chris@193 2945
Chris@295 2946 FileOpenStatus status;
Chris@295 2947
Chris@295 2948 if (i == uriList.begin()) {
Chris@295 2949 status = open(*i, ReplaceCurrentPane);
Chris@295 2950 } else {
Chris@295 2951 status = open(*i, CreateAdditionalModel);
Chris@295 2952 }
Chris@193 2953
Chris@193 2954 if (status == FileOpenFailed) {
Chris@247 2955 emit hideSplash();
Chris@193 2956 QMessageBox::critical(this, tr("Failed to open dropped URL"),
Chris@193 2957 tr("<b>Open failed</b><p>Dropped URL \"%1\" could not be opened").arg(*i));
Chris@295 2958 break;
Chris@193 2959 } else if (status == FileOpenWrongMode) {
Chris@247 2960 emit hideSplash();
Chris@193 2961 QMessageBox::critical(this, tr("Failed to open dropped URL"),
Chris@294 2962 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 2963 break;
Chris@295 2964 } else if (status == FileOpenCancelled) {
Chris@295 2965 break;
Chris@193 2966 }
Chris@193 2967 }
Chris@193 2968 }
Chris@193 2969
Chris@193 2970 void
Chris@193 2971 MainWindow::paneDropAccepted(Pane *pane, QString text)
Chris@193 2972 {
Chris@193 2973 if (pane) m_paneStack->setCurrentPane(pane);
Chris@193 2974
Chris@193 2975 QUrl testUrl(text);
Chris@193 2976 if (testUrl.scheme() == "file" ||
Chris@193 2977 testUrl.scheme() == "http" ||
Chris@193 2978 testUrl.scheme() == "ftp") {
Chris@193 2979 QStringList list;
Chris@193 2980 list.push_back(text);
Chris@193 2981 paneDropAccepted(pane, list);
Chris@193 2982 return;
Chris@193 2983 }
Chris@193 2984
Chris@193 2985 //!!! open as text -- but by importing as if a CSV, or just adding
Chris@193 2986 //to a text layer?
Chris@193 2987 }
Chris@193 2988
Chris@193 2989 void
Chris@0 2990 MainWindow::closeEvent(QCloseEvent *e)
Chris@0 2991 {
Chris@137 2992 // std::cerr << "MainWindow::closeEvent" << std::endl;
Chris@118 2993
Chris@136 2994 if (m_openingAudioFile) {
Chris@137 2995 // std::cerr << "Busy - ignoring close event" << std::endl;
Chris@136 2996 e->ignore();
Chris@136 2997 return;
Chris@136 2998 }
Chris@136 2999
Chris@70 3000 if (!m_abandoning && !checkSaveModified()) {
Chris@137 3001 // std::cerr << "Ignoring close event" << std::endl;
Chris@0 3002 e->ignore();
Chris@0 3003 return;
Chris@0 3004 }
Chris@0 3005
Chris@5 3006 QSettings settings;
Chris@5 3007 settings.beginGroup("MainWindow");
Chris@5 3008 settings.setValue("size", size());
Chris@5 3009 settings.setValue("position", pos());
Chris@5 3010 settings.endGroup();
Chris@5 3011
Chris@163 3012 delete m_keyReference;
Chris@163 3013 m_keyReference = 0;
Chris@163 3014
Chris@163 3015 if (m_preferencesDialog &&
Chris@163 3016 m_preferencesDialog->isVisible()) {
Chris@164 3017 closeSession(); // otherwise we'll have to wait for prefs changes
Chris@163 3018 m_preferencesDialog->applicationClosing(false);
Chris@163 3019 }
Chris@163 3020
Chris@200 3021 closeSession();
Chris@200 3022
Chris@0 3023 e->accept();
Chris@0 3024 return;
Chris@0 3025 }
Chris@0 3026
Chris@0 3027 bool
Chris@11 3028 MainWindow::commitData(bool mayAskUser)
Chris@11 3029 {
Chris@11 3030 if (mayAskUser) {
Chris@163 3031 bool rv = checkSaveModified();
Chris@163 3032 if (rv) {
Chris@163 3033 if (m_preferencesDialog &&
Chris@163 3034 m_preferencesDialog->isVisible()) {
Chris@163 3035 m_preferencesDialog->applicationClosing(false);
Chris@163 3036 }
Chris@163 3037 }
Chris@163 3038 return rv;
Chris@11 3039 } else {
Chris@163 3040 if (m_preferencesDialog &&
Chris@163 3041 m_preferencesDialog->isVisible()) {
Chris@163 3042 m_preferencesDialog->applicationClosing(true);
Chris@163 3043 }
Chris@11 3044 if (!m_documentModified) return true;
Chris@11 3045
Chris@11 3046 // If we can't check with the user first, then we can't save
Chris@11 3047 // to the original session file (even if we have it) -- have
Chris@11 3048 // to use a temporary file
Chris@11 3049
Chris@11 3050 QString svDirBase = ".sv1";
Chris@11 3051 QString svDir = QDir::home().filePath(svDirBase);
Chris@11 3052
Chris@11 3053 if (!QFileInfo(svDir).exists()) {
Chris@11 3054 if (!QDir::home().mkdir(svDirBase)) return false;
Chris@11 3055 } else {
Chris@11 3056 if (!QFileInfo(svDir).isDir()) return false;
Chris@11 3057 }
Chris@11 3058
Chris@11 3059 // This name doesn't have to be unguessable
Chris@93 3060 #ifndef _WIN32
Chris@11 3061 QString fname = QString("tmp-%1-%2.sv")
Chris@11 3062 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"))
Chris@11 3063 .arg(QProcess().pid());
Chris@93 3064 #else
Chris@93 3065 QString fname = QString("tmp-%1.sv")
Chris@93 3066 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"));
Chris@93 3067 #endif
Chris@11 3068 QString fpath = QDir(svDir).filePath(fname);
Chris@11 3069 if (saveSessionFile(fpath)) {
Chris@34 3070 m_recentFiles.addFile(fpath);
Chris@310 3071 emit activity(tr("Export image to \"%1\"").arg(fpath));
Chris@11 3072 return true;
Chris@11 3073 } else {
Chris@11 3074 return false;
Chris@11 3075 }
Chris@11 3076 }
Chris@11 3077 }
Chris@11 3078
Chris@11 3079 bool
Chris@0 3080 MainWindow::checkSaveModified()
Chris@0 3081 {
Chris@0 3082 // Called before some destructive operation (e.g. new session,
Chris@0 3083 // exit program). Return true if we can safely proceed, false to
Chris@0 3084 // cancel.
Chris@0 3085
Chris@0 3086 if (!m_documentModified) return true;
Chris@0 3087
Chris@247 3088 emit hideSplash();
Chris@247 3089
Chris@0 3090 int button =
Chris@0 3091 QMessageBox::warning(this,
Chris@0 3092 tr("Session modified"),
Chris@207 3093 tr("<b>Session modified</b><p>The current session has been modified.<br>Do you want to save it?"),
Chris@165 3094 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
Chris@165 3095 QMessageBox::Yes);
Chris@0 3096
Chris@0 3097 if (button == QMessageBox::Yes) {
Chris@0 3098 saveSession();
Chris@0 3099 if (m_documentModified) { // save failed -- don't proceed!
Chris@0 3100 return false;
Chris@0 3101 } else {
Chris@0 3102 return true; // saved, so it's safe to continue now
Chris@0 3103 }
Chris@0 3104 } else if (button == QMessageBox::No) {
Chris@0 3105 m_documentModified = false; // so we know to abandon it
Chris@0 3106 return true;
Chris@0 3107 }
Chris@0 3108
Chris@0 3109 // else cancel
Chris@0 3110 return false;
Chris@0 3111 }
Chris@0 3112
Chris@290 3113 bool
Chris@294 3114 MainWindow::shouldCreateNewSessionForRDFAudio(bool *cancel)
Chris@290 3115 {
Chris@294 3116 //!!! This is very similar to part of MainWindowBase::openAudio --
Chris@294 3117 //!!! make them a bit more uniform
Chris@294 3118
Chris@294 3119 QSettings settings;
Chris@294 3120 settings.beginGroup("MainWindow");
Chris@294 3121 bool prevNewSession = settings.value("newsessionforrdfaudio", true).toBool();
Chris@294 3122 settings.endGroup();
Chris@294 3123 bool newSession = true;
Chris@294 3124
Chris@294 3125 QStringList items;
Chris@294 3126 items << tr("Close the current session and create a new one")
Chris@294 3127 << tr("Add this data to the current session");
Chris@294 3128
Chris@294 3129 bool ok = false;
Chris@294 3130 QString item = ListInputDialog::getItem
Chris@294 3131 (this, tr("Select target for import"),
Chris@294 3132 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 3133 items, prevNewSession ? 0 : 1, &ok);
Chris@294 3134
Chris@294 3135 if (!ok || item.isEmpty()) {
Chris@294 3136 *cancel = true;
Chris@290 3137 return false;
Chris@290 3138 }
Chris@294 3139
Chris@294 3140 newSession = (item == items[0]);
Chris@294 3141 settings.beginGroup("MainWindow");
Chris@294 3142 settings.setValue("newsessionforrdfaudio", newSession);
Chris@294 3143 settings.endGroup();
Chris@294 3144
Chris@294 3145 if (newSession) return true;
Chris@294 3146 else return false;
Chris@290 3147 }
Chris@290 3148
Chris@0 3149 void
Chris@0 3150 MainWindow::saveSession()
Chris@0 3151 {
Chris@0 3152 if (m_sessionFile != "") {
Chris@0 3153 if (!saveSessionFile(m_sessionFile)) {
Chris@0 3154 QMessageBox::critical(this, tr("Failed to save file"),
Chris@193 3155 tr("<b>Save failed</b><p>Session file \"%1\" could not be saved.").arg(m_sessionFile));
Chris@0 3156 } else {
Chris@0 3157 CommandHistory::getInstance()->documentSaved();
Chris@0 3158 documentRestored();
Chris@0 3159 }
Chris@0 3160 } else {
Chris@0 3161 saveSessionAs();
Chris@0 3162 }
Chris@0 3163 }
Chris@0 3164
Chris@0 3165 void
Chris@0 3166 MainWindow::saveSessionAs()
Chris@0 3167 {
Chris@0 3168 QString orig = m_audioFile;
Chris@0 3169 if (orig == "") orig = ".";
Chris@0 3170 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 3171
Chris@88 3172 QString path = getSaveFileName(FileFinder::SessionFile);
Chris@81 3173
Chris@81 3174 if (path == "") return;
Chris@0 3175
Chris@0 3176 if (!saveSessionFile(path)) {
Chris@0 3177 QMessageBox::critical(this, tr("Failed to save file"),
Chris@193 3178 tr("<b>Save failed</b><p>Session file \"%1\" could not be saved.").arg(path));
Chris@0 3179 } else {
Chris@0 3180 setWindowTitle(tr("Sonic Visualiser: %1")
Chris@0 3181 .arg(QFileInfo(path).fileName()));
Chris@0 3182 m_sessionFile = path;
Chris@0 3183 CommandHistory::getInstance()->documentSaved();
Chris@0 3184 documentRestored();
Chris@34 3185 m_recentFiles.addFile(path);
Chris@310 3186 emit activity(tr("Save session as \"%1\"").arg(path));
Chris@0 3187 }
Chris@0 3188 }
Chris@0 3189
Chris@90 3190 void
Chris@72 3191 MainWindow::preferenceChanged(PropertyContainer::PropertyName name)
Chris@72 3192 {
Chris@200 3193 MainWindowBase::preferenceChanged(name);
Chris@200 3194
Chris@200 3195 if (name == "Background Mode" && m_viewManager) {
Chris@180 3196 if (m_viewManager->getGlobalDarkBackground()) {
Chris@180 3197 m_panLayer->setBaseColour
Chris@180 3198 (ColourDatabase::getInstance()->getColourIndex(tr("Bright Green")));
Chris@180 3199 } else {
Chris@180 3200 m_panLayer->setBaseColour
Chris@180 3201 (ColourDatabase::getInstance()->getColourIndex(tr("Green")));
Chris@180 3202 }
Chris@200 3203 }
Chris@0 3204 }
Chris@0 3205
Chris@0 3206 void
Chris@239 3207 MainWindow::propertyStacksResized(int width)
Chris@239 3208 {
Chris@251 3209 // std::cerr << "MainWindow::propertyStacksResized(" << width << ")" << std::endl;
Chris@239 3210
Chris@239 3211 if (!m_playControlsSpacer) return;
Chris@239 3212
Chris@239 3213 int spacerWidth = width - m_playControlsWidth - 4;
Chris@239 3214
Chris@251 3215 // std::cerr << "resizing spacer from " << m_playControlsSpacer->width() << " to " << spacerWidth << std::endl;
Chris@239 3216
Chris@239 3217 m_playControlsSpacer->setFixedSize(QSize(spacerWidth, 2));
Chris@239 3218 }
Chris@239 3219
Chris@239 3220 void
Chris@0 3221 MainWindow::addPane()
Chris@0 3222 {
Chris@0 3223 QObject *s = sender();
Chris@0 3224 QAction *action = dynamic_cast<QAction *>(s);
Chris@0 3225
Chris@0 3226 if (!action) {
Chris@0 3227 std::cerr << "WARNING: MainWindow::addPane: sender is not an action"
Chris@0 3228 << std::endl;
Chris@0 3229 return;
Chris@0 3230 }
Chris@0 3231
Chris@0 3232 PaneActionMap::iterator i = m_paneActions.find(action);
Chris@0 3233
Chris@0 3234 if (i == m_paneActions.end()) {
Chris@0 3235 std::cerr << "WARNING: MainWindow::addPane: unknown action "
Chris@0 3236 << action->objectName().toStdString() << std::endl;
Chris@0 3237 return;
Chris@0 3238 }
Chris@0 3239
Chris@69 3240 addPane(i->second, action->text());
Chris@69 3241 }
Chris@69 3242
Chris@69 3243 void
Chris@232 3244 MainWindow::addPane(const LayerConfiguration &configuration, QString text)
Chris@69 3245 {
Chris@69 3246 CommandHistory::getInstance()->startCompoundOperation(text, true);
Chris@0 3247
Chris@0 3248 AddPaneCommand *command = new AddPaneCommand(this);
Chris@0 3249 CommandHistory::getInstance()->addCommand(command);
Chris@0 3250
Chris@0 3251 Pane *pane = command->getPane();
Chris@0 3252
Chris@69 3253 if (configuration.layer == LayerFactory::Spectrum) {
Chris@109 3254 pane->setPlaybackFollow(PlaybackScrollContinuous);
Chris@110 3255 pane->setFollowGlobalZoom(false);
Chris@112 3256 pane->setZoomLevel(512);
Chris@7 3257 }
Chris@7 3258
Chris@69 3259 if (configuration.layer != LayerFactory::TimeRuler &&
Chris@69 3260 configuration.layer != LayerFactory::Spectrum) {
Chris@8 3261
Chris@0 3262 if (!m_timeRulerLayer) {
Chris@0 3263 // std::cerr << "no time ruler layer, creating one" << std::endl;
Chris@0 3264 m_timeRulerLayer = m_document->createMainModelLayer
Chris@0 3265 (LayerFactory::TimeRuler);
Chris@0 3266 }
Chris@0 3267
Chris@0 3268 // std::cerr << "adding time ruler layer " << m_timeRulerLayer << std::endl;
Chris@0 3269
Chris@0 3270 m_document->addLayerToView(pane, m_timeRulerLayer);
Chris@0 3271 }
Chris@0 3272
Chris@69 3273 Layer *newLayer = m_document->createLayer(configuration.layer);
Chris@69 3274
Chris@69 3275 Model *suggestedModel = configuration.sourceModel;
Chris@66 3276 Model *model = 0;
Chris@66 3277
Chris@66 3278 if (suggestedModel) {
Chris@66 3279
Chris@66 3280 // check its validity
Chris@224 3281 std::vector<Model *> inputModels = m_document->getTransformInputModels();
Chris@66 3282 for (size_t j = 0; j < inputModels.size(); ++j) {
Chris@66 3283 if (inputModels[j] == suggestedModel) {
Chris@66 3284 model = suggestedModel;
Chris@66 3285 break;
Chris@66 3286 }
Chris@66 3287 }
Chris@66 3288
Chris@66 3289 if (!model) {
Chris@66 3290 std::cerr << "WARNING: Model " << (void *)suggestedModel
Chris@66 3291 << " appears in pane action map, but is not reported "
Chris@66 3292 << "by document as a valid transform source" << std::endl;
Chris@66 3293 }
Chris@66 3294 }
Chris@66 3295
Chris@346 3296 if (!model) {
Chris@346 3297 model = m_document->getMainModel();
Chris@346 3298 }
Chris@66 3299
Chris@66 3300 m_document->setModel(newLayer, model);
Chris@66 3301
Chris@69 3302 m_document->setChannel(newLayer, configuration.channel);
Chris@0 3303 m_document->addLayerToView(pane, newLayer);
Chris@0 3304
Chris@0 3305 m_paneStack->setCurrentPane(pane);
Chris@70 3306 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 3307
Chris@130 3308 // std::cerr << "MainWindow::addPane: global centre frame is "
Chris@130 3309 // << m_viewManager->getGlobalCentreFrame() << std::endl;
Chris@130 3310 // pane->setCentreFrame(m_viewManager->getGlobalCentreFrame());
Chris@73 3311
Chris@0 3312 CommandHistory::getInstance()->endCompoundOperation();
Chris@0 3313
Chris@0 3314 updateMenuStates();
Chris@0 3315 }
Chris@0 3316
Chris@0 3317 void
Chris@0 3318 MainWindow::addLayer()
Chris@0 3319 {
Chris@0 3320 QObject *s = sender();
Chris@0 3321 QAction *action = dynamic_cast<QAction *>(s);
Chris@0 3322
Chris@0 3323 if (!action) {
Chris@0 3324 std::cerr << "WARNING: MainWindow::addLayer: sender is not an action"
Chris@0 3325 << std::endl;
Chris@0 3326 return;
Chris@0 3327 }
Chris@0 3328
Chris@0 3329 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 3330
Chris@0 3331 if (!pane) {
Chris@0 3332 std::cerr << "WARNING: MainWindow::addLayer: no current pane" << std::endl;
Chris@0 3333 return;
Chris@0 3334 }
Chris@0 3335
Chris@0 3336 ExistingLayerActionMap::iterator ei = m_existingLayerActions.find(action);
Chris@0 3337
Chris@0 3338 if (ei != m_existingLayerActions.end()) {
Chris@0 3339 Layer *newLayer = ei->second;
Chris@0 3340 m_document->addLayerToView(pane, newLayer);
Chris@0 3341 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 3342 return;
Chris@0 3343 }
Chris@0 3344
Chris@95 3345 ei = m_sliceActions.find(action);
Chris@95 3346
Chris@95 3347 if (ei != m_sliceActions.end()) {
Chris@95 3348 Layer *newLayer = m_document->createLayer(LayerFactory::Slice);
Chris@95 3349 // document->setModel(newLayer, ei->second->getModel());
Chris@95 3350 SliceableLayer *source = dynamic_cast<SliceableLayer *>(ei->second);
Chris@95 3351 SliceLayer *dest = dynamic_cast<SliceLayer *>(newLayer);
Chris@95 3352 if (source && dest) {
Chris@205 3353 //!!!???
Chris@95 3354 dest->setSliceableModel(source->getSliceableModel());
Chris@95 3355 connect(source, SIGNAL(sliceableModelReplaced(const Model *, const Model *)),
Chris@95 3356 dest, SLOT(sliceableModelReplaced(const Model *, const Model *)));
Chris@95 3357 connect(m_document, SIGNAL(modelAboutToBeDeleted(Model *)),
Chris@95 3358 dest, SLOT(modelAboutToBeDeleted(Model *)));
Chris@95 3359 }
Chris@95 3360 m_document->addLayerToView(pane, newLayer);
Chris@95 3361 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@95 3362 return;
Chris@95 3363 }
Chris@95 3364
Chris@211 3365 TransformActionMap::iterator i = m_transformActions.find(action);
Chris@34 3366
Chris@34 3367 if (i == m_transformActions.end()) {
Chris@0 3368
Chris@0 3369 LayerActionMap::iterator i = m_layerActions.find(action);
Chris@0 3370
Chris@0 3371 if (i == m_layerActions.end()) {
Chris@0 3372 std::cerr << "WARNING: MainWindow::addLayer: unknown action "
Chris@0 3373 << action->objectName().toStdString() << std::endl;
Chris@0 3374 return;
Chris@0 3375 }
Chris@0 3376
Chris@232 3377 LayerFactory::LayerType type = i->second.layer;
Chris@0 3378
Chris@0 3379 LayerFactory::LayerTypeSet emptyTypes =
Chris@0 3380 LayerFactory::getInstance()->getValidEmptyLayerTypes();
Chris@0 3381
Chris@0 3382 Layer *newLayer;
Chris@0 3383
Chris@0 3384 if (emptyTypes.find(type) != emptyTypes.end()) {
Chris@0 3385
Chris@0 3386 newLayer = m_document->createEmptyLayer(type);
Chris@217 3387 if (newLayer) {
Chris@217 3388 m_toolActions[ViewManager::DrawMode]->trigger();
Chris@217 3389 }
Chris@0 3390
Chris@0 3391 } else {
Chris@0 3392
Chris@346 3393 Model *model = i->second.sourceModel;
Chris@346 3394
Chris@415 3395 cerr << "model = "<< model << endl;
Chris@415 3396
Chris@346 3397 if (!model) {
Chris@346 3398 if (type == LayerFactory::TimeRuler) {
Chris@346 3399 newLayer = m_document->createMainModelLayer(type);
Chris@346 3400 } else {
Chris@346 3401 // if model is unspecified and this is not a
Chris@415 3402 // time-ruler layer, use any plausible model from
Chris@415 3403 // the current pane -- this is the case for
Chris@415 3404 // right-button menu layer additions
Chris@415 3405 Pane::ModelSet ms = pane->getModels();
Chris@415 3406 foreach (Model *m, ms) {
Chris@415 3407 RangeSummarisableTimeValueModel *r =
Chris@415 3408 dynamic_cast<RangeSummarisableTimeValueModel *>(m);
Chris@415 3409 if (r) model = m;
Chris@346 3410 }
Chris@346 3411 if (!model) model = getMainModel();
Chris@346 3412 }
Chris@346 3413 }
Chris@346 3414
Chris@346 3415 if (model) {
Chris@238 3416 newLayer = m_document->createLayer(type);
Chris@346 3417 if (m_document->isKnownModel(model)) {
Chris@238 3418 m_document->setChannel(newLayer, i->second.channel);
Chris@346 3419 m_document->setModel(newLayer, model);
Chris@238 3420 } else {
Chris@238 3421 std::cerr << "WARNING: MainWindow::addLayer: unknown model "
Chris@346 3422 << model
Chris@238 3423 << " (\""
Chris@346 3424 << (model ? model->objectName().toStdString() : "")
Chris@238 3425 << "\") in layer action map"
Chris@238 3426 << std::endl;
Chris@238 3427 }
Chris@232 3428 }
Chris@238 3429 }
Chris@0 3430
Chris@217 3431 if (newLayer) {
Chris@217 3432 m_document->addLayerToView(pane, newLayer);
Chris@217 3433 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@217 3434 }
Chris@0 3435
Chris@0 3436 return;
Chris@0 3437 }
Chris@0 3438
Chris@224 3439 //!!! want to do something like this, but it's not supported in
Chris@224 3440 //ModelTransformerFactory yet
Chris@224 3441 /*
Chris@0 3442 int channel = -1;
Chris@0 3443 // pick up the default channel from any existing layers on the same pane
Chris@0 3444 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@0 3445 int c = LayerFactory::getInstance()->getChannel(pane->getLayer(j));
Chris@0 3446 if (c != -1) {
Chris@0 3447 channel = c;
Chris@0 3448 break;
Chris@0 3449 }
Chris@0 3450 }
Chris@224 3451 */
Chris@0 3452
Chris@33 3453 // We always ask for configuration, even if the plugin isn't
Chris@33 3454 // supposed to be configurable, because we need to let the user
Chris@33 3455 // change the execution context (block size etc).
Chris@0 3456
Chris@224 3457 QString transformId = i->second;
Chris@274 3458
Chris@274 3459 addLayer(transformId);
Chris@274 3460 }
Chris@274 3461
Chris@274 3462 void
Chris@274 3463 MainWindow::addLayer(QString transformId)
Chris@274 3464 {
Chris@274 3465 Pane *pane = m_paneStack->getCurrentPane();
Chris@274 3466 if (!pane) {
Chris@274 3467 std::cerr << "WARNING: MainWindow::addLayer: no current pane" << std::endl;
Chris@274 3468 return;
Chris@274 3469 }
Chris@274 3470
Chris@224 3471 Transform transform = TransformFactory::getInstance()->
Chris@224 3472 getDefaultTransformFor(transformId);
Chris@27 3473
Chris@66 3474 std::vector<Model *> candidateInputModels =
Chris@224 3475 m_document->getTransformInputModels();
Chris@53 3476
Chris@219 3477 Model *defaultInputModel = 0;
Chris@219 3478 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@219 3479 Layer *layer = pane->getLayer(j);
Chris@219 3480 if (!layer) continue;
Chris@243 3481 if (LayerFactory::getInstance()->getLayerType(layer) !=
Chris@243 3482 LayerFactory::Waveform &&
Chris@243 3483 !layer->isLayerOpaque()) continue;
Chris@219 3484 Model *model = layer->getModel();
Chris@219 3485 if (!model) continue;
Chris@219 3486 for (size_t k = 0; k < candidateInputModels.size(); ++k) {
Chris@219 3487 if (candidateInputModels[k] == model) {
Chris@219 3488 defaultInputModel = model;
Chris@219 3489 break;
Chris@219 3490 }
Chris@219 3491 }
Chris@219 3492 if (defaultInputModel) break;
Chris@219 3493 }
Chris@219 3494
Chris@184 3495 size_t startFrame = 0, duration = 0;
Chris@184 3496 size_t endFrame = 0;
Chris@184 3497 m_viewManager->getSelection().getExtents(startFrame, endFrame);
Chris@184 3498 if (endFrame > startFrame) duration = endFrame - startFrame;
Chris@184 3499 else startFrame = 0;
Chris@184 3500
Chris@357 3501 TransformUserConfigurator configurator;
Chris@357 3502
Chris@224 3503 ModelTransformer::Input input = ModelTransformerFactory::getInstance()->
Chris@224 3504 getConfigurationForTransform
Chris@211 3505 (transform,
Chris@211 3506 candidateInputModels,
Chris@219 3507 defaultInputModel,
Chris@211 3508 m_playSource,
Chris@211 3509 startFrame,
Chris@357 3510 duration,
Chris@357 3511 &configurator);
Chris@211 3512
Chris@224 3513 if (!input.getModel()) return;
Chris@224 3514
Chris@324 3515 // 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 3516
Chris@224 3517 Layer *newLayer = m_document->createDerivedLayer(transform, input);
Chris@0 3518
Chris@0 3519 if (newLayer) {
Chris@0 3520 m_document->addLayerToView(pane, newLayer);
Chris@224 3521 m_document->setChannel(newLayer, input.getChannel());
Chris@224 3522 m_recentTransforms.add(transformId);
Chris@70 3523 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 3524 }
Chris@0 3525
Chris@0 3526 updateMenuStates();
Chris@0 3527 }
Chris@0 3528
Chris@0 3529 void
Chris@0 3530 MainWindow::renameCurrentLayer()
Chris@0 3531 {
Chris@0 3532 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 3533 if (pane) {
Chris@0 3534 Layer *layer = pane->getSelectedLayer();
Chris@0 3535 if (layer) {
Chris@0 3536 bool ok = false;
Chris@0 3537 QString newName = QInputDialog::getText
Chris@0 3538 (this, tr("Rename Layer"),
Chris@0 3539 tr("New name for this layer:"),
Chris@0 3540 QLineEdit::Normal, layer->objectName(), &ok);
Chris@0 3541 if (ok) {
Chris@239 3542 layer->setPresentationName(newName);
Chris@95 3543 setupExistingLayersMenus();
Chris@0 3544 }
Chris@0 3545 }
Chris@0 3546 }
Chris@0 3547 }
Chris@0 3548
Chris@0 3549 void
Chris@272 3550 MainWindow::findTransform()
Chris@272 3551 {
Chris@274 3552 TransformFinder *finder = new TransformFinder(this);
Chris@274 3553 if (!finder->exec()) {
Chris@274 3554 delete finder;
Chris@274 3555 return;
Chris@273 3556 }
Chris@274 3557 TransformId transform = finder->getTransform();
Chris@274 3558 delete finder;
Chris@287 3559
Chris@287 3560 if (getMainModel() != 0 && m_paneStack->getCurrentPane() != 0) {
Chris@287 3561 addLayer(transform);
Chris@287 3562 }
Chris@272 3563 }
Chris@272 3564
Chris@272 3565 void
Chris@207 3566 MainWindow::playSoloToggled()
Chris@207 3567 {
Chris@207 3568 MainWindowBase::playSoloToggled();
Chris@207 3569 m_soloModified = true;
Chris@207 3570 }
Chris@207 3571
Chris@207 3572 void
Chris@206 3573 MainWindow::alignToggled()
Chris@206 3574 {
Chris@206 3575 QAction *action = dynamic_cast<QAction *>(sender());
Chris@206 3576
Chris@207 3577 if (!m_viewManager) return;
Chris@207 3578
Chris@206 3579 if (action) {
Chris@206 3580 m_viewManager->setAlignMode(action->isChecked());
Chris@206 3581 } else {
Chris@206 3582 m_viewManager->setAlignMode(!m_viewManager->getAlignMode());
Chris@206 3583 }
Chris@206 3584
Chris@206 3585 if (m_viewManager->getAlignMode()) {
Chris@207 3586 m_prevSolo = m_soloAction->isChecked();
Chris@208 3587 if (!m_soloAction->isChecked()) {
Chris@208 3588 m_soloAction->setChecked(true);
Chris@208 3589 MainWindowBase::playSoloToggled();
Chris@208 3590 }
Chris@207 3591 m_soloModified = false;
Chris@207 3592 emit canChangeSolo(false);
Chris@206 3593 m_document->alignModels();
Chris@206 3594 m_document->setAutoAlignment(true);
Chris@206 3595 } else {
Chris@207 3596 if (!m_soloModified) {
Chris@208 3597 if (m_soloAction->isChecked() != m_prevSolo) {
Chris@208 3598 m_soloAction->setChecked(m_prevSolo);
Chris@208 3599 MainWindowBase::playSoloToggled();
Chris@208 3600 }
Chris@207 3601 }
Chris@207 3602 emit canChangeSolo(true);
Chris@206 3603 m_document->setAutoAlignment(false);
Chris@206 3604 }
Chris@206 3605
Chris@206 3606 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@206 3607
Chris@206 3608 Pane *pane = m_paneStack->getPane(i);
Chris@206 3609 if (!pane) continue;
Chris@206 3610
Chris@206 3611 pane->update();
Chris@206 3612 }
Chris@206 3613 }
Chris@206 3614
Chris@206 3615 void
Chris@59 3616 MainWindow::playSpeedChanged(int position)
Chris@0 3617 {
Chris@59 3618 PlaySpeedRangeMapper mapper(0, 200);
Chris@60 3619
Chris@60 3620 float percent = m_playSpeed->mappedValue();
Chris@60 3621 float factor = mapper.getFactorForValue(percent);
Chris@60 3622
Chris@267 3623 // std::cerr << "speed = " << position << " percent = " << percent << " factor = " << factor << std::endl;
Chris@60 3624
Chris@59 3625 bool something = (position != 100);
Chris@155 3626
Chris@59 3627 int pc = lrintf(percent);
Chris@21 3628
Chris@155 3629 if (!something) {
Chris@155 3630 contextHelpChanged(tr("Playback speed: Normal"));
Chris@155 3631 } else {
Chris@155 3632 contextHelpChanged(tr("Playback speed: %1%2%")
Chris@155 3633 .arg(position > 100 ? "+" : "")
Chris@155 3634 .arg(pc));
Chris@155 3635 }
Chris@155 3636
Chris@240 3637 m_playSource->setTimeStretch(factor);
Chris@155 3638
Chris@155 3639 updateMenuStates();
Chris@16 3640 }
Chris@16 3641
Chris@26 3642 void
Chris@155 3643 MainWindow::speedUpPlayback()
Chris@155 3644 {
Chris@155 3645 int value = m_playSpeed->value();
Chris@155 3646 value = value + m_playSpeed->pageStep();
Chris@155 3647 if (value > m_playSpeed->maximum()) value = m_playSpeed->maximum();
Chris@155 3648 m_playSpeed->setValue(value);
Chris@155 3649 }
Chris@155 3650
Chris@155 3651 void
Chris@155 3652 MainWindow::slowDownPlayback()
Chris@155 3653 {
Chris@155 3654 int value = m_playSpeed->value();
Chris@155 3655 value = value - m_playSpeed->pageStep();
Chris@155 3656 if (value < m_playSpeed->minimum()) value = m_playSpeed->minimum();
Chris@155 3657 m_playSpeed->setValue(value);
Chris@155 3658 }
Chris@155 3659
Chris@155 3660 void
Chris@155 3661 MainWindow::restoreNormalPlayback()
Chris@155 3662 {
Chris@155 3663 m_playSpeed->setValue(m_playSpeed->defaultValue());
Chris@155 3664 }
Chris@155 3665
Chris@155 3666 void
Chris@227 3667 MainWindow::currentPaneChanged(Pane *pane)
Chris@227 3668 {
Chris@228 3669 MainWindowBase::currentPaneChanged(pane);
Chris@228 3670
Chris@227 3671 if (!pane || !m_panLayer) return;
Chris@227 3672 for (int i = pane->getLayerCount(); i > 0; ) {
Chris@227 3673 --i;
Chris@227 3674 Layer *layer = pane->getLayer(i);
Chris@227 3675 if (LayerFactory::getInstance()->getLayerType(layer) ==
Chris@227 3676 LayerFactory::Waveform) {
Chris@227 3677 RangeSummarisableTimeValueModel *tvm =
Chris@227 3678 dynamic_cast<RangeSummarisableTimeValueModel *>(layer->getModel());
Chris@227 3679 if (tvm) {
Chris@227 3680 m_panLayer->setModel(tvm);
Chris@227 3681 return;
Chris@227 3682 }
Chris@227 3683 }
Chris@227 3684 }
Chris@227 3685 }
Chris@227 3686
Chris@227 3687 void
Chris@116 3688 MainWindow::updateVisibleRangeDisplay(Pane *p) const
Chris@116 3689 {
Chris@116 3690 if (!getMainModel() || !p) {
Chris@116 3691 return;
Chris@116 3692 }
Chris@116 3693
Chris@117 3694 bool haveSelection = false;
Chris@117 3695 size_t startFrame = 0, endFrame = 0;
Chris@117 3696
Chris@117 3697 if (m_viewManager && m_viewManager->haveInProgressSelection()) {
Chris@117 3698
Chris@117 3699 bool exclusive = false;
Chris@117 3700 Selection s = m_viewManager->getInProgressSelection(exclusive);
Chris@117 3701
Chris@117 3702 if (!s.isEmpty()) {
Chris@117 3703 haveSelection = true;
Chris@117 3704 startFrame = s.getStartFrame();
Chris@117 3705 endFrame = s.getEndFrame();
Chris@117 3706 }
Chris@117 3707 }
Chris@117 3708
Chris@117 3709 if (!haveSelection) {
Chris@117 3710 startFrame = p->getFirstVisibleFrame();
Chris@117 3711 endFrame = p->getLastVisibleFrame();
Chris@117 3712 }
Chris@117 3713
Chris@116 3714 RealTime start = RealTime::frame2RealTime
Chris@117 3715 (startFrame, getMainModel()->getSampleRate());
Chris@116 3716
Chris@116 3717 RealTime end = RealTime::frame2RealTime
Chris@117 3718 (endFrame, getMainModel()->getSampleRate());
Chris@116 3719
Chris@116 3720 RealTime duration = end - start;
Chris@116 3721
Chris@116 3722 QString startStr, endStr, durationStr;
Chris@116 3723 startStr = start.toText(true).c_str();
Chris@116 3724 endStr = end.toText(true).c_str();
Chris@116 3725 durationStr = duration.toText(true).c_str();
Chris@116 3726
Chris@117 3727 if (haveSelection) {
Chris@117 3728 m_myStatusMessage = tr("Selection: %1 to %2 (duration %3)")
Chris@117 3729 .arg(startStr).arg(endStr).arg(durationStr);
Chris@117 3730 } else {
Chris@117 3731 m_myStatusMessage = tr("Visible: %1 to %2 (duration %3)")
Chris@117 3732 .arg(startStr).arg(endStr).arg(durationStr);
Chris@117 3733 }
Chris@116 3734
Chris@116 3735 statusBar()->showMessage(m_myStatusMessage);
Chris@340 3736
Chris@340 3737 updatePositionStatusDisplays();
Chris@340 3738 }
Chris@340 3739
Chris@340 3740 void
Chris@340 3741 MainWindow::updatePositionStatusDisplays() const
Chris@340 3742 {
Chris@340 3743 if (!statusBar()->isVisible()) return;
Chris@340 3744
Chris@340 3745 Pane *pane = 0;
Chris@340 3746 size_t frame = m_viewManager->getPlaybackFrame();
Chris@340 3747
Chris@340 3748 if (m_paneStack) pane = m_paneStack->getCurrentPane();
Chris@340 3749 if (!pane) return;
Chris@340 3750
Chris@340 3751 int layers = pane->getLayerCount();
Chris@340 3752 if (layers == 0) m_currentLabel->setText("");
Chris@340 3753
Chris@340 3754 for (int i = layers-1; i >= 0; --i) {
Chris@340 3755 Layer *layer = pane->getLayer(i);
Chris@340 3756 if (!layer) continue;
Chris@340 3757 if (!layer->isLayerEditable()) continue;
Chris@340 3758 QString label = layer->getLabelPreceding
Chris@340 3759 (pane->alignFromReference(frame));
Chris@340 3760 m_currentLabel->setText(label);
Chris@340 3761 break;
Chris@340 3762 }
Chris@116 3763 }
Chris@116 3764
Chris@116 3765 void
Chris@0 3766 MainWindow::outputLevelsChanged(float left, float right)
Chris@0 3767 {
Chris@0 3768 m_fader->setPeakLeft(left);
Chris@0 3769 m_fader->setPeakRight(right);
Chris@0 3770 }
Chris@0 3771
Chris@0 3772 void
Chris@0 3773 MainWindow::sampleRateMismatch(size_t requested, size_t actual,
Chris@0 3774 bool willResample)
Chris@0 3775 {
Chris@0 3776 if (!willResample) {
Chris@247 3777 emit hideSplash();
Chris@0 3778 QMessageBox::information
Chris@0 3779 (this, tr("Sample rate mismatch"),
Chris@193 3780 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 3781 .arg(requested).arg(actual));
Chris@0 3782 }
Chris@0 3783
Chris@0 3784 updateDescriptionLabel();
Chris@0 3785 }
Chris@0 3786
Chris@0 3787 void
Chris@42 3788 MainWindow::audioOverloadPluginDisabled()
Chris@42 3789 {
Chris@42 3790 QMessageBox::information
Chris@42 3791 (this, tr("Audio processing overload"),
Chris@193 3792 tr("<b>Overloaded</b><p>Audio effects plugin auditioning has been disabled due to a processing overload."));
Chris@42 3793 }
Chris@42 3794
Chris@42 3795 void
Chris@266 3796 MainWindow::audioTimeStretchMultiChannelDisabled()
Chris@266 3797 {
Chris@266 3798 static bool shownOnce = false;
Chris@266 3799 if (shownOnce) return;
Chris@266 3800 QMessageBox::information
Chris@266 3801 (this, tr("Audio processing overload"),
Chris@266 3802 tr("<b>Overloaded</b><p>Audio playback speed processing has been reduced to a single channel, due to a processing overload."));
Chris@266 3803 shownOnce = true;
Chris@266 3804 }
Chris@266 3805
Chris@266 3806 void
Chris@304 3807 MainWindow::midiEventsAvailable()
Chris@304 3808 {
Chris@307 3809 Pane *currentPane = 0;
Chris@307 3810 NoteLayer *currentNoteLayer = 0;
Chris@309 3811 TimeValueLayer *currentTimeValueLayer = 0;
Chris@307 3812
Chris@307 3813 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
Chris@307 3814 if (currentPane) {
Chris@307 3815 currentNoteLayer = dynamic_cast<NoteLayer *>
Chris@307 3816 (currentPane->getSelectedLayer());
Chris@309 3817 currentTimeValueLayer = dynamic_cast<TimeValueLayer *>
Chris@309 3818 (currentPane->getSelectedLayer());
Chris@307 3819 }
Chris@307 3820
Chris@305 3821 // This is called through a serialised signal/slot invocation
Chris@305 3822 // (across threads). It could happen quite some time after the
Chris@305 3823 // event was actually received, which is why event timestamping
Chris@305 3824 // happens in the MIDI input class and not here.
Chris@307 3825
Chris@305 3826 while (m_midiInput->getEventsAvailable() > 0) {
Chris@308 3827
Chris@305 3828 MIDIEvent ev(m_midiInput->readEvent());
Chris@307 3829
Chris@309 3830 size_t frame = currentPane->alignFromReference(ev.getTime());
Chris@309 3831
Chris@308 3832 bool noteOn = (ev.getMessageType() == MIDIConstants::MIDI_NOTE_ON &&
Chris@308 3833 ev.getVelocity() > 0);
Chris@308 3834
Chris@308 3835 bool noteOff = (ev.getMessageType() == MIDIConstants::MIDI_NOTE_OFF ||
Chris@308 3836 (ev.getMessageType() == MIDIConstants::MIDI_NOTE_ON &&
Chris@308 3837 ev.getVelocity() == 0));
Chris@308 3838
Chris@307 3839 if (currentNoteLayer) {
Chris@307 3840
Chris@310 3841 if (!m_playSource || !m_playSource->isPlaying()) continue;
Chris@310 3842
Chris@308 3843 if (noteOn) {
Chris@307 3844
Chris@309 3845 currentNoteLayer->addNoteOn(frame,
Chris@307 3846 ev.getPitch(),
Chris@307 3847 ev.getVelocity());
Chris@307 3848
Chris@308 3849 } else if (noteOff) {
Chris@307 3850
Chris@309 3851 currentNoteLayer->addNoteOff(frame,
Chris@307 3852 ev.getPitch());
Chris@307 3853
Chris@307 3854 }
Chris@307 3855
Chris@309 3856 continue;
Chris@309 3857 }
Chris@309 3858
Chris@309 3859 if (currentTimeValueLayer) {
Chris@308 3860
Chris@308 3861 if (!noteOn) continue;
Chris@310 3862
Chris@310 3863 if (!m_playSource || !m_playSource->isPlaying()) continue;
Chris@310 3864
Chris@309 3865 Model *model = static_cast<Layer *>(currentTimeValueLayer)->getModel();
Chris@309 3866 SparseTimeValueModel *tvm =
Chris@309 3867 dynamic_cast<SparseTimeValueModel *>(model);
Chris@309 3868 if (tvm) {
Chris@309 3869 SparseTimeValueModel::Point point(frame, ev.getPitch() % 12, "");
Chris@309 3870 SparseTimeValueModel::AddPointCommand *command =
Chris@309 3871 new SparseTimeValueModel::AddPointCommand
Chris@309 3872 (tvm, point, tr("Add Point"));
Chris@309 3873 CommandHistory::getInstance()->addCommand(command);
Chris@309 3874 }
Chris@309 3875 continue;
Chris@309 3876
Chris@305 3877 }
Chris@309 3878
Chris@309 3879 if (!noteOn) continue;
Chris@309 3880 insertInstantAt(ev.getTime());
Chris@304 3881 }
Chris@304 3882 }
Chris@304 3883
Chris@304 3884 void
Chris@305 3885 MainWindow::playStatusChanged(bool playing)
Chris@305 3886 {
Chris@307 3887 Pane *currentPane = 0;
Chris@307 3888 NoteLayer *currentNoteLayer = 0;
Chris@307 3889
Chris@307 3890 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
Chris@307 3891 if (currentPane) {
Chris@307 3892 currentNoteLayer = dynamic_cast<NoteLayer *>(currentPane->getSelectedLayer());
Chris@307 3893 }
Chris@307 3894
Chris@307 3895 if (currentNoteLayer) {
Chris@307 3896 currentNoteLayer->abandonNoteOns();
Chris@307 3897 }
Chris@305 3898 }
Chris@305 3899
Chris@305 3900 void
Chris@200 3901 MainWindow::layerRemoved(Layer *layer)
Chris@0 3902 {
Chris@95 3903 setupExistingLayersMenus();
Chris@200 3904 MainWindowBase::layerRemoved(layer);
Chris@0 3905 }
Chris@0 3906
Chris@0 3907 void
Chris@0 3908 MainWindow::layerInAView(Layer *layer, bool inAView)
Chris@0 3909 {
Chris@95 3910 setupExistingLayersMenus();
Chris@200 3911 MainWindowBase::layerInAView(layer, inAView);
Chris@0 3912 }
Chris@0 3913
Chris@0 3914 void
Chris@0 3915 MainWindow::modelAdded(Model *model)
Chris@0 3916 {
Chris@200 3917 MainWindowBase::modelAdded(model);
Chris@66 3918 if (dynamic_cast<DenseTimeValueModel *>(model)) {
Chris@66 3919 setupPaneAndLayerMenus();
Chris@66 3920 }
Chris@0 3921 }
Chris@0 3922
Chris@0 3923 void
Chris@0 3924 MainWindow::mainModelChanged(WaveFileModel *model)
Chris@0 3925 {
Chris@0 3926 m_panLayer->setModel(model);
Chris@200 3927
Chris@200 3928 MainWindowBase::mainModelChanged(model);
Chris@200 3929
Chris@200 3930 if (m_playTarget) {
Chris@200 3931 connect(m_fader, SIGNAL(valueChanged(float)),
Chris@200 3932 m_playTarget, SLOT(setOutputGain(float)));
Chris@200 3933 }
Chris@0 3934 }
Chris@0 3935
Chris@0 3936 void
Chris@200 3937 MainWindow::setInstantsNumbering()
Chris@0 3938 {
Chris@200 3939 QAction *a = dynamic_cast<QAction *>(sender());
Chris@200 3940 if (!a) return;
Chris@200 3941
Chris@200 3942 int type = m_numberingActions[a];
Chris@200 3943
Chris@200 3944 if (m_labeller) m_labeller->setType(Labeller::ValueType(type));
Chris@200 3945
Chris@200 3946 QSettings settings;
Chris@200 3947 settings.beginGroup("MainWindow");
Chris@200 3948 settings.setValue("labellertype", type);
Chris@200 3949 settings.endGroup();
Chris@200 3950 }
Chris@200 3951
Chris@200 3952 void
Chris@200 3953 MainWindow::setInstantsCounterCycle()
Chris@200 3954 {
Chris@200 3955 QAction *a = dynamic_cast<QAction *>(sender());
Chris@200 3956 if (!a) return;
Chris@200 3957
Chris@200 3958 int cycle = a->text().toInt();
Chris@200 3959 if (cycle == 0) return;
Chris@200 3960
Chris@200 3961 if (m_labeller) m_labeller->setCounterCycleSize(cycle);
Chris@200 3962
Chris@200 3963 QSettings settings;
Chris@200 3964 settings.beginGroup("MainWindow");
Chris@200 3965 settings.setValue("labellercycle", cycle);
Chris@200 3966 settings.endGroup();
Chris@200 3967 }
Chris@200 3968
Chris@200 3969 void
Chris@200 3970 MainWindow::resetInstantsCounters()
Chris@200 3971 {
Chris@200 3972 LabelCounterInputDialog dialog(m_labeller, this);
Chris@241 3973 dialog.setWindowTitle(tr("Reset Counters"));
Chris@200 3974 dialog.exec();
Chris@0 3975 }
Chris@0 3976
Chris@0 3977 void
Chris@233 3978 MainWindow::modelGenerationFailed(QString transformName, QString message)
Chris@233 3979 {
Chris@247 3980 emit hideSplash();
Chris@247 3981
Chris@233 3982 if (message != "") {
Chris@233 3983
Chris@233 3984 QMessageBox::warning
Chris@233 3985 (this,
Chris@233 3986 tr("Failed to generate layer"),
Chris@233 3987 tr("<b>Layer generation failed</b><p>Failed to generate derived layer.<p>The layer transform \"%1\" failed:<p>%2")
Chris@233 3988 .arg(transformName).arg(message),
Chris@233 3989 QMessageBox::Ok);
Chris@233 3990 } else {
Chris@233 3991 QMessageBox::warning
Chris@233 3992 (this,
Chris@233 3993 tr("Failed to generate layer"),
Chris@233 3994 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 3995 .arg(transformName),
Chris@233 3996 QMessageBox::Ok);
Chris@233 3997 }
Chris@233 3998 }
Chris@233 3999
Chris@233 4000 void
Chris@233 4001 MainWindow::modelGenerationWarning(QString transformName, QString message)
Chris@233 4002 {
Chris@247 4003 emit hideSplash();
Chris@247 4004
Chris@233 4005 QMessageBox::warning
Chris@233 4006 (this, tr("Warning"), message, QMessageBox::Ok);
Chris@233 4007 }
Chris@233 4008
Chris@233 4009 void
Chris@233 4010 MainWindow::modelRegenerationFailed(QString layerName,
Chris@233 4011 QString transformName, QString message)
Chris@233 4012 {
Chris@247 4013 emit hideSplash();
Chris@247 4014
Chris@233 4015 if (message != "") {
Chris@233 4016
Chris@233 4017 QMessageBox::warning
Chris@233 4018 (this,
Chris@233 4019 tr("Failed to regenerate layer"),
Chris@233 4020 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 4021 .arg(layerName).arg(transformName).arg(message),
Chris@233 4022 QMessageBox::Ok);
Chris@233 4023 } else {
Chris@233 4024 QMessageBox::warning
Chris@233 4025 (this,
Chris@233 4026 tr("Failed to regenerate layer"),
Chris@233 4027 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 4028 .arg(layerName).arg(transformName),
Chris@233 4029 QMessageBox::Ok);
Chris@233 4030 }
Chris@233 4031 }
Chris@233 4032
Chris@233 4033 void
Chris@233 4034 MainWindow::modelRegenerationWarning(QString layerName,
Chris@233 4035 QString transformName, QString message)
Chris@233 4036 {
Chris@247 4037 emit hideSplash();
Chris@247 4038
Chris@233 4039 QMessageBox::warning
Chris@233 4040 (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 4041 }
Chris@233 4042
Chris@233 4043 void
Chris@233 4044 MainWindow::alignmentFailed(QString transformName, QString message)
Chris@0 4045 {
Chris@247 4046 emit hideSplash();
Chris@247 4047
Chris@0 4048 QMessageBox::warning
Chris@0 4049 (this,
Chris@233 4050 tr("Failed to calculate alignment"),
Chris@233 4051 tr("<b>Alignment calculation failed</b><p>Failed to calculate an audio alignment using transform \"%1\":<p>%2")
Chris@233 4052 .arg(transformName).arg(message),
Chris@165 4053 QMessageBox::Ok);
Chris@0 4054 }
Chris@0 4055
Chris@0 4056 void
Chris@0 4057 MainWindow::rightButtonMenuRequested(Pane *pane, QPoint position)
Chris@0 4058 {
Chris@0 4059 // std::cerr << "MainWindow::rightButtonMenuRequested(" << pane << ", " << position.x() << ", " << position.y() << ")" << std::endl;
Chris@0 4060 m_paneStack->setCurrentPane(pane);
Chris@0 4061 m_rightButtonMenu->popup(position);
Chris@0 4062 }
Chris@0 4063
Chris@0 4064 void
Chris@0 4065 MainWindow::showLayerTree()
Chris@0 4066 {
Chris@219 4067 if (!m_layerTreeDialog.isNull()) {
Chris@219 4068 m_layerTreeDialog->show();
Chris@219 4069 m_layerTreeDialog->raise();
Chris@177 4070 return;
Chris@177 4071 }
Chris@177 4072
Chris@219 4073 m_layerTreeDialog = new LayerTreeDialog(m_paneStack);
Chris@232 4074 m_layerTreeDialog->setAttribute(Qt::WA_DeleteOnClose); // see below
Chris@219 4075 m_layerTreeDialog->show();
Chris@0 4076 }
Chris@0 4077
Chris@0 4078 void
Chris@306 4079 MainWindow::showActivityLog()
Chris@306 4080 {
Chris@306 4081 m_activityLog->show();
Chris@306 4082 m_activityLog->raise();
Chris@306 4083 m_activityLog->scrollToEnd();
Chris@306 4084 }
Chris@306 4085
Chris@306 4086 void
Chris@0 4087 MainWindow::preferences()
Chris@0 4088 {
Chris@0 4089 if (!m_preferencesDialog.isNull()) {
Chris@0 4090 m_preferencesDialog->show();
Chris@0 4091 m_preferencesDialog->raise();
Chris@0 4092 return;
Chris@0 4093 }
Chris@0 4094
Chris@0 4095 m_preferencesDialog = new PreferencesDialog(this);
Chris@0 4096
Chris@0 4097 // DeleteOnClose is safe here, because m_preferencesDialog is a
Chris@0 4098 // QPointer that will be zeroed when the dialog is deleted. We
Chris@0 4099 // use it in preference to leaving the dialog lying around because
Chris@0 4100 // if you Cancel the dialog, it resets the preferences state
Chris@0 4101 // without resetting its own widgets, so its state will be
Chris@0 4102 // incorrect when next shown unless we construct it afresh
Chris@0 4103 m_preferencesDialog->setAttribute(Qt::WA_DeleteOnClose);
Chris@0 4104
Chris@0 4105 m_preferencesDialog->show();
Chris@0 4106 }
Chris@0 4107
Chris@0 4108 void
Chris@90 4109 MainWindow::mouseEnteredWidget()
Chris@90 4110 {
Chris@90 4111 QWidget *w = dynamic_cast<QWidget *>(sender());
Chris@90 4112 if (!w) return;
Chris@90 4113
Chris@90 4114 if (w == m_fader) {
Chris@116 4115 contextHelpChanged(tr("Adjust the master playback level"));
Chris@90 4116 } else if (w == m_playSpeed) {
Chris@116 4117 contextHelpChanged(tr("Adjust the master playback speed"));
Chris@90 4118 }
Chris@90 4119 }
Chris@90 4120
Chris@90 4121 void
Chris@90 4122 MainWindow::mouseLeftWidget()
Chris@90 4123 {
Chris@116 4124 contextHelpChanged("");
Chris@116 4125 }
Chris@116 4126
Chris@116 4127 void
Chris@0 4128 MainWindow::website()
Chris@0 4129 {
Chris@0 4130 openHelpUrl(tr("http://www.sonicvisualiser.org/"));
Chris@0 4131 }
Chris@0 4132
Chris@0 4133 void
Chris@0 4134 MainWindow::help()
Chris@0 4135 {
Chris@318 4136 openHelpUrl(tr("http://www.sonicvisualiser.org/doc/reference/%1/en/").arg(SV_VERSION));
Chris@0 4137 }
Chris@0 4138
Chris@0 4139 void
Chris@0 4140 MainWindow::about()
Chris@0 4141 {
Chris@0 4142 bool debug = false;
Chris@0 4143 QString version = "(unknown version)";
Chris@0 4144
Chris@0 4145 #ifdef BUILD_DEBUG
Chris@0 4146 debug = true;
Chris@285 4147 #endif // BUILD_DEBUG
Chris@0 4148 #ifdef SV_VERSION
Chris@0 4149 #ifdef SVNREV
Chris@0 4150 version = tr("Release %1 : Revision %2").arg(SV_VERSION).arg(SVNREV);
Chris@285 4151 #else // !SVNREV
Chris@0 4152 version = tr("Release %1").arg(SV_VERSION);
Chris@285 4153 #endif // SVNREV
Chris@285 4154 #else // !SV_VERSION
Chris@0 4155 #ifdef SVNREV
Chris@0 4156 version = tr("Unreleased : Revision %1").arg(SVNREV);
Chris@285 4157 #endif // SVNREV
Chris@285 4158 #endif // SV_VERSION
Chris@0 4159
Chris@0 4160 QString aboutText;
Chris@0 4161
Chris@0 4162 aboutText += tr("<h3>About Sonic Visualiser</h3>");
Chris@285 4163 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 4164 aboutText += tr("<p><small>%1 : %2 configuration</small></p>")
Chris@0 4165 .arg(version)
Chris@0 4166 .arg(debug ? tr("Debug") : tr("Release"));
Chris@0 4167
Chris@285 4168 aboutText += "<small>";
Chris@285 4169
Chris@285 4170 aboutText += tr("With Qt v%1 &copy; Nokia Corporation").arg(QT_VERSION_STR);
Chris@285 4171
Chris@0 4172 #ifdef HAVE_JACK
Chris@93 4173 #ifdef JACK_VERSION
Chris@285 4174 aboutText += tr("<br>With JACK audio output library v%1 &copy; Paul Davis and Jack O'Quin").arg(JACK_VERSION);
Chris@285 4175 #else // !JACK_VERSION
Chris@257 4176 aboutText += tr("<br>With JACK audio output library &copy; Paul Davis and Jack O'Quin");
Chris@285 4177 #endif // JACK_VERSION
Chris@285 4178 #endif // HAVE_JACK
Chris@0 4179 #ifdef HAVE_PORTAUDIO
Chris@257 4180 aboutText += tr("<br>With PortAudio audio output library &copy; Ross Bencina and Phil Burk");
Chris@285 4181 #endif // HAVE_PORTAUDIO
Chris@257 4182 #ifdef HAVE_LIBPULSE
Chris@285 4183 #ifdef LIBPULSE_VERSION
Chris@285 4184 aboutText += tr("<br>With PulseAudio audio output library v%1 &copy; Lennart Poettering and Pierre Ossman").arg(LIBPULSE_VERSION);
Chris@285 4185 #else // !LIBPULSE_VERSION
Chris@257 4186 aboutText += tr("<br>With PulseAudio audio output library &copy; Lennart Poettering and Pierre Ossman");
Chris@285 4187 #endif // LIBPULSE_VERSION
Chris@285 4188 #endif // HAVE_LIBPULSE
Chris@0 4189 #ifdef HAVE_OGGZ
Chris@93 4190 #ifdef OGGZ_VERSION
Chris@0 4191 aboutText += tr("<br>With Ogg file decoder (oggz v%1, fishsound v%2) &copy; CSIRO Australia").arg(OGGZ_VERSION).arg(FISHSOUND_VERSION);
Chris@285 4192 #else // !OGGZ_VERSION
Chris@93 4193 aboutText += tr("<br>With Ogg file decoder &copy; CSIRO Australia");
Chris@285 4194 #endif // OGGZ_VERSION
Chris@285 4195 #endif // HAVE_OGGZ
Chris@0 4196 #ifdef HAVE_MAD
Chris@93 4197 #ifdef MAD_VERSION
Chris@285 4198 aboutText += tr("<br>With MAD mp3 decoder v%1 &copy; Underbit Technologies Inc").arg(MAD_VERSION);
Chris@285 4199 #else // !MAD_VERSION
Chris@93 4200 aboutText += tr("<br>With MAD mp3 decoder &copy; Underbit Technologies Inc");
Chris@285 4201 #endif // MAD_VERSION
Chris@285 4202 #endif // HAVE_MAD
Chris@0 4203 #ifdef HAVE_SAMPLERATE
Chris@93 4204 #ifdef SAMPLERATE_VERSION
Chris@285 4205 aboutText += tr("<br>With libsamplerate v%1 &copy; Erik de Castro Lopo").arg(SAMPLERATE_VERSION);
Chris@285 4206 #else // !SAMPLERATE_VERSION
Chris@93 4207 aboutText += tr("<br>With libsamplerate &copy; Erik de Castro Lopo");
Chris@285 4208 #endif // SAMPLERATE_VERSION
Chris@285 4209 #endif // HAVE_SAMPLERATE
Chris@0 4210 #ifdef HAVE_SNDFILE
Chris@93 4211 #ifdef SNDFILE_VERSION
Chris@285 4212 aboutText += tr("<br>With libsndfile v%1 &copy; Erik de Castro Lopo").arg(SNDFILE_VERSION);
Chris@285 4213 #else // !SNDFILE_VERSION
Chris@93 4214 aboutText += tr("<br>With libsndfile &copy; Erik de Castro Lopo");
Chris@285 4215 #endif // SNDFILE_VERSION
Chris@285 4216 #endif // HAVE_SNDFILE
Chris@127 4217 #ifdef HAVE_FFTW3F
Chris@93 4218 #ifdef FFTW3_VERSION
Chris@285 4219 aboutText += tr("<br>With FFTW3 v%1 &copy; Matteo Frigo and MIT").arg(FFTW3_VERSION);
Chris@285 4220 #else // !FFTW3_VERSION
Chris@93 4221 aboutText += tr("<br>With FFTW3 &copy; Matteo Frigo and MIT");
Chris@285 4222 #endif // FFTW3_VERSION
Chris@285 4223 #endif // HAVE_FFTW3F
Chris@267 4224 #ifdef HAVE_RUBBERBAND
Chris@267 4225 #ifdef RUBBERBAND_VERSION
Chris@285 4226 aboutText += tr("<br>With Rubber Band v%1 &copy; Chris Cannam").arg(RUBBERBAND_VERSION);
Chris@285 4227 #else // !RUBBERBAND_VERSION
Chris@267 4228 aboutText += tr("<br>With Rubber Band &copy; Chris Cannam");
Chris@285 4229 #endif // RUBBERBAND_VERSION
Chris@285 4230 #endif // HAVE_RUBBERBAND
Chris@0 4231 #ifdef HAVE_VAMP
Chris@114 4232 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 4233 #endif // !HAVE_VAMP
Chris@0 4234 aboutText += tr("<br>With LADSPA plugin support (API v%1) &copy; Richard Furse, Paul Davis, Stefan Westerfeld").arg(LADSPA_VERSION);
Chris@0 4235 aboutText += tr("<br>With DSSI plugin support (API v%1) &copy; Chris Cannam, Steve Harris, Sean Bolton").arg(DSSI_VERSION);
Chris@285 4236 #ifdef RAPTOR_VERSION
Chris@285 4237 aboutText += tr("<br>With Raptor RDF parser v%1 &copy; Dave Beckett and the University of Bristol").arg(RAPTOR_VERSION);
Chris@285 4238 #else // !RAPTOR_VERSION
Chris@285 4239 aboutText += tr("<br>With Raptor RDF parser &copy; Dave Beckett and the University of Bristol");
Chris@285 4240 #endif // RAPTOR_VERSION
Chris@285 4241 #ifdef RASQAL_VERSION
Chris@285 4242 aboutText += tr("<br>With Rasqal RDF query engine v%1 &copy; Dave Beckett and the University of Bristol").arg(RASQAL_VERSION);
Chris@285 4243 #else // !RASQAL_VERSION
Chris@285 4244 aboutText += tr("<br>With Rasqal RDF query engine &copy; Dave Beckett and the University of Bristol");
Chris@285 4245 #endif // RASQAL_VERSION
Chris@285 4246 #ifdef HAVE_REDLAND
Chris@285 4247 #ifdef REDLAND_VERSION
Chris@285 4248 aboutText += tr("<br>With Redland RDF datastore v%1 &copy; Dave Beckett and the University of Bristol").arg(REDLAND_VERSION);
Chris@285 4249 #else // !REDLAND_VERSION
Chris@285 4250 aboutText += tr("<br>With Redland RDF datastore &copy; Dave Beckett and the University of Bristol");
Chris@285 4251 #endif // REDLAND_VERSION
Chris@285 4252 #endif // HAVE_REDLAND
Chris@285 4253
Chris@300 4254 aboutText += tr("<br>With RtMidi &copy; Gary P. Scavone");
Chris@300 4255
Chris@69 4256 #ifdef HAVE_LIBLO
Chris@93 4257 #ifdef LIBLO_VERSION
Chris@285 4258 aboutText += tr("<br>With liblo Lite OSC library v%1 &copy; Steve Harris").arg(LIBLO_VERSION);
Chris@285 4259 #else // !LIBLO_VERSION
Chris@327 4260 aboutText += tr("<br>With liblo Lite OSC library &copy; Steve Harris");
Chris@285 4261 #endif // LIBLO_VERSION
Chris@285 4262
Chris@285 4263 if (m_oscQueue && m_oscQueue->isOK()) {
Chris@285 4264 aboutText += tr("</small><p><small>The OSC URL for this instance is: \"%1\"").arg(m_oscQueue->getOSCURL());
Chris@285 4265 }
Chris@285 4266
Chris@285 4267 aboutText += "</small></p>";
Chris@285 4268 #endif // HAVE_LIBLO
Chris@285 4269
Chris@285 4270 #ifndef BUILD_STATIC
Chris@285 4271 aboutText.replace(tr("With "), tr("Using "));
Chris@93 4272 #endif
Chris@0 4273
Chris@0 4274 aboutText +=
Chris@392 4275 "<p><small>Sonic Visualiser Copyright &copy; 2005&ndash;2011 Chris Cannam and "
Chris@285 4276 "Queen Mary, University of London.</small></p>"
Chris@285 4277 "<p><small>This program is free software; you can redistribute it and/or "
Chris@231 4278 "modify it under the terms of the GNU General Public License as "
Chris@231 4279 "published by the Free Software Foundation; either version 2 of the "
Chris@0 4280 "License, or (at your option) any later version.<br>See the file "
Chris@285 4281 "COPYING included with this distribution for more information.</small></p>";
Chris@0 4282
Chris@0 4283 QMessageBox::about(this, tr("About Sonic Visualiser"), aboutText);
Chris@0 4284 }
Chris@0 4285
Chris@162 4286 void
Chris@162 4287 MainWindow::keyReference()
Chris@162 4288 {
Chris@162 4289 m_keyReference->show();
Chris@162 4290 }
Chris@162 4291
Chris@333 4292 void
Chris@333 4293 MainWindow::newerVersionAvailable(QString version)
Chris@333 4294 {
Chris@334 4295 QSettings settings;
Chris@334 4296 settings.beginGroup("NewerVersionWarning");
Chris@334 4297 QString tag = QString("version-%1-available-show").arg(version);
Chris@334 4298 if (settings.value(tag, true).toBool()) {
Chris@334 4299 QString title(tr("Newer version available"));
Chris@334 4300 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 4301 QMessageBox::information(this, title, text);
Chris@334 4302 settings.setValue(tag, false);
Chris@334 4303 }
Chris@334 4304 settings.endGroup();
Chris@333 4305 }
Chris@333 4306
Chris@333 4307