annotate main/MainWindow.cpp @ 98:32b386dac447

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