annotate main/MainWindow.cpp @ 508:26ebbe098bce

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