annotate main/MainWindow.cpp @ 103:99d44871334b

* better recollection of last opened remote location; remember to offer to save session if modified when opening a new remote location
author Chris Cannam
date Fri, 16 Feb 2007 16:57:15 +0000
parents 32b386dac447
children efc8b5da414a
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@103 2573 QSettings settings;
Chris@103 2574 settings.beginGroup("MainWindow");
Chris@103 2575 QString lastLocation = settings.value("lastremote", "").toString();
Chris@103 2576
Chris@86 2577 bool ok = false;
Chris@86 2578 QString text = QInputDialog::getText
Chris@86 2579 (this, tr("Open Location"),
Chris@86 2580 tr("Please enter the URL of the location to open:"),
Chris@103 2581 QLineEdit::Normal, lastLocation, &ok);
Chris@103 2582
Chris@103 2583 if (!ok) return;
Chris@103 2584
Chris@103 2585 settings.setValue("lastremote", text);
Chris@103 2586
Chris@103 2587 if (text.isEmpty()) return;
Chris@86 2588
Chris@86 2589 if (openURL(QUrl(text)) == FileOpenFailed) {
Chris@86 2590 QMessageBox::critical(this, tr("Failed to open location"),
Chris@86 2591 tr("URL \"%1\" could not be opened").arg(text));
Chris@86 2592 }
Chris@86 2593 }
Chris@86 2594
Chris@86 2595 void
Chris@0 2596 MainWindow::openRecentFile()
Chris@0 2597 {
Chris@0 2598 QObject *obj = sender();
Chris@0 2599 QAction *action = dynamic_cast<QAction *>(obj);
Chris@0 2600
Chris@0 2601 if (!action) {
Chris@0 2602 std::cerr << "WARNING: MainWindow::openRecentFile: sender is not an action"
Chris@0 2603 << std::endl;
Chris@0 2604 return;
Chris@0 2605 }
Chris@0 2606
Chris@0 2607 QString path = action->text();
Chris@0 2608 if (path == "") return;
Chris@0 2609
Chris@86 2610 QUrl url(path);
Chris@86 2611 if (RemoteFile::canHandleScheme(url)) {
Chris@86 2612 openURL(url);
Chris@86 2613 return;
Chris@86 2614 }
Chris@86 2615
Chris@0 2616 if (path.endsWith("sv")) {
Chris@0 2617
Chris@103 2618 if (!checkSaveModified()) return;
Chris@0 2619
Chris@82 2620 if (openSessionFile(path) == FileOpenFailed) {
Chris@0 2621 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 2622 tr("Session file \"%1\" could not be opened").arg(path));
Chris@0 2623 }
Chris@0 2624
Chris@0 2625 } else {
Chris@0 2626
Chris@82 2627 if (openAudioFile(path, AskUser) == FileOpenFailed) {
Chris@0 2628
Chris@0 2629 bool canImportLayer = (getMainModel() != 0 &&
Chris@0 2630 m_paneStack != 0 &&
Chris@0 2631 m_paneStack->getCurrentPane() != 0);
Chris@0 2632
Chris@82 2633 if (!canImportLayer || (openLayerFile(path) == FileOpenFailed)) {
Chris@0 2634
Chris@0 2635 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 2636 tr("File \"%1\" could not be opened").arg(path));
Chris@0 2637 }
Chris@0 2638 }
Chris@0 2639 }
Chris@0 2640 }
Chris@0 2641
Chris@82 2642 MainWindow::FileOpenStatus
Chris@85 2643 MainWindow::openURL(QUrl url)
Chris@85 2644 {
Chris@85 2645 if (url.scheme().toLower() == "file") {
Chris@85 2646 return openSomeFile(url.toLocalFile());
Chris@86 2647 } else if (!RemoteFile::canHandleScheme(url)) {
Chris@85 2648 QMessageBox::critical(this, tr("Unsupported scheme in URL"),
Chris@85 2649 tr("The URL scheme \"%1\" is not supported")
Chris@85 2650 .arg(url.scheme()));
Chris@85 2651 return FileOpenFailed;
Chris@85 2652 } else {
Chris@85 2653 RemoteFile rf(url);
Chris@85 2654 rf.wait();
Chris@85 2655 if (!rf.isOK()) {
Chris@85 2656 QMessageBox::critical(this, tr("File download failed"),
Chris@85 2657 tr("Failed to download URL \"%1\": %2")
Chris@85 2658 .arg(url.toString()).arg(rf.getErrorString()));
Chris@85 2659 return FileOpenFailed;
Chris@85 2660 }
Chris@88 2661 FileOpenStatus status;
Chris@88 2662 if ((status = openSomeFile(rf.getLocalFilename(), url.toString())) !=
Chris@88 2663 FileOpenSucceeded) {
Chris@88 2664 rf.deleteLocalFile();
Chris@88 2665 }
Chris@88 2666 return status;
Chris@85 2667 }
Chris@85 2668 }
Chris@85 2669
Chris@85 2670 MainWindow::FileOpenStatus
Chris@54 2671 MainWindow::openSomeFile(QString path, AudioFileOpenMode mode)
Chris@0 2672 {
Chris@86 2673 return openSomeFile(path, path, mode);
Chris@86 2674 }
Chris@86 2675
Chris@86 2676 MainWindow::FileOpenStatus
Chris@86 2677 MainWindow::openSomeFile(QString path, QString location,
Chris@86 2678 AudioFileOpenMode mode)
Chris@86 2679 {
Chris@82 2680 FileOpenStatus status;
Chris@82 2681
Chris@85 2682 bool canImportLayer = (getMainModel() != 0 &&
Chris@85 2683 m_paneStack != 0 &&
Chris@85 2684 m_paneStack->getCurrentPane() != 0);
Chris@85 2685
Chris@86 2686 if ((status = openAudioFile(path, location, mode)) != FileOpenFailed) {
Chris@82 2687 return status;
Chris@86 2688 } else if ((status = openSessionFile(path, location)) != FileOpenFailed) {
Chris@82 2689 return status;
Chris@85 2690 } else if (!canImportLayer) {
Chris@85 2691 return FileOpenFailed;
Chris@86 2692 } else if ((status = openLayerFile(path, location)) != FileOpenFailed) {
Chris@85 2693 return status;
Chris@0 2694 } else {
Chris@82 2695 return FileOpenFailed;
Chris@0 2696 }
Chris@0 2697 }
Chris@0 2698
Chris@82 2699 MainWindow::FileOpenStatus
Chris@0 2700 MainWindow::openSessionFile(QString path)
Chris@0 2701 {
Chris@86 2702 return openSessionFile(path, path);
Chris@86 2703 }
Chris@86 2704
Chris@86 2705 MainWindow::FileOpenStatus
Chris@86 2706 MainWindow::openSessionFile(QString path, QString location)
Chris@86 2707 {
Chris@0 2708 BZipFileDevice bzFile(path);
Chris@0 2709 if (!bzFile.open(QIODevice::ReadOnly)) {
Chris@86 2710 std::cerr << "Failed to open session file \"" << location.toStdString()
Chris@0 2711 << "\": " << bzFile.errorString().toStdString() << std::endl;
Chris@82 2712 return FileOpenFailed;
Chris@0 2713 }
Chris@0 2714
Chris@103 2715 if (!checkSaveModified()) return FileOpenCancelled;
Chris@103 2716
Chris@0 2717 QString error;
Chris@0 2718 closeSession();
Chris@0 2719 createDocument();
Chris@0 2720
Chris@0 2721 PaneCallback callback(this);
Chris@0 2722 m_viewManager->clearSelections();
Chris@0 2723
Chris@87 2724 SVFileReader reader(m_document, callback, location);
Chris@0 2725 QXmlInputSource inputSource(&bzFile);
Chris@0 2726 reader.parse(inputSource);
Chris@0 2727
Chris@0 2728 if (!reader.isOK()) {
Chris@0 2729 error = tr("SV XML file read error:\n%1").arg(reader.getErrorString());
Chris@0 2730 }
Chris@0 2731
Chris@0 2732 bzFile.close();
Chris@0 2733
Chris@0 2734 bool ok = (error == "");
Chris@86 2735
Chris@86 2736 bool realFile = (location == path);
Chris@0 2737
Chris@0 2738 if (ok) {
Chris@86 2739
Chris@0 2740 setWindowTitle(tr("Sonic Visualiser: %1")
Chris@86 2741 .arg(QFileInfo(location).fileName()));
Chris@86 2742
Chris@86 2743 if (realFile) m_sessionFile = path;
Chris@86 2744
Chris@0 2745 setupMenus();
Chris@0 2746 CommandHistory::getInstance()->clear();
Chris@0 2747 CommandHistory::getInstance()->documentSaved();
Chris@0 2748 m_documentModified = false;
Chris@0 2749 updateMenuStates();
Chris@86 2750
Chris@86 2751 m_recentFiles.addFile(location);
Chris@86 2752
Chris@86 2753 if (realFile) {
Chris@88 2754 registerLastOpenedFilePath(FileFinder::SessionFile, path); // for file dialog
Chris@86 2755 }
Chris@86 2756
Chris@0 2757 } else {
Chris@0 2758 setWindowTitle(tr("Sonic Visualiser"));
Chris@0 2759 }
Chris@0 2760
Chris@82 2761 return ok ? FileOpenSucceeded : FileOpenFailed;
Chris@0 2762 }
Chris@0 2763
Chris@0 2764 void
Chris@0 2765 MainWindow::closeEvent(QCloseEvent *e)
Chris@0 2766 {
Chris@70 2767 if (!m_abandoning && !checkSaveModified()) {
Chris@0 2768 e->ignore();
Chris@0 2769 return;
Chris@0 2770 }
Chris@0 2771
Chris@5 2772 QSettings settings;
Chris@5 2773 settings.beginGroup("MainWindow");
Chris@5 2774 settings.setValue("size", size());
Chris@5 2775 settings.setValue("position", pos());
Chris@5 2776 settings.endGroup();
Chris@5 2777
Chris@0 2778 e->accept();
Chris@0 2779 return;
Chris@0 2780 }
Chris@0 2781
Chris@0 2782 bool
Chris@11 2783 MainWindow::commitData(bool mayAskUser)
Chris@11 2784 {
Chris@11 2785 if (mayAskUser) {
Chris@11 2786 return checkSaveModified();
Chris@11 2787 } else {
Chris@11 2788 if (!m_documentModified) return true;
Chris@11 2789
Chris@11 2790 // If we can't check with the user first, then we can't save
Chris@11 2791 // to the original session file (even if we have it) -- have
Chris@11 2792 // to use a temporary file
Chris@11 2793
Chris@11 2794 QString svDirBase = ".sv1";
Chris@11 2795 QString svDir = QDir::home().filePath(svDirBase);
Chris@11 2796
Chris@11 2797 if (!QFileInfo(svDir).exists()) {
Chris@11 2798 if (!QDir::home().mkdir(svDirBase)) return false;
Chris@11 2799 } else {
Chris@11 2800 if (!QFileInfo(svDir).isDir()) return false;
Chris@11 2801 }
Chris@11 2802
Chris@11 2803 // This name doesn't have to be unguessable
Chris@93 2804 #ifndef _WIN32
Chris@11 2805 QString fname = QString("tmp-%1-%2.sv")
Chris@11 2806 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"))
Chris@11 2807 .arg(QProcess().pid());
Chris@93 2808 #else
Chris@93 2809 QString fname = QString("tmp-%1.sv")
Chris@93 2810 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"));
Chris@93 2811 #endif
Chris@11 2812 QString fpath = QDir(svDir).filePath(fname);
Chris@11 2813 if (saveSessionFile(fpath)) {
Chris@34 2814 m_recentFiles.addFile(fpath);
Chris@11 2815 return true;
Chris@11 2816 } else {
Chris@11 2817 return false;
Chris@11 2818 }
Chris@11 2819 }
Chris@11 2820 }
Chris@11 2821
Chris@11 2822 bool
Chris@0 2823 MainWindow::checkSaveModified()
Chris@0 2824 {
Chris@0 2825 // Called before some destructive operation (e.g. new session,
Chris@0 2826 // exit program). Return true if we can safely proceed, false to
Chris@0 2827 // cancel.
Chris@0 2828
Chris@0 2829 if (!m_documentModified) return true;
Chris@0 2830
Chris@0 2831 int button =
Chris@0 2832 QMessageBox::warning(this,
Chris@0 2833 tr("Session modified"),
Chris@0 2834 tr("The current session has been modified.\nDo you want to save it?"),
Chris@0 2835 QMessageBox::Yes,
Chris@0 2836 QMessageBox::No,
Chris@0 2837 QMessageBox::Cancel);
Chris@0 2838
Chris@0 2839 if (button == QMessageBox::Yes) {
Chris@0 2840 saveSession();
Chris@0 2841 if (m_documentModified) { // save failed -- don't proceed!
Chris@0 2842 return false;
Chris@0 2843 } else {
Chris@0 2844 return true; // saved, so it's safe to continue now
Chris@0 2845 }
Chris@0 2846 } else if (button == QMessageBox::No) {
Chris@0 2847 m_documentModified = false; // so we know to abandon it
Chris@0 2848 return true;
Chris@0 2849 }
Chris@0 2850
Chris@0 2851 // else cancel
Chris@0 2852 return false;
Chris@0 2853 }
Chris@0 2854
Chris@0 2855 void
Chris@0 2856 MainWindow::saveSession()
Chris@0 2857 {
Chris@0 2858 if (m_sessionFile != "") {
Chris@0 2859 if (!saveSessionFile(m_sessionFile)) {
Chris@0 2860 QMessageBox::critical(this, tr("Failed to save file"),
Chris@0 2861 tr("Session file \"%1\" could not be saved.").arg(m_sessionFile));
Chris@0 2862 } else {
Chris@0 2863 CommandHistory::getInstance()->documentSaved();
Chris@0 2864 documentRestored();
Chris@0 2865 }
Chris@0 2866 } else {
Chris@0 2867 saveSessionAs();
Chris@0 2868 }
Chris@0 2869 }
Chris@0 2870
Chris@0 2871 void
Chris@0 2872 MainWindow::saveSessionAs()
Chris@0 2873 {
Chris@0 2874 QString orig = m_audioFile;
Chris@0 2875 if (orig == "") orig = ".";
Chris@0 2876 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 2877
Chris@88 2878 QString path = getSaveFileName(FileFinder::SessionFile);
Chris@81 2879
Chris@81 2880 if (path == "") return;
Chris@0 2881
Chris@0 2882 if (!saveSessionFile(path)) {
Chris@0 2883 QMessageBox::critical(this, tr("Failed to save file"),
Chris@79 2884 tr("Session file \"%1\" could not be saved.").arg(path));
Chris@0 2885 } else {
Chris@0 2886 setWindowTitle(tr("Sonic Visualiser: %1")
Chris@0 2887 .arg(QFileInfo(path).fileName()));
Chris@0 2888 m_sessionFile = path;
Chris@0 2889 CommandHistory::getInstance()->documentSaved();
Chris@0 2890 documentRestored();
Chris@34 2891 m_recentFiles.addFile(path);
Chris@0 2892 }
Chris@0 2893 }
Chris@0 2894
Chris@0 2895 bool
Chris@0 2896 MainWindow::saveSessionFile(QString path)
Chris@0 2897 {
Chris@0 2898 BZipFileDevice bzFile(path);
Chris@0 2899 if (!bzFile.open(QIODevice::WriteOnly)) {
Chris@0 2900 std::cerr << "Failed to open session file \"" << path.toStdString()
Chris@0 2901 << "\" for writing: "
Chris@0 2902 << bzFile.errorString().toStdString() << std::endl;
Chris@0 2903 return false;
Chris@0 2904 }
Chris@0 2905
Chris@0 2906 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
Chris@0 2907
Chris@0 2908 QTextStream out(&bzFile);
Chris@0 2909 toXml(out);
Chris@0 2910 out.flush();
Chris@0 2911
Chris@0 2912 QApplication::restoreOverrideCursor();
Chris@0 2913
Chris@84 2914 if (!bzFile.isOK()) {
Chris@0 2915 QMessageBox::critical(this, tr("Failed to write file"),
Chris@0 2916 tr("Failed to write to file \"%1\": %2")
Chris@0 2917 .arg(path).arg(bzFile.errorString()));
Chris@0 2918 bzFile.close();
Chris@0 2919 return false;
Chris@0 2920 }
Chris@0 2921
Chris@0 2922 bzFile.close();
Chris@0 2923 return true;
Chris@0 2924 }
Chris@0 2925
Chris@0 2926 void
Chris@0 2927 MainWindow::toXml(QTextStream &out)
Chris@0 2928 {
Chris@0 2929 QString indent(" ");
Chris@0 2930
Chris@0 2931 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
Chris@0 2932 out << "<!DOCTYPE sonic-visualiser>\n";
Chris@0 2933 out << "<sv>\n";
Chris@0 2934
Chris@0 2935 m_document->toXml(out, "", "");
Chris@0 2936
Chris@0 2937 out << "<display>\n";
Chris@0 2938
Chris@0 2939 out << QString(" <window width=\"%1\" height=\"%2\"/>\n")
Chris@0 2940 .arg(width()).arg(height());
Chris@0 2941
Chris@0 2942 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@0 2943
Chris@0 2944 Pane *pane = m_paneStack->getPane(i);
Chris@0 2945
Chris@0 2946 if (pane) {
Chris@0 2947 pane->toXml(out, indent);
Chris@0 2948 }
Chris@0 2949 }
Chris@0 2950
Chris@0 2951 out << "</display>\n";
Chris@0 2952
Chris@0 2953 m_viewManager->getSelection().toXml(out);
Chris@0 2954
Chris@0 2955 out << "</sv>\n";
Chris@0 2956 }
Chris@0 2957
Chris@0 2958 Pane *
Chris@0 2959 MainWindow::addPaneToStack()
Chris@0 2960 {
Chris@0 2961 AddPaneCommand *command = new AddPaneCommand(this);
Chris@0 2962 CommandHistory::getInstance()->addCommand(command);
Chris@0 2963 return command->getPane();
Chris@0 2964 }
Chris@0 2965
Chris@0 2966 void
Chris@0 2967 MainWindow::zoomIn()
Chris@0 2968 {
Chris@0 2969 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 2970 if (currentPane) currentPane->zoom(true);
Chris@0 2971 }
Chris@0 2972
Chris@0 2973 void
Chris@0 2974 MainWindow::zoomOut()
Chris@0 2975 {
Chris@0 2976 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 2977 if (currentPane) currentPane->zoom(false);
Chris@0 2978 }
Chris@0 2979
Chris@0 2980 void
Chris@0 2981 MainWindow::zoomToFit()
Chris@0 2982 {
Chris@0 2983 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 2984 if (!currentPane) return;
Chris@0 2985
Chris@0 2986 Model *model = getMainModel();
Chris@0 2987 if (!model) return;
Chris@0 2988
Chris@0 2989 size_t start = model->getStartFrame();
Chris@0 2990 size_t end = model->getEndFrame();
Chris@0 2991 size_t pixels = currentPane->width();
Chris@0 2992 size_t zoomLevel = (end - start) / pixels;
Chris@0 2993
Chris@0 2994 currentPane->setZoomLevel(zoomLevel);
Chris@0 2995 currentPane->setStartFrame(start);
Chris@0 2996 }
Chris@0 2997
Chris@0 2998 void
Chris@0 2999 MainWindow::zoomDefault()
Chris@0 3000 {
Chris@0 3001 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 3002 if (currentPane) currentPane->setZoomLevel(1024);
Chris@0 3003 }
Chris@0 3004
Chris@0 3005 void
Chris@0 3006 MainWindow::scrollLeft()
Chris@0 3007 {
Chris@0 3008 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 3009 if (currentPane) currentPane->scroll(false, false);
Chris@0 3010 }
Chris@0 3011
Chris@0 3012 void
Chris@0 3013 MainWindow::jumpLeft()
Chris@0 3014 {
Chris@0 3015 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 3016 if (currentPane) currentPane->scroll(false, true);
Chris@0 3017 }
Chris@0 3018
Chris@0 3019 void
Chris@0 3020 MainWindow::scrollRight()
Chris@0 3021 {
Chris@0 3022 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 3023 if (currentPane) currentPane->scroll(true, false);
Chris@0 3024 }
Chris@0 3025
Chris@0 3026 void
Chris@0 3027 MainWindow::jumpRight()
Chris@0 3028 {
Chris@0 3029 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@0 3030 if (currentPane) currentPane->scroll(true, true);
Chris@0 3031 }
Chris@0 3032
Chris@0 3033 void
Chris@0 3034 MainWindow::showNoOverlays()
Chris@0 3035 {
Chris@0 3036 m_viewManager->setOverlayMode(ViewManager::NoOverlays);
Chris@0 3037 }
Chris@0 3038
Chris@0 3039 void
Chris@90 3040 MainWindow::showMinimalOverlays()
Chris@0 3041 {
Chris@90 3042 m_viewManager->setOverlayMode(ViewManager::MinimalOverlays);
Chris@0 3043 }
Chris@0 3044
Chris@0 3045 void
Chris@90 3046 MainWindow::showStandardOverlays()
Chris@90 3047 {
Chris@90 3048 m_viewManager->setOverlayMode(ViewManager::StandardOverlays);
Chris@90 3049 }
Chris@90 3050
Chris@90 3051 void
Chris@90 3052 MainWindow::showAllOverlays()
Chris@0 3053 {
Chris@0 3054 m_viewManager->setOverlayMode(ViewManager::AllOverlays);
Chris@0 3055 }
Chris@0 3056
Chris@0 3057 void
Chris@7 3058 MainWindow::toggleZoomWheels()
Chris@7 3059 {
Chris@7 3060 if (m_viewManager->getZoomWheelsEnabled()) {
Chris@7 3061 m_viewManager->setZoomWheelsEnabled(false);
Chris@7 3062 } else {
Chris@7 3063 m_viewManager->setZoomWheelsEnabled(true);
Chris@7 3064 }
Chris@7 3065 }
Chris@7 3066
Chris@7 3067 void
Chris@72 3068 MainWindow::togglePropertyBoxes()
Chris@72 3069 {
Chris@72 3070 if (m_paneStack->getLayoutStyle() == PaneStack::NoPropertyStacks) {
Chris@72 3071 if (Preferences::getInstance()->getPropertyBoxLayout() ==
Chris@72 3072 Preferences::VerticallyStacked) {
Chris@72 3073 m_paneStack->setLayoutStyle(PaneStack::PropertyStackPerPaneLayout);
Chris@72 3074 } else {
Chris@72 3075 m_paneStack->setLayoutStyle(PaneStack::SinglePropertyStackLayout);
Chris@72 3076 }
Chris@72 3077 } else {
Chris@72 3078 m_paneStack->setLayoutStyle(PaneStack::NoPropertyStacks);
Chris@72 3079 }
Chris@72 3080 }
Chris@72 3081
Chris@72 3082 void
Chris@90 3083 MainWindow::toggleStatusBar()
Chris@90 3084 {
Chris@90 3085 QSettings settings;
Chris@90 3086 settings.beginGroup("MainWindow");
Chris@90 3087 bool sb = settings.value("showstatusbar", true).toBool();
Chris@90 3088
Chris@90 3089 if (sb) {
Chris@90 3090 statusBar()->hide();
Chris@90 3091 } else {
Chris@90 3092 statusBar()->show();
Chris@90 3093 }
Chris@90 3094
Chris@90 3095 settings.setValue("showstatusbar", !sb);
Chris@90 3096
Chris@90 3097 settings.endGroup();
Chris@90 3098 }
Chris@90 3099
Chris@90 3100 void
Chris@72 3101 MainWindow::preferenceChanged(PropertyContainer::PropertyName name)
Chris@72 3102 {
Chris@72 3103 if (name == "Property Box Layout") {
Chris@72 3104 if (m_paneStack->getLayoutStyle() != PaneStack::NoPropertyStacks) {
Chris@72 3105 if (Preferences::getInstance()->getPropertyBoxLayout() ==
Chris@72 3106 Preferences::VerticallyStacked) {
Chris@72 3107 m_paneStack->setLayoutStyle(PaneStack::PropertyStackPerPaneLayout);
Chris@72 3108 } else {
Chris@72 3109 m_paneStack->setLayoutStyle(PaneStack::SinglePropertyStackLayout);
Chris@72 3110 }
Chris@72 3111 }
Chris@72 3112 }
Chris@72 3113 }
Chris@72 3114
Chris@72 3115 void
Chris@0 3116 MainWindow::play()
Chris@0 3117 {
Chris@0 3118 if (m_playSource->isPlaying()) {
Chris@0 3119 m_playSource->stop();
Chris@0 3120 } else {
Chris@0 3121 m_playSource->play(m_viewManager->getPlaybackFrame());
Chris@0 3122 }
Chris@0 3123 }
Chris@0 3124
Chris@0 3125 void
Chris@0 3126 MainWindow::ffwd()
Chris@0 3127 {
Chris@0 3128 if (!getMainModel()) return;
Chris@0 3129
Chris@0 3130 int frame = m_viewManager->getPlaybackFrame();
Chris@0 3131 ++frame;
Chris@0 3132
Chris@0 3133 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 3134 if (!pane) return;
Chris@0 3135
Chris@0 3136 Layer *layer = pane->getSelectedLayer();
Chris@0 3137
Chris@0 3138 if (!dynamic_cast<TimeInstantLayer *>(layer) &&
Chris@0 3139 !dynamic_cast<TimeValueLayer *>(layer)) return;
Chris@0 3140
Chris@0 3141 size_t resolution = 0;
Chris@0 3142 if (!layer->snapToFeatureFrame(pane, frame, resolution, Layer::SnapRight)) {
Chris@0 3143 frame = getMainModel()->getEndFrame();
Chris@0 3144 }
Chris@0 3145
Chris@0 3146 m_viewManager->setPlaybackFrame(frame);
Chris@0 3147 }
Chris@0 3148
Chris@0 3149 void
Chris@0 3150 MainWindow::ffwdEnd()
Chris@0 3151 {
Chris@0 3152 if (!getMainModel()) return;
Chris@0 3153 m_viewManager->setPlaybackFrame(getMainModel()->getEndFrame());
Chris@0 3154 }
Chris@0 3155
Chris@0 3156 void
Chris@0 3157 MainWindow::rewind()
Chris@0 3158 {
Chris@0 3159 if (!getMainModel()) return;
Chris@0 3160
Chris@0 3161 int frame = m_viewManager->getPlaybackFrame();
Chris@0 3162 if (frame > 0) --frame;
Chris@0 3163
Chris@0 3164 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 3165 if (!pane) return;
Chris@0 3166
Chris@0 3167 Layer *layer = pane->getSelectedLayer();
Chris@0 3168
Chris@0 3169 if (!dynamic_cast<TimeInstantLayer *>(layer) &&
Chris@0 3170 !dynamic_cast<TimeValueLayer *>(layer)) return;
Chris@0 3171
Chris@0 3172 size_t resolution = 0;
Chris@0 3173 if (!layer->snapToFeatureFrame(pane, frame, resolution, Layer::SnapLeft)) {
Chris@0 3174 frame = getMainModel()->getEndFrame();
Chris@0 3175 }
Chris@0 3176
Chris@0 3177 m_viewManager->setPlaybackFrame(frame);
Chris@0 3178 }
Chris@0 3179
Chris@0 3180 void
Chris@0 3181 MainWindow::rewindStart()
Chris@0 3182 {
Chris@0 3183 if (!getMainModel()) return;
Chris@0 3184 m_viewManager->setPlaybackFrame(getMainModel()->getStartFrame());
Chris@0 3185 }
Chris@0 3186
Chris@0 3187 void
Chris@0 3188 MainWindow::stop()
Chris@0 3189 {
Chris@0 3190 m_playSource->stop();
Chris@0 3191 }
Chris@0 3192
Chris@0 3193 void
Chris@0 3194 MainWindow::addPane()
Chris@0 3195 {
Chris@0 3196 QObject *s = sender();
Chris@0 3197 QAction *action = dynamic_cast<QAction *>(s);
Chris@0 3198
Chris@0 3199 if (!action) {
Chris@0 3200 std::cerr << "WARNING: MainWindow::addPane: sender is not an action"
Chris@0 3201 << std::endl;
Chris@0 3202 return;
Chris@0 3203 }
Chris@0 3204
Chris@0 3205 PaneActionMap::iterator i = m_paneActions.find(action);
Chris@0 3206
Chris@0 3207 if (i == m_paneActions.end()) {
Chris@0 3208 std::cerr << "WARNING: MainWindow::addPane: unknown action "
Chris@0 3209 << action->objectName().toStdString() << std::endl;
Chris@0 3210 return;
Chris@0 3211 }
Chris@0 3212
Chris@69 3213 addPane(i->second, action->text());
Chris@69 3214 }
Chris@69 3215
Chris@69 3216 void
Chris@69 3217 MainWindow::addPane(const PaneConfiguration &configuration, QString text)
Chris@69 3218 {
Chris@69 3219 CommandHistory::getInstance()->startCompoundOperation(text, true);
Chris@0 3220
Chris@0 3221 AddPaneCommand *command = new AddPaneCommand(this);
Chris@0 3222 CommandHistory::getInstance()->addCommand(command);
Chris@0 3223
Chris@0 3224 Pane *pane = command->getPane();
Chris@0 3225
Chris@69 3226 if (configuration.layer == LayerFactory::Spectrum) {
Chris@7 3227 pane->setPlaybackFollow(View::PlaybackScrollContinuous);
Chris@7 3228 }
Chris@7 3229
Chris@69 3230 if (configuration.layer != LayerFactory::TimeRuler &&
Chris@69 3231 configuration.layer != LayerFactory::Spectrum) {
Chris@8 3232
Chris@0 3233 if (!m_timeRulerLayer) {
Chris@0 3234 // std::cerr << "no time ruler layer, creating one" << std::endl;
Chris@0 3235 m_timeRulerLayer = m_document->createMainModelLayer
Chris@0 3236 (LayerFactory::TimeRuler);
Chris@0 3237 }
Chris@0 3238
Chris@0 3239 // std::cerr << "adding time ruler layer " << m_timeRulerLayer << std::endl;
Chris@0 3240
Chris@0 3241 m_document->addLayerToView(pane, m_timeRulerLayer);
Chris@0 3242 }
Chris@0 3243
Chris@69 3244 Layer *newLayer = m_document->createLayer(configuration.layer);
Chris@69 3245
Chris@69 3246 Model *suggestedModel = configuration.sourceModel;
Chris@66 3247 Model *model = 0;
Chris@66 3248
Chris@66 3249 if (suggestedModel) {
Chris@66 3250
Chris@66 3251 // check its validity
Chris@66 3252 std::vector<Model *> inputModels = m_document->getTransformInputModels();
Chris@66 3253 for (size_t j = 0; j < inputModels.size(); ++j) {
Chris@66 3254 if (inputModels[j] == suggestedModel) {
Chris@66 3255 model = suggestedModel;
Chris@66 3256 break;
Chris@66 3257 }
Chris@66 3258 }
Chris@66 3259
Chris@66 3260 if (!model) {
Chris@66 3261 std::cerr << "WARNING: Model " << (void *)suggestedModel
Chris@66 3262 << " appears in pane action map, but is not reported "
Chris@66 3263 << "by document as a valid transform source" << std::endl;
Chris@66 3264 }
Chris@66 3265 }
Chris@66 3266
Chris@66 3267 if (!model) model = m_document->getMainModel();
Chris@66 3268
Chris@66 3269 m_document->setModel(newLayer, model);
Chris@66 3270
Chris@69 3271 m_document->setChannel(newLayer, configuration.channel);
Chris@0 3272 m_document->addLayerToView(pane, newLayer);
Chris@0 3273
Chris@0 3274 m_paneStack->setCurrentPane(pane);
Chris@70 3275 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 3276
Chris@73 3277 std::cerr << "MainWindow::addPane: global centre frame is "
Chris@73 3278 << m_viewManager->getGlobalCentreFrame() << std::endl;
Chris@73 3279 pane->setCentreFrame(m_viewManager->getGlobalCentreFrame());
Chris@73 3280
Chris@0 3281 CommandHistory::getInstance()->endCompoundOperation();
Chris@0 3282
Chris@0 3283 updateMenuStates();
Chris@0 3284 }
Chris@0 3285
Chris@0 3286 MainWindow::AddPaneCommand::AddPaneCommand(MainWindow *mw) :
Chris@0 3287 m_mw(mw),
Chris@0 3288 m_pane(0),
Chris@0 3289 m_prevCurrentPane(0),
Chris@0 3290 m_added(false)
Chris@0 3291 {
Chris@0 3292 }
Chris@0 3293
Chris@0 3294 MainWindow::AddPaneCommand::~AddPaneCommand()
Chris@0 3295 {
Chris@0 3296 if (m_pane && !m_added) {
Chris@0 3297 m_mw->m_paneStack->deletePane(m_pane);
Chris@0 3298 }
Chris@0 3299 }
Chris@0 3300
Chris@0 3301 QString
Chris@0 3302 MainWindow::AddPaneCommand::getName() const
Chris@0 3303 {
Chris@0 3304 return tr("Add Pane");
Chris@0 3305 }
Chris@0 3306
Chris@0 3307 void
Chris@0 3308 MainWindow::AddPaneCommand::execute()
Chris@0 3309 {
Chris@0 3310 if (!m_pane) {
Chris@0 3311 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
Chris@0 3312 m_pane = m_mw->m_paneStack->addPane();
Chris@90 3313
Chris@90 3314 connect(m_pane, SIGNAL(contextHelpChanged(const QString &)),
Chris@90 3315 m_mw->statusBar(), SLOT(showMessage(const QString &)));
Chris@0 3316 } else {
Chris@0 3317 m_mw->m_paneStack->showPane(m_pane);
Chris@0 3318 }
Chris@0 3319
Chris@0 3320 m_mw->m_paneStack->setCurrentPane(m_pane);
Chris@65 3321 m_mw->m_overview->registerView(m_pane);
Chris@0 3322 m_added = true;
Chris@0 3323 }
Chris@0 3324
Chris@0 3325 void
Chris@0 3326 MainWindow::AddPaneCommand::unexecute()
Chris@0 3327 {
Chris@0 3328 m_mw->m_paneStack->hidePane(m_pane);
Chris@0 3329 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
Chris@65 3330 m_mw->m_overview->unregisterView(m_pane);
Chris@0 3331 m_added = false;
Chris@0 3332 }
Chris@0 3333
Chris@0 3334 MainWindow::RemovePaneCommand::RemovePaneCommand(MainWindow *mw, Pane *pane) :
Chris@0 3335 m_mw(mw),
Chris@0 3336 m_pane(pane),
Chris@0 3337 m_added(true)
Chris@0 3338 {
Chris@0 3339 }
Chris@0 3340
Chris@0 3341 MainWindow::RemovePaneCommand::~RemovePaneCommand()
Chris@0 3342 {
Chris@0 3343 if (m_pane && !m_added) {
Chris@0 3344 m_mw->m_paneStack->deletePane(m_pane);
Chris@0 3345 }
Chris@0 3346 }
Chris@0 3347
Chris@0 3348 QString
Chris@0 3349 MainWindow::RemovePaneCommand::getName() const
Chris@0 3350 {
Chris@0 3351 return tr("Remove Pane");
Chris@0 3352 }
Chris@0 3353
Chris@0 3354 void
Chris@0 3355 MainWindow::RemovePaneCommand::execute()
Chris@0 3356 {
Chris@0 3357 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
Chris@0 3358 m_mw->m_paneStack->hidePane(m_pane);
Chris@65 3359 m_mw->m_overview->unregisterView(m_pane);
Chris@0 3360 m_added = false;
Chris@0 3361 }
Chris@0 3362
Chris@0 3363 void
Chris@0 3364 MainWindow::RemovePaneCommand::unexecute()
Chris@0 3365 {
Chris@0 3366 m_mw->m_paneStack->showPane(m_pane);
Chris@0 3367 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
Chris@65 3368 m_mw->m_overview->registerView(m_pane);
Chris@0 3369 m_added = true;
Chris@0 3370 }
Chris@0 3371
Chris@0 3372 void
Chris@0 3373 MainWindow::addLayer()
Chris@0 3374 {
Chris@0 3375 QObject *s = sender();
Chris@0 3376 QAction *action = dynamic_cast<QAction *>(s);
Chris@0 3377
Chris@0 3378 if (!action) {
Chris@0 3379 std::cerr << "WARNING: MainWindow::addLayer: sender is not an action"
Chris@0 3380 << std::endl;
Chris@0 3381 return;
Chris@0 3382 }
Chris@0 3383
Chris@0 3384 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 3385
Chris@0 3386 if (!pane) {
Chris@0 3387 std::cerr << "WARNING: MainWindow::addLayer: no current pane" << std::endl;
Chris@0 3388 return;
Chris@0 3389 }
Chris@0 3390
Chris@0 3391 ExistingLayerActionMap::iterator ei = m_existingLayerActions.find(action);
Chris@0 3392
Chris@0 3393 if (ei != m_existingLayerActions.end()) {
Chris@0 3394 Layer *newLayer = ei->second;
Chris@0 3395 m_document->addLayerToView(pane, newLayer);
Chris@0 3396 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 3397 return;
Chris@0 3398 }
Chris@0 3399
Chris@95 3400 ei = m_sliceActions.find(action);
Chris@95 3401
Chris@95 3402 if (ei != m_sliceActions.end()) {
Chris@95 3403 Layer *newLayer = m_document->createLayer(LayerFactory::Slice);
Chris@95 3404 // document->setModel(newLayer, ei->second->getModel());
Chris@95 3405 SliceableLayer *source = dynamic_cast<SliceableLayer *>(ei->second);
Chris@95 3406 SliceLayer *dest = dynamic_cast<SliceLayer *>(newLayer);
Chris@95 3407 if (source && dest) {
Chris@95 3408 dest->setSliceableModel(source->getSliceableModel());
Chris@95 3409 connect(source, SIGNAL(sliceableModelReplaced(const Model *, const Model *)),
Chris@95 3410 dest, SLOT(sliceableModelReplaced(const Model *, const Model *)));
Chris@95 3411 connect(m_document, SIGNAL(modelAboutToBeDeleted(Model *)),
Chris@95 3412 dest, SLOT(modelAboutToBeDeleted(Model *)));
Chris@95 3413 }
Chris@95 3414 m_document->addLayerToView(pane, newLayer);
Chris@95 3415 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@95 3416 return;
Chris@95 3417 }
Chris@95 3418
Chris@34 3419 TransformActionMap::iterator i = m_transformActions.find(action);
Chris@34 3420
Chris@34 3421 if (i == m_transformActions.end()) {
Chris@0 3422
Chris@0 3423 LayerActionMap::iterator i = m_layerActions.find(action);
Chris@0 3424
Chris@0 3425 if (i == m_layerActions.end()) {
Chris@0 3426 std::cerr << "WARNING: MainWindow::addLayer: unknown action "
Chris@0 3427 << action->objectName().toStdString() << std::endl;
Chris@0 3428 return;
Chris@0 3429 }
Chris@0 3430
Chris@0 3431 LayerFactory::LayerType type = i->second;
Chris@0 3432
Chris@0 3433 LayerFactory::LayerTypeSet emptyTypes =
Chris@0 3434 LayerFactory::getInstance()->getValidEmptyLayerTypes();
Chris@0 3435
Chris@0 3436 Layer *newLayer;
Chris@0 3437
Chris@0 3438 if (emptyTypes.find(type) != emptyTypes.end()) {
Chris@0 3439
Chris@0 3440 newLayer = m_document->createEmptyLayer(type);
Chris@0 3441 m_toolActions[ViewManager::DrawMode]->trigger();
Chris@0 3442
Chris@0 3443 } else {
Chris@0 3444
Chris@0 3445 newLayer = m_document->createMainModelLayer(type);
Chris@0 3446 }
Chris@0 3447
Chris@0 3448 m_document->addLayerToView(pane, newLayer);
Chris@0 3449 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 3450
Chris@0 3451 return;
Chris@0 3452 }
Chris@0 3453
Chris@0 3454 TransformName transform = i->second;
Chris@0 3455 TransformFactory *factory = TransformFactory::getInstance();
Chris@0 3456
Chris@0 3457 QString configurationXml;
Chris@0 3458
Chris@0 3459 int channel = -1;
Chris@0 3460 // pick up the default channel from any existing layers on the same pane
Chris@0 3461 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@0 3462 int c = LayerFactory::getInstance()->getChannel(pane->getLayer(j));
Chris@0 3463 if (c != -1) {
Chris@0 3464 channel = c;
Chris@0 3465 break;
Chris@0 3466 }
Chris@0 3467 }
Chris@0 3468
Chris@33 3469 // We always ask for configuration, even if the plugin isn't
Chris@33 3470 // supposed to be configurable, because we need to let the user
Chris@33 3471 // change the execution context (block size etc).
Chris@0 3472
Chris@27 3473 PluginTransform::ExecutionContext context(channel);
Chris@27 3474
Chris@66 3475 std::vector<Model *> candidateInputModels =
Chris@66 3476 m_document->getTransformInputModels();
Chris@53 3477
Chris@54 3478 Model *inputModel = factory->getConfigurationForTransform(transform,
Chris@54 3479 candidateInputModels,
Chris@54 3480 context,
Chris@54 3481 configurationXml,
Chris@54 3482 m_playSource);
Chris@54 3483 if (!inputModel) return;
Chris@54 3484
Chris@54 3485 std::cerr << "Input model is " << inputModel << " \"" << inputModel->objectName().toStdString() << std::endl;
Chris@0 3486
Chris@0 3487 Layer *newLayer = m_document->createDerivedLayer(transform,
Chris@54 3488 inputModel,
Chris@27 3489 context,
Chris@0 3490 configurationXml);
Chris@0 3491
Chris@0 3492 if (newLayer) {
Chris@0 3493 m_document->addLayerToView(pane, newLayer);
Chris@27 3494 m_document->setChannel(newLayer, context.channel);
Chris@34 3495 m_recentTransforms.add(transform);
Chris@70 3496 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 3497 }
Chris@0 3498
Chris@0 3499 updateMenuStates();
Chris@0 3500 }
Chris@0 3501
Chris@0 3502 void
Chris@0 3503 MainWindow::deleteCurrentPane()
Chris@0 3504 {
Chris@0 3505 CommandHistory::getInstance()->startCompoundOperation
Chris@0 3506 (tr("Delete Pane"), true);
Chris@0 3507
Chris@0 3508 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 3509 if (pane) {
Chris@0 3510 while (pane->getLayerCount() > 0) {
Chris@0 3511 Layer *layer = pane->getLayer(0);
Chris@0 3512 if (layer) {
Chris@0 3513 m_document->removeLayerFromView(pane, layer);
Chris@0 3514 } else {
Chris@0 3515 break;
Chris@0 3516 }
Chris@0 3517 }
Chris@0 3518
Chris@0 3519 RemovePaneCommand *command = new RemovePaneCommand(this, pane);
Chris@0 3520 CommandHistory::getInstance()->addCommand(command);
Chris@0 3521 }
Chris@0 3522
Chris@0 3523 CommandHistory::getInstance()->endCompoundOperation();
Chris@0 3524
Chris@0 3525 updateMenuStates();
Chris@0 3526 }
Chris@0 3527
Chris@0 3528 void
Chris@0 3529 MainWindow::deleteCurrentLayer()
Chris@0 3530 {
Chris@0 3531 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 3532 if (pane) {
Chris@0 3533 Layer *layer = pane->getSelectedLayer();
Chris@0 3534 if (layer) {
Chris@0 3535 m_document->removeLayerFromView(pane, layer);
Chris@0 3536 }
Chris@0 3537 }
Chris@0 3538 updateMenuStates();
Chris@0 3539 }
Chris@0 3540
Chris@0 3541 void
Chris@0 3542 MainWindow::renameCurrentLayer()
Chris@0 3543 {
Chris@0 3544 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 3545 if (pane) {
Chris@0 3546 Layer *layer = pane->getSelectedLayer();
Chris@0 3547 if (layer) {
Chris@0 3548 bool ok = false;
Chris@0 3549 QString newName = QInputDialog::getText
Chris@0 3550 (this, tr("Rename Layer"),
Chris@0 3551 tr("New name for this layer:"),
Chris@0 3552 QLineEdit::Normal, layer->objectName(), &ok);
Chris@0 3553 if (ok) {
Chris@0 3554 layer->setObjectName(newName);
Chris@95 3555 setupExistingLayersMenus();
Chris@0 3556 }
Chris@0 3557 }
Chris@0 3558 }
Chris@0 3559 }
Chris@0 3560
Chris@0 3561 void
Chris@59 3562 MainWindow::playSpeedChanged(int position)
Chris@0 3563 {
Chris@59 3564 PlaySpeedRangeMapper mapper(0, 200);
Chris@60 3565
Chris@60 3566 float percent = m_playSpeed->mappedValue();
Chris@60 3567
Chris@60 3568 float factor = mapper.getFactorForValue(percent);
Chris@60 3569
Chris@60 3570 // float factor = mapper.getFactorForPosition(position);
Chris@60 3571 // float percent = mapper.getValueForPosition(position);
Chris@60 3572
Chris@60 3573 std::cerr << "speed = " << position << " percent = " << percent << " factor = " << factor << std::endl;
Chris@60 3574
Chris@60 3575 //!!! bool slow = (position < 100);
Chris@59 3576 bool something = (position != 100);
Chris@60 3577 /*!!!
Chris@59 3578 int pc = lrintf(percent);
Chris@21 3579
Chris@21 3580 m_playSpeed->setToolTip(tr("Playback speed: %1%2%")
Chris@60 3581 .arg(!slow ? "+" : "")
Chris@21 3582 .arg(pc));
Chris@60 3583 */
Chris@25 3584 m_playSharpen->setEnabled(something);
Chris@26 3585 m_playMono->setEnabled(something);
Chris@25 3586 bool sharpen = (something && m_playSharpen->isChecked());
Chris@26 3587 bool mono = (something && m_playMono->isChecked());
Chris@26 3588 m_playSource->setTimeStretch(factor, sharpen, mono);
Chris@16 3589 }
Chris@16 3590
Chris@16 3591 void
Chris@16 3592 MainWindow::playSharpenToggled()
Chris@16 3593 {
Chris@21 3594 QSettings settings;
Chris@21 3595 settings.beginGroup("MainWindow");
Chris@21 3596 settings.setValue("playsharpen", m_playSharpen->isChecked());
Chris@21 3597 settings.endGroup();
Chris@21 3598
Chris@16 3599 playSpeedChanged(m_playSpeed->value());
Chris@0 3600 }
Chris@0 3601
Chris@0 3602 void
Chris@26 3603 MainWindow::playMonoToggled()
Chris@26 3604 {
Chris@26 3605 QSettings settings;
Chris@26 3606 settings.beginGroup("MainWindow");
Chris@26 3607 settings.setValue("playmono", m_playMono->isChecked());
Chris@26 3608 settings.endGroup();
Chris@26 3609
Chris@26 3610 playSpeedChanged(m_playSpeed->value());
Chris@26 3611 }
Chris@26 3612
Chris@26 3613 void
Chris@0 3614 MainWindow::outputLevelsChanged(float left, float right)
Chris@0 3615 {
Chris@0 3616 m_fader->setPeakLeft(left);
Chris@0 3617 m_fader->setPeakRight(right);
Chris@0 3618 }
Chris@0 3619
Chris@0 3620 void
Chris@0 3621 MainWindow::sampleRateMismatch(size_t requested, size_t actual,
Chris@0 3622 bool willResample)
Chris@0 3623 {
Chris@0 3624 if (!willResample) {
Chris@0 3625 //!!! more helpful message needed
Chris@0 3626 QMessageBox::information
Chris@0 3627 (this, tr("Sample rate mismatch"),
Chris@0 3628 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 3629 .arg(requested).arg(actual));
Chris@0 3630 }
Chris@0 3631
Chris@0 3632 /*!!! Let's not do this for now, and see how we go -- now that we're putting
Chris@0 3633 sample rate information in the status bar
Chris@0 3634
Chris@0 3635 QMessageBox::information
Chris@0 3636 (this, tr("Sample rate mismatch"),
Chris@0 3637 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 3638 .arg(requested).arg(actual));
Chris@0 3639 */
Chris@0 3640
Chris@0 3641 updateDescriptionLabel();
Chris@0 3642 }
Chris@0 3643
Chris@0 3644 void
Chris@42 3645 MainWindow::audioOverloadPluginDisabled()
Chris@42 3646 {
Chris@42 3647 QMessageBox::information
Chris@42 3648 (this, tr("Audio processing overload"),
Chris@42 3649 tr("Audio effects plugin auditioning has been disabled\ndue to a processing overload."));
Chris@42 3650 }
Chris@42 3651
Chris@42 3652 void
Chris@0 3653 MainWindow::layerAdded(Layer *layer)
Chris@0 3654 {
Chris@0 3655 // std::cerr << "MainWindow::layerAdded(" << layer << ")" << std::endl;
Chris@0 3656 // setupExistingLayersMenu();
Chris@0 3657 updateMenuStates();
Chris@0 3658 }
Chris@0 3659
Chris@0 3660 void
Chris@0 3661 MainWindow::layerRemoved(Layer *layer)
Chris@0 3662 {
Chris@0 3663 // std::cerr << "MainWindow::layerRemoved(" << layer << ")" << std::endl;
Chris@95 3664 setupExistingLayersMenus();
Chris@0 3665 updateMenuStates();
Chris@0 3666 }
Chris@0 3667
Chris@0 3668 void
Chris@0 3669 MainWindow::layerAboutToBeDeleted(Layer *layer)
Chris@0 3670 {
Chris@0 3671 // std::cerr << "MainWindow::layerAboutToBeDeleted(" << layer << ")" << std::endl;
Chris@0 3672 if (layer == m_timeRulerLayer) {
Chris@0 3673 // std::cerr << "(this is the time ruler layer)" << std::endl;
Chris@0 3674 m_timeRulerLayer = 0;
Chris@0 3675 }
Chris@0 3676 }
Chris@0 3677
Chris@0 3678 void
Chris@0 3679 MainWindow::layerInAView(Layer *layer, bool inAView)
Chris@0 3680 {
Chris@0 3681 // std::cerr << "MainWindow::layerInAView(" << layer << "," << inAView << ")" << std::endl;
Chris@0 3682
Chris@0 3683 // Check whether we need to add or remove model from play source
Chris@0 3684 Model *model = layer->getModel();
Chris@0 3685 if (model) {
Chris@0 3686 if (inAView) {
Chris@0 3687 m_playSource->addModel(model);
Chris@0 3688 } else {
Chris@0 3689 bool found = false;
Chris@0 3690 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@0 3691 Pane *pane = m_paneStack->getPane(i);
Chris@0 3692 if (!pane) continue;
Chris@0 3693 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@0 3694 Layer *pl = pane->getLayer(j);
Chris@0 3695 if (pl && pl->getModel() == model) {
Chris@0 3696 found = true;
Chris@0 3697 break;
Chris@0 3698 }
Chris@0 3699 }
Chris@0 3700 if (found) break;
Chris@0 3701 }
Chris@0 3702 if (!found) m_playSource->removeModel(model);
Chris@0 3703 }
Chris@0 3704 }
Chris@0 3705
Chris@95 3706 setupExistingLayersMenus();
Chris@0 3707 updateMenuStates();
Chris@0 3708 }
Chris@0 3709
Chris@0 3710 void
Chris@0 3711 MainWindow::modelAdded(Model *model)
Chris@0 3712 {
Chris@0 3713 // std::cerr << "MainWindow::modelAdded(" << model << ")" << std::endl;
Chris@0 3714 m_playSource->addModel(model);
Chris@66 3715 if (dynamic_cast<DenseTimeValueModel *>(model)) {
Chris@66 3716 setupPaneAndLayerMenus();
Chris@66 3717 }
Chris@0 3718 }
Chris@0 3719
Chris@0 3720 void
Chris@0 3721 MainWindow::mainModelChanged(WaveFileModel *model)
Chris@0 3722 {
Chris@0 3723 // std::cerr << "MainWindow::mainModelChanged(" << model << ")" << std::endl;
Chris@0 3724 updateDescriptionLabel();
Chris@0 3725 m_panLayer->setModel(model);
Chris@0 3726 if (model) m_viewManager->setMainModelSampleRate(model->getSampleRate());
Chris@46 3727 if (model && !m_playTarget && m_audioOutput) createPlayTarget();
Chris@0 3728 }
Chris@0 3729
Chris@0 3730 void
Chris@0 3731 MainWindow::modelAboutToBeDeleted(Model *model)
Chris@0 3732 {
Chris@0 3733 // std::cerr << "MainWindow::modelAboutToBeDeleted(" << model << ")" << std::endl;
Chris@0 3734 m_playSource->removeModel(model);
Chris@91 3735 FFTDataServer::modelAboutToBeDeleted(model);
Chris@0 3736 }
Chris@0 3737
Chris@0 3738 void
Chris@0 3739 MainWindow::modelGenerationFailed(QString transformName)
Chris@0 3740 {
Chris@0 3741 QMessageBox::warning
Chris@0 3742 (this,
Chris@0 3743 tr("Failed to generate layer"),
Chris@34 3744 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 3745 .arg(transformName),
Chris@0 3746 QMessageBox::Ok, 0);
Chris@0 3747 }
Chris@0 3748
Chris@0 3749 void
Chris@0 3750 MainWindow::modelRegenerationFailed(QString layerName, QString transformName)
Chris@0 3751 {
Chris@0 3752 QMessageBox::warning
Chris@0 3753 (this,
Chris@0 3754 tr("Failed to regenerate layer"),
Chris@34 3755 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 3756 .arg(layerName).arg(transformName),
Chris@0 3757 QMessageBox::Ok, 0);
Chris@0 3758 }
Chris@0 3759
Chris@0 3760 void
Chris@0 3761 MainWindow::rightButtonMenuRequested(Pane *pane, QPoint position)
Chris@0 3762 {
Chris@0 3763 // std::cerr << "MainWindow::rightButtonMenuRequested(" << pane << ", " << position.x() << ", " << position.y() << ")" << std::endl;
Chris@0 3764 m_paneStack->setCurrentPane(pane);
Chris@0 3765 m_rightButtonMenu->popup(position);
Chris@0 3766 }
Chris@0 3767
Chris@0 3768 void
Chris@73 3769 MainWindow::propertyStacksResized()
Chris@73 3770 {
Chris@73 3771 /*
Chris@73 3772 std::cerr << "MainWindow::propertyStacksResized" << std::endl;
Chris@73 3773 Pane *pane = m_paneStack->getCurrentPane();
Chris@73 3774 if (pane && m_overview) {
Chris@73 3775 std::cerr << "Fixed width: " << pane->width() << std::endl;
Chris@73 3776 m_overview->setFixedWidth(pane->width());
Chris@73 3777 }
Chris@73 3778 */
Chris@73 3779 }
Chris@73 3780
Chris@73 3781 void
Chris@0 3782 MainWindow::showLayerTree()
Chris@0 3783 {
Chris@0 3784 QTreeView *view = new QTreeView();
Chris@0 3785 LayerTreeModel *tree = new LayerTreeModel(m_paneStack);
Chris@0 3786 view->expand(tree->index(0, 0, QModelIndex()));
Chris@0 3787 view->setModel(tree);
Chris@0 3788 view->show();
Chris@0 3789 }
Chris@0 3790
Chris@0 3791 void
Chris@69 3792 MainWindow::pollOSC()
Chris@69 3793 {
Chris@70 3794 if (!m_oscQueue || m_oscQueue->isEmpty()) return;
Chris@69 3795 std::cerr << "MainWindow::pollOSC: have " << m_oscQueue->getMessagesAvailable() << " messages" << std::endl;
Chris@69 3796
Chris@70 3797 if (m_openingAudioFile) return;
Chris@70 3798
Chris@69 3799 OSCMessage message = m_oscQueue->readMessage();
Chris@69 3800
Chris@69 3801 if (message.getTarget() != 0) {
Chris@69 3802 return; //!!! for now -- this class is target 0, others not handled yet
Chris@69 3803 }
Chris@69 3804
Chris@69 3805 handleOSCMessage(message);
Chris@69 3806 }
Chris@69 3807
Chris@69 3808 void
Chris@69 3809 MainWindow::handleOSCMessage(const OSCMessage &message)
Chris@69 3810 {
Chris@70 3811 std::cerr << "MainWindow::handleOSCMessage: thread id = "
Chris@70 3812 << QThread::currentThreadId() << std::endl;
Chris@70 3813
Chris@69 3814 // This large function should really be abstracted out.
Chris@69 3815
Chris@69 3816 if (message.getMethod() == "open") {
Chris@69 3817
Chris@69 3818 if (message.getArgCount() == 1 &&
Chris@69 3819 message.getArg(0).canConvert(QVariant::String)) {
Chris@69 3820 QString path = message.getArg(0).toString();
Chris@82 3821 if (openSomeFile(path, ReplaceMainModel) != FileOpenSucceeded) {
Chris@69 3822 std::cerr << "MainWindow::handleOSCMessage: File open failed for path \""
Chris@69 3823 << path.toStdString() << "\"" << std::endl;
Chris@69 3824 }
Chris@69 3825 //!!! we really need to spin here and not return until the
Chris@69 3826 // file has been completely decoded...
Chris@69 3827 }
Chris@69 3828
Chris@69 3829 } else if (message.getMethod() == "openadditional") {
Chris@69 3830
Chris@69 3831 if (message.getArgCount() == 1 &&
Chris@69 3832 message.getArg(0).canConvert(QVariant::String)) {
Chris@69 3833 QString path = message.getArg(0).toString();
Chris@82 3834 if (openSomeFile(path, CreateAdditionalModel) != FileOpenSucceeded) {
Chris@69 3835 std::cerr << "MainWindow::handleOSCMessage: File open failed for path \""
Chris@69 3836 << path.toStdString() << "\"" << std::endl;
Chris@69 3837 }
Chris@69 3838 }
Chris@69 3839
Chris@69 3840 } else if (message.getMethod() == "recent" ||
Chris@69 3841 message.getMethod() == "last") {
Chris@69 3842
Chris@69 3843 int n = 0;
Chris@69 3844 if (message.getMethod() == "recent" &&
Chris@69 3845 message.getArgCount() == 1 &&
Chris@69 3846 message.getArg(0).canConvert(QVariant::Int)) {
Chris@69 3847 n = message.getArg(0).toInt() - 1;
Chris@69 3848 }
Chris@69 3849 std::vector<QString> recent = m_recentFiles.getRecent();
Chris@69 3850 if (n >= 0 && n < recent.size()) {
Chris@82 3851 if (openSomeFile(recent[n], ReplaceMainModel) != FileOpenSucceeded) {
Chris@69 3852 std::cerr << "MainWindow::handleOSCMessage: File open failed for path \""
Chris@69 3853 << recent[n].toStdString() << "\"" << std::endl;
Chris@69 3854 }
Chris@69 3855 }
Chris@69 3856
Chris@69 3857 } else if (message.getMethod() == "save") {
Chris@69 3858
Chris@69 3859 QString path;
Chris@69 3860 if (message.getArgCount() == 1 &&
Chris@69 3861 message.getArg(0).canConvert(QVariant::String)) {
Chris@69 3862 path = message.getArg(0).toString();
Chris@69 3863 if (QFileInfo(path).exists()) {
Chris@69 3864 std::cerr << "MainWindow::handleOSCMessage: Refusing to overwrite existing file in save" << std::endl;
Chris@69 3865 } else {
Chris@69 3866 saveSessionFile(path);
Chris@69 3867 }
Chris@69 3868 }
Chris@69 3869
Chris@69 3870 } else if (message.getMethod() == "export") {
Chris@69 3871
Chris@69 3872 QString path;
Chris@69 3873 if (getMainModel()) {
Chris@69 3874 if (message.getArgCount() == 1 &&
Chris@69 3875 message.getArg(0).canConvert(QVariant::String)) {
Chris@69 3876 path = message.getArg(0).toString();
Chris@69 3877 if (QFileInfo(path).exists()) {
Chris@69 3878 std::cerr << "MainWindow::handleOSCMessage: Refusing to overwrite existing file in export" << std::endl;
Chris@69 3879 } else {
Chris@69 3880 WavFileWriter writer(path,
Chris@69 3881 getMainModel()->getSampleRate(),
Chris@69 3882 getMainModel()->getChannelCount());
Chris@69 3883 MultiSelection ms = m_viewManager->getSelection();
Chris@69 3884 if (!ms.getSelections().empty()) {
Chris@69 3885 writer.writeModel(getMainModel(), &ms);
Chris@69 3886 } else {
Chris@69 3887 writer.writeModel(getMainModel());
Chris@69 3888 }
Chris@69 3889 }
Chris@69 3890 }
Chris@69 3891 }
Chris@69 3892
Chris@69 3893 } else if (message.getMethod() == "jump" ||
Chris@69 3894 message.getMethod() == "play") {
Chris@69 3895
Chris@69 3896 if (getMainModel()) {
Chris@69 3897
Chris@69 3898 unsigned long frame = m_viewManager->getPlaybackFrame();
Chris@69 3899 bool selection = false;
Chris@69 3900 bool play = (message.getMethod() == "play");
Chris@69 3901
Chris@69 3902 if (message.getArgCount() == 1) {
Chris@69 3903
Chris@69 3904 if (message.getArg(0).canConvert(QVariant::String) &&
Chris@69 3905 message.getArg(0).toString() == "selection") {
Chris@69 3906
Chris@69 3907 selection = true;
Chris@69 3908
Chris@69 3909 } else if (message.getArg(0).canConvert(QVariant::String) &&
Chris@69 3910 message.getArg(0).toString() == "end") {
Chris@69 3911
Chris@69 3912 frame = getMainModel()->getEndFrame();
Chris@69 3913
Chris@69 3914 } else if (message.getArg(0).canConvert(QVariant::Double)) {
Chris@69 3915
Chris@69 3916 double time = message.getArg(0).toDouble();
Chris@69 3917 if (time < 0.0) time = 0.0;
Chris@69 3918
Chris@69 3919 frame = lrint(time * getMainModel()->getSampleRate());
Chris@69 3920 }
Chris@69 3921 }
Chris@69 3922
Chris@69 3923 if (frame > getMainModel()->getEndFrame()) {
Chris@69 3924 frame = getMainModel()->getEndFrame();
Chris@69 3925 }
Chris@69 3926
Chris@69 3927 if (play) {
Chris@69 3928 m_viewManager->setPlaySelectionMode(selection);
Chris@69 3929 }
Chris@69 3930
Chris@69 3931 if (selection) {
Chris@69 3932 MultiSelection::SelectionList sl = m_viewManager->getSelections();
Chris@69 3933 if (!sl.empty()) {
Chris@69 3934 frame = sl.begin()->getStartFrame();
Chris@69 3935 }
Chris@69 3936 }
Chris@69 3937
Chris@69 3938 m_viewManager->setPlaybackFrame(frame);
Chris@69 3939
Chris@69 3940 if (play && !m_playSource->isPlaying()) {
Chris@69 3941 m_playSource->play(frame);
Chris@69 3942 }
Chris@69 3943 }
Chris@69 3944
Chris@69 3945 } else if (message.getMethod() == "stop") {
Chris@69 3946
Chris@69 3947 if (m_playSource->isPlaying()) m_playSource->stop();
Chris@69 3948
Chris@69 3949 } else if (message.getMethod() == "loop") {
Chris@69 3950
Chris@69 3951 if (message.getArgCount() == 1 &&
Chris@69 3952 message.getArg(0).canConvert(QVariant::String)) {
Chris@69 3953
Chris@69 3954 QString str = message.getArg(0).toString();
Chris@69 3955 if (str == "on") {
Chris@69 3956 m_viewManager->setPlayLoopMode(true);
Chris@69 3957 } else if (str == "off") {
Chris@69 3958 m_viewManager->setPlayLoopMode(false);
Chris@69 3959 }
Chris@69 3960 }
Chris@69 3961
Chris@69 3962 } else if (message.getMethod() == "select" ||
Chris@69 3963 message.getMethod() == "addselect") {
Chris@69 3964
Chris@69 3965 if (getMainModel()) {
Chris@69 3966
Chris@73 3967 int f0 = getMainModel()->getStartFrame();
Chris@73 3968 int f1 = getMainModel()->getEndFrame();
Chris@69 3969
Chris@69 3970 bool done = false;
Chris@69 3971
Chris@69 3972 if (message.getArgCount() == 2 &&
Chris@69 3973 message.getArg(0).canConvert(QVariant::Double) &&
Chris@69 3974 message.getArg(1).canConvert(QVariant::Double)) {
Chris@69 3975
Chris@69 3976 double t0 = message.getArg(0).toDouble();
Chris@69 3977 double t1 = message.getArg(1).toDouble();
Chris@69 3978 if (t1 < t0) { double temp = t0; t0 = t1; t1 = temp; }
Chris@69 3979 if (t0 < 0.0) t0 = 0.0;
Chris@69 3980 if (t1 < 0.0) t1 = 0.0;
Chris@69 3981
Chris@69 3982 f0 = lrint(t0 * getMainModel()->getSampleRate());
Chris@69 3983 f1 = lrint(t1 * getMainModel()->getSampleRate());
Chris@73 3984
Chris@73 3985 Pane *pane = m_paneStack->getCurrentPane();
Chris@73 3986 Layer *layer = 0;
Chris@73 3987 if (pane) layer = pane->getSelectedLayer();
Chris@73 3988 if (layer) {
Chris@73 3989 size_t resolution;
Chris@73 3990 layer->snapToFeatureFrame(pane, f0, resolution,
Chris@73 3991 Layer::SnapLeft);
Chris@73 3992 layer->snapToFeatureFrame(pane, f1, resolution,
Chris@73 3993 Layer::SnapRight);
Chris@73 3994 }
Chris@69 3995
Chris@69 3996 } else if (message.getArgCount() == 1 &&
Chris@69 3997 message.getArg(0).canConvert(QVariant::String)) {
Chris@69 3998
Chris@69 3999 QString str = message.getArg(0).toString();
Chris@69 4000 if (str == "none") {
Chris@69 4001 m_viewManager->clearSelections();
Chris@69 4002 done = true;
Chris@69 4003 }
Chris@69 4004 }
Chris@69 4005
Chris@69 4006 if (!done) {
Chris@69 4007 if (message.getMethod() == "select") {
Chris@69 4008 m_viewManager->setSelection(Selection(f0, f1));
Chris@69 4009 } else {
Chris@69 4010 m_viewManager->addSelection(Selection(f0, f1));
Chris@69 4011 }
Chris@69 4012 }
Chris@69 4013 }
Chris@69 4014
Chris@69 4015 } else if (message.getMethod() == "add") {
Chris@69 4016
Chris@69 4017 if (getMainModel()) {
Chris@69 4018
Chris@69 4019 if (message.getArgCount() >= 1 &&
Chris@69 4020 message.getArg(0).canConvert(QVariant::String)) {
Chris@69 4021
Chris@69 4022 int channel = -1;
Chris@69 4023 if (message.getArgCount() == 2 &&
Chris@69 4024 message.getArg(0).canConvert(QVariant::Int)) {
Chris@69 4025 channel = message.getArg(0).toInt();
Chris@69 4026 if (channel < -1 ||
Chris@69 4027 channel > getMainModel()->getChannelCount()) {
Chris@69 4028 std::cerr << "WARNING: MainWindow::handleOSCMessage: channel "
Chris@69 4029 << channel << " out of range" << std::endl;
Chris@69 4030 channel = -1;
Chris@69 4031 }
Chris@69 4032 }
Chris@69 4033
Chris@69 4034 QString str = message.getArg(0).toString();
Chris@69 4035
Chris@69 4036 LayerFactory::LayerType type =
Chris@69 4037 LayerFactory::getInstance()->getLayerTypeForName(str);
Chris@69 4038
Chris@69 4039 if (type == LayerFactory::UnknownLayer) {
Chris@69 4040 std::cerr << "WARNING: MainWindow::handleOSCMessage: unknown layer "
Chris@69 4041 << "type " << str.toStdString() << std::endl;
Chris@69 4042 } else {
Chris@69 4043
Chris@69 4044 PaneConfiguration configuration(type,
Chris@69 4045 getMainModel(),
Chris@69 4046 channel);
Chris@69 4047
Chris@69 4048 addPane(configuration,
Chris@69 4049 tr("Add %1 Pane")
Chris@69 4050 .arg(LayerFactory::getInstance()->
Chris@69 4051 getLayerPresentationName(type)));
Chris@69 4052 }
Chris@69 4053 }
Chris@69 4054 }
Chris@69 4055
Chris@69 4056 } else if (message.getMethod() == "undo") {
Chris@69 4057
Chris@69 4058 CommandHistory::getInstance()->undo();
Chris@69 4059
Chris@69 4060 } else if (message.getMethod() == "redo") {
Chris@69 4061
Chris@69 4062 CommandHistory::getInstance()->redo();
Chris@69 4063
Chris@69 4064 } else if (message.getMethod() == "set") {
Chris@69 4065
Chris@70 4066 if (message.getArgCount() == 2 &&
Chris@69 4067 message.getArg(0).canConvert(QVariant::String) &&
Chris@69 4068 message.getArg(1).canConvert(QVariant::Double)) {
Chris@69 4069
Chris@69 4070 QString property = message.getArg(0).toString();
Chris@69 4071 float value = (float)message.getArg(1).toDouble();
Chris@69 4072
Chris@69 4073 if (property == "gain") {
Chris@69 4074 if (value < 0.0) value = 0.0;
Chris@69 4075 m_fader->setValue(value);
Chris@69 4076 if (m_playTarget) m_playTarget->setOutputGain(value);
Chris@69 4077 } else if (property == "speedup") {
Chris@69 4078 m_playSpeed->setMappedValue(value);
Chris@69 4079 } else if (property == "overlays") {
Chris@69 4080 if (value < 0.5) {
Chris@69 4081 m_viewManager->setOverlayMode(ViewManager::NoOverlays);
Chris@69 4082 } else if (value < 1.5) {
Chris@90 4083 m_viewManager->setOverlayMode(ViewManager::MinimalOverlays);
Chris@90 4084 } else if (value < 2.5) {
Chris@90 4085 m_viewManager->setOverlayMode(ViewManager::StandardOverlays);
Chris@69 4086 } else {
Chris@69 4087 m_viewManager->setOverlayMode(ViewManager::AllOverlays);
Chris@69 4088 }
Chris@70 4089 } else if (property == "zoomwheels") {
Chris@70 4090 m_viewManager->setZoomWheelsEnabled(value > 0.5);
Chris@72 4091 } else if (property == "propertyboxes") {
Chris@72 4092 bool toggle = ((value < 0.5) !=
Chris@72 4093 (m_paneStack->getLayoutStyle() == PaneStack::NoPropertyStacks));
Chris@72 4094 if (toggle) togglePropertyBoxes();
Chris@70 4095 }
Chris@70 4096
Chris@70 4097 } else {
Chris@70 4098 PropertyContainer *container = 0;
Chris@70 4099 Pane *pane = m_paneStack->getCurrentPane();
Chris@70 4100 if (pane &&
Chris@70 4101 message.getArgCount() == 3 &&
Chris@70 4102 message.getArg(0).canConvert(QVariant::String) &&
Chris@70 4103 message.getArg(1).canConvert(QVariant::String) &&
Chris@70 4104 message.getArg(2).canConvert(QVariant::String)) {
Chris@70 4105 if (message.getArg(0).toString() == "pane") {
Chris@70 4106 container = pane->getPropertyContainer(0);
Chris@70 4107 } else if (message.getArg(0).toString() == "layer") {
Chris@70 4108 container = pane->getSelectedLayer();
Chris@70 4109 }
Chris@70 4110 }
Chris@70 4111 if (container) {
Chris@70 4112 QString nameString = message.getArg(1).toString();
Chris@70 4113 QString valueString = message.getArg(2).toString();
Chris@70 4114 container->setPropertyWithCommand(nameString, valueString);
Chris@69 4115 }
Chris@69 4116 }
Chris@69 4117
Chris@69 4118 } else if (message.getMethod() == "setcurrent") {
Chris@69 4119
Chris@69 4120 int paneIndex = -1, layerIndex = -1;
Chris@69 4121 bool wantLayer = false;
Chris@69 4122
Chris@69 4123 if (message.getArgCount() >= 1 &&
Chris@69 4124 message.getArg(0).canConvert(QVariant::Int)) {
Chris@69 4125
Chris@69 4126 paneIndex = message.getArg(0).toInt() - 1;
Chris@69 4127
Chris@69 4128 if (message.getArgCount() >= 2 &&
Chris@69 4129 message.getArg(1).canConvert(QVariant::Int)) {
Chris@69 4130 wantLayer = true;
Chris@69 4131 layerIndex = message.getArg(1).toInt() - 1;
Chris@69 4132 }
Chris@69 4133 }
Chris@69 4134
Chris@69 4135 if (paneIndex >= 0 && paneIndex < m_paneStack->getPaneCount()) {
Chris@69 4136 Pane *pane = m_paneStack->getPane(paneIndex);
Chris@70 4137 m_paneStack->setCurrentPane(pane);
Chris@69 4138 if (layerIndex >= 0 && layerIndex < pane->getLayerCount()) {
Chris@69 4139 Layer *layer = pane->getLayer(layerIndex);
Chris@69 4140 m_paneStack->setCurrentLayer(pane, layer);
Chris@69 4141 } else if (wantLayer && layerIndex == -1) {
Chris@69 4142 m_paneStack->setCurrentLayer(pane, 0);
Chris@69 4143 }
Chris@69 4144 }
Chris@69 4145
Chris@69 4146 } else if (message.getMethod() == "delete") {
Chris@69 4147
Chris@69 4148 if (message.getArgCount() == 1 &&
Chris@69 4149 message.getArg(0).canConvert(QVariant::String)) {
Chris@69 4150
Chris@69 4151 QString target = message.getArg(0).toString();
Chris@69 4152
Chris@69 4153 if (target == "pane") {
Chris@69 4154
Chris@69 4155 deleteCurrentPane();
Chris@69 4156
Chris@69 4157 } else if (target == "layer") {
Chris@69 4158
Chris@69 4159 deleteCurrentLayer();
Chris@69 4160
Chris@69 4161 } else {
Chris@69 4162
Chris@69 4163 std::cerr << "WARNING: MainWindow::handleOSCMessage: Unknown delete target " << target.toStdString() << std::endl;
Chris@69 4164 }
Chris@69 4165 }
Chris@69 4166
Chris@69 4167 } else if (message.getMethod() == "zoom") {
Chris@69 4168
Chris@69 4169 if (message.getArgCount() == 1) {
Chris@69 4170 if (message.getArg(0).canConvert(QVariant::String) &&
Chris@69 4171 message.getArg(0).toString() == "in") {
Chris@69 4172 zoomIn();
Chris@69 4173 } else if (message.getArg(0).canConvert(QVariant::String) &&
Chris@69 4174 message.getArg(0).toString() == "out") {
Chris@69 4175 zoomOut();
Chris@69 4176 } else if (message.getArg(0).canConvert(QVariant::String) &&
Chris@69 4177 message.getArg(0).toString() == "default") {
Chris@69 4178 zoomDefault();
Chris@69 4179 } else if (message.getArg(0).canConvert(QVariant::Double)) {
Chris@69 4180 double level = message.getArg(0).toDouble();
Chris@69 4181 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@69 4182 if (level < 1.0) level = 1.0;
Chris@69 4183 if (currentPane) currentPane->setZoomLevel(lrint(level));
Chris@69 4184 }
Chris@69 4185 }
Chris@69 4186
Chris@73 4187 } else if (message.getMethod() == "zoomvertical") {
Chris@73 4188
Chris@73 4189 Pane *pane = m_paneStack->getCurrentPane();
Chris@73 4190 Layer *layer = 0;
Chris@73 4191 if (pane && pane->getLayerCount() > 0) {
Chris@73 4192 layer = pane->getLayer(pane->getLayerCount() - 1);
Chris@73 4193 }
Chris@73 4194 int defaultStep = 0;
Chris@73 4195 int steps = 0;
Chris@73 4196 if (layer) {
Chris@73 4197 steps = layer->getVerticalZoomSteps(defaultStep);
Chris@73 4198 if (message.getArgCount() == 1 && steps > 0) {
Chris@73 4199 if (message.getArg(0).canConvert(QVariant::String) &&
Chris@73 4200 message.getArg(0).toString() == "in") {
Chris@73 4201 int step = layer->getCurrentVerticalZoomStep() + 1;
Chris@73 4202 if (step < steps) layer->setVerticalZoomStep(step);
Chris@73 4203 } else if (message.getArg(0).canConvert(QVariant::String) &&
Chris@73 4204 message.getArg(0).toString() == "out") {
Chris@73 4205 int step = layer->getCurrentVerticalZoomStep() - 1;
Chris@73 4206 if (step >= 0) layer->setVerticalZoomStep(step);
Chris@73 4207 } else if (message.getArg(0).canConvert(QVariant::String) &&
Chris@73 4208 message.getArg(0).toString() == "default") {
Chris@73 4209 layer->setVerticalZoomStep(defaultStep);
Chris@73 4210 }
Chris@73 4211 } else if (message.getArgCount() == 2) {
Chris@73 4212 if (message.getArg(0).canConvert(QVariant::Double) &&
Chris@73 4213 message.getArg(1).canConvert(QVariant::Double)) {
Chris@73 4214 double min = message.getArg(0).toDouble();
Chris@73 4215 double max = message.getArg(1).toDouble();
Chris@73 4216 layer->setDisplayExtents(min, max);
Chris@73 4217 }
Chris@73 4218 }
Chris@73 4219 }
Chris@73 4220
Chris@70 4221 } else if (message.getMethod() == "quit") {
Chris@70 4222
Chris@70 4223 m_abandoning = true;
Chris@70 4224 close();
Chris@70 4225
Chris@70 4226 } else if (message.getMethod() == "resize") {
Chris@70 4227
Chris@70 4228 if (message.getArgCount() == 2) {
Chris@70 4229
Chris@70 4230 int width = 0, height = 0;
Chris@70 4231
Chris@70 4232 if (message.getArg(1).canConvert(QVariant::Int)) {
Chris@70 4233
Chris@70 4234 height = message.getArg(1).toInt();
Chris@70 4235
Chris@70 4236 if (message.getArg(0).canConvert(QVariant::String) &&
Chris@70 4237 message.getArg(0).toString() == "pane") {
Chris@70 4238
Chris@70 4239 Pane *pane = m_paneStack->getCurrentPane();
Chris@70 4240 if (pane) pane->resize(pane->width(), height);
Chris@70 4241
Chris@70 4242 } else if (message.getArg(0).canConvert(QVariant::Int)) {
Chris@70 4243
Chris@70 4244 width = message.getArg(0).toInt();
Chris@70 4245 resize(width, height);
Chris@70 4246 }
Chris@70 4247 }
Chris@70 4248 }
Chris@70 4249
Chris@70 4250 } else if (message.getMethod() == "transform") {
Chris@70 4251
Chris@70 4252 Pane *pane = m_paneStack->getCurrentPane();
Chris@70 4253
Chris@70 4254 if (getMainModel() &&
Chris@70 4255 pane &&
Chris@70 4256 message.getArgCount() == 1 &&
Chris@70 4257 message.getArg(0).canConvert(QVariant::String)) {
Chris@70 4258
Chris@70 4259 TransformName transform = message.getArg(0).toString();
Chris@70 4260
Chris@70 4261 Layer *newLayer = m_document->createDerivedLayer
Chris@70 4262 (transform,
Chris@70 4263 getMainModel(),
Chris@73 4264 TransformFactory::getInstance()->getDefaultContextForTransform
Chris@73 4265 (transform, getMainModel()),
Chris@70 4266 "");
Chris@70 4267
Chris@70 4268 if (newLayer) {
Chris@70 4269 m_document->addLayerToView(pane, newLayer);
Chris@70 4270 m_recentTransforms.add(transform);
Chris@70 4271 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@70 4272 }
Chris@70 4273 }
Chris@70 4274
Chris@69 4275 } else {
Chris@69 4276 std::cerr << "WARNING: MainWindow::handleOSCMessage: Unknown or unsupported "
Chris@69 4277 << "method \"" << message.getMethod().toStdString()
Chris@69 4278 << "\"" << std::endl;
Chris@69 4279 }
Chris@69 4280
Chris@69 4281 }
Chris@69 4282
Chris@69 4283 void
Chris@0 4284 MainWindow::preferences()
Chris@0 4285 {
Chris@0 4286 if (!m_preferencesDialog.isNull()) {
Chris@0 4287 m_preferencesDialog->show();
Chris@0 4288 m_preferencesDialog->raise();
Chris@0 4289 return;
Chris@0 4290 }
Chris@0 4291
Chris@0 4292 m_preferencesDialog = new PreferencesDialog(this);
Chris@0 4293
Chris@0 4294 // DeleteOnClose is safe here, because m_preferencesDialog is a
Chris@0 4295 // QPointer that will be zeroed when the dialog is deleted. We
Chris@0 4296 // use it in preference to leaving the dialog lying around because
Chris@0 4297 // if you Cancel the dialog, it resets the preferences state
Chris@0 4298 // without resetting its own widgets, so its state will be
Chris@0 4299 // incorrect when next shown unless we construct it afresh
Chris@0 4300 m_preferencesDialog->setAttribute(Qt::WA_DeleteOnClose);
Chris@0 4301
Chris@0 4302 m_preferencesDialog->show();
Chris@0 4303 }
Chris@0 4304
Chris@0 4305 void
Chris@90 4306 MainWindow::mouseEnteredWidget()
Chris@90 4307 {
Chris@90 4308 QWidget *w = dynamic_cast<QWidget *>(sender());
Chris@90 4309 if (!w) return;
Chris@90 4310
Chris@90 4311 if (w == m_fader) {
Chris@90 4312 statusBar()->showMessage(tr("Adjust the master playback level"));
Chris@90 4313 } else if (w == m_playSpeed) {
Chris@90 4314 statusBar()->showMessage(tr("Adjust the master playback speed"));
Chris@90 4315 } else if (w == m_playSharpen && w->isEnabled()) {
Chris@90 4316 statusBar()->showMessage(tr("Toggle transient sharpening for playback time scaling"));
Chris@90 4317 } else if (w == m_playMono && w->isEnabled()) {
Chris@90 4318 statusBar()->showMessage(tr("Toggle mono mode for playback time scaling"));
Chris@90 4319 }
Chris@90 4320 }
Chris@90 4321
Chris@90 4322 void
Chris@90 4323 MainWindow::mouseLeftWidget()
Chris@90 4324 {
Chris@90 4325 statusBar()->showMessage("");
Chris@90 4326 }
Chris@90 4327
Chris@90 4328 void
Chris@0 4329 MainWindow::website()
Chris@0 4330 {
Chris@0 4331 openHelpUrl(tr("http://www.sonicvisualiser.org/"));
Chris@0 4332 }
Chris@0 4333
Chris@0 4334 void
Chris@0 4335 MainWindow::help()
Chris@0 4336 {
Chris@0 4337 openHelpUrl(tr("http://www.sonicvisualiser.org/doc/reference/en/"));
Chris@0 4338 }
Chris@0 4339
Chris@0 4340 void
Chris@0 4341 MainWindow::openHelpUrl(QString url)
Chris@0 4342 {
Chris@0 4343 // This method mostly lifted from Qt Assistant source code
Chris@0 4344
Chris@0 4345 QProcess *process = new QProcess(this);
Chris@0 4346 connect(process, SIGNAL(finished(int)), process, SLOT(deleteLater()));
Chris@0 4347
Chris@0 4348 QStringList args;
Chris@0 4349
Chris@0 4350 #ifdef Q_OS_MAC
Chris@0 4351 args.append(url);
Chris@0 4352 process->start("open", args);
Chris@0 4353 #else
Chris@0 4354 #ifdef Q_OS_WIN32
Chris@0 4355
Chris@0 4356 QString pf(getenv("ProgramFiles"));
Chris@0 4357 QString command = pf + QString("\\Internet Explorer\\IEXPLORE.EXE");
Chris@0 4358
Chris@0 4359 args.append(url);
Chris@0 4360 process->start(command, args);
Chris@0 4361
Chris@0 4362 #else
Chris@0 4363 #ifdef Q_WS_X11
Chris@0 4364 if (!qgetenv("KDE_FULL_SESSION").isEmpty()) {
Chris@0 4365 args.append("exec");
Chris@0 4366 args.append(url);
Chris@0 4367 process->start("kfmclient", args);
Chris@0 4368 } else if (!qgetenv("BROWSER").isEmpty()) {
Chris@0 4369 args.append(url);
Chris@0 4370 process->start(qgetenv("BROWSER"), args);
Chris@0 4371 } else {
Chris@0 4372 args.append(url);
Chris@0 4373 process->start("firefox", args);
Chris@0 4374 }
Chris@0 4375 #endif
Chris@0 4376 #endif
Chris@0 4377 #endif
Chris@0 4378 }
Chris@0 4379
Chris@0 4380 void
Chris@0 4381 MainWindow::about()
Chris@0 4382 {
Chris@0 4383 bool debug = false;
Chris@0 4384 QString version = "(unknown version)";
Chris@0 4385
Chris@0 4386 #ifdef BUILD_DEBUG
Chris@0 4387 debug = true;
Chris@0 4388 #endif
Chris@0 4389 #ifdef SV_VERSION
Chris@0 4390 #ifdef SVNREV
Chris@0 4391 version = tr("Release %1 : Revision %2").arg(SV_VERSION).arg(SVNREV);
Chris@0 4392 #else
Chris@0 4393 version = tr("Release %1").arg(SV_VERSION);
Chris@0 4394 #endif
Chris@0 4395 #else
Chris@0 4396 #ifdef SVNREV
Chris@0 4397 version = tr("Unreleased : Revision %1").arg(SVNREV);
Chris@0 4398 #endif
Chris@0 4399 #endif
Chris@0 4400
Chris@0 4401 QString aboutText;
Chris@0 4402
Chris@0 4403 aboutText += tr("<h3>About Sonic Visualiser</h3>");
Chris@90 4404 aboutText += tr("<p>Sonic Visualiser is a program for viewing and exploring audio data for<br>semantic music analysis and annotation.</p>");
Chris@0 4405 aboutText += tr("<p>%1 : %2 build</p>")
Chris@0 4406 .arg(version)
Chris@0 4407 .arg(debug ? tr("Debug") : tr("Release"));
Chris@0 4408
Chris@0 4409 #ifdef BUILD_STATIC
Chris@0 4410 aboutText += tr("<p>Statically linked");
Chris@0 4411 #ifndef QT_SHARED
Chris@0 4412 aboutText += tr("<br>With Qt (v%1) &copy; Trolltech AS").arg(QT_VERSION_STR);
Chris@0 4413 #endif
Chris@0 4414 #ifdef HAVE_JACK
Chris@93 4415 #ifdef JACK_VERSION
Chris@0 4416 aboutText += tr("<br>With JACK audio output (v%1) &copy; Paul Davis and Jack O'Quin").arg(JACK_VERSION);
Chris@93 4417 #else
Chris@93 4418 aboutText += tr("<br>With JACK audio output &copy; Paul Davis and Jack O'Quin");
Chris@93 4419 #endif
Chris@0 4420 #endif
Chris@0 4421 #ifdef HAVE_PORTAUDIO
Chris@0 4422 aboutText += tr("<br>With PortAudio audio output &copy; Ross Bencina and Phil Burk");
Chris@0 4423 #endif
Chris@0 4424 #ifdef HAVE_OGGZ
Chris@93 4425 #ifdef OGGZ_VERSION
Chris@0 4426 aboutText += tr("<br>With Ogg file decoder (oggz v%1, fishsound v%2) &copy; CSIRO Australia").arg(OGGZ_VERSION).arg(FISHSOUND_VERSION);
Chris@93 4427 #else
Chris@93 4428 aboutText += tr("<br>With Ogg file decoder &copy; CSIRO Australia");
Chris@93 4429 #endif
Chris@0 4430 #endif
Chris@0 4431 #ifdef HAVE_MAD
Chris@93 4432 #ifdef MAD_VERSION
Chris@0 4433 aboutText += tr("<br>With MAD mp3 decoder (v%1) &copy; Underbit Technologies Inc").arg(MAD_VERSION);
Chris@93 4434 #else
Chris@93 4435 aboutText += tr("<br>With MAD mp3 decoder &copy; Underbit Technologies Inc");
Chris@93 4436 #endif
Chris@0 4437 #endif
Chris@0 4438 #ifdef HAVE_SAMPLERATE
Chris@93 4439 #ifdef SAMPLERATE_VERSION
Chris@0 4440 aboutText += tr("<br>With libsamplerate (v%1) &copy; Erik de Castro Lopo").arg(SAMPLERATE_VERSION);
Chris@93 4441 #else
Chris@93 4442 aboutText += tr("<br>With libsamplerate &copy; Erik de Castro Lopo");
Chris@93 4443 #endif
Chris@0 4444 #endif
Chris@0 4445 #ifdef HAVE_SNDFILE
Chris@93 4446 #ifdef SNDFILE_VERSION
Chris@0 4447 aboutText += tr("<br>With libsndfile (v%1) &copy; Erik de Castro Lopo").arg(SNDFILE_VERSION);
Chris@93 4448 #else
Chris@93 4449 aboutText += tr("<br>With libsndfile &copy; Erik de Castro Lopo");
Chris@93 4450 #endif
Chris@0 4451 #endif
Chris@0 4452 #ifdef HAVE_FFTW3
Chris@93 4453 #ifdef FFTW3_VERSION
Chris@0 4454 aboutText += tr("<br>With FFTW3 (v%1) &copy; Matteo Frigo and MIT").arg(FFTW3_VERSION);
Chris@93 4455 #else
Chris@93 4456 aboutText += tr("<br>With FFTW3 &copy; Matteo Frigo and MIT");
Chris@93 4457 #endif
Chris@0 4458 #endif
Chris@0 4459 #ifdef HAVE_VAMP
Chris@0 4460 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 4461 #endif
Chris@0 4462 aboutText += tr("<br>With LADSPA plugin support (API v%1) &copy; Richard Furse, Paul Davis, Stefan Westerfeld").arg(LADSPA_VERSION);
Chris@0 4463 aboutText += tr("<br>With DSSI plugin support (API v%1) &copy; Chris Cannam, Steve Harris, Sean Bolton").arg(DSSI_VERSION);
Chris@69 4464 #ifdef HAVE_LIBLO
Chris@93 4465 #ifdef LIBLO_VERSION
Chris@69 4466 aboutText += tr("<br>With liblo Lite OSC library (v%1) &copy; Steve Harris").arg(LIBLO_VERSION);
Chris@93 4467 #else
Chris@93 4468 aboutText += tr("<br>With liblo Lite OSC library &copy; Steve Harris").arg(LIBLO_VERSION);
Chris@93 4469 #endif
Chris@70 4470 if (m_oscQueue && m_oscQueue->isOK()) {
Chris@69 4471 aboutText += tr("<p>The OSC URL for this instance is: \"%1\"").arg(m_oscQueue->getOSCURL());
Chris@69 4472 }
Chris@69 4473 #endif
Chris@0 4474 aboutText += "</p>";
Chris@0 4475 #endif
Chris@0 4476
Chris@0 4477 aboutText +=
Chris@90 4478 "<p>Sonic Visualiser Copyright &copy; 2005 - 2007 Chris Cannam and<br>"
Chris@90 4479 "Queen Mary, University of London.</p>"
Chris@0 4480 "<p>This program is free software; you can redistribute it and/or<br>"
Chris@0 4481 "modify it under the terms of the GNU General Public License as<br>"
Chris@0 4482 "published by the Free Software Foundation; either version 2 of the<br>"
Chris@0 4483 "License, or (at your option) any later version.<br>See the file "
Chris@0 4484 "COPYING included with this distribution for more information.</p>";
Chris@0 4485
Chris@0 4486 QMessageBox::about(this, tr("About Sonic Visualiser"), aboutText);
Chris@0 4487 }
Chris@0 4488
Chris@0 4489
Chris@0 4490 #ifdef INCLUDE_MOCFILES
Chris@0 4491 #include "MainWindow.moc.cpp"
Chris@0 4492 #endif