annotate main/MainWindow.cpp @ 163:652b22dcd4ed

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