annotate main/MainWindow.cpp @ 144:56c00f977cac

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