annotate main/MainWindow.cpp @ 190:89a41f3d24d1

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