annotate main/MainWindow.cpp @ 85:4eae5b521a34

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