annotate main/MainWindow.cpp @ 185:f3191ab6d564

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