annotate main/MainWindow.cpp @ 97:398889687f3d

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