annotate main/MainWindow.cpp @ 63:dc7a73ef69af

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