annotate main/MainWindow.cpp @ 161:39dda80acb10

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