annotate main/MainWindow.cpp @ 192:d3477f673fb4

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