annotate main/MainWindow.cpp @ 59:1016a8ceceda

* Introduce PlaySpeedRangeMapper for playback speed dial
author Chris Cannam
date Tue, 17 Oct 2006 11:42:14 +0000
parents ca1e3f5657d5
children 06b3c3f437e6
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@0 7 This file copyright 2006 Chris Cannam.
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@1 34 #include "view/Panner.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@1 50 #include "base/RecentFiles.h"
Chris@0 51 #include "transform/TransformFactory.h"
Chris@0 52 #include "base/PlayParameterRepository.h"
Chris@0 53 #include "base/XmlExportable.h"
Chris@0 54 #include "base/CommandHistory.h"
Chris@0 55 #include "base/Profiler.h"
Chris@0 56 #include "base/Clipboard.h"
Chris@0 57
Chris@0 58 // For version information
Chris@0 59 #include "vamp/vamp.h"
Chris@0 60 #include "vamp-sdk/PluginBase.h"
Chris@0 61 #include "plugin/api/ladspa.h"
Chris@0 62 #include "plugin/api/dssi.h"
Chris@0 63
Chris@0 64 #include <QApplication>
Chris@0 65 #include <QPushButton>
Chris@0 66 #include <QFileDialog>
Chris@0 67 #include <QMessageBox>
Chris@0 68 #include <QGridLayout>
Chris@0 69 #include <QLabel>
Chris@0 70 #include <QAction>
Chris@0 71 #include <QMenuBar>
Chris@0 72 #include <QToolBar>
Chris@0 73 #include <QInputDialog>
Chris@0 74 #include <QStatusBar>
Chris@0 75 #include <QTreeView>
Chris@0 76 #include <QFile>
Chris@0 77 #include <QTextStream>
Chris@0 78 #include <QProcess>
Chris@7 79 #include <QShortcut>
Chris@5 80 #include <QSettings>
Chris@11 81 #include <QDateTime>
Chris@11 82 #include <QProcess>
Chris@16 83 #include <QCheckBox>
Chris@55 84 #include <QRegExp>
Chris@0 85
Chris@0 86 #include <iostream>
Chris@0 87 #include <cstdio>
Chris@0 88 #include <errno.h>
Chris@0 89
Chris@0 90 using std::cerr;
Chris@0 91 using std::endl;
Chris@0 92
Chris@33 93 using std::vector;
Chris@33 94 using std::map;
Chris@33 95 using std::set;
Chris@33 96
Chris@0 97
Chris@46 98 MainWindow::MainWindow(bool withAudioOutput) :
Chris@0 99 m_document(0),
Chris@0 100 m_paneStack(0),
Chris@0 101 m_viewManager(0),
Chris@0 102 m_panner(0),
Chris@0 103 m_timeRulerLayer(0),
Chris@46 104 m_audioOutput(withAudioOutput),
Chris@0 105 m_playSource(0),
Chris@0 106 m_playTarget(0),
Chris@34 107 m_recentFiles("RecentFiles"),
Chris@49 108 m_recentTransforms("RecentTransforms", 20),
Chris@0 109 m_mainMenusCreated(false),
Chris@0 110 m_paneMenu(0),
Chris@0 111 m_layerMenu(0),
Chris@34 112 m_transformsMenu(0),
Chris@0 113 m_existingLayersMenu(0),
Chris@34 114 m_recentFilesMenu(0),
Chris@34 115 m_recentTransformsMenu(0),
Chris@0 116 m_rightButtonMenu(0),
Chris@0 117 m_rightButtonLayerMenu(0),
Chris@34 118 m_rightButtonTransformsMenu(0),
Chris@0 119 m_documentModified(false),
Chris@0 120 m_preferencesDialog(0)
Chris@0 121 {
Chris@0 122 setWindowTitle(tr("Sonic Visualiser"));
Chris@0 123
Chris@0 124 UnitDatabase::getInstance()->registerUnit("Hz");
Chris@0 125 UnitDatabase::getInstance()->registerUnit("dB");
Chris@0 126
Chris@0 127 connect(CommandHistory::getInstance(), SIGNAL(commandExecuted()),
Chris@0 128 this, SLOT(documentModified()));
Chris@0 129 connect(CommandHistory::getInstance(), SIGNAL(documentRestored()),
Chris@0 130 this, SLOT(documentRestored()));
Chris@0 131
Chris@0 132 QFrame *frame = new QFrame;
Chris@0 133 setCentralWidget(frame);
Chris@0 134
Chris@0 135 QGridLayout *layout = new QGridLayout;
Chris@0 136
Chris@0 137 m_viewManager = new ViewManager();
Chris@0 138 connect(m_viewManager, SIGNAL(selectionChanged()),
Chris@0 139 this, SLOT(updateMenuStates()));
Chris@0 140
Chris@0 141 m_descriptionLabel = new QLabel;
Chris@0 142
Chris@0 143 m_paneStack = new PaneStack(frame, m_viewManager);
Chris@0 144 connect(m_paneStack, SIGNAL(currentPaneChanged(Pane *)),
Chris@0 145 this, SLOT(currentPaneChanged(Pane *)));
Chris@0 146 connect(m_paneStack, SIGNAL(currentLayerChanged(Pane *, Layer *)),
Chris@0 147 this, SLOT(currentLayerChanged(Pane *, Layer *)));
Chris@0 148 connect(m_paneStack, SIGNAL(rightButtonMenuRequested(Pane *, QPoint)),
Chris@0 149 this, SLOT(rightButtonMenuRequested(Pane *, QPoint)));
Chris@0 150
Chris@0 151 m_panner = new Panner(frame);
Chris@0 152 m_panner->setViewManager(m_viewManager);
Chris@0 153 m_panner->setFixedHeight(40);
Chris@0 154
Chris@0 155 m_panLayer = new WaveformLayer;
Chris@0 156 m_panLayer->setChannelMode(WaveformLayer::MergeChannels);
Chris@0 157 // m_panLayer->setScale(WaveformLayer::MeterScale);
Chris@39 158 // m_panLayer->setAutoNormalize(true);
Chris@0 159 m_panLayer->setBaseColour(Qt::darkGreen);
Chris@0 160 m_panLayer->setAggressiveCacheing(true);
Chris@0 161 m_panner->addLayer(m_panLayer);
Chris@0 162
Chris@0 163 m_playSource = new AudioCallbackPlaySource(m_viewManager);
Chris@0 164
Chris@0 165 connect(m_playSource, SIGNAL(sampleRateMismatch(size_t, size_t, bool)),
Chris@0 166 this, SLOT(sampleRateMismatch(size_t, size_t, bool)));
Chris@42 167 connect(m_playSource, SIGNAL(audioOverloadPluginDisabled()),
Chris@42 168 this, SLOT(audioOverloadPluginDisabled()));
Chris@0 169
Chris@0 170 m_fader = new Fader(frame, false);
Chris@0 171
Chris@0 172 m_playSpeed = new AudioDial(frame);
Chris@12 173 m_playSpeed->setMinimum(0);
Chris@48 174 m_playSpeed->setMaximum(200);
Chris@25 175 m_playSpeed->setValue(100);
Chris@0 176 m_playSpeed->setFixedWidth(24);
Chris@0 177 m_playSpeed->setFixedHeight(24);
Chris@0 178 m_playSpeed->setNotchesVisible(true);
Chris@25 179 m_playSpeed->setPageStep(10);
Chris@25 180 m_playSpeed->setToolTip(tr("Playback speed: +0%"));
Chris@59 181 m_playSpeed->setObjectName(tr("Playback Speed"));
Chris@25 182 m_playSpeed->setDefaultValue(100);
Chris@59 183 m_playSpeed->setRangeMapper(new PlaySpeedRangeMapper(0, 200));
Chris@0 184 connect(m_playSpeed, SIGNAL(valueChanged(int)),
Chris@0 185 this, SLOT(playSpeedChanged(int)));
Chris@0 186
Chris@26 187 m_playSharpen = new QPushButton(frame);
Chris@17 188 m_playSharpen->setToolTip(tr("Sharpen percussive transients"));
Chris@26 189 m_playSharpen->setFixedSize(20, 20);
Chris@26 190 // m_playSharpen->setFlat(true);
Chris@16 191 m_playSharpen->setEnabled(false);
Chris@26 192 m_playSharpen->setCheckable(true);
Chris@26 193 m_playSharpen->setChecked(false);
Chris@26 194 m_playSharpen->setIcon(QIcon(":icons/sharpen.png"));
Chris@26 195 connect(m_playSharpen, SIGNAL(clicked()), this, SLOT(playSharpenToggled()));
Chris@26 196
Chris@26 197 m_playMono = new QPushButton(frame);
Chris@26 198 m_playMono->setToolTip(tr("Run time stretcher in mono only"));
Chris@26 199 m_playMono->setFixedSize(20, 20);
Chris@26 200 // m_playMono->setFlat(true);
Chris@26 201 m_playMono->setEnabled(false);
Chris@26 202 m_playMono->setCheckable(true);
Chris@26 203 m_playMono->setChecked(false);
Chris@26 204 m_playMono->setIcon(QIcon(":icons/mono.png"));
Chris@26 205 connect(m_playMono, SIGNAL(clicked()), this, SLOT(playMonoToggled()));
Chris@21 206
Chris@21 207 QSettings settings;
Chris@21 208 settings.beginGroup("MainWindow");
Chris@24 209 m_playSharpen->setChecked(settings.value("playsharpen", true).toBool());
Chris@26 210 m_playMono->setChecked(settings.value("playmono", false).toBool());
Chris@21 211 settings.endGroup();
Chris@21 212
Chris@26 213 layout->addWidget(m_paneStack, 0, 0, 1, 5);
Chris@0 214 layout->addWidget(m_panner, 1, 0);
Chris@0 215 layout->addWidget(m_fader, 1, 1);
Chris@0 216 layout->addWidget(m_playSpeed, 1, 2);
Chris@16 217 layout->addWidget(m_playSharpen, 1, 3);
Chris@26 218 layout->addWidget(m_playMono, 1, 4);
Chris@16 219
Chris@16 220 layout->setColumnStretch(0, 10);
Chris@16 221
Chris@0 222 frame->setLayout(layout);
Chris@0 223
Chris@0 224 connect(m_viewManager, SIGNAL(outputLevelsChanged(float, float)),
Chris@0 225 this, SLOT(outputLevelsChanged(float, float)));
Chris@0 226
Chris@0 227 connect(Preferences::getInstance(),
Chris@0 228 SIGNAL(propertyChanged(PropertyContainer::PropertyName)),
Chris@0 229 this,
Chris@0 230 SLOT(preferenceChanged(PropertyContainer::PropertyName)));
Chris@0 231
Chris@0 232 setupMenus();
Chris@0 233 setupToolbars();
Chris@0 234
Chris@47 235 // statusBar()->addWidget(m_descriptionLabel);
Chris@0 236
Chris@0 237 newSession();
Chris@0 238 }
Chris@0 239
Chris@0 240 MainWindow::~MainWindow()
Chris@0 241 {
Chris@0 242 closeSession();
Chris@0 243 delete m_playTarget;
Chris@0 244 delete m_playSource;
Chris@0 245 delete m_viewManager;
Chris@0 246 Profiles::getInstance()->dump();
Chris@0 247 }
Chris@0 248
Chris@0 249 void
Chris@0 250 MainWindow::setupMenus()
Chris@0 251 {
Chris@0 252 QAction *action = 0;
Chris@0 253 QMenu *menu = 0;
Chris@0 254 QToolBar *toolbar = 0;
Chris@0 255
Chris@0 256 if (!m_mainMenusCreated) {
Chris@0 257 m_rightButtonMenu = new QMenu();
Chris@0 258 }
Chris@0 259
Chris@0 260 if (m_rightButtonLayerMenu) {
Chris@0 261 m_rightButtonLayerMenu->clear();
Chris@0 262 } else {
Chris@0 263 m_rightButtonLayerMenu = m_rightButtonMenu->addMenu(tr("&Layer"));
Chris@0 264 m_rightButtonMenu->addSeparator();
Chris@0 265 }
Chris@0 266
Chris@34 267 if (m_rightButtonTransformsMenu) {
Chris@34 268 m_rightButtonTransformsMenu->clear();
Chris@34 269 } else {
Chris@34 270 m_rightButtonTransformsMenu = m_rightButtonMenu->addMenu(tr("&Transform"));
Chris@34 271 m_rightButtonMenu->addSeparator();
Chris@34 272 }
Chris@34 273
Chris@0 274 if (!m_mainMenusCreated) {
Chris@0 275
Chris@0 276 CommandHistory::getInstance()->registerMenu(m_rightButtonMenu);
Chris@0 277 m_rightButtonMenu->addSeparator();
Chris@0 278
Chris@0 279 menu = menuBar()->addMenu(tr("&File"));
Chris@0 280 toolbar = addToolBar(tr("File Toolbar"));
Chris@0 281
Chris@0 282 QIcon icon(":icons/filenew.png");
Chris@0 283 icon.addFile(":icons/filenew-22.png");
Chris@0 284 action = new QAction(icon, tr("&New Session"), this);
Chris@0 285 action->setShortcut(tr("Ctrl+N"));
Chris@0 286 action->setStatusTip(tr("Clear the current Sonic Visualiser session and start a new one"));
Chris@0 287 connect(action, SIGNAL(triggered()), this, SLOT(newSession()));
Chris@0 288 menu->addAction(action);
Chris@0 289 toolbar->addAction(action);
Chris@0 290
Chris@0 291 icon = QIcon(":icons/fileopen.png");
Chris@0 292 icon.addFile(":icons/fileopen-22.png");
Chris@0 293
Chris@0 294 action = new QAction(icon, tr("&Open Session..."), this);
Chris@0 295 action->setShortcut(tr("Ctrl+O"));
Chris@0 296 action->setStatusTip(tr("Open a previously saved Sonic Visualiser session file"));
Chris@0 297 connect(action, SIGNAL(triggered()), this, SLOT(openSession()));
Chris@0 298 menu->addAction(action);
Chris@0 299
Chris@0 300 action = new QAction(icon, tr("&Open..."), this);
Chris@0 301 action->setStatusTip(tr("Open a session file, audio file, or layer"));
Chris@0 302 connect(action, SIGNAL(triggered()), this, SLOT(openSomething()));
Chris@0 303 toolbar->addAction(action);
Chris@0 304
Chris@0 305 icon = QIcon(":icons/filesave.png");
Chris@0 306 icon.addFile(":icons/filesave-22.png");
Chris@0 307 action = new QAction(icon, tr("&Save Session"), this);
Chris@0 308 action->setShortcut(tr("Ctrl+S"));
Chris@0 309 action->setStatusTip(tr("Save the current session into a Sonic Visualiser session file"));
Chris@0 310 connect(action, SIGNAL(triggered()), this, SLOT(saveSession()));
Chris@0 311 connect(this, SIGNAL(canSave(bool)), action, SLOT(setEnabled(bool)));
Chris@0 312 menu->addAction(action);
Chris@0 313 toolbar->addAction(action);
Chris@0 314
Chris@0 315 icon = QIcon(":icons/filesaveas.png");
Chris@0 316 icon.addFile(":icons/filesaveas-22.png");
Chris@0 317 action = new QAction(icon, tr("Save Session &As..."), this);
Chris@0 318 action->setStatusTip(tr("Save the current session into a new Sonic Visualiser session file"));
Chris@0 319 connect(action, SIGNAL(triggered()), this, SLOT(saveSessionAs()));
Chris@0 320 menu->addAction(action);
Chris@0 321 toolbar->addAction(action);
Chris@0 322
Chris@0 323 menu->addSeparator();
Chris@0 324
Chris@0 325 action = new QAction(tr("&Import Audio File..."), this);
Chris@0 326 action->setShortcut(tr("Ctrl+I"));
Chris@0 327 action->setStatusTip(tr("Import an existing audio file"));
Chris@0 328 connect(action, SIGNAL(triggered()), this, SLOT(importAudio()));
Chris@0 329 menu->addAction(action);
Chris@0 330
Chris@0 331 action = new QAction(tr("Import Secondary Audio File..."), this);
Chris@0 332 action->setShortcut(tr("Ctrl+Shift+I"));
Chris@0 333 action->setStatusTip(tr("Import an extra audio file as a separate layer"));
Chris@0 334 connect(action, SIGNAL(triggered()), this, SLOT(importMoreAudio()));
Chris@0 335 connect(this, SIGNAL(canImportMoreAudio(bool)), action, SLOT(setEnabled(bool)));
Chris@0 336 menu->addAction(action);
Chris@0 337
Chris@0 338 action = new QAction(tr("&Export Audio File..."), this);
Chris@0 339 action->setStatusTip(tr("Export selection as an audio file"));
Chris@0 340 connect(action, SIGNAL(triggered()), this, SLOT(exportAudio()));
Chris@0 341 connect(this, SIGNAL(canExportAudio(bool)), action, SLOT(setEnabled(bool)));
Chris@0 342 menu->addAction(action);
Chris@0 343
Chris@0 344 menu->addSeparator();
Chris@0 345
Chris@0 346 action = new QAction(tr("Import Annotation &Layer..."), this);
Chris@0 347 action->setShortcut(tr("Ctrl+L"));
Chris@0 348 action->setStatusTip(tr("Import layer data from an existing file"));
Chris@0 349 connect(action, SIGNAL(triggered()), this, SLOT(importLayer()));
Chris@0 350 connect(this, SIGNAL(canImportLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@0 351 menu->addAction(action);
Chris@0 352
Chris@0 353 action = new QAction(tr("Export Annotation Layer..."), this);
Chris@0 354 action->setStatusTip(tr("Export layer data to a file"));
Chris@0 355 connect(action, SIGNAL(triggered()), this, SLOT(exportLayer()));
Chris@0 356 connect(this, SIGNAL(canExportLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@0 357 menu->addAction(action);
Chris@0 358
Chris@0 359 menu->addSeparator();
Chris@0 360 m_recentFilesMenu = menu->addMenu(tr("&Recent Files"));
Chris@0 361 setupRecentFilesMenu();
Chris@34 362 connect(&m_recentFiles, SIGNAL(recentChanged()),
Chris@0 363 this, SLOT(setupRecentFilesMenu()));
Chris@0 364
Chris@0 365 menu->addSeparator();
Chris@0 366 action = new QAction(tr("&Preferences..."), this);
Chris@0 367 action->setStatusTip(tr("Adjust the application preferences"));
Chris@0 368 connect(action, SIGNAL(triggered()), this, SLOT(preferences()));
Chris@0 369 menu->addAction(action);
Chris@0 370
Chris@0 371 /*!!!
Chris@0 372 menu->addSeparator();
Chris@0 373
Chris@0 374 action = new QAction(tr("Play / Pause"), this);
Chris@0 375 action->setShortcut(tr("Space"));
Chris@0 376 action->setStatusTip(tr("Start or stop playback from the current position"));
Chris@0 377 connect(action, SIGNAL(triggered()), this, SLOT(play()));
Chris@0 378 menu->addAction(action);
Chris@0 379 */
Chris@0 380
Chris@0 381 menu->addSeparator();
Chris@0 382 action = new QAction(QIcon(":/icons/exit.png"),
Chris@0 383 tr("&Quit"), this);
Chris@0 384 action->setShortcut(tr("Ctrl+Q"));
Chris@0 385 connect(action, SIGNAL(triggered()), this, SLOT(close()));
Chris@0 386 menu->addAction(action);
Chris@0 387
Chris@0 388 menu = menuBar()->addMenu(tr("&Edit"));
Chris@0 389 CommandHistory::getInstance()->registerMenu(menu);
Chris@0 390
Chris@0 391 menu->addSeparator();
Chris@0 392
Chris@0 393 action = new QAction(QIcon(":/icons/editcut.png"),
Chris@0 394 tr("Cu&t"), this);
Chris@0 395 action->setShortcut(tr("Ctrl+X"));
Chris@0 396 connect(action, SIGNAL(triggered()), this, SLOT(cut()));
Chris@0 397 connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@0 398 menu->addAction(action);
Chris@0 399 m_rightButtonMenu->addAction(action);
Chris@0 400
Chris@0 401 action = new QAction(QIcon(":/icons/editcopy.png"),
Chris@0 402 tr("&Copy"), this);
Chris@0 403 action->setShortcut(tr("Ctrl+C"));
Chris@0 404 connect(action, SIGNAL(triggered()), this, SLOT(copy()));
Chris@0 405 connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@0 406 menu->addAction(action);
Chris@0 407 m_rightButtonMenu->addAction(action);
Chris@0 408
Chris@0 409 action = new QAction(QIcon(":/icons/editpaste.png"),
Chris@0 410 tr("&Paste"), this);
Chris@0 411 action->setShortcut(tr("Ctrl+V"));
Chris@0 412 connect(action, SIGNAL(triggered()), this, SLOT(paste()));
Chris@0 413 connect(this, SIGNAL(canPaste(bool)), action, SLOT(setEnabled(bool)));
Chris@0 414 menu->addAction(action);
Chris@0 415 m_rightButtonMenu->addAction(action);
Chris@0 416
Chris@0 417 action = new QAction(tr("&Delete Selected Items"), this);
Chris@0 418 action->setShortcut(tr("Del"));
Chris@0 419 connect(action, SIGNAL(triggered()), this, SLOT(deleteSelected()));
Chris@0 420 connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@0 421 menu->addAction(action);
Chris@0 422 m_rightButtonMenu->addAction(action);
Chris@0 423
Chris@0 424 menu->addSeparator();
Chris@0 425 m_rightButtonMenu->addSeparator();
Chris@0 426
Chris@0 427 action = new QAction(tr("Select &All"), this);
Chris@0 428 action->setShortcut(tr("Ctrl+A"));
Chris@0 429 connect(action, SIGNAL(triggered()), this, SLOT(selectAll()));
Chris@0 430 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
Chris@0 431 menu->addAction(action);
Chris@0 432 m_rightButtonMenu->addAction(action);
Chris@0 433
Chris@0 434 action = new QAction(tr("Select &Visible Range"), this);
Chris@0 435 action->setShortcut(tr("Ctrl+Shift+A"));
Chris@0 436 connect(action, SIGNAL(triggered()), this, SLOT(selectVisible()));
Chris@0 437 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
Chris@0 438 menu->addAction(action);
Chris@0 439
Chris@0 440 action = new QAction(tr("Select to &Start"), this);
Chris@0 441 action->setShortcut(tr("Shift+Left"));
Chris@0 442 connect(action, SIGNAL(triggered()), this, SLOT(selectToStart()));
Chris@0 443 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
Chris@0 444 menu->addAction(action);
Chris@0 445
Chris@0 446 action = new QAction(tr("Select to &End"), this);
Chris@0 447 action->setShortcut(tr("Shift+Right"));
Chris@0 448 connect(action, SIGNAL(triggered()), this, SLOT(selectToEnd()));
Chris@0 449 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
Chris@0 450 menu->addAction(action);
Chris@0 451
Chris@0 452 action = new QAction(tr("C&lear Selection"), this);
Chris@0 453 action->setShortcut(tr("Esc"));
Chris@0 454 connect(action, SIGNAL(triggered()), this, SLOT(clearSelection()));
Chris@0 455 connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@0 456 menu->addAction(action);
Chris@0 457 m_rightButtonMenu->addAction(action);
Chris@0 458
Chris@0 459 menu->addSeparator();
Chris@0 460
Chris@0 461 action = new QAction(tr("&Insert Instant at Playback Position"), this);
Chris@0 462 action->setShortcut(tr("Enter"));
Chris@0 463 connect(action, SIGNAL(triggered()), this, SLOT(insertInstant()));
Chris@0 464 connect(this, SIGNAL(canInsertInstant(bool)), action, SLOT(setEnabled(bool)));
Chris@0 465 menu->addAction(action);
Chris@0 466
Chris@7 467 // Laptop shortcut (no keypad Enter key)
Chris@7 468 connect(new QShortcut(tr(";"), this), SIGNAL(activated()),
Chris@7 469 this, SLOT(insertInstant()));
Chris@7 470
Chris@0 471 menu = menuBar()->addMenu(tr("&View"));
Chris@0 472
Chris@0 473 QActionGroup *overlayGroup = new QActionGroup(this);
Chris@0 474
Chris@0 475 action = new QAction(tr("&No Text Overlays"), this);
Chris@0 476 action->setShortcut(tr("0"));
Chris@0 477 action->setStatusTip(tr("Show no texts for frame times, layer names etc"));
Chris@0 478 connect(action, SIGNAL(triggered()), this, SLOT(showNoOverlays()));
Chris@0 479 action->setCheckable(true);
Chris@0 480 action->setChecked(false);
Chris@0 481 overlayGroup->addAction(action);
Chris@0 482 menu->addAction(action);
Chris@0 483
Chris@0 484 action = new QAction(tr("Basic &Text Overlays"), this);
Chris@0 485 action->setShortcut(tr("9"));
Chris@0 486 action->setStatusTip(tr("Show texts for frame times etc, but not layer names etc"));
Chris@0 487 connect(action, SIGNAL(triggered()), this, SLOT(showBasicOverlays()));
Chris@0 488 action->setCheckable(true);
Chris@0 489 action->setChecked(true);
Chris@0 490 overlayGroup->addAction(action);
Chris@0 491 menu->addAction(action);
Chris@0 492
Chris@0 493 action = new QAction(tr("&All Text Overlays"), this);
Chris@0 494 action->setShortcut(tr("8"));
Chris@0 495 action->setStatusTip(tr("Show texts for frame times, layer names etc"));
Chris@7 496 connect(action, SIGNAL(triggered()), this, SLOT(showAllTextOverlays()));
Chris@0 497 action->setCheckable(true);
Chris@0 498 action->setChecked(false);
Chris@0 499 overlayGroup->addAction(action);
Chris@0 500 menu->addAction(action);
Chris@0 501
Chris@0 502 menu->addSeparator();
Chris@0 503
Chris@0 504 action = new QAction(tr("Scroll &Left"), this);
Chris@0 505 action->setShortcut(tr("Left"));
Chris@0 506 action->setStatusTip(tr("Scroll the current pane to the left"));
Chris@0 507 connect(action, SIGNAL(triggered()), this, SLOT(scrollLeft()));
Chris@0 508 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@0 509 menu->addAction(action);
Chris@0 510
Chris@0 511 action = new QAction(tr("Scroll &Right"), this);
Chris@0 512 action->setShortcut(tr("Right"));
Chris@0 513 action->setStatusTip(tr("Scroll the current pane to the right"));
Chris@0 514 connect(action, SIGNAL(triggered()), this, SLOT(scrollRight()));
Chris@0 515 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@0 516 menu->addAction(action);
Chris@0 517
Chris@0 518 action = new QAction(tr("Jump Left"), this);
Chris@0 519 action->setShortcut(tr("Ctrl+Left"));
Chris@0 520 action->setStatusTip(tr("Scroll the current pane a big step to the left"));
Chris@0 521 connect(action, SIGNAL(triggered()), this, SLOT(jumpLeft()));
Chris@0 522 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@0 523 menu->addAction(action);
Chris@0 524
Chris@0 525 action = new QAction(tr("Jump Right"), this);
Chris@0 526 action->setShortcut(tr("Ctrl+Right"));
Chris@0 527 action->setStatusTip(tr("Scroll the current pane a big step to the right"));
Chris@0 528 connect(action, SIGNAL(triggered()), this, SLOT(jumpRight()));
Chris@0 529 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@0 530 menu->addAction(action);
Chris@0 531
Chris@0 532 menu->addSeparator();
Chris@0 533
Chris@0 534 action = new QAction(QIcon(":/icons/zoom-in.png"),
Chris@0 535 tr("Zoom &In"), this);
Chris@0 536 action->setShortcut(tr("Up"));
Chris@0 537 action->setStatusTip(tr("Increase the zoom level"));
Chris@0 538 connect(action, SIGNAL(triggered()), this, SLOT(zoomIn()));
Chris@0 539 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@0 540 menu->addAction(action);
Chris@0 541
Chris@0 542 action = new QAction(QIcon(":/icons/zoom-out.png"),
Chris@0 543 tr("Zoom &Out"), this);
Chris@0 544 action->setShortcut(tr("Down"));
Chris@0 545 action->setStatusTip(tr("Decrease the zoom level"));
Chris@0 546 connect(action, SIGNAL(triggered()), this, SLOT(zoomOut()));
Chris@0 547 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@0 548 menu->addAction(action);
Chris@0 549
Chris@0 550 action = new QAction(tr("Restore &Default Zoom"), this);
Chris@0 551 connect(action, SIGNAL(triggered()), this, SLOT(zoomDefault()));
Chris@0 552 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@0 553 menu->addAction(action);
Chris@0 554
Chris@0 555 action = new QAction(tr("Zoom to &Fit"), this);
Chris@0 556 action->setStatusTip(tr("Zoom to show the whole file"));
Chris@0 557 connect(action, SIGNAL(triggered()), this, SLOT(zoomToFit()));
Chris@0 558 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@0 559 menu->addAction(action);
Chris@7 560
Chris@7 561 action = new QAction(tr("Show &Zoom Wheels"), this);
Chris@7 562 action->setShortcut(tr("Z"));
Chris@7 563 action->setStatusTip(tr("Show thumbwheels for zooming horizontally and vertically"));
Chris@7 564 connect(action, SIGNAL(triggered()), this, SLOT(toggleZoomWheels()));
Chris@7 565 action->setCheckable(true);
Chris@7 566 action->setChecked(m_viewManager->getZoomWheelsEnabled());
Chris@7 567 menu->addAction(action);
Chris@0 568
Chris@0 569 /*!!! This one doesn't work properly yet
Chris@0 570
Chris@0 571 menu->addSeparator();
Chris@0 572
Chris@0 573 action = new QAction(tr("Show &Layer Hierarchy"), this);
Chris@0 574 action->setShortcut(tr("Alt+L"));
Chris@0 575 connect(action, SIGNAL(triggered()), this, SLOT(showLayerTree()));
Chris@0 576 menu->addAction(action);
Chris@0 577 */
Chris@0 578 }
Chris@0 579
Chris@0 580 if (m_paneMenu) {
Chris@0 581 m_paneActions.clear();
Chris@0 582 m_paneMenu->clear();
Chris@0 583 } else {
Chris@0 584 m_paneMenu = menuBar()->addMenu(tr("&Pane"));
Chris@0 585 }
Chris@0 586
Chris@0 587 if (m_layerMenu) {
Chris@0 588 m_layerActions.clear();
Chris@0 589 m_layerMenu->clear();
Chris@0 590 } else {
Chris@0 591 m_layerMenu = menuBar()->addMenu(tr("&Layer"));
Chris@0 592 }
Chris@0 593
Chris@34 594 if (m_transformsMenu) {
Chris@34 595 m_transformActions.clear();
Chris@34 596 m_transformActionsReverse.clear();
Chris@34 597 m_transformsMenu->clear();
Chris@34 598 } else {
Chris@34 599 m_transformsMenu = menuBar()->addMenu(tr("&Transform"));
Chris@34 600 }
Chris@34 601
Chris@0 602 TransformFactory::TransformList transforms =
Chris@0 603 TransformFactory::getInstance()->getAllTransforms();
Chris@0 604
Chris@33 605 vector<QString> types =
Chris@0 606 TransformFactory::getInstance()->getAllTransformTypes();
Chris@0 607
Chris@37 608 map<QString, map<QString, SubdividingMenu *> > categoryMenus;
Chris@37 609 map<QString, map<QString, SubdividingMenu *> > makerMenus;
Chris@33 610
Chris@36 611 map<QString, SubdividingMenu *> byPluginNameMenus;
Chris@33 612 map<QString, map<QString, QMenu *> > pluginNameMenus;
Chris@33 613
Chris@37 614 set<SubdividingMenu *> pendingMenus;
Chris@37 615
Chris@34 616 m_recentTransformsMenu = m_transformsMenu->addMenu(tr("&Recent Transforms"));
Chris@34 617 m_rightButtonTransformsMenu->addMenu(m_recentTransformsMenu);
Chris@34 618 connect(&m_recentTransforms, SIGNAL(recentChanged()),
Chris@34 619 this, SLOT(setupRecentTransformsMenu()));
Chris@34 620
Chris@34 621 m_transformsMenu->addSeparator();
Chris@34 622 m_rightButtonTransformsMenu->addSeparator();
Chris@34 623
Chris@33 624 for (vector<QString>::iterator i = types.begin(); i != types.end(); ++i) {
Chris@33 625
Chris@33 626 if (i != types.begin()) {
Chris@34 627 m_transformsMenu->addSeparator();
Chris@34 628 m_rightButtonTransformsMenu->addSeparator();
Chris@33 629 }
Chris@33 630
Chris@33 631 QString byCategoryLabel = tr("%1 by Category").arg(*i);
Chris@37 632 SubdividingMenu *byCategoryMenu = new SubdividingMenu(byCategoryLabel,
Chris@37 633 20, 40);
Chris@37 634 m_transformsMenu->addMenu(byCategoryMenu);
Chris@34 635 m_rightButtonTransformsMenu->addMenu(byCategoryMenu);
Chris@37 636 pendingMenus.insert(byCategoryMenu);
Chris@33 637
Chris@33 638 vector<QString> categories =
Chris@33 639 TransformFactory::getInstance()->getTransformCategories(*i);
Chris@33 640
Chris@33 641 for (vector<QString>::iterator j = categories.begin();
Chris@33 642 j != categories.end(); ++j) {
Chris@33 643
Chris@33 644 QString category = *j;
Chris@33 645 if (category == "") category = tr("Unclassified");
Chris@33 646
Chris@33 647 if (categories.size() < 2) {
Chris@33 648 categoryMenus[*i][category] = byCategoryMenu;
Chris@33 649 continue;
Chris@33 650 }
Chris@33 651
Chris@33 652 QStringList components = category.split(" > ");
Chris@33 653 QString key;
Chris@33 654
Chris@33 655 for (QStringList::iterator k = components.begin();
Chris@33 656 k != components.end(); ++k) {
Chris@33 657
Chris@33 658 QString parentKey = key;
Chris@33 659 if (key != "") key += " > ";
Chris@33 660 key += *k;
Chris@33 661
Chris@33 662 if (categoryMenus[*i].find(key) == categoryMenus[*i].end()) {
Chris@37 663 SubdividingMenu *m = new SubdividingMenu(*k, 20, 40);
Chris@37 664 pendingMenus.insert(m);
Chris@37 665 categoryMenus[*i][key] = m;
Chris@33 666 if (parentKey == "") {
Chris@37 667 byCategoryMenu->addMenu(m);
Chris@33 668 } else {
Chris@37 669 categoryMenus[*i][parentKey]->addMenu(m);
Chris@33 670 }
Chris@33 671 }
Chris@33 672 }
Chris@33 673 }
Chris@33 674
Chris@34 675 QString byPluginNameLabel = tr("%1 by Plugin Name").arg(*i);
Chris@36 676 byPluginNameMenus[*i] = new SubdividingMenu(byPluginNameLabel);
Chris@36 677 m_transformsMenu->addMenu(byPluginNameMenus[*i]);
Chris@34 678 m_rightButtonTransformsMenu->addMenu(byPluginNameMenus[*i]);
Chris@37 679 pendingMenus.insert(byPluginNameMenus[*i]);
Chris@34 680
Chris@33 681 QString byMakerLabel = tr("%1 by Maker").arg(*i);
Chris@37 682 SubdividingMenu *byMakerMenu = new SubdividingMenu(byMakerLabel, 20, 40);
Chris@37 683 m_transformsMenu->addMenu(byMakerMenu);
Chris@34 684 m_rightButtonTransformsMenu->addMenu(byMakerMenu);
Chris@37 685 pendingMenus.insert(byMakerMenu);
Chris@33 686
Chris@33 687 vector<QString> makers =
Chris@33 688 TransformFactory::getInstance()->getTransformMakers(*i);
Chris@37 689
Chris@33 690 for (vector<QString>::iterator j = makers.begin();
Chris@33 691 j != makers.end(); ++j) {
Chris@33 692
Chris@33 693 QString maker = *j;
Chris@33 694 if (maker == "") maker = tr("Unknown");
Chris@55 695 maker.replace(QRegExp(tr(" [\\(<].*$")), "");
Chris@55 696
Chris@37 697 makerMenus[*i][maker] = new SubdividingMenu(maker, 30, 40);
Chris@37 698 byMakerMenu->addMenu(makerMenus[*i][maker]);
Chris@37 699 pendingMenus.insert(makerMenus[*i][maker]);
Chris@33 700 }
Chris@0 701 }
Chris@0 702
Chris@0 703 for (unsigned int i = 0; i < transforms.size(); ++i) {
Chris@0 704
Chris@0 705 QString description = transforms[i].description;
Chris@0 706 if (description == "") description = transforms[i].name;
Chris@0 707
Chris@33 708 QString type = transforms[i].type;
Chris@33 709
Chris@33 710 QString category = transforms[i].category;
Chris@33 711 if (category == "") category = tr("Unclassified");
Chris@33 712
Chris@33 713 QString maker = transforms[i].maker;
Chris@33 714 if (maker == "") maker = tr("Unknown");
Chris@55 715 maker.replace(QRegExp(tr(" [\\(<].*$")), "");
Chris@33 716
Chris@33 717 QString pluginName = description.section(": ", 0, 0);
Chris@33 718 QString output = description.section(": ", 1);
Chris@33 719
Chris@33 720 action = new QAction(tr("%1...").arg(description), this);
Chris@0 721 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@34 722 m_transformActions[action] = transforms[i].name;
Chris@34 723 m_transformActionsReverse[transforms[i].name] = action;
Chris@0 724 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@33 725
Chris@33 726 if (categoryMenus[type].find(category) == categoryMenus[type].end()) {
Chris@33 727 std::cerr << "WARNING: MainWindow::setupMenus: Internal error: "
Chris@33 728 << "No category menu for transform \""
Chris@33 729 << description.toStdString() << "\" (category = \""
Chris@33 730 << category.toStdString() << "\")" << std::endl;
Chris@33 731 } else {
Chris@33 732 categoryMenus[type][category]->addAction(action);
Chris@33 733 }
Chris@33 734
Chris@33 735 if (makerMenus[type].find(maker) == makerMenus[type].end()) {
Chris@33 736 std::cerr << "WARNING: MainWindow::setupMenus: Internal error: "
Chris@33 737 << "No maker menu for transform \""
Chris@33 738 << description.toStdString() << "\" (maker = \""
Chris@33 739 << maker.toStdString() << "\")" << std::endl;
Chris@33 740 } else {
Chris@37 741 makerMenus[type][maker]->addAction(pluginName, action);
Chris@33 742 }
Chris@33 743
Chris@33 744 action = new QAction(tr("%1...").arg(output == "" ? pluginName : output), this);
Chris@33 745 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@34 746 m_transformActions[action] = transforms[i].name;
Chris@33 747 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@33 748
Chris@34 749 // cerr << "Transform: \"" << name.toStdString() << "\": plugin name \"" << pluginName.toStdString() << "\"" << endl;
Chris@34 750
Chris@33 751 if (pluginNameMenus[type].find(pluginName) ==
Chris@33 752 pluginNameMenus[type].end()) {
Chris@33 753
Chris@36 754 SubdividingMenu *parentMenu = byPluginNameMenus[type];
Chris@34 755
Chris@33 756 if (output == "") {
Chris@36 757 parentMenu->addAction(pluginName, action);
Chris@33 758 } else {
Chris@34 759 pluginNameMenus[type][pluginName] =
Chris@34 760 parentMenu->addMenu(pluginName);
Chris@33 761 connect(this, SIGNAL(canAddLayer(bool)),
Chris@33 762 pluginNameMenus[type][pluginName],
Chris@33 763 SLOT(setEnabled(bool)));
Chris@33 764 }
Chris@33 765 }
Chris@33 766
Chris@33 767 if (pluginNameMenus[type].find(pluginName) !=
Chris@33 768 pluginNameMenus[type].end()) {
Chris@33 769 pluginNameMenus[type][pluginName]->addAction(action);
Chris@33 770 }
Chris@0 771 }
Chris@0 772
Chris@37 773 for (set<SubdividingMenu *>::iterator i = pendingMenus.begin();
Chris@37 774 i != pendingMenus.end(); ++i) {
Chris@37 775 (*i)->entriesAdded();
Chris@37 776 }
Chris@37 777
Chris@34 778 setupRecentTransformsMenu();
Chris@0 779
Chris@0 780 menu = m_paneMenu;
Chris@0 781
Chris@0 782 action = new QAction(QIcon(":/icons/pane.png"), tr("Add &New Pane"), this);
Chris@0 783 action->setShortcut(tr("Alt+N"));
Chris@0 784 action->setStatusTip(tr("Add a new pane containing only a time ruler"));
Chris@0 785 connect(action, SIGNAL(triggered()), this, SLOT(addPane()));
Chris@0 786 connect(this, SIGNAL(canAddPane(bool)), action, SLOT(setEnabled(bool)));
Chris@0 787 m_paneActions[action] = PaneConfiguration(LayerFactory::TimeRuler);
Chris@0 788 menu->addAction(action);
Chris@0 789
Chris@0 790 menu->addSeparator();
Chris@0 791
Chris@0 792 menu = m_layerMenu;
Chris@0 793
Chris@34 794 // menu->addSeparator();
Chris@0 795
Chris@0 796 LayerFactory::LayerTypeSet emptyLayerTypes =
Chris@0 797 LayerFactory::getInstance()->getValidEmptyLayerTypes();
Chris@0 798
Chris@0 799 for (LayerFactory::LayerTypeSet::iterator i = emptyLayerTypes.begin();
Chris@0 800 i != emptyLayerTypes.end(); ++i) {
Chris@0 801
Chris@0 802 QIcon icon;
Chris@0 803 QString mainText, tipText, channelText;
Chris@0 804 LayerFactory::LayerType type = *i;
Chris@0 805 QString name = LayerFactory::getInstance()->getLayerPresentationName(type);
Chris@0 806
Chris@0 807 icon = QIcon(QString(":/icons/%1.png")
Chris@0 808 .arg(LayerFactory::getInstance()->getLayerIconName(type)));
Chris@0 809
Chris@0 810 mainText = tr("Add New %1 Layer").arg(name);
Chris@0 811 tipText = tr("Add a new empty layer of type %1").arg(name);
Chris@0 812
Chris@0 813 action = new QAction(icon, mainText, this);
Chris@0 814 action->setStatusTip(tipText);
Chris@0 815
Chris@0 816 if (type == LayerFactory::Text) {
Chris@0 817 action->setShortcut(tr("Alt+T"));
Chris@0 818 }
Chris@0 819
Chris@0 820 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@0 821 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@0 822 m_layerActions[action] = type;
Chris@0 823 menu->addAction(action);
Chris@0 824 m_rightButtonLayerMenu->addAction(action);
Chris@0 825 }
Chris@0 826
Chris@0 827 m_rightButtonLayerMenu->addSeparator();
Chris@0 828 menu->addSeparator();
Chris@0 829
Chris@0 830 int channels = 1;
Chris@0 831 if (getMainModel()) channels = getMainModel()->getChannelCount();
Chris@0 832
Chris@0 833 if (channels < 1) channels = 1;
Chris@0 834
Chris@0 835 LayerFactory::LayerType backgroundTypes[] = {
Chris@0 836 LayerFactory::Waveform,
Chris@0 837 LayerFactory::Spectrogram,
Chris@0 838 LayerFactory::MelodicRangeSpectrogram,
Chris@7 839 LayerFactory::PeakFrequencySpectrogram,
Chris@7 840 LayerFactory::Spectrum
Chris@0 841 };
Chris@0 842
Chris@0 843 for (unsigned int i = 0;
Chris@0 844 i < sizeof(backgroundTypes)/sizeof(backgroundTypes[0]); ++i) {
Chris@0 845
Chris@0 846 for (int menuType = 0; menuType <= 1; ++menuType) { // pane, layer
Chris@0 847
Chris@0 848 if (menuType == 0) menu = m_paneMenu;
Chris@0 849 else menu = m_layerMenu;
Chris@0 850
Chris@0 851 QMenu *submenu = 0;
Chris@0 852
Chris@0 853 for (int c = 0; c <= channels; ++c) {
Chris@0 854
Chris@0 855 if (c == 1 && channels == 1) continue;
Chris@0 856 bool isDefault = (c == 0);
Chris@0 857 bool isOnly = (isDefault && (channels == 1));
Chris@0 858
Chris@0 859 if (menuType == 1) {
Chris@0 860 if (isDefault) isOnly = true;
Chris@0 861 else continue;
Chris@0 862 }
Chris@0 863
Chris@0 864 QIcon icon;
Chris@0 865 QString mainText, shortcutText, tipText, channelText;
Chris@0 866 LayerFactory::LayerType type = backgroundTypes[i];
Chris@0 867 bool mono = true;
Chris@0 868
Chris@0 869 switch (type) {
Chris@0 870
Chris@0 871 case LayerFactory::Waveform:
Chris@0 872 icon = QIcon(":/icons/waveform.png");
Chris@0 873 mainText = tr("Add &Waveform");
Chris@0 874 if (menuType == 0) {
Chris@0 875 shortcutText = tr("Alt+W");
Chris@0 876 tipText = tr("Add a new pane showing a waveform view");
Chris@0 877 } else {
Chris@0 878 tipText = tr("Add a new layer showing a waveform view");
Chris@0 879 }
Chris@0 880 mono = false;
Chris@0 881 break;
Chris@0 882
Chris@0 883 case LayerFactory::Spectrogram:
Chris@0 884 mainText = tr("Add &Spectrogram");
Chris@0 885 if (menuType == 0) {
Chris@0 886 shortcutText = tr("Alt+S");
Chris@0 887 tipText = tr("Add a new pane showing a dB spectrogram");
Chris@0 888 } else {
Chris@0 889 tipText = tr("Add a new layer showing a dB spectrogram");
Chris@0 890 }
Chris@0 891 break;
Chris@0 892
Chris@0 893 case LayerFactory::MelodicRangeSpectrogram:
Chris@0 894 mainText = tr("Add &Melodic Range Spectrogram");
Chris@0 895 if (menuType == 0) {
Chris@0 896 shortcutText = tr("Alt+M");
Chris@0 897 tipText = tr("Add a new pane showing a spectrogram set up for a pitch overview");
Chris@0 898 } else {
Chris@0 899 tipText = tr("Add a new layer showing a spectrogram set up for a pitch overview");
Chris@0 900 }
Chris@0 901 break;
Chris@0 902
Chris@0 903 case LayerFactory::PeakFrequencySpectrogram:
Chris@0 904 mainText = tr("Add &Peak Frequency Spectrogram");
Chris@0 905 if (menuType == 0) {
Chris@0 906 shortcutText = tr("Alt+P");
Chris@0 907 tipText = tr("Add a new pane showing a spectrogram set up for tracking frequencies");
Chris@0 908 } else {
Chris@0 909 tipText = tr("Add a new layer showing a spectrogram set up for tracking frequencies");
Chris@0 910 }
Chris@0 911 break;
Chris@0 912
Chris@7 913 case LayerFactory::Spectrum:
Chris@7 914 mainText = tr("Add Spectr&um");
Chris@7 915 if (menuType == 0) {
Chris@7 916 shortcutText = tr("Alt+U");
Chris@7 917 tipText = tr("Add a new pane showing a frequency spectrum");
Chris@7 918 } else {
Chris@7 919 tipText = tr("Add a new layer showing a frequency spectrum");
Chris@7 920 }
Chris@7 921 break;
Chris@7 922
Chris@0 923 default: break;
Chris@0 924 }
Chris@0 925
Chris@0 926 if (isOnly) {
Chris@0 927
Chris@0 928 action = new QAction(icon, mainText, this);
Chris@0 929 action->setShortcut(shortcutText);
Chris@0 930 action->setStatusTip(tipText);
Chris@0 931 if (menuType == 0) {
Chris@0 932 connect(action, SIGNAL(triggered()), this, SLOT(addPane()));
Chris@0 933 connect(this, SIGNAL(canAddPane(bool)), action, SLOT(setEnabled(bool)));
Chris@0 934 m_paneActions[action] = PaneConfiguration(type);
Chris@0 935 } else {
Chris@0 936 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@0 937 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@0 938 m_layerActions[action] = type;
Chris@0 939 }
Chris@0 940 menu->addAction(action);
Chris@0 941
Chris@0 942 } else {
Chris@0 943
Chris@0 944 QString actionText;
Chris@0 945 if (c == 0)
Chris@0 946 if (mono) actionText = tr("&All Channels Mixed");
Chris@0 947 else actionText = tr("&All Channels");
Chris@0 948 else actionText = tr("Channel &%1").arg(c);
Chris@0 949
Chris@0 950 if (!submenu) {
Chris@0 951 submenu = menu->addMenu(mainText);
Chris@0 952 }
Chris@0 953
Chris@0 954 action = new QAction(icon, actionText, this);
Chris@0 955 if (isDefault) action->setShortcut(shortcutText);
Chris@0 956 action->setStatusTip(tipText);
Chris@0 957 if (menuType == 0) {
Chris@0 958 connect(action, SIGNAL(triggered()), this, SLOT(addPane()));
Chris@0 959 connect(this, SIGNAL(canAddPane(bool)), action, SLOT(setEnabled(bool)));
Chris@0 960 m_paneActions[action] = PaneConfiguration(type, c - 1);
Chris@0 961 } else {
Chris@0 962 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@0 963 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@0 964 m_layerActions[action] = type;
Chris@0 965 }
Chris@0 966 submenu->addAction(action);
Chris@0 967 }
Chris@0 968 }
Chris@0 969 }
Chris@0 970 }
Chris@0 971
Chris@0 972 menu = m_paneMenu;
Chris@0 973
Chris@0 974 menu->addSeparator();
Chris@0 975
Chris@0 976 action = new QAction(QIcon(":/icons/editdelete.png"), tr("&Delete Pane"), this);
Chris@0 977 action->setShortcut(tr("Alt+D"));
Chris@0 978 action->setStatusTip(tr("Delete the currently selected pane"));
Chris@0 979 connect(action, SIGNAL(triggered()), this, SLOT(deleteCurrentPane()));
Chris@0 980 connect(this, SIGNAL(canDeleteCurrentPane(bool)), action, SLOT(setEnabled(bool)));
Chris@0 981 menu->addAction(action);
Chris@0 982
Chris@0 983 menu = m_layerMenu;
Chris@0 984
Chris@0 985 action = new QAction(QIcon(":/icons/timeruler.png"), tr("Add &Time Ruler"), this);
Chris@0 986 action->setStatusTip(tr("Add a new layer showing a time ruler"));
Chris@0 987 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@0 988 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@0 989 m_layerActions[action] = LayerFactory::TimeRuler;
Chris@0 990 menu->addAction(action);
Chris@0 991
Chris@0 992 menu->addSeparator();
Chris@0 993
Chris@0 994 m_existingLayersMenu = menu->addMenu(tr("Add &Existing Layer"));
Chris@0 995 m_rightButtonLayerMenu->addMenu(m_existingLayersMenu);
Chris@0 996 setupExistingLayersMenu();
Chris@0 997
Chris@0 998 m_rightButtonLayerMenu->addSeparator();
Chris@0 999 menu->addSeparator();
Chris@0 1000
Chris@0 1001 action = new QAction(tr("&Rename Layer..."), this);
Chris@0 1002 action->setShortcut(tr("Alt+R"));
Chris@0 1003 action->setStatusTip(tr("Rename the currently active layer"));
Chris@0 1004 connect(action, SIGNAL(triggered()), this, SLOT(renameCurrentLayer()));
Chris@0 1005 connect(this, SIGNAL(canRenameLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1006 menu->addAction(action);
Chris@0 1007 m_rightButtonLayerMenu->addAction(action);
Chris@0 1008
Chris@0 1009 action = new QAction(QIcon(":/icons/editdelete.png"), tr("&Delete Layer"), this);
Chris@0 1010 action->setShortcut(tr("Alt+Shift+D"));
Chris@0 1011 action->setStatusTip(tr("Delete the currently active layer"));
Chris@0 1012 connect(action, SIGNAL(triggered()), this, SLOT(deleteCurrentLayer()));
Chris@0 1013 connect(this, SIGNAL(canDeleteCurrentLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1014 menu->addAction(action);
Chris@0 1015 m_rightButtonLayerMenu->addAction(action);
Chris@0 1016
Chris@0 1017 if (!m_mainMenusCreated) {
Chris@0 1018
Chris@0 1019 menu = menuBar()->addMenu(tr("&Help"));
Chris@0 1020
Chris@0 1021 action = new QAction(tr("&Help Reference"), this);
Chris@0 1022 action->setStatusTip(tr("Open the Sonic Visualiser reference manual"));
Chris@0 1023 connect(action, SIGNAL(triggered()), this, SLOT(help()));
Chris@0 1024 menu->addAction(action);
Chris@0 1025
Chris@0 1026 action = new QAction(tr("Sonic Visualiser on the &Web"), this);
Chris@0 1027 action->setStatusTip(tr("Open the Sonic Visualiser website"));
Chris@0 1028 connect(action, SIGNAL(triggered()), this, SLOT(website()));
Chris@0 1029 menu->addAction(action);
Chris@0 1030
Chris@0 1031 action = new QAction(tr("&About Sonic Visualiser"), this);
Chris@0 1032 action->setStatusTip(tr("Show information about Sonic Visualiser"));
Chris@0 1033 connect(action, SIGNAL(triggered()), this, SLOT(about()));
Chris@0 1034 menu->addAction(action);
Chris@0 1035 /*
Chris@0 1036 action = new QAction(tr("About &Qt"), this);
Chris@0 1037 action->setStatusTip(tr("Show information about Qt"));
Chris@0 1038 connect(action, SIGNAL(triggered()),
Chris@0 1039 QApplication::getInstance(), SLOT(aboutQt()));
Chris@0 1040 menu->addAction(action);
Chris@0 1041 */
Chris@0 1042 }
Chris@0 1043
Chris@0 1044 m_mainMenusCreated = true;
Chris@0 1045 }
Chris@0 1046
Chris@0 1047 void
Chris@0 1048 MainWindow::setupRecentFilesMenu()
Chris@0 1049 {
Chris@0 1050 m_recentFilesMenu->clear();
Chris@34 1051 vector<QString> files = m_recentFiles.getRecent();
Chris@0 1052 for (size_t i = 0; i < files.size(); ++i) {
Chris@0 1053 QAction *action = new QAction(files[i], this);
Chris@0 1054 connect(action, SIGNAL(triggered()), this, SLOT(openRecentFile()));
Chris@0 1055 m_recentFilesMenu->addAction(action);
Chris@0 1056 }
Chris@0 1057 }
Chris@0 1058
Chris@0 1059 void
Chris@34 1060 MainWindow::setupRecentTransformsMenu()
Chris@34 1061 {
Chris@34 1062 m_recentTransformsMenu->clear();
Chris@34 1063 vector<QString> transforms = m_recentTransforms.getRecent();
Chris@34 1064 for (size_t i = 0; i < transforms.size(); ++i) {
Chris@34 1065 TransformActionReverseMap::iterator ti =
Chris@34 1066 m_transformActionsReverse.find(transforms[i]);
Chris@34 1067 if (ti == m_transformActionsReverse.end()) {
Chris@34 1068 std::cerr << "WARNING: MainWindow::setupRecentTransformsMenu: "
Chris@34 1069 << "Unknown transform \"" << transforms[i].toStdString()
Chris@34 1070 << "\" in recent transforms list" << std::endl;
Chris@34 1071 continue;
Chris@34 1072 }
Chris@34 1073 m_recentTransformsMenu->addAction(ti->second);
Chris@34 1074 }
Chris@34 1075 }
Chris@34 1076
Chris@34 1077 void
Chris@0 1078 MainWindow::setupExistingLayersMenu()
Chris@0 1079 {
Chris@0 1080 if (!m_existingLayersMenu) return; // should have been created by setupMenus
Chris@0 1081
Chris@0 1082 // std::cerr << "MainWindow::setupExistingLayersMenu" << std::endl;
Chris@0 1083
Chris@0 1084 m_existingLayersMenu->clear();
Chris@0 1085 m_existingLayerActions.clear();
Chris@0 1086
Chris@33 1087 vector<Layer *> orderedLayers;
Chris@33 1088 set<Layer *> observedLayers;
Chris@0 1089
Chris@0 1090 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@0 1091
Chris@0 1092 Pane *pane = m_paneStack->getPane(i);
Chris@0 1093 if (!pane) continue;
Chris@0 1094
Chris@0 1095 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@0 1096
Chris@0 1097 Layer *layer = pane->getLayer(j);
Chris@0 1098 if (!layer) continue;
Chris@0 1099 if (observedLayers.find(layer) != observedLayers.end()) {
Chris@0 1100 std::cerr << "found duplicate layer " << layer << std::endl;
Chris@0 1101 continue;
Chris@0 1102 }
Chris@0 1103
Chris@0 1104 // std::cerr << "found new layer " << layer << " (name = "
Chris@0 1105 // << layer->getLayerPresentationName().toStdString() << ")" << std::endl;
Chris@0 1106
Chris@0 1107 orderedLayers.push_back(layer);
Chris@0 1108 observedLayers.insert(layer);
Chris@0 1109 }
Chris@0 1110 }
Chris@0 1111
Chris@33 1112 map<QString, int> observedNames;
Chris@0 1113
Chris@0 1114 for (int i = 0; i < orderedLayers.size(); ++i) {
Chris@0 1115
Chris@0 1116 QString name = orderedLayers[i]->getLayerPresentationName();
Chris@0 1117 int n = ++observedNames[name];
Chris@0 1118 if (n > 1) name = QString("%1 <%2>").arg(name).arg(n);
Chris@0 1119
Chris@0 1120 QAction *action = new QAction(name, this);
Chris@0 1121 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@0 1122 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1123 m_existingLayerActions[action] = orderedLayers[i];
Chris@0 1124
Chris@0 1125 m_existingLayersMenu->addAction(action);
Chris@0 1126 }
Chris@0 1127 }
Chris@0 1128
Chris@0 1129 void
Chris@0 1130 MainWindow::setupToolbars()
Chris@0 1131 {
Chris@0 1132 QToolBar *toolbar = addToolBar(tr("Transport Toolbar"));
Chris@0 1133
Chris@0 1134 QAction *action = toolbar->addAction(QIcon(":/icons/rewind-start.png"),
Chris@0 1135 tr("Rewind to Start"));
Chris@0 1136 action->setShortcut(tr("Home"));
Chris@0 1137 action->setStatusTip(tr("Rewind to the start"));
Chris@0 1138 connect(action, SIGNAL(triggered()), this, SLOT(rewindStart()));
Chris@0 1139 connect(this, SIGNAL(canPlay(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1140
Chris@0 1141 action = toolbar->addAction(QIcon(":/icons/rewind.png"),
Chris@0 1142 tr("Rewind"));
Chris@0 1143 action->setShortcut(tr("PageUp"));
Chris@0 1144 action->setStatusTip(tr("Rewind to the previous time instant in the current layer"));
Chris@0 1145 connect(action, SIGNAL(triggered()), this, SLOT(rewind()));
Chris@0 1146 connect(this, SIGNAL(canRewind(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1147
Chris@0 1148 action = toolbar->addAction(QIcon(":/icons/playpause.png"),
Chris@0 1149 tr("Play / Pause"));
Chris@0 1150 action->setCheckable(true);
Chris@0 1151 action->setShortcut(tr("Space"));
Chris@0 1152 action->setStatusTip(tr("Start or stop playback from the current position"));
Chris@0 1153 connect(action, SIGNAL(triggered()), this, SLOT(play()));
Chris@0 1154 connect(m_playSource, SIGNAL(playStatusChanged(bool)),
Chris@0 1155 action, SLOT(setChecked(bool)));
Chris@0 1156 connect(this, SIGNAL(canPlay(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1157
Chris@0 1158 action = toolbar->addAction(QIcon(":/icons/ffwd.png"),
Chris@0 1159 tr("Fast Forward"));
Chris@0 1160 action->setShortcut(tr("PageDown"));
Chris@0 1161 action->setStatusTip(tr("Fast forward to the next time instant in the current layer"));
Chris@0 1162 connect(action, SIGNAL(triggered()), this, SLOT(ffwd()));
Chris@0 1163 connect(this, SIGNAL(canFfwd(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1164
Chris@0 1165 action = toolbar->addAction(QIcon(":/icons/ffwd-end.png"),
Chris@0 1166 tr("Fast Forward to End"));
Chris@0 1167 action->setShortcut(tr("End"));
Chris@0 1168 action->setStatusTip(tr("Fast-forward to the end"));
Chris@0 1169 connect(action, SIGNAL(triggered()), this, SLOT(ffwdEnd()));
Chris@0 1170 connect(this, SIGNAL(canPlay(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1171
Chris@0 1172 toolbar = addToolBar(tr("Play Mode Toolbar"));
Chris@0 1173
Chris@0 1174 action = toolbar->addAction(QIcon(":/icons/playselection.png"),
Chris@0 1175 tr("Constrain Playback to Selection"));
Chris@0 1176 action->setCheckable(true);
Chris@0 1177 action->setChecked(m_viewManager->getPlaySelectionMode());
Chris@0 1178 action->setShortcut(tr("s"));
Chris@0 1179 action->setStatusTip(tr("Constrain playback to the selected area"));
Chris@0 1180 connect(action, SIGNAL(triggered()), this, SLOT(playSelectionToggled()));
Chris@0 1181 connect(this, SIGNAL(canPlaySelection(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1182
Chris@0 1183 action = toolbar->addAction(QIcon(":/icons/playloop.png"),
Chris@0 1184 tr("Loop Playback"));
Chris@0 1185 action->setCheckable(true);
Chris@0 1186 action->setChecked(m_viewManager->getPlayLoopMode());
Chris@0 1187 action->setShortcut(tr("l"));
Chris@0 1188 action->setStatusTip(tr("Loop playback"));
Chris@0 1189 connect(action, SIGNAL(triggered()), this, SLOT(playLoopToggled()));
Chris@0 1190 connect(this, SIGNAL(canPlay(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1191
Chris@0 1192 toolbar = addToolBar(tr("Edit Toolbar"));
Chris@0 1193 CommandHistory::getInstance()->registerToolbar(toolbar);
Chris@0 1194
Chris@0 1195 toolbar = addToolBar(tr("Tools Toolbar"));
Chris@0 1196 QActionGroup *group = new QActionGroup(this);
Chris@0 1197
Chris@0 1198 action = toolbar->addAction(QIcon(":/icons/navigate.png"),
Chris@0 1199 tr("Navigate"));
Chris@0 1200 action->setCheckable(true);
Chris@0 1201 action->setChecked(true);
Chris@0 1202 action->setShortcut(tr("1"));
Chris@0 1203 connect(action, SIGNAL(triggered()), this, SLOT(toolNavigateSelected()));
Chris@0 1204 group->addAction(action);
Chris@0 1205 m_toolActions[ViewManager::NavigateMode] = action;
Chris@0 1206
Chris@0 1207 action = toolbar->addAction(QIcon(":/icons/select.png"),
Chris@0 1208 tr("Select"));
Chris@0 1209 action->setCheckable(true);
Chris@0 1210 action->setShortcut(tr("2"));
Chris@0 1211 connect(action, SIGNAL(triggered()), this, SLOT(toolSelectSelected()));
Chris@0 1212 group->addAction(action);
Chris@0 1213 m_toolActions[ViewManager::SelectMode] = action;
Chris@0 1214
Chris@0 1215 action = toolbar->addAction(QIcon(":/icons/move.png"),
Chris@0 1216 tr("Edit"));
Chris@0 1217 action->setCheckable(true);
Chris@0 1218 action->setShortcut(tr("3"));
Chris@0 1219 connect(action, SIGNAL(triggered()), this, SLOT(toolEditSelected()));
Chris@0 1220 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1221 group->addAction(action);
Chris@0 1222 m_toolActions[ViewManager::EditMode] = action;
Chris@0 1223
Chris@0 1224 action = toolbar->addAction(QIcon(":/icons/draw.png"),
Chris@0 1225 tr("Draw"));
Chris@0 1226 action->setCheckable(true);
Chris@0 1227 action->setShortcut(tr("4"));
Chris@0 1228 connect(action, SIGNAL(triggered()), this, SLOT(toolDrawSelected()));
Chris@0 1229 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1230 group->addAction(action);
Chris@0 1231 m_toolActions[ViewManager::DrawMode] = action;
Chris@0 1232
Chris@0 1233 // action = toolbar->addAction(QIcon(":/icons/text.png"),
Chris@0 1234 // tr("Text"));
Chris@0 1235 // action->setCheckable(true);
Chris@0 1236 // action->setShortcut(tr("5"));
Chris@0 1237 // connect(action, SIGNAL(triggered()), this, SLOT(toolTextSelected()));
Chris@0 1238 // group->addAction(action);
Chris@0 1239 // m_toolActions[ViewManager::TextMode] = action;
Chris@0 1240
Chris@0 1241 toolNavigateSelected();
Chris@0 1242 }
Chris@0 1243
Chris@0 1244 void
Chris@0 1245 MainWindow::updateMenuStates()
Chris@0 1246 {
Chris@0 1247 bool haveCurrentPane =
Chris@0 1248 (m_paneStack &&
Chris@0 1249 (m_paneStack->getCurrentPane() != 0));
Chris@0 1250 bool haveCurrentLayer =
Chris@0 1251 (haveCurrentPane &&
Chris@0 1252 (m_paneStack->getCurrentPane()->getSelectedLayer()));
Chris@0 1253 bool haveMainModel =
Chris@0 1254 (getMainModel() != 0);
Chris@0 1255 bool havePlayTarget =
Chris@0 1256 (m_playTarget != 0);
Chris@0 1257 bool haveSelection =
Chris@0 1258 (m_viewManager &&
Chris@0 1259 !m_viewManager->getSelections().empty());
Chris@0 1260 bool haveCurrentEditableLayer =
Chris@0 1261 (haveCurrentLayer &&
Chris@0 1262 m_paneStack->getCurrentPane()->getSelectedLayer()->
Chris@0 1263 isLayerEditable());
Chris@0 1264 bool haveCurrentTimeInstantsLayer =
Chris@0 1265 (haveCurrentLayer &&
Chris@0 1266 dynamic_cast<TimeInstantLayer *>
Chris@0 1267 (m_paneStack->getCurrentPane()->getSelectedLayer()));
Chris@0 1268 bool haveCurrentTimeValueLayer =
Chris@0 1269 (haveCurrentLayer &&
Chris@0 1270 dynamic_cast<TimeValueLayer *>
Chris@0 1271 (m_paneStack->getCurrentPane()->getSelectedLayer()));
Chris@0 1272 bool haveCurrentColour3DPlot =
Chris@0 1273 (haveCurrentLayer &&
Chris@0 1274 dynamic_cast<Colour3DPlotLayer *>
Chris@0 1275 (m_paneStack->getCurrentPane()->getSelectedLayer()));
Chris@0 1276 bool haveClipboardContents =
Chris@0 1277 (m_viewManager &&
Chris@0 1278 !m_viewManager->getClipboard().empty());
Chris@0 1279
Chris@0 1280 emit canAddPane(haveMainModel);
Chris@0 1281 emit canDeleteCurrentPane(haveCurrentPane);
Chris@0 1282 emit canZoom(haveMainModel && haveCurrentPane);
Chris@0 1283 emit canScroll(haveMainModel && haveCurrentPane);
Chris@0 1284 emit canAddLayer(haveMainModel && haveCurrentPane);
Chris@0 1285 emit canImportMoreAudio(haveMainModel);
Chris@0 1286 emit canImportLayer(haveMainModel && haveCurrentPane);
Chris@0 1287 emit canExportAudio(haveMainModel);
Chris@0 1288 emit canExportLayer(haveMainModel &&
Chris@0 1289 (haveCurrentEditableLayer || haveCurrentColour3DPlot));
Chris@0 1290 emit canDeleteCurrentLayer(haveCurrentLayer);
Chris@0 1291 emit canRenameLayer(haveCurrentLayer);
Chris@0 1292 emit canEditLayer(haveCurrentEditableLayer);
Chris@0 1293 emit canSelect(haveMainModel && haveCurrentPane);
Chris@0 1294 emit canPlay(/*!!! haveMainModel && */ havePlayTarget);
Chris@0 1295 emit canFfwd(haveCurrentTimeInstantsLayer || haveCurrentTimeValueLayer);
Chris@0 1296 emit canRewind(haveCurrentTimeInstantsLayer || haveCurrentTimeValueLayer);
Chris@0 1297 emit canPaste(haveCurrentEditableLayer && haveClipboardContents);
Chris@0 1298 emit canInsertInstant(haveCurrentPane);
Chris@0 1299 emit canPlaySelection(haveMainModel && havePlayTarget && haveSelection);
Chris@0 1300 emit canClearSelection(haveSelection);
Chris@0 1301 emit canEditSelection(haveSelection && haveCurrentEditableLayer);
Chris@0 1302 emit canSave(m_sessionFile != "" && m_documentModified);
Chris@0 1303 }
Chris@0 1304
Chris@0 1305 void
Chris@0 1306 MainWindow::updateDescriptionLabel()
Chris@0 1307 {
Chris@0 1308 if (!getMainModel()) {
Chris@0 1309 m_descriptionLabel->setText(tr("No audio file loaded."));
Chris@0 1310 return;
Chris@0 1311 }
Chris@0 1312
Chris@0 1313 QString description;
Chris@0 1314
Chris@0 1315 size_t ssr = getMainModel()->getSampleRate();
Chris@0 1316 size_t tsr = ssr;
Chris@0 1317 if (m_playSource) tsr = m_playSource->getTargetSampleRate();
Chris@0 1318
Chris@0 1319 if (ssr != tsr) {
Chris@0 1320 description = tr("%1Hz (resampling to %2Hz)").arg(ssr).arg(tsr);
Chris@0 1321 } else {
Chris@0 1322 description = QString("%1Hz").arg(ssr);
Chris@0 1323 }
Chris@0 1324
Chris@0 1325 description = QString("%1 - %2")
Chris@0 1326 .arg(RealTime::frame2RealTime(getMainModel()->getEndFrame(), ssr)
Chris@0 1327 .toText(false).c_str())
Chris@0 1328 .arg(description);
Chris@0 1329
Chris@0 1330 m_descriptionLabel->setText(description);
Chris@0 1331 }
Chris@0 1332
Chris@0 1333 void
Chris@0 1334 MainWindow::documentModified()
Chris@0 1335 {
Chris@0 1336 // std::cerr << "MainWindow::documentModified" << std::endl;
Chris@0 1337
Chris@0 1338 if (!m_documentModified) {
Chris@0 1339 setWindowTitle(tr("%1 (modified)").arg(windowTitle()));
Chris@0 1340 }
Chris@0 1341
Chris@0 1342 m_documentModified = true;
Chris@0 1343 updateMenuStates();
Chris@0 1344 }
Chris@0 1345
Chris@0 1346 void
Chris@0 1347 MainWindow::documentRestored()
Chris@0 1348 {
Chris@0 1349 // std::cerr << "MainWindow::documentRestored" << std::endl;
Chris@0 1350
Chris@0 1351 if (m_documentModified) {
Chris@0 1352 QString wt(windowTitle());
Chris@0 1353 wt.replace(tr(" (modified)"), "");
Chris@0 1354 setWindowTitle(wt);
Chris@0 1355 }
Chris@0 1356
Chris@0 1357 m_documentModified = false;
Chris@0 1358 updateMenuStates();
Chris@0 1359 }
Chris@0 1360
Chris@0 1361 void
Chris@0 1362 MainWindow::playLoopToggled()
Chris@0 1363 {
Chris@0 1364 QAction *action = dynamic_cast<QAction *>(sender());
Chris@0 1365
Chris@0 1366 if (action) {
Chris@0 1367 m_viewManager->setPlayLoopMode(action->isChecked());
Chris@0 1368 } else {
Chris@0 1369 m_viewManager->setPlayLoopMode(!m_viewManager->getPlayLoopMode());
Chris@0 1370 }
Chris@0 1371 }
Chris@0 1372
Chris@0 1373 void
Chris@0 1374 MainWindow::playSelectionToggled()
Chris@0 1375 {
Chris@0 1376 QAction *action = dynamic_cast<QAction *>(sender());
Chris@0 1377
Chris@0 1378 if (action) {
Chris@0 1379 m_viewManager->setPlaySelectionMode(action->isChecked());
Chris@0 1380 } else {
Chris@0 1381 m_viewManager->setPlaySelectionMode(!m_viewManager->getPlaySelectionMode());
Chris@0 1382 }
Chris@0 1383 }
Chris@0 1384
Chris@0 1385 void
Chris@0 1386 MainWindow::currentPaneChanged(Pane *)
Chris@0 1387 {
Chris@0 1388 updateMenuStates();
Chris@0 1389 }
Chris@0 1390
Chris@0 1391 void
Chris@0 1392 MainWindow::currentLayerChanged(Pane *, Layer *)
Chris@0 1393 {
Chris@0 1394 updateMenuStates();
Chris@0 1395 }
Chris@0 1396
Chris@0 1397 void
Chris@0 1398 MainWindow::toolNavigateSelected()
Chris@0 1399 {
Chris@0 1400 m_viewManager->setToolMode(ViewManager::NavigateMode);
Chris@0 1401 }
Chris@0 1402
Chris@0 1403 void
Chris@0 1404 MainWindow::toolSelectSelected()
Chris@0 1405 {
Chris@0 1406 m_viewManager->setToolMode(ViewManager::SelectMode);
Chris@0 1407 }
Chris@0 1408
Chris@0 1409 void
Chris@0 1410 MainWindow::toolEditSelected()
Chris@0 1411 {
Chris@0 1412 m_viewManager->setToolMode(ViewManager::EditMode);
Chris@0 1413 }
Chris@0 1414
Chris@0 1415 void
Chris@0 1416 MainWindow::toolDrawSelected()
Chris@0 1417 {
Chris@0 1418 m_viewManager->setToolMode(ViewManager::DrawMode);
Chris@0 1419 }
Chris@0 1420
Chris@0 1421 //void
Chris@0 1422 //MainWindow::toolTextSelected()
Chris@0 1423 //{
Chris@0 1424 // m_viewManager->setToolMode(ViewManager::TextMode);
Chris@0 1425 //}
Chris@0 1426
Chris@0 1427 void
Chris@0 1428 MainWindow::selectAll()
Chris@0 1429 {
Chris@0 1430 if (!getMainModel()) return;
Chris@0 1431 m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(),
Chris@0 1432 getMainModel()->getEndFrame()));
Chris@0 1433 }
Chris@0 1434
Chris@0 1435 void
Chris@0 1436 MainWindow::selectToStart()
Chris@0 1437 {
Chris@0 1438 if (!getMainModel()) return;
Chris@0 1439 m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(),
Chris@0 1440 m_viewManager->getGlobalCentreFrame()));
Chris@0 1441 }
Chris@0 1442
Chris@0 1443 void
Chris@0 1444 MainWindow::selectToEnd()
Chris@0 1445 {
Chris@0 1446 if (!getMainModel()) return;
Chris@0 1447 m_viewManager->setSelection(Selection(m_viewManager->getGlobalCentreFrame(),
Chris@0 1448 getMainModel()->getEndFrame()));
Chris@0 1449 }
Chris@0 1450
Chris@0 1451 void
Chris@0 1452 MainWindow::selectVisible()
Chris@0 1453 {
Chris@0 1454 Model *model = getMainModel();
Chris@0 1455 if (!model) return;
Chris@0 1456
Chris@0 1457 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 1458 if (!currentPane) return;
Chris@0 1459
Chris@0 1460 size_t startFrame, endFrame;
Chris@0 1461
Chris@0 1462 if (currentPane->getStartFrame() < 0) startFrame = 0;
Chris@0 1463 else startFrame = currentPane->getStartFrame();
Chris@0 1464
Chris@0 1465 if (currentPane->getEndFrame() > model->getEndFrame()) endFrame = model->getEndFrame();
Chris@0 1466 else endFrame = currentPane->getEndFrame();
Chris@0 1467
Chris@0 1468 m_viewManager->setSelection(Selection(startFrame, endFrame));
Chris@0 1469 }
Chris@0 1470
Chris@0 1471 void
Chris@0 1472 MainWindow::clearSelection()
Chris@0 1473 {
Chris@0 1474 m_viewManager->clearSelections();
Chris@0 1475 }
Chris@0 1476
Chris@0 1477 void
Chris@0 1478 MainWindow::cut()
Chris@0 1479 {
Chris@0 1480 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 1481 if (!currentPane) return;
Chris@0 1482
Chris@0 1483 Layer *layer = currentPane->getSelectedLayer();
Chris@0 1484 if (!layer) return;
Chris@0 1485
Chris@0 1486 Clipboard &clipboard = m_viewManager->getClipboard();
Chris@0 1487 clipboard.clear();
Chris@0 1488
Chris@0 1489 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@0 1490
Chris@0 1491 CommandHistory::getInstance()->startCompoundOperation(tr("Cut"), true);
Chris@0 1492
Chris@0 1493 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@0 1494 i != selections.end(); ++i) {
Chris@0 1495 layer->copy(*i, clipboard);
Chris@0 1496 layer->deleteSelection(*i);
Chris@0 1497 }
Chris@0 1498
Chris@0 1499 CommandHistory::getInstance()->endCompoundOperation();
Chris@0 1500 }
Chris@0 1501
Chris@0 1502 void
Chris@0 1503 MainWindow::copy()
Chris@0 1504 {
Chris@0 1505 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 1506 if (!currentPane) return;
Chris@0 1507
Chris@0 1508 Layer *layer = currentPane->getSelectedLayer();
Chris@0 1509 if (!layer) return;
Chris@0 1510
Chris@0 1511 Clipboard &clipboard = m_viewManager->getClipboard();
Chris@0 1512 clipboard.clear();
Chris@0 1513
Chris@0 1514 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@0 1515
Chris@0 1516 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@0 1517 i != selections.end(); ++i) {
Chris@0 1518 layer->copy(*i, clipboard);
Chris@0 1519 }
Chris@0 1520 }
Chris@0 1521
Chris@0 1522 void
Chris@0 1523 MainWindow::paste()
Chris@0 1524 {
Chris@0 1525 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 1526 if (!currentPane) return;
Chris@0 1527
Chris@0 1528 //!!! if we have no current layer, we should create one of the most
Chris@0 1529 // appropriate type
Chris@0 1530
Chris@0 1531 Layer *layer = currentPane->getSelectedLayer();
Chris@0 1532 if (!layer) return;
Chris@0 1533
Chris@0 1534 Clipboard &clipboard = m_viewManager->getClipboard();
Chris@0 1535 Clipboard::PointList contents = clipboard.getPoints();
Chris@0 1536 /*
Chris@0 1537 long minFrame = 0;
Chris@0 1538 bool have = false;
Chris@0 1539 for (int i = 0; i < contents.size(); ++i) {
Chris@0 1540 if (!contents[i].haveFrame()) continue;
Chris@0 1541 if (!have || contents[i].getFrame() < minFrame) {
Chris@0 1542 minFrame = contents[i].getFrame();
Chris@0 1543 have = true;
Chris@0 1544 }
Chris@0 1545 }
Chris@0 1546
Chris@0 1547 long frameOffset = long(m_viewManager->getGlobalCentreFrame()) - minFrame;
Chris@0 1548
Chris@0 1549 layer->paste(clipboard, frameOffset);
Chris@0 1550 */
Chris@0 1551 layer->paste(clipboard, 0, true);
Chris@0 1552 }
Chris@0 1553
Chris@0 1554 void
Chris@0 1555 MainWindow::deleteSelected()
Chris@0 1556 {
Chris@0 1557 if (m_paneStack->getCurrentPane() &&
Chris@0 1558 m_paneStack->getCurrentPane()->getSelectedLayer()) {
Chris@0 1559
Chris@0 1560 MultiSelection::SelectionList selections =
Chris@0 1561 m_viewManager->getSelections();
Chris@0 1562
Chris@0 1563 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@0 1564 i != selections.end(); ++i) {
Chris@0 1565
Chris@0 1566 m_paneStack->getCurrentPane()->getSelectedLayer()->deleteSelection(*i);
Chris@0 1567 }
Chris@0 1568 }
Chris@0 1569 }
Chris@0 1570
Chris@0 1571 void
Chris@0 1572 MainWindow::insertInstant()
Chris@0 1573 {
Chris@0 1574 int frame = m_viewManager->getPlaybackFrame();
Chris@0 1575
Chris@0 1576 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 1577 if (!pane) {
Chris@0 1578 return;
Chris@0 1579 }
Chris@0 1580
Chris@0 1581 Layer *layer = dynamic_cast<TimeInstantLayer *>
Chris@0 1582 (pane->getSelectedLayer());
Chris@0 1583
Chris@0 1584 if (!layer) {
Chris@0 1585 for (int i = pane->getLayerCount(); i > 0; --i) {
Chris@0 1586 layer = dynamic_cast<TimeInstantLayer *>(pane->getLayer(i - 1));
Chris@0 1587 if (layer) break;
Chris@0 1588 }
Chris@0 1589
Chris@0 1590 if (!layer) {
Chris@0 1591 CommandHistory::getInstance()->startCompoundOperation
Chris@0 1592 (tr("Add Point"), true);
Chris@0 1593 layer = m_document->createEmptyLayer(LayerFactory::TimeInstants);
Chris@0 1594 if (layer) {
Chris@0 1595 m_document->addLayerToView(pane, layer);
Chris@0 1596 m_paneStack->setCurrentLayer(pane, layer);
Chris@0 1597 }
Chris@0 1598 CommandHistory::getInstance()->endCompoundOperation();
Chris@0 1599 }
Chris@0 1600 }
Chris@0 1601
Chris@0 1602 if (layer) {
Chris@0 1603
Chris@0 1604 Model *model = layer->getModel();
Chris@0 1605 SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *>
Chris@0 1606 (model);
Chris@0 1607
Chris@0 1608 if (sodm) {
Chris@0 1609 SparseOneDimensionalModel::Point point
Chris@0 1610 (frame, QString("%1").arg(sodm->getPointCount() + 1));
Chris@0 1611 CommandHistory::getInstance()->addCommand
Chris@0 1612 (new SparseOneDimensionalModel::AddPointCommand(sodm, point,
Chris@0 1613 tr("Add Points")),
Chris@0 1614 true, true); // bundled
Chris@0 1615 }
Chris@0 1616 }
Chris@0 1617 }
Chris@0 1618
Chris@0 1619 void
Chris@0 1620 MainWindow::importAudio()
Chris@0 1621 {
Chris@0 1622 QString orig = m_audioFile;
Chris@0 1623
Chris@0 1624 // std::cerr << "orig = " << orig.toStdString() << std::endl;
Chris@0 1625
Chris@0 1626 if (orig == "") orig = ".";
Chris@0 1627
Chris@0 1628 QString path = QFileDialog::getOpenFileName
Chris@0 1629 (this, tr("Select an audio file"), orig,
Chris@0 1630 tr("Audio files (%1)\nAll files (*.*)")
Chris@0 1631 .arg(AudioFileReaderFactory::getKnownExtensions()));
Chris@0 1632
Chris@0 1633 if (path != "") {
Chris@0 1634 if (!openAudioFile(path, ReplaceMainModel)) {
Chris@0 1635 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 1636 tr("Audio file \"%1\" could not be opened").arg(path));
Chris@0 1637 }
Chris@0 1638 }
Chris@0 1639 }
Chris@0 1640
Chris@0 1641 void
Chris@0 1642 MainWindow::importMoreAudio()
Chris@0 1643 {
Chris@0 1644 QString orig = m_audioFile;
Chris@0 1645
Chris@0 1646 // std::cerr << "orig = " << orig.toStdString() << std::endl;
Chris@0 1647
Chris@0 1648 if (orig == "") orig = ".";
Chris@0 1649
Chris@0 1650 QString path = QFileDialog::getOpenFileName
Chris@0 1651 (this, tr("Select an audio file"), orig,
Chris@0 1652 tr("Audio files (%1)\nAll files (*.*)")
Chris@0 1653 .arg(AudioFileReaderFactory::getKnownExtensions()));
Chris@0 1654
Chris@0 1655 if (path != "") {
Chris@0 1656 if (!openAudioFile(path, CreateAdditionalModel)) {
Chris@0 1657 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 1658 tr("Audio file \"%1\" could not be opened").arg(path));
Chris@0 1659 }
Chris@0 1660 }
Chris@0 1661 }
Chris@0 1662
Chris@0 1663 void
Chris@0 1664 MainWindow::exportAudio()
Chris@0 1665 {
Chris@0 1666 if (!getMainModel()) return;
Chris@0 1667
Chris@0 1668 QString path = QFileDialog::getSaveFileName
Chris@0 1669 (this, tr("Select a file to export to"), ".",
Chris@0 1670 tr("WAV audio files (*.wav)\nAll files (*.*)"));
Chris@0 1671
Chris@0 1672 if (path == "") return;
Chris@0 1673
Chris@0 1674 if (!path.endsWith(".wav")) path = path + ".wav";
Chris@0 1675
Chris@0 1676 bool ok = false;
Chris@0 1677 QString error;
Chris@0 1678
Chris@0 1679 MultiSelection ms = m_viewManager->getSelection();
Chris@0 1680 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@0 1681
Chris@0 1682 bool multiple = false;
Chris@0 1683
Chris@38 1684 MultiSelection *selectionToWrite = 0;
Chris@38 1685
Chris@38 1686 if (selections.size() == 1) {
Chris@0 1687
Chris@0 1688 QStringList items;
Chris@0 1689 items << tr("Export the selected region only")
Chris@0 1690 << tr("Export the whole audio file");
Chris@0 1691
Chris@0 1692 bool ok = false;
Chris@0 1693 QString item = ListInputDialog::getItem
Chris@0 1694 (this, tr("Select region to export"),
Chris@0 1695 tr("Which region from the original audio file do you want to export?"),
Chris@0 1696 items, 0, &ok);
Chris@0 1697
Chris@0 1698 if (!ok || item.isEmpty()) return;
Chris@0 1699
Chris@38 1700 if (item == items[0]) selectionToWrite = &ms;
Chris@38 1701
Chris@38 1702 } else if (selections.size() > 1) {
Chris@0 1703
Chris@0 1704 QStringList items;
Chris@0 1705 items << tr("Export the selected regions into a single audio file")
Chris@0 1706 << tr("Export the selected regions into separate files")
Chris@0 1707 << tr("Export the whole audio file");
Chris@0 1708
Chris@0 1709 QString item = ListInputDialog::getItem
Chris@0 1710 (this, tr("Select region to export"),
Chris@0 1711 tr("Multiple regions of the original audio file are selected.\nWhat do you want to export?"),
Chris@0 1712 items, 0, &ok);
Chris@0 1713
Chris@0 1714 if (!ok || item.isEmpty()) return;
Chris@0 1715
Chris@0 1716 if (item == items[0]) {
Chris@0 1717
Chris@38 1718 selectionToWrite = &ms;
Chris@38 1719
Chris@38 1720 } else if (item == items[1]) {
Chris@0 1721
Chris@0 1722 multiple = true;
Chris@0 1723
Chris@0 1724 int n = 1;
Chris@0 1725 QString base = path;
Chris@0 1726 base.replace(".wav", "");
Chris@0 1727
Chris@0 1728 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@0 1729 i != selections.end(); ++i) {
Chris@0 1730
Chris@0 1731 MultiSelection subms;
Chris@0 1732 subms.setSelection(*i);
Chris@0 1733
Chris@0 1734 QString subpath = QString("%1.%2.wav").arg(base).arg(n);
Chris@0 1735 ++n;
Chris@0 1736
Chris@0 1737 if (QFileInfo(subpath).exists()) {
Chris@0 1738 error = tr("Fragment file %1 already exists, aborting").arg(subpath);
Chris@0 1739 break;
Chris@0 1740 }
Chris@0 1741
Chris@38 1742 WavFileWriter subwriter(subpath,
Chris@38 1743 getMainModel()->getSampleRate(),
Chris@38 1744 getMainModel()->getChannelCount());
Chris@38 1745 subwriter.writeModel(getMainModel(), &subms);
Chris@0 1746 ok = subwriter.isOK();
Chris@0 1747
Chris@0 1748 if (!ok) {
Chris@0 1749 error = subwriter.getError();
Chris@0 1750 break;
Chris@0 1751 }
Chris@0 1752 }
Chris@0 1753 }
Chris@0 1754 }
Chris@0 1755
Chris@38 1756 if (!multiple) {
Chris@38 1757 WavFileWriter writer(path,
Chris@38 1758 getMainModel()->getSampleRate(),
Chris@38 1759 getMainModel()->getChannelCount());
Chris@38 1760 writer.writeModel(getMainModel(), selectionToWrite);
Chris@38 1761 ok = writer.isOK();
Chris@38 1762 error = writer.getError();
Chris@0 1763 }
Chris@0 1764
Chris@0 1765 if (ok) {
Chris@0 1766 if (!multiple) {
Chris@34 1767 m_recentFiles.addFile(path);
Chris@0 1768 }
Chris@0 1769 } else {
Chris@0 1770 QMessageBox::critical(this, tr("Failed to write file"), error);
Chris@0 1771 }
Chris@0 1772 }
Chris@0 1773
Chris@0 1774 void
Chris@0 1775 MainWindow::importLayer()
Chris@0 1776 {
Chris@0 1777 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 1778
Chris@0 1779 if (!pane) {
Chris@0 1780 // shouldn't happen, as the menu action should have been disabled
Chris@0 1781 std::cerr << "WARNING: MainWindow::importLayer: no current pane" << std::endl;
Chris@0 1782 return;
Chris@0 1783 }
Chris@0 1784
Chris@0 1785 if (!getMainModel()) {
Chris@0 1786 // shouldn't happen, as the menu action should have been disabled
Chris@0 1787 std::cerr << "WARNING: MainWindow::importLayer: No main model -- hence no default sample rate available" << std::endl;
Chris@0 1788 return;
Chris@0 1789 }
Chris@0 1790
Chris@0 1791 QString path = QFileDialog::getOpenFileName
Chris@0 1792 (this, tr("Select file"), ".",
Chris@0 1793 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@0 1794
Chris@0 1795 if (path != "") {
Chris@0 1796
Chris@0 1797 if (!openLayerFile(path)) {
Chris@0 1798 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 1799 tr("File %1 could not be opened.").arg(path));
Chris@0 1800 return;
Chris@0 1801 }
Chris@0 1802 }
Chris@0 1803 }
Chris@0 1804
Chris@0 1805 bool
Chris@0 1806 MainWindow::openLayerFile(QString path)
Chris@0 1807 {
Chris@0 1808 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 1809
Chris@0 1810 if (!pane) {
Chris@0 1811 // shouldn't happen, as the menu action should have been disabled
Chris@0 1812 std::cerr << "WARNING: MainWindow::openLayerFile: no current pane" << std::endl;
Chris@0 1813 return false;
Chris@0 1814 }
Chris@0 1815
Chris@0 1816 if (!getMainModel()) {
Chris@0 1817 // shouldn't happen, as the menu action should have been disabled
Chris@0 1818 std::cerr << "WARNING: MainWindow::openLayerFile: No main model -- hence no default sample rate available" << std::endl;
Chris@0 1819 return false;
Chris@0 1820 }
Chris@0 1821
Chris@0 1822 if (path.endsWith(".svl") || path.endsWith(".xml")) {
Chris@0 1823
Chris@0 1824 PaneCallback callback(this);
Chris@0 1825 QFile file(path);
Chris@0 1826
Chris@0 1827 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
Chris@0 1828 std::cerr << "ERROR: MainWindow::openLayerFile("
Chris@0 1829 << path.toStdString()
Chris@0 1830 << "): Failed to open file for reading" << std::endl;
Chris@0 1831 return false;
Chris@0 1832 }
Chris@0 1833
Chris@0 1834 SVFileReader reader(m_document, callback);
Chris@0 1835 reader.setCurrentPane(pane);
Chris@0 1836
Chris@0 1837 QXmlInputSource inputSource(&file);
Chris@0 1838 reader.parse(inputSource);
Chris@0 1839
Chris@0 1840 if (!reader.isOK()) {
Chris@0 1841 std::cerr << "ERROR: MainWindow::openLayerFile("
Chris@0 1842 << path.toStdString()
Chris@0 1843 << "): Failed to read XML file: "
Chris@0 1844 << reader.getErrorString().toStdString() << std::endl;
Chris@0 1845 return false;
Chris@0 1846 }
Chris@0 1847
Chris@34 1848 m_recentFiles.addFile(path);
Chris@0 1849 return true;
Chris@0 1850
Chris@0 1851 } else {
Chris@0 1852
Chris@0 1853 Model *model = DataFileReaderFactory::load(path, getMainModel()->getSampleRate());
Chris@0 1854
Chris@0 1855 if (model) {
Chris@0 1856 Layer *newLayer = m_document->createImportedLayer(model);
Chris@0 1857 if (newLayer) {
Chris@0 1858 m_document->addLayerToView(pane, newLayer);
Chris@34 1859 m_recentFiles.addFile(path);
Chris@0 1860 return true;
Chris@0 1861 }
Chris@0 1862 }
Chris@0 1863 }
Chris@0 1864
Chris@0 1865 return false;
Chris@0 1866 }
Chris@0 1867
Chris@0 1868 void
Chris@0 1869 MainWindow::exportLayer()
Chris@0 1870 {
Chris@0 1871 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 1872 if (!pane) return;
Chris@0 1873
Chris@0 1874 Layer *layer = pane->getSelectedLayer();
Chris@0 1875 if (!layer) return;
Chris@0 1876
Chris@0 1877 Model *model = layer->getModel();
Chris@0 1878 if (!model) return;
Chris@0 1879
Chris@0 1880 QString path = QFileDialog::getSaveFileName
Chris@0 1881 (this, tr("Select a file to export to"), ".",
Chris@0 1882 tr("Sonic Visualiser Layer XML files (*.svl)\nComma-separated data files (*.csv)\nText files (*.txt)\nAll files (*.*)"));
Chris@0 1883
Chris@0 1884 if (path == "") return;
Chris@0 1885
Chris@0 1886 if (QFileInfo(path).suffix() == "") path += ".svl";
Chris@0 1887
Chris@0 1888 QString error;
Chris@0 1889
Chris@0 1890 if (path.endsWith(".xml") || path.endsWith(".svl")) {
Chris@0 1891
Chris@0 1892 QFile file(path);
Chris@0 1893 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
Chris@0 1894 error = tr("Failed to open file %1 for writing").arg(path);
Chris@0 1895 } else {
Chris@0 1896 QTextStream out(&file);
Chris@0 1897 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
Chris@0 1898 << "<!DOCTYPE sonic-visualiser>\n"
Chris@0 1899 << "<sv>\n"
Chris@0 1900 << " <data>\n";
Chris@0 1901
Chris@0 1902 model->toXml(out, " ");
Chris@0 1903
Chris@0 1904 out << " </data>\n"
Chris@0 1905 << " <display>\n";
Chris@0 1906
Chris@0 1907 layer->toXml(out, " ");
Chris@0 1908
Chris@0 1909 out << " </display>\n"
Chris@0 1910 << "</sv>\n";
Chris@0 1911 }
Chris@0 1912
Chris@0 1913 } else {
Chris@0 1914
Chris@0 1915 CSVFileWriter writer(path, model,
Chris@0 1916 (path.endsWith(".csv") ? "," : "\t"));
Chris@0 1917 writer.write();
Chris@0 1918
Chris@0 1919 if (!writer.isOK()) {
Chris@0 1920 error = writer.getError();
Chris@0 1921 }
Chris@0 1922 }
Chris@0 1923
Chris@0 1924 if (error != "") {
Chris@0 1925 QMessageBox::critical(this, tr("Failed to write file"), error);
Chris@0 1926 } else {
Chris@34 1927 m_recentFiles.addFile(path);
Chris@0 1928 }
Chris@0 1929 }
Chris@0 1930
Chris@0 1931 bool
Chris@0 1932 MainWindow::openAudioFile(QString path, AudioFileOpenMode mode)
Chris@0 1933 {
Chris@0 1934 if (!(QFileInfo(path).exists() &&
Chris@0 1935 QFileInfo(path).isFile() &&
Chris@0 1936 QFileInfo(path).isReadable())) {
Chris@0 1937 return false;
Chris@0 1938 }
Chris@0 1939
Chris@0 1940 WaveFileModel *newModel = new WaveFileModel(path);
Chris@0 1941
Chris@0 1942 if (!newModel->isOK()) {
Chris@0 1943 delete newModel;
Chris@0 1944 return false;
Chris@0 1945 }
Chris@0 1946
Chris@0 1947 bool setAsMain = true;
Chris@0 1948 static bool prevSetAsMain = true;
Chris@0 1949
Chris@0 1950 if (mode == CreateAdditionalModel) setAsMain = false;
Chris@0 1951 else if (mode == AskUser) {
Chris@0 1952 if (m_document->getMainModel()) {
Chris@0 1953
Chris@0 1954 QStringList items;
Chris@0 1955 items << tr("Replace the existing main waveform")
Chris@0 1956 << tr("Load this file into a new waveform pane");
Chris@0 1957
Chris@0 1958 bool ok = false;
Chris@0 1959 QString item = ListInputDialog::getItem
Chris@0 1960 (this, tr("Select target for import"),
Chris@0 1961 tr("You already have an audio waveform loaded.\nWhat would you like to do with the new audio file?"),
Chris@0 1962 items, prevSetAsMain ? 0 : 1, &ok);
Chris@0 1963
Chris@0 1964 if (!ok || item.isEmpty()) {
Chris@0 1965 delete newModel;
Chris@0 1966 return false;
Chris@0 1967 }
Chris@0 1968
Chris@0 1969 setAsMain = (item == items[0]);
Chris@0 1970 prevSetAsMain = setAsMain;
Chris@0 1971 }
Chris@0 1972 }
Chris@0 1973
Chris@0 1974 if (setAsMain) {
Chris@0 1975
Chris@0 1976 Model *prevMain = getMainModel();
Chris@0 1977 if (prevMain) m_playSource->removeModel(prevMain);
Chris@0 1978
Chris@0 1979 PlayParameterRepository::getInstance()->clear();
Chris@0 1980
Chris@0 1981 // The clear() call will have removed the parameters for the
Chris@0 1982 // main model. Re-add them with the new one.
Chris@0 1983 PlayParameterRepository::getInstance()->addModel(newModel);
Chris@0 1984
Chris@0 1985 m_document->setMainModel(newModel);
Chris@0 1986 setupMenus();
Chris@0 1987
Chris@0 1988 if (m_sessionFile == "") {
Chris@0 1989 setWindowTitle(tr("Sonic Visualiser: %1")
Chris@0 1990 .arg(QFileInfo(path).fileName()));
Chris@0 1991 CommandHistory::getInstance()->clear();
Chris@0 1992 CommandHistory::getInstance()->documentSaved();
Chris@0 1993 m_documentModified = false;
Chris@0 1994 } else {
Chris@0 1995 setWindowTitle(tr("Sonic Visualiser: %1 [%2]")
Chris@0 1996 .arg(QFileInfo(m_sessionFile).fileName())
Chris@0 1997 .arg(QFileInfo(path).fileName()));
Chris@0 1998 if (m_documentModified) {
Chris@0 1999 m_documentModified = false;
Chris@0 2000 documentModified(); // so as to restore "(modified)" window title
Chris@0 2001 }
Chris@0 2002 }
Chris@0 2003
Chris@0 2004 m_audioFile = path;
Chris@0 2005
Chris@0 2006 } else { // !setAsMain
Chris@0 2007
Chris@0 2008 CommandHistory::getInstance()->startCompoundOperation
Chris@0 2009 (tr("Import \"%1\"").arg(QFileInfo(path).fileName()), true);
Chris@0 2010
Chris@0 2011 m_document->addImportedModel(newModel);
Chris@0 2012
Chris@0 2013 AddPaneCommand *command = new AddPaneCommand(this);
Chris@0 2014 CommandHistory::getInstance()->addCommand(command);
Chris@0 2015
Chris@0 2016 Pane *pane = command->getPane();
Chris@0 2017
Chris@0 2018 if (!m_timeRulerLayer) {
Chris@0 2019 m_timeRulerLayer = m_document->createMainModelLayer
Chris@0 2020 (LayerFactory::TimeRuler);
Chris@0 2021 }
Chris@0 2022
Chris@0 2023 m_document->addLayerToView(pane, m_timeRulerLayer);
Chris@0 2024
Chris@0 2025 Layer *newLayer = m_document->createImportedLayer(newModel);
Chris@0 2026
Chris@0 2027 if (newLayer) {
Chris@0 2028 m_document->addLayerToView(pane, newLayer);
Chris@0 2029 }
Chris@0 2030
Chris@0 2031 CommandHistory::getInstance()->endCompoundOperation();
Chris@0 2032 }
Chris@0 2033
Chris@0 2034 updateMenuStates();
Chris@34 2035 m_recentFiles.addFile(path);
Chris@0 2036
Chris@0 2037 return true;
Chris@0 2038 }
Chris@0 2039
Chris@0 2040 void
Chris@0 2041 MainWindow::createPlayTarget()
Chris@0 2042 {
Chris@0 2043 if (m_playTarget) return;
Chris@0 2044
Chris@0 2045 m_playTarget = AudioTargetFactory::createCallbackTarget(m_playSource);
Chris@0 2046 if (!m_playTarget) {
Chris@0 2047 QMessageBox::warning
Chris@0 2048 (this, tr("Couldn't open audio device"),
Chris@0 2049 tr("Could not open an audio device for playback.\nAudio playback will not be available during this session.\n"),
Chris@0 2050 QMessageBox::Ok, 0);
Chris@0 2051 }
Chris@0 2052 connect(m_fader, SIGNAL(valueChanged(float)),
Chris@0 2053 m_playTarget, SLOT(setOutputGain(float)));
Chris@0 2054 }
Chris@0 2055
Chris@0 2056 WaveFileModel *
Chris@0 2057 MainWindow::getMainModel()
Chris@0 2058 {
Chris@0 2059 if (!m_document) return 0;
Chris@0 2060 return m_document->getMainModel();
Chris@0 2061 }
Chris@0 2062
Chris@0 2063 void
Chris@0 2064 MainWindow::newSession()
Chris@0 2065 {
Chris@0 2066 if (!checkSaveModified()) return;
Chris@0 2067
Chris@0 2068 closeSession();
Chris@0 2069 createDocument();
Chris@0 2070
Chris@0 2071 Pane *pane = m_paneStack->addPane();
Chris@0 2072
Chris@0 2073 if (!m_timeRulerLayer) {
Chris@0 2074 m_timeRulerLayer = m_document->createMainModelLayer
Chris@0 2075 (LayerFactory::TimeRuler);
Chris@0 2076 }
Chris@0 2077
Chris@0 2078 m_document->addLayerToView(pane, m_timeRulerLayer);
Chris@0 2079
Chris@0 2080 Layer *waveform = m_document->createMainModelLayer(LayerFactory::Waveform);
Chris@0 2081 m_document->addLayerToView(pane, waveform);
Chris@0 2082
Chris@0 2083 m_panner->registerView(pane);
Chris@0 2084
Chris@0 2085 CommandHistory::getInstance()->clear();
Chris@0 2086 CommandHistory::getInstance()->documentSaved();
Chris@0 2087 documentRestored();
Chris@0 2088 updateMenuStates();
Chris@0 2089 }
Chris@0 2090
Chris@0 2091 void
Chris@0 2092 MainWindow::createDocument()
Chris@0 2093 {
Chris@0 2094 m_document = new Document;
Chris@0 2095
Chris@0 2096 connect(m_document, SIGNAL(layerAdded(Layer *)),
Chris@0 2097 this, SLOT(layerAdded(Layer *)));
Chris@0 2098 connect(m_document, SIGNAL(layerRemoved(Layer *)),
Chris@0 2099 this, SLOT(layerRemoved(Layer *)));
Chris@0 2100 connect(m_document, SIGNAL(layerAboutToBeDeleted(Layer *)),
Chris@0 2101 this, SLOT(layerAboutToBeDeleted(Layer *)));
Chris@0 2102 connect(m_document, SIGNAL(layerInAView(Layer *, bool)),
Chris@0 2103 this, SLOT(layerInAView(Layer *, bool)));
Chris@0 2104
Chris@0 2105 connect(m_document, SIGNAL(modelAdded(Model *)),
Chris@0 2106 this, SLOT(modelAdded(Model *)));
Chris@0 2107 connect(m_document, SIGNAL(mainModelChanged(WaveFileModel *)),
Chris@0 2108 this, SLOT(mainModelChanged(WaveFileModel *)));
Chris@0 2109 connect(m_document, SIGNAL(modelAboutToBeDeleted(Model *)),
Chris@0 2110 this, SLOT(modelAboutToBeDeleted(Model *)));
Chris@0 2111
Chris@0 2112 connect(m_document, SIGNAL(modelGenerationFailed(QString)),
Chris@0 2113 this, SLOT(modelGenerationFailed(QString)));
Chris@0 2114 connect(m_document, SIGNAL(modelRegenerationFailed(QString)),
Chris@0 2115 this, SLOT(modelRegenerationFailed(QString)));
Chris@0 2116 }
Chris@0 2117
Chris@0 2118 void
Chris@0 2119 MainWindow::closeSession()
Chris@0 2120 {
Chris@0 2121 if (!checkSaveModified()) return;
Chris@0 2122
Chris@0 2123 while (m_paneStack->getPaneCount() > 0) {
Chris@0 2124
Chris@0 2125 Pane *pane = m_paneStack->getPane(m_paneStack->getPaneCount() - 1);
Chris@0 2126
Chris@0 2127 while (pane->getLayerCount() > 0) {
Chris@0 2128 m_document->removeLayerFromView
Chris@0 2129 (pane, pane->getLayer(pane->getLayerCount() - 1));
Chris@0 2130 }
Chris@0 2131
Chris@0 2132 m_panner->unregisterView(pane);
Chris@0 2133 m_paneStack->deletePane(pane);
Chris@0 2134 }
Chris@0 2135
Chris@0 2136 while (m_paneStack->getHiddenPaneCount() > 0) {
Chris@0 2137
Chris@0 2138 Pane *pane = m_paneStack->getHiddenPane
Chris@0 2139 (m_paneStack->getHiddenPaneCount() - 1);
Chris@0 2140
Chris@0 2141 while (pane->getLayerCount() > 0) {
Chris@0 2142 m_document->removeLayerFromView
Chris@0 2143 (pane, pane->getLayer(pane->getLayerCount() - 1));
Chris@0 2144 }
Chris@0 2145
Chris@0 2146 m_panner->unregisterView(pane);
Chris@0 2147 m_paneStack->deletePane(pane);
Chris@0 2148 }
Chris@0 2149
Chris@0 2150 delete m_document;
Chris@0 2151 m_document = 0;
Chris@0 2152 m_viewManager->clearSelections();
Chris@0 2153 m_timeRulerLayer = 0; // document owned this
Chris@0 2154
Chris@0 2155 m_sessionFile = "";
Chris@0 2156 setWindowTitle(tr("Sonic Visualiser"));
Chris@0 2157
Chris@0 2158 CommandHistory::getInstance()->clear();
Chris@0 2159 CommandHistory::getInstance()->documentSaved();
Chris@0 2160 documentRestored();
Chris@0 2161 }
Chris@0 2162
Chris@0 2163 void
Chris@0 2164 MainWindow::openSession()
Chris@0 2165 {
Chris@0 2166 if (!checkSaveModified()) return;
Chris@0 2167
Chris@0 2168 QString orig = m_audioFile;
Chris@0 2169 if (orig == "") orig = ".";
Chris@0 2170 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 2171
Chris@0 2172 QString path = QFileDialog::getOpenFileName
Chris@0 2173 (this, tr("Select a session file"), orig,
Chris@0 2174 tr("Sonic Visualiser session files (*.sv)\nAll files (*.*)"));
Chris@0 2175
Chris@0 2176 if (path.isEmpty()) return;
Chris@0 2177
Chris@0 2178 if (!(QFileInfo(path).exists() &&
Chris@0 2179 QFileInfo(path).isFile() &&
Chris@0 2180 QFileInfo(path).isReadable())) {
Chris@0 2181 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 2182 tr("File \"%1\" does not exist or is not a readable file").arg(path));
Chris@0 2183 return;
Chris@0 2184 }
Chris@0 2185
Chris@0 2186 if (!openSessionFile(path)) {
Chris@0 2187 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 2188 tr("Session file \"%1\" could not be opened").arg(path));
Chris@0 2189 }
Chris@0 2190 }
Chris@0 2191
Chris@0 2192 void
Chris@0 2193 MainWindow::openSomething()
Chris@0 2194 {
Chris@0 2195 QString orig = m_audioFile;
Chris@0 2196 if (orig == "") orig = ".";
Chris@0 2197 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 2198
Chris@0 2199 bool canImportLayer = (getMainModel() != 0 &&
Chris@0 2200 m_paneStack != 0 &&
Chris@0 2201 m_paneStack->getCurrentPane() != 0);
Chris@0 2202
Chris@0 2203 QString importSpec;
Chris@0 2204
Chris@0 2205 if (canImportLayer) {
Chris@0 2206 importSpec = tr("All supported files (*.sv %1 %2)\nSonic Visualiser session files (*.sv)\nAudio files (%1)\nLayer files (%2)\nAll files (*.*)")
Chris@0 2207 .arg(AudioFileReaderFactory::getKnownExtensions())
Chris@0 2208 .arg(DataFileReaderFactory::getKnownExtensions());
Chris@0 2209 } else {
Chris@0 2210 importSpec = tr("All supported files (*.sv %1)\nSonic Visualiser session files (*.sv)\nAudio files (%1)\nAll files (*.*)")
Chris@0 2211 .arg(AudioFileReaderFactory::getKnownExtensions());
Chris@0 2212 }
Chris@0 2213
Chris@0 2214 QString path = QFileDialog::getOpenFileName
Chris@0 2215 (this, tr("Select a file to open"), orig, importSpec);
Chris@0 2216
Chris@0 2217 if (path.isEmpty()) return;
Chris@0 2218
Chris@0 2219 if (!(QFileInfo(path).exists() &&
Chris@0 2220 QFileInfo(path).isFile() &&
Chris@0 2221 QFileInfo(path).isReadable())) {
Chris@0 2222 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 2223 tr("File \"%1\" does not exist or is not a readable file").arg(path));
Chris@0 2224 return;
Chris@0 2225 }
Chris@0 2226
Chris@0 2227 if (path.endsWith(".sv")) {
Chris@0 2228
Chris@0 2229 if (!checkSaveModified()) return;
Chris@0 2230
Chris@0 2231 if (!openSessionFile(path)) {
Chris@0 2232 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 2233 tr("Session file \"%1\" could not be opened").arg(path));
Chris@0 2234 }
Chris@0 2235
Chris@0 2236 } else {
Chris@0 2237
Chris@0 2238 if (!openAudioFile(path, AskUser)) {
Chris@0 2239
Chris@0 2240 if (!canImportLayer || !openLayerFile(path)) {
Chris@0 2241
Chris@0 2242 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 2243 tr("File \"%1\" could not be opened").arg(path));
Chris@0 2244 }
Chris@0 2245 }
Chris@0 2246 }
Chris@0 2247 }
Chris@0 2248
Chris@0 2249 void
Chris@0 2250 MainWindow::openRecentFile()
Chris@0 2251 {
Chris@0 2252 QObject *obj = sender();
Chris@0 2253 QAction *action = dynamic_cast<QAction *>(obj);
Chris@0 2254
Chris@0 2255 if (!action) {
Chris@0 2256 std::cerr << "WARNING: MainWindow::openRecentFile: sender is not an action"
Chris@0 2257 << std::endl;
Chris@0 2258 return;
Chris@0 2259 }
Chris@0 2260
Chris@0 2261 QString path = action->text();
Chris@0 2262 if (path == "") return;
Chris@0 2263
Chris@0 2264 if (path.endsWith("sv")) {
Chris@0 2265
Chris@0 2266 if (!checkSaveModified()) return ;
Chris@0 2267
Chris@0 2268 if (!openSessionFile(path)) {
Chris@0 2269 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 2270 tr("Session file \"%1\" could not be opened").arg(path));
Chris@0 2271 }
Chris@0 2272
Chris@0 2273 } else {
Chris@0 2274
Chris@0 2275 if (!openAudioFile(path, AskUser)) {
Chris@0 2276
Chris@0 2277 bool canImportLayer = (getMainModel() != 0 &&
Chris@0 2278 m_paneStack != 0 &&
Chris@0 2279 m_paneStack->getCurrentPane() != 0);
Chris@0 2280
Chris@0 2281 if (!canImportLayer || !openLayerFile(path)) {
Chris@0 2282
Chris@0 2283 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 2284 tr("File \"%1\" could not be opened").arg(path));
Chris@0 2285 }
Chris@0 2286 }
Chris@0 2287 }
Chris@0 2288 }
Chris@0 2289
Chris@0 2290 bool
Chris@54 2291 MainWindow::openSomeFile(QString path, AudioFileOpenMode mode)
Chris@0 2292 {
Chris@54 2293 if (openAudioFile(path, mode)) {
Chris@0 2294 return true;
Chris@0 2295 } else if (openSessionFile(path)) {
Chris@0 2296 return true;
Chris@0 2297 } else {
Chris@0 2298 return false;
Chris@0 2299 }
Chris@0 2300 }
Chris@0 2301
Chris@0 2302 bool
Chris@0 2303 MainWindow::openSessionFile(QString path)
Chris@0 2304 {
Chris@0 2305 BZipFileDevice bzFile(path);
Chris@0 2306 if (!bzFile.open(QIODevice::ReadOnly)) {
Chris@0 2307 std::cerr << "Failed to open session file \"" << path.toStdString()
Chris@0 2308 << "\": " << bzFile.errorString().toStdString() << std::endl;
Chris@0 2309 return false;
Chris@0 2310 }
Chris@0 2311
Chris@0 2312 QString error;
Chris@0 2313 closeSession();
Chris@0 2314 createDocument();
Chris@0 2315
Chris@0 2316 PaneCallback callback(this);
Chris@0 2317 m_viewManager->clearSelections();
Chris@0 2318
Chris@0 2319 SVFileReader reader(m_document, callback);
Chris@0 2320 QXmlInputSource inputSource(&bzFile);
Chris@0 2321 reader.parse(inputSource);
Chris@0 2322
Chris@0 2323 if (!reader.isOK()) {
Chris@0 2324 error = tr("SV XML file read error:\n%1").arg(reader.getErrorString());
Chris@0 2325 }
Chris@0 2326
Chris@0 2327 bzFile.close();
Chris@0 2328
Chris@0 2329 bool ok = (error == "");
Chris@0 2330
Chris@0 2331 if (ok) {
Chris@0 2332 setWindowTitle(tr("Sonic Visualiser: %1")
Chris@0 2333 .arg(QFileInfo(path).fileName()));
Chris@0 2334 m_sessionFile = path;
Chris@0 2335 setupMenus();
Chris@0 2336 CommandHistory::getInstance()->clear();
Chris@0 2337 CommandHistory::getInstance()->documentSaved();
Chris@0 2338 m_documentModified = false;
Chris@0 2339 updateMenuStates();
Chris@34 2340 m_recentFiles.addFile(path);
Chris@0 2341 } else {
Chris@0 2342 setWindowTitle(tr("Sonic Visualiser"));
Chris@0 2343 }
Chris@0 2344
Chris@0 2345 return ok;
Chris@0 2346 }
Chris@0 2347
Chris@0 2348 void
Chris@0 2349 MainWindow::closeEvent(QCloseEvent *e)
Chris@0 2350 {
Chris@0 2351 if (!checkSaveModified()) {
Chris@0 2352 e->ignore();
Chris@0 2353 return;
Chris@0 2354 }
Chris@0 2355
Chris@5 2356 QSettings settings;
Chris@5 2357 settings.beginGroup("MainWindow");
Chris@5 2358 settings.setValue("size", size());
Chris@5 2359 settings.setValue("position", pos());
Chris@5 2360 settings.endGroup();
Chris@5 2361
Chris@0 2362 e->accept();
Chris@0 2363 return;
Chris@0 2364 }
Chris@0 2365
Chris@0 2366 bool
Chris@11 2367 MainWindow::commitData(bool mayAskUser)
Chris@11 2368 {
Chris@11 2369 if (mayAskUser) {
Chris@11 2370 return checkSaveModified();
Chris@11 2371 } else {
Chris@11 2372 if (!m_documentModified) return true;
Chris@11 2373
Chris@11 2374 // If we can't check with the user first, then we can't save
Chris@11 2375 // to the original session file (even if we have it) -- have
Chris@11 2376 // to use a temporary file
Chris@11 2377
Chris@11 2378 QString svDirBase = ".sv1";
Chris@11 2379 QString svDir = QDir::home().filePath(svDirBase);
Chris@11 2380
Chris@11 2381 if (!QFileInfo(svDir).exists()) {
Chris@11 2382 if (!QDir::home().mkdir(svDirBase)) return false;
Chris@11 2383 } else {
Chris@11 2384 if (!QFileInfo(svDir).isDir()) return false;
Chris@11 2385 }
Chris@11 2386
Chris@11 2387 // This name doesn't have to be unguessable
Chris@11 2388
Chris@11 2389 QString fname = QString("tmp-%1-%2.sv")
Chris@11 2390 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"))
Chris@11 2391 .arg(QProcess().pid());
Chris@11 2392 QString fpath = QDir(svDir).filePath(fname);
Chris@11 2393 if (saveSessionFile(fpath)) {
Chris@34 2394 m_recentFiles.addFile(fpath);
Chris@11 2395 return true;
Chris@11 2396 } else {
Chris@11 2397 return false;
Chris@11 2398 }
Chris@11 2399 }
Chris@11 2400 }
Chris@11 2401
Chris@11 2402 bool
Chris@0 2403 MainWindow::checkSaveModified()
Chris@0 2404 {
Chris@0 2405 // Called before some destructive operation (e.g. new session,
Chris@0 2406 // exit program). Return true if we can safely proceed, false to
Chris@0 2407 // cancel.
Chris@0 2408
Chris@0 2409 if (!m_documentModified) return true;
Chris@0 2410
Chris@0 2411 int button =
Chris@0 2412 QMessageBox::warning(this,
Chris@0 2413 tr("Session modified"),
Chris@0 2414 tr("The current session has been modified.\nDo you want to save it?"),
Chris@0 2415 QMessageBox::Yes,
Chris@0 2416 QMessageBox::No,
Chris@0 2417 QMessageBox::Cancel);
Chris@0 2418
Chris@0 2419 if (button == QMessageBox::Yes) {
Chris@0 2420 saveSession();
Chris@0 2421 if (m_documentModified) { // save failed -- don't proceed!
Chris@0 2422 return false;
Chris@0 2423 } else {
Chris@0 2424 return true; // saved, so it's safe to continue now
Chris@0 2425 }
Chris@0 2426 } else if (button == QMessageBox::No) {
Chris@0 2427 m_documentModified = false; // so we know to abandon it
Chris@0 2428 return true;
Chris@0 2429 }
Chris@0 2430
Chris@0 2431 // else cancel
Chris@0 2432 return false;
Chris@0 2433 }
Chris@0 2434
Chris@0 2435 void
Chris@0 2436 MainWindow::saveSession()
Chris@0 2437 {
Chris@0 2438 if (m_sessionFile != "") {
Chris@0 2439 if (!saveSessionFile(m_sessionFile)) {
Chris@0 2440 QMessageBox::critical(this, tr("Failed to save file"),
Chris@0 2441 tr("Session file \"%1\" could not be saved.").arg(m_sessionFile));
Chris@0 2442 } else {
Chris@0 2443 CommandHistory::getInstance()->documentSaved();
Chris@0 2444 documentRestored();
Chris@0 2445 }
Chris@0 2446 } else {
Chris@0 2447 saveSessionAs();
Chris@0 2448 }
Chris@0 2449 }
Chris@0 2450
Chris@0 2451 void
Chris@0 2452 MainWindow::saveSessionAs()
Chris@0 2453 {
Chris@0 2454 QString orig = m_audioFile;
Chris@0 2455 if (orig == "") orig = ".";
Chris@0 2456 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 2457
Chris@0 2458 QString path;
Chris@0 2459 bool good = false;
Chris@0 2460
Chris@0 2461 while (!good) {
Chris@0 2462
Chris@0 2463 path = QFileDialog::getSaveFileName
Chris@0 2464 (this, tr("Select a file to save to"), orig,
Chris@0 2465 tr("Sonic Visualiser session files (*.sv)\nAll files (*.*)"), 0,
Chris@0 2466 QFileDialog::DontConfirmOverwrite); // we'll do that
Chris@0 2467
Chris@0 2468 if (path.isEmpty()) return;
Chris@0 2469
Chris@0 2470 if (!path.endsWith(".sv")) path = path + ".sv";
Chris@0 2471
Chris@0 2472 QFileInfo fi(path);
Chris@0 2473
Chris@0 2474 if (fi.isDir()) {
Chris@0 2475 QMessageBox::critical(this, tr("Directory selected"),
Chris@0 2476 tr("File \"%1\" is a directory").arg(path));
Chris@0 2477 continue;
Chris@0 2478 }
Chris@0 2479
Chris@0 2480 if (fi.exists()) {
Chris@0 2481 if (QMessageBox::question(this, tr("File exists"),
Chris@0 2482 tr("The file \"%1\" already exists.\nDo you want to overwrite it?").arg(path),
Chris@0 2483 QMessageBox::Ok,
Chris@0 2484 QMessageBox::Cancel) == QMessageBox::Ok) {
Chris@0 2485 good = true;
Chris@0 2486 } else {
Chris@0 2487 continue;
Chris@0 2488 }
Chris@0 2489 }
Chris@0 2490
Chris@0 2491 good = true;
Chris@0 2492 }
Chris@0 2493
Chris@0 2494 if (!saveSessionFile(path)) {
Chris@0 2495 QMessageBox::critical(this, tr("Failed to save file"),
Chris@0 2496 tr("Session file \"%1\" could not be saved.").arg(m_sessionFile));
Chris@0 2497 } else {
Chris@0 2498 setWindowTitle(tr("Sonic Visualiser: %1")
Chris@0 2499 .arg(QFileInfo(path).fileName()));
Chris@0 2500 m_sessionFile = path;
Chris@0 2501 CommandHistory::getInstance()->documentSaved();
Chris@0 2502 documentRestored();
Chris@34 2503 m_recentFiles.addFile(path);
Chris@0 2504 }
Chris@0 2505 }
Chris@0 2506
Chris@0 2507 bool
Chris@0 2508 MainWindow::saveSessionFile(QString path)
Chris@0 2509 {
Chris@0 2510 BZipFileDevice bzFile(path);
Chris@0 2511 if (!bzFile.open(QIODevice::WriteOnly)) {
Chris@0 2512 std::cerr << "Failed to open session file \"" << path.toStdString()
Chris@0 2513 << "\" for writing: "
Chris@0 2514 << bzFile.errorString().toStdString() << std::endl;
Chris@0 2515 return false;
Chris@0 2516 }
Chris@0 2517
Chris@0 2518 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
Chris@0 2519
Chris@0 2520 QTextStream out(&bzFile);
Chris@0 2521 toXml(out);
Chris@0 2522 out.flush();
Chris@0 2523
Chris@0 2524 QApplication::restoreOverrideCursor();
Chris@0 2525
Chris@0 2526 if (bzFile.errorString() != "") {
Chris@0 2527 QMessageBox::critical(this, tr("Failed to write file"),
Chris@0 2528 tr("Failed to write to file \"%1\": %2")
Chris@0 2529 .arg(path).arg(bzFile.errorString()));
Chris@0 2530 bzFile.close();
Chris@0 2531 return false;
Chris@0 2532 }
Chris@0 2533
Chris@0 2534 bzFile.close();
Chris@0 2535 return true;
Chris@0 2536 }
Chris@0 2537
Chris@0 2538 void
Chris@0 2539 MainWindow::toXml(QTextStream &out)
Chris@0 2540 {
Chris@0 2541 QString indent(" ");
Chris@0 2542
Chris@0 2543 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
Chris@0 2544 out << "<!DOCTYPE sonic-visualiser>\n";
Chris@0 2545 out << "<sv>\n";
Chris@0 2546
Chris@0 2547 m_document->toXml(out, "", "");
Chris@0 2548
Chris@0 2549 out << "<display>\n";
Chris@0 2550
Chris@0 2551 out << QString(" <window width=\"%1\" height=\"%2\"/>\n")
Chris@0 2552 .arg(width()).arg(height());
Chris@0 2553
Chris@0 2554 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@0 2555
Chris@0 2556 Pane *pane = m_paneStack->getPane(i);
Chris@0 2557
Chris@0 2558 if (pane) {
Chris@0 2559 pane->toXml(out, indent);
Chris@0 2560 }
Chris@0 2561 }
Chris@0 2562
Chris@0 2563 out << "</display>\n";
Chris@0 2564
Chris@0 2565 m_viewManager->getSelection().toXml(out);
Chris@0 2566
Chris@0 2567 out << "</sv>\n";
Chris@0 2568 }
Chris@0 2569
Chris@0 2570 Pane *
Chris@0 2571 MainWindow::addPaneToStack()
Chris@0 2572 {
Chris@0 2573 AddPaneCommand *command = new AddPaneCommand(this);
Chris@0 2574 CommandHistory::getInstance()->addCommand(command);
Chris@0 2575 return command->getPane();
Chris@0 2576 }
Chris@0 2577
Chris@0 2578 void
Chris@0 2579 MainWindow::zoomIn()
Chris@0 2580 {
Chris@0 2581 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 2582 if (currentPane) currentPane->zoom(true);
Chris@0 2583 }
Chris@0 2584
Chris@0 2585 void
Chris@0 2586 MainWindow::zoomOut()
Chris@0 2587 {
Chris@0 2588 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 2589 if (currentPane) currentPane->zoom(false);
Chris@0 2590 }
Chris@0 2591
Chris@0 2592 void
Chris@0 2593 MainWindow::zoomToFit()
Chris@0 2594 {
Chris@0 2595 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 2596 if (!currentPane) return;
Chris@0 2597
Chris@0 2598 Model *model = getMainModel();
Chris@0 2599 if (!model) return;
Chris@0 2600
Chris@0 2601 size_t start = model->getStartFrame();
Chris@0 2602 size_t end = model->getEndFrame();
Chris@0 2603 size_t pixels = currentPane->width();
Chris@0 2604 size_t zoomLevel = (end - start) / pixels;
Chris@0 2605
Chris@0 2606 currentPane->setZoomLevel(zoomLevel);
Chris@0 2607 currentPane->setStartFrame(start);
Chris@0 2608 }
Chris@0 2609
Chris@0 2610 void
Chris@0 2611 MainWindow::zoomDefault()
Chris@0 2612 {
Chris@0 2613 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 2614 if (currentPane) currentPane->setZoomLevel(1024);
Chris@0 2615 }
Chris@0 2616
Chris@0 2617 void
Chris@0 2618 MainWindow::scrollLeft()
Chris@0 2619 {
Chris@0 2620 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 2621 if (currentPane) currentPane->scroll(false, false);
Chris@0 2622 }
Chris@0 2623
Chris@0 2624 void
Chris@0 2625 MainWindow::jumpLeft()
Chris@0 2626 {
Chris@0 2627 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 2628 if (currentPane) currentPane->scroll(false, true);
Chris@0 2629 }
Chris@0 2630
Chris@0 2631 void
Chris@0 2632 MainWindow::scrollRight()
Chris@0 2633 {
Chris@0 2634 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 2635 if (currentPane) currentPane->scroll(true, false);
Chris@0 2636 }
Chris@0 2637
Chris@0 2638 void
Chris@0 2639 MainWindow::jumpRight()
Chris@0 2640 {
Chris@0 2641 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 2642 if (currentPane) currentPane->scroll(true, true);
Chris@0 2643 }
Chris@0 2644
Chris@0 2645 void
Chris@0 2646 MainWindow::showNoOverlays()
Chris@0 2647 {
Chris@0 2648 m_viewManager->setOverlayMode(ViewManager::NoOverlays);
Chris@0 2649 }
Chris@0 2650
Chris@0 2651 void
Chris@0 2652 MainWindow::showBasicOverlays()
Chris@0 2653 {
Chris@0 2654 m_viewManager->setOverlayMode(ViewManager::BasicOverlays);
Chris@0 2655 }
Chris@0 2656
Chris@0 2657 void
Chris@7 2658 MainWindow::showAllTextOverlays()
Chris@0 2659 {
Chris@0 2660 m_viewManager->setOverlayMode(ViewManager::AllOverlays);
Chris@0 2661 }
Chris@0 2662
Chris@0 2663 void
Chris@7 2664 MainWindow::toggleZoomWheels()
Chris@7 2665 {
Chris@7 2666 if (m_viewManager->getZoomWheelsEnabled()) {
Chris@7 2667 m_viewManager->setZoomWheelsEnabled(false);
Chris@7 2668 } else {
Chris@7 2669 m_viewManager->setZoomWheelsEnabled(true);
Chris@7 2670 }
Chris@7 2671 }
Chris@7 2672
Chris@7 2673 void
Chris@0 2674 MainWindow::play()
Chris@0 2675 {
Chris@0 2676 if (m_playSource->isPlaying()) {
Chris@0 2677 m_playSource->stop();
Chris@0 2678 } else {
Chris@0 2679 m_playSource->play(m_viewManager->getPlaybackFrame());
Chris@0 2680 }
Chris@0 2681 }
Chris@0 2682
Chris@0 2683 void
Chris@0 2684 MainWindow::ffwd()
Chris@0 2685 {
Chris@0 2686 if (!getMainModel()) return;
Chris@0 2687
Chris@0 2688 int frame = m_viewManager->getPlaybackFrame();
Chris@0 2689 ++frame;
Chris@0 2690
Chris@0 2691 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 2692 if (!pane) return;
Chris@0 2693
Chris@0 2694 Layer *layer = pane->getSelectedLayer();
Chris@0 2695
Chris@0 2696 if (!dynamic_cast<TimeInstantLayer *>(layer) &&
Chris@0 2697 !dynamic_cast<TimeValueLayer *>(layer)) return;
Chris@0 2698
Chris@0 2699 size_t resolution = 0;
Chris@0 2700 if (!layer->snapToFeatureFrame(pane, frame, resolution, Layer::SnapRight)) {
Chris@0 2701 frame = getMainModel()->getEndFrame();
Chris@0 2702 }
Chris@0 2703
Chris@0 2704 m_viewManager->setPlaybackFrame(frame);
Chris@0 2705 }
Chris@0 2706
Chris@0 2707 void
Chris@0 2708 MainWindow::ffwdEnd()
Chris@0 2709 {
Chris@0 2710 if (!getMainModel()) return;
Chris@0 2711 m_viewManager->setPlaybackFrame(getMainModel()->getEndFrame());
Chris@0 2712 }
Chris@0 2713
Chris@0 2714 void
Chris@0 2715 MainWindow::rewind()
Chris@0 2716 {
Chris@0 2717 if (!getMainModel()) return;
Chris@0 2718
Chris@0 2719 int frame = m_viewManager->getPlaybackFrame();
Chris@0 2720 if (frame > 0) --frame;
Chris@0 2721
Chris@0 2722 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 2723 if (!pane) return;
Chris@0 2724
Chris@0 2725 Layer *layer = pane->getSelectedLayer();
Chris@0 2726
Chris@0 2727 if (!dynamic_cast<TimeInstantLayer *>(layer) &&
Chris@0 2728 !dynamic_cast<TimeValueLayer *>(layer)) return;
Chris@0 2729
Chris@0 2730 size_t resolution = 0;
Chris@0 2731 if (!layer->snapToFeatureFrame(pane, frame, resolution, Layer::SnapLeft)) {
Chris@0 2732 frame = getMainModel()->getEndFrame();
Chris@0 2733 }
Chris@0 2734
Chris@0 2735 m_viewManager->setPlaybackFrame(frame);
Chris@0 2736 }
Chris@0 2737
Chris@0 2738 void
Chris@0 2739 MainWindow::rewindStart()
Chris@0 2740 {
Chris@0 2741 if (!getMainModel()) return;
Chris@0 2742 m_viewManager->setPlaybackFrame(getMainModel()->getStartFrame());
Chris@0 2743 }
Chris@0 2744
Chris@0 2745 void
Chris@0 2746 MainWindow::stop()
Chris@0 2747 {
Chris@0 2748 m_playSource->stop();
Chris@0 2749 }
Chris@0 2750
Chris@0 2751 void
Chris@0 2752 MainWindow::addPane()
Chris@0 2753 {
Chris@0 2754 QObject *s = sender();
Chris@0 2755 QAction *action = dynamic_cast<QAction *>(s);
Chris@0 2756
Chris@0 2757 if (!action) {
Chris@0 2758 std::cerr << "WARNING: MainWindow::addPane: sender is not an action"
Chris@0 2759 << std::endl;
Chris@0 2760 return;
Chris@0 2761 }
Chris@0 2762
Chris@0 2763 PaneActionMap::iterator i = m_paneActions.find(action);
Chris@0 2764
Chris@0 2765 if (i == m_paneActions.end()) {
Chris@0 2766 std::cerr << "WARNING: MainWindow::addPane: unknown action "
Chris@0 2767 << action->objectName().toStdString() << std::endl;
Chris@0 2768 return;
Chris@0 2769 }
Chris@0 2770
Chris@0 2771 CommandHistory::getInstance()->startCompoundOperation
Chris@0 2772 (action->text(), true);
Chris@0 2773
Chris@0 2774 AddPaneCommand *command = new AddPaneCommand(this);
Chris@0 2775 CommandHistory::getInstance()->addCommand(command);
Chris@0 2776
Chris@0 2777 Pane *pane = command->getPane();
Chris@0 2778
Chris@7 2779 if (i->second.layer == LayerFactory::Spectrum) {
Chris@7 2780 pane->setPlaybackFollow(View::PlaybackScrollContinuous);
Chris@7 2781 }
Chris@7 2782
Chris@8 2783 if (i->second.layer != LayerFactory::TimeRuler &&
Chris@8 2784 i->second.layer != LayerFactory::Spectrum) {
Chris@8 2785
Chris@0 2786 if (!m_timeRulerLayer) {
Chris@0 2787 // std::cerr << "no time ruler layer, creating one" << std::endl;
Chris@0 2788 m_timeRulerLayer = m_document->createMainModelLayer
Chris@0 2789 (LayerFactory::TimeRuler);
Chris@0 2790 }
Chris@0 2791
Chris@0 2792 // std::cerr << "adding time ruler layer " << m_timeRulerLayer << std::endl;
Chris@0 2793
Chris@0 2794 m_document->addLayerToView(pane, m_timeRulerLayer);
Chris@0 2795 }
Chris@0 2796
Chris@0 2797 Layer *newLayer = m_document->createLayer(i->second.layer);
Chris@0 2798 m_document->setModel(newLayer, m_document->getMainModel());
Chris@0 2799 m_document->setChannel(newLayer, i->second.channel);
Chris@0 2800 m_document->addLayerToView(pane, newLayer);
Chris@0 2801
Chris@0 2802 m_paneStack->setCurrentPane(pane);
Chris@0 2803
Chris@0 2804 CommandHistory::getInstance()->endCompoundOperation();
Chris@0 2805
Chris@0 2806 updateMenuStates();
Chris@0 2807 }
Chris@0 2808
Chris@0 2809 MainWindow::AddPaneCommand::AddPaneCommand(MainWindow *mw) :
Chris@0 2810 m_mw(mw),
Chris@0 2811 m_pane(0),
Chris@0 2812 m_prevCurrentPane(0),
Chris@0 2813 m_added(false)
Chris@0 2814 {
Chris@0 2815 }
Chris@0 2816
Chris@0 2817 MainWindow::AddPaneCommand::~AddPaneCommand()
Chris@0 2818 {
Chris@0 2819 if (m_pane && !m_added) {
Chris@0 2820 m_mw->m_paneStack->deletePane(m_pane);
Chris@0 2821 }
Chris@0 2822 }
Chris@0 2823
Chris@0 2824 QString
Chris@0 2825 MainWindow::AddPaneCommand::getName() const
Chris@0 2826 {
Chris@0 2827 return tr("Add Pane");
Chris@0 2828 }
Chris@0 2829
Chris@0 2830 void
Chris@0 2831 MainWindow::AddPaneCommand::execute()
Chris@0 2832 {
Chris@0 2833 if (!m_pane) {
Chris@0 2834 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
Chris@0 2835 m_pane = m_mw->m_paneStack->addPane();
Chris@0 2836 } else {
Chris@0 2837 m_mw->m_paneStack->showPane(m_pane);
Chris@0 2838 }
Chris@0 2839
Chris@0 2840 m_mw->m_paneStack->setCurrentPane(m_pane);
Chris@0 2841 m_mw->m_panner->registerView(m_pane);
Chris@0 2842 m_added = true;
Chris@0 2843 }
Chris@0 2844
Chris@0 2845 void
Chris@0 2846 MainWindow::AddPaneCommand::unexecute()
Chris@0 2847 {
Chris@0 2848 m_mw->m_paneStack->hidePane(m_pane);
Chris@0 2849 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
Chris@0 2850 m_mw->m_panner->unregisterView(m_pane);
Chris@0 2851 m_added = false;
Chris@0 2852 }
Chris@0 2853
Chris@0 2854 MainWindow::RemovePaneCommand::RemovePaneCommand(MainWindow *mw, Pane *pane) :
Chris@0 2855 m_mw(mw),
Chris@0 2856 m_pane(pane),
Chris@0 2857 m_added(true)
Chris@0 2858 {
Chris@0 2859 }
Chris@0 2860
Chris@0 2861 MainWindow::RemovePaneCommand::~RemovePaneCommand()
Chris@0 2862 {
Chris@0 2863 if (m_pane && !m_added) {
Chris@0 2864 m_mw->m_paneStack->deletePane(m_pane);
Chris@0 2865 }
Chris@0 2866 }
Chris@0 2867
Chris@0 2868 QString
Chris@0 2869 MainWindow::RemovePaneCommand::getName() const
Chris@0 2870 {
Chris@0 2871 return tr("Remove Pane");
Chris@0 2872 }
Chris@0 2873
Chris@0 2874 void
Chris@0 2875 MainWindow::RemovePaneCommand::execute()
Chris@0 2876 {
Chris@0 2877 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
Chris@0 2878 m_mw->m_paneStack->hidePane(m_pane);
Chris@0 2879 m_mw->m_panner->unregisterView(m_pane);
Chris@0 2880 m_added = false;
Chris@0 2881 }
Chris@0 2882
Chris@0 2883 void
Chris@0 2884 MainWindow::RemovePaneCommand::unexecute()
Chris@0 2885 {
Chris@0 2886 m_mw->m_paneStack->showPane(m_pane);
Chris@0 2887 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
Chris@0 2888 m_mw->m_panner->registerView(m_pane);
Chris@0 2889 m_added = true;
Chris@0 2890 }
Chris@0 2891
Chris@0 2892 void
Chris@0 2893 MainWindow::addLayer()
Chris@0 2894 {
Chris@0 2895 QObject *s = sender();
Chris@0 2896 QAction *action = dynamic_cast<QAction *>(s);
Chris@0 2897
Chris@0 2898 if (!action) {
Chris@0 2899 std::cerr << "WARNING: MainWindow::addLayer: sender is not an action"
Chris@0 2900 << std::endl;
Chris@0 2901 return;
Chris@0 2902 }
Chris@0 2903
Chris@0 2904 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 2905
Chris@0 2906 if (!pane) {
Chris@0 2907 std::cerr << "WARNING: MainWindow::addLayer: no current pane" << std::endl;
Chris@0 2908 return;
Chris@0 2909 }
Chris@0 2910
Chris@0 2911 ExistingLayerActionMap::iterator ei = m_existingLayerActions.find(action);
Chris@0 2912
Chris@0 2913 if (ei != m_existingLayerActions.end()) {
Chris@0 2914 Layer *newLayer = ei->second;
Chris@0 2915 m_document->addLayerToView(pane, newLayer);
Chris@0 2916 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 2917 return;
Chris@0 2918 }
Chris@0 2919
Chris@34 2920 TransformActionMap::iterator i = m_transformActions.find(action);
Chris@34 2921
Chris@34 2922 if (i == m_transformActions.end()) {
Chris@0 2923
Chris@0 2924 LayerActionMap::iterator i = m_layerActions.find(action);
Chris@0 2925
Chris@0 2926 if (i == m_layerActions.end()) {
Chris@0 2927 std::cerr << "WARNING: MainWindow::addLayer: unknown action "
Chris@0 2928 << action->objectName().toStdString() << std::endl;
Chris@0 2929 return;
Chris@0 2930 }
Chris@0 2931
Chris@0 2932 LayerFactory::LayerType type = i->second;
Chris@0 2933
Chris@0 2934 LayerFactory::LayerTypeSet emptyTypes =
Chris@0 2935 LayerFactory::getInstance()->getValidEmptyLayerTypes();
Chris@0 2936
Chris@0 2937 Layer *newLayer;
Chris@0 2938
Chris@0 2939 if (emptyTypes.find(type) != emptyTypes.end()) {
Chris@0 2940
Chris@0 2941 newLayer = m_document->createEmptyLayer(type);
Chris@0 2942 m_toolActions[ViewManager::DrawMode]->trigger();
Chris@0 2943
Chris@0 2944 } else {
Chris@0 2945
Chris@0 2946 newLayer = m_document->createMainModelLayer(type);
Chris@0 2947 }
Chris@0 2948
Chris@0 2949 m_document->addLayerToView(pane, newLayer);
Chris@0 2950 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 2951
Chris@0 2952 return;
Chris@0 2953 }
Chris@0 2954
Chris@0 2955 TransformName transform = i->second;
Chris@0 2956 TransformFactory *factory = TransformFactory::getInstance();
Chris@0 2957
Chris@0 2958 QString configurationXml;
Chris@0 2959
Chris@0 2960 int channel = -1;
Chris@0 2961 // pick up the default channel from any existing layers on the same pane
Chris@0 2962 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@0 2963 int c = LayerFactory::getInstance()->getChannel(pane->getLayer(j));
Chris@0 2964 if (c != -1) {
Chris@0 2965 channel = c;
Chris@0 2966 break;
Chris@0 2967 }
Chris@0 2968 }
Chris@0 2969
Chris@33 2970 // We always ask for configuration, even if the plugin isn't
Chris@33 2971 // supposed to be configurable, because we need to let the user
Chris@33 2972 // change the execution context (block size etc).
Chris@0 2973
Chris@27 2974 PluginTransform::ExecutionContext context(channel);
Chris@27 2975
Chris@53 2976 std::vector<Model *> candidateInputModels;
Chris@53 2977 candidateInputModels.push_back(m_document->getMainModel());
Chris@53 2978
Chris@53 2979 //!!! rationalise this (via document method for example)
Chris@53 2980 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@53 2981 Pane *ip = m_paneStack->getPane(i);
Chris@53 2982 if (!ip) continue;
Chris@53 2983 for (int j = 0; j < ip->getLayerCount(); ++j) {
Chris@53 2984 Layer *jl = ip->getLayer(j);
Chris@53 2985 if (jl) {
Chris@53 2986 Model *model = jl->getModel();
Chris@53 2987 DenseTimeValueModel *dtvm = dynamic_cast<DenseTimeValueModel *>
Chris@53 2988 (model);
Chris@53 2989 if (dtvm) {
Chris@53 2990 int k;
Chris@53 2991 for (k = 0; k < candidateInputModels.size(); ++k) {
Chris@53 2992 if (candidateInputModels[k] == dtvm) break;
Chris@53 2993 }
Chris@53 2994 if (k == candidateInputModels.size()) {
Chris@53 2995 candidateInputModels.push_back(dtvm);
Chris@53 2996 }
Chris@53 2997 }
Chris@53 2998 }
Chris@53 2999 }
Chris@53 3000 }
Chris@53 3001
Chris@54 3002 Model *inputModel = factory->getConfigurationForTransform(transform,
Chris@54 3003 candidateInputModels,
Chris@54 3004 context,
Chris@54 3005 configurationXml,
Chris@54 3006 m_playSource);
Chris@54 3007 if (!inputModel) return;
Chris@54 3008
Chris@54 3009 std::cerr << "Input model is " << inputModel << " \"" << inputModel->objectName().toStdString() << std::endl;
Chris@0 3010
Chris@0 3011 Layer *newLayer = m_document->createDerivedLayer(transform,
Chris@54 3012 inputModel,
Chris@27 3013 context,
Chris@0 3014 configurationXml);
Chris@0 3015
Chris@0 3016 if (newLayer) {
Chris@0 3017 m_document->addLayerToView(pane, newLayer);
Chris@27 3018 m_document->setChannel(newLayer, context.channel);
Chris@34 3019 m_recentTransforms.add(transform);
Chris@0 3020 }
Chris@0 3021
Chris@0 3022 updateMenuStates();
Chris@0 3023 }
Chris@0 3024
Chris@0 3025 void
Chris@0 3026 MainWindow::deleteCurrentPane()
Chris@0 3027 {
Chris@0 3028 CommandHistory::getInstance()->startCompoundOperation
Chris@0 3029 (tr("Delete Pane"), true);
Chris@0 3030
Chris@0 3031 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 3032 if (pane) {
Chris@0 3033 while (pane->getLayerCount() > 0) {
Chris@0 3034 Layer *layer = pane->getLayer(0);
Chris@0 3035 if (layer) {
Chris@0 3036 m_document->removeLayerFromView(pane, layer);
Chris@0 3037 } else {
Chris@0 3038 break;
Chris@0 3039 }
Chris@0 3040 }
Chris@0 3041
Chris@0 3042 RemovePaneCommand *command = new RemovePaneCommand(this, pane);
Chris@0 3043 CommandHistory::getInstance()->addCommand(command);
Chris@0 3044 }
Chris@0 3045
Chris@0 3046 CommandHistory::getInstance()->endCompoundOperation();
Chris@0 3047
Chris@0 3048 updateMenuStates();
Chris@0 3049 }
Chris@0 3050
Chris@0 3051 void
Chris@0 3052 MainWindow::deleteCurrentLayer()
Chris@0 3053 {
Chris@0 3054 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 3055 if (pane) {
Chris@0 3056 Layer *layer = pane->getSelectedLayer();
Chris@0 3057 if (layer) {
Chris@0 3058 m_document->removeLayerFromView(pane, layer);
Chris@0 3059 }
Chris@0 3060 }
Chris@0 3061 updateMenuStates();
Chris@0 3062 }
Chris@0 3063
Chris@0 3064 void
Chris@0 3065 MainWindow::renameCurrentLayer()
Chris@0 3066 {
Chris@0 3067 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 3068 if (pane) {
Chris@0 3069 Layer *layer = pane->getSelectedLayer();
Chris@0 3070 if (layer) {
Chris@0 3071 bool ok = false;
Chris@0 3072 QString newName = QInputDialog::getText
Chris@0 3073 (this, tr("Rename Layer"),
Chris@0 3074 tr("New name for this layer:"),
Chris@0 3075 QLineEdit::Normal, layer->objectName(), &ok);
Chris@0 3076 if (ok) {
Chris@0 3077 layer->setObjectName(newName);
Chris@0 3078 setupExistingLayersMenu();
Chris@0 3079 }
Chris@0 3080 }
Chris@0 3081 }
Chris@0 3082 }
Chris@0 3083
Chris@0 3084 void
Chris@59 3085 MainWindow::playSpeedChanged(int position)
Chris@0 3086 {
Chris@59 3087 PlaySpeedRangeMapper mapper(0, 200);
Chris@59 3088 float factor = mapper.getFactorForPosition(position);
Chris@59 3089 float percent = mapper.getValueForPosition(position);
Chris@59 3090
Chris@59 3091 // std::cerr << "speed = " << position << " factor = " << factor << std::endl;
Chris@59 3092
Chris@59 3093 bool slow = (position < 100);
Chris@59 3094 bool something = (position != 100);
Chris@59 3095
Chris@59 3096 int pc = lrintf(percent);
Chris@21 3097
Chris@21 3098 m_playSpeed->setToolTip(tr("Playback speed: %1%2%")
Chris@25 3099 .arg(!slow ? "+" : "-")
Chris@21 3100 .arg(pc));
Chris@21 3101
Chris@25 3102 m_playSharpen->setEnabled(something);
Chris@26 3103 m_playMono->setEnabled(something);
Chris@25 3104 bool sharpen = (something && m_playSharpen->isChecked());
Chris@26 3105 bool mono = (something && m_playMono->isChecked());
Chris@26 3106 m_playSource->setTimeStretch(factor, sharpen, mono);
Chris@16 3107 }
Chris@16 3108
Chris@16 3109 void
Chris@16 3110 MainWindow::playSharpenToggled()
Chris@16 3111 {
Chris@21 3112 QSettings settings;
Chris@21 3113 settings.beginGroup("MainWindow");
Chris@21 3114 settings.setValue("playsharpen", m_playSharpen->isChecked());
Chris@21 3115 settings.endGroup();
Chris@21 3116
Chris@16 3117 playSpeedChanged(m_playSpeed->value());
Chris@0 3118 }
Chris@0 3119
Chris@0 3120 void
Chris@26 3121 MainWindow::playMonoToggled()
Chris@26 3122 {
Chris@26 3123 QSettings settings;
Chris@26 3124 settings.beginGroup("MainWindow");
Chris@26 3125 settings.setValue("playmono", m_playMono->isChecked());
Chris@26 3126 settings.endGroup();
Chris@26 3127
Chris@26 3128 playSpeedChanged(m_playSpeed->value());
Chris@26 3129 }
Chris@26 3130
Chris@26 3131 void
Chris@0 3132 MainWindow::outputLevelsChanged(float left, float right)
Chris@0 3133 {
Chris@0 3134 m_fader->setPeakLeft(left);
Chris@0 3135 m_fader->setPeakRight(right);
Chris@0 3136 }
Chris@0 3137
Chris@0 3138 void
Chris@0 3139 MainWindow::sampleRateMismatch(size_t requested, size_t actual,
Chris@0 3140 bool willResample)
Chris@0 3141 {
Chris@0 3142 if (!willResample) {
Chris@0 3143 //!!! more helpful message needed
Chris@0 3144 QMessageBox::information
Chris@0 3145 (this, tr("Sample rate mismatch"),
Chris@0 3146 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 3147 .arg(requested).arg(actual));
Chris@0 3148 }
Chris@0 3149
Chris@0 3150 /*!!! Let's not do this for now, and see how we go -- now that we're putting
Chris@0 3151 sample rate information in the status bar
Chris@0 3152
Chris@0 3153 QMessageBox::information
Chris@0 3154 (this, tr("Sample rate mismatch"),
Chris@0 3155 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 3156 .arg(requested).arg(actual));
Chris@0 3157 */
Chris@0 3158
Chris@0 3159 updateDescriptionLabel();
Chris@0 3160 }
Chris@0 3161
Chris@0 3162 void
Chris@42 3163 MainWindow::audioOverloadPluginDisabled()
Chris@42 3164 {
Chris@42 3165 QMessageBox::information
Chris@42 3166 (this, tr("Audio processing overload"),
Chris@42 3167 tr("Audio effects plugin auditioning has been disabled\ndue to a processing overload."));
Chris@42 3168 }
Chris@42 3169
Chris@42 3170 void
Chris@0 3171 MainWindow::layerAdded(Layer *layer)
Chris@0 3172 {
Chris@0 3173 // std::cerr << "MainWindow::layerAdded(" << layer << ")" << std::endl;
Chris@0 3174 // setupExistingLayersMenu();
Chris@0 3175 updateMenuStates();
Chris@0 3176 }
Chris@0 3177
Chris@0 3178 void
Chris@0 3179 MainWindow::layerRemoved(Layer *layer)
Chris@0 3180 {
Chris@0 3181 // std::cerr << "MainWindow::layerRemoved(" << layer << ")" << std::endl;
Chris@0 3182 setupExistingLayersMenu();
Chris@0 3183 updateMenuStates();
Chris@0 3184 }
Chris@0 3185
Chris@0 3186 void
Chris@0 3187 MainWindow::layerAboutToBeDeleted(Layer *layer)
Chris@0 3188 {
Chris@0 3189 // std::cerr << "MainWindow::layerAboutToBeDeleted(" << layer << ")" << std::endl;
Chris@0 3190 if (layer == m_timeRulerLayer) {
Chris@0 3191 // std::cerr << "(this is the time ruler layer)" << std::endl;
Chris@0 3192 m_timeRulerLayer = 0;
Chris@0 3193 }
Chris@0 3194 }
Chris@0 3195
Chris@0 3196 void
Chris@0 3197 MainWindow::layerInAView(Layer *layer, bool inAView)
Chris@0 3198 {
Chris@0 3199 // std::cerr << "MainWindow::layerInAView(" << layer << "," << inAView << ")" << std::endl;
Chris@0 3200
Chris@0 3201 // Check whether we need to add or remove model from play source
Chris@0 3202 Model *model = layer->getModel();
Chris@0 3203 if (model) {
Chris@0 3204 if (inAView) {
Chris@0 3205 m_playSource->addModel(model);
Chris@0 3206 } else {
Chris@0 3207 bool found = false;
Chris@0 3208 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@0 3209 Pane *pane = m_paneStack->getPane(i);
Chris@0 3210 if (!pane) continue;
Chris@0 3211 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@0 3212 Layer *pl = pane->getLayer(j);
Chris@0 3213 if (pl && pl->getModel() == model) {
Chris@0 3214 found = true;
Chris@0 3215 break;
Chris@0 3216 }
Chris@0 3217 }
Chris@0 3218 if (found) break;
Chris@0 3219 }
Chris@0 3220 if (!found) m_playSource->removeModel(model);
Chris@0 3221 }
Chris@0 3222 }
Chris@0 3223
Chris@0 3224 setupExistingLayersMenu();
Chris@0 3225 updateMenuStates();
Chris@0 3226 }
Chris@0 3227
Chris@0 3228 void
Chris@0 3229 MainWindow::modelAdded(Model *model)
Chris@0 3230 {
Chris@0 3231 // std::cerr << "MainWindow::modelAdded(" << model << ")" << std::endl;
Chris@0 3232 m_playSource->addModel(model);
Chris@0 3233 }
Chris@0 3234
Chris@0 3235 void
Chris@0 3236 MainWindow::mainModelChanged(WaveFileModel *model)
Chris@0 3237 {
Chris@0 3238 // std::cerr << "MainWindow::mainModelChanged(" << model << ")" << std::endl;
Chris@0 3239 updateDescriptionLabel();
Chris@0 3240 m_panLayer->setModel(model);
Chris@0 3241 if (model) m_viewManager->setMainModelSampleRate(model->getSampleRate());
Chris@46 3242 if (model && !m_playTarget && m_audioOutput) createPlayTarget();
Chris@0 3243 }
Chris@0 3244
Chris@0 3245 void
Chris@0 3246 MainWindow::modelAboutToBeDeleted(Model *model)
Chris@0 3247 {
Chris@0 3248 // std::cerr << "MainWindow::modelAboutToBeDeleted(" << model << ")" << std::endl;
Chris@0 3249 m_playSource->removeModel(model);
Chris@0 3250 }
Chris@0 3251
Chris@0 3252 void
Chris@0 3253 MainWindow::modelGenerationFailed(QString transformName)
Chris@0 3254 {
Chris@0 3255 QMessageBox::warning
Chris@0 3256 (this,
Chris@0 3257 tr("Failed to generate layer"),
Chris@34 3258 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 3259 .arg(transformName),
Chris@0 3260 QMessageBox::Ok, 0);
Chris@0 3261 }
Chris@0 3262
Chris@0 3263 void
Chris@0 3264 MainWindow::modelRegenerationFailed(QString layerName, QString transformName)
Chris@0 3265 {
Chris@0 3266 QMessageBox::warning
Chris@0 3267 (this,
Chris@0 3268 tr("Failed to regenerate layer"),
Chris@34 3269 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 3270 .arg(layerName).arg(transformName),
Chris@0 3271 QMessageBox::Ok, 0);
Chris@0 3272 }
Chris@0 3273
Chris@0 3274 void
Chris@0 3275 MainWindow::rightButtonMenuRequested(Pane *pane, QPoint position)
Chris@0 3276 {
Chris@0 3277 // std::cerr << "MainWindow::rightButtonMenuRequested(" << pane << ", " << position.x() << ", " << position.y() << ")" << std::endl;
Chris@0 3278 m_paneStack->setCurrentPane(pane);
Chris@0 3279 m_rightButtonMenu->popup(position);
Chris@0 3280 }
Chris@0 3281
Chris@0 3282 void
Chris@0 3283 MainWindow::showLayerTree()
Chris@0 3284 {
Chris@0 3285 QTreeView *view = new QTreeView();
Chris@0 3286 LayerTreeModel *tree = new LayerTreeModel(m_paneStack);
Chris@0 3287 view->expand(tree->index(0, 0, QModelIndex()));
Chris@0 3288 view->setModel(tree);
Chris@0 3289 view->show();
Chris@0 3290 }
Chris@0 3291
Chris@0 3292 void
Chris@0 3293 MainWindow::preferenceChanged(PropertyContainer::PropertyName name)
Chris@0 3294 {
Chris@0 3295 if (name == "Property Box Layout") {
Chris@0 3296 if (Preferences::getInstance()->getPropertyBoxLayout() ==
Chris@0 3297 Preferences::VerticallyStacked) {
Chris@0 3298 m_paneStack->setLayoutStyle(PaneStack::PropertyStackPerPaneLayout);
Chris@0 3299 } else {
Chris@0 3300 m_paneStack->setLayoutStyle(PaneStack::SinglePropertyStackLayout);
Chris@0 3301 }
Chris@0 3302 }
Chris@0 3303 }
Chris@0 3304
Chris@0 3305 void
Chris@0 3306 MainWindow::preferences()
Chris@0 3307 {
Chris@0 3308 if (!m_preferencesDialog.isNull()) {
Chris@0 3309 m_preferencesDialog->show();
Chris@0 3310 m_preferencesDialog->raise();
Chris@0 3311 return;
Chris@0 3312 }
Chris@0 3313
Chris@0 3314 m_preferencesDialog = new PreferencesDialog(this);
Chris@0 3315
Chris@0 3316 // DeleteOnClose is safe here, because m_preferencesDialog is a
Chris@0 3317 // QPointer that will be zeroed when the dialog is deleted. We
Chris@0 3318 // use it in preference to leaving the dialog lying around because
Chris@0 3319 // if you Cancel the dialog, it resets the preferences state
Chris@0 3320 // without resetting its own widgets, so its state will be
Chris@0 3321 // incorrect when next shown unless we construct it afresh
Chris@0 3322 m_preferencesDialog->setAttribute(Qt::WA_DeleteOnClose);
Chris@0 3323
Chris@0 3324 m_preferencesDialog->show();
Chris@0 3325 }
Chris@0 3326
Chris@0 3327 void
Chris@0 3328 MainWindow::website()
Chris@0 3329 {
Chris@0 3330 openHelpUrl(tr("http://www.sonicvisualiser.org/"));
Chris@0 3331 }
Chris@0 3332
Chris@0 3333 void
Chris@0 3334 MainWindow::help()
Chris@0 3335 {
Chris@0 3336 openHelpUrl(tr("http://www.sonicvisualiser.org/doc/reference/en/"));
Chris@0 3337 }
Chris@0 3338
Chris@0 3339 void
Chris@0 3340 MainWindow::openHelpUrl(QString url)
Chris@0 3341 {
Chris@0 3342 // This method mostly lifted from Qt Assistant source code
Chris@0 3343
Chris@0 3344 QProcess *process = new QProcess(this);
Chris@0 3345 connect(process, SIGNAL(finished(int)), process, SLOT(deleteLater()));
Chris@0 3346
Chris@0 3347 QStringList args;
Chris@0 3348
Chris@0 3349 #ifdef Q_OS_MAC
Chris@0 3350 args.append(url);
Chris@0 3351 process->start("open", args);
Chris@0 3352 #else
Chris@0 3353 #ifdef Q_OS_WIN32
Chris@0 3354
Chris@0 3355 QString pf(getenv("ProgramFiles"));
Chris@0 3356 QString command = pf + QString("\\Internet Explorer\\IEXPLORE.EXE");
Chris@0 3357
Chris@0 3358 args.append(url);
Chris@0 3359 process->start(command, args);
Chris@0 3360
Chris@0 3361 #else
Chris@0 3362 #ifdef Q_WS_X11
Chris@0 3363 if (!qgetenv("KDE_FULL_SESSION").isEmpty()) {
Chris@0 3364 args.append("exec");
Chris@0 3365 args.append(url);
Chris@0 3366 process->start("kfmclient", args);
Chris@0 3367 } else if (!qgetenv("BROWSER").isEmpty()) {
Chris@0 3368 args.append(url);
Chris@0 3369 process->start(qgetenv("BROWSER"), args);
Chris@0 3370 } else {
Chris@0 3371 args.append(url);
Chris@0 3372 process->start("firefox", args);
Chris@0 3373 }
Chris@0 3374 #endif
Chris@0 3375 #endif
Chris@0 3376 #endif
Chris@0 3377 }
Chris@0 3378
Chris@0 3379 void
Chris@0 3380 MainWindow::about()
Chris@0 3381 {
Chris@0 3382 bool debug = false;
Chris@0 3383 QString version = "(unknown version)";
Chris@0 3384
Chris@0 3385 #ifdef BUILD_DEBUG
Chris@0 3386 debug = true;
Chris@0 3387 #endif
Chris@0 3388 #ifdef SV_VERSION
Chris@0 3389 #ifdef SVNREV
Chris@0 3390 version = tr("Release %1 : Revision %2").arg(SV_VERSION).arg(SVNREV);
Chris@0 3391 #else
Chris@0 3392 version = tr("Release %1").arg(SV_VERSION);
Chris@0 3393 #endif
Chris@0 3394 #else
Chris@0 3395 #ifdef SVNREV
Chris@0 3396 version = tr("Unreleased : Revision %1").arg(SVNREV);
Chris@0 3397 #endif
Chris@0 3398 #endif
Chris@0 3399
Chris@0 3400 QString aboutText;
Chris@0 3401
Chris@0 3402 aboutText += tr("<h3>About Sonic Visualiser</h3>");
Chris@0 3403 aboutText += tr("<p>Sonic Visualiser is a program for viewing and exploring audio data for semantic music analysis and annotation.</p>");
Chris@0 3404 aboutText += tr("<p>%1 : %2 build</p>")
Chris@0 3405 .arg(version)
Chris@0 3406 .arg(debug ? tr("Debug") : tr("Release"));
Chris@0 3407
Chris@0 3408 #ifdef BUILD_STATIC
Chris@0 3409 aboutText += tr("<p>Statically linked");
Chris@0 3410 #ifndef QT_SHARED
Chris@0 3411 aboutText += tr("<br>With Qt (v%1) &copy; Trolltech AS").arg(QT_VERSION_STR);
Chris@0 3412 #endif
Chris@0 3413 #ifdef HAVE_JACK
Chris@0 3414 aboutText += tr("<br>With JACK audio output (v%1) &copy; Paul Davis and Jack O'Quin").arg(JACK_VERSION);
Chris@0 3415 #endif
Chris@0 3416 #ifdef HAVE_PORTAUDIO
Chris@0 3417 aboutText += tr("<br>With PortAudio audio output &copy; Ross Bencina and Phil Burk");
Chris@0 3418 #endif
Chris@0 3419 #ifdef HAVE_OGGZ
Chris@0 3420 aboutText += tr("<br>With Ogg file decoder (oggz v%1, fishsound v%2) &copy; CSIRO Australia").arg(OGGZ_VERSION).arg(FISHSOUND_VERSION);
Chris@0 3421 #endif
Chris@0 3422 #ifdef HAVE_MAD
Chris@0 3423 aboutText += tr("<br>With MAD mp3 decoder (v%1) &copy; Underbit Technologies Inc").arg(MAD_VERSION);
Chris@0 3424 #endif
Chris@0 3425 #ifdef HAVE_SAMPLERATE
Chris@0 3426 aboutText += tr("<br>With libsamplerate (v%1) &copy; Erik de Castro Lopo").arg(SAMPLERATE_VERSION);
Chris@0 3427 #endif
Chris@0 3428 #ifdef HAVE_SNDFILE
Chris@0 3429 aboutText += tr("<br>With libsndfile (v%1) &copy; Erik de Castro Lopo").arg(SNDFILE_VERSION);
Chris@0 3430 #endif
Chris@0 3431 #ifdef HAVE_FFTW3
Chris@0 3432 aboutText += tr("<br>With FFTW3 (v%1) &copy; Matteo Frigo and MIT").arg(FFTW3_VERSION);
Chris@0 3433 #endif
Chris@0 3434 #ifdef HAVE_VAMP
Chris@0 3435 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 3436 #endif
Chris@0 3437 aboutText += tr("<br>With LADSPA plugin support (API v%1) &copy; Richard Furse, Paul Davis, Stefan Westerfeld").arg(LADSPA_VERSION);
Chris@0 3438 aboutText += tr("<br>With DSSI plugin support (API v%1) &copy; Chris Cannam, Steve Harris, Sean Bolton").arg(DSSI_VERSION);
Chris@0 3439 aboutText += "</p>";
Chris@0 3440 #endif
Chris@0 3441
Chris@0 3442 aboutText +=
Chris@0 3443 "<p>Sonic Visualiser Copyright &copy; 2005 - 2006 Chris Cannam<br>"
Chris@0 3444 "Centre for Digital Music, Queen Mary, University of London.</p>"
Chris@0 3445 "<p>This program is free software; you can redistribute it and/or<br>"
Chris@0 3446 "modify it under the terms of the GNU General Public License as<br>"
Chris@0 3447 "published by the Free Software Foundation; either version 2 of the<br>"
Chris@0 3448 "License, or (at your option) any later version.<br>See the file "
Chris@0 3449 "COPYING included with this distribution for more information.</p>";
Chris@0 3450
Chris@0 3451 QMessageBox::about(this, tr("About Sonic Visualiser"), aboutText);
Chris@0 3452 }
Chris@0 3453
Chris@0 3454
Chris@0 3455 #ifdef INCLUDE_MOCFILES
Chris@0 3456 #include "MainWindow.moc.cpp"
Chris@0 3457 #endif