annotate main/MainWindow.cpp @ 494:238a97d2a8f4 fullscreen

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