annotate main/MainWindow.cpp @ 171:cd58be60e5f2

* Add QuickTime file reader class -- totally untested, shouldn't even compile
author Chris Cannam
date Mon, 06 Aug 2007 14:37:59 +0000
parents ca825d1a4a6b
children c1980ed39d2e
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@77 7 This file copyright 2006 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@1 19 #include "document/Document.h"
Chris@0 20 #include "PreferencesDialog.h"
Chris@0 21
Chris@1 22 #include "view/Pane.h"
Chris@1 23 #include "view/PaneStack.h"
Chris@1 24 #include "data/model/WaveFileModel.h"
Chris@1 25 #include "data/model/SparseOneDimensionalModel.h"
Chris@1 26 #include "view/ViewManager.h"
Chris@0 27 #include "base/Preferences.h"
Chris@0 28 #include "layer/WaveformLayer.h"
Chris@0 29 #include "layer/TimeRulerLayer.h"
Chris@0 30 #include "layer/TimeInstantLayer.h"
Chris@0 31 #include "layer/TimeValueLayer.h"
Chris@0 32 #include "layer/Colour3DPlotLayer.h"
Chris@95 33 #include "layer/SliceLayer.h"
Chris@95 34 #include "layer/SliceableLayer.h"
Chris@0 35 #include "widgets/Fader.h"
Chris@65 36 #include "view/Overview.h"
Chris@0 37 #include "widgets/PropertyBox.h"
Chris@0 38 #include "widgets/PropertyStack.h"
Chris@0 39 #include "widgets/AudioDial.h"
Chris@168 40 #include "widgets/IconLoader.h"
Chris@0 41 #include "widgets/LayerTree.h"
Chris@0 42 #include "widgets/ListInputDialog.h"
Chris@36 43 #include "widgets/SubdividingMenu.h"
Chris@90 44 #include "widgets/NotifyingPushButton.h"
Chris@162 45 #include "widgets/KeyReference.h"
Chris@0 46 #include "audioio/AudioCallbackPlaySource.h"
Chris@0 47 #include "audioio/AudioCallbackPlayTarget.h"
Chris@0 48 #include "audioio/AudioTargetFactory.h"
Chris@59 49 #include "audioio/PlaySpeedRangeMapper.h"
Chris@1 50 #include "data/fileio/AudioFileReaderFactory.h"
Chris@1 51 #include "data/fileio/DataFileReaderFactory.h"
Chris@1 52 #include "data/fileio/WavFileWriter.h"
Chris@1 53 #include "data/fileio/CSVFileWriter.h"
Chris@1 54 #include "data/fileio/BZipFileDevice.h"
Chris@85 55 #include "data/fileio/RemoteFile.h"
Chris@91 56 #include "data/fft/FFTDataServer.h"
Chris@1 57 #include "base/RecentFiles.h"
Chris@0 58 #include "transform/TransformFactory.h"
Chris@0 59 #include "base/PlayParameterRepository.h"
Chris@0 60 #include "base/XmlExportable.h"
Chris@0 61 #include "base/CommandHistory.h"
Chris@0 62 #include "base/Profiler.h"
Chris@0 63 #include "base/Clipboard.h"
Chris@165 64 #include "base/UnitDatabase.h"
Chris@165 65 #include "base/ColourDatabase.h"
Chris@69 66 #include "osc/OSCQueue.h"
Chris@0 67
Chris@0 68 // For version information
Chris@0 69 #include "vamp/vamp.h"
Chris@0 70 #include "vamp-sdk/PluginBase.h"
Chris@0 71 #include "plugin/api/ladspa.h"
Chris@0 72 #include "plugin/api/dssi.h"
Chris@0 73
Chris@0 74 #include <QApplication>
Chris@0 75 #include <QMessageBox>
Chris@0 76 #include <QGridLayout>
Chris@0 77 #include <QLabel>
Chris@0 78 #include <QAction>
Chris@0 79 #include <QMenuBar>
Chris@0 80 #include <QToolBar>
Chris@0 81 #include <QInputDialog>
Chris@0 82 #include <QStatusBar>
Chris@0 83 #include <QTreeView>
Chris@0 84 #include <QFile>
Chris@88 85 #include <QFileInfo>
Chris@88 86 #include <QDir>
Chris@0 87 #include <QTextStream>
Chris@0 88 #include <QProcess>
Chris@7 89 #include <QShortcut>
Chris@5 90 #include <QSettings>
Chris@11 91 #include <QDateTime>
Chris@11 92 #include <QProcess>
Chris@16 93 #include <QCheckBox>
Chris@55 94 #include <QRegExp>
Chris@158 95 #include <QScrollArea>
Chris@0 96
Chris@0 97 #include <iostream>
Chris@0 98 #include <cstdio>
Chris@0 99 #include <errno.h>
Chris@0 100
Chris@0 101 using std::cerr;
Chris@0 102 using std::endl;
Chris@0 103
Chris@33 104 using std::vector;
Chris@33 105 using std::map;
Chris@33 106 using std::set;
Chris@33 107
Chris@0 108
Chris@70 109 MainWindow::MainWindow(bool withAudioOutput, bool withOSCSupport) :
Chris@0 110 m_document(0),
Chris@0 111 m_paneStack(0),
Chris@0 112 m_viewManager(0),
Chris@65 113 m_overview(0),
Chris@0 114 m_timeRulerLayer(0),
Chris@46 115 m_audioOutput(withAudioOutput),
Chris@0 116 m_playSource(0),
Chris@0 117 m_playTarget(0),
Chris@70 118 m_oscQueue(withOSCSupport ? new OSCQueue() : 0),
Chris@81 119 m_recentFiles("RecentFiles", 20),
Chris@49 120 m_recentTransforms("RecentTransforms", 20),
Chris@0 121 m_mainMenusCreated(false),
Chris@0 122 m_paneMenu(0),
Chris@0 123 m_layerMenu(0),
Chris@34 124 m_transformsMenu(0),
Chris@155 125 m_playbackMenu(0),
Chris@0 126 m_existingLayersMenu(0),
Chris@95 127 m_sliceMenu(0),
Chris@34 128 m_recentFilesMenu(0),
Chris@34 129 m_recentTransformsMenu(0),
Chris@0 130 m_rightButtonMenu(0),
Chris@0 131 m_rightButtonLayerMenu(0),
Chris@34 132 m_rightButtonTransformsMenu(0),
Chris@155 133 m_rightButtonPlaybackMenu(0),
Chris@155 134 m_ffwdAction(0),
Chris@155 135 m_rwdAction(0),
Chris@0 136 m_documentModified(false),
Chris@70 137 m_openingAudioFile(false),
Chris@70 138 m_abandoning(false),
Chris@162 139 m_preferencesDialog(0),
Chris@162 140 m_keyReference(new KeyReference())
Chris@0 141 {
Chris@0 142 setWindowTitle(tr("Sonic Visualiser"));
Chris@0 143
Chris@165 144 UnitDatabase *udb = UnitDatabase::getInstance();
Chris@165 145 udb->registerUnit("Hz");
Chris@165 146 udb->registerUnit("dB");
Chris@165 147 udb->registerUnit("s");
Chris@165 148
Chris@165 149 ColourDatabase *cdb = ColourDatabase::getInstance();
Chris@165 150 cdb->addColour(Qt::black, tr("Black"));
Chris@165 151 cdb->addColour(Qt::darkRed, tr("Red"));
Chris@165 152 cdb->addColour(Qt::darkBlue, tr("Blue"));
Chris@165 153 cdb->addColour(Qt::darkGreen, tr("Green"));
Chris@165 154 cdb->addColour(QColor(200, 50, 255), tr("Purple"));
Chris@165 155 cdb->addColour(QColor(255, 150, 50), tr("Orange"));
Chris@166 156 cdb->setUseDarkBackground(cdb->addColour(Qt::white, tr("White")), true);
Chris@166 157 cdb->setUseDarkBackground(cdb->addColour(Qt::red, tr("Bright Red")), true);
Chris@166 158 cdb->setUseDarkBackground(cdb->addColour(QColor(30, 150, 255), tr("Bright Blue")), true);
Chris@166 159 cdb->setUseDarkBackground(cdb->addColour(Qt::green, tr("Bright Green")), true);
Chris@166 160 cdb->setUseDarkBackground(cdb->addColour(QColor(225, 74, 255), tr("Bright Purple")), true);
Chris@166 161 cdb->setUseDarkBackground(cdb->addColour(QColor(255, 188, 80), tr("Bright Orange")), true);
Chris@0 162
Chris@0 163 connect(CommandHistory::getInstance(), SIGNAL(commandExecuted()),
Chris@0 164 this, SLOT(documentModified()));
Chris@0 165 connect(CommandHistory::getInstance(), SIGNAL(documentRestored()),
Chris@0 166 this, SLOT(documentRestored()));
Chris@0 167
Chris@0 168 QFrame *frame = new QFrame;
Chris@0 169 setCentralWidget(frame);
Chris@0 170
Chris@0 171 QGridLayout *layout = new QGridLayout;
Chris@0 172
Chris@0 173 m_viewManager = new ViewManager();
Chris@0 174 connect(m_viewManager, SIGNAL(selectionChanged()),
Chris@0 175 this, SLOT(updateMenuStates()));
Chris@117 176 connect(m_viewManager, SIGNAL(inProgressSelectionChanged()),
Chris@117 177 this, SLOT(inProgressSelectionChanged()));
Chris@0 178
Chris@0 179 m_descriptionLabel = new QLabel;
Chris@0 180
Chris@158 181 QScrollArea *scroll = new QScrollArea(frame);
Chris@158 182 scroll->setWidgetResizable(true);
Chris@158 183 scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
Chris@159 184 scroll->setFrameShape(QFrame::NoFrame);
Chris@159 185
Chris@159 186 m_paneStack = new PaneStack(scroll, m_viewManager);
Chris@0 187 connect(m_paneStack, SIGNAL(currentPaneChanged(Pane *)),
Chris@0 188 this, SLOT(currentPaneChanged(Pane *)));
Chris@0 189 connect(m_paneStack, SIGNAL(currentLayerChanged(Pane *, Layer *)),
Chris@0 190 this, SLOT(currentLayerChanged(Pane *, Layer *)));
Chris@0 191 connect(m_paneStack, SIGNAL(rightButtonMenuRequested(Pane *, QPoint)),
Chris@0 192 this, SLOT(rightButtonMenuRequested(Pane *, QPoint)));
Chris@73 193 connect(m_paneStack, SIGNAL(propertyStacksResized()),
Chris@73 194 this, SLOT(propertyStacksResized()));
Chris@90 195 connect(m_paneStack, SIGNAL(contextHelpChanged(const QString &)),
Chris@116 196 this, SLOT(contextHelpChanged(const QString &)));
Chris@0 197
Chris@159 198 scroll->setWidget(m_paneStack);
Chris@159 199
Chris@65 200 m_overview = new Overview(frame);
Chris@65 201 m_overview->setViewManager(m_viewManager);
Chris@65 202 m_overview->setFixedHeight(40);
Chris@144 203 #ifndef _WIN32
Chris@144 204 // For some reason, the contents of the overview never appear if we
Chris@144 205 // make this setting on Windows. I have no inclination at the moment
Chris@144 206 // to track down the reason why.
Chris@129 207 m_overview->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
Chris@144 208 #endif
Chris@90 209 connect(m_overview, SIGNAL(contextHelpChanged(const QString &)),
Chris@116 210 this, SLOT(contextHelpChanged(const QString &)));
Chris@0 211
Chris@0 212 m_panLayer = new WaveformLayer;
Chris@0 213 m_panLayer->setChannelMode(WaveformLayer::MergeChannels);
Chris@0 214 m_panLayer->setBaseColour(Qt::darkGreen);
Chris@0 215 m_panLayer->setAggressiveCacheing(true);
Chris@65 216 m_overview->addLayer(m_panLayer);
Chris@0 217
Chris@0 218 m_playSource = new AudioCallbackPlaySource(m_viewManager);
Chris@0 219
Chris@0 220 connect(m_playSource, SIGNAL(sampleRateMismatch(size_t, size_t, bool)),
Chris@0 221 this, SLOT(sampleRateMismatch(size_t, size_t, bool)));
Chris@42 222 connect(m_playSource, SIGNAL(audioOverloadPluginDisabled()),
Chris@42 223 this, SLOT(audioOverloadPluginDisabled()));
Chris@0 224
Chris@0 225 m_fader = new Fader(frame, false);
Chris@90 226 connect(m_fader, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
Chris@90 227 connect(m_fader, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
Chris@0 228
Chris@0 229 m_playSpeed = new AudioDial(frame);
Chris@12 230 m_playSpeed->setMinimum(0);
Chris@48 231 m_playSpeed->setMaximum(200);
Chris@25 232 m_playSpeed->setValue(100);
Chris@0 233 m_playSpeed->setFixedWidth(24);
Chris@0 234 m_playSpeed->setFixedHeight(24);
Chris@0 235 m_playSpeed->setNotchesVisible(true);
Chris@25 236 m_playSpeed->setPageStep(10);
Chris@60 237 m_playSpeed->setObjectName(tr("Playback Speedup"));
Chris@25 238 m_playSpeed->setDefaultValue(100);
Chris@59 239 m_playSpeed->setRangeMapper(new PlaySpeedRangeMapper(0, 200));
Chris@60 240 m_playSpeed->setShowToolTip(true);
Chris@0 241 connect(m_playSpeed, SIGNAL(valueChanged(int)),
Chris@0 242 this, SLOT(playSpeedChanged(int)));
Chris@90 243 connect(m_playSpeed, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
Chris@90 244 connect(m_playSpeed, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
Chris@90 245
Chris@168 246 IconLoader il;
Chris@168 247
Chris@90 248 m_playSharpen = new NotifyingPushButton(frame);
Chris@17 249 m_playSharpen->setToolTip(tr("Sharpen percussive transients"));
Chris@26 250 m_playSharpen->setFixedSize(20, 20);
Chris@16 251 m_playSharpen->setEnabled(false);
Chris@26 252 m_playSharpen->setCheckable(true);
Chris@26 253 m_playSharpen->setChecked(false);
Chris@168 254 m_playSharpen->setIcon(il.load("sharpen"));
Chris@26 255 connect(m_playSharpen, SIGNAL(clicked()), this, SLOT(playSharpenToggled()));
Chris@90 256 connect(m_playSharpen, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
Chris@90 257 connect(m_playSharpen, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
Chris@90 258
Chris@90 259 m_playMono = new NotifyingPushButton(frame);
Chris@26 260 m_playMono->setToolTip(tr("Run time stretcher in mono only"));
Chris@26 261 m_playMono->setFixedSize(20, 20);
Chris@26 262 m_playMono->setEnabled(false);
Chris@26 263 m_playMono->setCheckable(true);
Chris@26 264 m_playMono->setChecked(false);
Chris@168 265 m_playMono->setIcon(il.load("mono"));
Chris@26 266 connect(m_playMono, SIGNAL(clicked()), this, SLOT(playMonoToggled()));
Chris@90 267 connect(m_playMono, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
Chris@90 268 connect(m_playMono, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
Chris@21 269
Chris@21 270 QSettings settings;
Chris@21 271 settings.beginGroup("MainWindow");
Chris@24 272 m_playSharpen->setChecked(settings.value("playsharpen", true).toBool());
Chris@26 273 m_playMono->setChecked(settings.value("playmono", false).toBool());
Chris@21 274 settings.endGroup();
Chris@21 275
Chris@129 276 layout->setSpacing(4);
Chris@159 277 layout->addWidget(scroll, 0, 0, 1, 5);
Chris@65 278 layout->addWidget(m_overview, 1, 0);
Chris@0 279 layout->addWidget(m_fader, 1, 1);
Chris@0 280 layout->addWidget(m_playSpeed, 1, 2);
Chris@16 281 layout->addWidget(m_playSharpen, 1, 3);
Chris@26 282 layout->addWidget(m_playMono, 1, 4);
Chris@16 283
Chris@129 284 m_paneStack->setPropertyStackMinWidth
Chris@129 285 (m_fader->width() + m_playSpeed->width() + m_playSharpen->width() +
Chris@129 286 m_playMono->width() + layout->spacing() * 4);
Chris@129 287
Chris@16 288 layout->setColumnStretch(0, 10);
Chris@16 289
Chris@0 290 frame->setLayout(layout);
Chris@0 291
Chris@0 292 connect(m_viewManager, SIGNAL(outputLevelsChanged(float, float)),
Chris@0 293 this, SLOT(outputLevelsChanged(float, float)));
Chris@0 294
Chris@116 295 connect(m_viewManager, SIGNAL(playbackFrameChanged(unsigned long)),
Chris@116 296 this, SLOT(playbackFrameChanged(unsigned long)));
Chris@116 297
Chris@116 298 connect(m_viewManager, SIGNAL(globalCentreFrameChanged(unsigned long)),
Chris@116 299 this, SLOT(globalCentreFrameChanged(unsigned long)));
Chris@116 300
Chris@116 301 connect(m_viewManager, SIGNAL(viewCentreFrameChanged(View *, unsigned long)),
Chris@116 302 this, SLOT(viewCentreFrameChanged(View *, unsigned long)));
Chris@116 303
Chris@116 304 connect(m_viewManager, SIGNAL(viewZoomLevelChanged(View *, unsigned long, bool)),
Chris@116 305 this, SLOT(viewZoomLevelChanged(View *, unsigned long, bool)));
Chris@116 306
Chris@0 307 connect(Preferences::getInstance(),
Chris@0 308 SIGNAL(propertyChanged(PropertyContainer::PropertyName)),
Chris@0 309 this,
Chris@0 310 SLOT(preferenceChanged(PropertyContainer::PropertyName)));
Chris@0 311
Chris@98 312 // preferenceChanged("Property Box Layout");
Chris@98 313
Chris@70 314 if (m_oscQueue && m_oscQueue->isOK()) {
Chris@69 315 connect(m_oscQueue, SIGNAL(messagesAvailable()), this, SLOT(pollOSC()));
Chris@69 316 QTimer *oscTimer = new QTimer(this);
Chris@69 317 connect(oscTimer, SIGNAL(timeout()), this, SLOT(pollOSC()));
Chris@69 318 oscTimer->start(1000);
Chris@69 319 }
Chris@69 320
Chris@0 321 setupMenus();
Chris@0 322 setupToolbars();
Chris@155 323 setupHelpMenu();
Chris@0 324
Chris@90 325 statusBar();
Chris@0 326
Chris@0 327 newSession();
Chris@0 328 }
Chris@0 329
Chris@0 330 MainWindow::~MainWindow()
Chris@0 331 {
Chris@137 332 // std::cerr << "MainWindow::~MainWindow()" << std::endl;
Chris@118 333
Chris@70 334 if (!m_abandoning) {
Chris@70 335 closeSession();
Chris@70 336 }
Chris@0 337 delete m_playTarget;
Chris@0 338 delete m_playSource;
Chris@0 339 delete m_viewManager;
Chris@69 340 delete m_oscQueue;
Chris@162 341 delete m_keyReference;
Chris@163 342 delete m_preferencesDialog;
Chris@0 343 Profiles::getInstance()->dump();
Chris@0 344 }
Chris@0 345
Chris@81 346 QString
Chris@88 347 MainWindow::getOpenFileName(FileFinder::FileType type)
Chris@81 348 {
Chris@88 349 FileFinder *ff = FileFinder::getInstance();
Chris@81 350 switch (type) {
Chris@88 351 case FileFinder::SessionFile:
Chris@88 352 return ff->getOpenFileName(type, m_sessionFile);
Chris@88 353 case FileFinder::AudioFile:
Chris@88 354 return ff->getOpenFileName(type, m_audioFile);
Chris@88 355 case FileFinder::LayerFile:
Chris@88 356 return ff->getOpenFileName(type, m_sessionFile);
Chris@88 357 case FileFinder::SessionOrAudioFile:
Chris@88 358 return ff->getOpenFileName(type, m_sessionFile);
Chris@121 359 case FileFinder::ImageFile:
Chris@121 360 return ff->getOpenFileName(type, m_sessionFile);
Chris@88 361 case FileFinder::AnyFile:
Chris@88 362 if (getMainModel() != 0 &&
Chris@88 363 m_paneStack != 0 &&
Chris@88 364 m_paneStack->getCurrentPane() != 0) { // can import a layer
Chris@88 365 return ff->getOpenFileName(FileFinder::AnyFile, m_sessionFile);
Chris@81 366 } else {
Chris@88 367 return ff->getOpenFileName(FileFinder::SessionOrAudioFile,
Chris@88 368 m_sessionFile);
Chris@81 369 }
Chris@81 370 }
Chris@88 371 return "";
Chris@88 372 }
Chris@88 373
Chris@88 374 QString
Chris@88 375 MainWindow::getSaveFileName(FileFinder::FileType type)
Chris@88 376 {
Chris@88 377 FileFinder *ff = FileFinder::getInstance();
Chris@88 378 switch (type) {
Chris@88 379 case FileFinder::SessionFile:
Chris@88 380 return ff->getSaveFileName(type, m_sessionFile);
Chris@88 381 case FileFinder::AudioFile:
Chris@88 382 return ff->getSaveFileName(type, m_audioFile);
Chris@88 383 case FileFinder::LayerFile:
Chris@88 384 return ff->getSaveFileName(type, m_sessionFile);
Chris@88 385 case FileFinder::SessionOrAudioFile:
Chris@88 386 return ff->getSaveFileName(type, m_sessionFile);
Chris@121 387 case FileFinder::ImageFile:
Chris@121 388 return ff->getSaveFileName(type, m_sessionFile);
Chris@88 389 case FileFinder::AnyFile:
Chris@88 390 return ff->getSaveFileName(type, m_sessionFile);
Chris@81 391 }
Chris@88 392 return "";
Chris@81 393 }
Chris@81 394
Chris@88 395 void
Chris@88 396 MainWindow::registerLastOpenedFilePath(FileFinder::FileType type, QString path)
Chris@81 397 {
Chris@88 398 FileFinder *ff = FileFinder::getInstance();
Chris@88 399 ff->registerLastOpenedFilePath(type, path);
Chris@81 400 }
Chris@81 401
Chris@81 402 void
Chris@0 403 MainWindow::setupMenus()
Chris@0 404 {
Chris@0 405 if (!m_mainMenusCreated) {
Chris@0 406 m_rightButtonMenu = new QMenu();
Chris@104 407
Chris@104 408 // No -- we don't want tear-off enabled on the right-button
Chris@104 409 // menu. If it is enabled, then simply right-clicking and
Chris@104 410 // releasing will pop up the menu, activate the tear-off, and
Chris@104 411 // leave the torn-off menu window in front of the main window.
Chris@104 412 // That isn't desirable. I'm not sure it ever would be, in a
Chris@104 413 // context menu -- perhaps technically a Qt bug?
Chris@104 414 // m_rightButtonMenu->setTearOffEnabled(true);
Chris@0 415 }
Chris@0 416
Chris@0 417 if (m_rightButtonLayerMenu) {
Chris@0 418 m_rightButtonLayerMenu->clear();
Chris@0 419 } else {
Chris@0 420 m_rightButtonLayerMenu = m_rightButtonMenu->addMenu(tr("&Layer"));
Chris@97 421 m_rightButtonLayerMenu->setTearOffEnabled(true);
Chris@0 422 m_rightButtonMenu->addSeparator();
Chris@0 423 }
Chris@0 424
Chris@34 425 if (m_rightButtonTransformsMenu) {
Chris@34 426 m_rightButtonTransformsMenu->clear();
Chris@34 427 } else {
Chris@34 428 m_rightButtonTransformsMenu = m_rightButtonMenu->addMenu(tr("&Transform"));
Chris@97 429 m_rightButtonTransformsMenu->setTearOffEnabled(true);
Chris@34 430 m_rightButtonMenu->addSeparator();
Chris@34 431 }
Chris@34 432
Chris@0 433 if (!m_mainMenusCreated) {
Chris@0 434 CommandHistory::getInstance()->registerMenu(m_rightButtonMenu);
Chris@0 435 m_rightButtonMenu->addSeparator();
Chris@66 436 }
Chris@66 437
Chris@66 438 setupFileMenu();
Chris@66 439 setupEditMenu();
Chris@66 440 setupViewMenu();
Chris@66 441 setupPaneAndLayerMenus();
Chris@66 442 setupTransformsMenu();
Chris@66 443
Chris@66 444 m_mainMenusCreated = true;
Chris@66 445 }
Chris@66 446
Chris@66 447 void
Chris@66 448 MainWindow::setupFileMenu()
Chris@66 449 {
Chris@66 450 if (m_mainMenusCreated) return;
Chris@66 451
Chris@66 452 QMenu *menu = menuBar()->addMenu(tr("&File"));
Chris@97 453 menu->setTearOffEnabled(true);
Chris@66 454 QToolBar *toolbar = addToolBar(tr("File Toolbar"));
Chris@66 455
Chris@162 456 m_keyReference->setCategory(tr("File and Session Management"));
Chris@162 457
Chris@168 458 IconLoader il;
Chris@168 459
Chris@168 460 QIcon icon = il.load("filenew");
Chris@168 461 icon.addPixmap(il.loadPixmap("filenew-22"));
Chris@66 462 QAction *action = new QAction(icon, tr("&New Session"), this);
Chris@66 463 action->setShortcut(tr("Ctrl+N"));
Chris@90 464 action->setStatusTip(tr("Abandon the current Sonic Visualiser session and start a new one"));
Chris@66 465 connect(action, SIGNAL(triggered()), this, SLOT(newSession()));
Chris@162 466 m_keyReference->registerShortcut(action);
Chris@66 467 menu->addAction(action);
Chris@66 468 toolbar->addAction(action);
Chris@138 469
Chris@168 470 icon = il.load("fileopensession");
Chris@66 471 action = new QAction(icon, tr("&Open Session..."), this);
Chris@66 472 action->setShortcut(tr("Ctrl+O"));
Chris@66 473 action->setStatusTip(tr("Open a previously saved Sonic Visualiser session file"));
Chris@66 474 connect(action, SIGNAL(triggered()), this, SLOT(openSession()));
Chris@162 475 m_keyReference->registerShortcut(action);
Chris@66 476 menu->addAction(action);
Chris@66 477
Chris@168 478 icon = il.load("fileopen");
Chris@168 479 icon.addPixmap(il.loadPixmap("fileopen-22"));
Chris@138 480
Chris@66 481 action = new QAction(icon, tr("&Open..."), this);
Chris@66 482 action->setStatusTip(tr("Open a session file, audio file, or layer"));
Chris@66 483 connect(action, SIGNAL(triggered()), this, SLOT(openSomething()));
Chris@66 484 toolbar->addAction(action);
Chris@66 485
Chris@168 486 icon = il.load("filesave");
Chris@168 487 icon.addPixmap(il.loadPixmap("filesave-22"));
Chris@66 488 action = new QAction(icon, tr("&Save Session"), this);
Chris@66 489 action->setShortcut(tr("Ctrl+S"));
Chris@66 490 action->setStatusTip(tr("Save the current session into a Sonic Visualiser session file"));
Chris@66 491 connect(action, SIGNAL(triggered()), this, SLOT(saveSession()));
Chris@66 492 connect(this, SIGNAL(canSave(bool)), action, SLOT(setEnabled(bool)));
Chris@162 493 m_keyReference->registerShortcut(action);
Chris@66 494 menu->addAction(action);
Chris@66 495 toolbar->addAction(action);
Chris@0 496
Chris@168 497 icon = il.load("filesaveas");
Chris@168 498 icon.addPixmap(il.loadPixmap("filesaveas-22"));
Chris@66 499 action = new QAction(icon, tr("Save Session &As..."), this);
Chris@66 500 action->setStatusTip(tr("Save the current session into a new Sonic Visualiser session file"));
Chris@66 501 connect(action, SIGNAL(triggered()), this, SLOT(saveSessionAs()));
Chris@66 502 menu->addAction(action);
Chris@66 503 toolbar->addAction(action);
Chris@66 504
Chris@66 505 menu->addSeparator();
Chris@66 506
Chris@168 507 icon = il.load("fileopenaudio");
Chris@138 508 action = new QAction(icon, tr("&Import Audio File..."), this);
Chris@66 509 action->setShortcut(tr("Ctrl+I"));
Chris@66 510 action->setStatusTip(tr("Import an existing audio file"));
Chris@66 511 connect(action, SIGNAL(triggered()), this, SLOT(importAudio()));
Chris@162 512 m_keyReference->registerShortcut(action);
Chris@66 513 menu->addAction(action);
Chris@66 514
Chris@66 515 action = new QAction(tr("Import Secondary Audio File..."), this);
Chris@66 516 action->setShortcut(tr("Ctrl+Shift+I"));
Chris@66 517 action->setStatusTip(tr("Import an extra audio file as a separate layer"));
Chris@66 518 connect(action, SIGNAL(triggered()), this, SLOT(importMoreAudio()));
Chris@66 519 connect(this, SIGNAL(canImportMoreAudio(bool)), action, SLOT(setEnabled(bool)));
Chris@162 520 m_keyReference->registerShortcut(action);
Chris@66 521 menu->addAction(action);
Chris@66 522
Chris@66 523 action = new QAction(tr("&Export Audio File..."), this);
Chris@66 524 action->setStatusTip(tr("Export selection as an audio file"));
Chris@66 525 connect(action, SIGNAL(triggered()), this, SLOT(exportAudio()));
Chris@66 526 connect(this, SIGNAL(canExportAudio(bool)), action, SLOT(setEnabled(bool)));
Chris@66 527 menu->addAction(action);
Chris@66 528
Chris@66 529 menu->addSeparator();
Chris@66 530
Chris@66 531 action = new QAction(tr("Import Annotation &Layer..."), this);
Chris@66 532 action->setShortcut(tr("Ctrl+L"));
Chris@66 533 action->setStatusTip(tr("Import layer data from an existing file"));
Chris@66 534 connect(action, SIGNAL(triggered()), this, SLOT(importLayer()));
Chris@66 535 connect(this, SIGNAL(canImportLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@162 536 m_keyReference->registerShortcut(action);
Chris@66 537 menu->addAction(action);
Chris@66 538
Chris@66 539 action = new QAction(tr("Export Annotation Layer..."), this);
Chris@66 540 action->setStatusTip(tr("Export layer data to a file"));
Chris@66 541 connect(action, SIGNAL(triggered()), this, SLOT(exportLayer()));
Chris@66 542 connect(this, SIGNAL(canExportLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@66 543 menu->addAction(action);
Chris@66 544
Chris@66 545 menu->addSeparator();
Chris@86 546
Chris@121 547 action = new QAction(tr("Export Image File..."), this);
Chris@121 548 action->setStatusTip(tr("Export a single pane to an image file"));
Chris@121 549 connect(action, SIGNAL(triggered()), this, SLOT(exportImage()));
Chris@121 550 connect(this, SIGNAL(canExportImage(bool)), action, SLOT(setEnabled(bool)));
Chris@121 551 menu->addAction(action);
Chris@121 552
Chris@121 553 menu->addSeparator();
Chris@121 554
Chris@86 555 action = new QAction(tr("Open Lo&cation..."), this);
Chris@86 556 action->setShortcut(tr("Ctrl+Shift+O"));
Chris@86 557 action->setStatusTip(tr("Open or import a file from a remote URL"));
Chris@86 558 connect(action, SIGNAL(triggered()), this, SLOT(openLocation()));
Chris@162 559 m_keyReference->registerShortcut(action);
Chris@86 560 menu->addAction(action);
Chris@86 561
Chris@86 562 menu->addSeparator();
Chris@86 563
Chris@66 564 m_recentFilesMenu = menu->addMenu(tr("&Recent Files"));
Chris@97 565 m_recentFilesMenu->setTearOffEnabled(true);
Chris@66 566 setupRecentFilesMenu();
Chris@66 567 connect(&m_recentFiles, SIGNAL(recentChanged()),
Chris@66 568 this, SLOT(setupRecentFilesMenu()));
Chris@66 569
Chris@66 570 menu->addSeparator();
Chris@66 571 action = new QAction(tr("&Preferences..."), this);
Chris@66 572 action->setStatusTip(tr("Adjust the application preferences"));
Chris@66 573 connect(action, SIGNAL(triggered()), this, SLOT(preferences()));
Chris@66 574 menu->addAction(action);
Chris@0 575
Chris@66 576 menu->addSeparator();
Chris@168 577 action = new QAction(il.load("exit"),
Chris@66 578 tr("&Quit"), this);
Chris@66 579 action->setShortcut(tr("Ctrl+Q"));
Chris@90 580 action->setStatusTip(tr("Exit Sonic Visualiser"));
Chris@66 581 connect(action, SIGNAL(triggered()), this, SLOT(close()));
Chris@162 582 m_keyReference->registerShortcut(action);
Chris@66 583 menu->addAction(action);
Chris@66 584 }
Chris@66 585
Chris@66 586 void
Chris@66 587 MainWindow::setupEditMenu()
Chris@66 588 {
Chris@66 589 if (m_mainMenusCreated) return;
Chris@66 590
Chris@66 591 QMenu *menu = menuBar()->addMenu(tr("&Edit"));
Chris@97 592 menu->setTearOffEnabled(true);
Chris@66 593 CommandHistory::getInstance()->registerMenu(menu);
Chris@66 594
Chris@162 595 m_keyReference->setCategory(tr("Editing"));
Chris@162 596
Chris@66 597 menu->addSeparator();
Chris@66 598
Chris@168 599 IconLoader il;
Chris@168 600
Chris@168 601 QAction *action = new QAction(il.load("editcut"),
Chris@66 602 tr("Cu&t"), this);
Chris@66 603 action->setShortcut(tr("Ctrl+X"));
Chris@90 604 action->setStatusTip(tr("Cut the selection from the current layer to the clipboard"));
Chris@66 605 connect(action, SIGNAL(triggered()), this, SLOT(cut()));
Chris@66 606 connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@162 607 m_keyReference->registerShortcut(action);
Chris@66 608 menu->addAction(action);
Chris@66 609 m_rightButtonMenu->addAction(action);
Chris@66 610
Chris@168 611 action = new QAction(il.load("editcopy"),
Chris@66 612 tr("&Copy"), this);
Chris@66 613 action->setShortcut(tr("Ctrl+C"));
Chris@90 614 action->setStatusTip(tr("Copy the selection from the current layer to the clipboard"));
Chris@66 615 connect(action, SIGNAL(triggered()), this, SLOT(copy()));
Chris@66 616 connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@162 617 m_keyReference->registerShortcut(action);
Chris@66 618 menu->addAction(action);
Chris@66 619 m_rightButtonMenu->addAction(action);
Chris@66 620
Chris@168 621 action = new QAction(il.load("editpaste"),
Chris@66 622 tr("&Paste"), this);
Chris@66 623 action->setShortcut(tr("Ctrl+V"));
Chris@90 624 action->setStatusTip(tr("Paste from the clipboard to the current layer"));
Chris@66 625 connect(action, SIGNAL(triggered()), this, SLOT(paste()));
Chris@66 626 connect(this, SIGNAL(canPaste(bool)), action, SLOT(setEnabled(bool)));
Chris@162 627 m_keyReference->registerShortcut(action);
Chris@66 628 menu->addAction(action);
Chris@66 629 m_rightButtonMenu->addAction(action);
Chris@66 630
Chris@164 631 m_deleteSelectedAction = new QAction(tr("&Delete Selected Items"), this);
Chris@164 632 m_deleteSelectedAction->setShortcut(tr("Del"));
Chris@164 633 m_deleteSelectedAction->setStatusTip(tr("Delete items in current selection from the current layer"));
Chris@164 634 connect(m_deleteSelectedAction, SIGNAL(triggered()), this, SLOT(deleteSelected()));
Chris@164 635 connect(this, SIGNAL(canDeleteSelection(bool)), m_deleteSelectedAction, SLOT(setEnabled(bool)));
Chris@164 636 m_keyReference->registerShortcut(m_deleteSelectedAction);
Chris@164 637 menu->addAction(m_deleteSelectedAction);
Chris@164 638 m_rightButtonMenu->addAction(m_deleteSelectedAction);
Chris@66 639
Chris@66 640 menu->addSeparator();
Chris@66 641 m_rightButtonMenu->addSeparator();
Chris@162 642
Chris@162 643 m_keyReference->setCategory(tr("Selection"));
Chris@162 644
Chris@66 645 action = new QAction(tr("Select &All"), this);
Chris@66 646 action->setShortcut(tr("Ctrl+A"));
Chris@90 647 action->setStatusTip(tr("Select the whole duration of the current session"));
Chris@66 648 connect(action, SIGNAL(triggered()), this, SLOT(selectAll()));
Chris@66 649 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
Chris@162 650 m_keyReference->registerShortcut(action);
Chris@66 651 menu->addAction(action);
Chris@66 652 m_rightButtonMenu->addAction(action);
Chris@0 653
Chris@66 654 action = new QAction(tr("Select &Visible Range"), this);
Chris@66 655 action->setShortcut(tr("Ctrl+Shift+A"));
Chris@90 656 action->setStatusTip(tr("Select the time range corresponding to the current window width"));
Chris@66 657 connect(action, SIGNAL(triggered()), this, SLOT(selectVisible()));
Chris@66 658 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
Chris@162 659 m_keyReference->registerShortcut(action);
Chris@66 660 menu->addAction(action);
Chris@0 661
Chris@66 662 action = new QAction(tr("Select to &Start"), this);
Chris@66 663 action->setShortcut(tr("Shift+Left"));
Chris@90 664 action->setStatusTip(tr("Select from the start of the session to the current playback position"));
Chris@66 665 connect(action, SIGNAL(triggered()), this, SLOT(selectToStart()));
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@0 669
Chris@66 670 action = new QAction(tr("Select to &End"), this);
Chris@66 671 action->setShortcut(tr("Shift+Right"));
Chris@90 672 action->setStatusTip(tr("Select from the current playback position to the end of the session"));
Chris@66 673 connect(action, SIGNAL(triggered()), this, SLOT(selectToEnd()));
Chris@66 674 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
Chris@162 675 m_keyReference->registerShortcut(action);
Chris@66 676 menu->addAction(action);
Chris@66 677
Chris@66 678 action = new QAction(tr("C&lear Selection"), this);
Chris@66 679 action->setShortcut(tr("Esc"));
Chris@90 680 action->setStatusTip(tr("Clear the selection"));
Chris@66 681 connect(action, SIGNAL(triggered()), this, SLOT(clearSelection()));
Chris@66 682 connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@162 683 m_keyReference->registerShortcut(action);
Chris@66 684 menu->addAction(action);
Chris@66 685 m_rightButtonMenu->addAction(action);
Chris@66 686
Chris@66 687 menu->addSeparator();
Chris@66 688
Chris@162 689 m_keyReference->setCategory(tr("Tapping Time Instants"));
Chris@162 690
Chris@66 691 action = new QAction(tr("&Insert Instant at Playback Position"), this);
Chris@66 692 action->setShortcut(tr("Enter"));
Chris@90 693 action->setStatusTip(tr("Insert a new time instant at the current playback position, in a new layer if necessary"));
Chris@66 694 connect(action, SIGNAL(triggered()), this, SLOT(insertInstant()));
Chris@66 695 connect(this, SIGNAL(canInsertInstant(bool)), action, SLOT(setEnabled(bool)));
Chris@162 696 m_keyReference->registerShortcut(action);
Chris@66 697 menu->addAction(action);
Chris@66 698
Chris@162 699 // Laptop shortcut (no keypad Enter key)
Chris@162 700 QString shortcut(tr(";"));
Chris@162 701 connect(new QShortcut(shortcut, this), SIGNAL(activated()),
Chris@162 702 this, SLOT(insertInstant()));
Chris@162 703 m_keyReference->registerAlternativeShortcut(action, shortcut);
Chris@162 704
Chris@81 705 action = new QAction(tr("Insert Instants at Selection &Boundaries"), this);
Chris@81 706 action->setShortcut(tr("Shift+Enter"));
Chris@163 707 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 708 connect(action, SIGNAL(triggered()), this, SLOT(insertInstantsAtBoundaries()));
Chris@81 709 connect(this, SIGNAL(canInsertInstantsAtBoundaries(bool)), action, SLOT(setEnabled(bool)));
Chris@162 710 m_keyReference->registerShortcut(action);
Chris@81 711 menu->addAction(action);
Chris@66 712 }
Chris@66 713
Chris@66 714 void
Chris@66 715 MainWindow::setupViewMenu()
Chris@66 716 {
Chris@66 717 if (m_mainMenusCreated) return;
Chris@66 718
Chris@168 719 IconLoader il;
Chris@168 720
Chris@90 721 QAction *action = 0;
Chris@90 722
Chris@162 723 m_keyReference->setCategory(tr("Panning and Navigation"));
Chris@162 724
Chris@66 725 QMenu *menu = menuBar()->addMenu(tr("&View"));
Chris@97 726 menu->setTearOffEnabled(true);
Chris@66 727 action = new QAction(tr("Scroll &Left"), this);
Chris@66 728 action->setShortcut(tr("Left"));
Chris@66 729 action->setStatusTip(tr("Scroll the current pane to the left"));
Chris@66 730 connect(action, SIGNAL(triggered()), this, SLOT(scrollLeft()));
Chris@66 731 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@162 732 m_keyReference->registerShortcut(action);
Chris@66 733 menu->addAction(action);
Chris@0 734
Chris@66 735 action = new QAction(tr("Scroll &Right"), this);
Chris@66 736 action->setShortcut(tr("Right"));
Chris@66 737 action->setStatusTip(tr("Scroll the current pane to the right"));
Chris@66 738 connect(action, SIGNAL(triggered()), this, SLOT(scrollRight()));
Chris@66 739 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@162 740 m_keyReference->registerShortcut(action);
Chris@66 741 menu->addAction(action);
Chris@0 742
Chris@90 743 action = new QAction(tr("&Jump Left"), this);
Chris@66 744 action->setShortcut(tr("Ctrl+Left"));
Chris@66 745 action->setStatusTip(tr("Scroll the current pane a big step to the left"));
Chris@66 746 connect(action, SIGNAL(triggered()), this, SLOT(jumpLeft()));
Chris@66 747 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@162 748 m_keyReference->registerShortcut(action);
Chris@66 749 menu->addAction(action);
Chris@0 750
Chris@90 751 action = new QAction(tr("J&ump Right"), this);
Chris@66 752 action->setShortcut(tr("Ctrl+Right"));
Chris@66 753 action->setStatusTip(tr("Scroll the current pane a big step to the right"));
Chris@66 754 connect(action, SIGNAL(triggered()), this, SLOT(jumpRight()));
Chris@66 755 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@162 756 m_keyReference->registerShortcut(action);
Chris@66 757 menu->addAction(action);
Chris@66 758
Chris@66 759 menu->addSeparator();
Chris@66 760
Chris@162 761 m_keyReference->setCategory(tr("Zoom"));
Chris@162 762
Chris@168 763 action = new QAction(il.load("zoom-in"),
Chris@66 764 tr("Zoom &In"), this);
Chris@66 765 action->setShortcut(tr("Up"));
Chris@66 766 action->setStatusTip(tr("Increase the zoom level"));
Chris@66 767 connect(action, SIGNAL(triggered()), this, SLOT(zoomIn()));
Chris@66 768 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@162 769 m_keyReference->registerShortcut(action);
Chris@66 770 menu->addAction(action);
Chris@0 771
Chris@168 772 action = new QAction(il.load("zoom-out"),
Chris@66 773 tr("Zoom &Out"), this);
Chris@66 774 action->setShortcut(tr("Down"));
Chris@66 775 action->setStatusTip(tr("Decrease the zoom level"));
Chris@66 776 connect(action, SIGNAL(triggered()), this, SLOT(zoomOut()));
Chris@66 777 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@162 778 m_keyReference->registerShortcut(action);
Chris@66 779 menu->addAction(action);
Chris@0 780
Chris@66 781 action = new QAction(tr("Restore &Default Zoom"), this);
Chris@90 782 action->setStatusTip(tr("Restore the zoom level to the default"));
Chris@66 783 connect(action, SIGNAL(triggered()), this, SLOT(zoomDefault()));
Chris@66 784 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@66 785 menu->addAction(action);
Chris@66 786
Chris@168 787 action = new QAction(il.load("zoom-fit"),
Chris@138 788 tr("Zoom to &Fit"), this);
Chris@155 789 action->setShortcut(tr("F"));
Chris@66 790 action->setStatusTip(tr("Zoom to show the whole file"));
Chris@66 791 connect(action, SIGNAL(triggered()), this, SLOT(zoomToFit()));
Chris@66 792 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@162 793 m_keyReference->registerShortcut(action);
Chris@66 794 menu->addAction(action);
Chris@90 795
Chris@90 796 menu->addSeparator();
Chris@90 797
Chris@162 798 m_keyReference->setCategory(tr("Display Features"));
Chris@162 799
Chris@90 800 QActionGroup *overlayGroup = new QActionGroup(this);
Chris@90 801
Chris@90 802 action = new QAction(tr("Show &No Overlays"), this);
Chris@90 803 action->setShortcut(tr("0"));
Chris@90 804 action->setStatusTip(tr("Hide centre indicator, frame times, layer names and scale"));
Chris@90 805 connect(action, SIGNAL(triggered()), this, SLOT(showNoOverlays()));
Chris@90 806 action->setCheckable(true);
Chris@90 807 action->setChecked(false);
Chris@90 808 overlayGroup->addAction(action);
Chris@162 809 m_keyReference->registerShortcut(action);
Chris@90 810 menu->addAction(action);
Chris@90 811
Chris@90 812 action = new QAction(tr("Show &Minimal Overlays"), this);
Chris@90 813 action->setShortcut(tr("9"));
Chris@90 814 action->setStatusTip(tr("Show centre indicator only"));
Chris@90 815 connect(action, SIGNAL(triggered()), this, SLOT(showMinimalOverlays()));
Chris@90 816 action->setCheckable(true);
Chris@90 817 action->setChecked(false);
Chris@90 818 overlayGroup->addAction(action);
Chris@162 819 m_keyReference->registerShortcut(action);
Chris@90 820 menu->addAction(action);
Chris@90 821
Chris@90 822 action = new QAction(tr("Show &Standard Overlays"), this);
Chris@90 823 action->setShortcut(tr("8"));
Chris@90 824 action->setStatusTip(tr("Show centre indicator, frame times and scale"));
Chris@90 825 connect(action, SIGNAL(triggered()), this, SLOT(showStandardOverlays()));
Chris@90 826 action->setCheckable(true);
Chris@90 827 action->setChecked(true);
Chris@90 828 overlayGroup->addAction(action);
Chris@162 829 m_keyReference->registerShortcut(action);
Chris@90 830 menu->addAction(action);
Chris@90 831
Chris@90 832 action = new QAction(tr("Show &All Overlays"), this);
Chris@90 833 action->setShortcut(tr("7"));
Chris@90 834 action->setStatusTip(tr("Show all texts and scale"));
Chris@90 835 connect(action, SIGNAL(triggered()), this, SLOT(showAllOverlays()));
Chris@90 836 action->setCheckable(true);
Chris@90 837 action->setChecked(false);
Chris@90 838 overlayGroup->addAction(action);
Chris@162 839 m_keyReference->registerShortcut(action);
Chris@90 840 menu->addAction(action);
Chris@7 841
Chris@72 842 menu->addSeparator();
Chris@72 843
Chris@171 844 /* Doesn't quite work well enough
Chris@171 845
Chris@171 846 action = new QAction(tr("Use Dar&k Background"), this);
Chris@171 847 action->setStatusTip(tr("Switch between light and dark background colour schemes"));
Chris@171 848 connect(action, SIGNAL(triggered()), this, SLOT(toggleDarkBackground()));
Chris@171 849 action->setCheckable(true);
Chris@171 850 action->setChecked(m_viewManager->getGlobalDarkBackground());
Chris@171 851 menu->addAction(action);
Chris@171 852
Chris@171 853 menu->addSeparator();
Chris@171 854
Chris@171 855 */
Chris@171 856
Chris@66 857 action = new QAction(tr("Show &Zoom Wheels"), this);
Chris@66 858 action->setShortcut(tr("Z"));
Chris@66 859 action->setStatusTip(tr("Show thumbwheels for zooming horizontally and vertically"));
Chris@66 860 connect(action, SIGNAL(triggered()), this, SLOT(toggleZoomWheels()));
Chris@66 861 action->setCheckable(true);
Chris@66 862 action->setChecked(m_viewManager->getZoomWheelsEnabled());
Chris@162 863 m_keyReference->registerShortcut(action);
Chris@66 864 menu->addAction(action);
Chris@72 865
Chris@72 866 action = new QAction(tr("Show Property Bo&xes"), this);
Chris@72 867 action->setShortcut(tr("X"));
Chris@72 868 action->setStatusTip(tr("Show the layer property boxes at the side of the main window"));
Chris@72 869 connect(action, SIGNAL(triggered()), this, SLOT(togglePropertyBoxes()));
Chris@72 870 action->setCheckable(true);
Chris@72 871 action->setChecked(true);
Chris@162 872 m_keyReference->registerShortcut(action);
Chris@72 873 menu->addAction(action);
Chris@0 874
Chris@90 875 action = new QAction(tr("Show Status &Bar"), this);
Chris@90 876 action->setStatusTip(tr("Show context help information in the status bar at the bottom of the window"));
Chris@90 877 connect(action, SIGNAL(triggered()), this, SLOT(toggleStatusBar()));
Chris@90 878 action->setCheckable(true);
Chris@90 879 action->setChecked(true);
Chris@90 880 menu->addAction(action);
Chris@90 881
Chris@90 882 QSettings settings;
Chris@90 883 settings.beginGroup("MainWindow");
Chris@90 884 bool sb = settings.value("showstatusbar", true).toBool();
Chris@90 885 if (!sb) {
Chris@90 886 action->setChecked(false);
Chris@90 887 statusBar()->hide();
Chris@90 888 }
Chris@90 889 settings.endGroup();
Chris@90 890
Chris@66 891 menu->addSeparator();
Chris@66 892
Chris@90 893 action = new QAction(tr("Show La&yer Hierarchy"), this);
Chris@155 894 action->setShortcut(tr("H"));
Chris@90 895 action->setStatusTip(tr("Open a window displaying the hierarchy of panes and layers in this session"));
Chris@66 896 connect(action, SIGNAL(triggered()), this, SLOT(showLayerTree()));
Chris@162 897 m_keyReference->registerShortcut(action);
Chris@66 898 menu->addAction(action);
Chris@66 899 }
Chris@66 900
Chris@66 901 void
Chris@66 902 MainWindow::setupPaneAndLayerMenus()
Chris@66 903 {
Chris@0 904 if (m_paneMenu) {
Chris@0 905 m_paneActions.clear();
Chris@0 906 m_paneMenu->clear();
Chris@0 907 } else {
Chris@0 908 m_paneMenu = menuBar()->addMenu(tr("&Pane"));
Chris@97 909 m_paneMenu->setTearOffEnabled(true);
Chris@0 910 }
Chris@0 911
Chris@0 912 if (m_layerMenu) {
Chris@0 913 m_layerActions.clear();
Chris@0 914 m_layerMenu->clear();
Chris@0 915 } else {
Chris@0 916 m_layerMenu = menuBar()->addMenu(tr("&Layer"));
Chris@97 917 m_layerMenu->setTearOffEnabled(true);
Chris@0 918 }
Chris@0 919
Chris@66 920 QMenu *menu = m_paneMenu;
Chris@66 921
Chris@168 922 IconLoader il;
Chris@168 923
Chris@162 924 m_keyReference->setCategory(tr("Managing Panes and Layers"));
Chris@162 925
Chris@168 926 QAction *action = new QAction(il.load("pane"), tr("Add &New Pane"), this);
Chris@155 927 action->setShortcut(tr("N"));
Chris@66 928 action->setStatusTip(tr("Add a new pane containing only a time ruler"));
Chris@66 929 connect(action, SIGNAL(triggered()), this, SLOT(addPane()));
Chris@66 930 connect(this, SIGNAL(canAddPane(bool)), action, SLOT(setEnabled(bool)));
Chris@66 931 m_paneActions[action] = PaneConfiguration(LayerFactory::TimeRuler);
Chris@162 932 m_keyReference->registerShortcut(action);
Chris@66 933 menu->addAction(action);
Chris@66 934
Chris@66 935 menu->addSeparator();
Chris@66 936
Chris@66 937 menu = m_layerMenu;
Chris@66 938
Chris@66 939 // menu->addSeparator();
Chris@66 940
Chris@66 941 LayerFactory::LayerTypeSet emptyLayerTypes =
Chris@66 942 LayerFactory::getInstance()->getValidEmptyLayerTypes();
Chris@66 943
Chris@66 944 for (LayerFactory::LayerTypeSet::iterator i = emptyLayerTypes.begin();
Chris@66 945 i != emptyLayerTypes.end(); ++i) {
Chris@66 946
Chris@66 947 QIcon icon;
Chris@66 948 QString mainText, tipText, channelText;
Chris@66 949 LayerFactory::LayerType type = *i;
Chris@66 950 QString name = LayerFactory::getInstance()->getLayerPresentationName(type);
Chris@66 951
Chris@168 952 icon = il.load(LayerFactory::getInstance()->getLayerIconName(type));
Chris@66 953
Chris@66 954 mainText = tr("Add New %1 Layer").arg(name);
Chris@66 955 tipText = tr("Add a new empty layer of type %1").arg(name);
Chris@66 956
Chris@66 957 action = new QAction(icon, mainText, this);
Chris@66 958 action->setStatusTip(tipText);
Chris@66 959
Chris@66 960 if (type == LayerFactory::Text) {
Chris@155 961 action->setShortcut(tr("T"));
Chris@162 962 m_keyReference->registerShortcut(action);
Chris@66 963 }
Chris@66 964
Chris@66 965 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@66 966 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@66 967 m_layerActions[action] = type;
Chris@66 968 menu->addAction(action);
Chris@66 969 m_rightButtonLayerMenu->addAction(action);
Chris@66 970 }
Chris@66 971
Chris@66 972 m_rightButtonLayerMenu->addSeparator();
Chris@66 973 menu->addSeparator();
Chris@66 974
Chris@66 975 LayerFactory::LayerType backgroundTypes[] = {
Chris@66 976 LayerFactory::Waveform,
Chris@66 977 LayerFactory::Spectrogram,
Chris@66 978 LayerFactory::MelodicRangeSpectrogram,
Chris@66 979 LayerFactory::PeakFrequencySpectrogram,
Chris@66 980 LayerFactory::Spectrum
Chris@66 981 };
Chris@66 982
Chris@66 983 std::vector<Model *> models;
Chris@66 984 if (m_document) models = m_document->getTransformInputModels(); //!!! not well named for this!
Chris@66 985 bool plural = (models.size() > 1);
Chris@66 986 if (models.empty()) {
Chris@67 987 models.push_back(getMainModel()); // probably 0
Chris@66 988 }
Chris@66 989
Chris@66 990 for (unsigned int i = 0;
Chris@66 991 i < sizeof(backgroundTypes)/sizeof(backgroundTypes[0]); ++i) {
Chris@66 992
Chris@66 993 for (int menuType = 0; menuType <= 1; ++menuType) { // pane, layer
Chris@66 994
Chris@66 995 if (menuType == 0) menu = m_paneMenu;
Chris@66 996 else menu = m_layerMenu;
Chris@66 997
Chris@66 998 QMenu *submenu = 0;
Chris@66 999
Chris@66 1000 QIcon icon;
Chris@66 1001 QString mainText, shortcutText, tipText, channelText;
Chris@66 1002 LayerFactory::LayerType type = backgroundTypes[i];
Chris@66 1003 bool mono = true;
Chris@66 1004
Chris@66 1005 switch (type) {
Chris@66 1006
Chris@66 1007 case LayerFactory::Waveform:
Chris@168 1008 icon = il.load("waveform");
Chris@66 1009 mainText = tr("Add &Waveform");
Chris@66 1010 if (menuType == 0) {
Chris@155 1011 shortcutText = tr("W");
Chris@66 1012 tipText = tr("Add a new pane showing a waveform view");
Chris@66 1013 } else {
Chris@66 1014 tipText = tr("Add a new layer showing a waveform view");
Chris@66 1015 }
Chris@66 1016 mono = false;
Chris@66 1017 break;
Chris@66 1018
Chris@66 1019 case LayerFactory::Spectrogram:
Chris@168 1020 icon = il.load("spectrogram");
Chris@161 1021 mainText = tr("Add Spectro&gram");
Chris@66 1022 if (menuType == 0) {
Chris@155 1023 shortcutText = tr("G");
Chris@90 1024 tipText = tr("Add a new pane showing a spectrogram");
Chris@66 1025 } else {
Chris@90 1026 tipText = tr("Add a new layer showing a spectrogram");
Chris@66 1027 }
Chris@66 1028 break;
Chris@66 1029
Chris@66 1030 case LayerFactory::MelodicRangeSpectrogram:
Chris@168 1031 icon = il.load("spectrogram");
Chris@66 1032 mainText = tr("Add &Melodic Range Spectrogram");
Chris@66 1033 if (menuType == 0) {
Chris@155 1034 shortcutText = tr("M");
Chris@90 1035 tipText = tr("Add a new pane showing a spectrogram set up for an overview of note pitches");
Chris@66 1036 } else {
Chris@90 1037 tipText = tr("Add a new layer showing a spectrogram set up for an overview of note pitches");
Chris@66 1038 }
Chris@66 1039 break;
Chris@66 1040
Chris@66 1041 case LayerFactory::PeakFrequencySpectrogram:
Chris@168 1042 icon = il.load("spectrogram");
Chris@155 1043 mainText = tr("Add Pea&k Frequency Spectrogram");
Chris@66 1044 if (menuType == 0) {
Chris@155 1045 shortcutText = tr("K");
Chris@66 1046 tipText = tr("Add a new pane showing a spectrogram set up for tracking frequencies");
Chris@66 1047 } else {
Chris@66 1048 tipText = tr("Add a new layer showing a spectrogram set up for tracking frequencies");
Chris@66 1049 }
Chris@66 1050 break;
Chris@66 1051
Chris@66 1052 case LayerFactory::Spectrum:
Chris@168 1053 icon = il.load("spectrum");
Chris@66 1054 mainText = tr("Add Spectr&um");
Chris@66 1055 if (menuType == 0) {
Chris@155 1056 shortcutText = tr("U");
Chris@66 1057 tipText = tr("Add a new pane showing a frequency spectrum");
Chris@66 1058 } else {
Chris@66 1059 tipText = tr("Add a new layer showing a frequency spectrum");
Chris@66 1060 }
Chris@66 1061 break;
Chris@66 1062
Chris@66 1063 default: break;
Chris@66 1064 }
Chris@66 1065
Chris@66 1066 std::vector<Model *> candidateModels;
Chris@66 1067 if (menuType == 0) {
Chris@66 1068 candidateModels = models;
Chris@66 1069 } else {
Chris@66 1070 candidateModels.push_back(0);
Chris@66 1071 }
Chris@66 1072
Chris@66 1073 for (std::vector<Model *>::iterator mi =
Chris@66 1074 candidateModels.begin();
Chris@66 1075 mi != candidateModels.end(); ++mi) {
Chris@66 1076
Chris@66 1077 Model *model = *mi;
Chris@66 1078
Chris@66 1079 int channels = 0;
Chris@66 1080 if (model) {
Chris@66 1081 DenseTimeValueModel *dtvm =
Chris@66 1082 dynamic_cast<DenseTimeValueModel *>(model);
Chris@66 1083 if (dtvm) channels = dtvm->getChannelCount();
Chris@66 1084 }
Chris@66 1085 if (channels < 1 && getMainModel()) {
Chris@66 1086 channels = getMainModel()->getChannelCount();
Chris@66 1087 }
Chris@66 1088 if (channels < 1) channels = 1;
Chris@66 1089
Chris@66 1090 for (int c = 0; c <= channels; ++c) {
Chris@66 1091
Chris@66 1092 if (c == 1 && channels == 1) continue;
Chris@66 1093 bool isDefault = (c == 0);
Chris@66 1094 bool isOnly = (isDefault && (channels == 1));
Chris@66 1095
Chris@66 1096 if (menuType == 1) {
Chris@66 1097 if (isDefault) isOnly = true;
Chris@66 1098 else continue;
Chris@66 1099 }
Chris@66 1100
Chris@66 1101 if (isOnly && (!plural || menuType == 1)) {
Chris@66 1102
Chris@138 1103 if (menuType == 1 && type != LayerFactory::Waveform) {
Chris@67 1104 action = new QAction(mainText, this);
Chris@67 1105 } else {
Chris@67 1106 action = new QAction(icon, mainText, this);
Chris@67 1107 }
Chris@67 1108
Chris@66 1109 action->setShortcut(shortcutText);
Chris@66 1110 action->setStatusTip(tipText);
Chris@66 1111 if (menuType == 0) {
Chris@66 1112 connect(action, SIGNAL(triggered()),
Chris@66 1113 this, SLOT(addPane()));
Chris@66 1114 connect(this, SIGNAL(canAddPane(bool)),
Chris@66 1115 action, SLOT(setEnabled(bool)));
Chris@66 1116 m_paneActions[action] = PaneConfiguration(type);
Chris@66 1117 } else {
Chris@66 1118 connect(action, SIGNAL(triggered()),
Chris@66 1119 this, SLOT(addLayer()));
Chris@66 1120 connect(this, SIGNAL(canAddLayer(bool)),
Chris@66 1121 action, SLOT(setEnabled(bool)));
Chris@66 1122 m_layerActions[action] = type;
Chris@66 1123 }
Chris@162 1124 if (shortcutText != "") {
Chris@162 1125 m_keyReference->registerShortcut(action);
Chris@162 1126 }
Chris@66 1127 menu->addAction(action);
Chris@66 1128
Chris@66 1129 } else {
Chris@66 1130
Chris@66 1131 if (!submenu) {
Chris@66 1132 submenu = menu->addMenu(mainText);
Chris@97 1133 submenu->setTearOffEnabled(true);
Chris@67 1134 } else if (isDefault) {
Chris@67 1135 submenu->addSeparator();
Chris@66 1136 }
Chris@66 1137
Chris@66 1138 QString actionText;
Chris@66 1139 if (c == 0) {
Chris@66 1140 if (mono) {
Chris@66 1141 actionText = tr("&All Channels Mixed");
Chris@66 1142 } else {
Chris@66 1143 actionText = tr("&All Channels");
Chris@66 1144 }
Chris@66 1145 } else {
Chris@66 1146 actionText = tr("Channel &%1").arg(c);
Chris@66 1147 }
Chris@66 1148
Chris@66 1149 if (model) {
Chris@66 1150 actionText = tr("%1: %2")
Chris@66 1151 .arg(model->objectName())
Chris@66 1152 .arg(actionText);
Chris@66 1153 }
Chris@67 1154
Chris@67 1155 if (isDefault) {
Chris@67 1156 action = new QAction(icon, actionText, this);
Chris@67 1157 if (!model || model == getMainModel()) {
Chris@162 1158 action->setShortcut(shortcutText);
Chris@67 1159 }
Chris@67 1160 } else {
Chris@67 1161 action = new QAction(actionText, this);
Chris@67 1162 }
Chris@67 1163
Chris@66 1164 action->setStatusTip(tipText);
Chris@66 1165
Chris@66 1166 if (menuType == 0) {
Chris@66 1167 connect(action, SIGNAL(triggered()),
Chris@66 1168 this, SLOT(addPane()));
Chris@66 1169 connect(this, SIGNAL(canAddPane(bool)),
Chris@66 1170 action, SLOT(setEnabled(bool)));
Chris@66 1171 m_paneActions[action] =
Chris@66 1172 PaneConfiguration(type, model, c - 1);
Chris@66 1173 } else {
Chris@66 1174 connect(action, SIGNAL(triggered()),
Chris@66 1175 this, SLOT(addLayer()));
Chris@66 1176 connect(this, SIGNAL(canAddLayer(bool)),
Chris@66 1177 action, SLOT(setEnabled(bool)));
Chris@66 1178 m_layerActions[action] = type;
Chris@66 1179 }
Chris@66 1180
Chris@66 1181 submenu->addAction(action);
Chris@66 1182 }
Chris@66 1183 }
Chris@66 1184 }
Chris@66 1185 }
Chris@66 1186 }
Chris@66 1187
Chris@66 1188 menu = m_paneMenu;
Chris@66 1189
Chris@66 1190 menu->addSeparator();
Chris@66 1191
Chris@168 1192 action = new QAction(il.load("editdelete"), tr("&Delete Pane"), this);
Chris@155 1193 action->setShortcut(tr("Ctrl+Shift+D"));
Chris@90 1194 action->setStatusTip(tr("Delete the currently active pane"));
Chris@66 1195 connect(action, SIGNAL(triggered()), this, SLOT(deleteCurrentPane()));
Chris@66 1196 connect(this, SIGNAL(canDeleteCurrentPane(bool)), action, SLOT(setEnabled(bool)));
Chris@162 1197 m_keyReference->registerShortcut(action);
Chris@66 1198 menu->addAction(action);
Chris@66 1199
Chris@66 1200 menu = m_layerMenu;
Chris@66 1201
Chris@168 1202 action = new QAction(il.load("timeruler"), tr("Add &Time Ruler"), this);
Chris@66 1203 action->setStatusTip(tr("Add a new layer showing a time ruler"));
Chris@66 1204 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@66 1205 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@66 1206 m_layerActions[action] = LayerFactory::TimeRuler;
Chris@66 1207 menu->addAction(action);
Chris@66 1208
Chris@66 1209 menu->addSeparator();
Chris@66 1210
Chris@66 1211 m_existingLayersMenu = menu->addMenu(tr("Add &Existing Layer"));
Chris@97 1212 m_existingLayersMenu->setTearOffEnabled(true);
Chris@66 1213 m_rightButtonLayerMenu->addMenu(m_existingLayersMenu);
Chris@95 1214
Chris@95 1215 m_sliceMenu = menu->addMenu(tr("Add S&lice of Layer"));
Chris@97 1216 m_sliceMenu->setTearOffEnabled(true);
Chris@95 1217 m_rightButtonLayerMenu->addMenu(m_sliceMenu);
Chris@95 1218
Chris@95 1219 setupExistingLayersMenus();
Chris@66 1220
Chris@66 1221 m_rightButtonLayerMenu->addSeparator();
Chris@66 1222 menu->addSeparator();
Chris@66 1223
Chris@163 1224 QAction *raction = new QAction(tr("&Rename Layer..."), this);
Chris@163 1225 raction->setShortcut(tr("R"));
Chris@163 1226 raction->setStatusTip(tr("Rename the currently active layer"));
Chris@163 1227 connect(raction, SIGNAL(triggered()), this, SLOT(renameCurrentLayer()));
Chris@163 1228 connect(this, SIGNAL(canRenameLayer(bool)), raction, SLOT(setEnabled(bool)));
Chris@163 1229 menu->addAction(raction);
Chris@163 1230 m_rightButtonLayerMenu->addAction(raction);
Chris@66 1231
Chris@168 1232 action = new QAction(il.load("editdelete"), tr("&Delete Layer"), this);
Chris@155 1233 action->setShortcut(tr("Ctrl+D"));
Chris@66 1234 action->setStatusTip(tr("Delete the currently active layer"));
Chris@66 1235 connect(action, SIGNAL(triggered()), this, SLOT(deleteCurrentLayer()));
Chris@66 1236 connect(this, SIGNAL(canDeleteCurrentLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@162 1237 m_keyReference->registerShortcut(action);
Chris@66 1238 menu->addAction(action);
Chris@66 1239 m_rightButtonLayerMenu->addAction(action);
Chris@163 1240
Chris@163 1241 m_keyReference->registerShortcut(raction); // rename after delete, so delete layer goes next to delete pane
Chris@66 1242 }
Chris@66 1243
Chris@66 1244 void
Chris@66 1245 MainWindow::setupTransformsMenu()
Chris@66 1246 {
Chris@34 1247 if (m_transformsMenu) {
Chris@34 1248 m_transformActions.clear();
Chris@34 1249 m_transformActionsReverse.clear();
Chris@34 1250 m_transformsMenu->clear();
Chris@34 1251 } else {
Chris@97 1252 m_transformsMenu = menuBar()->addMenu(tr("&Transform"));
Chris@97 1253 m_transformsMenu->setTearOffEnabled(true);
Chris@97 1254 }
Chris@34 1255
Chris@0 1256 TransformFactory::TransformList transforms =
Chris@0 1257 TransformFactory::getInstance()->getAllTransforms();
Chris@0 1258
Chris@33 1259 vector<QString> types =
Chris@0 1260 TransformFactory::getInstance()->getAllTransformTypes();
Chris@0 1261
Chris@37 1262 map<QString, map<QString, SubdividingMenu *> > categoryMenus;
Chris@37 1263 map<QString, map<QString, SubdividingMenu *> > makerMenus;
Chris@33 1264
Chris@36 1265 map<QString, SubdividingMenu *> byPluginNameMenus;
Chris@33 1266 map<QString, map<QString, QMenu *> > pluginNameMenus;
Chris@33 1267
Chris@37 1268 set<SubdividingMenu *> pendingMenus;
Chris@37 1269
Chris@34 1270 m_recentTransformsMenu = m_transformsMenu->addMenu(tr("&Recent Transforms"));
Chris@97 1271 m_recentTransformsMenu->setTearOffEnabled(true);
Chris@34 1272 m_rightButtonTransformsMenu->addMenu(m_recentTransformsMenu);
Chris@34 1273 connect(&m_recentTransforms, SIGNAL(recentChanged()),
Chris@34 1274 this, SLOT(setupRecentTransformsMenu()));
Chris@34 1275
Chris@34 1276 m_transformsMenu->addSeparator();
Chris@34 1277 m_rightButtonTransformsMenu->addSeparator();
Chris@34 1278
Chris@33 1279 for (vector<QString>::iterator i = types.begin(); i != types.end(); ++i) {
Chris@33 1280
Chris@33 1281 if (i != types.begin()) {
Chris@34 1282 m_transformsMenu->addSeparator();
Chris@34 1283 m_rightButtonTransformsMenu->addSeparator();
Chris@33 1284 }
Chris@33 1285
Chris@33 1286 QString byCategoryLabel = tr("%1 by Category").arg(*i);
Chris@37 1287 SubdividingMenu *byCategoryMenu = new SubdividingMenu(byCategoryLabel,
Chris@37 1288 20, 40);
Chris@97 1289 byCategoryMenu->setTearOffEnabled(true);
Chris@37 1290 m_transformsMenu->addMenu(byCategoryMenu);
Chris@34 1291 m_rightButtonTransformsMenu->addMenu(byCategoryMenu);
Chris@37 1292 pendingMenus.insert(byCategoryMenu);
Chris@33 1293
Chris@33 1294 vector<QString> categories =
Chris@33 1295 TransformFactory::getInstance()->getTransformCategories(*i);
Chris@33 1296
Chris@33 1297 for (vector<QString>::iterator j = categories.begin();
Chris@33 1298 j != categories.end(); ++j) {
Chris@33 1299
Chris@33 1300 QString category = *j;
Chris@33 1301 if (category == "") category = tr("Unclassified");
Chris@33 1302
Chris@33 1303 if (categories.size() < 2) {
Chris@33 1304 categoryMenus[*i][category] = byCategoryMenu;
Chris@33 1305 continue;
Chris@33 1306 }
Chris@33 1307
Chris@33 1308 QStringList components = category.split(" > ");
Chris@33 1309 QString key;
Chris@33 1310
Chris@33 1311 for (QStringList::iterator k = components.begin();
Chris@33 1312 k != components.end(); ++k) {
Chris@33 1313
Chris@33 1314 QString parentKey = key;
Chris@33 1315 if (key != "") key += " > ";
Chris@33 1316 key += *k;
Chris@33 1317
Chris@33 1318 if (categoryMenus[*i].find(key) == categoryMenus[*i].end()) {
Chris@37 1319 SubdividingMenu *m = new SubdividingMenu(*k, 20, 40);
Chris@97 1320 m->setTearOffEnabled(true);
Chris@37 1321 pendingMenus.insert(m);
Chris@37 1322 categoryMenus[*i][key] = m;
Chris@33 1323 if (parentKey == "") {
Chris@37 1324 byCategoryMenu->addMenu(m);
Chris@33 1325 } else {
Chris@37 1326 categoryMenus[*i][parentKey]->addMenu(m);
Chris@33 1327 }
Chris@33 1328 }
Chris@33 1329 }
Chris@33 1330 }
Chris@33 1331
Chris@34 1332 QString byPluginNameLabel = tr("%1 by Plugin Name").arg(*i);
Chris@36 1333 byPluginNameMenus[*i] = new SubdividingMenu(byPluginNameLabel);
Chris@97 1334 byPluginNameMenus[*i]->setTearOffEnabled(true);
Chris@36 1335 m_transformsMenu->addMenu(byPluginNameMenus[*i]);
Chris@34 1336 m_rightButtonTransformsMenu->addMenu(byPluginNameMenus[*i]);
Chris@37 1337 pendingMenus.insert(byPluginNameMenus[*i]);
Chris@34 1338
Chris@33 1339 QString byMakerLabel = tr("%1 by Maker").arg(*i);
Chris@37 1340 SubdividingMenu *byMakerMenu = new SubdividingMenu(byMakerLabel, 20, 40);
Chris@97 1341 byMakerMenu->setTearOffEnabled(true);
Chris@37 1342 m_transformsMenu->addMenu(byMakerMenu);
Chris@34 1343 m_rightButtonTransformsMenu->addMenu(byMakerMenu);
Chris@37 1344 pendingMenus.insert(byMakerMenu);
Chris@33 1345
Chris@33 1346 vector<QString> makers =
Chris@33 1347 TransformFactory::getInstance()->getTransformMakers(*i);
Chris@37 1348
Chris@33 1349 for (vector<QString>::iterator j = makers.begin();
Chris@33 1350 j != makers.end(); ++j) {
Chris@33 1351
Chris@33 1352 QString maker = *j;
Chris@33 1353 if (maker == "") maker = tr("Unknown");
Chris@55 1354 maker.replace(QRegExp(tr(" [\\(<].*$")), "");
Chris@55 1355
Chris@37 1356 makerMenus[*i][maker] = new SubdividingMenu(maker, 30, 40);
Chris@97 1357 makerMenus[*i][maker]->setTearOffEnabled(true);
Chris@37 1358 byMakerMenu->addMenu(makerMenus[*i][maker]);
Chris@37 1359 pendingMenus.insert(makerMenus[*i][maker]);
Chris@33 1360 }
Chris@0 1361 }
Chris@0 1362
Chris@0 1363 for (unsigned int i = 0; i < transforms.size(); ++i) {
Chris@0 1364
Chris@107 1365 QString name = transforms[i].name;
Chris@107 1366 if (name == "") name = transforms[i].identifier;
Chris@107 1367
Chris@107 1368 // std::cerr << "Plugin Name: " << name.toStdString() << std::endl;
Chris@80 1369
Chris@33 1370 QString type = transforms[i].type;
Chris@33 1371
Chris@33 1372 QString category = transforms[i].category;
Chris@33 1373 if (category == "") category = tr("Unclassified");
Chris@33 1374
Chris@33 1375 QString maker = transforms[i].maker;
Chris@33 1376 if (maker == "") maker = tr("Unknown");
Chris@55 1377 maker.replace(QRegExp(tr(" [\\(<].*$")), "");
Chris@33 1378
Chris@107 1379 QString pluginName = name.section(": ", 0, 0);
Chris@107 1380 QString output = name.section(": ", 1);
Chris@107 1381
Chris@107 1382 QAction *action = new QAction(tr("%1...").arg(name), this);
Chris@0 1383 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@107 1384 m_transformActions[action] = transforms[i].identifier;
Chris@107 1385 m_transformActionsReverse[transforms[i].identifier] = action;
Chris@0 1386 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@33 1387
Chris@108 1388 action->setStatusTip(transforms[i].description);
Chris@90 1389
Chris@33 1390 if (categoryMenus[type].find(category) == categoryMenus[type].end()) {
Chris@33 1391 std::cerr << "WARNING: MainWindow::setupMenus: Internal error: "
Chris@33 1392 << "No category menu for transform \""
Chris@107 1393 << name.toStdString() << "\" (category = \""
Chris@33 1394 << category.toStdString() << "\")" << std::endl;
Chris@33 1395 } else {
Chris@33 1396 categoryMenus[type][category]->addAction(action);
Chris@33 1397 }
Chris@33 1398
Chris@33 1399 if (makerMenus[type].find(maker) == makerMenus[type].end()) {
Chris@33 1400 std::cerr << "WARNING: MainWindow::setupMenus: Internal error: "
Chris@33 1401 << "No maker menu for transform \""
Chris@107 1402 << name.toStdString() << "\" (maker = \""
Chris@33 1403 << maker.toStdString() << "\")" << std::endl;
Chris@33 1404 } else {
Chris@80 1405 makerMenus[type][maker]->addAction(action);
Chris@33 1406 }
Chris@33 1407
Chris@33 1408 action = new QAction(tr("%1...").arg(output == "" ? pluginName : output), this);
Chris@33 1409 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@107 1410 m_transformActions[action] = transforms[i].identifier;
Chris@33 1411 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@108 1412 action->setStatusTip(transforms[i].description);
Chris@33 1413
Chris@34 1414 // cerr << "Transform: \"" << name.toStdString() << "\": plugin name \"" << pluginName.toStdString() << "\"" << endl;
Chris@34 1415
Chris@33 1416 if (pluginNameMenus[type].find(pluginName) ==
Chris@33 1417 pluginNameMenus[type].end()) {
Chris@33 1418
Chris@36 1419 SubdividingMenu *parentMenu = byPluginNameMenus[type];
Chris@97 1420 parentMenu->setTearOffEnabled(true);
Chris@34 1421
Chris@33 1422 if (output == "") {
Chris@36 1423 parentMenu->addAction(pluginName, action);
Chris@33 1424 } else {
Chris@34 1425 pluginNameMenus[type][pluginName] =
Chris@34 1426 parentMenu->addMenu(pluginName);
Chris@33 1427 connect(this, SIGNAL(canAddLayer(bool)),
Chris@33 1428 pluginNameMenus[type][pluginName],
Chris@33 1429 SLOT(setEnabled(bool)));
Chris@33 1430 }
Chris@33 1431 }
Chris@33 1432
Chris@33 1433 if (pluginNameMenus[type].find(pluginName) !=
Chris@33 1434 pluginNameMenus[type].end()) {
Chris@33 1435 pluginNameMenus[type][pluginName]->addAction(action);
Chris@33 1436 }
Chris@0 1437 }
Chris@0 1438
Chris@37 1439 for (set<SubdividingMenu *>::iterator i = pendingMenus.begin();
Chris@37 1440 i != pendingMenus.end(); ++i) {
Chris@37 1441 (*i)->entriesAdded();
Chris@37 1442 }
Chris@37 1443
Chris@34 1444 setupRecentTransformsMenu();
Chris@66 1445 }
Chris@66 1446
Chris@66 1447 void
Chris@66 1448 MainWindow::setupHelpMenu()
Chris@66 1449 {
Chris@66 1450 QMenu *menu = menuBar()->addMenu(tr("&Help"));
Chris@97 1451 menu->setTearOffEnabled(true);
Chris@66 1452
Chris@162 1453 m_keyReference->setCategory(tr("Help"));
Chris@162 1454
Chris@168 1455 IconLoader il;
Chris@168 1456
Chris@168 1457 QAction *action = new QAction(il.load("help"),
Chris@138 1458 tr("&Help Reference"), this);
Chris@162 1459 action->setShortcut(tr("F1"));
Chris@66 1460 action->setStatusTip(tr("Open the Sonic Visualiser reference manual"));
Chris@66 1461 connect(action, SIGNAL(triggered()), this, SLOT(help()));
Chris@162 1462 m_keyReference->registerShortcut(action);
Chris@0 1463 menu->addAction(action);
Chris@162 1464
Chris@163 1465 action = new QAction(tr("&Key and Mouse Reference"), this);
Chris@162 1466 action->setShortcut(tr("F2"));
Chris@162 1467 action->setStatusTip(tr("Open a window showing the keystrokes you can use in Sonic Visualiser"));
Chris@162 1468 connect(action, SIGNAL(triggered()), this, SLOT(keyReference()));
Chris@162 1469 m_keyReference->registerShortcut(action);
Chris@162 1470 menu->addAction(action);
Chris@66 1471
Chris@164 1472 action = new QAction(tr("Sonic Visualiser on the &Web"), this);
Chris@164 1473 action->setStatusTip(tr("Open the Sonic Visualiser website"));
Chris@164 1474 connect(action, SIGNAL(triggered()), this, SLOT(website()));
Chris@164 1475 menu->addAction(action);
Chris@164 1476
Chris@66 1477 action = new QAction(tr("&About Sonic Visualiser"), this);
Chris@66 1478 action->setStatusTip(tr("Show information about Sonic Visualiser"));
Chris@66 1479 connect(action, SIGNAL(triggered()), this, SLOT(about()));
Chris@0 1480 menu->addAction(action);
Chris@0 1481 }
Chris@0 1482
Chris@0 1483 void
Chris@0 1484 MainWindow::setupRecentFilesMenu()
Chris@0 1485 {
Chris@0 1486 m_recentFilesMenu->clear();
Chris@34 1487 vector<QString> files = m_recentFiles.getRecent();
Chris@0 1488 for (size_t i = 0; i < files.size(); ++i) {
Chris@0 1489 QAction *action = new QAction(files[i], this);
Chris@0 1490 connect(action, SIGNAL(triggered()), this, SLOT(openRecentFile()));
Chris@162 1491 if (i == 0) {
Chris@162 1492 action->setShortcut(tr("Ctrl+R"));
Chris@162 1493 m_keyReference->registerShortcut
Chris@163 1494 (tr("Re-open"),
Chris@163 1495 action->shortcut(),
Chris@163 1496 tr("Re-open the current or most recently opened file"));
Chris@162 1497 }
Chris@0 1498 m_recentFilesMenu->addAction(action);
Chris@0 1499 }
Chris@0 1500 }
Chris@0 1501
Chris@0 1502 void
Chris@34 1503 MainWindow::setupRecentTransformsMenu()
Chris@34 1504 {
Chris@34 1505 m_recentTransformsMenu->clear();
Chris@34 1506 vector<QString> transforms = m_recentTransforms.getRecent();
Chris@34 1507 for (size_t i = 0; i < transforms.size(); ++i) {
Chris@34 1508 TransformActionReverseMap::iterator ti =
Chris@34 1509 m_transformActionsReverse.find(transforms[i]);
Chris@34 1510 if (ti == m_transformActionsReverse.end()) {
Chris@34 1511 std::cerr << "WARNING: MainWindow::setupRecentTransformsMenu: "
Chris@34 1512 << "Unknown transform \"" << transforms[i].toStdString()
Chris@34 1513 << "\" in recent transforms list" << std::endl;
Chris@34 1514 continue;
Chris@34 1515 }
Chris@162 1516 if (i == 0) {
Chris@162 1517 ti->second->setShortcut(tr("Ctrl+T"));
Chris@162 1518 m_keyReference->registerShortcut
Chris@163 1519 (tr("Repeat Transform"),
Chris@162 1520 ti->second->shortcut(),
Chris@163 1521 tr("Re-select the most recently run transform"));
Chris@162 1522 }
Chris@34 1523 m_recentTransformsMenu->addAction(ti->second);
Chris@34 1524 }
Chris@34 1525 }
Chris@34 1526
Chris@34 1527 void
Chris@95 1528 MainWindow::setupExistingLayersMenus()
Chris@0 1529 {
Chris@0 1530 if (!m_existingLayersMenu) return; // should have been created by setupMenus
Chris@0 1531
Chris@0 1532 // std::cerr << "MainWindow::setupExistingLayersMenu" << std::endl;
Chris@0 1533
Chris@0 1534 m_existingLayersMenu->clear();
Chris@0 1535 m_existingLayerActions.clear();
Chris@0 1536
Chris@95 1537 m_sliceMenu->clear();
Chris@95 1538 m_sliceActions.clear();
Chris@95 1539
Chris@168 1540 IconLoader il;
Chris@168 1541
Chris@33 1542 vector<Layer *> orderedLayers;
Chris@33 1543 set<Layer *> observedLayers;
Chris@95 1544 set<Layer *> sliceableLayers;
Chris@95 1545
Chris@95 1546 LayerFactory *factory = LayerFactory::getInstance();
Chris@0 1547
Chris@0 1548 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@0 1549
Chris@0 1550 Pane *pane = m_paneStack->getPane(i);
Chris@0 1551 if (!pane) continue;
Chris@0 1552
Chris@0 1553 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@0 1554
Chris@0 1555 Layer *layer = pane->getLayer(j);
Chris@0 1556 if (!layer) continue;
Chris@0 1557 if (observedLayers.find(layer) != observedLayers.end()) {
Chris@137 1558 // std::cerr << "found duplicate layer " << layer << std::endl;
Chris@0 1559 continue;
Chris@0 1560 }
Chris@0 1561
Chris@0 1562 // std::cerr << "found new layer " << layer << " (name = "
Chris@0 1563 // << layer->getLayerPresentationName().toStdString() << ")" << std::endl;
Chris@0 1564
Chris@0 1565 orderedLayers.push_back(layer);
Chris@0 1566 observedLayers.insert(layer);
Chris@95 1567
Chris@95 1568 if (factory->isLayerSliceable(layer)) {
Chris@95 1569 sliceableLayers.insert(layer);
Chris@95 1570 }
Chris@0 1571 }
Chris@0 1572 }
Chris@0 1573
Chris@33 1574 map<QString, int> observedNames;
Chris@0 1575
Chris@137 1576 for (size_t i = 0; i < orderedLayers.size(); ++i) {
Chris@0 1577
Chris@95 1578 Layer *layer = orderedLayers[i];
Chris@95 1579
Chris@95 1580 QString name = layer->getLayerPresentationName();
Chris@0 1581 int n = ++observedNames[name];
Chris@0 1582 if (n > 1) name = QString("%1 <%2>").arg(name).arg(n);
Chris@0 1583
Chris@168 1584 QIcon icon = il.load(factory->getLayerIconName
Chris@168 1585 (factory->getLayerType(layer)));
Chris@95 1586
Chris@95 1587 QAction *action = new QAction(icon, name, this);
Chris@0 1588 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@0 1589 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@95 1590 m_existingLayerActions[action] = layer;
Chris@0 1591
Chris@0 1592 m_existingLayersMenu->addAction(action);
Chris@95 1593
Chris@95 1594 if (sliceableLayers.find(layer) != sliceableLayers.end()) {
Chris@95 1595 action = new QAction(icon, name, this);
Chris@95 1596 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@95 1597 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@95 1598 m_sliceActions[action] = layer;
Chris@95 1599 m_sliceMenu->addAction(action);
Chris@95 1600 }
Chris@0 1601 }
Chris@95 1602
Chris@95 1603 m_sliceMenu->setEnabled(!m_sliceActions.empty());
Chris@0 1604 }
Chris@0 1605
Chris@0 1606 void
Chris@0 1607 MainWindow::setupToolbars()
Chris@0 1608 {
Chris@162 1609 m_keyReference->setCategory(tr("Playback and Transport Controls"));
Chris@162 1610
Chris@168 1611 IconLoader il;
Chris@168 1612
Chris@155 1613 QMenu *menu = m_playbackMenu = menuBar()->addMenu(tr("Play&back"));
Chris@155 1614 menu->setTearOffEnabled(true);
Chris@155 1615 m_rightButtonMenu->addSeparator();
Chris@155 1616 m_rightButtonPlaybackMenu = m_rightButtonMenu->addMenu(tr("Playback"));
Chris@155 1617
Chris@155 1618 QToolBar *toolbar = addToolBar(tr("Playback Toolbar"));
Chris@155 1619
Chris@168 1620 QAction *rwdStartAction = toolbar->addAction(il.load("rewind-start"),
Chris@155 1621 tr("Rewind to Start"));
Chris@155 1622 rwdStartAction->setShortcut(tr("Home"));
Chris@155 1623 rwdStartAction->setStatusTip(tr("Rewind to the start"));
Chris@155 1624 connect(rwdStartAction, SIGNAL(triggered()), this, SLOT(rewindStart()));
Chris@155 1625 connect(this, SIGNAL(canPlay(bool)), rwdStartAction, SLOT(setEnabled(bool)));
Chris@155 1626
Chris@168 1627 QAction *m_rwdAction = toolbar->addAction(il.load("rewind"),
Chris@155 1628 tr("Rewind"));
Chris@155 1629 m_rwdAction->setShortcut(tr("PgUp"));
Chris@163 1630 m_rwdAction->setStatusTip(tr("Rewind to the previous time instant or time ruler notch"));
Chris@155 1631 connect(m_rwdAction, SIGNAL(triggered()), this, SLOT(rewind()));
Chris@155 1632 connect(this, SIGNAL(canRewind(bool)), m_rwdAction, SLOT(setEnabled(bool)));
Chris@155 1633
Chris@168 1634 QAction *playAction = toolbar->addAction(il.load("playpause"),
Chris@155 1635 tr("Play / Pause"));
Chris@155 1636 playAction->setCheckable(true);
Chris@155 1637 playAction->setShortcut(tr("Space"));
Chris@155 1638 playAction->setStatusTip(tr("Start or stop playback from the current position"));
Chris@155 1639 connect(playAction, SIGNAL(triggered()), this, SLOT(play()));
Chris@0 1640 connect(m_playSource, SIGNAL(playStatusChanged(bool)),
Chris@155 1641 playAction, SLOT(setChecked(bool)));
Chris@155 1642 connect(this, SIGNAL(canPlay(bool)), playAction, SLOT(setEnabled(bool)));
Chris@155 1643
Chris@168 1644 m_ffwdAction = toolbar->addAction(il.load("ffwd"),
Chris@155 1645 tr("Fast Forward"));
Chris@155 1646 m_ffwdAction->setShortcut(tr("PgDown"));
Chris@163 1647 m_ffwdAction->setStatusTip(tr("Fast-forward to the next time instant or time ruler notch"));
Chris@155 1648 connect(m_ffwdAction, SIGNAL(triggered()), this, SLOT(ffwd()));
Chris@155 1649 connect(this, SIGNAL(canFfwd(bool)), m_ffwdAction, SLOT(setEnabled(bool)));
Chris@155 1650
Chris@168 1651 QAction *ffwdEndAction = toolbar->addAction(il.load("ffwd-end"),
Chris@155 1652 tr("Fast Forward to End"));
Chris@155 1653 ffwdEndAction->setShortcut(tr("End"));
Chris@155 1654 ffwdEndAction->setStatusTip(tr("Fast-forward to the end"));
Chris@155 1655 connect(ffwdEndAction, SIGNAL(triggered()), this, SLOT(ffwdEnd()));
Chris@155 1656 connect(this, SIGNAL(canPlay(bool)), ffwdEndAction, SLOT(setEnabled(bool)));
Chris@0 1657
Chris@0 1658 toolbar = addToolBar(tr("Play Mode Toolbar"));
Chris@0 1659
Chris@168 1660 QAction *psAction = toolbar->addAction(il.load("playselection"),
Chris@155 1661 tr("Constrain Playback to Selection"));
Chris@155 1662 psAction->setCheckable(true);
Chris@155 1663 psAction->setChecked(m_viewManager->getPlaySelectionMode());
Chris@155 1664 psAction->setShortcut(tr("s"));
Chris@163 1665 psAction->setStatusTip(tr("Constrain playback to the selected regions"));
Chris@69 1666 connect(m_viewManager, SIGNAL(playSelectionModeChanged(bool)),
Chris@155 1667 psAction, SLOT(setChecked(bool)));
Chris@155 1668 connect(psAction, SIGNAL(triggered()), this, SLOT(playSelectionToggled()));
Chris@155 1669 connect(this, SIGNAL(canPlaySelection(bool)), psAction, SLOT(setEnabled(bool)));
Chris@155 1670
Chris@168 1671 QAction *plAction = toolbar->addAction(il.load("playloop"),
Chris@155 1672 tr("Loop Playback"));
Chris@155 1673 plAction->setCheckable(true);
Chris@155 1674 plAction->setChecked(m_viewManager->getPlayLoopMode());
Chris@155 1675 plAction->setShortcut(tr("l"));
Chris@155 1676 plAction->setStatusTip(tr("Loop playback"));
Chris@69 1677 connect(m_viewManager, SIGNAL(playLoopModeChanged(bool)),
Chris@155 1678 plAction, SLOT(setChecked(bool)));
Chris@155 1679 connect(plAction, SIGNAL(triggered()), this, SLOT(playLoopToggled()));
Chris@155 1680 connect(this, SIGNAL(canPlay(bool)), plAction, SLOT(setEnabled(bool)));
Chris@155 1681
Chris@162 1682 m_keyReference->registerShortcut(playAction);
Chris@162 1683 m_keyReference->registerShortcut(psAction);
Chris@162 1684 m_keyReference->registerShortcut(plAction);
Chris@162 1685 m_keyReference->registerShortcut(m_rwdAction);
Chris@162 1686 m_keyReference->registerShortcut(m_ffwdAction);
Chris@162 1687 m_keyReference->registerShortcut(rwdStartAction);
Chris@162 1688 m_keyReference->registerShortcut(ffwdEndAction);
Chris@162 1689
Chris@155 1690 menu->addAction(playAction);
Chris@155 1691 menu->addAction(psAction);
Chris@155 1692 menu->addAction(plAction);
Chris@155 1693 menu->addSeparator();
Chris@155 1694 menu->addAction(m_rwdAction);
Chris@155 1695 menu->addAction(m_ffwdAction);
Chris@155 1696 menu->addSeparator();
Chris@155 1697 menu->addAction(rwdStartAction);
Chris@155 1698 menu->addAction(ffwdEndAction);
Chris@155 1699 menu->addSeparator();
Chris@155 1700
Chris@155 1701 m_rightButtonPlaybackMenu->addAction(playAction);
Chris@155 1702 m_rightButtonPlaybackMenu->addAction(psAction);
Chris@155 1703 m_rightButtonPlaybackMenu->addAction(plAction);
Chris@155 1704 m_rightButtonPlaybackMenu->addSeparator();
Chris@155 1705 m_rightButtonPlaybackMenu->addAction(m_rwdAction);
Chris@155 1706 m_rightButtonPlaybackMenu->addAction(m_ffwdAction);
Chris@155 1707 m_rightButtonPlaybackMenu->addSeparator();
Chris@155 1708 m_rightButtonPlaybackMenu->addAction(rwdStartAction);
Chris@155 1709 m_rightButtonPlaybackMenu->addAction(ffwdEndAction);
Chris@155 1710 m_rightButtonPlaybackMenu->addSeparator();
Chris@155 1711
Chris@155 1712 QAction *fastAction = menu->addAction(tr("Speed Up"));
Chris@155 1713 fastAction->setShortcut(tr("Ctrl+PgUp"));
Chris@163 1714 fastAction->setStatusTip(tr("Time-stretch playback to speed it up without changing pitch"));
Chris@155 1715 connect(fastAction, SIGNAL(triggered()), this, SLOT(speedUpPlayback()));
Chris@155 1716 connect(this, SIGNAL(canSpeedUpPlayback(bool)), fastAction, SLOT(setEnabled(bool)));
Chris@155 1717
Chris@155 1718 QAction *slowAction = menu->addAction(tr("Slow Down"));
Chris@155 1719 slowAction->setShortcut(tr("Ctrl+PgDown"));
Chris@163 1720 slowAction->setStatusTip(tr("Time-stretch playback to slow it down without changing pitch"));
Chris@155 1721 connect(slowAction, SIGNAL(triggered()), this, SLOT(slowDownPlayback()));
Chris@155 1722 connect(this, SIGNAL(canSlowDownPlayback(bool)), slowAction, SLOT(setEnabled(bool)));
Chris@155 1723
Chris@155 1724 QAction *normalAction = menu->addAction(tr("Restore Normal Speed"));
Chris@155 1725 normalAction->setShortcut(tr("Ctrl+Home"));
Chris@163 1726 normalAction->setStatusTip(tr("Restore non-time-stretched playback"));
Chris@155 1727 connect(normalAction, SIGNAL(triggered()), this, SLOT(restoreNormalPlayback()));
Chris@155 1728 connect(this, SIGNAL(canChangePlaybackSpeed(bool)), normalAction, SLOT(setEnabled(bool)));
Chris@155 1729
Chris@162 1730 m_keyReference->registerShortcut(fastAction);
Chris@162 1731 m_keyReference->registerShortcut(slowAction);
Chris@162 1732 m_keyReference->registerShortcut(normalAction);
Chris@162 1733
Chris@155 1734 m_rightButtonPlaybackMenu->addAction(fastAction);
Chris@155 1735 m_rightButtonPlaybackMenu->addAction(slowAction);
Chris@155 1736 m_rightButtonPlaybackMenu->addAction(normalAction);
Chris@0 1737
Chris@0 1738 toolbar = addToolBar(tr("Edit Toolbar"));
Chris@0 1739 CommandHistory::getInstance()->registerToolbar(toolbar);
Chris@0 1740
Chris@162 1741 m_keyReference->setCategory(tr("Tool Selection"));
Chris@162 1742
Chris@0 1743 toolbar = addToolBar(tr("Tools Toolbar"));
Chris@0 1744 QActionGroup *group = new QActionGroup(this);
Chris@0 1745
Chris@168 1746 QAction *action = toolbar->addAction(il.load("navigate"),
Chris@155 1747 tr("Navigate"));
Chris@0 1748 action->setCheckable(true);
Chris@0 1749 action->setChecked(true);
Chris@0 1750 action->setShortcut(tr("1"));
Chris@90 1751 action->setStatusTip(tr("Navigate"));
Chris@0 1752 connect(action, SIGNAL(triggered()), this, SLOT(toolNavigateSelected()));
Chris@0 1753 group->addAction(action);
Chris@162 1754 m_keyReference->registerShortcut(action);
Chris@0 1755 m_toolActions[ViewManager::NavigateMode] = action;
Chris@0 1756
Chris@168 1757 action = toolbar->addAction(il.load("select"),
Chris@0 1758 tr("Select"));
Chris@0 1759 action->setCheckable(true);
Chris@0 1760 action->setShortcut(tr("2"));
Chris@90 1761 action->setStatusTip(tr("Select ranges"));
Chris@0 1762 connect(action, SIGNAL(triggered()), this, SLOT(toolSelectSelected()));
Chris@0 1763 group->addAction(action);
Chris@162 1764 m_keyReference->registerShortcut(action);
Chris@0 1765 m_toolActions[ViewManager::SelectMode] = action;
Chris@0 1766
Chris@168 1767 action = toolbar->addAction(il.load("move"),
Chris@0 1768 tr("Edit"));
Chris@0 1769 action->setCheckable(true);
Chris@0 1770 action->setShortcut(tr("3"));
Chris@90 1771 action->setStatusTip(tr("Edit items in layer"));
Chris@0 1772 connect(action, SIGNAL(triggered()), this, SLOT(toolEditSelected()));
Chris@0 1773 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1774 group->addAction(action);
Chris@162 1775 m_keyReference->registerShortcut(action);
Chris@0 1776 m_toolActions[ViewManager::EditMode] = action;
Chris@0 1777
Chris@168 1778 action = toolbar->addAction(il.load("draw"),
Chris@0 1779 tr("Draw"));
Chris@0 1780 action->setCheckable(true);
Chris@0 1781 action->setShortcut(tr("4"));
Chris@90 1782 action->setStatusTip(tr("Draw new items in layer"));
Chris@0 1783 connect(action, SIGNAL(triggered()), this, SLOT(toolDrawSelected()));
Chris@0 1784 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1785 group->addAction(action);
Chris@162 1786 m_keyReference->registerShortcut(action);
Chris@0 1787 m_toolActions[ViewManager::DrawMode] = action;
Chris@0 1788
Chris@168 1789 action = toolbar->addAction(il.load("measure"),
Chris@151 1790 tr("Measure"));
Chris@151 1791 action->setCheckable(true);
Chris@151 1792 action->setShortcut(tr("5"));
Chris@151 1793 action->setStatusTip(tr("Make measurements in layer"));
Chris@151 1794 connect(action, SIGNAL(triggered()), this, SLOT(toolMeasureSelected()));
Chris@169 1795 connect(this, SIGNAL(canMeasureLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@151 1796 group->addAction(action);
Chris@162 1797 m_keyReference->registerShortcut(action);
Chris@151 1798 m_toolActions[ViewManager::MeasureMode] = action;
Chris@151 1799
Chris@168 1800 // action = toolbar->addAction(il.load("text"),
Chris@0 1801 // tr("Text"));
Chris@0 1802 // action->setCheckable(true);
Chris@0 1803 // action->setShortcut(tr("5"));
Chris@0 1804 // connect(action, SIGNAL(triggered()), this, SLOT(toolTextSelected()));
Chris@0 1805 // group->addAction(action);
Chris@0 1806 // m_toolActions[ViewManager::TextMode] = action;
Chris@0 1807
Chris@0 1808 toolNavigateSelected();
Chris@163 1809
Chris@163 1810 Pane::registerShortcuts(*m_keyReference);
Chris@0 1811 }
Chris@0 1812
Chris@0 1813 void
Chris@0 1814 MainWindow::updateMenuStates()
Chris@0 1815 {
Chris@117 1816 Pane *currentPane = 0;
Chris@117 1817 Layer *currentLayer = 0;
Chris@117 1818
Chris@117 1819 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
Chris@117 1820 if (currentPane) currentLayer = currentPane->getSelectedLayer();
Chris@117 1821
Chris@0 1822 bool haveCurrentPane =
Chris@117 1823 (currentPane != 0);
Chris@0 1824 bool haveCurrentLayer =
Chris@117 1825 (haveCurrentPane &&
Chris@117 1826 (currentLayer != 0));
Chris@0 1827 bool haveMainModel =
Chris@0 1828 (getMainModel() != 0);
Chris@0 1829 bool havePlayTarget =
Chris@0 1830 (m_playTarget != 0);
Chris@0 1831 bool haveSelection =
Chris@0 1832 (m_viewManager &&
Chris@0 1833 !m_viewManager->getSelections().empty());
Chris@0 1834 bool haveCurrentEditableLayer =
Chris@0 1835 (haveCurrentLayer &&
Chris@117 1836 currentLayer->isLayerEditable());
Chris@0 1837 bool haveCurrentTimeInstantsLayer =
Chris@0 1838 (haveCurrentLayer &&
Chris@117 1839 dynamic_cast<TimeInstantLayer *>(currentLayer));
Chris@0 1840 bool haveCurrentTimeValueLayer =
Chris@0 1841 (haveCurrentLayer &&
Chris@117 1842 dynamic_cast<TimeValueLayer *>(currentLayer));
Chris@0 1843 bool haveCurrentColour3DPlot =
Chris@0 1844 (haveCurrentLayer &&
Chris@117 1845 dynamic_cast<Colour3DPlotLayer *>(currentLayer));
Chris@0 1846 bool haveClipboardContents =
Chris@0 1847 (m_viewManager &&
Chris@0 1848 !m_viewManager->getClipboard().empty());
Chris@0 1849
Chris@0 1850 emit canAddPane(haveMainModel);
Chris@0 1851 emit canDeleteCurrentPane(haveCurrentPane);
Chris@0 1852 emit canZoom(haveMainModel && haveCurrentPane);
Chris@0 1853 emit canScroll(haveMainModel && haveCurrentPane);
Chris@0 1854 emit canAddLayer(haveMainModel && haveCurrentPane);
Chris@0 1855 emit canImportMoreAudio(haveMainModel);
Chris@0 1856 emit canImportLayer(haveMainModel && haveCurrentPane);
Chris@0 1857 emit canExportAudio(haveMainModel);
Chris@0 1858 emit canExportLayer(haveMainModel &&
Chris@0 1859 (haveCurrentEditableLayer || haveCurrentColour3DPlot));
Chris@121 1860 emit canExportImage(haveMainModel && haveCurrentPane);
Chris@0 1861 emit canDeleteCurrentLayer(haveCurrentLayer);
Chris@0 1862 emit canRenameLayer(haveCurrentLayer);
Chris@0 1863 emit canEditLayer(haveCurrentEditableLayer);
Chris@169 1864 emit canMeasureLayer(haveCurrentLayer);
Chris@0 1865 emit canSelect(haveMainModel && haveCurrentPane);
Chris@155 1866 emit canPlay(havePlayTarget);
Chris@155 1867 emit canFfwd(true);
Chris@155 1868 emit canRewind(true);
Chris@0 1869 emit canPaste(haveCurrentEditableLayer && haveClipboardContents);
Chris@0 1870 emit canInsertInstant(haveCurrentPane);
Chris@81 1871 emit canInsertInstantsAtBoundaries(haveCurrentPane && haveSelection);
Chris@0 1872 emit canPlaySelection(haveMainModel && havePlayTarget && haveSelection);
Chris@0 1873 emit canClearSelection(haveSelection);
Chris@0 1874 emit canEditSelection(haveSelection && haveCurrentEditableLayer);
Chris@0 1875 emit canSave(m_sessionFile != "" && m_documentModified);
Chris@155 1876
Chris@164 1877 if (m_viewManager &&
Chris@164 1878 (m_viewManager->getToolMode() == ViewManager::MeasureMode)) {
Chris@164 1879 emit canDeleteSelection(haveCurrentLayer);
Chris@164 1880 m_deleteSelectedAction->setText(tr("&Delete Current Measurement"));
Chris@164 1881 m_deleteSelectedAction->setStatusTip(tr("Delete the measurement currently under the mouse pointer"));
Chris@164 1882 } else {
Chris@164 1883 emit canDeleteSelection(haveSelection && haveCurrentEditableLayer);
Chris@164 1884 m_deleteSelectedAction->setText(tr("&Delete Selected Items"));
Chris@164 1885 m_deleteSelectedAction->setStatusTip(tr("Delete items in current selection from the current layer"));
Chris@164 1886 }
Chris@164 1887
Chris@155 1888 emit canChangePlaybackSpeed(true);
Chris@155 1889 int v = m_playSpeed->value();
Chris@155 1890 emit canSpeedUpPlayback(v < m_playSpeed->maximum());
Chris@155 1891 emit canSlowDownPlayback(v > m_playSpeed->minimum());
Chris@155 1892
Chris@155 1893 if (m_ffwdAction && m_rwdAction) {
Chris@155 1894 if (haveCurrentTimeInstantsLayer) {
Chris@155 1895 m_ffwdAction->setText(tr("Fast Forward to Next Instant"));
Chris@155 1896 m_ffwdAction->setStatusTip(tr("Fast forward to the next time instant in the current layer"));
Chris@155 1897 m_rwdAction->setText(tr("Rewind to Previous Instant"));
Chris@155 1898 m_rwdAction->setStatusTip(tr("Rewind to the previous time instant in the current layer"));
Chris@155 1899 } else if (haveCurrentTimeValueLayer) {
Chris@155 1900 m_ffwdAction->setText(tr("Fast Forward to Next Point"));
Chris@155 1901 m_ffwdAction->setStatusTip(tr("Fast forward to the next point in the current layer"));
Chris@155 1902 m_rwdAction->setText(tr("Rewind to Previous Point"));
Chris@155 1903 m_rwdAction->setStatusTip(tr("Rewind to the previous point in the current layer"));
Chris@155 1904 } else {
Chris@155 1905 m_ffwdAction->setText(tr("Fast Forward"));
Chris@155 1906 m_ffwdAction->setStatusTip(tr("Fast forward"));
Chris@155 1907 m_rwdAction->setText(tr("Rewind"));
Chris@155 1908 m_rwdAction->setStatusTip(tr("Rewind"));
Chris@155 1909 }
Chris@155 1910 }
Chris@0 1911 }
Chris@0 1912
Chris@0 1913 void
Chris@0 1914 MainWindow::updateDescriptionLabel()
Chris@0 1915 {
Chris@0 1916 if (!getMainModel()) {
Chris@0 1917 m_descriptionLabel->setText(tr("No audio file loaded."));
Chris@0 1918 return;
Chris@0 1919 }
Chris@0 1920
Chris@0 1921 QString description;
Chris@0 1922
Chris@0 1923 size_t ssr = getMainModel()->getSampleRate();
Chris@0 1924 size_t tsr = ssr;
Chris@0 1925 if (m_playSource) tsr = m_playSource->getTargetSampleRate();
Chris@0 1926
Chris@0 1927 if (ssr != tsr) {
Chris@0 1928 description = tr("%1Hz (resampling to %2Hz)").arg(ssr).arg(tsr);
Chris@0 1929 } else {
Chris@0 1930 description = QString("%1Hz").arg(ssr);
Chris@0 1931 }
Chris@0 1932
Chris@0 1933 description = QString("%1 - %2")
Chris@0 1934 .arg(RealTime::frame2RealTime(getMainModel()->getEndFrame(), ssr)
Chris@0 1935 .toText(false).c_str())
Chris@0 1936 .arg(description);
Chris@0 1937
Chris@0 1938 m_descriptionLabel->setText(description);
Chris@0 1939 }
Chris@0 1940
Chris@0 1941 void
Chris@0 1942 MainWindow::documentModified()
Chris@0 1943 {
Chris@0 1944 // std::cerr << "MainWindow::documentModified" << std::endl;
Chris@0 1945
Chris@0 1946 if (!m_documentModified) {
Chris@0 1947 setWindowTitle(tr("%1 (modified)").arg(windowTitle()));
Chris@0 1948 }
Chris@0 1949
Chris@0 1950 m_documentModified = true;
Chris@0 1951 updateMenuStates();
Chris@0 1952 }
Chris@0 1953
Chris@0 1954 void
Chris@0 1955 MainWindow::documentRestored()
Chris@0 1956 {
Chris@0 1957 // std::cerr << "MainWindow::documentRestored" << std::endl;
Chris@0 1958
Chris@0 1959 if (m_documentModified) {
Chris@0 1960 QString wt(windowTitle());
Chris@0 1961 wt.replace(tr(" (modified)"), "");
Chris@0 1962 setWindowTitle(wt);
Chris@0 1963 }
Chris@0 1964
Chris@0 1965 m_documentModified = false;
Chris@0 1966 updateMenuStates();
Chris@0 1967 }
Chris@0 1968
Chris@0 1969 void
Chris@0 1970 MainWindow::playLoopToggled()
Chris@0 1971 {
Chris@0 1972 QAction *action = dynamic_cast<QAction *>(sender());
Chris@0 1973
Chris@0 1974 if (action) {
Chris@0 1975 m_viewManager->setPlayLoopMode(action->isChecked());
Chris@0 1976 } else {
Chris@0 1977 m_viewManager->setPlayLoopMode(!m_viewManager->getPlayLoopMode());
Chris@0 1978 }
Chris@0 1979 }
Chris@0 1980
Chris@0 1981 void
Chris@0 1982 MainWindow::playSelectionToggled()
Chris@0 1983 {
Chris@0 1984 QAction *action = dynamic_cast<QAction *>(sender());
Chris@0 1985
Chris@0 1986 if (action) {
Chris@0 1987 m_viewManager->setPlaySelectionMode(action->isChecked());
Chris@0 1988 } else {
Chris@0 1989 m_viewManager->setPlaySelectionMode(!m_viewManager->getPlaySelectionMode());
Chris@0 1990 }
Chris@0 1991 }
Chris@0 1992
Chris@0 1993 void
Chris@116 1994 MainWindow::currentPaneChanged(Pane *p)
Chris@0 1995 {
Chris@0 1996 updateMenuStates();
Chris@116 1997 updateVisibleRangeDisplay(p);
Chris@0 1998 }
Chris@0 1999
Chris@0 2000 void
Chris@116 2001 MainWindow::currentLayerChanged(Pane *p, Layer *)
Chris@0 2002 {
Chris@0 2003 updateMenuStates();
Chris@116 2004 updateVisibleRangeDisplay(p);
Chris@0 2005 }
Chris@0 2006
Chris@0 2007 void
Chris@0 2008 MainWindow::toolNavigateSelected()
Chris@0 2009 {
Chris@0 2010 m_viewManager->setToolMode(ViewManager::NavigateMode);
Chris@0 2011 }
Chris@0 2012
Chris@0 2013 void
Chris@0 2014 MainWindow::toolSelectSelected()
Chris@0 2015 {
Chris@0 2016 m_viewManager->setToolMode(ViewManager::SelectMode);
Chris@0 2017 }
Chris@0 2018
Chris@0 2019 void
Chris@0 2020 MainWindow::toolEditSelected()
Chris@0 2021 {
Chris@0 2022 m_viewManager->setToolMode(ViewManager::EditMode);
Chris@0 2023 }
Chris@0 2024
Chris@0 2025 void
Chris@0 2026 MainWindow::toolDrawSelected()
Chris@0 2027 {
Chris@0 2028 m_viewManager->setToolMode(ViewManager::DrawMode);
Chris@0 2029 }
Chris@0 2030
Chris@151 2031 void
Chris@151 2032 MainWindow::toolMeasureSelected()
Chris@151 2033 {
Chris@151 2034 m_viewManager->setToolMode(ViewManager::MeasureMode);
Chris@151 2035 }
Chris@151 2036
Chris@0 2037 //void
Chris@0 2038 //MainWindow::toolTextSelected()
Chris@0 2039 //{
Chris@0 2040 // m_viewManager->setToolMode(ViewManager::TextMode);
Chris@0 2041 //}
Chris@0 2042
Chris@0 2043 void
Chris@0 2044 MainWindow::selectAll()
Chris@0 2045 {
Chris@0 2046 if (!getMainModel()) return;
Chris@0 2047 m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(),
Chris@0 2048 getMainModel()->getEndFrame()));
Chris@0 2049 }
Chris@0 2050
Chris@0 2051 void
Chris@0 2052 MainWindow::selectToStart()
Chris@0 2053 {
Chris@0 2054 if (!getMainModel()) return;
Chris@0 2055 m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(),
Chris@0 2056 m_viewManager->getGlobalCentreFrame()));
Chris@0 2057 }
Chris@0 2058
Chris@0 2059 void
Chris@0 2060 MainWindow::selectToEnd()
Chris@0 2061 {
Chris@0 2062 if (!getMainModel()) return;
Chris@0 2063 m_viewManager->setSelection(Selection(m_viewManager->getGlobalCentreFrame(),
Chris@0 2064 getMainModel()->getEndFrame()));
Chris@0 2065 }
Chris@0 2066
Chris@0 2067 void
Chris@0 2068 MainWindow::selectVisible()
Chris@0 2069 {
Chris@0 2070 Model *model = getMainModel();
Chris@0 2071 if (!model) return;
Chris@0 2072
Chris@0 2073 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 2074 if (!currentPane) return;
Chris@0 2075
Chris@0 2076 size_t startFrame, endFrame;
Chris@0 2077
Chris@0 2078 if (currentPane->getStartFrame() < 0) startFrame = 0;
Chris@0 2079 else startFrame = currentPane->getStartFrame();
Chris@0 2080
Chris@0 2081 if (currentPane->getEndFrame() > model->getEndFrame()) endFrame = model->getEndFrame();
Chris@0 2082 else endFrame = currentPane->getEndFrame();
Chris@0 2083
Chris@0 2084 m_viewManager->setSelection(Selection(startFrame, endFrame));
Chris@0 2085 }
Chris@0 2086
Chris@0 2087 void
Chris@0 2088 MainWindow::clearSelection()
Chris@0 2089 {
Chris@0 2090 m_viewManager->clearSelections();
Chris@0 2091 }
Chris@0 2092
Chris@0 2093 void
Chris@0 2094 MainWindow::cut()
Chris@0 2095 {
Chris@0 2096 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 2097 if (!currentPane) return;
Chris@0 2098
Chris@0 2099 Layer *layer = currentPane->getSelectedLayer();
Chris@0 2100 if (!layer) return;
Chris@0 2101
Chris@0 2102 Clipboard &clipboard = m_viewManager->getClipboard();
Chris@0 2103 clipboard.clear();
Chris@0 2104
Chris@0 2105 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@0 2106
Chris@0 2107 CommandHistory::getInstance()->startCompoundOperation(tr("Cut"), true);
Chris@0 2108
Chris@0 2109 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@0 2110 i != selections.end(); ++i) {
Chris@0 2111 layer->copy(*i, clipboard);
Chris@0 2112 layer->deleteSelection(*i);
Chris@0 2113 }
Chris@0 2114
Chris@0 2115 CommandHistory::getInstance()->endCompoundOperation();
Chris@0 2116 }
Chris@0 2117
Chris@0 2118 void
Chris@0 2119 MainWindow::copy()
Chris@0 2120 {
Chris@0 2121 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 2122 if (!currentPane) return;
Chris@0 2123
Chris@0 2124 Layer *layer = currentPane->getSelectedLayer();
Chris@0 2125 if (!layer) return;
Chris@0 2126
Chris@0 2127 Clipboard &clipboard = m_viewManager->getClipboard();
Chris@0 2128 clipboard.clear();
Chris@0 2129
Chris@0 2130 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@0 2131
Chris@0 2132 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@0 2133 i != selections.end(); ++i) {
Chris@0 2134 layer->copy(*i, clipboard);
Chris@0 2135 }
Chris@0 2136 }
Chris@0 2137
Chris@0 2138 void
Chris@0 2139 MainWindow::paste()
Chris@0 2140 {
Chris@0 2141 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 2142 if (!currentPane) return;
Chris@0 2143
Chris@0 2144 //!!! if we have no current layer, we should create one of the most
Chris@0 2145 // appropriate type
Chris@0 2146
Chris@0 2147 Layer *layer = currentPane->getSelectedLayer();
Chris@0 2148 if (!layer) return;
Chris@0 2149
Chris@0 2150 Clipboard &clipboard = m_viewManager->getClipboard();
Chris@0 2151 Clipboard::PointList contents = clipboard.getPoints();
Chris@0 2152 /*
Chris@0 2153 long minFrame = 0;
Chris@0 2154 bool have = false;
Chris@0 2155 for (int i = 0; i < contents.size(); ++i) {
Chris@0 2156 if (!contents[i].haveFrame()) continue;
Chris@0 2157 if (!have || contents[i].getFrame() < minFrame) {
Chris@0 2158 minFrame = contents[i].getFrame();
Chris@0 2159 have = true;
Chris@0 2160 }
Chris@0 2161 }
Chris@0 2162
Chris@0 2163 long frameOffset = long(m_viewManager->getGlobalCentreFrame()) - minFrame;
Chris@0 2164
Chris@0 2165 layer->paste(clipboard, frameOffset);
Chris@0 2166 */
Chris@0 2167 layer->paste(clipboard, 0, true);
Chris@0 2168 }
Chris@0 2169
Chris@0 2170 void
Chris@0 2171 MainWindow::deleteSelected()
Chris@0 2172 {
Chris@0 2173 if (m_paneStack->getCurrentPane() &&
Chris@0 2174 m_paneStack->getCurrentPane()->getSelectedLayer()) {
Chris@164 2175
Chris@164 2176 Layer *layer = m_paneStack->getCurrentPane()->getSelectedLayer();
Chris@164 2177
Chris@164 2178 if (m_viewManager &&
Chris@164 2179 (m_viewManager->getToolMode() == ViewManager::MeasureMode)) {
Chris@164 2180
Chris@164 2181 layer->deleteCurrentMeasureRect();
Chris@164 2182
Chris@164 2183 } else {
Chris@164 2184
Chris@164 2185 MultiSelection::SelectionList selections =
Chris@164 2186 m_viewManager->getSelections();
Chris@164 2187
Chris@164 2188 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@164 2189 i != selections.end(); ++i) {
Chris@164 2190 layer->deleteSelection(*i);
Chris@164 2191 }
Chris@0 2192 }
Chris@0 2193 }
Chris@0 2194 }
Chris@0 2195
Chris@0 2196 void
Chris@0 2197 MainWindow::insertInstant()
Chris@0 2198 {
Chris@0 2199 int frame = m_viewManager->getPlaybackFrame();
Chris@81 2200 insertInstantAt(frame);
Chris@81 2201 }
Chris@81 2202
Chris@81 2203 void
Chris@81 2204 MainWindow::insertInstantsAtBoundaries()
Chris@81 2205 {
Chris@81 2206 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@81 2207 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@81 2208 i != selections.end(); ++i) {
Chris@81 2209 size_t start = i->getStartFrame();
Chris@81 2210 size_t end = i->getEndFrame();
Chris@81 2211 if (start != end) {
Chris@81 2212 insertInstantAt(i->getStartFrame());
Chris@81 2213 insertInstantAt(i->getEndFrame());
Chris@81 2214 }
Chris@81 2215 }
Chris@81 2216 }
Chris@81 2217
Chris@81 2218 void
Chris@81 2219 MainWindow::insertInstantAt(size_t frame)
Chris@81 2220 {
Chris@0 2221 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 2222 if (!pane) {
Chris@0 2223 return;
Chris@0 2224 }
Chris@0 2225
Chris@0 2226 Layer *layer = dynamic_cast<TimeInstantLayer *>
Chris@0 2227 (pane->getSelectedLayer());
Chris@0 2228
Chris@0 2229 if (!layer) {
Chris@0 2230 for (int i = pane->getLayerCount(); i > 0; --i) {
Chris@0 2231 layer = dynamic_cast<TimeInstantLayer *>(pane->getLayer(i - 1));
Chris@0 2232 if (layer) break;
Chris@0 2233 }
Chris@0 2234
Chris@0 2235 if (!layer) {
Chris@0 2236 CommandHistory::getInstance()->startCompoundOperation
Chris@0 2237 (tr("Add Point"), true);
Chris@0 2238 layer = m_document->createEmptyLayer(LayerFactory::TimeInstants);
Chris@0 2239 if (layer) {
Chris@0 2240 m_document->addLayerToView(pane, layer);
Chris@0 2241 m_paneStack->setCurrentLayer(pane, layer);
Chris@0 2242 }
Chris@0 2243 CommandHistory::getInstance()->endCompoundOperation();
Chris@0 2244 }
Chris@0 2245 }
Chris@0 2246
Chris@0 2247 if (layer) {
Chris@0 2248
Chris@0 2249 Model *model = layer->getModel();
Chris@0 2250 SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *>
Chris@0 2251 (model);
Chris@0 2252
Chris@0 2253 if (sodm) {
Chris@0 2254 SparseOneDimensionalModel::Point point
Chris@0 2255 (frame, QString("%1").arg(sodm->getPointCount() + 1));
Chris@0 2256 CommandHistory::getInstance()->addCommand
Chris@0 2257 (new SparseOneDimensionalModel::AddPointCommand(sodm, point,
Chris@0 2258 tr("Add Points")),
Chris@0 2259 true, true); // bundled
Chris@0 2260 }
Chris@0 2261 }
Chris@0 2262 }
Chris@0 2263
Chris@0 2264 void
Chris@0 2265 MainWindow::importAudio()
Chris@0 2266 {
Chris@88 2267 QString path = getOpenFileName(FileFinder::AudioFile);
Chris@0 2268
Chris@0 2269 if (path != "") {
Chris@82 2270 if (openAudioFile(path, ReplaceMainModel) == FileOpenFailed) {
Chris@0 2271 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 2272 tr("Audio file \"%1\" could not be opened").arg(path));
Chris@0 2273 }
Chris@0 2274 }
Chris@0 2275 }
Chris@0 2276
Chris@0 2277 void
Chris@0 2278 MainWindow::importMoreAudio()
Chris@0 2279 {
Chris@88 2280 QString path = getOpenFileName(FileFinder::AudioFile);
Chris@0 2281
Chris@0 2282 if (path != "") {
Chris@82 2283 if (openAudioFile(path, CreateAdditionalModel) == FileOpenFailed) {
Chris@0 2284 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 2285 tr("Audio file \"%1\" could not be opened").arg(path));
Chris@0 2286 }
Chris@0 2287 }
Chris@0 2288 }
Chris@0 2289
Chris@0 2290 void
Chris@0 2291 MainWindow::exportAudio()
Chris@0 2292 {
Chris@0 2293 if (!getMainModel()) return;
Chris@0 2294
Chris@88 2295 QString path = getSaveFileName(FileFinder::AudioFile);
Chris@0 2296
Chris@0 2297 if (path == "") return;
Chris@0 2298
Chris@0 2299 bool ok = false;
Chris@0 2300 QString error;
Chris@0 2301
Chris@0 2302 MultiSelection ms = m_viewManager->getSelection();
Chris@0 2303 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@0 2304
Chris@0 2305 bool multiple = false;
Chris@0 2306
Chris@38 2307 MultiSelection *selectionToWrite = 0;
Chris@38 2308
Chris@38 2309 if (selections.size() == 1) {
Chris@0 2310
Chris@0 2311 QStringList items;
Chris@0 2312 items << tr("Export the selected region only")
Chris@0 2313 << tr("Export the whole audio file");
Chris@0 2314
Chris@0 2315 bool ok = false;
Chris@0 2316 QString item = ListInputDialog::getItem
Chris@0 2317 (this, tr("Select region to export"),
Chris@0 2318 tr("Which region from the original audio file do you want to export?"),
Chris@0 2319 items, 0, &ok);
Chris@0 2320
Chris@0 2321 if (!ok || item.isEmpty()) return;
Chris@0 2322
Chris@38 2323 if (item == items[0]) selectionToWrite = &ms;
Chris@38 2324
Chris@38 2325 } else if (selections.size() > 1) {
Chris@0 2326
Chris@0 2327 QStringList items;
Chris@0 2328 items << tr("Export the selected regions into a single audio file")
Chris@0 2329 << tr("Export the selected regions into separate files")
Chris@0 2330 << tr("Export the whole audio file");
Chris@0 2331
Chris@0 2332 QString item = ListInputDialog::getItem
Chris@0 2333 (this, tr("Select region to export"),
Chris@0 2334 tr("Multiple regions of the original audio file are selected.\nWhat do you want to export?"),
Chris@0 2335 items, 0, &ok);
Chris@0 2336
Chris@0 2337 if (!ok || item.isEmpty()) return;
Chris@0 2338
Chris@0 2339 if (item == items[0]) {
Chris@0 2340
Chris@38 2341 selectionToWrite = &ms;
Chris@38 2342
Chris@38 2343 } else if (item == items[1]) {
Chris@0 2344
Chris@0 2345 multiple = true;
Chris@0 2346
Chris@0 2347 int n = 1;
Chris@0 2348 QString base = path;
Chris@0 2349 base.replace(".wav", "");
Chris@0 2350
Chris@0 2351 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@0 2352 i != selections.end(); ++i) {
Chris@0 2353
Chris@0 2354 MultiSelection subms;
Chris@0 2355 subms.setSelection(*i);
Chris@0 2356
Chris@0 2357 QString subpath = QString("%1.%2.wav").arg(base).arg(n);
Chris@0 2358 ++n;
Chris@0 2359
Chris@0 2360 if (QFileInfo(subpath).exists()) {
Chris@0 2361 error = tr("Fragment file %1 already exists, aborting").arg(subpath);
Chris@0 2362 break;
Chris@0 2363 }
Chris@0 2364
Chris@38 2365 WavFileWriter subwriter(subpath,
Chris@38 2366 getMainModel()->getSampleRate(),
Chris@38 2367 getMainModel()->getChannelCount());
Chris@38 2368 subwriter.writeModel(getMainModel(), &subms);
Chris@0 2369 ok = subwriter.isOK();
Chris@0 2370
Chris@0 2371 if (!ok) {
Chris@0 2372 error = subwriter.getError();
Chris@0 2373 break;
Chris@0 2374 }
Chris@0 2375 }
Chris@0 2376 }
Chris@0 2377 }
Chris@0 2378
Chris@38 2379 if (!multiple) {
Chris@38 2380 WavFileWriter writer(path,
Chris@38 2381 getMainModel()->getSampleRate(),
Chris@38 2382 getMainModel()->getChannelCount());
Chris@38 2383 writer.writeModel(getMainModel(), selectionToWrite);
Chris@38 2384 ok = writer.isOK();
Chris@38 2385 error = writer.getError();
Chris@0 2386 }
Chris@0 2387
Chris@0 2388 if (ok) {
Chris@0 2389 if (!multiple) {
Chris@34 2390 m_recentFiles.addFile(path);
Chris@0 2391 }
Chris@0 2392 } else {
Chris@0 2393 QMessageBox::critical(this, tr("Failed to write file"), error);
Chris@0 2394 }
Chris@0 2395 }
Chris@0 2396
Chris@0 2397 void
Chris@0 2398 MainWindow::importLayer()
Chris@0 2399 {
Chris@0 2400 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 2401
Chris@0 2402 if (!pane) {
Chris@0 2403 // shouldn't happen, as the menu action should have been disabled
Chris@0 2404 std::cerr << "WARNING: MainWindow::importLayer: no current pane" << std::endl;
Chris@0 2405 return;
Chris@0 2406 }
Chris@0 2407
Chris@0 2408 if (!getMainModel()) {
Chris@0 2409 // shouldn't happen, as the menu action should have been disabled
Chris@0 2410 std::cerr << "WARNING: MainWindow::importLayer: No main model -- hence no default sample rate available" << std::endl;
Chris@0 2411 return;
Chris@0 2412 }
Chris@0 2413
Chris@88 2414 QString path = getOpenFileName(FileFinder::LayerFile);
Chris@0 2415
Chris@0 2416 if (path != "") {
Chris@0 2417
Chris@82 2418 if (openLayerFile(path) == FileOpenFailed) {
Chris@0 2419 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 2420 tr("File %1 could not be opened.").arg(path));
Chris@0 2421 return;
Chris@0 2422 }
Chris@0 2423 }
Chris@0 2424 }
Chris@0 2425
Chris@82 2426 MainWindow::FileOpenStatus
Chris@0 2427 MainWindow::openLayerFile(QString path)
Chris@0 2428 {
Chris@86 2429 return openLayerFile(path, path);
Chris@86 2430 }
Chris@86 2431
Chris@86 2432 MainWindow::FileOpenStatus
Chris@86 2433 MainWindow::openLayerFile(QString path, QString location)
Chris@86 2434 {
Chris@0 2435 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 2436
Chris@0 2437 if (!pane) {
Chris@0 2438 // shouldn't happen, as the menu action should have been disabled
Chris@0 2439 std::cerr << "WARNING: MainWindow::openLayerFile: no current pane" << std::endl;
Chris@82 2440 return FileOpenFailed;
Chris@0 2441 }
Chris@0 2442
Chris@0 2443 if (!getMainModel()) {
Chris@0 2444 // shouldn't happen, as the menu action should have been disabled
Chris@0 2445 std::cerr << "WARNING: MainWindow::openLayerFile: No main model -- hence no default sample rate available" << std::endl;
Chris@82 2446 return FileOpenFailed;
Chris@0 2447 }
Chris@0 2448
Chris@86 2449 bool realFile = (location == path);
Chris@86 2450
Chris@0 2451 if (path.endsWith(".svl") || path.endsWith(".xml")) {
Chris@0 2452
Chris@0 2453 PaneCallback callback(this);
Chris@0 2454 QFile file(path);
Chris@0 2455
Chris@0 2456 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
Chris@0 2457 std::cerr << "ERROR: MainWindow::openLayerFile("
Chris@86 2458 << location.toStdString()
Chris@0 2459 << "): Failed to open file for reading" << std::endl;
Chris@82 2460 return FileOpenFailed;
Chris@0 2461 }
Chris@0 2462
Chris@87 2463 SVFileReader reader(m_document, callback, location);
Chris@0 2464 reader.setCurrentPane(pane);
Chris@0 2465
Chris@0 2466 QXmlInputSource inputSource(&file);
Chris@0 2467 reader.parse(inputSource);
Chris@0 2468
Chris@0 2469 if (!reader.isOK()) {
Chris@0 2470 std::cerr << "ERROR: MainWindow::openLayerFile("
Chris@86 2471 << location.toStdString()
Chris@0 2472 << "): Failed to read XML file: "
Chris@0 2473 << reader.getErrorString().toStdString() << std::endl;
Chris@82 2474 return FileOpenFailed;
Chris@0 2475 }
Chris@0 2476
Chris@86 2477 m_recentFiles.addFile(location);
Chris@86 2478
Chris@86 2479 if (realFile) {
Chris@88 2480 registerLastOpenedFilePath(FileFinder::LayerFile, path); // for file dialog
Chris@86 2481 }
Chris@86 2482
Chris@82 2483 return FileOpenSucceeded;
Chris@0 2484
Chris@0 2485 } else {
Chris@0 2486
Chris@0 2487 Model *model = DataFileReaderFactory::load(path, getMainModel()->getSampleRate());
Chris@0 2488
Chris@0 2489 if (model) {
Chris@86 2490
Chris@0 2491 Layer *newLayer = m_document->createImportedLayer(model);
Chris@86 2492
Chris@0 2493 if (newLayer) {
Chris@86 2494
Chris@0 2495 m_document->addLayerToView(pane, newLayer);
Chris@86 2496 m_recentFiles.addFile(location);
Chris@86 2497
Chris@86 2498 if (realFile) {
Chris@88 2499 registerLastOpenedFilePath(FileFinder::LayerFile, path); // for file dialog
Chris@86 2500 }
Chris@86 2501
Chris@82 2502 return FileOpenSucceeded;
Chris@0 2503 }
Chris@0 2504 }
Chris@0 2505 }
Chris@0 2506
Chris@82 2507 return FileOpenFailed;
Chris@0 2508 }
Chris@0 2509
Chris@0 2510 void
Chris@0 2511 MainWindow::exportLayer()
Chris@0 2512 {
Chris@0 2513 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 2514 if (!pane) return;
Chris@0 2515
Chris@0 2516 Layer *layer = pane->getSelectedLayer();
Chris@0 2517 if (!layer) return;
Chris@0 2518
Chris@0 2519 Model *model = layer->getModel();
Chris@0 2520 if (!model) return;
Chris@0 2521
Chris@88 2522 QString path = getSaveFileName(FileFinder::LayerFile);
Chris@0 2523
Chris@0 2524 if (path == "") return;
Chris@0 2525
Chris@0 2526 if (QFileInfo(path).suffix() == "") path += ".svl";
Chris@0 2527
Chris@0 2528 QString error;
Chris@0 2529
Chris@0 2530 if (path.endsWith(".xml") || path.endsWith(".svl")) {
Chris@0 2531
Chris@0 2532 QFile file(path);
Chris@0 2533 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
Chris@0 2534 error = tr("Failed to open file %1 for writing").arg(path);
Chris@0 2535 } else {
Chris@0 2536 QTextStream out(&file);
Chris@0 2537 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
Chris@0 2538 << "<!DOCTYPE sonic-visualiser>\n"
Chris@0 2539 << "<sv>\n"
Chris@0 2540 << " <data>\n";
Chris@0 2541
Chris@0 2542 model->toXml(out, " ");
Chris@0 2543
Chris@0 2544 out << " </data>\n"
Chris@0 2545 << " <display>\n";
Chris@0 2546
Chris@0 2547 layer->toXml(out, " ");
Chris@0 2548
Chris@0 2549 out << " </display>\n"
Chris@0 2550 << "</sv>\n";
Chris@0 2551 }
Chris@0 2552
Chris@0 2553 } else {
Chris@0 2554
Chris@0 2555 CSVFileWriter writer(path, model,
Chris@0 2556 (path.endsWith(".csv") ? "," : "\t"));
Chris@0 2557 writer.write();
Chris@0 2558
Chris@0 2559 if (!writer.isOK()) {
Chris@0 2560 error = writer.getError();
Chris@0 2561 }
Chris@0 2562 }
Chris@0 2563
Chris@0 2564 if (error != "") {
Chris@0 2565 QMessageBox::critical(this, tr("Failed to write file"), error);
Chris@0 2566 } else {
Chris@34 2567 m_recentFiles.addFile(path);
Chris@0 2568 }
Chris@0 2569 }
Chris@0 2570
Chris@121 2571 void
Chris@121 2572 MainWindow::exportImage()
Chris@121 2573 {
Chris@121 2574 Pane *pane = m_paneStack->getCurrentPane();
Chris@121 2575 if (!pane) return;
Chris@121 2576
Chris@121 2577 QString path = getSaveFileName(FileFinder::ImageFile);
Chris@121 2578
Chris@121 2579 if (path == "") return;
Chris@121 2580
Chris@121 2581 if (QFileInfo(path).suffix() == "") path += ".png";
Chris@121 2582
Chris@123 2583 bool haveSelection = m_viewManager && !m_viewManager->getSelections().empty();
Chris@123 2584
Chris@123 2585 QSize total, visible, selected;
Chris@123 2586 total = pane->getImageSize();
Chris@123 2587 visible = pane->getImageSize(pane->getFirstVisibleFrame(),
Chris@123 2588 pane->getLastVisibleFrame());
Chris@123 2589
Chris@123 2590 size_t sf0 = 0, sf1 = 0;
Chris@123 2591
Chris@123 2592 if (haveSelection) {
Chris@123 2593 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@123 2594 sf0 = selections.begin()->getStartFrame();
Chris@123 2595 MultiSelection::SelectionList::iterator e = selections.end();
Chris@123 2596 --e;
Chris@123 2597 sf1 = e->getEndFrame();
Chris@123 2598 selected = pane->getImageSize(sf0, sf1);
Chris@123 2599 }
Chris@123 2600
Chris@123 2601 QStringList items;
Chris@125 2602 items << tr("Export the whole pane (%1x%2 pixels)")
Chris@123 2603 .arg(total.width()).arg(total.height());
Chris@123 2604 items << tr("Export the visible area only (%1x%2 pixels)")
Chris@123 2605 .arg(visible.width()).arg(visible.height());
Chris@123 2606 if (haveSelection) {
Chris@123 2607 items << tr("Export the selection extent (%1x%2 pixels)")
Chris@123 2608 .arg(selected.width()).arg(selected.height());
Chris@124 2609 } else {
Chris@124 2610 items << tr("Export the selection extent");
Chris@123 2611 }
Chris@123 2612
Chris@123 2613 QSettings settings;
Chris@123 2614 settings.beginGroup("MainWindow");
Chris@123 2615 int deflt = settings.value("lastimageexportregion", 0).toInt();
Chris@123 2616 if (deflt == 2 && !haveSelection) deflt = 1;
Chris@124 2617 if (deflt == 0 && total.width() > 32767) deflt = 1;
Chris@124 2618
Chris@124 2619 ListInputDialog *lid = new ListInputDialog
Chris@123 2620 (this, tr("Select region to export"),
Chris@123 2621 tr("Which region of the current pane do you want to export as an image?"),
Chris@124 2622 items, deflt);
Chris@124 2623
Chris@124 2624 if (!haveSelection) {
Chris@124 2625 lid->setItemAvailability(2, false);
Chris@124 2626 }
Chris@124 2627 if (total.width() > 32767) { // appears to be the limit of a QImage
Chris@124 2628 lid->setItemAvailability(0, false);
Chris@124 2629 lid->setFootnote(tr("Note: the whole pane is too wide to be exported as a single image."));
Chris@124 2630 }
Chris@124 2631
Chris@124 2632 bool ok = lid->exec();
Chris@124 2633 QString item = lid->getCurrentString();
Chris@124 2634 delete lid;
Chris@123 2635
Chris@123 2636 if (!ok || item.isEmpty()) return;
Chris@123 2637
Chris@123 2638 settings.setValue("lastimageexportregion", deflt);
Chris@123 2639
Chris@123 2640 QImage *image = 0;
Chris@123 2641
Chris@123 2642 if (item == items[0]) {
Chris@123 2643 image = pane->toNewImage();
Chris@123 2644 } else if (item == items[1]) {
Chris@123 2645 image = pane->toNewImage(pane->getFirstVisibleFrame(),
Chris@123 2646 pane->getLastVisibleFrame());
Chris@123 2647 } else if (haveSelection) {
Chris@123 2648 image = pane->toNewImage(sf0, sf1);
Chris@123 2649 }
Chris@123 2650
Chris@121 2651 if (!image) return;
Chris@121 2652
Chris@121 2653 if (!image->save(path, "PNG")) {
Chris@121 2654 QMessageBox::critical(this, tr("Failed to save image file"),
Chris@121 2655 tr("Failed to save image file %1").arg(path));
Chris@121 2656 }
Chris@121 2657
Chris@121 2658 delete image;
Chris@121 2659 }
Chris@121 2660
Chris@82 2661 MainWindow::FileOpenStatus
Chris@0 2662 MainWindow::openAudioFile(QString path, AudioFileOpenMode mode)
Chris@0 2663 {
Chris@86 2664 return openAudioFile(path, path, mode);
Chris@86 2665 }
Chris@86 2666
Chris@86 2667 MainWindow::FileOpenStatus
Chris@86 2668 MainWindow::openAudioFile(QString path, QString location, AudioFileOpenMode mode)
Chris@86 2669 {
Chris@0 2670 if (!(QFileInfo(path).exists() &&
Chris@0 2671 QFileInfo(path).isFile() &&
Chris@0 2672 QFileInfo(path).isReadable())) {
Chris@82 2673 return FileOpenFailed;
Chris@0 2674 }
Chris@0 2675
Chris@70 2676 m_openingAudioFile = true;
Chris@70 2677
Chris@88 2678 WaveFileModel *newModel = new WaveFileModel(path, location);
Chris@0 2679
Chris@0 2680 if (!newModel->isOK()) {
Chris@0 2681 delete newModel;
Chris@70 2682 m_openingAudioFile = false;
Chris@82 2683 return FileOpenFailed;
Chris@0 2684 }
Chris@0 2685
Chris@0 2686 bool setAsMain = true;
Chris@0 2687 static bool prevSetAsMain = true;
Chris@0 2688
Chris@86 2689 bool realFile = (location == path);
Chris@86 2690
Chris@0 2691 if (mode == CreateAdditionalModel) setAsMain = false;
Chris@0 2692 else if (mode == AskUser) {
Chris@0 2693 if (m_document->getMainModel()) {
Chris@0 2694
Chris@0 2695 QStringList items;
Chris@0 2696 items << tr("Replace the existing main waveform")
Chris@0 2697 << tr("Load this file into a new waveform pane");
Chris@0 2698
Chris@0 2699 bool ok = false;
Chris@0 2700 QString item = ListInputDialog::getItem
Chris@0 2701 (this, tr("Select target for import"),
Chris@0 2702 tr("You already have an audio waveform loaded.\nWhat would you like to do with the new audio file?"),
Chris@0 2703 items, prevSetAsMain ? 0 : 1, &ok);
Chris@0 2704
Chris@0 2705 if (!ok || item.isEmpty()) {
Chris@0 2706 delete newModel;
Chris@70 2707 m_openingAudioFile = false;
Chris@82 2708 return FileOpenCancelled;
Chris@0 2709 }
Chris@0 2710
Chris@0 2711 setAsMain = (item == items[0]);
Chris@0 2712 prevSetAsMain = setAsMain;
Chris@0 2713 }
Chris@0 2714 }
Chris@0 2715
Chris@0 2716 if (setAsMain) {
Chris@0 2717
Chris@0 2718 Model *prevMain = getMainModel();
Chris@118 2719 if (prevMain) {
Chris@118 2720 m_playSource->removeModel(prevMain);
Chris@118 2721 PlayParameterRepository::getInstance()->removeModel(prevMain);
Chris@118 2722 }
Chris@118 2723
Chris@118 2724 PlayParameterRepository::getInstance()->addModel(newModel);
Chris@0 2725
Chris@0 2726 m_document->setMainModel(newModel);
Chris@0 2727 setupMenus();
Chris@0 2728
Chris@0 2729 if (m_sessionFile == "") {
Chris@0 2730 setWindowTitle(tr("Sonic Visualiser: %1")
Chris@86 2731 .arg(QFileInfo(location).fileName()));
Chris@0 2732 CommandHistory::getInstance()->clear();
Chris@0 2733 CommandHistory::getInstance()->documentSaved();
Chris@0 2734 m_documentModified = false;
Chris@0 2735 } else {
Chris@0 2736 setWindowTitle(tr("Sonic Visualiser: %1 [%2]")
Chris@0 2737 .arg(QFileInfo(m_sessionFile).fileName())
Chris@86 2738 .arg(QFileInfo(location).fileName()));
Chris@0 2739 if (m_documentModified) {
Chris@0 2740 m_documentModified = false;
Chris@0 2741 documentModified(); // so as to restore "(modified)" window title
Chris@0 2742 }
Chris@0 2743 }
Chris@0 2744
Chris@86 2745 if (realFile) m_audioFile = path;
Chris@0 2746
Chris@0 2747 } else { // !setAsMain
Chris@0 2748
Chris@0 2749 CommandHistory::getInstance()->startCompoundOperation
Chris@86 2750 (tr("Import \"%1\"").arg(QFileInfo(location).fileName()), true);
Chris@0 2751
Chris@0 2752 m_document->addImportedModel(newModel);
Chris@0 2753
Chris@0 2754 AddPaneCommand *command = new AddPaneCommand(this);
Chris@0 2755 CommandHistory::getInstance()->addCommand(command);
Chris@0 2756
Chris@0 2757 Pane *pane = command->getPane();
Chris@0 2758
Chris@0 2759 if (!m_timeRulerLayer) {
Chris@0 2760 m_timeRulerLayer = m_document->createMainModelLayer
Chris@0 2761 (LayerFactory::TimeRuler);
Chris@0 2762 }
Chris@0 2763
Chris@0 2764 m_document->addLayerToView(pane, m_timeRulerLayer);
Chris@0 2765
Chris@0 2766 Layer *newLayer = m_document->createImportedLayer(newModel);
Chris@0 2767
Chris@0 2768 if (newLayer) {
Chris@0 2769 m_document->addLayerToView(pane, newLayer);
Chris@0 2770 }
Chris@0 2771
Chris@0 2772 CommandHistory::getInstance()->endCompoundOperation();
Chris@0 2773 }
Chris@0 2774
Chris@0 2775 updateMenuStates();
Chris@86 2776 m_recentFiles.addFile(location);
Chris@86 2777 if (realFile) {
Chris@88 2778 registerLastOpenedFilePath(FileFinder::AudioFile, path); // for file dialog
Chris@86 2779 }
Chris@70 2780 m_openingAudioFile = false;
Chris@0 2781
Chris@82 2782 return FileOpenSucceeded;
Chris@0 2783 }
Chris@0 2784
Chris@0 2785 void
Chris@0 2786 MainWindow::createPlayTarget()
Chris@0 2787 {
Chris@0 2788 if (m_playTarget) return;
Chris@0 2789
Chris@0 2790 m_playTarget = AudioTargetFactory::createCallbackTarget(m_playSource);
Chris@0 2791 if (!m_playTarget) {
Chris@0 2792 QMessageBox::warning
Chris@0 2793 (this, tr("Couldn't open audio device"),
Chris@0 2794 tr("Could not open an audio device for playback.\nAudio playback will not be available during this session.\n"),
Chris@165 2795 QMessageBox::Ok);
Chris@0 2796 }
Chris@0 2797 connect(m_fader, SIGNAL(valueChanged(float)),
Chris@0 2798 m_playTarget, SLOT(setOutputGain(float)));
Chris@0 2799 }
Chris@0 2800
Chris@0 2801 WaveFileModel *
Chris@0 2802 MainWindow::getMainModel()
Chris@0 2803 {
Chris@0 2804 if (!m_document) return 0;
Chris@0 2805 return m_document->getMainModel();
Chris@0 2806 }
Chris@0 2807
Chris@116 2808 const WaveFileModel *
Chris@116 2809 MainWindow::getMainModel() const
Chris@116 2810 {
Chris@116 2811 if (!m_document) return 0;
Chris@116 2812 return m_document->getMainModel();
Chris@116 2813 }
Chris@116 2814
Chris@0 2815 void
Chris@0 2816 MainWindow::newSession()
Chris@0 2817 {
Chris@0 2818 if (!checkSaveModified()) return;
Chris@0 2819
Chris@0 2820 closeSession();
Chris@0 2821 createDocument();
Chris@0 2822
Chris@0 2823 Pane *pane = m_paneStack->addPane();
Chris@0 2824
Chris@90 2825 connect(pane, SIGNAL(contextHelpChanged(const QString &)),
Chris@116 2826 this, SLOT(contextHelpChanged(const QString &)));
Chris@90 2827
Chris@0 2828 if (!m_timeRulerLayer) {
Chris@0 2829 m_timeRulerLayer = m_document->createMainModelLayer
Chris@0 2830 (LayerFactory::TimeRuler);
Chris@0 2831 }
Chris@0 2832
Chris@0 2833 m_document->addLayerToView(pane, m_timeRulerLayer);
Chris@0 2834
Chris@0 2835 Layer *waveform = m_document->createMainModelLayer(LayerFactory::Waveform);
Chris@0 2836 m_document->addLayerToView(pane, waveform);
Chris@0 2837
Chris@65 2838 m_overview->registerView(pane);
Chris@0 2839
Chris@0 2840 CommandHistory::getInstance()->clear();
Chris@0 2841 CommandHistory::getInstance()->documentSaved();
Chris@0 2842 documentRestored();
Chris@0 2843 updateMenuStates();
Chris@0 2844 }
Chris@0 2845
Chris@0 2846 void
Chris@0 2847 MainWindow::createDocument()
Chris@0 2848 {
Chris@0 2849 m_document = new Document;
Chris@0 2850
Chris@0 2851 connect(m_document, SIGNAL(layerAdded(Layer *)),
Chris@0 2852 this, SLOT(layerAdded(Layer *)));
Chris@0 2853 connect(m_document, SIGNAL(layerRemoved(Layer *)),
Chris@0 2854 this, SLOT(layerRemoved(Layer *)));
Chris@0 2855 connect(m_document, SIGNAL(layerAboutToBeDeleted(Layer *)),
Chris@0 2856 this, SLOT(layerAboutToBeDeleted(Layer *)));
Chris@0 2857 connect(m_document, SIGNAL(layerInAView(Layer *, bool)),
Chris@0 2858 this, SLOT(layerInAView(Layer *, bool)));
Chris@0 2859
Chris@0 2860 connect(m_document, SIGNAL(modelAdded(Model *)),
Chris@0 2861 this, SLOT(modelAdded(Model *)));
Chris@0 2862 connect(m_document, SIGNAL(mainModelChanged(WaveFileModel *)),
Chris@0 2863 this, SLOT(mainModelChanged(WaveFileModel *)));
Chris@0 2864 connect(m_document, SIGNAL(modelAboutToBeDeleted(Model *)),
Chris@0 2865 this, SLOT(modelAboutToBeDeleted(Model *)));
Chris@0 2866
Chris@0 2867 connect(m_document, SIGNAL(modelGenerationFailed(QString)),
Chris@0 2868 this, SLOT(modelGenerationFailed(QString)));
Chris@63 2869 connect(m_document, SIGNAL(modelRegenerationFailed(QString, QString)),
Chris@63 2870 this, SLOT(modelRegenerationFailed(QString, QString)));
Chris@0 2871 }
Chris@0 2872
Chris@0 2873 void
Chris@0 2874 MainWindow::closeSession()
Chris@0 2875 {
Chris@0 2876 if (!checkSaveModified()) return;
Chris@0 2877
Chris@0 2878 while (m_paneStack->getPaneCount() > 0) {
Chris@0 2879
Chris@0 2880 Pane *pane = m_paneStack->getPane(m_paneStack->getPaneCount() - 1);
Chris@0 2881
Chris@0 2882 while (pane->getLayerCount() > 0) {
Chris@0 2883 m_document->removeLayerFromView
Chris@0 2884 (pane, pane->getLayer(pane->getLayerCount() - 1));
Chris@0 2885 }
Chris@0 2886
Chris@65 2887 m_overview->unregisterView(pane);
Chris@0 2888 m_paneStack->deletePane(pane);
Chris@0 2889 }
Chris@0 2890
Chris@0 2891 while (m_paneStack->getHiddenPaneCount() > 0) {
Chris@0 2892
Chris@0 2893 Pane *pane = m_paneStack->getHiddenPane
Chris@0 2894 (m_paneStack->getHiddenPaneCount() - 1);
Chris@0 2895
Chris@0 2896 while (pane->getLayerCount() > 0) {
Chris@0 2897 m_document->removeLayerFromView
Chris@0 2898 (pane, pane->getLayer(pane->getLayerCount() - 1));
Chris@0 2899 }
Chris@0 2900
Chris@65 2901 m_overview->unregisterView(pane);
Chris@0 2902 m_paneStack->deletePane(pane);
Chris@0 2903 }
Chris@0 2904
Chris@0 2905 delete m_document;
Chris@0 2906 m_document = 0;
Chris@0 2907 m_viewManager->clearSelections();
Chris@0 2908 m_timeRulerLayer = 0; // document owned this
Chris@0 2909
Chris@0 2910 m_sessionFile = "";
Chris@0 2911 setWindowTitle(tr("Sonic Visualiser"));
Chris@0 2912
Chris@0 2913 CommandHistory::getInstance()->clear();
Chris@0 2914 CommandHistory::getInstance()->documentSaved();
Chris@0 2915 documentRestored();
Chris@0 2916 }
Chris@0 2917
Chris@0 2918 void
Chris@0 2919 MainWindow::openSession()
Chris@0 2920 {
Chris@0 2921 if (!checkSaveModified()) return;
Chris@0 2922
Chris@0 2923 QString orig = m_audioFile;
Chris@0 2924 if (orig == "") orig = ".";
Chris@0 2925 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 2926
Chris@88 2927 QString path = getOpenFileName(FileFinder::SessionFile);
Chris@0 2928
Chris@0 2929 if (path.isEmpty()) return;
Chris@0 2930
Chris@82 2931 if (openSessionFile(path) == FileOpenFailed) {
Chris@0 2932 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 2933 tr("Session file \"%1\" could not be opened").arg(path));
Chris@0 2934 }
Chris@0 2935 }
Chris@0 2936
Chris@0 2937 void
Chris@0 2938 MainWindow::openSomething()
Chris@0 2939 {
Chris@0 2940 QString orig = m_audioFile;
Chris@0 2941 if (orig == "") orig = ".";
Chris@0 2942 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 2943
Chris@0 2944 bool canImportLayer = (getMainModel() != 0 &&
Chris@0 2945 m_paneStack != 0 &&
Chris@0 2946 m_paneStack->getCurrentPane() != 0);
Chris@0 2947
Chris@88 2948 QString path = getOpenFileName(FileFinder::AnyFile);
Chris@0 2949
Chris@0 2950 if (path.isEmpty()) return;
Chris@0 2951
Chris@0 2952 if (path.endsWith(".sv")) {
Chris@0 2953
Chris@0 2954 if (!checkSaveModified()) return;
Chris@0 2955
Chris@82 2956 if (openSessionFile(path) == FileOpenFailed) {
Chris@0 2957 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 2958 tr("Session file \"%1\" could not be opened").arg(path));
Chris@0 2959 }
Chris@0 2960
Chris@0 2961 } else {
Chris@0 2962
Chris@82 2963 if (openAudioFile(path, AskUser) == FileOpenFailed) {
Chris@82 2964
Chris@82 2965 if (!canImportLayer || (openLayerFile(path) == FileOpenFailed)) {
Chris@0 2966
Chris@0 2967 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 2968 tr("File \"%1\" could not be opened").arg(path));
Chris@0 2969 }
Chris@0 2970 }
Chris@0 2971 }
Chris@0 2972 }
Chris@0 2973
Chris@0 2974 void
Chris@86 2975 MainWindow::openLocation()
Chris@86 2976 {
Chris@103 2977 QSettings settings;
Chris@103 2978 settings.beginGroup("MainWindow");
Chris@103 2979 QString lastLocation = settings.value("lastremote", "").toString();
Chris@103 2980
Chris@86 2981 bool ok = false;
Chris@86 2982 QString text = QInputDialog::getText
Chris@86 2983 (this, tr("Open Location"),
Chris@86 2984 tr("Please enter the URL of the location to open:"),
Chris@103 2985 QLineEdit::Normal, lastLocation, &ok);
Chris@103 2986
Chris@103 2987 if (!ok) return;
Chris@103 2988
Chris@103 2989 settings.setValue("lastremote", text);
Chris@103 2990
Chris@103 2991 if (text.isEmpty()) return;
Chris@86 2992
Chris@86 2993 if (openURL(QUrl(text)) == FileOpenFailed) {
Chris@86 2994 QMessageBox::critical(this, tr("Failed to open location"),
Chris@86 2995 tr("URL \"%1\" could not be opened").arg(text));
Chris@86 2996 }
Chris@86 2997 }
Chris@86 2998
Chris@86 2999 void
Chris@0 3000 MainWindow::openRecentFile()
Chris@0 3001 {
Chris@0 3002 QObject *obj = sender();
Chris@0 3003 QAction *action = dynamic_cast<QAction *>(obj);
Chris@0 3004
Chris@0 3005 if (!action) {
Chris@0 3006 std::cerr << "WARNING: MainWindow::openRecentFile: sender is not an action"
Chris@0 3007 << std::endl;
Chris@0 3008 return;
Chris@0 3009 }
Chris@0 3010
Chris@0 3011 QString path = action->text();
Chris@0 3012 if (path == "") return;
Chris@0 3013
Chris@86 3014 QUrl url(path);
Chris@86 3015 if (RemoteFile::canHandleScheme(url)) {
Chris@86 3016 openURL(url);
Chris@86 3017 return;
Chris@86 3018 }
Chris@86 3019
Chris@0 3020 if (path.endsWith("sv")) {
Chris@0 3021
Chris@103 3022 if (!checkSaveModified()) return;
Chris@0 3023
Chris@82 3024 if (openSessionFile(path) == FileOpenFailed) {
Chris@0 3025 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 3026 tr("Session file \"%1\" could not be opened").arg(path));
Chris@0 3027 }
Chris@0 3028
Chris@0 3029 } else {
Chris@0 3030
Chris@82 3031 if (openAudioFile(path, AskUser) == FileOpenFailed) {
Chris@0 3032
Chris@0 3033 bool canImportLayer = (getMainModel() != 0 &&
Chris@0 3034 m_paneStack != 0 &&
Chris@0 3035 m_paneStack->getCurrentPane() != 0);
Chris@0 3036
Chris@82 3037 if (!canImportLayer || (openLayerFile(path) == FileOpenFailed)) {
Chris@0 3038
Chris@0 3039 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 3040 tr("File \"%1\" could not be opened").arg(path));
Chris@0 3041 }
Chris@0 3042 }
Chris@0 3043 }
Chris@0 3044 }
Chris@0 3045
Chris@82 3046 MainWindow::FileOpenStatus
Chris@85 3047 MainWindow::openURL(QUrl url)
Chris@85 3048 {
Chris@85 3049 if (url.scheme().toLower() == "file") {
Chris@85 3050 return openSomeFile(url.toLocalFile());
Chris@86 3051 } else if (!RemoteFile::canHandleScheme(url)) {
Chris@85 3052 QMessageBox::critical(this, tr("Unsupported scheme in URL"),
Chris@85 3053 tr("The URL scheme \"%1\" is not supported")
Chris@85 3054 .arg(url.scheme()));
Chris@85 3055 return FileOpenFailed;
Chris@85 3056 } else {
Chris@85 3057 RemoteFile rf(url);
Chris@85 3058 rf.wait();
Chris@85 3059 if (!rf.isOK()) {
Chris@85 3060 QMessageBox::critical(this, tr("File download failed"),
Chris@85 3061 tr("Failed to download URL \"%1\": %2")
Chris@85 3062 .arg(url.toString()).arg(rf.getErrorString()));
Chris@85 3063 return FileOpenFailed;
Chris@85 3064 }
Chris@88 3065 FileOpenStatus status;
Chris@88 3066 if ((status = openSomeFile(rf.getLocalFilename(), url.toString())) !=
Chris@88 3067 FileOpenSucceeded) {
Chris@88 3068 rf.deleteLocalFile();
Chris@88 3069 }
Chris@88 3070 return status;
Chris@85 3071 }
Chris@85 3072 }
Chris@85 3073
Chris@85 3074 MainWindow::FileOpenStatus
Chris@54 3075 MainWindow::openSomeFile(QString path, AudioFileOpenMode mode)
Chris@0 3076 {
Chris@86 3077 return openSomeFile(path, path, mode);
Chris@86 3078 }
Chris@86 3079
Chris@86 3080 MainWindow::FileOpenStatus
Chris@86 3081 MainWindow::openSomeFile(QString path, QString location,
Chris@86 3082 AudioFileOpenMode mode)
Chris@86 3083 {
Chris@82 3084 FileOpenStatus status;
Chris@82 3085
Chris@85 3086 bool canImportLayer = (getMainModel() != 0 &&
Chris@85 3087 m_paneStack != 0 &&
Chris@85 3088 m_paneStack->getCurrentPane() != 0);
Chris@85 3089
Chris@86 3090 if ((status = openAudioFile(path, location, mode)) != FileOpenFailed) {
Chris@82 3091 return status;
Chris@86 3092 } else if ((status = openSessionFile(path, location)) != FileOpenFailed) {
Chris@82 3093 return status;
Chris@85 3094 } else if (!canImportLayer) {
Chris@85 3095 return FileOpenFailed;
Chris@86 3096 } else if ((status = openLayerFile(path, location)) != FileOpenFailed) {
Chris@85 3097 return status;
Chris@0 3098 } else {
Chris@82 3099 return FileOpenFailed;
Chris@0 3100 }
Chris@0 3101 }
Chris@0 3102
Chris@82 3103 MainWindow::FileOpenStatus
Chris@0 3104 MainWindow::openSessionFile(QString path)
Chris@0 3105 {
Chris@86 3106 return openSessionFile(path, path);
Chris@86 3107 }
Chris@86 3108
Chris@86 3109 MainWindow::FileOpenStatus
Chris@86 3110 MainWindow::openSessionFile(QString path, QString location)
Chris@86 3111 {
Chris@0 3112 BZipFileDevice bzFile(path);
Chris@0 3113 if (!bzFile.open(QIODevice::ReadOnly)) {
Chris@86 3114 std::cerr << "Failed to open session file \"" << location.toStdString()
Chris@0 3115 << "\": " << bzFile.errorString().toStdString() << std::endl;
Chris@82 3116 return FileOpenFailed;
Chris@0 3117 }
Chris@0 3118
Chris@103 3119 if (!checkSaveModified()) return FileOpenCancelled;
Chris@103 3120
Chris@0 3121 QString error;
Chris@0 3122 closeSession();
Chris@0 3123 createDocument();
Chris@0 3124
Chris@0 3125 PaneCallback callback(this);
Chris@0 3126 m_viewManager->clearSelections();
Chris@0 3127
Chris@87 3128 SVFileReader reader(m_document, callback, location);
Chris@0 3129 QXmlInputSource inputSource(&bzFile);
Chris@0 3130 reader.parse(inputSource);
Chris@0 3131
Chris@0 3132 if (!reader.isOK()) {
Chris@0 3133 error = tr("SV XML file read error:\n%1").arg(reader.getErrorString());
Chris@0 3134 }
Chris@0 3135
Chris@0 3136 bzFile.close();
Chris@0 3137
Chris@0 3138 bool ok = (error == "");
Chris@86 3139
Chris@86 3140 bool realFile = (location == path);
Chris@0 3141
Chris@0 3142 if (ok) {
Chris@86 3143
Chris@0 3144 setWindowTitle(tr("Sonic Visualiser: %1")
Chris@86 3145 .arg(QFileInfo(location).fileName()));
Chris@86 3146
Chris@86 3147 if (realFile) m_sessionFile = path;
Chris@86 3148
Chris@0 3149 setupMenus();
Chris@0 3150 CommandHistory::getInstance()->clear();
Chris@0 3151 CommandHistory::getInstance()->documentSaved();
Chris@0 3152 m_documentModified = false;
Chris@0 3153 updateMenuStates();
Chris@86 3154
Chris@86 3155 m_recentFiles.addFile(location);
Chris@86 3156
Chris@86 3157 if (realFile) {
Chris@88 3158 registerLastOpenedFilePath(FileFinder::SessionFile, path); // for file dialog
Chris@86 3159 }
Chris@86 3160
Chris@0 3161 } else {
Chris@0 3162 setWindowTitle(tr("Sonic Visualiser"));
Chris@0 3163 }
Chris@0 3164
Chris@82 3165 return ok ? FileOpenSucceeded : FileOpenFailed;
Chris@0 3166 }
Chris@0 3167
Chris@0 3168 void
Chris@0 3169 MainWindow::closeEvent(QCloseEvent *e)
Chris@0 3170 {
Chris@137 3171 // std::cerr << "MainWindow::closeEvent" << std::endl;
Chris@118 3172
Chris@136 3173 if (m_openingAudioFile) {
Chris@137 3174 // std::cerr << "Busy - ignoring close event" << std::endl;
Chris@136 3175 e->ignore();
Chris@136 3176 return;
Chris@136 3177 }
Chris@136 3178
Chris@70 3179 if (!m_abandoning && !checkSaveModified()) {
Chris@137 3180 // std::cerr << "Ignoring close event" << std::endl;
Chris@0 3181 e->ignore();
Chris@0 3182 return;
Chris@0 3183 }
Chris@0 3184
Chris@5 3185 QSettings settings;
Chris@5 3186 settings.beginGroup("MainWindow");
Chris@5 3187 settings.setValue("size", size());
Chris@5 3188 settings.setValue("position", pos());
Chris@5 3189 settings.endGroup();
Chris@5 3190
Chris@163 3191 delete m_keyReference;
Chris@163 3192 m_keyReference = 0;
Chris@163 3193
Chris@163 3194 if (m_preferencesDialog &&
Chris@163 3195 m_preferencesDialog->isVisible()) {
Chris@164 3196 closeSession(); // otherwise we'll have to wait for prefs changes
Chris@163 3197 m_preferencesDialog->applicationClosing(false);
Chris@163 3198 }
Chris@163 3199
Chris@0 3200 e->accept();
Chris@0 3201 return;
Chris@0 3202 }
Chris@0 3203
Chris@0 3204 bool
Chris@11 3205 MainWindow::commitData(bool mayAskUser)
Chris@11 3206 {
Chris@11 3207 if (mayAskUser) {
Chris@163 3208 bool rv = checkSaveModified();
Chris@163 3209 if (rv) {
Chris@163 3210 if (m_preferencesDialog &&
Chris@163 3211 m_preferencesDialog->isVisible()) {
Chris@163 3212 m_preferencesDialog->applicationClosing(false);
Chris@163 3213 }
Chris@163 3214 }
Chris@163 3215 return rv;
Chris@11 3216 } else {
Chris@163 3217 if (m_preferencesDialog &&
Chris@163 3218 m_preferencesDialog->isVisible()) {
Chris@163 3219 m_preferencesDialog->applicationClosing(true);
Chris@163 3220 }
Chris@11 3221 if (!m_documentModified) return true;
Chris@11 3222
Chris@11 3223 // If we can't check with the user first, then we can't save
Chris@11 3224 // to the original session file (even if we have it) -- have
Chris@11 3225 // to use a temporary file
Chris@11 3226
Chris@11 3227 QString svDirBase = ".sv1";
Chris@11 3228 QString svDir = QDir::home().filePath(svDirBase);
Chris@11 3229
Chris@11 3230 if (!QFileInfo(svDir).exists()) {
Chris@11 3231 if (!QDir::home().mkdir(svDirBase)) return false;
Chris@11 3232 } else {
Chris@11 3233 if (!QFileInfo(svDir).isDir()) return false;
Chris@11 3234 }
Chris@11 3235
Chris@11 3236 // This name doesn't have to be unguessable
Chris@93 3237 #ifndef _WIN32
Chris@11 3238 QString fname = QString("tmp-%1-%2.sv")
Chris@11 3239 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"))
Chris@11 3240 .arg(QProcess().pid());
Chris@93 3241 #else
Chris@93 3242 QString fname = QString("tmp-%1.sv")
Chris@93 3243 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"));
Chris@93 3244 #endif
Chris@11 3245 QString fpath = QDir(svDir).filePath(fname);
Chris@11 3246 if (saveSessionFile(fpath)) {
Chris@34 3247 m_recentFiles.addFile(fpath);
Chris@11 3248 return true;
Chris@11 3249 } else {
Chris@11 3250 return false;
Chris@11 3251 }
Chris@11 3252 }
Chris@11 3253 }
Chris@11 3254
Chris@11 3255 bool
Chris@0 3256 MainWindow::checkSaveModified()
Chris@0 3257 {
Chris@0 3258 // Called before some destructive operation (e.g. new session,
Chris@0 3259 // exit program). Return true if we can safely proceed, false to
Chris@0 3260 // cancel.
Chris@0 3261
Chris@0 3262 if (!m_documentModified) return true;
Chris@0 3263
Chris@0 3264 int button =
Chris@0 3265 QMessageBox::warning(this,
Chris@0 3266 tr("Session modified"),
Chris@0 3267 tr("The current session has been modified.\nDo you want to save it?"),
Chris@165 3268 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
Chris@165 3269 QMessageBox::Yes);
Chris@0 3270
Chris@0 3271 if (button == QMessageBox::Yes) {
Chris@0 3272 saveSession();
Chris@0 3273 if (m_documentModified) { // save failed -- don't proceed!
Chris@0 3274 return false;
Chris@0 3275 } else {
Chris@0 3276 return true; // saved, so it's safe to continue now
Chris@0 3277 }
Chris@0 3278 } else if (button == QMessageBox::No) {
Chris@0 3279 m_documentModified = false; // so we know to abandon it
Chris@0 3280 return true;
Chris@0 3281 }
Chris@0 3282
Chris@0 3283 // else cancel
Chris@0 3284 return false;
Chris@0 3285 }
Chris@0 3286
Chris@0 3287 void
Chris@0 3288 MainWindow::saveSession()
Chris@0 3289 {
Chris@0 3290 if (m_sessionFile != "") {
Chris@0 3291 if (!saveSessionFile(m_sessionFile)) {
Chris@0 3292 QMessageBox::critical(this, tr("Failed to save file"),
Chris@0 3293 tr("Session file \"%1\" could not be saved.").arg(m_sessionFile));
Chris@0 3294 } else {
Chris@0 3295 CommandHistory::getInstance()->documentSaved();
Chris@0 3296 documentRestored();
Chris@0 3297 }
Chris@0 3298 } else {
Chris@0 3299 saveSessionAs();
Chris@0 3300 }
Chris@0 3301 }
Chris@0 3302
Chris@0 3303 void
Chris@0 3304 MainWindow::saveSessionAs()
Chris@0 3305 {
Chris@0 3306 QString orig = m_audioFile;
Chris@0 3307 if (orig == "") orig = ".";
Chris@0 3308 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 3309
Chris@88 3310 QString path = getSaveFileName(FileFinder::SessionFile);
Chris@81 3311
Chris@81 3312 if (path == "") return;
Chris@0 3313
Chris@0 3314 if (!saveSessionFile(path)) {
Chris@0 3315 QMessageBox::critical(this, tr("Failed to save file"),
Chris@79 3316 tr("Session file \"%1\" could not be saved.").arg(path));
Chris@0 3317 } else {
Chris@0 3318 setWindowTitle(tr("Sonic Visualiser: %1")
Chris@0 3319 .arg(QFileInfo(path).fileName()));
Chris@0 3320 m_sessionFile = path;
Chris@0 3321 CommandHistory::getInstance()->documentSaved();
Chris@0 3322 documentRestored();
Chris@34 3323 m_recentFiles.addFile(path);
Chris@0 3324 }
Chris@0 3325 }
Chris@0 3326
Chris@0 3327 bool
Chris@0 3328 MainWindow::saveSessionFile(QString path)
Chris@0 3329 {
Chris@0 3330 BZipFileDevice bzFile(path);
Chris@0 3331 if (!bzFile.open(QIODevice::WriteOnly)) {
Chris@0 3332 std::cerr << "Failed to open session file \"" << path.toStdString()
Chris@0 3333 << "\" for writing: "
Chris@0 3334 << bzFile.errorString().toStdString() << std::endl;
Chris@0 3335 return false;
Chris@0 3336 }
Chris@0 3337
Chris@0 3338 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
Chris@0 3339
Chris@0 3340 QTextStream out(&bzFile);
Chris@0 3341 toXml(out);
Chris@0 3342 out.flush();
Chris@0 3343
Chris@0 3344 QApplication::restoreOverrideCursor();
Chris@0 3345
Chris@84 3346 if (!bzFile.isOK()) {
Chris@0 3347 QMessageBox::critical(this, tr("Failed to write file"),
Chris@0 3348 tr("Failed to write to file \"%1\": %2")
Chris@0 3349 .arg(path).arg(bzFile.errorString()));
Chris@0 3350 bzFile.close();
Chris@0 3351 return false;
Chris@0 3352 }
Chris@0 3353
Chris@0 3354 bzFile.close();
Chris@0 3355 return true;
Chris@0 3356 }
Chris@0 3357
Chris@0 3358 void
Chris@0 3359 MainWindow::toXml(QTextStream &out)
Chris@0 3360 {
Chris@0 3361 QString indent(" ");
Chris@0 3362
Chris@0 3363 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
Chris@0 3364 out << "<!DOCTYPE sonic-visualiser>\n";
Chris@0 3365 out << "<sv>\n";
Chris@0 3366
Chris@0 3367 m_document->toXml(out, "", "");
Chris@0 3368
Chris@0 3369 out << "<display>\n";
Chris@0 3370
Chris@0 3371 out << QString(" <window width=\"%1\" height=\"%2\"/>\n")
Chris@0 3372 .arg(width()).arg(height());
Chris@0 3373
Chris@0 3374 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@0 3375
Chris@0 3376 Pane *pane = m_paneStack->getPane(i);
Chris@0 3377
Chris@0 3378 if (pane) {
Chris@0 3379 pane->toXml(out, indent);
Chris@0 3380 }
Chris@0 3381 }
Chris@0 3382
Chris@0 3383 out << "</display>\n";
Chris@0 3384
Chris@0 3385 m_viewManager->getSelection().toXml(out);
Chris@0 3386
Chris@0 3387 out << "</sv>\n";
Chris@0 3388 }
Chris@0 3389
Chris@0 3390 Pane *
Chris@0 3391 MainWindow::addPaneToStack()
Chris@0 3392 {
Chris@0 3393 AddPaneCommand *command = new AddPaneCommand(this);
Chris@0 3394 CommandHistory::getInstance()->addCommand(command);
Chris@0 3395 return command->getPane();
Chris@0 3396 }
Chris@0 3397
Chris@0 3398 void
Chris@0 3399 MainWindow::zoomIn()
Chris@0 3400 {
Chris@0 3401 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 3402 if (currentPane) currentPane->zoom(true);
Chris@0 3403 }
Chris@0 3404
Chris@0 3405 void
Chris@0 3406 MainWindow::zoomOut()
Chris@0 3407 {
Chris@0 3408 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 3409 if (currentPane) currentPane->zoom(false);
Chris@0 3410 }
Chris@0 3411
Chris@0 3412 void
Chris@0 3413 MainWindow::zoomToFit()
Chris@0 3414 {
Chris@0 3415 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 3416 if (!currentPane) return;
Chris@0 3417
Chris@0 3418 Model *model = getMainModel();
Chris@0 3419 if (!model) return;
Chris@0 3420
Chris@0 3421 size_t start = model->getStartFrame();
Chris@0 3422 size_t end = model->getEndFrame();
Chris@0 3423 size_t pixels = currentPane->width();
Chris@159 3424
Chris@158 3425 size_t sw = currentPane->getVerticalScaleWidth();
Chris@158 3426 if (pixels > sw * 2) pixels -= sw * 2;
Chris@158 3427 else pixels = 1;
Chris@159 3428 if (pixels > 4) pixels -= 4;
Chris@159 3429
Chris@0 3430 size_t zoomLevel = (end - start) / pixels;
Chris@0 3431
Chris@0 3432 currentPane->setZoomLevel(zoomLevel);
Chris@159 3433 currentPane->setCentreFrame((start + end) / 2);
Chris@0 3434 }
Chris@0 3435
Chris@0 3436 void
Chris@0 3437 MainWindow::zoomDefault()
Chris@0 3438 {
Chris@0 3439 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 3440 if (currentPane) currentPane->setZoomLevel(1024);
Chris@0 3441 }
Chris@0 3442
Chris@0 3443 void
Chris@0 3444 MainWindow::scrollLeft()
Chris@0 3445 {
Chris@0 3446 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 3447 if (currentPane) currentPane->scroll(false, false);
Chris@0 3448 }
Chris@0 3449
Chris@0 3450 void
Chris@0 3451 MainWindow::jumpLeft()
Chris@0 3452 {
Chris@0 3453 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 3454 if (currentPane) currentPane->scroll(false, true);
Chris@0 3455 }
Chris@0 3456
Chris@0 3457 void
Chris@0 3458 MainWindow::scrollRight()
Chris@0 3459 {
Chris@0 3460 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 3461 if (currentPane) currentPane->scroll(true, false);
Chris@0 3462 }
Chris@0 3463
Chris@0 3464 void
Chris@0 3465 MainWindow::jumpRight()
Chris@0 3466 {
Chris@0 3467 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 3468 if (currentPane) currentPane->scroll(true, true);
Chris@0 3469 }
Chris@0 3470
Chris@0 3471 void
Chris@0 3472 MainWindow::showNoOverlays()
Chris@0 3473 {
Chris@0 3474 m_viewManager->setOverlayMode(ViewManager::NoOverlays);
Chris@0 3475 }
Chris@0 3476
Chris@0 3477 void
Chris@90 3478 MainWindow::showMinimalOverlays()
Chris@0 3479 {
Chris@90 3480 m_viewManager->setOverlayMode(ViewManager::MinimalOverlays);
Chris@0 3481 }
Chris@0 3482
Chris@0 3483 void
Chris@90 3484 MainWindow::showStandardOverlays()
Chris@90 3485 {
Chris@90 3486 m_viewManager->setOverlayMode(ViewManager::StandardOverlays);
Chris@90 3487 }
Chris@90 3488
Chris@90 3489 void
Chris@90 3490 MainWindow::showAllOverlays()
Chris@0 3491 {
Chris@0 3492 m_viewManager->setOverlayMode(ViewManager::AllOverlays);
Chris@0 3493 }
Chris@0 3494
Chris@0 3495 void
Chris@7 3496 MainWindow::toggleZoomWheels()
Chris@7 3497 {
Chris@7 3498 if (m_viewManager->getZoomWheelsEnabled()) {
Chris@7 3499 m_viewManager->setZoomWheelsEnabled(false);
Chris@7 3500 } else {
Chris@7 3501 m_viewManager->setZoomWheelsEnabled(true);
Chris@7 3502 }
Chris@7 3503 }
Chris@7 3504
Chris@7 3505 void
Chris@72 3506 MainWindow::togglePropertyBoxes()
Chris@72 3507 {
Chris@72 3508 if (m_paneStack->getLayoutStyle() == PaneStack::NoPropertyStacks) {
Chris@72 3509 if (Preferences::getInstance()->getPropertyBoxLayout() ==
Chris@72 3510 Preferences::VerticallyStacked) {
Chris@72 3511 m_paneStack->setLayoutStyle(PaneStack::PropertyStackPerPaneLayout);
Chris@72 3512 } else {
Chris@72 3513 m_paneStack->setLayoutStyle(PaneStack::SinglePropertyStackLayout);
Chris@72 3514 }
Chris@72 3515 } else {
Chris@72 3516 m_paneStack->setLayoutStyle(PaneStack::NoPropertyStacks);
Chris@72 3517 }
Chris@72 3518 }
Chris@72 3519
Chris@72 3520 void
Chris@90 3521 MainWindow::toggleStatusBar()
Chris@90 3522 {
Chris@90 3523 QSettings settings;
Chris@90 3524 settings.beginGroup("MainWindow");
Chris@90 3525 bool sb = settings.value("showstatusbar", true).toBool();
Chris@90 3526
Chris@90 3527 if (sb) {
Chris@90 3528 statusBar()->hide();
Chris@90 3529 } else {
Chris@90 3530 statusBar()->show();
Chris@90 3531 }
Chris@90 3532
Chris@90 3533 settings.setValue("showstatusbar", !sb);
Chris@90 3534
Chris@90 3535 settings.endGroup();
Chris@90 3536 }
Chris@90 3537
Chris@90 3538 void
Chris@171 3539 MainWindow::toggleDarkBackground()
Chris@171 3540 {
Chris@171 3541 if (!m_viewManager) return;
Chris@171 3542 m_viewManager->setGlobalDarkBackground
Chris@171 3543 (!m_viewManager->getGlobalDarkBackground());
Chris@171 3544 }
Chris@171 3545
Chris@171 3546 void
Chris@72 3547 MainWindow::preferenceChanged(PropertyContainer::PropertyName name)
Chris@72 3548 {
Chris@72 3549 if (name == "Property Box Layout") {
Chris@72 3550 if (m_paneStack->getLayoutStyle() != PaneStack::NoPropertyStacks) {
Chris@72 3551 if (Preferences::getInstance()->getPropertyBoxLayout() ==
Chris@72 3552 Preferences::VerticallyStacked) {
Chris@72 3553 m_paneStack->setLayoutStyle(PaneStack::PropertyStackPerPaneLayout);
Chris@72 3554 } else {
Chris@72 3555 m_paneStack->setLayoutStyle(PaneStack::SinglePropertyStackLayout);
Chris@72 3556 }
Chris@72 3557 }
Chris@72 3558 }
Chris@72 3559 }
Chris@72 3560
Chris@72 3561 void
Chris@0 3562 MainWindow::play()
Chris@0 3563 {
Chris@0 3564 if (m_playSource->isPlaying()) {
Chris@116 3565 stop();
Chris@0 3566 } else {
Chris@116 3567 playbackFrameChanged(m_viewManager->getPlaybackFrame());
Chris@0 3568 m_playSource->play(m_viewManager->getPlaybackFrame());
Chris@0 3569 }
Chris@0 3570 }
Chris@0 3571
Chris@0 3572 void
Chris@0 3573 MainWindow::ffwd()
Chris@0 3574 {
Chris@0 3575 if (!getMainModel()) return;
Chris@0 3576
Chris@0 3577 int frame = m_viewManager->getPlaybackFrame();
Chris@0 3578 ++frame;
Chris@0 3579
Chris@155 3580 Layer *layer = getSnapLayer();
Chris@155 3581 size_t sr = getMainModel()->getSampleRate();
Chris@155 3582
Chris@155 3583 if (!layer) {
Chris@155 3584
Chris@155 3585 frame = RealTime::realTime2Frame
Chris@155 3586 (RealTime::frame2RealTime(frame, sr) + RealTime(2, 0), sr);
Chris@155 3587 if (frame > int(getMainModel()->getEndFrame())) {
Chris@155 3588 frame = getMainModel()->getEndFrame();
Chris@155 3589 }
Chris@155 3590
Chris@155 3591 } else {
Chris@155 3592
Chris@155 3593 size_t resolution = 0;
Chris@155 3594 if (!layer->snapToFeatureFrame(m_paneStack->getCurrentPane(),
Chris@155 3595 frame, resolution, Layer::SnapRight)) {
Chris@155 3596 frame = getMainModel()->getEndFrame();
Chris@155 3597 }
Chris@0 3598 }
Chris@155 3599
Chris@155 3600 if (frame < 0) frame = 0;
Chris@147 3601
Chris@147 3602 if (m_viewManager->getPlaySelectionMode()) {
Chris@155 3603 frame = m_viewManager->constrainFrameToSelection(size_t(frame));
Chris@147 3604 }
Chris@0 3605
Chris@0 3606 m_viewManager->setPlaybackFrame(frame);
Chris@0 3607 }
Chris@0 3608
Chris@0 3609 void
Chris@0 3610 MainWindow::ffwdEnd()
Chris@0 3611 {
Chris@0 3612 if (!getMainModel()) return;
Chris@147 3613
Chris@147 3614 size_t frame = getMainModel()->getEndFrame();
Chris@147 3615
Chris@147 3616 if (m_viewManager->getPlaySelectionMode()) {
Chris@155 3617 frame = m_viewManager->constrainFrameToSelection(frame);
Chris@147 3618 }
Chris@147 3619
Chris@147 3620 m_viewManager->setPlaybackFrame(frame);
Chris@0 3621 }
Chris@0 3622
Chris@0 3623 void
Chris@0 3624 MainWindow::rewind()
Chris@0 3625 {
Chris@0 3626 if (!getMainModel()) return;
Chris@0 3627
Chris@0 3628 int frame = m_viewManager->getPlaybackFrame();
Chris@0 3629 if (frame > 0) --frame;
Chris@0 3630
Chris@155 3631 Layer *layer = getSnapLayer();
Chris@155 3632 size_t sr = getMainModel()->getSampleRate();
Chris@156 3633
Chris@156 3634 // when rewinding during playback, we want to allow a period
Chris@156 3635 // following a rewind target point at which the rewind will go to
Chris@156 3636 // the prior point instead of the immediately neighbouring one
Chris@156 3637 if (m_playSource && m_playSource->isPlaying()) {
Chris@156 3638 RealTime ct = RealTime::frame2RealTime(frame, sr);
Chris@156 3639 ct = ct - RealTime::fromSeconds(0.25);
Chris@156 3640 if (ct < RealTime::zeroTime) ct = RealTime::zeroTime;
Chris@156 3641 // std::cerr << "rewind: frame " << frame << " -> ";
Chris@156 3642 frame = RealTime::realTime2Frame(ct, sr);
Chris@156 3643 // std::cerr << frame << std::endl;
Chris@156 3644 }
Chris@155 3645
Chris@155 3646 if (!layer) {
Chris@155 3647
Chris@155 3648 frame = RealTime::realTime2Frame
Chris@155 3649 (RealTime::frame2RealTime(frame, sr) - RealTime(2, 0), sr);
Chris@155 3650 if (frame < int(getMainModel()->getStartFrame())) {
Chris@155 3651 frame = getMainModel()->getStartFrame();
Chris@155 3652 }
Chris@155 3653
Chris@155 3654 } else {
Chris@155 3655
Chris@155 3656 size_t resolution = 0;
Chris@155 3657 if (!layer->snapToFeatureFrame(m_paneStack->getCurrentPane(),
Chris@155 3658 frame, resolution, Layer::SnapLeft)) {
Chris@155 3659 frame = getMainModel()->getStartFrame();
Chris@155 3660 }
Chris@0 3661 }
Chris@147 3662
Chris@155 3663 if (frame < 0) frame = 0;
Chris@155 3664
Chris@147 3665 if (m_viewManager->getPlaySelectionMode()) {
Chris@155 3666 frame = m_viewManager->constrainFrameToSelection(size_t(frame));
Chris@147 3667 }
Chris@147 3668
Chris@0 3669 m_viewManager->setPlaybackFrame(frame);
Chris@0 3670 }
Chris@0 3671
Chris@0 3672 void
Chris@0 3673 MainWindow::rewindStart()
Chris@0 3674 {
Chris@0 3675 if (!getMainModel()) return;
Chris@147 3676
Chris@147 3677 size_t frame = getMainModel()->getStartFrame();
Chris@147 3678
Chris@147 3679 if (m_viewManager->getPlaySelectionMode()) {
Chris@155 3680 frame = m_viewManager->constrainFrameToSelection(frame);
Chris@155 3681 }
Chris@155 3682
Chris@155 3683 m_viewManager->setPlaybackFrame(frame);
Chris@155 3684 }
Chris@155 3685
Chris@155 3686 Layer *
Chris@155 3687 MainWindow::getSnapLayer() const
Chris@155 3688 {
Chris@155 3689 Pane *pane = m_paneStack->getCurrentPane();
Chris@155 3690 if (!pane) return 0;
Chris@155 3691
Chris@155 3692 Layer *layer = pane->getSelectedLayer();
Chris@155 3693
Chris@155 3694 if (!dynamic_cast<TimeInstantLayer *>(layer) &&
Chris@155 3695 !dynamic_cast<TimeValueLayer *>(layer) &&
Chris@155 3696 !dynamic_cast<TimeRulerLayer *>(layer)) {
Chris@155 3697
Chris@155 3698 layer = 0;
Chris@155 3699
Chris@155 3700 for (int i = pane->getLayerCount(); i > 0; --i) {
Chris@155 3701 Layer *l = pane->getLayer(i-1);
Chris@155 3702 if (dynamic_cast<TimeRulerLayer *>(l)) {
Chris@155 3703 layer = l;
Chris@155 3704 break;
Chris@155 3705 }
Chris@147 3706 }
Chris@147 3707 }
Chris@147 3708
Chris@155 3709 return layer;
Chris@0 3710 }
Chris@0 3711
Chris@0 3712 void
Chris@0 3713 MainWindow::stop()
Chris@0 3714 {
Chris@0 3715 m_playSource->stop();
Chris@116 3716
Chris@116 3717 if (m_paneStack && m_paneStack->getCurrentPane()) {
Chris@116 3718 updateVisibleRangeDisplay(m_paneStack->getCurrentPane());
Chris@116 3719 } else {
Chris@116 3720 m_myStatusMessage = "";
Chris@116 3721 statusBar()->showMessage("");
Chris@116 3722 }
Chris@0 3723 }
Chris@0 3724
Chris@0 3725 void
Chris@0 3726 MainWindow::addPane()
Chris@0 3727 {
Chris@0 3728 QObject *s = sender();
Chris@0 3729 QAction *action = dynamic_cast<QAction *>(s);
Chris@0 3730
Chris@0 3731 if (!action) {
Chris@0 3732 std::cerr << "WARNING: MainWindow::addPane: sender is not an action"
Chris@0 3733 << std::endl;
Chris@0 3734 return;
Chris@0 3735 }
Chris@0 3736
Chris@0 3737 PaneActionMap::iterator i = m_paneActions.find(action);
Chris@0 3738
Chris@0 3739 if (i == m_paneActions.end()) {
Chris@0 3740 std::cerr << "WARNING: MainWindow::addPane: unknown action "
Chris@0 3741 << action->objectName().toStdString() << std::endl;
Chris@0 3742 return;
Chris@0 3743 }
Chris@0 3744
Chris@69 3745 addPane(i->second, action->text());
Chris@69 3746 }
Chris@69 3747
Chris@69 3748 void
Chris@69 3749 MainWindow::addPane(const PaneConfiguration &configuration, QString text)
Chris@69 3750 {
Chris@69 3751 CommandHistory::getInstance()->startCompoundOperation(text, true);
Chris@0 3752
Chris@0 3753 AddPaneCommand *command = new AddPaneCommand(this);
Chris@0 3754 CommandHistory::getInstance()->addCommand(command);
Chris@0 3755
Chris@0 3756 Pane *pane = command->getPane();
Chris@0 3757
Chris@69 3758 if (configuration.layer == LayerFactory::Spectrum) {
Chris@109 3759 pane->setPlaybackFollow(PlaybackScrollContinuous);
Chris@110 3760 pane->setFollowGlobalZoom(false);
Chris@112 3761 pane->setZoomLevel(512);
Chris@7 3762 }
Chris@7 3763
Chris@69 3764 if (configuration.layer != LayerFactory::TimeRuler &&
Chris@69 3765 configuration.layer != LayerFactory::Spectrum) {
Chris@8 3766
Chris@0 3767 if (!m_timeRulerLayer) {
Chris@0 3768 // std::cerr << "no time ruler layer, creating one" << std::endl;
Chris@0 3769 m_timeRulerLayer = m_document->createMainModelLayer
Chris@0 3770 (LayerFactory::TimeRuler);
Chris@0 3771 }
Chris@0 3772
Chris@0 3773 // std::cerr << "adding time ruler layer " << m_timeRulerLayer << std::endl;
Chris@0 3774
Chris@0 3775 m_document->addLayerToView(pane, m_timeRulerLayer);
Chris@0 3776 }
Chris@0 3777
Chris@69 3778 Layer *newLayer = m_document->createLayer(configuration.layer);
Chris@69 3779
Chris@69 3780 Model *suggestedModel = configuration.sourceModel;
Chris@66 3781 Model *model = 0;
Chris@66 3782
Chris@66 3783 if (suggestedModel) {
Chris@66 3784
Chris@66 3785 // check its validity
Chris@66 3786 std::vector<Model *> inputModels = m_document->getTransformInputModels();
Chris@66 3787 for (size_t j = 0; j < inputModels.size(); ++j) {
Chris@66 3788 if (inputModels[j] == suggestedModel) {
Chris@66 3789 model = suggestedModel;
Chris@66 3790 break;
Chris@66 3791 }
Chris@66 3792 }
Chris@66 3793
Chris@66 3794 if (!model) {
Chris@66 3795 std::cerr << "WARNING: Model " << (void *)suggestedModel
Chris@66 3796 << " appears in pane action map, but is not reported "
Chris@66 3797 << "by document as a valid transform source" << std::endl;
Chris@66 3798 }
Chris@66 3799 }
Chris@66 3800
Chris@66 3801 if (!model) model = m_document->getMainModel();
Chris@66 3802
Chris@66 3803 m_document->setModel(newLayer, model);
Chris@66 3804
Chris@69 3805 m_document->setChannel(newLayer, configuration.channel);
Chris@0 3806 m_document->addLayerToView(pane, newLayer);
Chris@0 3807
Chris@0 3808 m_paneStack->setCurrentPane(pane);
Chris@70 3809 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 3810
Chris@130 3811 // std::cerr << "MainWindow::addPane: global centre frame is "
Chris@130 3812 // << m_viewManager->getGlobalCentreFrame() << std::endl;
Chris@130 3813 // pane->setCentreFrame(m_viewManager->getGlobalCentreFrame());
Chris@73 3814
Chris@0 3815 CommandHistory::getInstance()->endCompoundOperation();
Chris@0 3816
Chris@0 3817 updateMenuStates();
Chris@0 3818 }
Chris@0 3819
Chris@0 3820 MainWindow::AddPaneCommand::AddPaneCommand(MainWindow *mw) :
Chris@0 3821 m_mw(mw),
Chris@0 3822 m_pane(0),
Chris@0 3823 m_prevCurrentPane(0),
Chris@0 3824 m_added(false)
Chris@0 3825 {
Chris@0 3826 }
Chris@0 3827
Chris@0 3828 MainWindow::AddPaneCommand::~AddPaneCommand()
Chris@0 3829 {
Chris@0 3830 if (m_pane && !m_added) {
Chris@0 3831 m_mw->m_paneStack->deletePane(m_pane);
Chris@0 3832 }
Chris@0 3833 }
Chris@0 3834
Chris@0 3835 QString
Chris@0 3836 MainWindow::AddPaneCommand::getName() const
Chris@0 3837 {
Chris@0 3838 return tr("Add Pane");
Chris@0 3839 }
Chris@0 3840
Chris@0 3841 void
Chris@0 3842 MainWindow::AddPaneCommand::execute()
Chris@0 3843 {
Chris@0 3844 if (!m_pane) {
Chris@0 3845 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
Chris@0 3846 m_pane = m_mw->m_paneStack->addPane();
Chris@90 3847
Chris@90 3848 connect(m_pane, SIGNAL(contextHelpChanged(const QString &)),
Chris@116 3849 m_mw, SLOT(contextHelpChanged(const QString &)));
Chris@0 3850 } else {
Chris@0 3851 m_mw->m_paneStack->showPane(m_pane);
Chris@0 3852 }
Chris@0 3853
Chris@0 3854 m_mw->m_paneStack->setCurrentPane(m_pane);
Chris@65 3855 m_mw->m_overview->registerView(m_pane);
Chris@0 3856 m_added = true;
Chris@0 3857 }
Chris@0 3858
Chris@0 3859 void
Chris@0 3860 MainWindow::AddPaneCommand::unexecute()
Chris@0 3861 {
Chris@0 3862 m_mw->m_paneStack->hidePane(m_pane);
Chris@0 3863 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
Chris@65 3864 m_mw->m_overview->unregisterView(m_pane);
Chris@0 3865 m_added = false;
Chris@0 3866 }
Chris@0 3867
Chris@0 3868 MainWindow::RemovePaneCommand::RemovePaneCommand(MainWindow *mw, Pane *pane) :
Chris@0 3869 m_mw(mw),
Chris@0 3870 m_pane(pane),
Chris@0 3871 m_added(true)
Chris@0 3872 {
Chris@0 3873 }
Chris@0 3874
Chris@0 3875 MainWindow::RemovePaneCommand::~RemovePaneCommand()
Chris@0 3876 {
Chris@0 3877 if (m_pane && !m_added) {
Chris@0 3878 m_mw->m_paneStack->deletePane(m_pane);
Chris@0 3879 }
Chris@0 3880 }
Chris@0 3881
Chris@0 3882 QString
Chris@0 3883 MainWindow::RemovePaneCommand::getName() const
Chris@0 3884 {
Chris@0 3885 return tr("Remove Pane");
Chris@0 3886 }
Chris@0 3887
Chris@0 3888 void
Chris@0 3889 MainWindow::RemovePaneCommand::execute()
Chris@0 3890 {
Chris@0 3891 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
Chris@0 3892 m_mw->m_paneStack->hidePane(m_pane);
Chris@65 3893 m_mw->m_overview->unregisterView(m_pane);
Chris@0 3894 m_added = false;
Chris@0 3895 }
Chris@0 3896
Chris@0 3897 void
Chris@0 3898 MainWindow::RemovePaneCommand::unexecute()
Chris@0 3899 {
Chris@0 3900 m_mw->m_paneStack->showPane(m_pane);
Chris@0 3901 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
Chris@65 3902 m_mw->m_overview->registerView(m_pane);
Chris@0 3903 m_added = true;
Chris@0 3904 }
Chris@0 3905
Chris@0 3906 void
Chris@0 3907 MainWindow::addLayer()
Chris@0 3908 {
Chris@0 3909 QObject *s = sender();
Chris@0 3910 QAction *action = dynamic_cast<QAction *>(s);
Chris@0 3911
Chris@0 3912 if (!action) {
Chris@0 3913 std::cerr << "WARNING: MainWindow::addLayer: sender is not an action"
Chris@0 3914 << std::endl;
Chris@0 3915 return;
Chris@0 3916 }
Chris@0 3917
Chris@0 3918 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 3919
Chris@0 3920 if (!pane) {
Chris@0 3921 std::cerr << "WARNING: MainWindow::addLayer: no current pane" << std::endl;
Chris@0 3922 return;
Chris@0 3923 }
Chris@0 3924
Chris@0 3925 ExistingLayerActionMap::iterator ei = m_existingLayerActions.find(action);
Chris@0 3926
Chris@0 3927 if (ei != m_existingLayerActions.end()) {
Chris@0 3928 Layer *newLayer = ei->second;
Chris@0 3929 m_document->addLayerToView(pane, newLayer);
Chris@0 3930 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 3931 return;
Chris@0 3932 }
Chris@0 3933
Chris@95 3934 ei = m_sliceActions.find(action);
Chris@95 3935
Chris@95 3936 if (ei != m_sliceActions.end()) {
Chris@95 3937 Layer *newLayer = m_document->createLayer(LayerFactory::Slice);
Chris@95 3938 // document->setModel(newLayer, ei->second->getModel());
Chris@95 3939 SliceableLayer *source = dynamic_cast<SliceableLayer *>(ei->second);
Chris@95 3940 SliceLayer *dest = dynamic_cast<SliceLayer *>(newLayer);
Chris@95 3941 if (source && dest) {
Chris@95 3942 dest->setSliceableModel(source->getSliceableModel());
Chris@95 3943 connect(source, SIGNAL(sliceableModelReplaced(const Model *, const Model *)),
Chris@95 3944 dest, SLOT(sliceableModelReplaced(const Model *, const Model *)));
Chris@95 3945 connect(m_document, SIGNAL(modelAboutToBeDeleted(Model *)),
Chris@95 3946 dest, SLOT(modelAboutToBeDeleted(Model *)));
Chris@95 3947 }
Chris@95 3948 m_document->addLayerToView(pane, newLayer);
Chris@95 3949 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@95 3950 return;
Chris@95 3951 }
Chris@95 3952
Chris@34 3953 TransformActionMap::iterator i = m_transformActions.find(action);
Chris@34 3954
Chris@34 3955 if (i == m_transformActions.end()) {
Chris@0 3956
Chris@0 3957 LayerActionMap::iterator i = m_layerActions.find(action);
Chris@0 3958
Chris@0 3959 if (i == m_layerActions.end()) {
Chris@0 3960 std::cerr << "WARNING: MainWindow::addLayer: unknown action "
Chris@0 3961 << action->objectName().toStdString() << std::endl;
Chris@0 3962 return;
Chris@0 3963 }
Chris@0 3964
Chris@0 3965 LayerFactory::LayerType type = i->second;
Chris@0 3966
Chris@0 3967 LayerFactory::LayerTypeSet emptyTypes =
Chris@0 3968 LayerFactory::getInstance()->getValidEmptyLayerTypes();
Chris@0 3969
Chris@0 3970 Layer *newLayer;
Chris@0 3971
Chris@0 3972 if (emptyTypes.find(type) != emptyTypes.end()) {
Chris@0 3973
Chris@0 3974 newLayer = m_document->createEmptyLayer(type);
Chris@0 3975 m_toolActions[ViewManager::DrawMode]->trigger();
Chris@0 3976
Chris@0 3977 } else {
Chris@0 3978
Chris@0 3979 newLayer = m_document->createMainModelLayer(type);
Chris@0 3980 }
Chris@0 3981
Chris@0 3982 m_document->addLayerToView(pane, newLayer);
Chris@0 3983 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 3984
Chris@0 3985 return;
Chris@0 3986 }
Chris@0 3987
Chris@107 3988 TransformId transform = i->second;
Chris@0 3989 TransformFactory *factory = TransformFactory::getInstance();
Chris@0 3990
Chris@0 3991 QString configurationXml;
Chris@0 3992
Chris@0 3993 int channel = -1;
Chris@0 3994 // pick up the default channel from any existing layers on the same pane
Chris@0 3995 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@0 3996 int c = LayerFactory::getInstance()->getChannel(pane->getLayer(j));
Chris@0 3997 if (c != -1) {
Chris@0 3998 channel = c;
Chris@0 3999 break;
Chris@0 4000 }
Chris@0 4001 }
Chris@0 4002
Chris@33 4003 // We always ask for configuration, even if the plugin isn't
Chris@33 4004 // supposed to be configurable, because we need to let the user
Chris@33 4005 // change the execution context (block size etc).
Chris@0 4006
Chris@27 4007 PluginTransform::ExecutionContext context(channel);
Chris@27 4008
Chris@66 4009 std::vector<Model *> candidateInputModels =
Chris@66 4010 m_document->getTransformInputModels();
Chris@53 4011
Chris@54 4012 Model *inputModel = factory->getConfigurationForTransform(transform,
Chris@54 4013 candidateInputModels,
Chris@54 4014 context,
Chris@54 4015 configurationXml,
Chris@54 4016 m_playSource);
Chris@54 4017 if (!inputModel) return;
Chris@54 4018
Chris@135 4019 // std::cerr << "MainWindow::addLayer: Input model is " << inputModel << " \"" << inputModel->objectName().toStdString() << "\"" << std::endl;
Chris@0 4020
Chris@0 4021 Layer *newLayer = m_document->createDerivedLayer(transform,
Chris@54 4022 inputModel,
Chris@27 4023 context,
Chris@0 4024 configurationXml);
Chris@0 4025
Chris@0 4026 if (newLayer) {
Chris@0 4027 m_document->addLayerToView(pane, newLayer);
Chris@27 4028 m_document->setChannel(newLayer, context.channel);
Chris@34 4029 m_recentTransforms.add(transform);
Chris@70 4030 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 4031 }
Chris@0 4032
Chris@0 4033 updateMenuStates();
Chris@0 4034 }
Chris@0 4035
Chris@0 4036 void
Chris@0 4037 MainWindow::deleteCurrentPane()
Chris@0 4038 {
Chris@0 4039 CommandHistory::getInstance()->startCompoundOperation
Chris@0 4040 (tr("Delete Pane"), true);
Chris@0 4041
Chris@0 4042 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 4043 if (pane) {
Chris@0 4044 while (pane->getLayerCount() > 0) {
Chris@0 4045 Layer *layer = pane->getLayer(0);
Chris@0 4046 if (layer) {
Chris@0 4047 m_document->removeLayerFromView(pane, layer);
Chris@0 4048 } else {
Chris@0 4049 break;
Chris@0 4050 }
Chris@0 4051 }
Chris@0 4052
Chris@0 4053 RemovePaneCommand *command = new RemovePaneCommand(this, pane);
Chris@0 4054 CommandHistory::getInstance()->addCommand(command);
Chris@0 4055 }
Chris@0 4056
Chris@0 4057 CommandHistory::getInstance()->endCompoundOperation();
Chris@0 4058
Chris@0 4059 updateMenuStates();
Chris@0 4060 }
Chris@0 4061
Chris@0 4062 void
Chris@0 4063 MainWindow::deleteCurrentLayer()
Chris@0 4064 {
Chris@0 4065 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 4066 if (pane) {
Chris@0 4067 Layer *layer = pane->getSelectedLayer();
Chris@0 4068 if (layer) {
Chris@0 4069 m_document->removeLayerFromView(pane, layer);
Chris@0 4070 }
Chris@0 4071 }
Chris@0 4072 updateMenuStates();
Chris@0 4073 }
Chris@0 4074
Chris@0 4075 void
Chris@0 4076 MainWindow::renameCurrentLayer()
Chris@0 4077 {
Chris@0 4078 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 4079 if (pane) {
Chris@0 4080 Layer *layer = pane->getSelectedLayer();
Chris@0 4081 if (layer) {
Chris@0 4082 bool ok = false;
Chris@0 4083 QString newName = QInputDialog::getText
Chris@0 4084 (this, tr("Rename Layer"),
Chris@0 4085 tr("New name for this layer:"),
Chris@0 4086 QLineEdit::Normal, layer->objectName(), &ok);
Chris@0 4087 if (ok) {
Chris@0 4088 layer->setObjectName(newName);
Chris@95 4089 setupExistingLayersMenus();
Chris@0 4090 }
Chris@0 4091 }
Chris@0 4092 }
Chris@0 4093 }
Chris@0 4094
Chris@0 4095 void
Chris@59 4096 MainWindow::playSpeedChanged(int position)
Chris@0 4097 {
Chris@59 4098 PlaySpeedRangeMapper mapper(0, 200);
Chris@60 4099
Chris@60 4100 float percent = m_playSpeed->mappedValue();
Chris@60 4101 float factor = mapper.getFactorForValue(percent);
Chris@60 4102
Chris@60 4103 std::cerr << "speed = " << position << " percent = " << percent << " factor = " << factor << std::endl;
Chris@60 4104
Chris@59 4105 bool something = (position != 100);
Chris@155 4106
Chris@59 4107 int pc = lrintf(percent);
Chris@21 4108
Chris@155 4109 if (!something) {
Chris@155 4110 contextHelpChanged(tr("Playback speed: Normal"));
Chris@155 4111 } else {
Chris@155 4112 contextHelpChanged(tr("Playback speed: %1%2%")
Chris@155 4113 .arg(position > 100 ? "+" : "")
Chris@155 4114 .arg(pc));
Chris@155 4115 }
Chris@155 4116
Chris@25 4117 m_playSharpen->setEnabled(something);
Chris@26 4118 m_playMono->setEnabled(something);
Chris@25 4119 bool sharpen = (something && m_playSharpen->isChecked());
Chris@26 4120 bool mono = (something && m_playMono->isChecked());
Chris@26 4121 m_playSource->setTimeStretch(factor, sharpen, mono);
Chris@155 4122
Chris@155 4123 updateMenuStates();
Chris@16 4124 }
Chris@16 4125
Chris@16 4126 void
Chris@16 4127 MainWindow::playSharpenToggled()
Chris@16 4128 {
Chris@21 4129 QSettings settings;
Chris@21 4130 settings.beginGroup("MainWindow");
Chris@21 4131 settings.setValue("playsharpen", m_playSharpen->isChecked());
Chris@21 4132 settings.endGroup();
Chris@21 4133
Chris@16 4134 playSpeedChanged(m_playSpeed->value());
Chris@0 4135 }
Chris@0 4136
Chris@0 4137 void
Chris@26 4138 MainWindow::playMonoToggled()
Chris@26 4139 {
Chris@26 4140 QSettings settings;
Chris@26 4141 settings.beginGroup("MainWindow");
Chris@26 4142 settings.setValue("playmono", m_playMono->isChecked());
Chris@26 4143 settings.endGroup();
Chris@26 4144
Chris@26 4145 playSpeedChanged(m_playSpeed->value());
Chris@26 4146 }
Chris@26 4147
Chris@26 4148 void
Chris@155 4149 MainWindow::speedUpPlayback()
Chris@155 4150 {
Chris@155 4151 int value = m_playSpeed->value();
Chris@155 4152 value = value + m_playSpeed->pageStep();
Chris@155 4153 if (value > m_playSpeed->maximum()) value = m_playSpeed->maximum();
Chris@155 4154 m_playSpeed->setValue(value);
Chris@155 4155 }
Chris@155 4156
Chris@155 4157 void
Chris@155 4158 MainWindow::slowDownPlayback()
Chris@155 4159 {
Chris@155 4160 int value = m_playSpeed->value();
Chris@155 4161 value = value - m_playSpeed->pageStep();
Chris@155 4162 if (value < m_playSpeed->minimum()) value = m_playSpeed->minimum();
Chris@155 4163 m_playSpeed->setValue(value);
Chris@155 4164 }
Chris@155 4165
Chris@155 4166 void
Chris@155 4167 MainWindow::restoreNormalPlayback()
Chris@155 4168 {
Chris@155 4169 m_playSpeed->setValue(m_playSpeed->defaultValue());
Chris@155 4170 }
Chris@155 4171
Chris@155 4172 void
Chris@116 4173 MainWindow::playbackFrameChanged(unsigned long frame)
Chris@116 4174 {
Chris@116 4175 if (!(m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
Chris@116 4176
Chris@116 4177 RealTime now = RealTime::frame2RealTime
Chris@116 4178 (frame, getMainModel()->getSampleRate());
Chris@116 4179
Chris@116 4180 if (now.sec == m_lastPlayStatusSec) return;
Chris@116 4181
Chris@116 4182 RealTime then = RealTime::frame2RealTime
Chris@116 4183 (m_playSource->getPlayEndFrame(), getMainModel()->getSampleRate());
Chris@116 4184
Chris@116 4185 QString nowStr;
Chris@116 4186 QString thenStr;
Chris@116 4187 QString remainingStr;
Chris@116 4188
Chris@116 4189 if (then.sec > 10) {
Chris@116 4190 nowStr = now.toSecText().c_str();
Chris@116 4191 thenStr = then.toSecText().c_str();
Chris@116 4192 remainingStr = (then - now).toSecText().c_str();
Chris@116 4193 m_lastPlayStatusSec = now.sec;
Chris@116 4194 } else {
Chris@116 4195 nowStr = now.toText(true).c_str();
Chris@116 4196 thenStr = then.toText(true).c_str();
Chris@116 4197 remainingStr = (then - now).toText(true).c_str();
Chris@116 4198 }
Chris@116 4199
Chris@116 4200 m_myStatusMessage = tr("Playing: %1 of %2 (%3 remaining)")
Chris@116 4201 .arg(nowStr).arg(thenStr).arg(remainingStr);
Chris@116 4202
Chris@116 4203 statusBar()->showMessage(m_myStatusMessage);
Chris@116 4204 }
Chris@116 4205
Chris@116 4206 void
Chris@137 4207 MainWindow::globalCentreFrameChanged(unsigned long )
Chris@116 4208 {
Chris@116 4209 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
Chris@116 4210 Pane *p = 0;
Chris@116 4211 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
Chris@116 4212 if (!p->getFollowGlobalPan()) return;
Chris@116 4213 updateVisibleRangeDisplay(p);
Chris@116 4214 }
Chris@116 4215
Chris@116 4216 void
Chris@137 4217 MainWindow::viewCentreFrameChanged(View *v, unsigned long )
Chris@116 4218 {
Chris@116 4219 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
Chris@116 4220 Pane *p = 0;
Chris@116 4221 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
Chris@116 4222 if (v == p) updateVisibleRangeDisplay(p);
Chris@116 4223 }
Chris@116 4224
Chris@116 4225 void
Chris@137 4226 MainWindow::viewZoomLevelChanged(View *v, unsigned long , bool )
Chris@116 4227 {
Chris@116 4228 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
Chris@116 4229 Pane *p = 0;
Chris@116 4230 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
Chris@116 4231 if (v == p) updateVisibleRangeDisplay(p);
Chris@116 4232 }
Chris@116 4233
Chris@116 4234 void
Chris@116 4235 MainWindow::updateVisibleRangeDisplay(Pane *p) const
Chris@116 4236 {
Chris@116 4237 if (!getMainModel() || !p) {
Chris@116 4238 return;
Chris@116 4239 }
Chris@116 4240
Chris@117 4241 bool haveSelection = false;
Chris@117 4242 size_t startFrame = 0, endFrame = 0;
Chris@117 4243
Chris@117 4244 if (m_viewManager && m_viewManager->haveInProgressSelection()) {
Chris@117 4245
Chris@117 4246 bool exclusive = false;
Chris@117 4247 Selection s = m_viewManager->getInProgressSelection(exclusive);
Chris@117 4248
Chris@117 4249 if (!s.isEmpty()) {
Chris@117 4250 haveSelection = true;
Chris@117 4251 startFrame = s.getStartFrame();
Chris@117 4252 endFrame = s.getEndFrame();
Chris@117 4253 }
Chris@117 4254 }
Chris@117 4255
Chris@117 4256 if (!haveSelection) {
Chris@117 4257 startFrame = p->getFirstVisibleFrame();
Chris@117 4258 endFrame = p->getLastVisibleFrame();
Chris@117 4259 }
Chris@117 4260
Chris@116 4261 RealTime start = RealTime::frame2RealTime
Chris@117 4262 (startFrame, getMainModel()->getSampleRate());
Chris@116 4263
Chris@116 4264 RealTime end = RealTime::frame2RealTime
Chris@117 4265 (endFrame, getMainModel()->getSampleRate());
Chris@116 4266
Chris@116 4267 RealTime duration = end - start;
Chris@116 4268
Chris@116 4269 QString startStr, endStr, durationStr;
Chris@116 4270 startStr = start.toText(true).c_str();
Chris@116 4271 endStr = end.toText(true).c_str();
Chris@116 4272 durationStr = duration.toText(true).c_str();
Chris@116 4273
Chris@117 4274 if (haveSelection) {
Chris@117 4275 m_myStatusMessage = tr("Selection: %1 to %2 (duration %3)")
Chris@117 4276 .arg(startStr).arg(endStr).arg(durationStr);
Chris@117 4277 } else {
Chris@117 4278 m_myStatusMessage = tr("Visible: %1 to %2 (duration %3)")
Chris@117 4279 .arg(startStr).arg(endStr).arg(durationStr);
Chris@117 4280 }
Chris@116 4281
Chris@116 4282 statusBar()->showMessage(m_myStatusMessage);
Chris@116 4283 }
Chris@116 4284
Chris@116 4285 void
Chris@0 4286 MainWindow::outputLevelsChanged(float left, float right)
Chris@0 4287 {
Chris@0 4288 m_fader->setPeakLeft(left);
Chris@0 4289 m_fader->setPeakRight(right);
Chris@0 4290 }
Chris@0 4291
Chris@0 4292 void
Chris@0 4293 MainWindow::sampleRateMismatch(size_t requested, size_t actual,
Chris@0 4294 bool willResample)
Chris@0 4295 {
Chris@0 4296 if (!willResample) {
Chris@0 4297 //!!! more helpful message needed
Chris@0 4298 QMessageBox::information
Chris@0 4299 (this, tr("Sample rate mismatch"),
Chris@118 4300 tr("The sample rate of this audio file (%1 Hz) does not match\nthe current playback rate (%2 Hz).\n\nThe file will play at the wrong speed and pitch.")
Chris@0 4301 .arg(requested).arg(actual));
Chris@0 4302 }
Chris@0 4303
Chris@0 4304 updateDescriptionLabel();
Chris@0 4305 }
Chris@0 4306
Chris@0 4307 void
Chris@42 4308 MainWindow::audioOverloadPluginDisabled()
Chris@42 4309 {
Chris@42 4310 QMessageBox::information
Chris@42 4311 (this, tr("Audio processing overload"),
Chris@42 4312 tr("Audio effects plugin auditioning has been disabled\ndue to a processing overload."));
Chris@42 4313 }
Chris@42 4314
Chris@42 4315 void
Chris@137 4316 MainWindow::layerAdded(Layer *)
Chris@0 4317 {
Chris@0 4318 // std::cerr << "MainWindow::layerAdded(" << layer << ")" << std::endl;
Chris@0 4319 // setupExistingLayersMenu();
Chris@0 4320 updateMenuStates();
Chris@0 4321 }
Chris@0 4322
Chris@0 4323 void
Chris@137 4324 MainWindow::layerRemoved(Layer *)
Chris@0 4325 {
Chris@0 4326 // std::cerr << "MainWindow::layerRemoved(" << layer << ")" << std::endl;
Chris@95 4327 setupExistingLayersMenus();
Chris@0 4328 updateMenuStates();
Chris@0 4329 }
Chris@0 4330
Chris@0 4331 void
Chris@0 4332 MainWindow::layerAboutToBeDeleted(Layer *layer)
Chris@0 4333 {
Chris@0 4334 // std::cerr << "MainWindow::layerAboutToBeDeleted(" << layer << ")" << std::endl;
Chris@0 4335 if (layer == m_timeRulerLayer) {
Chris@0 4336 // std::cerr << "(this is the time ruler layer)" << std::endl;
Chris@0 4337 m_timeRulerLayer = 0;
Chris@0 4338 }
Chris@0 4339 }
Chris@0 4340
Chris@0 4341 void
Chris@0 4342 MainWindow::layerInAView(Layer *layer, bool inAView)
Chris@0 4343 {
Chris@0 4344 // std::cerr << "MainWindow::layerInAView(" << layer << "," << inAView << ")" << std::endl;
Chris@0 4345
Chris@0 4346 // Check whether we need to add or remove model from play source
Chris@0 4347 Model *model = layer->getModel();
Chris@0 4348 if (model) {
Chris@0 4349 if (inAView) {
Chris@0 4350 m_playSource->addModel(model);
Chris@0 4351 } else {
Chris@0 4352 bool found = false;
Chris@0 4353 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@0 4354 Pane *pane = m_paneStack->getPane(i);
Chris@0 4355 if (!pane) continue;
Chris@0 4356 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@0 4357 Layer *pl = pane->getLayer(j);
Chris@0 4358 if (pl && pl->getModel() == model) {
Chris@0 4359 found = true;
Chris@0 4360 break;
Chris@0 4361 }
Chris@0 4362 }
Chris@0 4363 if (found) break;
Chris@0 4364 }
Chris@0 4365 if (!found) m_playSource->removeModel(model);
Chris@0 4366 }
Chris@0 4367 }
Chris@0 4368
Chris@95 4369 setupExistingLayersMenus();
Chris@0 4370 updateMenuStates();
Chris@0 4371 }
Chris@0 4372
Chris@0 4373 void
Chris@0 4374 MainWindow::modelAdded(Model *model)
Chris@0 4375 {
Chris@0 4376 // std::cerr << "MainWindow::modelAdded(" << model << ")" << std::endl;
Chris@0 4377 m_playSource->addModel(model);
Chris@66 4378 if (dynamic_cast<DenseTimeValueModel *>(model)) {
Chris@66 4379 setupPaneAndLayerMenus();
Chris@66 4380 }
Chris@0 4381 }
Chris@0 4382
Chris@0 4383 void
Chris@0 4384 MainWindow::mainModelChanged(WaveFileModel *model)
Chris@0 4385 {
Chris@0 4386 // std::cerr << "MainWindow::mainModelChanged(" << model << ")" << std::endl;
Chris@0 4387 updateDescriptionLabel();
Chris@0 4388 m_panLayer->setModel(model);
Chris@0 4389 if (model) m_viewManager->setMainModelSampleRate(model->getSampleRate());
Chris@46 4390 if (model && !m_playTarget && m_audioOutput) createPlayTarget();
Chris@0 4391 }
Chris@0 4392
Chris@0 4393 void
Chris@0 4394 MainWindow::modelAboutToBeDeleted(Model *model)
Chris@0 4395 {
Chris@0 4396 // std::cerr << "MainWindow::modelAboutToBeDeleted(" << model << ")" << std::endl;
Chris@0 4397 m_playSource->removeModel(model);
Chris@91 4398 FFTDataServer::modelAboutToBeDeleted(model);
Chris@0 4399 }
Chris@0 4400
Chris@0 4401 void
Chris@0 4402 MainWindow::modelGenerationFailed(QString transformName)
Chris@0 4403 {
Chris@0 4404 QMessageBox::warning
Chris@0 4405 (this,
Chris@0 4406 tr("Failed to generate layer"),
Chris@34 4407 tr("Failed to generate a derived layer.\n\nThe layer transform \"%1\" failed.\n\nThis probably means that a plugin failed to initialise, perhaps because it\nrejected the processing block size that was requested.")
Chris@0 4408 .arg(transformName),
Chris@165 4409 QMessageBox::Ok);
Chris@0 4410 }
Chris@0 4411
Chris@0 4412 void
Chris@0 4413 MainWindow::modelRegenerationFailed(QString layerName, QString transformName)
Chris@0 4414 {
Chris@0 4415 QMessageBox::warning
Chris@0 4416 (this,
Chris@0 4417 tr("Failed to regenerate layer"),
Chris@34 4418 tr("Failed to regenerate derived layer \"%1\".\n\nThe layer transform \"%2\" failed to run.\n\nThis probably means the layer used a plugin that is not currently available.")
Chris@0 4419 .arg(layerName).arg(transformName),
Chris@165 4420 QMessageBox::Ok);
Chris@0 4421 }
Chris@0 4422
Chris@0 4423 void
Chris@0 4424 MainWindow::rightButtonMenuRequested(Pane *pane, QPoint position)
Chris@0 4425 {
Chris@0 4426 // std::cerr << "MainWindow::rightButtonMenuRequested(" << pane << ", " << position.x() << ", " << position.y() << ")" << std::endl;
Chris@0 4427 m_paneStack->setCurrentPane(pane);
Chris@0 4428 m_rightButtonMenu->popup(position);
Chris@0 4429 }
Chris@0 4430
Chris@0 4431 void
Chris@73 4432 MainWindow::propertyStacksResized()
Chris@73 4433 {
Chris@73 4434 /*
Chris@73 4435 std::cerr << "MainWindow::propertyStacksResized" << std::endl;
Chris@73 4436 Pane *pane = m_paneStack->getCurrentPane();
Chris@73 4437 if (pane && m_overview) {
Chris@73 4438 std::cerr << "Fixed width: " << pane->width() << std::endl;
Chris@73 4439 m_overview->setFixedWidth(pane->width());
Chris@73 4440 }
Chris@73 4441 */
Chris@73 4442 }
Chris@73 4443
Chris@73 4444 void
Chris@0 4445 MainWindow::showLayerTree()
Chris@0 4446 {
Chris@0 4447 QTreeView *view = new QTreeView();
Chris@0 4448 LayerTreeModel *tree = new LayerTreeModel(m_paneStack);
Chris@0 4449 view->setModel(tree);
Chris@155 4450 view->expandAll();
Chris@160 4451 view->resize(500, 300); //!!!
Chris@0 4452 view->show();
Chris@0 4453 }
Chris@0 4454
Chris@0 4455 void
Chris@69 4456 MainWindow::pollOSC()
Chris@69 4457 {
Chris@70 4458 if (!m_oscQueue || m_oscQueue->isEmpty()) return;
Chris@69 4459 std::cerr << "MainWindow::pollOSC: have " << m_oscQueue->getMessagesAvailable() << " messages" << std::endl;
Chris@69 4460
Chris@70 4461 if (m_openingAudioFile) return;
Chris@70 4462
Chris@69 4463 OSCMessage message = m_oscQueue->readMessage();
Chris@69 4464
Chris@69 4465 if (message.getTarget() != 0) {
Chris@69 4466 return; //!!! for now -- this class is target 0, others not handled yet
Chris@69 4467 }
Chris@69 4468
Chris@69 4469 handleOSCMessage(message);
Chris@69 4470 }
Chris@69 4471
Chris@69 4472 void
Chris@69 4473 MainWindow::handleOSCMessage(const OSCMessage &message)
Chris@69 4474 {
Chris@70 4475 std::cerr << "MainWindow::handleOSCMessage: thread id = "
Chris@70 4476 << QThread::currentThreadId() << std::endl;
Chris@70 4477
Chris@69 4478 // This large function should really be abstracted out.
Chris@69 4479
Chris@69 4480 if (message.getMethod() == "open") {
Chris@69 4481
Chris@69 4482 if (message.getArgCount() == 1 &&
Chris@69 4483 message.getArg(0).canConvert(QVariant::String)) {
Chris@69 4484 QString path = message.getArg(0).toString();
Chris@82 4485 if (openSomeFile(path, ReplaceMainModel) != FileOpenSucceeded) {
Chris@69 4486 std::cerr << "MainWindow::handleOSCMessage: File open failed for path \""
Chris@69 4487 << path.toStdString() << "\"" << std::endl;
Chris@69 4488 }
Chris@69 4489 //!!! we really need to spin here and not return until the
Chris@69 4490 // file has been completely decoded...
Chris@69 4491 }
Chris@69 4492
Chris@69 4493 } else if (message.getMethod() == "openadditional") {
Chris@69 4494
Chris@69 4495 if (message.getArgCount() == 1 &&
Chris@69 4496 message.getArg(0).canConvert(QVariant::String)) {
Chris@69 4497 QString path = message.getArg(0).toString();
Chris@82 4498 if (openSomeFile(path, CreateAdditionalModel) != FileOpenSucceeded) {
Chris@69 4499 std::cerr << "MainWindow::handleOSCMessage: File open failed for path \""
Chris@69 4500 << path.toStdString() << "\"" << std::endl;
Chris@69 4501 }
Chris@69 4502 }
Chris@69 4503
Chris@69 4504 } else if (message.getMethod() == "recent" ||
Chris@69 4505 message.getMethod() == "last") {
Chris@69 4506
Chris@69 4507 int n = 0;
Chris@69 4508 if (message.getMethod() == "recent" &&
Chris@69 4509 message.getArgCount() == 1 &&
Chris@69 4510 message.getArg(0).canConvert(QVariant::Int)) {
Chris@69 4511 n = message.getArg(0).toInt() - 1;
Chris@69 4512 }
Chris@69 4513 std::vector<QString> recent = m_recentFiles.getRecent();
Chris@137 4514 if (n >= 0 && n < int(recent.size())) {
Chris@82 4515 if (openSomeFile(recent[n], ReplaceMainModel) != FileOpenSucceeded) {
Chris@69 4516 std::cerr << "MainWindow::handleOSCMessage: File open failed for path \""
Chris@69 4517 << recent[n].toStdString() << "\"" << std::endl;
Chris@69 4518 }
Chris@69 4519 }
Chris@69 4520
Chris@69 4521 } else if (message.getMethod() == "save") {
Chris@69 4522
Chris@69 4523 QString path;
Chris@69 4524 if (message.getArgCount() == 1 &&
Chris@69 4525 message.getArg(0).canConvert(QVariant::String)) {
Chris@69 4526 path = message.getArg(0).toString();
Chris@69 4527 if (QFileInfo(path).exists()) {
Chris@69 4528 std::cerr << "MainWindow::handleOSCMessage: Refusing to overwrite existing file in save" << std::endl;
Chris@69 4529 } else {
Chris@69 4530 saveSessionFile(path);
Chris@69 4531 }
Chris@69 4532 }
Chris@69 4533
Chris@69 4534 } else if (message.getMethod() == "export") {
Chris@69 4535
Chris@69 4536 QString path;
Chris@69 4537 if (getMainModel()) {
Chris@69 4538 if (message.getArgCount() == 1 &&
Chris@69 4539 message.getArg(0).canConvert(QVariant::String)) {
Chris@69 4540 path = message.getArg(0).toString();
Chris@69 4541 if (QFileInfo(path).exists()) {
Chris@69 4542 std::cerr << "MainWindow::handleOSCMessage: Refusing to overwrite existing file in export" << std::endl;
Chris@69 4543 } else {
Chris@69 4544 WavFileWriter writer(path,
Chris@69 4545 getMainModel()->getSampleRate(),
Chris@69 4546 getMainModel()->getChannelCount());
Chris@69 4547 MultiSelection ms = m_viewManager->getSelection();
Chris@69 4548 if (!ms.getSelections().empty()) {
Chris@69 4549 writer.writeModel(getMainModel(), &ms);
Chris@69 4550 } else {
Chris@69 4551 writer.writeModel(getMainModel());
Chris@69 4552 }
Chris@69 4553 }
Chris@69 4554 }
Chris@69 4555 }
Chris@69 4556
Chris@69 4557 } else if (message.getMethod() == "jump" ||
Chris@69 4558 message.getMethod() == "play") {
Chris@69 4559
Chris@69 4560 if (getMainModel()) {
Chris@69 4561
Chris@69 4562 unsigned long frame = m_viewManager->getPlaybackFrame();
Chris@69 4563 bool selection = false;
Chris@69 4564 bool play = (message.getMethod() == "play");
Chris@69 4565
Chris@69 4566 if (message.getArgCount() == 1) {
Chris@69 4567
Chris@69 4568 if (message.getArg(0).canConvert(QVariant::String) &&
Chris@69 4569 message.getArg(0).toString() == "selection") {
Chris@69 4570
Chris@69 4571 selection = true;
Chris@69 4572
Chris@69 4573 } else if (message.getArg(0).canConvert(QVariant::String) &&
Chris@69 4574 message.getArg(0).toString() == "end") {
Chris@69 4575
Chris@69 4576 frame = getMainModel()->getEndFrame();
Chris@69 4577
Chris@69 4578 } else if (message.getArg(0).canConvert(QVariant::Double)) {
Chris@69 4579
Chris@69 4580 double time = message.getArg(0).toDouble();
Chris@69 4581 if (time < 0.0) time = 0.0;
Chris@69 4582
Chris@69 4583 frame = lrint(time * getMainModel()->getSampleRate());
Chris@69 4584 }
Chris@69 4585 }
Chris@69 4586
Chris@69 4587 if (frame > getMainModel()->getEndFrame()) {
Chris@69 4588 frame = getMainModel()->getEndFrame();
Chris@69 4589 }
Chris@69 4590
Chris@69 4591 if (play) {
Chris@69 4592 m_viewManager->setPlaySelectionMode(selection);
Chris@69 4593 }
Chris@69 4594
Chris@69 4595 if (selection) {
Chris@69 4596 MultiSelection::SelectionList sl = m_viewManager->getSelections();
Chris@69 4597 if (!sl.empty()) {
Chris@69 4598 frame = sl.begin()->getStartFrame();
Chris@69 4599 }
Chris@69 4600 }
Chris@69 4601
Chris@69 4602 m_viewManager->setPlaybackFrame(frame);
Chris@69 4603
Chris@69 4604 if (play && !m_playSource->isPlaying()) {
Chris@69 4605 m_playSource->play(frame);
Chris@69 4606 }
Chris@69 4607 }
Chris@69 4608
Chris@69 4609 } else if (message.getMethod() == "stop") {
Chris@69 4610
Chris@69 4611 if (m_playSource->isPlaying()) m_playSource->stop();
Chris@69 4612
Chris@69 4613 } else if (message.getMethod() == "loop") {
Chris@69 4614
Chris@69 4615 if (message.getArgCount() == 1 &&
Chris@69 4616 message.getArg(0).canConvert(QVariant::String)) {
Chris@69 4617
Chris@69 4618 QString str = message.getArg(0).toString();
Chris@69 4619 if (str == "on") {
Chris@69 4620 m_viewManager->setPlayLoopMode(true);
Chris@69 4621 } else if (str == "off") {
Chris@69 4622 m_viewManager->setPlayLoopMode(false);
Chris@69 4623 }
Chris@69 4624 }
Chris@69 4625
Chris@69 4626 } else if (message.getMethod() == "select" ||
Chris@69 4627 message.getMethod() == "addselect") {
Chris@69 4628
Chris@69 4629 if (getMainModel()) {
Chris@69 4630
Chris@73 4631 int f0 = getMainModel()->getStartFrame();
Chris@73 4632 int f1 = getMainModel()->getEndFrame();
Chris@69 4633
Chris@69 4634 bool done = false;
Chris@69 4635
Chris@69 4636 if (message.getArgCount() == 2 &&
Chris@69 4637 message.getArg(0).canConvert(QVariant::Double) &&
Chris@69 4638 message.getArg(1).canConvert(QVariant::Double)) {
Chris@69 4639
Chris@69 4640 double t0 = message.getArg(0).toDouble();
Chris@69 4641 double t1 = message.getArg(1).toDouble();
Chris@69 4642 if (t1 < t0) { double temp = t0; t0 = t1; t1 = temp; }
Chris@69 4643 if (t0 < 0.0) t0 = 0.0;
Chris@69 4644 if (t1 < 0.0) t1 = 0.0;
Chris@69 4645
Chris@69 4646 f0 = lrint(t0 * getMainModel()->getSampleRate());
Chris@69 4647 f1 = lrint(t1 * getMainModel()->getSampleRate());
Chris@73 4648
Chris@73 4649 Pane *pane = m_paneStack->getCurrentPane();
Chris@73 4650 Layer *layer = 0;
Chris@73 4651 if (pane) layer = pane->getSelectedLayer();
Chris@73 4652 if (layer) {
Chris@73 4653 size_t resolution;
Chris@73 4654 layer->snapToFeatureFrame(pane, f0, resolution,
Chris@73 4655 Layer::SnapLeft);
Chris@73 4656 layer->snapToFeatureFrame(pane, f1, resolution,
Chris@73 4657 Layer::SnapRight);
Chris@73 4658 }
Chris@69 4659
Chris@69 4660 } else if (message.getArgCount() == 1 &&
Chris@69 4661 message.getArg(0).canConvert(QVariant::String)) {
Chris@69 4662
Chris@69 4663 QString str = message.getArg(0).toString();
Chris@69 4664 if (str == "none") {
Chris@69 4665 m_viewManager->clearSelections();
Chris@69 4666 done = true;
Chris@69 4667 }
Chris@69 4668 }
Chris@69 4669
Chris@69 4670 if (!done) {
Chris@69 4671 if (message.getMethod() == "select") {
Chris@69 4672 m_viewManager->setSelection(Selection(f0, f1));
Chris@69 4673 } else {
Chris@69 4674 m_viewManager->addSelection(Selection(f0, f1));
Chris@69 4675 }
Chris@69 4676 }
Chris@69 4677 }
Chris@69 4678
Chris@69 4679 } else if (message.getMethod() == "add") {
Chris@69 4680
Chris@69 4681 if (getMainModel()) {
Chris@69 4682
Chris@69 4683 if (message.getArgCount() >= 1 &&
Chris@69 4684 message.getArg(0).canConvert(QVariant::String)) {
Chris@69 4685
Chris@69 4686 int channel = -1;
Chris@69 4687 if (message.getArgCount() == 2 &&
Chris@69 4688 message.getArg(0).canConvert(QVariant::Int)) {
Chris@69 4689 channel = message.getArg(0).toInt();
Chris@69 4690 if (channel < -1 ||
Chris@137 4691 channel > int(getMainModel()->getChannelCount())) {
Chris@69 4692 std::cerr << "WARNING: MainWindow::handleOSCMessage: channel "
Chris@69 4693 << channel << " out of range" << std::endl;
Chris@69 4694 channel = -1;
Chris@69 4695 }
Chris@69 4696 }
Chris@69 4697
Chris@69 4698 QString str = message.getArg(0).toString();
Chris@69 4699
Chris@69 4700 LayerFactory::LayerType type =
Chris@69 4701 LayerFactory::getInstance()->getLayerTypeForName(str);
Chris@69 4702
Chris@69 4703 if (type == LayerFactory::UnknownLayer) {
Chris@69 4704 std::cerr << "WARNING: MainWindow::handleOSCMessage: unknown layer "
Chris@69 4705 << "type " << str.toStdString() << std::endl;
Chris@69 4706 } else {
Chris@69 4707
Chris@69 4708 PaneConfiguration configuration(type,
Chris@69 4709 getMainModel(),
Chris@69 4710 channel);
Chris@69 4711
Chris@69 4712 addPane(configuration,
Chris@69 4713 tr("Add %1 Pane")
Chris@69 4714 .arg(LayerFactory::getInstance()->
Chris@69 4715 getLayerPresentationName(type)));
Chris@69 4716 }
Chris@69 4717 }
Chris@69 4718 }
Chris@69 4719
Chris@69 4720 } else if (message.getMethod() == "undo") {
Chris@69 4721
Chris@69 4722 CommandHistory::getInstance()->undo();
Chris@69 4723
Chris@69 4724 } else if (message.getMethod() == "redo") {
Chris@69 4725
Chris@69 4726 CommandHistory::getInstance()->redo();
Chris@69 4727
Chris@69 4728 } else if (message.getMethod() == "set") {
Chris@69 4729
Chris@70 4730 if (message.getArgCount() == 2 &&
Chris@69 4731 message.getArg(0).canConvert(QVariant::String) &&
Chris@69 4732 message.getArg(1).canConvert(QVariant::Double)) {
Chris@69 4733
Chris@69 4734 QString property = message.getArg(0).toString();
Chris@69 4735 float value = (float)message.getArg(1).toDouble();
Chris@69 4736
Chris@69 4737 if (property == "gain") {
Chris@69 4738 if (value < 0.0) value = 0.0;
Chris@69 4739 m_fader->setValue(value);
Chris@69 4740 if (m_playTarget) m_playTarget->setOutputGain(value);
Chris@69 4741 } else if (property == "speedup") {
Chris@69 4742 m_playSpeed->setMappedValue(value);
Chris@69 4743 } else if (property == "overlays") {
Chris@69 4744 if (value < 0.5) {
Chris@69 4745 m_viewManager->setOverlayMode(ViewManager::NoOverlays);
Chris@69 4746 } else if (value < 1.5) {
Chris@90 4747 m_viewManager->setOverlayMode(ViewManager::MinimalOverlays);
Chris@90 4748 } else if (value < 2.5) {
Chris@90 4749 m_viewManager->setOverlayMode(ViewManager::StandardOverlays);
Chris@69 4750 } else {
Chris@69 4751 m_viewManager->setOverlayMode(ViewManager::AllOverlays);
Chris@69 4752 }
Chris@70 4753 } else if (property == "zoomwheels") {
Chris@70 4754 m_viewManager->setZoomWheelsEnabled(value > 0.5);
Chris@72 4755 } else if (property == "propertyboxes") {
Chris@72 4756 bool toggle = ((value < 0.5) !=
Chris@72 4757 (m_paneStack->getLayoutStyle() == PaneStack::NoPropertyStacks));
Chris@72 4758 if (toggle) togglePropertyBoxes();
Chris@70 4759 }
Chris@70 4760
Chris@70 4761 } else {
Chris@70 4762 PropertyContainer *container = 0;
Chris@70 4763 Pane *pane = m_paneStack->getCurrentPane();
Chris@70 4764 if (pane &&
Chris@70 4765 message.getArgCount() == 3 &&
Chris@70 4766 message.getArg(0).canConvert(QVariant::String) &&
Chris@70 4767 message.getArg(1).canConvert(QVariant::String) &&
Chris@70 4768 message.getArg(2).canConvert(QVariant::String)) {
Chris@70 4769 if (message.getArg(0).toString() == "pane") {
Chris@70 4770 container = pane->getPropertyContainer(0);
Chris@70 4771 } else if (message.getArg(0).toString() == "layer") {
Chris@70 4772 container = pane->getSelectedLayer();
Chris@70 4773 }
Chris@70 4774 }
Chris@70 4775 if (container) {
Chris@70 4776 QString nameString = message.getArg(1).toString();
Chris@70 4777 QString valueString = message.getArg(2).toString();
Chris@70 4778 container->setPropertyWithCommand(nameString, valueString);
Chris@69 4779 }
Chris@69 4780 }
Chris@69 4781
Chris@69 4782 } else if (message.getMethod() == "setcurrent") {
Chris@69 4783
Chris@69 4784 int paneIndex = -1, layerIndex = -1;
Chris@69 4785 bool wantLayer = false;
Chris@69 4786
Chris@69 4787 if (message.getArgCount() >= 1 &&
Chris@69 4788 message.getArg(0).canConvert(QVariant::Int)) {
Chris@69 4789
Chris@69 4790 paneIndex = message.getArg(0).toInt() - 1;
Chris@69 4791
Chris@69 4792 if (message.getArgCount() >= 2 &&
Chris@69 4793 message.getArg(1).canConvert(QVariant::Int)) {
Chris@69 4794 wantLayer = true;
Chris@69 4795 layerIndex = message.getArg(1).toInt() - 1;
Chris@69 4796 }
Chris@69 4797 }
Chris@69 4798
Chris@69 4799 if (paneIndex >= 0 && paneIndex < m_paneStack->getPaneCount()) {
Chris@69 4800 Pane *pane = m_paneStack->getPane(paneIndex);
Chris@70 4801 m_paneStack->setCurrentPane(pane);
Chris@69 4802 if (layerIndex >= 0 && layerIndex < pane->getLayerCount()) {
Chris@69 4803 Layer *layer = pane->getLayer(layerIndex);
Chris@69 4804 m_paneStack->setCurrentLayer(pane, layer);
Chris@69 4805 } else if (wantLayer && layerIndex == -1) {
Chris@69 4806 m_paneStack->setCurrentLayer(pane, 0);
Chris@69 4807 }
Chris@69 4808 }
Chris@69 4809
Chris@69 4810 } else if (message.getMethod() == "delete") {
Chris@69 4811
Chris@69 4812 if (message.getArgCount() == 1 &&
Chris@69 4813 message.getArg(0).canConvert(QVariant::String)) {
Chris@69 4814
Chris@69 4815 QString target = message.getArg(0).toString();
Chris@69 4816
Chris@69 4817 if (target == "pane") {
Chris@69 4818
Chris@69 4819 deleteCurrentPane();
Chris@69 4820
Chris@69 4821 } else if (target == "layer") {
Chris@69 4822
Chris@69 4823 deleteCurrentLayer();
Chris@69 4824
Chris@69 4825 } else {
Chris@69 4826
Chris@69 4827 std::cerr << "WARNING: MainWindow::handleOSCMessage: Unknown delete target " << target.toStdString() << std::endl;
Chris@69 4828 }
Chris@69 4829 }
Chris@69 4830
Chris@69 4831 } else if (message.getMethod() == "zoom") {
Chris@69 4832
Chris@69 4833 if (message.getArgCount() == 1) {
Chris@69 4834 if (message.getArg(0).canConvert(QVariant::String) &&
Chris@69 4835 message.getArg(0).toString() == "in") {
Chris@69 4836 zoomIn();
Chris@69 4837 } else if (message.getArg(0).canConvert(QVariant::String) &&
Chris@69 4838 message.getArg(0).toString() == "out") {
Chris@69 4839 zoomOut();
Chris@69 4840 } else if (message.getArg(0).canConvert(QVariant::String) &&
Chris@69 4841 message.getArg(0).toString() == "default") {
Chris@69 4842 zoomDefault();
Chris@69 4843 } else if (message.getArg(0).canConvert(QVariant::Double)) {
Chris@69 4844 double level = message.getArg(0).toDouble();
Chris@69 4845 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@69 4846 if (level < 1.0) level = 1.0;
Chris@69 4847 if (currentPane) currentPane->setZoomLevel(lrint(level));
Chris@69 4848 }
Chris@69 4849 }
Chris@69 4850
Chris@73 4851 } else if (message.getMethod() == "zoomvertical") {
Chris@73 4852
Chris@73 4853 Pane *pane = m_paneStack->getCurrentPane();
Chris@73 4854 Layer *layer = 0;
Chris@73 4855 if (pane && pane->getLayerCount() > 0) {
Chris@73 4856 layer = pane->getLayer(pane->getLayerCount() - 1);
Chris@73 4857 }
Chris@73 4858 int defaultStep = 0;
Chris@73 4859 int steps = 0;
Chris@73 4860 if (layer) {
Chris@73 4861 steps = layer->getVerticalZoomSteps(defaultStep);
Chris@73 4862 if (message.getArgCount() == 1 && steps > 0) {
Chris@73 4863 if (message.getArg(0).canConvert(QVariant::String) &&
Chris@73 4864 message.getArg(0).toString() == "in") {
Chris@73 4865 int step = layer->getCurrentVerticalZoomStep() + 1;
Chris@73 4866 if (step < steps) layer->setVerticalZoomStep(step);
Chris@73 4867 } else if (message.getArg(0).canConvert(QVariant::String) &&
Chris@73 4868 message.getArg(0).toString() == "out") {
Chris@73 4869 int step = layer->getCurrentVerticalZoomStep() - 1;
Chris@73 4870 if (step >= 0) layer->setVerticalZoomStep(step);
Chris@73 4871 } else if (message.getArg(0).canConvert(QVariant::String) &&
Chris@73 4872 message.getArg(0).toString() == "default") {
Chris@73 4873 layer->setVerticalZoomStep(defaultStep);
Chris@73 4874 }
Chris@73 4875 } else if (message.getArgCount() == 2) {
Chris@73 4876 if (message.getArg(0).canConvert(QVariant::Double) &&
Chris@73 4877 message.getArg(1).canConvert(QVariant::Double)) {
Chris@73 4878 double min = message.getArg(0).toDouble();
Chris@73 4879 double max = message.getArg(1).toDouble();
Chris@73 4880 layer->setDisplayExtents(min, max);
Chris@73 4881 }
Chris@73 4882 }
Chris@73 4883 }
Chris@73 4884
Chris@70 4885 } else if (message.getMethod() == "quit") {
Chris@70 4886
Chris@70 4887 m_abandoning = true;
Chris@70 4888 close();
Chris@70 4889
Chris@70 4890 } else if (message.getMethod() == "resize") {
Chris@70 4891
Chris@70 4892 if (message.getArgCount() == 2) {
Chris@70 4893
Chris@70 4894 int width = 0, height = 0;
Chris@70 4895
Chris@70 4896 if (message.getArg(1).canConvert(QVariant::Int)) {
Chris@70 4897
Chris@70 4898 height = message.getArg(1).toInt();
Chris@70 4899
Chris@70 4900 if (message.getArg(0).canConvert(QVariant::String) &&
Chris@70 4901 message.getArg(0).toString() == "pane") {
Chris@70 4902
Chris@70 4903 Pane *pane = m_paneStack->getCurrentPane();
Chris@70 4904 if (pane) pane->resize(pane->width(), height);
Chris@70 4905
Chris@70 4906 } else if (message.getArg(0).canConvert(QVariant::Int)) {
Chris@70 4907
Chris@70 4908 width = message.getArg(0).toInt();
Chris@70 4909 resize(width, height);
Chris@70 4910 }
Chris@70 4911 }
Chris@70 4912 }
Chris@70 4913
Chris@70 4914 } else if (message.getMethod() == "transform") {
Chris@70 4915
Chris@70 4916 Pane *pane = m_paneStack->getCurrentPane();
Chris@70 4917
Chris@70 4918 if (getMainModel() &&
Chris@70 4919 pane &&
Chris@70 4920 message.getArgCount() == 1 &&
Chris@70 4921 message.getArg(0).canConvert(QVariant::String)) {
Chris@70 4922
Chris@107 4923 TransformId transform = message.getArg(0).toString();
Chris@70 4924
Chris@70 4925 Layer *newLayer = m_document->createDerivedLayer
Chris@70 4926 (transform,
Chris@70 4927 getMainModel(),
Chris@73 4928 TransformFactory::getInstance()->getDefaultContextForTransform
Chris@73 4929 (transform, getMainModel()),
Chris@70 4930 "");
Chris@70 4931
Chris@70 4932 if (newLayer) {
Chris@70 4933 m_document->addLayerToView(pane, newLayer);
Chris@70 4934 m_recentTransforms.add(transform);
Chris@70 4935 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@70 4936 }
Chris@70 4937 }
Chris@70 4938
Chris@69 4939 } else {
Chris@69 4940 std::cerr << "WARNING: MainWindow::handleOSCMessage: Unknown or unsupported "
Chris@69 4941 << "method \"" << message.getMethod().toStdString()
Chris@69 4942 << "\"" << std::endl;
Chris@69 4943 }
Chris@69 4944
Chris@69 4945 }
Chris@69 4946
Chris@69 4947 void
Chris@0 4948 MainWindow::preferences()
Chris@0 4949 {
Chris@0 4950 if (!m_preferencesDialog.isNull()) {
Chris@0 4951 m_preferencesDialog->show();
Chris@0 4952 m_preferencesDialog->raise();
Chris@0 4953 return;
Chris@0 4954 }
Chris@0 4955
Chris@0 4956 m_preferencesDialog = new PreferencesDialog(this);
Chris@0 4957
Chris@0 4958 // DeleteOnClose is safe here, because m_preferencesDialog is a
Chris@0 4959 // QPointer that will be zeroed when the dialog is deleted. We
Chris@0 4960 // use it in preference to leaving the dialog lying around because
Chris@0 4961 // if you Cancel the dialog, it resets the preferences state
Chris@0 4962 // without resetting its own widgets, so its state will be
Chris@0 4963 // incorrect when next shown unless we construct it afresh
Chris@0 4964 m_preferencesDialog->setAttribute(Qt::WA_DeleteOnClose);
Chris@0 4965
Chris@0 4966 m_preferencesDialog->show();
Chris@0 4967 }
Chris@0 4968
Chris@0 4969 void
Chris@90 4970 MainWindow::mouseEnteredWidget()
Chris@90 4971 {
Chris@90 4972 QWidget *w = dynamic_cast<QWidget *>(sender());
Chris@90 4973 if (!w) return;
Chris@90 4974
Chris@90 4975 if (w == m_fader) {
Chris@116 4976 contextHelpChanged(tr("Adjust the master playback level"));
Chris@90 4977 } else if (w == m_playSpeed) {
Chris@116 4978 contextHelpChanged(tr("Adjust the master playback speed"));
Chris@90 4979 } else if (w == m_playSharpen && w->isEnabled()) {
Chris@116 4980 contextHelpChanged(tr("Toggle transient sharpening for playback time scaling"));
Chris@90 4981 } else if (w == m_playMono && w->isEnabled()) {
Chris@116 4982 contextHelpChanged(tr("Toggle mono mode for playback time scaling"));
Chris@90 4983 }
Chris@90 4984 }
Chris@90 4985
Chris@90 4986 void
Chris@90 4987 MainWindow::mouseLeftWidget()
Chris@90 4988 {
Chris@116 4989 contextHelpChanged("");
Chris@116 4990 }
Chris@116 4991
Chris@116 4992 void
Chris@117 4993 MainWindow::inProgressSelectionChanged()
Chris@117 4994 {
Chris@117 4995 Pane *currentPane = 0;
Chris@117 4996 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
Chris@117 4997 if (currentPane) updateVisibleRangeDisplay(currentPane);
Chris@117 4998 }
Chris@117 4999
Chris@117 5000 void
Chris@116 5001 MainWindow::contextHelpChanged(const QString &s)
Chris@116 5002 {
Chris@116 5003 if (s == "" && m_myStatusMessage != "") {
Chris@116 5004 statusBar()->showMessage(m_myStatusMessage);
Chris@116 5005 return;
Chris@116 5006 }
Chris@116 5007 statusBar()->showMessage(s);
Chris@90 5008 }
Chris@90 5009
Chris@90 5010 void
Chris@0 5011 MainWindow::website()
Chris@0 5012 {
Chris@0 5013 openHelpUrl(tr("http://www.sonicvisualiser.org/"));
Chris@0 5014 }
Chris@0 5015
Chris@0 5016 void
Chris@0 5017 MainWindow::help()
Chris@0 5018 {
Chris@126 5019 openHelpUrl(tr("http://www.sonicvisualiser.org/doc/reference/1.0/en/"));
Chris@0 5020 }
Chris@0 5021
Chris@0 5022 void
Chris@0 5023 MainWindow::openHelpUrl(QString url)
Chris@0 5024 {
Chris@0 5025 // This method mostly lifted from Qt Assistant source code
Chris@0 5026
Chris@0 5027 QProcess *process = new QProcess(this);
Chris@0 5028 connect(process, SIGNAL(finished(int)), process, SLOT(deleteLater()));
Chris@0 5029
Chris@0 5030 QStringList args;
Chris@0 5031
Chris@0 5032 #ifdef Q_OS_MAC
Chris@0 5033 args.append(url);
Chris@0 5034 process->start("open", args);
Chris@0 5035 #else
Chris@0 5036 #ifdef Q_OS_WIN32
Chris@0 5037
Chris@0 5038 QString pf(getenv("ProgramFiles"));
Chris@0 5039 QString command = pf + QString("\\Internet Explorer\\IEXPLORE.EXE");
Chris@0 5040
Chris@0 5041 args.append(url);
Chris@0 5042 process->start(command, args);
Chris@0 5043
Chris@0 5044 #else
Chris@0 5045 #ifdef Q_WS_X11
Chris@0 5046 if (!qgetenv("KDE_FULL_SESSION").isEmpty()) {
Chris@0 5047 args.append("exec");
Chris@0 5048 args.append(url);
Chris@0 5049 process->start("kfmclient", args);
Chris@0 5050 } else if (!qgetenv("BROWSER").isEmpty()) {
Chris@0 5051 args.append(url);
Chris@0 5052 process->start(qgetenv("BROWSER"), args);
Chris@0 5053 } else {
Chris@0 5054 args.append(url);
Chris@0 5055 process->start("firefox", args);
Chris@0 5056 }
Chris@0 5057 #endif
Chris@0 5058 #endif
Chris@0 5059 #endif
Chris@0 5060 }
Chris@0 5061
Chris@0 5062 void
Chris@0 5063 MainWindow::about()
Chris@0 5064 {
Chris@0 5065 bool debug = false;
Chris@0 5066 QString version = "(unknown version)";
Chris@0 5067
Chris@0 5068 #ifdef BUILD_DEBUG
Chris@0 5069 debug = true;
Chris@0 5070 #endif
Chris@0 5071 #ifdef SV_VERSION
Chris@0 5072 #ifdef SVNREV
Chris@0 5073 version = tr("Release %1 : Revision %2").arg(SV_VERSION).arg(SVNREV);
Chris@0 5074 #else
Chris@0 5075 version = tr("Release %1").arg(SV_VERSION);
Chris@0 5076 #endif
Chris@0 5077 #else
Chris@0 5078 #ifdef SVNREV
Chris@0 5079 version = tr("Unreleased : Revision %1").arg(SVNREV);
Chris@0 5080 #endif
Chris@0 5081 #endif
Chris@0 5082
Chris@0 5083 QString aboutText;
Chris@0 5084
Chris@0 5085 aboutText += tr("<h3>About Sonic Visualiser</h3>");
Chris@90 5086 aboutText += tr("<p>Sonic Visualiser is a program for viewing and exploring audio data for<br>semantic music analysis and annotation.</p>");
Chris@111 5087 aboutText += tr("<p>%1 : %2 configuration</p>")
Chris@0 5088 .arg(version)
Chris@0 5089 .arg(debug ? tr("Debug") : tr("Release"));
Chris@0 5090
Chris@132 5091 #ifndef BUILD_STATIC
Chris@132 5092 aboutText += tr("<br>Using Qt v%1 &copy; Trolltech AS").arg(QT_VERSION_STR);
Chris@132 5093 #else
Chris@132 5094 #ifdef QT_SHARED
Chris@132 5095 aboutText += tr("<br>Using Qt v%1 &copy; Trolltech AS").arg(QT_VERSION_STR);
Chris@132 5096 #endif
Chris@132 5097 #endif
Chris@132 5098
Chris@0 5099 #ifdef BUILD_STATIC
Chris@0 5100 aboutText += tr("<p>Statically linked");
Chris@0 5101 #ifndef QT_SHARED
Chris@0 5102 aboutText += tr("<br>With Qt (v%1) &copy; Trolltech AS").arg(QT_VERSION_STR);
Chris@0 5103 #endif
Chris@0 5104 #ifdef HAVE_JACK
Chris@93 5105 #ifdef JACK_VERSION
Chris@0 5106 aboutText += tr("<br>With JACK audio output (v%1) &copy; Paul Davis and Jack O'Quin").arg(JACK_VERSION);
Chris@93 5107 #else
Chris@93 5108 aboutText += tr("<br>With JACK audio output &copy; Paul Davis and Jack O'Quin");
Chris@93 5109 #endif
Chris@0 5110 #endif
Chris@0 5111 #ifdef HAVE_PORTAUDIO
Chris@0 5112 aboutText += tr("<br>With PortAudio audio output &copy; Ross Bencina and Phil Burk");
Chris@0 5113 #endif
Chris@0 5114 #ifdef HAVE_OGGZ
Chris@93 5115 #ifdef OGGZ_VERSION
Chris@0 5116 aboutText += tr("<br>With Ogg file decoder (oggz v%1, fishsound v%2) &copy; CSIRO Australia").arg(OGGZ_VERSION).arg(FISHSOUND_VERSION);
Chris@93 5117 #else
Chris@93 5118 aboutText += tr("<br>With Ogg file decoder &copy; CSIRO Australia");
Chris@93 5119 #endif
Chris@0 5120 #endif
Chris@0 5121 #ifdef HAVE_MAD
Chris@93 5122 #ifdef MAD_VERSION
Chris@0 5123 aboutText += tr("<br>With MAD mp3 decoder (v%1) &copy; Underbit Technologies Inc").arg(MAD_VERSION);
Chris@93 5124 #else
Chris@93 5125 aboutText += tr("<br>With MAD mp3 decoder &copy; Underbit Technologies Inc");
Chris@93 5126 #endif
Chris@0 5127 #endif
Chris@0 5128 #ifdef HAVE_SAMPLERATE
Chris@93 5129 #ifdef SAMPLERATE_VERSION
Chris@0 5130 aboutText += tr("<br>With libsamplerate (v%1) &copy; Erik de Castro Lopo").arg(SAMPLERATE_VERSION);
Chris@93 5131 #else
Chris@93 5132 aboutText += tr("<br>With libsamplerate &copy; Erik de Castro Lopo");
Chris@93 5133 #endif
Chris@0 5134 #endif
Chris@0 5135 #ifdef HAVE_SNDFILE
Chris@93 5136 #ifdef SNDFILE_VERSION
Chris@0 5137 aboutText += tr("<br>With libsndfile (v%1) &copy; Erik de Castro Lopo").arg(SNDFILE_VERSION);
Chris@93 5138 #else
Chris@93 5139 aboutText += tr("<br>With libsndfile &copy; Erik de Castro Lopo");
Chris@93 5140 #endif
Chris@0 5141 #endif
Chris@127 5142 #ifdef HAVE_FFTW3F
Chris@93 5143 #ifdef FFTW3_VERSION
Chris@0 5144 aboutText += tr("<br>With FFTW3 (v%1) &copy; Matteo Frigo and MIT").arg(FFTW3_VERSION);
Chris@93 5145 #else
Chris@93 5146 aboutText += tr("<br>With FFTW3 &copy; Matteo Frigo and MIT");
Chris@93 5147 #endif
Chris@0 5148 #endif
Chris@0 5149 #ifdef HAVE_VAMP
Chris@114 5150 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@0 5151 #endif
Chris@0 5152 aboutText += tr("<br>With LADSPA plugin support (API v%1) &copy; Richard Furse, Paul Davis, Stefan Westerfeld").arg(LADSPA_VERSION);
Chris@0 5153 aboutText += tr("<br>With DSSI plugin support (API v%1) &copy; Chris Cannam, Steve Harris, Sean Bolton").arg(DSSI_VERSION);
Chris@69 5154 #ifdef HAVE_LIBLO
Chris@93 5155 #ifdef LIBLO_VERSION
Chris@69 5156 aboutText += tr("<br>With liblo Lite OSC library (v%1) &copy; Steve Harris").arg(LIBLO_VERSION);
Chris@93 5157 #else
Chris@93 5158 aboutText += tr("<br>With liblo Lite OSC library &copy; Steve Harris").arg(LIBLO_VERSION);
Chris@93 5159 #endif
Chris@70 5160 if (m_oscQueue && m_oscQueue->isOK()) {
Chris@69 5161 aboutText += tr("<p>The OSC URL for this instance is: \"%1\"").arg(m_oscQueue->getOSCURL());
Chris@69 5162 }
Chris@69 5163 #endif
Chris@0 5164 aboutText += "</p>";
Chris@0 5165 #endif
Chris@0 5166
Chris@0 5167 aboutText +=
Chris@90 5168 "<p>Sonic Visualiser Copyright &copy; 2005 - 2007 Chris Cannam and<br>"
Chris@90 5169 "Queen Mary, University of London.</p>"
Chris@0 5170 "<p>This program is free software; you can redistribute it and/or<br>"
Chris@0 5171 "modify it under the terms of the GNU General Public License as<br>"
Chris@0 5172 "published by the Free Software Foundation; either version 2 of the<br>"
Chris@0 5173 "License, or (at your option) any later version.<br>See the file "
Chris@0 5174 "COPYING included with this distribution for more information.</p>";
Chris@0 5175
Chris@0 5176 QMessageBox::about(this, tr("About Sonic Visualiser"), aboutText);
Chris@0 5177 }
Chris@0 5178
Chris@162 5179 void
Chris@162 5180 MainWindow::keyReference()
Chris@162 5181 {
Chris@162 5182 m_keyReference->show();
Chris@162 5183 }
Chris@162 5184