annotate main/MainWindow.cpp @ 166:4d762fe10919

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