annotate main/MainWindow.cpp @ 153:d2cc3b10e26f

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