annotate main/MainWindow.cpp @ 304:fdbb3971bafc

* more rudiments of midi->instants
author Chris Cannam
date Tue, 24 Feb 2009 17:53:01 +0000
parents 5d691489a84f
children f76efdd7d180
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@200 7 This file copyright 2006-2007 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@0 19 #include "PreferencesDialog.h"
Chris@0 20
Chris@1 21 #include "view/Pane.h"
Chris@1 22 #include "view/PaneStack.h"
Chris@1 23 #include "data/model/WaveFileModel.h"
Chris@1 24 #include "data/model/SparseOneDimensionalModel.h"
Chris@185 25 #include "data/model/NoteModel.h"
Chris@189 26 #include "data/model/Labeller.h"
Chris@222 27 #include "data/osc/OSCQueue.h"
Chris@216 28 #include "framework/Document.h"
Chris@1 29 #include "view/ViewManager.h"
Chris@0 30 #include "base/Preferences.h"
Chris@0 31 #include "layer/WaveformLayer.h"
Chris@0 32 #include "layer/TimeRulerLayer.h"
Chris@0 33 #include "layer/TimeInstantLayer.h"
Chris@0 34 #include "layer/TimeValueLayer.h"
Chris@0 35 #include "layer/Colour3DPlotLayer.h"
Chris@95 36 #include "layer/SliceLayer.h"
Chris@95 37 #include "layer/SliceableLayer.h"
Chris@193 38 #include "layer/ImageLayer.h"
Chris@0 39 #include "widgets/Fader.h"
Chris@65 40 #include "view/Overview.h"
Chris@0 41 #include "widgets/PropertyBox.h"
Chris@0 42 #include "widgets/PropertyStack.h"
Chris@0 43 #include "widgets/AudioDial.h"
Chris@168 44 #include "widgets/IconLoader.h"
Chris@219 45 #include "widgets/LayerTreeDialog.h"
Chris@0 46 #include "widgets/ListInputDialog.h"
Chris@36 47 #include "widgets/SubdividingMenu.h"
Chris@90 48 #include "widgets/NotifyingPushButton.h"
Chris@162 49 #include "widgets/KeyReference.h"
Chris@273 50 #include "widgets/TransformFinder.h"
Chris@192 51 #include "widgets/LabelCounterInputDialog.h"
Chris@302 52 #include "widgets/ActivityLog.h"
Chris@0 53 #include "audioio/AudioCallbackPlaySource.h"
Chris@0 54 #include "audioio/AudioCallbackPlayTarget.h"
Chris@0 55 #include "audioio/AudioTargetFactory.h"
Chris@59 56 #include "audioio/PlaySpeedRangeMapper.h"
Chris@1 57 #include "data/fileio/DataFileReaderFactory.h"
Chris@180 58 #include "data/fileio/PlaylistFileReader.h"
Chris@1 59 #include "data/fileio/WavFileWriter.h"
Chris@1 60 #include "data/fileio/CSVFileWriter.h"
Chris@185 61 #include "data/fileio/MIDIFileWriter.h"
Chris@1 62 #include "data/fileio/BZipFileDevice.h"
Chris@198 63 #include "data/fileio/FileSource.h"
Chris@91 64 #include "data/fft/FFTDataServer.h"
Chris@304 65 #include "data/midi/MIDIInput.h"
Chris@1 66 #include "base/RecentFiles.h"
Chris@249 67 #include "transform/TransformFactory.h"
Chris@249 68 #include "transform/ModelTransformerFactory.h"
Chris@0 69 #include "base/PlayParameterRepository.h"
Chris@0 70 #include "base/XmlExportable.h"
Chris@248 71 #include "widgets/CommandHistory.h"
Chris@0 72 #include "base/Profiler.h"
Chris@0 73 #include "base/Clipboard.h"
Chris@165 74 #include "base/UnitDatabase.h"
Chris@248 75 #include "layer/ColourDatabase.h"
Chris@265 76 #include "widgets/ModelDataTableDialog.h"
Chris@289 77 #include "rdf/PluginRDFIndexer.h"
Chris@291 78 #include "rdf/RDFExporter.h"
Chris@276 79
Chris@0 80 // For version information
Chris@280 81 #include <vamp/vamp.h>
Chris@280 82 #include <vamp-hostsdk/PluginBase.h>
Chris@0 83 #include "plugin/api/ladspa.h"
Chris@0 84 #include "plugin/api/dssi.h"
Chris@0 85
Chris@0 86 #include <QApplication>
Chris@0 87 #include <QMessageBox>
Chris@0 88 #include <QGridLayout>
Chris@0 89 #include <QLabel>
Chris@0 90 #include <QAction>
Chris@0 91 #include <QMenuBar>
Chris@0 92 #include <QToolBar>
Chris@0 93 #include <QInputDialog>
Chris@0 94 #include <QStatusBar>
Chris@0 95 #include <QTreeView>
Chris@0 96 #include <QFile>
Chris@88 97 #include <QFileInfo>
Chris@88 98 #include <QDir>
Chris@0 99 #include <QTextStream>
Chris@0 100 #include <QProcess>
Chris@7 101 #include <QShortcut>
Chris@5 102 #include <QSettings>
Chris@11 103 #include <QDateTime>
Chris@11 104 #include <QProcess>
Chris@16 105 #include <QCheckBox>
Chris@55 106 #include <QRegExp>
Chris@158 107 #include <QScrollArea>
Chris@0 108
Chris@0 109 #include <iostream>
Chris@0 110 #include <cstdio>
Chris@0 111 #include <errno.h>
Chris@0 112
Chris@0 113 using std::cerr;
Chris@0 114 using std::endl;
Chris@0 115
Chris@33 116 using std::vector;
Chris@33 117 using std::map;
Chris@33 118 using std::set;
Chris@33 119
Chris@0 120
Chris@70 121 MainWindow::MainWindow(bool withAudioOutput, bool withOSCSupport) :
Chris@200 122 MainWindowBase(withAudioOutput, withOSCSupport),
Chris@65 123 m_overview(0),
Chris@0 124 m_mainMenusCreated(false),
Chris@0 125 m_paneMenu(0),
Chris@0 126 m_layerMenu(0),
Chris@34 127 m_transformsMenu(0),
Chris@155 128 m_playbackMenu(0),
Chris@0 129 m_existingLayersMenu(0),
Chris@95 130 m_sliceMenu(0),
Chris@34 131 m_recentFilesMenu(0),
Chris@211 132 m_recentTransformsMenu(0),
Chris@0 133 m_rightButtonMenu(0),
Chris@0 134 m_rightButtonLayerMenu(0),
Chris@211 135 m_rightButtonTransformsMenu(0),
Chris@155 136 m_rightButtonPlaybackMenu(0),
Chris@207 137 m_soloAction(0),
Chris@207 138 m_soloModified(false),
Chris@207 139 m_prevSolo(false),
Chris@265 140 m_rwdStartAction(0),
Chris@265 141 m_rwdAction(0),
Chris@155 142 m_ffwdAction(0),
Chris@265 143 m_ffwdEndAction(0),
Chris@265 144 m_playAction(0),
Chris@265 145 m_playSelectionAction(0),
Chris@265 146 m_playLoopAction(0),
Chris@239 147 m_playControlsSpacer(0),
Chris@239 148 m_playControlsWidth(0),
Chris@162 149 m_preferencesDialog(0),
Chris@219 150 m_layerTreeDialog(0),
Chris@302 151 m_activityLog(new ActivityLog()),
Chris@162 152 m_keyReference(new KeyReference())
Chris@0 153 {
Chris@253 154 Profiler profiler("MainWindow::MainWindow");
Chris@253 155
Chris@0 156 setWindowTitle(tr("Sonic Visualiser"));
Chris@0 157
Chris@165 158 UnitDatabase *udb = UnitDatabase::getInstance();
Chris@165 159 udb->registerUnit("Hz");
Chris@165 160 udb->registerUnit("dB");
Chris@165 161 udb->registerUnit("s");
Chris@165 162
Chris@165 163 ColourDatabase *cdb = ColourDatabase::getInstance();
Chris@165 164 cdb->addColour(Qt::black, tr("Black"));
Chris@165 165 cdb->addColour(Qt::darkRed, tr("Red"));
Chris@165 166 cdb->addColour(Qt::darkBlue, tr("Blue"));
Chris@165 167 cdb->addColour(Qt::darkGreen, tr("Green"));
Chris@165 168 cdb->addColour(QColor(200, 50, 255), tr("Purple"));
Chris@165 169 cdb->addColour(QColor(255, 150, 50), tr("Orange"));
Chris@166 170 cdb->setUseDarkBackground(cdb->addColour(Qt::white, tr("White")), true);
Chris@166 171 cdb->setUseDarkBackground(cdb->addColour(Qt::red, tr("Bright Red")), true);
Chris@166 172 cdb->setUseDarkBackground(cdb->addColour(QColor(30, 150, 255), tr("Bright Blue")), true);
Chris@166 173 cdb->setUseDarkBackground(cdb->addColour(Qt::green, tr("Bright Green")), true);
Chris@166 174 cdb->setUseDarkBackground(cdb->addColour(QColor(225, 74, 255), tr("Bright Purple")), true);
Chris@166 175 cdb->setUseDarkBackground(cdb->addColour(QColor(255, 188, 80), tr("Bright Orange")), true);
Chris@0 176
Chris@0 177 QFrame *frame = new QFrame;
Chris@0 178 setCentralWidget(frame);
Chris@0 179
Chris@0 180 QGridLayout *layout = new QGridLayout;
Chris@180 181
Chris@205 182 m_descriptionLabel = new QLabel; //!!! hang on, this is declared in base class -- should be declared and initialised by same class
Chris@0 183
Chris@158 184 QScrollArea *scroll = new QScrollArea(frame);
Chris@158 185 scroll->setWidgetResizable(true);
Chris@158 186 scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
Chris@159 187 scroll->setFrameShape(QFrame::NoFrame);
Chris@159 188
Chris@159 189 scroll->setWidget(m_paneStack);
Chris@159 190
Chris@65 191 m_overview = new Overview(frame);
Chris@65 192 m_overview->setViewManager(m_viewManager);
Chris@65 193 m_overview->setFixedHeight(40);
Chris@144 194 #ifndef _WIN32
Chris@144 195 // For some reason, the contents of the overview never appear if we
Chris@144 196 // make this setting on Windows. I have no inclination at the moment
Chris@144 197 // to track down the reason why.
Chris@129 198 m_overview->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
Chris@144 199 #endif
Chris@90 200 connect(m_overview, SIGNAL(contextHelpChanged(const QString &)),
Chris@116 201 this, SLOT(contextHelpChanged(const QString &)));
Chris@0 202
Chris@0 203 m_panLayer = new WaveformLayer;
Chris@0 204 m_panLayer->setChannelMode(WaveformLayer::MergeChannels);
Chris@0 205 m_panLayer->setAggressiveCacheing(true);
Chris@65 206 m_overview->addLayer(m_panLayer);
Chris@174 207
Chris@174 208 if (m_viewManager->getGlobalDarkBackground()) {
Chris@174 209 m_panLayer->setBaseColour
Chris@174 210 (ColourDatabase::getInstance()->getColourIndex(tr("Bright Green")));
Chris@174 211 } else {
Chris@174 212 m_panLayer->setBaseColour
Chris@174 213 (ColourDatabase::getInstance()->getColourIndex(tr("Green")));
Chris@200 214 }
Chris@0 215
Chris@0 216 m_fader = new Fader(frame, false);
Chris@90 217 connect(m_fader, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
Chris@90 218 connect(m_fader, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
Chris@0 219
Chris@0 220 m_playSpeed = new AudioDial(frame);
Chris@12 221 m_playSpeed->setMinimum(0);
Chris@48 222 m_playSpeed->setMaximum(200);
Chris@25 223 m_playSpeed->setValue(100);
Chris@261 224 m_playSpeed->setFixedWidth(32);
Chris@261 225 m_playSpeed->setFixedHeight(32);
Chris@0 226 m_playSpeed->setNotchesVisible(true);
Chris@25 227 m_playSpeed->setPageStep(10);
Chris@60 228 m_playSpeed->setObjectName(tr("Playback Speedup"));
Chris@25 229 m_playSpeed->setDefaultValue(100);
Chris@59 230 m_playSpeed->setRangeMapper(new PlaySpeedRangeMapper(0, 200));
Chris@60 231 m_playSpeed->setShowToolTip(true);
Chris@0 232 connect(m_playSpeed, SIGNAL(valueChanged(int)),
Chris@0 233 this, SLOT(playSpeedChanged(int)));
Chris@90 234 connect(m_playSpeed, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
Chris@90 235 connect(m_playSpeed, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
Chris@90 236
Chris@168 237 IconLoader il;
Chris@168 238
Chris@21 239 QSettings settings;
Chris@21 240 settings.beginGroup("MainWindow");
Chris@21 241 settings.endGroup();
Chris@21 242
Chris@239 243 m_playControlsSpacer = new QFrame;
Chris@239 244
Chris@129 245 layout->setSpacing(4);
Chris@159 246 layout->addWidget(scroll, 0, 0, 1, 5);
Chris@239 247 layout->addWidget(m_overview, 1, 1);
Chris@239 248 layout->addWidget(m_playControlsSpacer, 1, 2);
Chris@239 249 layout->addWidget(m_playSpeed, 1, 3);
Chris@239 250 layout->addWidget(m_fader, 1, 4);
Chris@239 251
Chris@239 252 m_playControlsWidth =
Chris@240 253 m_fader->width() + m_playSpeed->width() + layout->spacing() * 2;
Chris@239 254
Chris@239 255 layout->setColumnMinimumWidth(0, 14);
Chris@239 256 layout->setColumnStretch(0, 0);
Chris@239 257
Chris@239 258 m_paneStack->setPropertyStackMinWidth(m_playControlsWidth
Chris@239 259 + 2 + layout->spacing());
Chris@239 260 m_playControlsSpacer->setFixedSize(QSize(2, 2));
Chris@239 261
Chris@239 262 layout->setColumnStretch(1, 10);
Chris@239 263
Chris@239 264 connect(m_paneStack, SIGNAL(propertyStacksResized(int)),
Chris@239 265 this, SLOT(propertyStacksResized(int)));
Chris@16 266
Chris@0 267 frame->setLayout(layout);
Chris@0 268
Chris@0 269 setupMenus();
Chris@0 270 setupToolbars();
Chris@155 271 setupHelpMenu();
Chris@0 272
Chris@90 273 statusBar();
Chris@0 274
Chris@302 275 connect(m_viewManager, SIGNAL(activity(QString)),
Chris@302 276 m_activityLog, SLOT(activityHappened(QString)));
Chris@302 277 connect(m_playSource, SIGNAL(activity(QString)),
Chris@302 278 m_activityLog, SLOT(activityHappened(QString)));
Chris@302 279 connect(CommandHistory::getInstance(), SIGNAL(activity(QString)),
Chris@302 280 m_activityLog, SLOT(activityHappened(QString)));
Chris@303 281 connect(this, SIGNAL(replacedDocument()), this, SLOT(documentReplaced()));
Chris@303 282
Chris@303 283 newSession();
Chris@303 284
Chris@302 285 m_activityLog->show();
Chris@304 286
Chris@304 287 connect(m_midiInput, SIGNAL(eventsAvailable()),
Chris@304 288 this, SLOT(midiEventsAvailable()));
Chris@281 289
Chris@283 290 TransformFactory::getInstance()->startPopulationThread();
Chris@0 291 }
Chris@0 292
Chris@0 293 MainWindow::~MainWindow()
Chris@0 294 {
Chris@162 295 delete m_keyReference;
Chris@163 296 delete m_preferencesDialog;
Chris@219 297 delete m_layerTreeDialog;
Chris@0 298 Profiles::getInstance()->dump();
Chris@0 299 }
Chris@0 300
Chris@81 301 void
Chris@0 302 MainWindow::setupMenus()
Chris@0 303 {
Chris@0 304 if (!m_mainMenusCreated) {
Chris@0 305 m_rightButtonMenu = new QMenu();
Chris@104 306
Chris@104 307 // No -- we don't want tear-off enabled on the right-button
Chris@104 308 // menu. If it is enabled, then simply right-clicking and
Chris@104 309 // releasing will pop up the menu, activate the tear-off, and
Chris@104 310 // leave the torn-off menu window in front of the main window.
Chris@104 311 // That isn't desirable. I'm not sure it ever would be, in a
Chris@104 312 // context menu -- perhaps technically a Qt bug?
Chris@104 313 // m_rightButtonMenu->setTearOffEnabled(true);
Chris@0 314 }
Chris@0 315
Chris@0 316 if (m_rightButtonLayerMenu) {
Chris@0 317 m_rightButtonLayerMenu->clear();
Chris@0 318 } else {
Chris@0 319 m_rightButtonLayerMenu = m_rightButtonMenu->addMenu(tr("&Layer"));
Chris@97 320 m_rightButtonLayerMenu->setTearOffEnabled(true);
Chris@0 321 m_rightButtonMenu->addSeparator();
Chris@0 322 }
Chris@0 323
Chris@211 324 if (m_rightButtonTransformsMenu) {
Chris@211 325 m_rightButtonTransformsMenu->clear();
Chris@34 326 } else {
Chris@211 327 m_rightButtonTransformsMenu = m_rightButtonMenu->addMenu(tr("&Transform"));
Chris@211 328 m_rightButtonTransformsMenu->setTearOffEnabled(true);
Chris@34 329 m_rightButtonMenu->addSeparator();
Chris@34 330 }
Chris@34 331
Chris@0 332 if (!m_mainMenusCreated) {
Chris@0 333 CommandHistory::getInstance()->registerMenu(m_rightButtonMenu);
Chris@0 334 m_rightButtonMenu->addSeparator();
Chris@66 335 }
Chris@66 336
Chris@66 337 setupFileMenu();
Chris@66 338 setupEditMenu();
Chris@66 339 setupViewMenu();
Chris@66 340 setupPaneAndLayerMenus();
Chris@211 341 setupTransformsMenu();
Chris@66 342
Chris@66 343 m_mainMenusCreated = true;
Chris@66 344 }
Chris@66 345
Chris@66 346 void
Chris@66 347 MainWindow::setupFileMenu()
Chris@66 348 {
Chris@66 349 if (m_mainMenusCreated) return;
Chris@66 350
Chris@66 351 QMenu *menu = menuBar()->addMenu(tr("&File"));
Chris@97 352 menu->setTearOffEnabled(true);
Chris@66 353 QToolBar *toolbar = addToolBar(tr("File Toolbar"));
Chris@66 354
Chris@162 355 m_keyReference->setCategory(tr("File and Session Management"));
Chris@162 356
Chris@168 357 IconLoader il;
Chris@168 358
Chris@168 359 QIcon icon = il.load("filenew");
Chris@168 360 icon.addPixmap(il.loadPixmap("filenew-22"));
Chris@66 361 QAction *action = new QAction(icon, tr("&New Session"), this);
Chris@66 362 action->setShortcut(tr("Ctrl+N"));
Chris@90 363 action->setStatusTip(tr("Abandon the current Sonic Visualiser session and start a new one"));
Chris@66 364 connect(action, SIGNAL(triggered()), this, SLOT(newSession()));
Chris@162 365 m_keyReference->registerShortcut(action);
Chris@66 366 menu->addAction(action);
Chris@66 367 toolbar->addAction(action);
Chris@138 368
Chris@168 369 icon = il.load("fileopensession");
Chris@66 370 action = new QAction(icon, tr("&Open Session..."), this);
Chris@66 371 action->setShortcut(tr("Ctrl+O"));
Chris@66 372 action->setStatusTip(tr("Open a previously saved Sonic Visualiser session file"));
Chris@66 373 connect(action, SIGNAL(triggered()), this, SLOT(openSession()));
Chris@162 374 m_keyReference->registerShortcut(action);
Chris@66 375 menu->addAction(action);
Chris@66 376
Chris@168 377 icon = il.load("fileopen");
Chris@168 378 icon.addPixmap(il.loadPixmap("fileopen-22"));
Chris@138 379
Chris@66 380 action = new QAction(icon, tr("&Open..."), this);
Chris@66 381 action->setStatusTip(tr("Open a session file, audio file, or layer"));
Chris@66 382 connect(action, SIGNAL(triggered()), this, SLOT(openSomething()));
Chris@66 383 toolbar->addAction(action);
Chris@66 384
Chris@168 385 icon = il.load("filesave");
Chris@168 386 icon.addPixmap(il.loadPixmap("filesave-22"));
Chris@66 387 action = new QAction(icon, tr("&Save Session"), this);
Chris@66 388 action->setShortcut(tr("Ctrl+S"));
Chris@66 389 action->setStatusTip(tr("Save the current session into a Sonic Visualiser session file"));
Chris@66 390 connect(action, SIGNAL(triggered()), this, SLOT(saveSession()));
Chris@66 391 connect(this, SIGNAL(canSave(bool)), action, SLOT(setEnabled(bool)));
Chris@162 392 m_keyReference->registerShortcut(action);
Chris@66 393 menu->addAction(action);
Chris@66 394 toolbar->addAction(action);
Chris@0 395
Chris@168 396 icon = il.load("filesaveas");
Chris@168 397 icon.addPixmap(il.loadPixmap("filesaveas-22"));
Chris@66 398 action = new QAction(icon, tr("Save Session &As..."), this);
Chris@66 399 action->setStatusTip(tr("Save the current session into a new Sonic Visualiser session file"));
Chris@66 400 connect(action, SIGNAL(triggered()), this, SLOT(saveSessionAs()));
Chris@66 401 menu->addAction(action);
Chris@66 402 toolbar->addAction(action);
Chris@66 403
Chris@66 404 menu->addSeparator();
Chris@66 405
Chris@168 406 icon = il.load("fileopenaudio");
Chris@138 407 action = new QAction(icon, tr("&Import Audio File..."), this);
Chris@66 408 action->setShortcut(tr("Ctrl+I"));
Chris@66 409 action->setStatusTip(tr("Import an existing audio file"));
Chris@66 410 connect(action, SIGNAL(triggered()), this, SLOT(importAudio()));
Chris@162 411 m_keyReference->registerShortcut(action);
Chris@66 412 menu->addAction(action);
Chris@66 413
Chris@66 414 action = new QAction(tr("Import Secondary Audio File..."), this);
Chris@66 415 action->setShortcut(tr("Ctrl+Shift+I"));
Chris@66 416 action->setStatusTip(tr("Import an extra audio file as a separate layer"));
Chris@66 417 connect(action, SIGNAL(triggered()), this, SLOT(importMoreAudio()));
Chris@66 418 connect(this, SIGNAL(canImportMoreAudio(bool)), action, SLOT(setEnabled(bool)));
Chris@162 419 m_keyReference->registerShortcut(action);
Chris@66 420 menu->addAction(action);
Chris@66 421
Chris@66 422 action = new QAction(tr("&Export Audio File..."), this);
Chris@66 423 action->setStatusTip(tr("Export selection as an audio file"));
Chris@66 424 connect(action, SIGNAL(triggered()), this, SLOT(exportAudio()));
Chris@66 425 connect(this, SIGNAL(canExportAudio(bool)), action, SLOT(setEnabled(bool)));
Chris@66 426 menu->addAction(action);
Chris@66 427
Chris@66 428 menu->addSeparator();
Chris@66 429
Chris@66 430 action = new QAction(tr("Import Annotation &Layer..."), this);
Chris@66 431 action->setShortcut(tr("Ctrl+L"));
Chris@66 432 action->setStatusTip(tr("Import layer data from an existing file"));
Chris@66 433 connect(action, SIGNAL(triggered()), this, SLOT(importLayer()));
Chris@66 434 connect(this, SIGNAL(canImportLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@162 435 m_keyReference->registerShortcut(action);
Chris@66 436 menu->addAction(action);
Chris@66 437
Chris@66 438 action = new QAction(tr("Export Annotation Layer..."), this);
Chris@66 439 action->setStatusTip(tr("Export layer data to a file"));
Chris@66 440 connect(action, SIGNAL(triggered()), this, SLOT(exportLayer()));
Chris@66 441 connect(this, SIGNAL(canExportLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@66 442 menu->addAction(action);
Chris@66 443
Chris@66 444 menu->addSeparator();
Chris@86 445
Chris@121 446 action = new QAction(tr("Export Image File..."), this);
Chris@121 447 action->setStatusTip(tr("Export a single pane to an image file"));
Chris@121 448 connect(action, SIGNAL(triggered()), this, SLOT(exportImage()));
Chris@121 449 connect(this, SIGNAL(canExportImage(bool)), action, SLOT(setEnabled(bool)));
Chris@121 450 menu->addAction(action);
Chris@121 451
Chris@121 452 menu->addSeparator();
Chris@121 453
Chris@86 454 action = new QAction(tr("Open Lo&cation..."), this);
Chris@86 455 action->setShortcut(tr("Ctrl+Shift+O"));
Chris@86 456 action->setStatusTip(tr("Open or import a file from a remote URL"));
Chris@86 457 connect(action, SIGNAL(triggered()), this, SLOT(openLocation()));
Chris@162 458 m_keyReference->registerShortcut(action);
Chris@86 459 menu->addAction(action);
Chris@86 460
Chris@86 461 menu->addSeparator();
Chris@86 462
Chris@66 463 m_recentFilesMenu = menu->addMenu(tr("&Recent Files"));
Chris@97 464 m_recentFilesMenu->setTearOffEnabled(true);
Chris@66 465 setupRecentFilesMenu();
Chris@66 466 connect(&m_recentFiles, SIGNAL(recentChanged()),
Chris@66 467 this, SLOT(setupRecentFilesMenu()));
Chris@66 468
Chris@66 469 menu->addSeparator();
Chris@66 470 action = new QAction(tr("&Preferences..."), this);
Chris@66 471 action->setStatusTip(tr("Adjust the application preferences"));
Chris@66 472 connect(action, SIGNAL(triggered()), this, SLOT(preferences()));
Chris@66 473 menu->addAction(action);
Chris@0 474
Chris@66 475 menu->addSeparator();
Chris@168 476 action = new QAction(il.load("exit"),
Chris@66 477 tr("&Quit"), this);
Chris@66 478 action->setShortcut(tr("Ctrl+Q"));
Chris@90 479 action->setStatusTip(tr("Exit Sonic Visualiser"));
Chris@66 480 connect(action, SIGNAL(triggered()), this, SLOT(close()));
Chris@162 481 m_keyReference->registerShortcut(action);
Chris@66 482 menu->addAction(action);
Chris@66 483 }
Chris@66 484
Chris@66 485 void
Chris@66 486 MainWindow::setupEditMenu()
Chris@66 487 {
Chris@66 488 if (m_mainMenusCreated) return;
Chris@66 489
Chris@66 490 QMenu *menu = menuBar()->addMenu(tr("&Edit"));
Chris@97 491 menu->setTearOffEnabled(true);
Chris@66 492 CommandHistory::getInstance()->registerMenu(menu);
Chris@66 493
Chris@162 494 m_keyReference->setCategory(tr("Editing"));
Chris@162 495
Chris@66 496 menu->addSeparator();
Chris@66 497
Chris@168 498 IconLoader il;
Chris@168 499
Chris@168 500 QAction *action = new QAction(il.load("editcut"),
Chris@66 501 tr("Cu&t"), this);
Chris@66 502 action->setShortcut(tr("Ctrl+X"));
Chris@90 503 action->setStatusTip(tr("Cut the selection from the current layer to the clipboard"));
Chris@66 504 connect(action, SIGNAL(triggered()), this, SLOT(cut()));
Chris@66 505 connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@162 506 m_keyReference->registerShortcut(action);
Chris@66 507 menu->addAction(action);
Chris@66 508 m_rightButtonMenu->addAction(action);
Chris@66 509
Chris@168 510 action = new QAction(il.load("editcopy"),
Chris@66 511 tr("&Copy"), this);
Chris@66 512 action->setShortcut(tr("Ctrl+C"));
Chris@90 513 action->setStatusTip(tr("Copy the selection from the current layer to the clipboard"));
Chris@66 514 connect(action, SIGNAL(triggered()), this, SLOT(copy()));
Chris@66 515 connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@162 516 m_keyReference->registerShortcut(action);
Chris@66 517 menu->addAction(action);
Chris@66 518 m_rightButtonMenu->addAction(action);
Chris@66 519
Chris@168 520 action = new QAction(il.load("editpaste"),
Chris@66 521 tr("&Paste"), this);
Chris@66 522 action->setShortcut(tr("Ctrl+V"));
Chris@90 523 action->setStatusTip(tr("Paste from the clipboard to the current layer"));
Chris@66 524 connect(action, SIGNAL(triggered()), this, SLOT(paste()));
Chris@66 525 connect(this, SIGNAL(canPaste(bool)), action, SLOT(setEnabled(bool)));
Chris@162 526 m_keyReference->registerShortcut(action);
Chris@66 527 menu->addAction(action);
Chris@66 528 m_rightButtonMenu->addAction(action);
Chris@66 529
Chris@164 530 m_deleteSelectedAction = new QAction(tr("&Delete Selected Items"), this);
Chris@164 531 m_deleteSelectedAction->setShortcut(tr("Del"));
Chris@164 532 m_deleteSelectedAction->setStatusTip(tr("Delete items in current selection from the current layer"));
Chris@164 533 connect(m_deleteSelectedAction, SIGNAL(triggered()), this, SLOT(deleteSelected()));
Chris@164 534 connect(this, SIGNAL(canDeleteSelection(bool)), m_deleteSelectedAction, SLOT(setEnabled(bool)));
Chris@164 535 m_keyReference->registerShortcut(m_deleteSelectedAction);
Chris@164 536 menu->addAction(m_deleteSelectedAction);
Chris@164 537 m_rightButtonMenu->addAction(m_deleteSelectedAction);
Chris@66 538
Chris@66 539 menu->addSeparator();
Chris@66 540 m_rightButtonMenu->addSeparator();
Chris@162 541
Chris@162 542 m_keyReference->setCategory(tr("Selection"));
Chris@162 543
Chris@66 544 action = new QAction(tr("Select &All"), this);
Chris@66 545 action->setShortcut(tr("Ctrl+A"));
Chris@90 546 action->setStatusTip(tr("Select the whole duration of the current session"));
Chris@66 547 connect(action, SIGNAL(triggered()), this, SLOT(selectAll()));
Chris@66 548 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
Chris@162 549 m_keyReference->registerShortcut(action);
Chris@66 550 menu->addAction(action);
Chris@66 551 m_rightButtonMenu->addAction(action);
Chris@0 552
Chris@66 553 action = new QAction(tr("Select &Visible Range"), this);
Chris@66 554 action->setShortcut(tr("Ctrl+Shift+A"));
Chris@90 555 action->setStatusTip(tr("Select the time range corresponding to the current window width"));
Chris@66 556 connect(action, SIGNAL(triggered()), this, SLOT(selectVisible()));
Chris@66 557 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
Chris@162 558 m_keyReference->registerShortcut(action);
Chris@66 559 menu->addAction(action);
Chris@0 560
Chris@66 561 action = new QAction(tr("Select to &Start"), this);
Chris@66 562 action->setShortcut(tr("Shift+Left"));
Chris@90 563 action->setStatusTip(tr("Select from the start of the session to the current playback position"));
Chris@66 564 connect(action, SIGNAL(triggered()), this, SLOT(selectToStart()));
Chris@66 565 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
Chris@162 566 m_keyReference->registerShortcut(action);
Chris@66 567 menu->addAction(action);
Chris@0 568
Chris@66 569 action = new QAction(tr("Select to &End"), this);
Chris@66 570 action->setShortcut(tr("Shift+Right"));
Chris@90 571 action->setStatusTip(tr("Select from the current playback position to the end of the session"));
Chris@66 572 connect(action, SIGNAL(triggered()), this, SLOT(selectToEnd()));
Chris@66 573 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
Chris@162 574 m_keyReference->registerShortcut(action);
Chris@66 575 menu->addAction(action);
Chris@66 576
Chris@66 577 action = new QAction(tr("C&lear Selection"), this);
Chris@66 578 action->setShortcut(tr("Esc"));
Chris@90 579 action->setStatusTip(tr("Clear the selection"));
Chris@66 580 connect(action, SIGNAL(triggered()), this, SLOT(clearSelection()));
Chris@66 581 connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@162 582 m_keyReference->registerShortcut(action);
Chris@66 583 menu->addAction(action);
Chris@66 584 m_rightButtonMenu->addAction(action);
Chris@66 585
Chris@66 586 menu->addSeparator();
Chris@66 587
Chris@162 588 m_keyReference->setCategory(tr("Tapping Time Instants"));
Chris@162 589
Chris@66 590 action = new QAction(tr("&Insert Instant at Playback Position"), this);
Chris@66 591 action->setShortcut(tr("Enter"));
Chris@90 592 action->setStatusTip(tr("Insert a new time instant at the current playback position, in a new layer if necessary"));
Chris@66 593 connect(action, SIGNAL(triggered()), this, SLOT(insertInstant()));
Chris@66 594 connect(this, SIGNAL(canInsertInstant(bool)), action, SLOT(setEnabled(bool)));
Chris@162 595 m_keyReference->registerShortcut(action);
Chris@66 596 menu->addAction(action);
Chris@66 597
Chris@162 598 // Laptop shortcut (no keypad Enter key)
Chris@162 599 QString shortcut(tr(";"));
Chris@162 600 connect(new QShortcut(shortcut, this), SIGNAL(activated()),
Chris@162 601 this, SLOT(insertInstant()));
Chris@162 602 m_keyReference->registerAlternativeShortcut(action, shortcut);
Chris@162 603
Chris@81 604 action = new QAction(tr("Insert Instants at Selection &Boundaries"), this);
Chris@81 605 action->setShortcut(tr("Shift+Enter"));
Chris@163 606 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 607 connect(action, SIGNAL(triggered()), this, SLOT(insertInstantsAtBoundaries()));
Chris@81 608 connect(this, SIGNAL(canInsertInstantsAtBoundaries(bool)), action, SLOT(setEnabled(bool)));
Chris@162 609 m_keyReference->registerShortcut(action);
Chris@81 610 menu->addAction(action);
Chris@189 611
Chris@190 612 QMenu *numberingMenu = menu->addMenu(tr("Number New Instants with"));
Chris@225 613 numberingMenu->setTearOffEnabled(true);
Chris@189 614 QActionGroup *numberingGroup = new QActionGroup(this);
Chris@189 615
Chris@189 616 Labeller::TypeNameMap types = m_labeller->getTypeNames();
Chris@189 617 for (Labeller::TypeNameMap::iterator i = types.begin(); i != types.end(); ++i) {
Chris@190 618
Chris@190 619 if (i->first == Labeller::ValueFromLabel ||
Chris@190 620 i->first == Labeller::ValueFromExistingNeighbour) continue;
Chris@190 621
Chris@189 622 action = new QAction(i->second, this);
Chris@189 623 connect(action, SIGNAL(triggered()), this, SLOT(setInstantsNumbering()));
Chris@189 624 action->setCheckable(true);
Chris@189 625 action->setChecked(m_labeller->getType() == i->first);
Chris@189 626 numberingGroup->addAction(action);
Chris@189 627 numberingMenu->addAction(action);
Chris@189 628 m_numberingActions[action] = (int)i->first;
Chris@190 629
Chris@190 630 if (i->first == Labeller::ValueFromTwoLevelCounter) {
Chris@192 631
Chris@190 632 QMenu *cycleMenu = numberingMenu->addMenu(tr("Cycle size"));
Chris@190 633 QActionGroup *cycleGroup = new QActionGroup(this);
Chris@190 634
Chris@229 635 int cycles[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 16 };
Chris@200 636 for (int i = 0; i < int(sizeof(cycles)/sizeof(cycles[0])); ++i) {
Chris@190 637 action = new QAction(QString("%1").arg(cycles[i]), this);
Chris@190 638 connect(action, SIGNAL(triggered()), this, SLOT(setInstantsCounterCycle()));
Chris@190 639 action->setCheckable(true);
Chris@190 640 action->setChecked(cycles[i] == m_labeller->getCounterCycleSize());
Chris@190 641 cycleGroup->addAction(action);
Chris@190 642 cycleMenu->addAction(action);
Chris@190 643 }
Chris@190 644 }
Chris@190 645
Chris@190 646 if (i->first == Labeller::ValueNone ||
Chris@190 647 i->first == Labeller::ValueFromTwoLevelCounter ||
Chris@190 648 i->first == Labeller::ValueFromRealTime) {
Chris@190 649 numberingMenu->addSeparator();
Chris@190 650 }
Chris@189 651 }
Chris@189 652
Chris@241 653 action = new QAction(tr("Set Numbering Counters..."), this);
Chris@241 654 action->setStatusTip(tr("Set the counters used for counter-based labelling"));
Chris@241 655 connect(action, SIGNAL(triggered()), this, SLOT(resetInstantsCounters()));
Chris@241 656 menu->addAction(action);
Chris@241 657
Chris@241 658 action = new QAction(tr("Renumber Selected Instants"), this);
Chris@241 659 action->setStatusTip(tr("Renumber the selected instants using the current labelling scheme"));
Chris@189 660 connect(action, SIGNAL(triggered()), this, SLOT(renumberInstants()));
Chris@189 661 connect(this, SIGNAL(canRenumberInstants(bool)), action, SLOT(setEnabled(bool)));
Chris@189 662 // m_keyReference->registerShortcut(action);
Chris@189 663 menu->addAction(action);
Chris@66 664 }
Chris@66 665
Chris@66 666 void
Chris@66 667 MainWindow::setupViewMenu()
Chris@66 668 {
Chris@66 669 if (m_mainMenusCreated) return;
Chris@66 670
Chris@168 671 IconLoader il;
Chris@168 672
Chris@90 673 QAction *action = 0;
Chris@90 674
Chris@162 675 m_keyReference->setCategory(tr("Panning and Navigation"));
Chris@162 676
Chris@66 677 QMenu *menu = menuBar()->addMenu(tr("&View"));
Chris@97 678 menu->setTearOffEnabled(true);
Chris@66 679 action = new QAction(tr("Scroll &Left"), this);
Chris@66 680 action->setShortcut(tr("Left"));
Chris@66 681 action->setStatusTip(tr("Scroll the current pane to the left"));
Chris@66 682 connect(action, SIGNAL(triggered()), this, SLOT(scrollLeft()));
Chris@66 683 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@162 684 m_keyReference->registerShortcut(action);
Chris@66 685 menu->addAction(action);
Chris@0 686
Chris@66 687 action = new QAction(tr("Scroll &Right"), this);
Chris@66 688 action->setShortcut(tr("Right"));
Chris@66 689 action->setStatusTip(tr("Scroll the current pane to the right"));
Chris@66 690 connect(action, SIGNAL(triggered()), this, SLOT(scrollRight()));
Chris@66 691 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@162 692 m_keyReference->registerShortcut(action);
Chris@66 693 menu->addAction(action);
Chris@0 694
Chris@90 695 action = new QAction(tr("&Jump Left"), this);
Chris@66 696 action->setShortcut(tr("Ctrl+Left"));
Chris@66 697 action->setStatusTip(tr("Scroll the current pane a big step to the left"));
Chris@66 698 connect(action, SIGNAL(triggered()), this, SLOT(jumpLeft()));
Chris@66 699 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@162 700 m_keyReference->registerShortcut(action);
Chris@66 701 menu->addAction(action);
Chris@0 702
Chris@90 703 action = new QAction(tr("J&ump Right"), this);
Chris@66 704 action->setShortcut(tr("Ctrl+Right"));
Chris@66 705 action->setStatusTip(tr("Scroll the current pane a big step to the right"));
Chris@66 706 connect(action, SIGNAL(triggered()), this, SLOT(jumpRight()));
Chris@66 707 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@162 708 m_keyReference->registerShortcut(action);
Chris@66 709 menu->addAction(action);
Chris@66 710
Chris@66 711 menu->addSeparator();
Chris@66 712
Chris@162 713 m_keyReference->setCategory(tr("Zoom"));
Chris@162 714
Chris@168 715 action = new QAction(il.load("zoom-in"),
Chris@66 716 tr("Zoom &In"), this);
Chris@66 717 action->setShortcut(tr("Up"));
Chris@66 718 action->setStatusTip(tr("Increase the zoom level"));
Chris@66 719 connect(action, SIGNAL(triggered()), this, SLOT(zoomIn()));
Chris@66 720 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@162 721 m_keyReference->registerShortcut(action);
Chris@66 722 menu->addAction(action);
Chris@0 723
Chris@168 724 action = new QAction(il.load("zoom-out"),
Chris@66 725 tr("Zoom &Out"), this);
Chris@66 726 action->setShortcut(tr("Down"));
Chris@66 727 action->setStatusTip(tr("Decrease the zoom level"));
Chris@66 728 connect(action, SIGNAL(triggered()), this, SLOT(zoomOut()));
Chris@66 729 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@162 730 m_keyReference->registerShortcut(action);
Chris@66 731 menu->addAction(action);
Chris@0 732
Chris@66 733 action = new QAction(tr("Restore &Default Zoom"), this);
Chris@90 734 action->setStatusTip(tr("Restore the zoom level to the default"));
Chris@66 735 connect(action, SIGNAL(triggered()), this, SLOT(zoomDefault()));
Chris@66 736 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@66 737 menu->addAction(action);
Chris@66 738
Chris@168 739 action = new QAction(il.load("zoom-fit"),
Chris@138 740 tr("Zoom to &Fit"), this);
Chris@155 741 action->setShortcut(tr("F"));
Chris@66 742 action->setStatusTip(tr("Zoom to show the whole file"));
Chris@66 743 connect(action, SIGNAL(triggered()), this, SLOT(zoomToFit()));
Chris@66 744 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@162 745 m_keyReference->registerShortcut(action);
Chris@66 746 menu->addAction(action);
Chris@90 747
Chris@90 748 menu->addSeparator();
Chris@90 749
Chris@162 750 m_keyReference->setCategory(tr("Display Features"));
Chris@162 751
Chris@90 752 QActionGroup *overlayGroup = new QActionGroup(this);
Chris@90 753
Chris@90 754 action = new QAction(tr("Show &No Overlays"), this);
Chris@90 755 action->setShortcut(tr("0"));
Chris@90 756 action->setStatusTip(tr("Hide centre indicator, frame times, layer names and scale"));
Chris@90 757 connect(action, SIGNAL(triggered()), this, SLOT(showNoOverlays()));
Chris@90 758 action->setCheckable(true);
Chris@90 759 action->setChecked(false);
Chris@90 760 overlayGroup->addAction(action);
Chris@162 761 m_keyReference->registerShortcut(action);
Chris@90 762 menu->addAction(action);
Chris@90 763
Chris@90 764 action = new QAction(tr("Show &Minimal Overlays"), this);
Chris@90 765 action->setShortcut(tr("9"));
Chris@90 766 action->setStatusTip(tr("Show centre indicator only"));
Chris@90 767 connect(action, SIGNAL(triggered()), this, SLOT(showMinimalOverlays()));
Chris@90 768 action->setCheckable(true);
Chris@90 769 action->setChecked(false);
Chris@90 770 overlayGroup->addAction(action);
Chris@162 771 m_keyReference->registerShortcut(action);
Chris@90 772 menu->addAction(action);
Chris@90 773
Chris@90 774 action = new QAction(tr("Show &Standard Overlays"), this);
Chris@90 775 action->setShortcut(tr("8"));
Chris@90 776 action->setStatusTip(tr("Show centre indicator, frame times and scale"));
Chris@90 777 connect(action, SIGNAL(triggered()), this, SLOT(showStandardOverlays()));
Chris@90 778 action->setCheckable(true);
Chris@90 779 action->setChecked(true);
Chris@90 780 overlayGroup->addAction(action);
Chris@162 781 m_keyReference->registerShortcut(action);
Chris@90 782 menu->addAction(action);
Chris@90 783
Chris@90 784 action = new QAction(tr("Show &All Overlays"), this);
Chris@90 785 action->setShortcut(tr("7"));
Chris@90 786 action->setStatusTip(tr("Show all texts and scale"));
Chris@90 787 connect(action, SIGNAL(triggered()), this, SLOT(showAllOverlays()));
Chris@90 788 action->setCheckable(true);
Chris@90 789 action->setChecked(false);
Chris@90 790 overlayGroup->addAction(action);
Chris@162 791 m_keyReference->registerShortcut(action);
Chris@90 792 menu->addAction(action);
Chris@7 793
Chris@72 794 menu->addSeparator();
Chris@72 795
Chris@66 796 action = new QAction(tr("Show &Zoom Wheels"), this);
Chris@66 797 action->setShortcut(tr("Z"));
Chris@66 798 action->setStatusTip(tr("Show thumbwheels for zooming horizontally and vertically"));
Chris@66 799 connect(action, SIGNAL(triggered()), this, SLOT(toggleZoomWheels()));
Chris@66 800 action->setCheckable(true);
Chris@66 801 action->setChecked(m_viewManager->getZoomWheelsEnabled());
Chris@162 802 m_keyReference->registerShortcut(action);
Chris@66 803 menu->addAction(action);
Chris@72 804
Chris@72 805 action = new QAction(tr("Show Property Bo&xes"), this);
Chris@72 806 action->setShortcut(tr("X"));
Chris@72 807 action->setStatusTip(tr("Show the layer property boxes at the side of the main window"));
Chris@72 808 connect(action, SIGNAL(triggered()), this, SLOT(togglePropertyBoxes()));
Chris@72 809 action->setCheckable(true);
Chris@72 810 action->setChecked(true);
Chris@162 811 m_keyReference->registerShortcut(action);
Chris@72 812 menu->addAction(action);
Chris@0 813
Chris@90 814 action = new QAction(tr("Show Status &Bar"), this);
Chris@90 815 action->setStatusTip(tr("Show context help information in the status bar at the bottom of the window"));
Chris@90 816 connect(action, SIGNAL(triggered()), this, SLOT(toggleStatusBar()));
Chris@90 817 action->setCheckable(true);
Chris@90 818 action->setChecked(true);
Chris@90 819 menu->addAction(action);
Chris@90 820
Chris@90 821 QSettings settings;
Chris@90 822 settings.beginGroup("MainWindow");
Chris@90 823 bool sb = settings.value("showstatusbar", true).toBool();
Chris@90 824 if (!sb) {
Chris@90 825 action->setChecked(false);
Chris@90 826 statusBar()->hide();
Chris@90 827 }
Chris@90 828 settings.endGroup();
Chris@90 829
Chris@66 830 menu->addSeparator();
Chris@66 831
Chris@219 832 action = new QAction(tr("Show La&yer Summary"), this);
Chris@219 833 action->setShortcut(tr("Y"));
Chris@90 834 action->setStatusTip(tr("Open a window displaying the hierarchy of panes and layers in this session"));
Chris@66 835 connect(action, SIGNAL(triggered()), this, SLOT(showLayerTree()));
Chris@162 836 m_keyReference->registerShortcut(action);
Chris@66 837 menu->addAction(action);
Chris@66 838 }
Chris@66 839
Chris@66 840 void
Chris@66 841 MainWindow::setupPaneAndLayerMenus()
Chris@66 842 {
Chris@0 843 if (m_paneMenu) {
Chris@0 844 m_paneActions.clear();
Chris@0 845 m_paneMenu->clear();
Chris@0 846 } else {
Chris@0 847 m_paneMenu = menuBar()->addMenu(tr("&Pane"));
Chris@97 848 m_paneMenu->setTearOffEnabled(true);
Chris@0 849 }
Chris@0 850
Chris@0 851 if (m_layerMenu) {
Chris@0 852 m_layerActions.clear();
Chris@0 853 m_layerMenu->clear();
Chris@0 854 } else {
Chris@0 855 m_layerMenu = menuBar()->addMenu(tr("&Layer"));
Chris@97 856 m_layerMenu->setTearOffEnabled(true);
Chris@0 857 }
Chris@0 858
Chris@66 859 QMenu *menu = m_paneMenu;
Chris@66 860
Chris@168 861 IconLoader il;
Chris@168 862
Chris@162 863 m_keyReference->setCategory(tr("Managing Panes and Layers"));
Chris@162 864
Chris@168 865 QAction *action = new QAction(il.load("pane"), tr("Add &New Pane"), this);
Chris@155 866 action->setShortcut(tr("N"));
Chris@66 867 action->setStatusTip(tr("Add a new pane containing only a time ruler"));
Chris@66 868 connect(action, SIGNAL(triggered()), this, SLOT(addPane()));
Chris@66 869 connect(this, SIGNAL(canAddPane(bool)), action, SLOT(setEnabled(bool)));
Chris@232 870 m_paneActions[action] = LayerConfiguration(LayerFactory::TimeRuler);
Chris@162 871 m_keyReference->registerShortcut(action);
Chris@66 872 menu->addAction(action);
Chris@66 873
Chris@66 874 menu->addSeparator();
Chris@66 875
Chris@66 876 menu = m_layerMenu;
Chris@66 877
Chris@66 878 // menu->addSeparator();
Chris@66 879
Chris@66 880 LayerFactory::LayerTypeSet emptyLayerTypes =
Chris@66 881 LayerFactory::getInstance()->getValidEmptyLayerTypes();
Chris@66 882
Chris@66 883 for (LayerFactory::LayerTypeSet::iterator i = emptyLayerTypes.begin();
Chris@66 884 i != emptyLayerTypes.end(); ++i) {
Chris@66 885
Chris@66 886 QIcon icon;
Chris@66 887 QString mainText, tipText, channelText;
Chris@66 888 LayerFactory::LayerType type = *i;
Chris@66 889 QString name = LayerFactory::getInstance()->getLayerPresentationName(type);
Chris@66 890
Chris@168 891 icon = il.load(LayerFactory::getInstance()->getLayerIconName(type));
Chris@66 892
Chris@66 893 mainText = tr("Add New %1 Layer").arg(name);
Chris@66 894 tipText = tr("Add a new empty layer of type %1").arg(name);
Chris@66 895
Chris@66 896 action = new QAction(icon, mainText, this);
Chris@66 897 action->setStatusTip(tipText);
Chris@66 898
Chris@66 899 if (type == LayerFactory::Text) {
Chris@155 900 action->setShortcut(tr("T"));
Chris@162 901 m_keyReference->registerShortcut(action);
Chris@66 902 }
Chris@66 903
Chris@66 904 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@66 905 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@232 906 m_layerActions[action] = LayerConfiguration(type);
Chris@66 907 menu->addAction(action);
Chris@66 908 m_rightButtonLayerMenu->addAction(action);
Chris@66 909 }
Chris@66 910
Chris@66 911 m_rightButtonLayerMenu->addSeparator();
Chris@66 912 menu->addSeparator();
Chris@66 913
Chris@66 914 LayerFactory::LayerType backgroundTypes[] = {
Chris@66 915 LayerFactory::Waveform,
Chris@66 916 LayerFactory::Spectrogram,
Chris@66 917 LayerFactory::MelodicRangeSpectrogram,
Chris@66 918 LayerFactory::PeakFrequencySpectrogram,
Chris@66 919 LayerFactory::Spectrum
Chris@66 920 };
Chris@66 921
Chris@66 922 std::vector<Model *> models;
Chris@224 923 if (m_document) models = m_document->getTransformInputModels();
Chris@66 924 bool plural = (models.size() > 1);
Chris@66 925 if (models.empty()) {
Chris@67 926 models.push_back(getMainModel()); // probably 0
Chris@66 927 }
Chris@66 928
Chris@66 929 for (unsigned int i = 0;
Chris@66 930 i < sizeof(backgroundTypes)/sizeof(backgroundTypes[0]); ++i) {
Chris@66 931
Chris@231 932 const int paneMenuType = 0, layerMenuType = 1;
Chris@231 933
Chris@231 934 for (int menuType = paneMenuType; menuType <= layerMenuType; ++menuType) {
Chris@231 935
Chris@231 936 if (menuType == paneMenuType) menu = m_paneMenu;
Chris@66 937 else menu = m_layerMenu;
Chris@66 938
Chris@66 939 QMenu *submenu = 0;
Chris@66 940
Chris@66 941 QIcon icon;
Chris@66 942 QString mainText, shortcutText, tipText, channelText;
Chris@66 943 LayerFactory::LayerType type = backgroundTypes[i];
Chris@66 944 bool mono = true;
Chris@66 945
Chris@66 946 switch (type) {
Chris@66 947
Chris@66 948 case LayerFactory::Waveform:
Chris@168 949 icon = il.load("waveform");
Chris@66 950 mainText = tr("Add &Waveform");
Chris@231 951 if (menuType == paneMenuType) {
Chris@155 952 shortcutText = tr("W");
Chris@66 953 tipText = tr("Add a new pane showing a waveform view");
Chris@66 954 } else {
Chris@66 955 tipText = tr("Add a new layer showing a waveform view");
Chris@66 956 }
Chris@66 957 mono = false;
Chris@66 958 break;
Chris@66 959
Chris@66 960 case LayerFactory::Spectrogram:
Chris@168 961 icon = il.load("spectrogram");
Chris@161 962 mainText = tr("Add Spectro&gram");
Chris@231 963 if (menuType == paneMenuType) {
Chris@155 964 shortcutText = tr("G");
Chris@90 965 tipText = tr("Add a new pane showing a spectrogram");
Chris@66 966 } else {
Chris@90 967 tipText = tr("Add a new layer showing a spectrogram");
Chris@66 968 }
Chris@66 969 break;
Chris@66 970
Chris@66 971 case LayerFactory::MelodicRangeSpectrogram:
Chris@168 972 icon = il.load("spectrogram");
Chris@66 973 mainText = tr("Add &Melodic Range Spectrogram");
Chris@231 974 if (menuType == paneMenuType) {
Chris@155 975 shortcutText = tr("M");
Chris@90 976 tipText = tr("Add a new pane showing a spectrogram set up for an overview of note pitches");
Chris@66 977 } else {
Chris@90 978 tipText = tr("Add a new layer showing a spectrogram set up for an overview of note pitches");
Chris@66 979 }
Chris@66 980 break;
Chris@66 981
Chris@66 982 case LayerFactory::PeakFrequencySpectrogram:
Chris@168 983 icon = il.load("spectrogram");
Chris@155 984 mainText = tr("Add Pea&k Frequency Spectrogram");
Chris@231 985 if (menuType == paneMenuType) {
Chris@155 986 shortcutText = tr("K");
Chris@66 987 tipText = tr("Add a new pane showing a spectrogram set up for tracking frequencies");
Chris@66 988 } else {
Chris@66 989 tipText = tr("Add a new layer showing a spectrogram set up for tracking frequencies");
Chris@66 990 }
Chris@66 991 break;
Chris@66 992
Chris@66 993 case LayerFactory::Spectrum:
Chris@168 994 icon = il.load("spectrum");
Chris@66 995 mainText = tr("Add Spectr&um");
Chris@231 996 if (menuType == paneMenuType) {
Chris@155 997 shortcutText = tr("U");
Chris@66 998 tipText = tr("Add a new pane showing a frequency spectrum");
Chris@66 999 } else {
Chris@66 1000 tipText = tr("Add a new layer showing a frequency spectrum");
Chris@66 1001 }
Chris@66 1002 break;
Chris@66 1003
Chris@66 1004 default: break;
Chris@66 1005 }
Chris@66 1006
Chris@66 1007 std::vector<Model *> candidateModels;
Chris@231 1008 // if (menuType == paneMenuType) {
Chris@66 1009 candidateModels = models;
Chris@231 1010 // } else {
Chris@231 1011 // candidateModels.push_back(0);
Chris@231 1012 // }
Chris@66 1013
Chris@66 1014 for (std::vector<Model *>::iterator mi =
Chris@66 1015 candidateModels.begin();
Chris@66 1016 mi != candidateModels.end(); ++mi) {
Chris@66 1017
Chris@66 1018 Model *model = *mi;
Chris@66 1019
Chris@66 1020 int channels = 0;
Chris@66 1021 if (model) {
Chris@66 1022 DenseTimeValueModel *dtvm =
Chris@66 1023 dynamic_cast<DenseTimeValueModel *>(model);
Chris@66 1024 if (dtvm) channels = dtvm->getChannelCount();
Chris@66 1025 }
Chris@66 1026 if (channels < 1 && getMainModel()) {
Chris@66 1027 channels = getMainModel()->getChannelCount();
Chris@66 1028 }
Chris@66 1029 if (channels < 1) channels = 1;
Chris@66 1030
Chris@66 1031 for (int c = 0; c <= channels; ++c) {
Chris@66 1032
Chris@66 1033 if (c == 1 && channels == 1) continue;
Chris@66 1034 bool isDefault = (c == 0);
Chris@66 1035 bool isOnly = (isDefault && (channels == 1));
Chris@66 1036
Chris@231 1037 // if (menuType == layerMenuType) {
Chris@231 1038 // if (isDefault) isOnly = true;
Chris@231 1039 // else continue;
Chris@231 1040 // }
Chris@231 1041
Chris@231 1042 if (isOnly && (!plural /*|| menuType == layerMenuType*/)) {
Chris@231 1043
Chris@231 1044 // if (menuType == layerMenuType && type != LayerFactory::Waveform) {
Chris@231 1045 // action = new QAction(mainText, this);
Chris@231 1046 // } else {
Chris@67 1047 action = new QAction(icon, mainText, this);
Chris@231 1048 // }
Chris@67 1049
Chris@66 1050 action->setShortcut(shortcutText);
Chris@66 1051 action->setStatusTip(tipText);
Chris@231 1052 if (menuType == paneMenuType) {
Chris@66 1053 connect(action, SIGNAL(triggered()),
Chris@66 1054 this, SLOT(addPane()));
Chris@66 1055 connect(this, SIGNAL(canAddPane(bool)),
Chris@66 1056 action, SLOT(setEnabled(bool)));
Chris@232 1057 m_paneActions[action] = LayerConfiguration(type);
Chris@66 1058 } else {
Chris@66 1059 connect(action, SIGNAL(triggered()),
Chris@66 1060 this, SLOT(addLayer()));
Chris@66 1061 connect(this, SIGNAL(canAddLayer(bool)),
Chris@66 1062 action, SLOT(setEnabled(bool)));
Chris@232 1063 m_layerActions[action] = LayerConfiguration(type);
Chris@66 1064 }
Chris@162 1065 if (shortcutText != "") {
Chris@162 1066 m_keyReference->registerShortcut(action);
Chris@162 1067 }
Chris@66 1068 menu->addAction(action);
Chris@66 1069
Chris@66 1070 } else {
Chris@66 1071
Chris@66 1072 if (!submenu) {
Chris@66 1073 submenu = menu->addMenu(mainText);
Chris@97 1074 submenu->setTearOffEnabled(true);
Chris@67 1075 } else if (isDefault) {
Chris@67 1076 submenu->addSeparator();
Chris@66 1077 }
Chris@66 1078
Chris@66 1079 QString actionText;
Chris@66 1080 if (c == 0) {
Chris@66 1081 if (mono) {
Chris@66 1082 actionText = tr("&All Channels Mixed");
Chris@66 1083 } else {
Chris@66 1084 actionText = tr("&All Channels");
Chris@66 1085 }
Chris@66 1086 } else {
Chris@66 1087 actionText = tr("Channel &%1").arg(c);
Chris@66 1088 }
Chris@66 1089
Chris@66 1090 if (model) {
Chris@66 1091 actionText = tr("%1: %2")
Chris@66 1092 .arg(model->objectName())
Chris@66 1093 .arg(actionText);
Chris@66 1094 }
Chris@67 1095
Chris@67 1096 if (isDefault) {
Chris@67 1097 action = new QAction(icon, actionText, this);
Chris@67 1098 if (!model || model == getMainModel()) {
Chris@162 1099 action->setShortcut(shortcutText);
Chris@67 1100 }
Chris@67 1101 } else {
Chris@67 1102 action = new QAction(actionText, this);
Chris@67 1103 }
Chris@67 1104
Chris@66 1105 action->setStatusTip(tipText);
Chris@66 1106
Chris@231 1107 if (menuType == paneMenuType) {
Chris@66 1108 connect(action, SIGNAL(triggered()),
Chris@66 1109 this, SLOT(addPane()));
Chris@66 1110 connect(this, SIGNAL(canAddPane(bool)),
Chris@66 1111 action, SLOT(setEnabled(bool)));
Chris@66 1112 m_paneActions[action] =
Chris@232 1113 LayerConfiguration(type, model, c - 1);
Chris@66 1114 } else {
Chris@66 1115 connect(action, SIGNAL(triggered()),
Chris@66 1116 this, SLOT(addLayer()));
Chris@66 1117 connect(this, SIGNAL(canAddLayer(bool)),
Chris@66 1118 action, SLOT(setEnabled(bool)));
Chris@232 1119 m_layerActions[action] =
Chris@232 1120 LayerConfiguration(type, model, c - 1);
Chris@66 1121 }
Chris@66 1122
Chris@66 1123 submenu->addAction(action);
Chris@66 1124 }
Chris@66 1125 }
Chris@66 1126 }
Chris@66 1127 }
Chris@66 1128 }
Chris@66 1129
Chris@66 1130 menu = m_paneMenu;
Chris@225 1131 menu->addSeparator();
Chris@225 1132
Chris@225 1133 action = new QAction(tr("Switch to Previous Pane"), this);
Chris@225 1134 action->setShortcut(tr("["));
Chris@225 1135 action->setStatusTip(tr("Make the next pane up in the pane stack current"));
Chris@225 1136 connect(action, SIGNAL(triggered()), this, SLOT(previousPane()));
Chris@225 1137 connect(this, SIGNAL(canSelectPreviousPane(bool)), action, SLOT(setEnabled(bool)));
Chris@225 1138 m_keyReference->registerShortcut(action);
Chris@225 1139 menu->addAction(action);
Chris@225 1140
Chris@225 1141 action = new QAction(tr("Switch to Next Pane"), this);
Chris@225 1142 action->setShortcut(tr("]"));
Chris@225 1143 action->setStatusTip(tr("Make the next pane down in the pane stack current"));
Chris@225 1144 connect(action, SIGNAL(triggered()), this, SLOT(nextPane()));
Chris@225 1145 connect(this, SIGNAL(canSelectNextPane(bool)), action, SLOT(setEnabled(bool)));
Chris@225 1146 m_keyReference->registerShortcut(action);
Chris@225 1147 menu->addAction(action);
Chris@66 1148
Chris@66 1149 menu->addSeparator();
Chris@66 1150
Chris@168 1151 action = new QAction(il.load("editdelete"), tr("&Delete Pane"), this);
Chris@155 1152 action->setShortcut(tr("Ctrl+Shift+D"));
Chris@90 1153 action->setStatusTip(tr("Delete the currently active pane"));
Chris@66 1154 connect(action, SIGNAL(triggered()), this, SLOT(deleteCurrentPane()));
Chris@66 1155 connect(this, SIGNAL(canDeleteCurrentPane(bool)), action, SLOT(setEnabled(bool)));
Chris@162 1156 m_keyReference->registerShortcut(action);
Chris@66 1157 menu->addAction(action);
Chris@66 1158
Chris@66 1159 menu = m_layerMenu;
Chris@66 1160
Chris@168 1161 action = new QAction(il.load("timeruler"), tr("Add &Time Ruler"), this);
Chris@66 1162 action->setStatusTip(tr("Add a new layer showing a time ruler"));
Chris@66 1163 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@66 1164 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@232 1165 m_layerActions[action] = LayerConfiguration(LayerFactory::TimeRuler);
Chris@66 1166 menu->addAction(action);
Chris@66 1167
Chris@66 1168 menu->addSeparator();
Chris@66 1169
Chris@66 1170 m_existingLayersMenu = menu->addMenu(tr("Add &Existing Layer"));
Chris@97 1171 m_existingLayersMenu->setTearOffEnabled(true);
Chris@66 1172 m_rightButtonLayerMenu->addMenu(m_existingLayersMenu);
Chris@95 1173
Chris@95 1174 m_sliceMenu = menu->addMenu(tr("Add S&lice of Layer"));
Chris@97 1175 m_sliceMenu->setTearOffEnabled(true);
Chris@95 1176 m_rightButtonLayerMenu->addMenu(m_sliceMenu);
Chris@95 1177
Chris@95 1178 setupExistingLayersMenus();
Chris@66 1179
Chris@225 1180 /*!!! These don't work correctly -- fix or omit
Chris@225 1181 menu->addSeparator();
Chris@225 1182
Chris@225 1183 action = new QAction(tr("Switch to Previous Layer"), this);
Chris@225 1184 action->setShortcut(tr("{"));
Chris@225 1185 action->setStatusTip(tr("Make the previous layer in the pane current"));
Chris@225 1186 connect(action, SIGNAL(triggered()), this, SLOT(previousLayer()));
Chris@225 1187 connect(this, SIGNAL(canSelectPreviousLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@225 1188 m_keyReference->registerShortcut(action);
Chris@225 1189 menu->addAction(action);
Chris@225 1190
Chris@225 1191 action = new QAction(tr("Switch to Next Layer"), this);
Chris@225 1192 action->setShortcut(tr("}"));
Chris@225 1193 action->setStatusTip(tr("Make the next layer in the pane current"));
Chris@225 1194 connect(action, SIGNAL(triggered()), this, SLOT(nextLayer()));
Chris@225 1195 connect(this, SIGNAL(canSelectNextLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@225 1196 m_keyReference->registerShortcut(action);
Chris@225 1197 menu->addAction(action);
Chris@225 1198 */
Chris@66 1199 m_rightButtonLayerMenu->addSeparator();
Chris@66 1200 menu->addSeparator();
Chris@66 1201
Chris@163 1202 QAction *raction = new QAction(tr("&Rename Layer..."), this);
Chris@163 1203 raction->setShortcut(tr("R"));
Chris@163 1204 raction->setStatusTip(tr("Rename the currently active layer"));
Chris@163 1205 connect(raction, SIGNAL(triggered()), this, SLOT(renameCurrentLayer()));
Chris@163 1206 connect(this, SIGNAL(canRenameLayer(bool)), raction, SLOT(setEnabled(bool)));
Chris@163 1207 menu->addAction(raction);
Chris@163 1208 m_rightButtonLayerMenu->addAction(raction);
Chris@66 1209
Chris@258 1210 QAction *eaction = new QAction(tr("Edit Layer Data"), this);
Chris@258 1211 eaction->setShortcut(tr("E"));
Chris@258 1212 eaction->setStatusTip(tr("Edit the currently active layer as a data grid"));
Chris@258 1213 connect(eaction, SIGNAL(triggered()), this, SLOT(editCurrentLayer()));
Chris@291 1214 connect(this, SIGNAL(canEditLayerTabular(bool)), eaction, SLOT(setEnabled(bool)));
Chris@258 1215 menu->addAction(eaction);
Chris@258 1216 m_rightButtonLayerMenu->addAction(eaction);
Chris@258 1217
Chris@168 1218 action = new QAction(il.load("editdelete"), tr("&Delete Layer"), this);
Chris@155 1219 action->setShortcut(tr("Ctrl+D"));
Chris@66 1220 action->setStatusTip(tr("Delete the currently active layer"));
Chris@66 1221 connect(action, SIGNAL(triggered()), this, SLOT(deleteCurrentLayer()));
Chris@66 1222 connect(this, SIGNAL(canDeleteCurrentLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@162 1223 m_keyReference->registerShortcut(action);
Chris@66 1224 menu->addAction(action);
Chris@66 1225 m_rightButtonLayerMenu->addAction(action);
Chris@163 1226
Chris@163 1227 m_keyReference->registerShortcut(raction); // rename after delete, so delete layer goes next to delete pane
Chris@258 1228 m_keyReference->registerShortcut(eaction); // edit also after delete
Chris@66 1229 }
Chris@66 1230
Chris@66 1231 void
Chris@211 1232 MainWindow::setupTransformsMenu()
Chris@66 1233 {
Chris@34 1234 if (m_transformsMenu) {
Chris@34 1235 m_transformActions.clear();
Chris@34 1236 m_transformActionsReverse.clear();
Chris@34 1237 m_transformsMenu->clear();
Chris@34 1238 } else {
Chris@97 1239 m_transformsMenu = menuBar()->addMenu(tr("&Transform"));
Chris@97 1240 m_transformsMenu->setTearOffEnabled(true);
Chris@286 1241 m_transformsMenu->setSeparatorsCollapsible(true);
Chris@272 1242 }
Chris@34 1243
Chris@288 1244 TransformFactory *factory = TransformFactory::getInstance();
Chris@288 1245
Chris@288 1246 TransformList transforms = factory->getAllTransformDescriptions();
Chris@288 1247 vector<TransformDescription::Type> types = factory->getAllTransformTypes();
Chris@288 1248
Chris@288 1249 map<TransformDescription::Type, map<QString, SubdividingMenu *> > categoryMenus;
Chris@288 1250 map<TransformDescription::Type, map<QString, SubdividingMenu *> > makerMenus;
Chris@288 1251
Chris@288 1252 map<TransformDescription::Type, SubdividingMenu *> byPluginNameMenus;
Chris@288 1253 map<TransformDescription::Type, map<QString, QMenu *> > pluginNameMenus;
Chris@33 1254
Chris@37 1255 set<SubdividingMenu *> pendingMenus;
Chris@37 1256
Chris@211 1257 m_recentTransformsMenu = m_transformsMenu->addMenu(tr("&Recent Transforms"));
Chris@211 1258 m_recentTransformsMenu->setTearOffEnabled(true);
Chris@211 1259 m_rightButtonTransformsMenu->addMenu(m_recentTransformsMenu);
Chris@211 1260 connect(&m_recentTransforms, SIGNAL(recentChanged()),
Chris@211 1261 this, SLOT(setupRecentTransformsMenu()));
Chris@34 1262
Chris@34 1263 m_transformsMenu->addSeparator();
Chris@211 1264 m_rightButtonTransformsMenu->addSeparator();
Chris@34 1265
Chris@288 1266 for (vector<TransformDescription::Type>::iterator i = types.begin();
Chris@288 1267 i != types.end(); ++i) {
Chris@33 1268
Chris@33 1269 if (i != types.begin()) {
Chris@34 1270 m_transformsMenu->addSeparator();
Chris@211 1271 m_rightButtonTransformsMenu->addSeparator();
Chris@33 1272 }
Chris@33 1273
Chris@288 1274 QString byCategoryLabel = tr("%1 by Category")
Chris@288 1275 .arg(factory->getTransformTypeName(*i));
Chris@37 1276 SubdividingMenu *byCategoryMenu = new SubdividingMenu(byCategoryLabel,
Chris@37 1277 20, 40);
Chris@97 1278 byCategoryMenu->setTearOffEnabled(true);
Chris@37 1279 m_transformsMenu->addMenu(byCategoryMenu);
Chris@211 1280 m_rightButtonTransformsMenu->addMenu(byCategoryMenu);
Chris@37 1281 pendingMenus.insert(byCategoryMenu);
Chris@33 1282
Chris@288 1283 vector<QString> categories = factory->getTransformCategories(*i);
Chris@33 1284
Chris@33 1285 for (vector<QString>::iterator j = categories.begin();
Chris@33 1286 j != categories.end(); ++j) {
Chris@33 1287
Chris@33 1288 QString category = *j;
Chris@33 1289 if (category == "") category = tr("Unclassified");
Chris@33 1290
Chris@33 1291 if (categories.size() < 2) {
Chris@33 1292 categoryMenus[*i][category] = byCategoryMenu;
Chris@33 1293 continue;
Chris@33 1294 }
Chris@33 1295
Chris@33 1296 QStringList components = category.split(" > ");
Chris@33 1297 QString key;
Chris@33 1298
Chris@33 1299 for (QStringList::iterator k = components.begin();
Chris@33 1300 k != components.end(); ++k) {
Chris@33 1301
Chris@33 1302 QString parentKey = key;
Chris@33 1303 if (key != "") key += " > ";
Chris@33 1304 key += *k;
Chris@33 1305
Chris@33 1306 if (categoryMenus[*i].find(key) == categoryMenus[*i].end()) {
Chris@37 1307 SubdividingMenu *m = new SubdividingMenu(*k, 20, 40);
Chris@97 1308 m->setTearOffEnabled(true);
Chris@37 1309 pendingMenus.insert(m);
Chris@37 1310 categoryMenus[*i][key] = m;
Chris@33 1311 if (parentKey == "") {
Chris@37 1312 byCategoryMenu->addMenu(m);
Chris@33 1313 } else {
Chris@37 1314 categoryMenus[*i][parentKey]->addMenu(m);
Chris@33 1315 }
Chris@33 1316 }
Chris@33 1317 }
Chris@33 1318 }
Chris@33 1319
Chris@288 1320 QString byPluginNameLabel = tr("%1 by Plugin Name")
Chris@288 1321 .arg(factory->getTransformTypeName(*i));
Chris@36 1322 byPluginNameMenus[*i] = new SubdividingMenu(byPluginNameLabel);
Chris@97 1323 byPluginNameMenus[*i]->setTearOffEnabled(true);
Chris@36 1324 m_transformsMenu->addMenu(byPluginNameMenus[*i]);
Chris@211 1325 m_rightButtonTransformsMenu->addMenu(byPluginNameMenus[*i]);
Chris@37 1326 pendingMenus.insert(byPluginNameMenus[*i]);
Chris@34 1327
Chris@288 1328 QString byMakerLabel = tr("%1 by Maker")
Chris@288 1329 .arg(factory->getTransformTypeName(*i));
Chris@37 1330 SubdividingMenu *byMakerMenu = new SubdividingMenu(byMakerLabel, 20, 40);
Chris@97 1331 byMakerMenu->setTearOffEnabled(true);
Chris@37 1332 m_transformsMenu->addMenu(byMakerMenu);
Chris@211 1333 m_rightButtonTransformsMenu->addMenu(byMakerMenu);
Chris@37 1334 pendingMenus.insert(byMakerMenu);
Chris@33 1335
Chris@288 1336 vector<QString> makers = factory->getTransformMakers(*i);
Chris@37 1337
Chris@33 1338 for (vector<QString>::iterator j = makers.begin();
Chris@33 1339 j != makers.end(); ++j) {
Chris@33 1340
Chris@33 1341 QString maker = *j;
Chris@33 1342 if (maker == "") maker = tr("Unknown");
Chris@55 1343 maker.replace(QRegExp(tr(" [\\(<].*$")), "");
Chris@55 1344
Chris@37 1345 makerMenus[*i][maker] = new SubdividingMenu(maker, 30, 40);
Chris@97 1346 makerMenus[*i][maker]->setTearOffEnabled(true);
Chris@37 1347 byMakerMenu->addMenu(makerMenus[*i][maker]);
Chris@37 1348 pendingMenus.insert(makerMenus[*i][maker]);
Chris@33 1349 }
Chris@0 1350 }
Chris@0 1351
Chris@230 1352 // Names should only be duplicated here if they have the same
Chris@230 1353 // plugin name, output name and maker but are in different library
Chris@230 1354 // .so names -- that won't happen often I hope
Chris@230 1355 std::map<QString, QString> idNameSonameMap;
Chris@230 1356 std::set<QString> seenNames, duplicateNames;
Chris@230 1357 for (unsigned int i = 0; i < transforms.size(); ++i) {
Chris@230 1358 QString name = transforms[i].name;
Chris@230 1359 if (seenNames.find(name) != seenNames.end()) {
Chris@230 1360 duplicateNames.insert(name);
Chris@230 1361 } else {
Chris@230 1362 seenNames.insert(name);
Chris@230 1363 }
Chris@230 1364 }
Chris@230 1365
Chris@0 1366 for (unsigned int i = 0; i < transforms.size(); ++i) {
Chris@0 1367
Chris@107 1368 QString name = transforms[i].name;
Chris@107 1369 if (name == "") name = transforms[i].identifier;
Chris@107 1370
Chris@107 1371 // std::cerr << "Plugin Name: " << name.toStdString() << std::endl;
Chris@80 1372
Chris@288 1373 TransformDescription::Type type = transforms[i].type;
Chris@288 1374 QString typeStr = factory->getTransformTypeName(type);
Chris@33 1375
Chris@33 1376 QString category = transforms[i].category;
Chris@33 1377 if (category == "") category = tr("Unclassified");
Chris@33 1378
Chris@33 1379 QString maker = transforms[i].maker;
Chris@33 1380 if (maker == "") maker = tr("Unknown");
Chris@55 1381 maker.replace(QRegExp(tr(" [\\(<].*$")), "");
Chris@33 1382
Chris@107 1383 QString pluginName = name.section(": ", 0, 0);
Chris@107 1384 QString output = name.section(": ", 1);
Chris@107 1385
Chris@230 1386 if (duplicateNames.find(pluginName) != duplicateNames.end()) {
Chris@230 1387 pluginName = QString("%1 <%2>")
Chris@230 1388 .arg(pluginName)
Chris@230 1389 .arg(transforms[i].identifier.section(':', 1, 1));
Chris@230 1390 if (output == "") name = pluginName;
Chris@230 1391 else name = QString("%1: %2")
Chris@230 1392 .arg(pluginName)
Chris@230 1393 .arg(output);
Chris@230 1394 }
Chris@230 1395
Chris@107 1396 QAction *action = new QAction(tr("%1...").arg(name), this);
Chris@0 1397 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@107 1398 m_transformActions[action] = transforms[i].identifier;
Chris@107 1399 m_transformActionsReverse[transforms[i].identifier] = action;
Chris@0 1400 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@33 1401
Chris@272 1402 action->setStatusTip(transforms[i].longDescription);
Chris@90 1403
Chris@33 1404 if (categoryMenus[type].find(category) == categoryMenus[type].end()) {
Chris@33 1405 std::cerr << "WARNING: MainWindow::setupMenus: Internal error: "
Chris@33 1406 << "No category menu for transform \""
Chris@107 1407 << name.toStdString() << "\" (category = \""
Chris@33 1408 << category.toStdString() << "\")" << std::endl;
Chris@33 1409 } else {
Chris@33 1410 categoryMenus[type][category]->addAction(action);
Chris@33 1411 }
Chris@33 1412
Chris@33 1413 if (makerMenus[type].find(maker) == makerMenus[type].end()) {
Chris@33 1414 std::cerr << "WARNING: MainWindow::setupMenus: Internal error: "
Chris@33 1415 << "No maker menu for transform \""
Chris@107 1416 << name.toStdString() << "\" (maker = \""
Chris@33 1417 << maker.toStdString() << "\")" << std::endl;
Chris@33 1418 } else {
Chris@80 1419 makerMenus[type][maker]->addAction(action);
Chris@33 1420 }
Chris@33 1421
Chris@33 1422 action = new QAction(tr("%1...").arg(output == "" ? pluginName : output), this);
Chris@33 1423 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@107 1424 m_transformActions[action] = transforms[i].identifier;
Chris@33 1425 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@272 1426 action->setStatusTip(transforms[i].longDescription);
Chris@33 1427
Chris@211 1428 // cerr << "Transform: \"" << name.toStdString() << "\": plugin name \"" << pluginName.toStdString() << "\"" << endl;
Chris@34 1429
Chris@33 1430 if (pluginNameMenus[type].find(pluginName) ==
Chris@33 1431 pluginNameMenus[type].end()) {
Chris@33 1432
Chris@36 1433 SubdividingMenu *parentMenu = byPluginNameMenus[type];
Chris@97 1434 parentMenu->setTearOffEnabled(true);
Chris@34 1435
Chris@33 1436 if (output == "") {
Chris@36 1437 parentMenu->addAction(pluginName, action);
Chris@33 1438 } else {
Chris@34 1439 pluginNameMenus[type][pluginName] =
Chris@34 1440 parentMenu->addMenu(pluginName);
Chris@33 1441 connect(this, SIGNAL(canAddLayer(bool)),
Chris@33 1442 pluginNameMenus[type][pluginName],
Chris@33 1443 SLOT(setEnabled(bool)));
Chris@33 1444 }
Chris@33 1445 }
Chris@33 1446
Chris@33 1447 if (pluginNameMenus[type].find(pluginName) !=
Chris@33 1448 pluginNameMenus[type].end()) {
Chris@33 1449 pluginNameMenus[type][pluginName]->addAction(action);
Chris@33 1450 }
Chris@0 1451 }
Chris@0 1452
Chris@37 1453 for (set<SubdividingMenu *>::iterator i = pendingMenus.begin();
Chris@37 1454 i != pendingMenus.end(); ++i) {
Chris@37 1455 (*i)->entriesAdded();
Chris@37 1456 }
Chris@37 1457
Chris@273 1458 m_transformsMenu->addSeparator();
Chris@273 1459 m_rightButtonTransformsMenu->addSeparator();
Chris@273 1460
Chris@273 1461 QAction *action = new QAction(tr("Find a Transform..."), this);
Chris@273 1462 action->setStatusTip(tr("Search for a transform from the installed plugins, by name or description"));
Chris@275 1463 action->setShortcut(tr("Ctrl+M"));
Chris@273 1464 connect(action, SIGNAL(triggered()), this, SLOT(findTransform()));
Chris@287 1465 // connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@275 1466 m_keyReference->registerShortcut(action);
Chris@273 1467 m_transformsMenu->addAction(action);
Chris@273 1468 m_rightButtonTransformsMenu->addAction(action);
Chris@273 1469
Chris@211 1470 setupRecentTransformsMenu();
Chris@66 1471 }
Chris@66 1472
Chris@66 1473 void
Chris@66 1474 MainWindow::setupHelpMenu()
Chris@66 1475 {
Chris@66 1476 QMenu *menu = menuBar()->addMenu(tr("&Help"));
Chris@97 1477 menu->setTearOffEnabled(true);
Chris@66 1478
Chris@162 1479 m_keyReference->setCategory(tr("Help"));
Chris@162 1480
Chris@168 1481 IconLoader il;
Chris@168 1482
Chris@168 1483 QAction *action = new QAction(il.load("help"),
Chris@138 1484 tr("&Help Reference"), this);
Chris@162 1485 action->setShortcut(tr("F1"));
Chris@66 1486 action->setStatusTip(tr("Open the Sonic Visualiser reference manual"));
Chris@66 1487 connect(action, SIGNAL(triggered()), this, SLOT(help()));
Chris@162 1488 m_keyReference->registerShortcut(action);
Chris@0 1489 menu->addAction(action);
Chris@162 1490
Chris@163 1491 action = new QAction(tr("&Key and Mouse Reference"), this);
Chris@162 1492 action->setShortcut(tr("F2"));
Chris@162 1493 action->setStatusTip(tr("Open a window showing the keystrokes you can use in Sonic Visualiser"));
Chris@162 1494 connect(action, SIGNAL(triggered()), this, SLOT(keyReference()));
Chris@162 1495 m_keyReference->registerShortcut(action);
Chris@162 1496 menu->addAction(action);
Chris@66 1497
Chris@164 1498 action = new QAction(tr("Sonic Visualiser on the &Web"), this);
Chris@164 1499 action->setStatusTip(tr("Open the Sonic Visualiser website"));
Chris@164 1500 connect(action, SIGNAL(triggered()), this, SLOT(website()));
Chris@164 1501 menu->addAction(action);
Chris@164 1502
Chris@66 1503 action = new QAction(tr("&About Sonic Visualiser"), this);
Chris@66 1504 action->setStatusTip(tr("Show information about Sonic Visualiser"));
Chris@66 1505 connect(action, SIGNAL(triggered()), this, SLOT(about()));
Chris@0 1506 menu->addAction(action);
Chris@0 1507 }
Chris@0 1508
Chris@0 1509 void
Chris@0 1510 MainWindow::setupRecentFilesMenu()
Chris@0 1511 {
Chris@0 1512 m_recentFilesMenu->clear();
Chris@34 1513 vector<QString> files = m_recentFiles.getRecent();
Chris@0 1514 for (size_t i = 0; i < files.size(); ++i) {
Chris@0 1515 QAction *action = new QAction(files[i], this);
Chris@0 1516 connect(action, SIGNAL(triggered()), this, SLOT(openRecentFile()));
Chris@162 1517 if (i == 0) {
Chris@162 1518 action->setShortcut(tr("Ctrl+R"));
Chris@162 1519 m_keyReference->registerShortcut
Chris@163 1520 (tr("Re-open"),
Chris@163 1521 action->shortcut(),
Chris@163 1522 tr("Re-open the current or most recently opened file"));
Chris@162 1523 }
Chris@0 1524 m_recentFilesMenu->addAction(action);
Chris@0 1525 }
Chris@0 1526 }
Chris@0 1527
Chris@0 1528 void
Chris@211 1529 MainWindow::setupRecentTransformsMenu()
Chris@34 1530 {
Chris@211 1531 m_recentTransformsMenu->clear();
Chris@211 1532 vector<QString> transforms = m_recentTransforms.getRecent();
Chris@34 1533 for (size_t i = 0; i < transforms.size(); ++i) {
Chris@211 1534 TransformActionReverseMap::iterator ti =
Chris@34 1535 m_transformActionsReverse.find(transforms[i]);
Chris@34 1536 if (ti == m_transformActionsReverse.end()) {
Chris@211 1537 std::cerr << "WARNING: MainWindow::setupRecentTransformsMenu: "
Chris@34 1538 << "Unknown transform \"" << transforms[i].toStdString()
Chris@34 1539 << "\" in recent transforms list" << std::endl;
Chris@34 1540 continue;
Chris@34 1541 }
Chris@162 1542 if (i == 0) {
Chris@162 1543 ti->second->setShortcut(tr("Ctrl+T"));
Chris@162 1544 m_keyReference->registerShortcut
Chris@211 1545 (tr("Repeat Transform"),
Chris@162 1546 ti->second->shortcut(),
Chris@163 1547 tr("Re-select the most recently run transform"));
Chris@216 1548 } else {
Chris@216 1549 ti->second->setShortcut(QString(""));
Chris@162 1550 }
Chris@211 1551 m_recentTransformsMenu->addAction(ti->second);
Chris@34 1552 }
Chris@34 1553 }
Chris@34 1554
Chris@34 1555 void
Chris@95 1556 MainWindow::setupExistingLayersMenus()
Chris@0 1557 {
Chris@0 1558 if (!m_existingLayersMenu) return; // should have been created by setupMenus
Chris@0 1559
Chris@0 1560 // std::cerr << "MainWindow::setupExistingLayersMenu" << std::endl;
Chris@0 1561
Chris@0 1562 m_existingLayersMenu->clear();
Chris@0 1563 m_existingLayerActions.clear();
Chris@0 1564
Chris@95 1565 m_sliceMenu->clear();
Chris@95 1566 m_sliceActions.clear();
Chris@95 1567
Chris@168 1568 IconLoader il;
Chris@168 1569
Chris@33 1570 vector<Layer *> orderedLayers;
Chris@33 1571 set<Layer *> observedLayers;
Chris@95 1572 set<Layer *> sliceableLayers;
Chris@95 1573
Chris@95 1574 LayerFactory *factory = LayerFactory::getInstance();
Chris@0 1575
Chris@0 1576 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@0 1577
Chris@0 1578 Pane *pane = m_paneStack->getPane(i);
Chris@0 1579 if (!pane) continue;
Chris@0 1580
Chris@0 1581 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@0 1582
Chris@0 1583 Layer *layer = pane->getLayer(j);
Chris@0 1584 if (!layer) continue;
Chris@0 1585 if (observedLayers.find(layer) != observedLayers.end()) {
Chris@137 1586 // std::cerr << "found duplicate layer " << layer << std::endl;
Chris@0 1587 continue;
Chris@0 1588 }
Chris@0 1589
Chris@0 1590 // std::cerr << "found new layer " << layer << " (name = "
Chris@0 1591 // << layer->getLayerPresentationName().toStdString() << ")" << std::endl;
Chris@0 1592
Chris@0 1593 orderedLayers.push_back(layer);
Chris@0 1594 observedLayers.insert(layer);
Chris@95 1595
Chris@95 1596 if (factory->isLayerSliceable(layer)) {
Chris@95 1597 sliceableLayers.insert(layer);
Chris@95 1598 }
Chris@0 1599 }
Chris@0 1600 }
Chris@0 1601
Chris@33 1602 map<QString, int> observedNames;
Chris@0 1603
Chris@137 1604 for (size_t i = 0; i < orderedLayers.size(); ++i) {
Chris@0 1605
Chris@95 1606 Layer *layer = orderedLayers[i];
Chris@95 1607
Chris@95 1608 QString name = layer->getLayerPresentationName();
Chris@0 1609 int n = ++observedNames[name];
Chris@0 1610 if (n > 1) name = QString("%1 <%2>").arg(name).arg(n);
Chris@0 1611
Chris@168 1612 QIcon icon = il.load(factory->getLayerIconName
Chris@168 1613 (factory->getLayerType(layer)));
Chris@95 1614
Chris@95 1615 QAction *action = new QAction(icon, name, this);
Chris@0 1616 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@0 1617 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@95 1618 m_existingLayerActions[action] = layer;
Chris@0 1619
Chris@0 1620 m_existingLayersMenu->addAction(action);
Chris@95 1621
Chris@95 1622 if (sliceableLayers.find(layer) != sliceableLayers.end()) {
Chris@95 1623 action = new QAction(icon, name, this);
Chris@95 1624 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@95 1625 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@95 1626 m_sliceActions[action] = layer;
Chris@95 1627 m_sliceMenu->addAction(action);
Chris@95 1628 }
Chris@0 1629 }
Chris@95 1630
Chris@95 1631 m_sliceMenu->setEnabled(!m_sliceActions.empty());
Chris@0 1632 }
Chris@0 1633
Chris@0 1634 void
Chris@0 1635 MainWindow::setupToolbars()
Chris@0 1636 {
Chris@162 1637 m_keyReference->setCategory(tr("Playback and Transport Controls"));
Chris@162 1638
Chris@168 1639 IconLoader il;
Chris@168 1640
Chris@155 1641 QMenu *menu = m_playbackMenu = menuBar()->addMenu(tr("Play&back"));
Chris@155 1642 menu->setTearOffEnabled(true);
Chris@155 1643 m_rightButtonMenu->addSeparator();
Chris@155 1644 m_rightButtonPlaybackMenu = m_rightButtonMenu->addMenu(tr("Playback"));
Chris@155 1645
Chris@155 1646 QToolBar *toolbar = addToolBar(tr("Playback Toolbar"));
Chris@155 1647
Chris@265 1648 m_rwdStartAction = toolbar->addAction(il.load("rewind-start"),
Chris@265 1649 tr("Rewind to Start"));
Chris@265 1650 m_rwdStartAction->setShortcut(tr("Home"));
Chris@265 1651 m_rwdStartAction->setStatusTip(tr("Rewind to the start"));
Chris@265 1652 connect(m_rwdStartAction, SIGNAL(triggered()), this, SLOT(rewindStart()));
Chris@265 1653 connect(this, SIGNAL(canPlay(bool)), m_rwdStartAction, SLOT(setEnabled(bool)));
Chris@265 1654
Chris@265 1655 m_rwdAction = toolbar->addAction(il.load("rewind"), tr("Rewind"));
Chris@155 1656 m_rwdAction->setShortcut(tr("PgUp"));
Chris@163 1657 m_rwdAction->setStatusTip(tr("Rewind to the previous time instant or time ruler notch"));
Chris@155 1658 connect(m_rwdAction, SIGNAL(triggered()), this, SLOT(rewind()));
Chris@155 1659 connect(this, SIGNAL(canRewind(bool)), m_rwdAction, SLOT(setEnabled(bool)));
Chris@155 1660
Chris@265 1661 m_playAction = toolbar->addAction(il.load("playpause"),
Chris@265 1662 tr("Play / Pause"));
Chris@265 1663 m_playAction->setCheckable(true);
Chris@265 1664 m_playAction->setShortcut(tr("Space"));
Chris@265 1665 m_playAction->setStatusTip(tr("Start or stop playback from the current position"));
Chris@265 1666 connect(m_playAction, SIGNAL(triggered()), this, SLOT(play()));
Chris@0 1667 connect(m_playSource, SIGNAL(playStatusChanged(bool)),
Chris@265 1668 m_playAction, SLOT(setChecked(bool)));
Chris@265 1669 connect(this, SIGNAL(canPlay(bool)), m_playAction, SLOT(setEnabled(bool)));
Chris@155 1670
Chris@168 1671 m_ffwdAction = toolbar->addAction(il.load("ffwd"),
Chris@286 1672 tr("Fast Forward"));
Chris@155 1673 m_ffwdAction->setShortcut(tr("PgDown"));
Chris@163 1674 m_ffwdAction->setStatusTip(tr("Fast-forward to the next time instant or time ruler notch"));
Chris@155 1675 connect(m_ffwdAction, SIGNAL(triggered()), this, SLOT(ffwd()));
Chris@155 1676 connect(this, SIGNAL(canFfwd(bool)), m_ffwdAction, SLOT(setEnabled(bool)));
Chris@155 1677
Chris@265 1678 m_ffwdEndAction = toolbar->addAction(il.load("ffwd-end"),
Chris@265 1679 tr("Fast Forward to End"));
Chris@265 1680 m_ffwdEndAction->setShortcut(tr("End"));
Chris@265 1681 m_ffwdEndAction->setStatusTip(tr("Fast-forward to the end"));
Chris@265 1682 connect(m_ffwdEndAction, SIGNAL(triggered()), this, SLOT(ffwdEnd()));
Chris@265 1683 connect(this, SIGNAL(canPlay(bool)), m_ffwdEndAction, SLOT(setEnabled(bool)));
Chris@0 1684
Chris@0 1685 toolbar = addToolBar(tr("Play Mode Toolbar"));
Chris@0 1686
Chris@265 1687 m_playSelectionAction = toolbar->addAction(il.load("playselection"),
Chris@265 1688 tr("Constrain Playback to Selection"));
Chris@265 1689 m_playSelectionAction->setCheckable(true);
Chris@265 1690 m_playSelectionAction->setChecked(m_viewManager->getPlaySelectionMode());
Chris@265 1691 m_playSelectionAction->setShortcut(tr("s"));
Chris@265 1692 m_playSelectionAction->setStatusTip(tr("Constrain playback to the selected regions"));
Chris@69 1693 connect(m_viewManager, SIGNAL(playSelectionModeChanged(bool)),
Chris@265 1694 m_playSelectionAction, SLOT(setChecked(bool)));
Chris@265 1695 connect(m_playSelectionAction, SIGNAL(triggered()), this, SLOT(playSelectionToggled()));
Chris@265 1696 connect(this, SIGNAL(canPlaySelection(bool)), m_playSelectionAction, SLOT(setEnabled(bool)));
Chris@265 1697
Chris@265 1698 m_playLoopAction = toolbar->addAction(il.load("playloop"),
Chris@265 1699 tr("Loop Playback"));
Chris@265 1700 m_playLoopAction->setCheckable(true);
Chris@265 1701 m_playLoopAction->setChecked(m_viewManager->getPlayLoopMode());
Chris@265 1702 m_playLoopAction->setShortcut(tr("l"));
Chris@265 1703 m_playLoopAction->setStatusTip(tr("Loop playback"));
Chris@69 1704 connect(m_viewManager, SIGNAL(playLoopModeChanged(bool)),
Chris@265 1705 m_playLoopAction, SLOT(setChecked(bool)));
Chris@265 1706 connect(m_playLoopAction, SIGNAL(triggered()), this, SLOT(playLoopToggled()));
Chris@265 1707 connect(this, SIGNAL(canPlay(bool)), m_playLoopAction, SLOT(setEnabled(bool)));
Chris@155 1708
Chris@207 1709 m_soloAction = toolbar->addAction(il.load("solo"),
Chris@180 1710 tr("Solo Current Pane"));
Chris@207 1711 m_soloAction->setCheckable(true);
Chris@207 1712 m_soloAction->setChecked(m_viewManager->getPlaySoloMode());
Chris@207 1713 m_prevSolo = m_viewManager->getPlaySoloMode();
Chris@207 1714 m_soloAction->setShortcut(tr("o"));
Chris@207 1715 m_soloAction->setStatusTip(tr("Solo the current pane during playback"));
Chris@180 1716 connect(m_viewManager, SIGNAL(playSoloModeChanged(bool)),
Chris@207 1717 m_soloAction, SLOT(setChecked(bool)));
Chris@207 1718 connect(m_soloAction, SIGNAL(triggered()), this, SLOT(playSoloToggled()));
Chris@207 1719 connect(this, SIGNAL(canChangeSolo(bool)), m_soloAction, SLOT(setEnabled(bool)));
Chris@180 1720
Chris@208 1721 QAction *alAction = 0;
Chris@208 1722 if (Document::canAlign()) {
Chris@208 1723 alAction = toolbar->addAction(il.load("align"),
Chris@208 1724 tr("Align File Timelines"));
Chris@208 1725 alAction->setCheckable(true);
Chris@208 1726 alAction->setChecked(m_viewManager->getAlignMode());
Chris@208 1727 alAction->setStatusTip(tr("Treat multiple audio files as versions of the same work, and align their timelines"));
Chris@208 1728 connect(m_viewManager, SIGNAL(alignModeChanged(bool)),
Chris@208 1729 alAction, SLOT(setChecked(bool)));
Chris@208 1730 connect(alAction, SIGNAL(triggered()), this, SLOT(alignToggled()));
Chris@208 1731 connect(this, SIGNAL(canAlign(bool)), alAction, SLOT(setEnabled(bool)));
Chris@208 1732 }
Chris@206 1733
Chris@265 1734 m_keyReference->registerShortcut(m_playAction);
Chris@265 1735 m_keyReference->registerShortcut(m_playSelectionAction);
Chris@265 1736 m_keyReference->registerShortcut(m_playLoopAction);
Chris@207 1737 m_keyReference->registerShortcut(m_soloAction);
Chris@208 1738 if (alAction) m_keyReference->registerShortcut(alAction);
Chris@162 1739 m_keyReference->registerShortcut(m_rwdAction);
Chris@162 1740 m_keyReference->registerShortcut(m_ffwdAction);
Chris@265 1741 m_keyReference->registerShortcut(m_rwdStartAction);
Chris@265 1742 m_keyReference->registerShortcut(m_ffwdEndAction);
Chris@265 1743
Chris@265 1744 menu->addAction(m_playAction);
Chris@265 1745 menu->addAction(m_playSelectionAction);
Chris@265 1746 menu->addAction(m_playLoopAction);
Chris@207 1747 menu->addAction(m_soloAction);
Chris@208 1748 if (alAction) menu->addAction(alAction);
Chris@155 1749 menu->addSeparator();
Chris@155 1750 menu->addAction(m_rwdAction);
Chris@155 1751 menu->addAction(m_ffwdAction);
Chris@155 1752 menu->addSeparator();
Chris@265 1753 menu->addAction(m_rwdStartAction);
Chris@265 1754 menu->addAction(m_ffwdEndAction);
Chris@155 1755 menu->addSeparator();
Chris@155 1756
Chris@265 1757 m_rightButtonPlaybackMenu->addAction(m_playAction);
Chris@265 1758 m_rightButtonPlaybackMenu->addAction(m_playSelectionAction);
Chris@265 1759 m_rightButtonPlaybackMenu->addAction(m_playLoopAction);
Chris@207 1760 m_rightButtonPlaybackMenu->addAction(m_soloAction);
Chris@208 1761 if (alAction) m_rightButtonPlaybackMenu->addAction(alAction);
Chris@155 1762 m_rightButtonPlaybackMenu->addSeparator();
Chris@155 1763 m_rightButtonPlaybackMenu->addAction(m_rwdAction);
Chris@155 1764 m_rightButtonPlaybackMenu->addAction(m_ffwdAction);
Chris@155 1765 m_rightButtonPlaybackMenu->addSeparator();
Chris@265 1766 m_rightButtonPlaybackMenu->addAction(m_rwdStartAction);
Chris@265 1767 m_rightButtonPlaybackMenu->addAction(m_ffwdEndAction);
Chris@155 1768 m_rightButtonPlaybackMenu->addSeparator();
Chris@155 1769
Chris@155 1770 QAction *fastAction = menu->addAction(tr("Speed Up"));
Chris@155 1771 fastAction->setShortcut(tr("Ctrl+PgUp"));
Chris@163 1772 fastAction->setStatusTip(tr("Time-stretch playback to speed it up without changing pitch"));
Chris@155 1773 connect(fastAction, SIGNAL(triggered()), this, SLOT(speedUpPlayback()));
Chris@155 1774 connect(this, SIGNAL(canSpeedUpPlayback(bool)), fastAction, SLOT(setEnabled(bool)));
Chris@155 1775
Chris@155 1776 QAction *slowAction = menu->addAction(tr("Slow Down"));
Chris@155 1777 slowAction->setShortcut(tr("Ctrl+PgDown"));
Chris@163 1778 slowAction->setStatusTip(tr("Time-stretch playback to slow it down without changing pitch"));
Chris@155 1779 connect(slowAction, SIGNAL(triggered()), this, SLOT(slowDownPlayback()));
Chris@155 1780 connect(this, SIGNAL(canSlowDownPlayback(bool)), slowAction, SLOT(setEnabled(bool)));
Chris@155 1781
Chris@155 1782 QAction *normalAction = menu->addAction(tr("Restore Normal Speed"));
Chris@155 1783 normalAction->setShortcut(tr("Ctrl+Home"));
Chris@163 1784 normalAction->setStatusTip(tr("Restore non-time-stretched playback"));
Chris@155 1785 connect(normalAction, SIGNAL(triggered()), this, SLOT(restoreNormalPlayback()));
Chris@155 1786 connect(this, SIGNAL(canChangePlaybackSpeed(bool)), normalAction, SLOT(setEnabled(bool)));
Chris@155 1787
Chris@162 1788 m_keyReference->registerShortcut(fastAction);
Chris@162 1789 m_keyReference->registerShortcut(slowAction);
Chris@162 1790 m_keyReference->registerShortcut(normalAction);
Chris@162 1791
Chris@155 1792 m_rightButtonPlaybackMenu->addAction(fastAction);
Chris@155 1793 m_rightButtonPlaybackMenu->addAction(slowAction);
Chris@155 1794 m_rightButtonPlaybackMenu->addAction(normalAction);
Chris@0 1795
Chris@0 1796 toolbar = addToolBar(tr("Edit Toolbar"));
Chris@0 1797 CommandHistory::getInstance()->registerToolbar(toolbar);
Chris@0 1798
Chris@162 1799 m_keyReference->setCategory(tr("Tool Selection"));
Chris@162 1800
Chris@0 1801 toolbar = addToolBar(tr("Tools Toolbar"));
Chris@0 1802 QActionGroup *group = new QActionGroup(this);
Chris@0 1803
Chris@168 1804 QAction *action = toolbar->addAction(il.load("navigate"),
Chris@155 1805 tr("Navigate"));
Chris@0 1806 action->setCheckable(true);
Chris@0 1807 action->setChecked(true);
Chris@0 1808 action->setShortcut(tr("1"));
Chris@90 1809 action->setStatusTip(tr("Navigate"));
Chris@0 1810 connect(action, SIGNAL(triggered()), this, SLOT(toolNavigateSelected()));
Chris@0 1811 group->addAction(action);
Chris@162 1812 m_keyReference->registerShortcut(action);
Chris@0 1813 m_toolActions[ViewManager::NavigateMode] = action;
Chris@0 1814
Chris@168 1815 action = toolbar->addAction(il.load("select"),
Chris@0 1816 tr("Select"));
Chris@0 1817 action->setCheckable(true);
Chris@0 1818 action->setShortcut(tr("2"));
Chris@90 1819 action->setStatusTip(tr("Select ranges"));
Chris@0 1820 connect(action, SIGNAL(triggered()), this, SLOT(toolSelectSelected()));
Chris@0 1821 group->addAction(action);
Chris@162 1822 m_keyReference->registerShortcut(action);
Chris@0 1823 m_toolActions[ViewManager::SelectMode] = action;
Chris@0 1824
Chris@168 1825 action = toolbar->addAction(il.load("move"),
Chris@0 1826 tr("Edit"));
Chris@0 1827 action->setCheckable(true);
Chris@0 1828 action->setShortcut(tr("3"));
Chris@90 1829 action->setStatusTip(tr("Edit items in layer"));
Chris@0 1830 connect(action, SIGNAL(triggered()), this, SLOT(toolEditSelected()));
Chris@0 1831 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1832 group->addAction(action);
Chris@162 1833 m_keyReference->registerShortcut(action);
Chris@0 1834 m_toolActions[ViewManager::EditMode] = action;
Chris@0 1835
Chris@168 1836 action = toolbar->addAction(il.load("draw"),
Chris@0 1837 tr("Draw"));
Chris@0 1838 action->setCheckable(true);
Chris@0 1839 action->setShortcut(tr("4"));
Chris@90 1840 action->setStatusTip(tr("Draw new items in layer"));
Chris@0 1841 connect(action, SIGNAL(triggered()), this, SLOT(toolDrawSelected()));
Chris@0 1842 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1843 group->addAction(action);
Chris@162 1844 m_keyReference->registerShortcut(action);
Chris@0 1845 m_toolActions[ViewManager::DrawMode] = action;
Chris@0 1846
Chris@217 1847 action = toolbar->addAction(il.load("erase"),
Chris@217 1848 tr("Erase"));
Chris@217 1849 action->setCheckable(true);
Chris@217 1850 action->setShortcut(tr("5"));
Chris@217 1851 action->setStatusTip(tr("Erase items from layer"));
Chris@217 1852 connect(action, SIGNAL(triggered()), this, SLOT(toolEraseSelected()));
Chris@217 1853 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@217 1854 group->addAction(action);
Chris@217 1855 m_keyReference->registerShortcut(action);
Chris@217 1856 m_toolActions[ViewManager::EraseMode] = action;
Chris@217 1857
Chris@265 1858 action = toolbar->addAction(il.load("measure"), tr("Measure"));
Chris@151 1859 action->setCheckable(true);
Chris@217 1860 action->setShortcut(tr("6"));
Chris@151 1861 action->setStatusTip(tr("Make measurements in layer"));
Chris@151 1862 connect(action, SIGNAL(triggered()), this, SLOT(toolMeasureSelected()));
Chris@169 1863 connect(this, SIGNAL(canMeasureLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@151 1864 group->addAction(action);
Chris@162 1865 m_keyReference->registerShortcut(action);
Chris@151 1866 m_toolActions[ViewManager::MeasureMode] = action;
Chris@151 1867
Chris@0 1868 toolNavigateSelected();
Chris@163 1869
Chris@163 1870 Pane::registerShortcuts(*m_keyReference);
Chris@0 1871 }
Chris@0 1872
Chris@0 1873 void
Chris@265 1874 MainWindow::connectLayerEditDialog(ModelDataTableDialog *dialog)
Chris@265 1875 {
Chris@265 1876 MainWindowBase::connectLayerEditDialog(dialog);
Chris@265 1877 QToolBar *toolbar = dialog->getPlayToolbar();
Chris@265 1878 if (toolbar) {
Chris@265 1879 toolbar->addAction(m_rwdStartAction);
Chris@265 1880 toolbar->addAction(m_rwdAction);
Chris@265 1881 toolbar->addAction(m_playAction);
Chris@265 1882 toolbar->addAction(m_ffwdAction);
Chris@265 1883 toolbar->addAction(m_ffwdEndAction);
Chris@265 1884 }
Chris@265 1885 }
Chris@265 1886
Chris@265 1887 void
Chris@0 1888 MainWindow::updateMenuStates()
Chris@0 1889 {
Chris@200 1890 MainWindowBase::updateMenuStates();
Chris@200 1891
Chris@117 1892 Pane *currentPane = 0;
Chris@117 1893 Layer *currentLayer = 0;
Chris@117 1894
Chris@117 1895 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
Chris@117 1896 if (currentPane) currentLayer = currentPane->getSelectedLayer();
Chris@117 1897
Chris@0 1898 bool haveCurrentPane =
Chris@117 1899 (currentPane != 0);
Chris@0 1900 bool haveCurrentLayer =
Chris@117 1901 (haveCurrentPane &&
Chris@117 1902 (currentLayer != 0));
Chris@206 1903 bool havePlayTarget =
Chris@206 1904 (m_playTarget != 0);
Chris@0 1905 bool haveSelection =
Chris@0 1906 (m_viewManager &&
Chris@0 1907 !m_viewManager->getSelections().empty());
Chris@0 1908 bool haveCurrentEditableLayer =
Chris@0 1909 (haveCurrentLayer &&
Chris@117 1910 currentLayer->isLayerEditable());
Chris@0 1911 bool haveCurrentTimeInstantsLayer =
Chris@0 1912 (haveCurrentLayer &&
Chris@117 1913 dynamic_cast<TimeInstantLayer *>(currentLayer));
Chris@0 1914 bool haveCurrentTimeValueLayer =
Chris@0 1915 (haveCurrentLayer &&
Chris@117 1916 dynamic_cast<TimeValueLayer *>(currentLayer));
Chris@207 1917
Chris@207 1918 emit canChangeSolo(havePlayTarget);
Chris@207 1919 emit canAlign(havePlayTarget && m_document && m_document->canAlign());
Chris@206 1920
Chris@200 1921 emit canChangePlaybackSpeed(true);
Chris@200 1922 int v = m_playSpeed->value();
Chris@200 1923 emit canSpeedUpPlayback(v < m_playSpeed->maximum());
Chris@200 1924 emit canSlowDownPlayback(v > m_playSpeed->minimum());
Chris@155 1925
Chris@164 1926 if (m_viewManager &&
Chris@164 1927 (m_viewManager->getToolMode() == ViewManager::MeasureMode)) {
Chris@164 1928 emit canDeleteSelection(haveCurrentLayer);
Chris@164 1929 m_deleteSelectedAction->setText(tr("&Delete Current Measurement"));
Chris@164 1930 m_deleteSelectedAction->setStatusTip(tr("Delete the measurement currently under the mouse pointer"));
Chris@164 1931 } else {
Chris@164 1932 emit canDeleteSelection(haveSelection && haveCurrentEditableLayer);
Chris@164 1933 m_deleteSelectedAction->setText(tr("&Delete Selected Items"));
Chris@164 1934 m_deleteSelectedAction->setStatusTip(tr("Delete items in current selection from the current layer"));
Chris@164 1935 }
Chris@164 1936
Chris@155 1937 if (m_ffwdAction && m_rwdAction) {
Chris@155 1938 if (haveCurrentTimeInstantsLayer) {
Chris@155 1939 m_ffwdAction->setText(tr("Fast Forward to Next Instant"));
Chris@155 1940 m_ffwdAction->setStatusTip(tr("Fast forward to the next time instant in the current layer"));
Chris@155 1941 m_rwdAction->setText(tr("Rewind to Previous Instant"));
Chris@155 1942 m_rwdAction->setStatusTip(tr("Rewind to the previous time instant in the current layer"));
Chris@155 1943 } else if (haveCurrentTimeValueLayer) {
Chris@155 1944 m_ffwdAction->setText(tr("Fast Forward to Next Point"));
Chris@155 1945 m_ffwdAction->setStatusTip(tr("Fast forward to the next point in the current layer"));
Chris@155 1946 m_rwdAction->setText(tr("Rewind to Previous Point"));
Chris@155 1947 m_rwdAction->setStatusTip(tr("Rewind to the previous point in the current layer"));
Chris@155 1948 } else {
Chris@155 1949 m_ffwdAction->setText(tr("Fast Forward"));
Chris@155 1950 m_ffwdAction->setStatusTip(tr("Fast forward"));
Chris@155 1951 m_rwdAction->setText(tr("Rewind"));
Chris@155 1952 m_rwdAction->setStatusTip(tr("Rewind"));
Chris@155 1953 }
Chris@155 1954 }
Chris@0 1955 }
Chris@0 1956
Chris@0 1957 void
Chris@0 1958 MainWindow::updateDescriptionLabel()
Chris@0 1959 {
Chris@0 1960 if (!getMainModel()) {
Chris@0 1961 m_descriptionLabel->setText(tr("No audio file loaded."));
Chris@0 1962 return;
Chris@0 1963 }
Chris@0 1964
Chris@0 1965 QString description;
Chris@0 1966
Chris@0 1967 size_t ssr = getMainModel()->getSampleRate();
Chris@0 1968 size_t tsr = ssr;
Chris@0 1969 if (m_playSource) tsr = m_playSource->getTargetSampleRate();
Chris@0 1970
Chris@0 1971 if (ssr != tsr) {
Chris@0 1972 description = tr("%1Hz (resampling to %2Hz)").arg(ssr).arg(tsr);
Chris@0 1973 } else {
Chris@0 1974 description = QString("%1Hz").arg(ssr);
Chris@0 1975 }
Chris@0 1976
Chris@0 1977 description = QString("%1 - %2")
Chris@0 1978 .arg(RealTime::frame2RealTime(getMainModel()->getEndFrame(), ssr)
Chris@0 1979 .toText(false).c_str())
Chris@0 1980 .arg(description);
Chris@0 1981
Chris@0 1982 m_descriptionLabel->setText(description);
Chris@0 1983 }
Chris@0 1984
Chris@0 1985 void
Chris@0 1986 MainWindow::documentModified()
Chris@0 1987 {
Chris@200 1988 //!!!
Chris@200 1989 MainWindowBase::documentModified();
Chris@0 1990 }
Chris@0 1991
Chris@0 1992 void
Chris@0 1993 MainWindow::documentRestored()
Chris@0 1994 {
Chris@200 1995 //!!!
Chris@200 1996 MainWindowBase::documentRestored();
Chris@0 1997 }
Chris@0 1998
Chris@0 1999 void
Chris@0 2000 MainWindow::toolNavigateSelected()
Chris@0 2001 {
Chris@0 2002 m_viewManager->setToolMode(ViewManager::NavigateMode);
Chris@0 2003 }
Chris@0 2004
Chris@0 2005 void
Chris@0 2006 MainWindow::toolSelectSelected()
Chris@0 2007 {
Chris@0 2008 m_viewManager->setToolMode(ViewManager::SelectMode);
Chris@0 2009 }
Chris@0 2010
Chris@0 2011 void
Chris@0 2012 MainWindow::toolEditSelected()
Chris@0 2013 {
Chris@0 2014 m_viewManager->setToolMode(ViewManager::EditMode);
Chris@0 2015 }
Chris@0 2016
Chris@0 2017 void
Chris@0 2018 MainWindow::toolDrawSelected()
Chris@0 2019 {
Chris@0 2020 m_viewManager->setToolMode(ViewManager::DrawMode);
Chris@0 2021 }
Chris@0 2022
Chris@151 2023 void
Chris@217 2024 MainWindow::toolEraseSelected()
Chris@217 2025 {
Chris@217 2026 m_viewManager->setToolMode(ViewManager::EraseMode);
Chris@217 2027 }
Chris@217 2028
Chris@217 2029 void
Chris@151 2030 MainWindow::toolMeasureSelected()
Chris@151 2031 {
Chris@151 2032 m_viewManager->setToolMode(ViewManager::MeasureMode);
Chris@151 2033 }
Chris@151 2034
Chris@0 2035 void
Chris@0 2036 MainWindow::importAudio()
Chris@0 2037 {
Chris@88 2038 QString path = getOpenFileName(FileFinder::AudioFile);
Chris@0 2039
Chris@0 2040 if (path != "") {
Chris@197 2041 if (openAudio(path, ReplaceMainModel) == FileOpenFailed) {
Chris@247 2042 emit hideSplash();
Chris@0 2043 QMessageBox::critical(this, tr("Failed to open file"),
Chris@193 2044 tr("<b>File open failed</b><p>Audio file \"%1\" could not be opened").arg(path));
Chris@0 2045 }
Chris@0 2046 }
Chris@0 2047 }
Chris@0 2048
Chris@0 2049 void
Chris@0 2050 MainWindow::importMoreAudio()
Chris@0 2051 {
Chris@88 2052 QString path = getOpenFileName(FileFinder::AudioFile);
Chris@0 2053
Chris@0 2054 if (path != "") {
Chris@197 2055 if (openAudio(path, CreateAdditionalModel) == FileOpenFailed) {
Chris@247 2056 emit hideSplash();
Chris@0 2057 QMessageBox::critical(this, tr("Failed to open file"),
Chris@193 2058 tr("<b>File open failed</b><p>Audio file \"%1\" could not be opened").arg(path));
Chris@0 2059 }
Chris@0 2060 }
Chris@0 2061 }
Chris@0 2062
Chris@0 2063 void
Chris@0 2064 MainWindow::exportAudio()
Chris@0 2065 {
Chris@0 2066 if (!getMainModel()) return;
Chris@0 2067
Chris@88 2068 QString path = getSaveFileName(FileFinder::AudioFile);
Chris@0 2069
Chris@0 2070 if (path == "") return;
Chris@0 2071
Chris@0 2072 bool ok = false;
Chris@0 2073 QString error;
Chris@0 2074
Chris@0 2075 MultiSelection ms = m_viewManager->getSelection();
Chris@0 2076 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@0 2077
Chris@0 2078 bool multiple = false;
Chris@0 2079
Chris@38 2080 MultiSelection *selectionToWrite = 0;
Chris@38 2081
Chris@38 2082 if (selections.size() == 1) {
Chris@0 2083
Chris@0 2084 QStringList items;
Chris@0 2085 items << tr("Export the selected region only")
Chris@0 2086 << tr("Export the whole audio file");
Chris@0 2087
Chris@0 2088 bool ok = false;
Chris@0 2089 QString item = ListInputDialog::getItem
Chris@0 2090 (this, tr("Select region to export"),
Chris@0 2091 tr("Which region from the original audio file do you want to export?"),
Chris@0 2092 items, 0, &ok);
Chris@0 2093
Chris@0 2094 if (!ok || item.isEmpty()) return;
Chris@0 2095
Chris@38 2096 if (item == items[0]) selectionToWrite = &ms;
Chris@38 2097
Chris@38 2098 } else if (selections.size() > 1) {
Chris@0 2099
Chris@0 2100 QStringList items;
Chris@0 2101 items << tr("Export the selected regions into a single audio file")
Chris@0 2102 << tr("Export the selected regions into separate files")
Chris@0 2103 << tr("Export the whole audio file");
Chris@0 2104
Chris@0 2105 QString item = ListInputDialog::getItem
Chris@0 2106 (this, tr("Select region to export"),
Chris@0 2107 tr("Multiple regions of the original audio file are selected.\nWhat do you want to export?"),
Chris@0 2108 items, 0, &ok);
Chris@0 2109
Chris@0 2110 if (!ok || item.isEmpty()) return;
Chris@0 2111
Chris@0 2112 if (item == items[0]) {
Chris@0 2113
Chris@38 2114 selectionToWrite = &ms;
Chris@38 2115
Chris@38 2116 } else if (item == items[1]) {
Chris@0 2117
Chris@0 2118 multiple = true;
Chris@0 2119
Chris@0 2120 int n = 1;
Chris@0 2121 QString base = path;
Chris@0 2122 base.replace(".wav", "");
Chris@0 2123
Chris@0 2124 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@0 2125 i != selections.end(); ++i) {
Chris@0 2126
Chris@0 2127 MultiSelection subms;
Chris@0 2128 subms.setSelection(*i);
Chris@0 2129
Chris@0 2130 QString subpath = QString("%1.%2.wav").arg(base).arg(n);
Chris@0 2131 ++n;
Chris@0 2132
Chris@0 2133 if (QFileInfo(subpath).exists()) {
Chris@0 2134 error = tr("Fragment file %1 already exists, aborting").arg(subpath);
Chris@0 2135 break;
Chris@0 2136 }
Chris@0 2137
Chris@38 2138 WavFileWriter subwriter(subpath,
Chris@38 2139 getMainModel()->getSampleRate(),
Chris@38 2140 getMainModel()->getChannelCount());
Chris@38 2141 subwriter.writeModel(getMainModel(), &subms);
Chris@0 2142 ok = subwriter.isOK();
Chris@0 2143
Chris@0 2144 if (!ok) {
Chris@0 2145 error = subwriter.getError();
Chris@0 2146 break;
Chris@0 2147 }
Chris@0 2148 }
Chris@0 2149 }
Chris@0 2150 }
Chris@0 2151
Chris@38 2152 if (!multiple) {
Chris@38 2153 WavFileWriter writer(path,
Chris@38 2154 getMainModel()->getSampleRate(),
Chris@38 2155 getMainModel()->getChannelCount());
Chris@38 2156 writer.writeModel(getMainModel(), selectionToWrite);
Chris@38 2157 ok = writer.isOK();
Chris@38 2158 error = writer.getError();
Chris@0 2159 }
Chris@0 2160
Chris@0 2161 if (ok) {
Chris@0 2162 if (!multiple) {
Chris@34 2163 m_recentFiles.addFile(path);
Chris@0 2164 }
Chris@0 2165 } else {
Chris@0 2166 QMessageBox::critical(this, tr("Failed to write file"), error);
Chris@0 2167 }
Chris@0 2168 }
Chris@0 2169
Chris@0 2170 void
Chris@0 2171 MainWindow::importLayer()
Chris@0 2172 {
Chris@0 2173 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 2174
Chris@0 2175 if (!pane) {
Chris@0 2176 // shouldn't happen, as the menu action should have been disabled
Chris@0 2177 std::cerr << "WARNING: MainWindow::importLayer: no current pane" << std::endl;
Chris@0 2178 return;
Chris@0 2179 }
Chris@0 2180
Chris@0 2181 if (!getMainModel()) {
Chris@0 2182 // shouldn't happen, as the menu action should have been disabled
Chris@0 2183 std::cerr << "WARNING: MainWindow::importLayer: No main model -- hence no default sample rate available" << std::endl;
Chris@0 2184 return;
Chris@0 2185 }
Chris@0 2186
Chris@88 2187 QString path = getOpenFileName(FileFinder::LayerFile);
Chris@0 2188
Chris@0 2189 if (path != "") {
Chris@0 2190
Chris@197 2191 FileOpenStatus status = openLayer(path);
Chris@193 2192
Chris@193 2193 if (status == FileOpenFailed) {
Chris@247 2194 emit hideSplash();
Chris@0 2195 QMessageBox::critical(this, tr("Failed to open file"),
Chris@193 2196 tr("<b>File open failed</b><p>Layer file %1 could not be opened.").arg(path));
Chris@0 2197 return;
Chris@193 2198 } else if (status == FileOpenWrongMode) {
Chris@247 2199 emit hideSplash();
Chris@193 2200 QMessageBox::critical(this, tr("Failed to open file"),
Chris@294 2201 tr("<b>Audio required</b><p>Unable to load layer data from \"%1\" without an audio file.<br>Please load at least one audio file before importing annotations.").arg(path));
Chris@0 2202 }
Chris@0 2203 }
Chris@0 2204 }
Chris@0 2205
Chris@0 2206 void
Chris@0 2207 MainWindow::exportLayer()
Chris@0 2208 {
Chris@0 2209 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 2210 if (!pane) return;
Chris@0 2211
Chris@0 2212 Layer *layer = pane->getSelectedLayer();
Chris@0 2213 if (!layer) return;
Chris@0 2214
Chris@0 2215 Model *model = layer->getModel();
Chris@0 2216 if (!model) return;
Chris@0 2217
Chris@185 2218 FileFinder::FileType type = FileFinder::LayerFileNoMidi;
Chris@185 2219
Chris@185 2220 if (dynamic_cast<NoteModel *>(model)) type = FileFinder::LayerFile;
Chris@185 2221
Chris@185 2222 QString path = getSaveFileName(type);
Chris@0 2223
Chris@0 2224 if (path == "") return;
Chris@0 2225
Chris@0 2226 if (QFileInfo(path).suffix() == "") path += ".svl";
Chris@0 2227
Chris@185 2228 QString suffix = QFileInfo(path).suffix().toLower();
Chris@185 2229
Chris@0 2230 QString error;
Chris@0 2231
Chris@185 2232 if (suffix == "xml" || suffix == "svl") {
Chris@0 2233
Chris@0 2234 QFile file(path);
Chris@0 2235 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
Chris@0 2236 error = tr("Failed to open file %1 for writing").arg(path);
Chris@0 2237 } else {
Chris@0 2238 QTextStream out(&file);
Chris@0 2239 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
Chris@0 2240 << "<!DOCTYPE sonic-visualiser>\n"
Chris@0 2241 << "<sv>\n"
Chris@0 2242 << " <data>\n";
Chris@0 2243
Chris@0 2244 model->toXml(out, " ");
Chris@0 2245
Chris@0 2246 out << " </data>\n"
Chris@0 2247 << " <display>\n";
Chris@0 2248
Chris@0 2249 layer->toXml(out, " ");
Chris@0 2250
Chris@0 2251 out << " </display>\n"
Chris@0 2252 << "</sv>\n";
Chris@0 2253 }
Chris@0 2254
Chris@185 2255 } else if (suffix == "mid" || suffix == "midi") {
Chris@185 2256
Chris@185 2257 NoteModel *nm = dynamic_cast<NoteModel *>(model);
Chris@185 2258
Chris@185 2259 if (!nm) {
Chris@185 2260 error = tr("Can't export non-note layers to MIDI");
Chris@185 2261 } else {
Chris@185 2262 MIDIFileWriter writer(path, nm);
Chris@185 2263 writer.write();
Chris@185 2264 if (!writer.isOK()) {
Chris@185 2265 error = writer.getError();
Chris@185 2266 }
Chris@185 2267 }
Chris@185 2268
Chris@291 2269 } else if (suffix == "ttl" || suffix == "n3") {
Chris@291 2270
Chris@291 2271 RDFExporter exporter(path, model);
Chris@291 2272 exporter.write();
Chris@291 2273 if (!exporter.isOK()) {
Chris@291 2274 error = exporter.getError();
Chris@291 2275 }
Chris@291 2276
Chris@0 2277 } else {
Chris@0 2278
Chris@0 2279 CSVFileWriter writer(path, model,
Chris@185 2280 ((suffix == "csv") ? "," : "\t"));
Chris@0 2281 writer.write();
Chris@0 2282
Chris@0 2283 if (!writer.isOK()) {
Chris@0 2284 error = writer.getError();
Chris@0 2285 }
Chris@0 2286 }
Chris@0 2287
Chris@0 2288 if (error != "") {
Chris@0 2289 QMessageBox::critical(this, tr("Failed to write file"), error);
Chris@0 2290 } else {
Chris@34 2291 m_recentFiles.addFile(path);
Chris@0 2292 }
Chris@0 2293 }
Chris@0 2294
Chris@121 2295 void
Chris@121 2296 MainWindow::exportImage()
Chris@121 2297 {
Chris@121 2298 Pane *pane = m_paneStack->getCurrentPane();
Chris@121 2299 if (!pane) return;
Chris@121 2300
Chris@121 2301 QString path = getSaveFileName(FileFinder::ImageFile);
Chris@121 2302
Chris@121 2303 if (path == "") return;
Chris@121 2304
Chris@121 2305 if (QFileInfo(path).suffix() == "") path += ".png";
Chris@121 2306
Chris@123 2307 bool haveSelection = m_viewManager && !m_viewManager->getSelections().empty();
Chris@123 2308
Chris@123 2309 QSize total, visible, selected;
Chris@123 2310 total = pane->getImageSize();
Chris@123 2311 visible = pane->getImageSize(pane->getFirstVisibleFrame(),
Chris@123 2312 pane->getLastVisibleFrame());
Chris@123 2313
Chris@123 2314 size_t sf0 = 0, sf1 = 0;
Chris@123 2315
Chris@123 2316 if (haveSelection) {
Chris@123 2317 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@123 2318 sf0 = selections.begin()->getStartFrame();
Chris@123 2319 MultiSelection::SelectionList::iterator e = selections.end();
Chris@123 2320 --e;
Chris@123 2321 sf1 = e->getEndFrame();
Chris@123 2322 selected = pane->getImageSize(sf0, sf1);
Chris@123 2323 }
Chris@123 2324
Chris@123 2325 QStringList items;
Chris@125 2326 items << tr("Export the whole pane (%1x%2 pixels)")
Chris@123 2327 .arg(total.width()).arg(total.height());
Chris@123 2328 items << tr("Export the visible area only (%1x%2 pixels)")
Chris@123 2329 .arg(visible.width()).arg(visible.height());
Chris@123 2330 if (haveSelection) {
Chris@123 2331 items << tr("Export the selection extent (%1x%2 pixels)")
Chris@123 2332 .arg(selected.width()).arg(selected.height());
Chris@124 2333 } else {
Chris@124 2334 items << tr("Export the selection extent");
Chris@123 2335 }
Chris@123 2336
Chris@123 2337 QSettings settings;
Chris@123 2338 settings.beginGroup("MainWindow");
Chris@123 2339 int deflt = settings.value("lastimageexportregion", 0).toInt();
Chris@123 2340 if (deflt == 2 && !haveSelection) deflt = 1;
Chris@124 2341 if (deflt == 0 && total.width() > 32767) deflt = 1;
Chris@124 2342
Chris@124 2343 ListInputDialog *lid = new ListInputDialog
Chris@123 2344 (this, tr("Select region to export"),
Chris@123 2345 tr("Which region of the current pane do you want to export as an image?"),
Chris@124 2346 items, deflt);
Chris@124 2347
Chris@124 2348 if (!haveSelection) {
Chris@124 2349 lid->setItemAvailability(2, false);
Chris@124 2350 }
Chris@124 2351 if (total.width() > 32767) { // appears to be the limit of a QImage
Chris@124 2352 lid->setItemAvailability(0, false);
Chris@124 2353 lid->setFootnote(tr("Note: the whole pane is too wide to be exported as a single image."));
Chris@124 2354 }
Chris@124 2355
Chris@124 2356 bool ok = lid->exec();
Chris@124 2357 QString item = lid->getCurrentString();
Chris@124 2358 delete lid;
Chris@123 2359
Chris@123 2360 if (!ok || item.isEmpty()) return;
Chris@123 2361
Chris@123 2362 settings.setValue("lastimageexportregion", deflt);
Chris@123 2363
Chris@123 2364 QImage *image = 0;
Chris@123 2365
Chris@123 2366 if (item == items[0]) {
Chris@123 2367 image = pane->toNewImage();
Chris@123 2368 } else if (item == items[1]) {
Chris@123 2369 image = pane->toNewImage(pane->getFirstVisibleFrame(),
Chris@123 2370 pane->getLastVisibleFrame());
Chris@123 2371 } else if (haveSelection) {
Chris@123 2372 image = pane->toNewImage(sf0, sf1);
Chris@123 2373 }
Chris@123 2374
Chris@121 2375 if (!image) return;
Chris@121 2376
Chris@121 2377 if (!image->save(path, "PNG")) {
Chris@121 2378 QMessageBox::critical(this, tr("Failed to save image file"),
Chris@121 2379 tr("Failed to save image file %1").arg(path));
Chris@121 2380 }
Chris@121 2381
Chris@121 2382 delete image;
Chris@121 2383 }
Chris@121 2384
Chris@0 2385 void
Chris@0 2386 MainWindow::newSession()
Chris@0 2387 {
Chris@0 2388 if (!checkSaveModified()) return;
Chris@0 2389
Chris@0 2390 closeSession();
Chris@0 2391 createDocument();
Chris@0 2392
Chris@0 2393 Pane *pane = m_paneStack->addPane();
Chris@0 2394
Chris@90 2395 connect(pane, SIGNAL(contextHelpChanged(const QString &)),
Chris@116 2396 this, SLOT(contextHelpChanged(const QString &)));
Chris@90 2397
Chris@0 2398 if (!m_timeRulerLayer) {
Chris@0 2399 m_timeRulerLayer = m_document->createMainModelLayer
Chris@0 2400 (LayerFactory::TimeRuler);
Chris@0 2401 }
Chris@0 2402
Chris@0 2403 m_document->addLayerToView(pane, m_timeRulerLayer);
Chris@0 2404
Chris@0 2405 Layer *waveform = m_document->createMainModelLayer(LayerFactory::Waveform);
Chris@0 2406 m_document->addLayerToView(pane, waveform);
Chris@0 2407
Chris@65 2408 m_overview->registerView(pane);
Chris@0 2409
Chris@0 2410 CommandHistory::getInstance()->clear();
Chris@0 2411 CommandHistory::getInstance()->documentSaved();
Chris@0 2412 documentRestored();
Chris@0 2413 updateMenuStates();
Chris@0 2414 }
Chris@0 2415
Chris@0 2416 void
Chris@303 2417 MainWindow::documentReplaced()
Chris@303 2418 {
Chris@303 2419 if (m_document) {
Chris@303 2420 connect(m_document, SIGNAL(activity(QString)),
Chris@303 2421 m_activityLog, SLOT(activityHappened(QString)));
Chris@303 2422 }
Chris@303 2423 }
Chris@303 2424
Chris@303 2425 void
Chris@0 2426 MainWindow::closeSession()
Chris@0 2427 {
Chris@0 2428 if (!checkSaveModified()) return;
Chris@0 2429
Chris@0 2430 while (m_paneStack->getPaneCount() > 0) {
Chris@0 2431
Chris@0 2432 Pane *pane = m_paneStack->getPane(m_paneStack->getPaneCount() - 1);
Chris@0 2433
Chris@0 2434 while (pane->getLayerCount() > 0) {
Chris@0 2435 m_document->removeLayerFromView
Chris@0 2436 (pane, pane->getLayer(pane->getLayerCount() - 1));
Chris@0 2437 }
Chris@0 2438
Chris@65 2439 m_overview->unregisterView(pane);
Chris@0 2440 m_paneStack->deletePane(pane);
Chris@0 2441 }
Chris@0 2442
Chris@0 2443 while (m_paneStack->getHiddenPaneCount() > 0) {
Chris@0 2444
Chris@0 2445 Pane *pane = m_paneStack->getHiddenPane
Chris@0 2446 (m_paneStack->getHiddenPaneCount() - 1);
Chris@0 2447
Chris@0 2448 while (pane->getLayerCount() > 0) {
Chris@0 2449 m_document->removeLayerFromView
Chris@0 2450 (pane, pane->getLayer(pane->getLayerCount() - 1));
Chris@0 2451 }
Chris@0 2452
Chris@65 2453 m_overview->unregisterView(pane);
Chris@0 2454 m_paneStack->deletePane(pane);
Chris@0 2455 }
Chris@0 2456
Chris@0 2457 delete m_document;
Chris@0 2458 m_document = 0;
Chris@0 2459 m_viewManager->clearSelections();
Chris@0 2460 m_timeRulerLayer = 0; // document owned this
Chris@0 2461
Chris@0 2462 m_sessionFile = "";
Chris@0 2463 setWindowTitle(tr("Sonic Visualiser"));
Chris@0 2464
Chris@0 2465 CommandHistory::getInstance()->clear();
Chris@0 2466 CommandHistory::getInstance()->documentSaved();
Chris@0 2467 documentRestored();
Chris@0 2468 }
Chris@0 2469
Chris@0 2470 void
Chris@0 2471 MainWindow::openSession()
Chris@0 2472 {
Chris@0 2473 if (!checkSaveModified()) return;
Chris@0 2474
Chris@0 2475 QString orig = m_audioFile;
Chris@0 2476 if (orig == "") orig = ".";
Chris@0 2477 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 2478
Chris@88 2479 QString path = getOpenFileName(FileFinder::SessionFile);
Chris@0 2480
Chris@0 2481 if (path.isEmpty()) return;
Chris@0 2482
Chris@200 2483 if (openSessionFile(path) == FileOpenFailed) {
Chris@247 2484 emit hideSplash();
Chris@0 2485 QMessageBox::critical(this, tr("Failed to open file"),
Chris@193 2486 tr("<b>File open failed</b><p>Session file \"%1\" could not be opened").arg(path));
Chris@0 2487 }
Chris@0 2488 }
Chris@0 2489
Chris@0 2490 void
Chris@0 2491 MainWindow::openSomething()
Chris@0 2492 {
Chris@0 2493 QString orig = m_audioFile;
Chris@0 2494 if (orig == "") orig = ".";
Chris@0 2495 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 2496
Chris@88 2497 QString path = getOpenFileName(FileFinder::AnyFile);
Chris@0 2498
Chris@0 2499 if (path.isEmpty()) return;
Chris@0 2500
Chris@197 2501 FileOpenStatus status = open(path, AskUser);
Chris@193 2502
Chris@193 2503 if (status == FileOpenFailed) {
Chris@247 2504 emit hideSplash();
Chris@193 2505 QMessageBox::critical(this, tr("Failed to open file"),
Chris@193 2506 tr("<b>File open failed</b><p>File \"%1\" could not be opened").arg(path));
Chris@193 2507 } else if (status == FileOpenWrongMode) {
Chris@247 2508 emit hideSplash();
Chris@193 2509 QMessageBox::critical(this, tr("Failed to open file"),
Chris@294 2510 tr("<b>Audio required</b><p>Unable to load layer data from \"%1\" without an audio file.<br>Please load at least one audio file before importing annotations.").arg(path));
Chris@0 2511 }
Chris@0 2512 }
Chris@0 2513
Chris@0 2514 void
Chris@86 2515 MainWindow::openLocation()
Chris@86 2516 {
Chris@103 2517 QSettings settings;
Chris@103 2518 settings.beginGroup("MainWindow");
Chris@103 2519 QString lastLocation = settings.value("lastremote", "").toString();
Chris@103 2520
Chris@86 2521 bool ok = false;
Chris@86 2522 QString text = QInputDialog::getText
Chris@86 2523 (this, tr("Open Location"),
Chris@86 2524 tr("Please enter the URL of the location to open:"),
Chris@103 2525 QLineEdit::Normal, lastLocation, &ok);
Chris@103 2526
Chris@103 2527 if (!ok) return;
Chris@103 2528
Chris@103 2529 settings.setValue("lastremote", text);
Chris@103 2530
Chris@103 2531 if (text.isEmpty()) return;
Chris@86 2532
Chris@197 2533 FileOpenStatus status = open(text);
Chris@193 2534
Chris@193 2535 if (status == FileOpenFailed) {
Chris@247 2536 emit hideSplash();
Chris@86 2537 QMessageBox::critical(this, tr("Failed to open location"),
Chris@193 2538 tr("<b>Open failed</b><p>URL \"%1\" could not be opened").arg(text));
Chris@193 2539 } else if (status == FileOpenWrongMode) {
Chris@247 2540 emit hideSplash();
Chris@193 2541 QMessageBox::critical(this, tr("Failed to open location"),
Chris@294 2542 tr("<b>Audio required</b><p>Unable to load layer data from \"%1\" without an audio file.<br>Please load at least one audio file before importing annotations.").arg(text));
Chris@86 2543 }
Chris@86 2544 }
Chris@86 2545
Chris@86 2546 void
Chris@0 2547 MainWindow::openRecentFile()
Chris@0 2548 {
Chris@0 2549 QObject *obj = sender();
Chris@0 2550 QAction *action = dynamic_cast<QAction *>(obj);
Chris@0 2551
Chris@0 2552 if (!action) {
Chris@0 2553 std::cerr << "WARNING: MainWindow::openRecentFile: sender is not an action"
Chris@0 2554 << std::endl;
Chris@0 2555 return;
Chris@0 2556 }
Chris@0 2557
Chris@0 2558 QString path = action->text();
Chris@0 2559 if (path == "") return;
Chris@0 2560
Chris@197 2561 FileOpenStatus status = open(path);
Chris@193 2562
Chris@193 2563 if (status == FileOpenFailed) {
Chris@247 2564 emit hideSplash();
Chris@193 2565 QMessageBox::critical(this, tr("Failed to open location"),
Chris@193 2566 tr("<b>Open failed</b><p>File or URL \"%1\" could not be opened").arg(path));
Chris@193 2567 } else if (status == FileOpenWrongMode) {
Chris@247 2568 emit hideSplash();
Chris@193 2569 QMessageBox::critical(this, tr("Failed to open location"),
Chris@294 2570 tr("<b>Audio required</b><p>Unable to load layer data from \"%1\" without an audio file.<br>Please load at least one audio file before importing annotations.").arg(path));
Chris@0 2571 }
Chris@0 2572 }
Chris@0 2573
Chris@0 2574 void
Chris@200 2575 MainWindow::paneAdded(Pane *pane)
Chris@200 2576 {
Chris@200 2577 if (m_overview) m_overview->registerView(pane);
Chris@200 2578 }
Chris@200 2579
Chris@200 2580 void
Chris@200 2581 MainWindow::paneHidden(Pane *pane)
Chris@200 2582 {
Chris@200 2583 if (m_overview) m_overview->unregisterView(pane);
Chris@200 2584 }
Chris@200 2585
Chris@200 2586 void
Chris@200 2587 MainWindow::paneAboutToBeDeleted(Pane *pane)
Chris@200 2588 {
Chris@200 2589 if (m_overview) m_overview->unregisterView(pane);
Chris@200 2590 }
Chris@200 2591
Chris@200 2592 void
Chris@193 2593 MainWindow::paneDropAccepted(Pane *pane, QStringList uriList)
Chris@193 2594 {
Chris@193 2595 if (pane) m_paneStack->setCurrentPane(pane);
Chris@193 2596
Chris@193 2597 for (QStringList::iterator i = uriList.begin(); i != uriList.end(); ++i) {
Chris@193 2598
Chris@295 2599 FileOpenStatus status;
Chris@295 2600
Chris@295 2601 if (i == uriList.begin()) {
Chris@295 2602 status = open(*i, ReplaceCurrentPane);
Chris@295 2603 } else {
Chris@295 2604 status = open(*i, CreateAdditionalModel);
Chris@295 2605 }
Chris@193 2606
Chris@193 2607 if (status == FileOpenFailed) {
Chris@247 2608 emit hideSplash();
Chris@193 2609 QMessageBox::critical(this, tr("Failed to open dropped URL"),
Chris@193 2610 tr("<b>Open failed</b><p>Dropped URL \"%1\" could not be opened").arg(*i));
Chris@295 2611 break;
Chris@193 2612 } else if (status == FileOpenWrongMode) {
Chris@247 2613 emit hideSplash();
Chris@193 2614 QMessageBox::critical(this, tr("Failed to open dropped URL"),
Chris@294 2615 tr("<b>Audio required</b><p>Unable to load layer data from \"%1\" without an audio file.<br>Please load at least one audio file before importing annotations.").arg(*i));
Chris@295 2616 break;
Chris@295 2617 } else if (status == FileOpenCancelled) {
Chris@295 2618 break;
Chris@193 2619 }
Chris@193 2620 }
Chris@193 2621 }
Chris@193 2622
Chris@193 2623 void
Chris@193 2624 MainWindow::paneDropAccepted(Pane *pane, QString text)
Chris@193 2625 {
Chris@193 2626 if (pane) m_paneStack->setCurrentPane(pane);
Chris@193 2627
Chris@193 2628 QUrl testUrl(text);
Chris@193 2629 if (testUrl.scheme() == "file" ||
Chris@193 2630 testUrl.scheme() == "http" ||
Chris@193 2631 testUrl.scheme() == "ftp") {
Chris@193 2632 QStringList list;
Chris@193 2633 list.push_back(text);
Chris@193 2634 paneDropAccepted(pane, list);
Chris@193 2635 return;
Chris@193 2636 }
Chris@193 2637
Chris@193 2638 //!!! open as text -- but by importing as if a CSV, or just adding
Chris@193 2639 //to a text layer?
Chris@193 2640 }
Chris@193 2641
Chris@193 2642 void
Chris@0 2643 MainWindow::closeEvent(QCloseEvent *e)
Chris@0 2644 {
Chris@137 2645 // std::cerr << "MainWindow::closeEvent" << std::endl;
Chris@118 2646
Chris@136 2647 if (m_openingAudioFile) {
Chris@137 2648 // std::cerr << "Busy - ignoring close event" << std::endl;
Chris@136 2649 e->ignore();
Chris@136 2650 return;
Chris@136 2651 }
Chris@136 2652
Chris@70 2653 if (!m_abandoning && !checkSaveModified()) {
Chris@137 2654 // std::cerr << "Ignoring close event" << std::endl;
Chris@0 2655 e->ignore();
Chris@0 2656 return;
Chris@0 2657 }
Chris@0 2658
Chris@5 2659 QSettings settings;
Chris@5 2660 settings.beginGroup("MainWindow");
Chris@5 2661 settings.setValue("size", size());
Chris@5 2662 settings.setValue("position", pos());
Chris@5 2663 settings.endGroup();
Chris@5 2664
Chris@163 2665 delete m_keyReference;
Chris@163 2666 m_keyReference = 0;
Chris@163 2667
Chris@163 2668 if (m_preferencesDialog &&
Chris@163 2669 m_preferencesDialog->isVisible()) {
Chris@164 2670 closeSession(); // otherwise we'll have to wait for prefs changes
Chris@163 2671 m_preferencesDialog->applicationClosing(false);
Chris@163 2672 }
Chris@163 2673
Chris@200 2674 closeSession();
Chris@200 2675
Chris@0 2676 e->accept();
Chris@0 2677 return;
Chris@0 2678 }
Chris@0 2679
Chris@0 2680 bool
Chris@11 2681 MainWindow::commitData(bool mayAskUser)
Chris@11 2682 {
Chris@11 2683 if (mayAskUser) {
Chris@163 2684 bool rv = checkSaveModified();
Chris@163 2685 if (rv) {
Chris@163 2686 if (m_preferencesDialog &&
Chris@163 2687 m_preferencesDialog->isVisible()) {
Chris@163 2688 m_preferencesDialog->applicationClosing(false);
Chris@163 2689 }
Chris@163 2690 }
Chris@163 2691 return rv;
Chris@11 2692 } else {
Chris@163 2693 if (m_preferencesDialog &&
Chris@163 2694 m_preferencesDialog->isVisible()) {
Chris@163 2695 m_preferencesDialog->applicationClosing(true);
Chris@163 2696 }
Chris@11 2697 if (!m_documentModified) return true;
Chris@11 2698
Chris@11 2699 // If we can't check with the user first, then we can't save
Chris@11 2700 // to the original session file (even if we have it) -- have
Chris@11 2701 // to use a temporary file
Chris@11 2702
Chris@11 2703 QString svDirBase = ".sv1";
Chris@11 2704 QString svDir = QDir::home().filePath(svDirBase);
Chris@11 2705
Chris@11 2706 if (!QFileInfo(svDir).exists()) {
Chris@11 2707 if (!QDir::home().mkdir(svDirBase)) return false;
Chris@11 2708 } else {
Chris@11 2709 if (!QFileInfo(svDir).isDir()) return false;
Chris@11 2710 }
Chris@11 2711
Chris@11 2712 // This name doesn't have to be unguessable
Chris@93 2713 #ifndef _WIN32
Chris@11 2714 QString fname = QString("tmp-%1-%2.sv")
Chris@11 2715 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"))
Chris@11 2716 .arg(QProcess().pid());
Chris@93 2717 #else
Chris@93 2718 QString fname = QString("tmp-%1.sv")
Chris@93 2719 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"));
Chris@93 2720 #endif
Chris@11 2721 QString fpath = QDir(svDir).filePath(fname);
Chris@11 2722 if (saveSessionFile(fpath)) {
Chris@34 2723 m_recentFiles.addFile(fpath);
Chris@11 2724 return true;
Chris@11 2725 } else {
Chris@11 2726 return false;
Chris@11 2727 }
Chris@11 2728 }
Chris@11 2729 }
Chris@11 2730
Chris@11 2731 bool
Chris@0 2732 MainWindow::checkSaveModified()
Chris@0 2733 {
Chris@0 2734 // Called before some destructive operation (e.g. new session,
Chris@0 2735 // exit program). Return true if we can safely proceed, false to
Chris@0 2736 // cancel.
Chris@0 2737
Chris@0 2738 if (!m_documentModified) return true;
Chris@0 2739
Chris@247 2740 emit hideSplash();
Chris@247 2741
Chris@0 2742 int button =
Chris@0 2743 QMessageBox::warning(this,
Chris@0 2744 tr("Session modified"),
Chris@207 2745 tr("<b>Session modified</b><p>The current session has been modified.<br>Do you want to save it?"),
Chris@165 2746 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
Chris@165 2747 QMessageBox::Yes);
Chris@0 2748
Chris@0 2749 if (button == QMessageBox::Yes) {
Chris@0 2750 saveSession();
Chris@0 2751 if (m_documentModified) { // save failed -- don't proceed!
Chris@0 2752 return false;
Chris@0 2753 } else {
Chris@0 2754 return true; // saved, so it's safe to continue now
Chris@0 2755 }
Chris@0 2756 } else if (button == QMessageBox::No) {
Chris@0 2757 m_documentModified = false; // so we know to abandon it
Chris@0 2758 return true;
Chris@0 2759 }
Chris@0 2760
Chris@0 2761 // else cancel
Chris@0 2762 return false;
Chris@0 2763 }
Chris@0 2764
Chris@290 2765 bool
Chris@294 2766 MainWindow::shouldCreateNewSessionForRDFAudio(bool *cancel)
Chris@290 2767 {
Chris@294 2768 //!!! This is very similar to part of MainWindowBase::openAudio --
Chris@294 2769 //!!! make them a bit more uniform
Chris@294 2770
Chris@294 2771 QSettings settings;
Chris@294 2772 settings.beginGroup("MainWindow");
Chris@294 2773 bool prevNewSession = settings.value("newsessionforrdfaudio", true).toBool();
Chris@294 2774 settings.endGroup();
Chris@294 2775 bool newSession = true;
Chris@294 2776
Chris@294 2777 QStringList items;
Chris@294 2778 items << tr("Close the current session and create a new one")
Chris@294 2779 << tr("Add this data to the current session");
Chris@294 2780
Chris@294 2781 bool ok = false;
Chris@294 2782 QString item = ListInputDialog::getItem
Chris@294 2783 (this, tr("Select target for import"),
Chris@294 2784 tr("<b>Select a target for import</b><p>This RDF document refers to one or more audio files.<br>You already have an audio waveform loaded.<br>What would you like to do with the new data?"),
Chris@294 2785 items, prevNewSession ? 0 : 1, &ok);
Chris@294 2786
Chris@294 2787 if (!ok || item.isEmpty()) {
Chris@294 2788 *cancel = true;
Chris@290 2789 return false;
Chris@290 2790 }
Chris@294 2791
Chris@294 2792 newSession = (item == items[0]);
Chris@294 2793 settings.beginGroup("MainWindow");
Chris@294 2794 settings.setValue("newsessionforrdfaudio", newSession);
Chris@294 2795 settings.endGroup();
Chris@294 2796
Chris@294 2797 if (newSession) return true;
Chris@294 2798 else return false;
Chris@290 2799 }
Chris@290 2800
Chris@0 2801 void
Chris@0 2802 MainWindow::saveSession()
Chris@0 2803 {
Chris@0 2804 if (m_sessionFile != "") {
Chris@0 2805 if (!saveSessionFile(m_sessionFile)) {
Chris@0 2806 QMessageBox::critical(this, tr("Failed to save file"),
Chris@193 2807 tr("<b>Save failed</b><p>Session file \"%1\" could not be saved.").arg(m_sessionFile));
Chris@0 2808 } else {
Chris@0 2809 CommandHistory::getInstance()->documentSaved();
Chris@0 2810 documentRestored();
Chris@0 2811 }
Chris@0 2812 } else {
Chris@0 2813 saveSessionAs();
Chris@0 2814 }
Chris@0 2815 }
Chris@0 2816
Chris@0 2817 void
Chris@0 2818 MainWindow::saveSessionAs()
Chris@0 2819 {
Chris@0 2820 QString orig = m_audioFile;
Chris@0 2821 if (orig == "") orig = ".";
Chris@0 2822 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 2823
Chris@88 2824 QString path = getSaveFileName(FileFinder::SessionFile);
Chris@81 2825
Chris@81 2826 if (path == "") return;
Chris@0 2827
Chris@0 2828 if (!saveSessionFile(path)) {
Chris@0 2829 QMessageBox::critical(this, tr("Failed to save file"),
Chris@193 2830 tr("<b>Save failed</b><p>Session file \"%1\" could not be saved.").arg(path));
Chris@0 2831 } else {
Chris@0 2832 setWindowTitle(tr("Sonic Visualiser: %1")
Chris@0 2833 .arg(QFileInfo(path).fileName()));
Chris@0 2834 m_sessionFile = path;
Chris@0 2835 CommandHistory::getInstance()->documentSaved();
Chris@0 2836 documentRestored();
Chris@34 2837 m_recentFiles.addFile(path);
Chris@0 2838 }
Chris@0 2839 }
Chris@0 2840
Chris@90 2841 void
Chris@72 2842 MainWindow::preferenceChanged(PropertyContainer::PropertyName name)
Chris@72 2843 {
Chris@200 2844 MainWindowBase::preferenceChanged(name);
Chris@200 2845
Chris@200 2846 if (name == "Background Mode" && m_viewManager) {
Chris@180 2847 if (m_viewManager->getGlobalDarkBackground()) {
Chris@180 2848 m_panLayer->setBaseColour
Chris@180 2849 (ColourDatabase::getInstance()->getColourIndex(tr("Bright Green")));
Chris@180 2850 } else {
Chris@180 2851 m_panLayer->setBaseColour
Chris@180 2852 (ColourDatabase::getInstance()->getColourIndex(tr("Green")));
Chris@180 2853 }
Chris@200 2854 }
Chris@0 2855 }
Chris@0 2856
Chris@0 2857 void
Chris@239 2858 MainWindow::propertyStacksResized(int width)
Chris@239 2859 {
Chris@251 2860 // std::cerr << "MainWindow::propertyStacksResized(" << width << ")" << std::endl;
Chris@239 2861
Chris@239 2862 if (!m_playControlsSpacer) return;
Chris@239 2863
Chris@239 2864 int spacerWidth = width - m_playControlsWidth - 4;
Chris@239 2865
Chris@251 2866 // std::cerr << "resizing spacer from " << m_playControlsSpacer->width() << " to " << spacerWidth << std::endl;
Chris@239 2867
Chris@239 2868 m_playControlsSpacer->setFixedSize(QSize(spacerWidth, 2));
Chris@239 2869 }
Chris@239 2870
Chris@239 2871 void
Chris@0 2872 MainWindow::addPane()
Chris@0 2873 {
Chris@0 2874 QObject *s = sender();
Chris@0 2875 QAction *action = dynamic_cast<QAction *>(s);
Chris@0 2876
Chris@0 2877 if (!action) {
Chris@0 2878 std::cerr << "WARNING: MainWindow::addPane: sender is not an action"
Chris@0 2879 << std::endl;
Chris@0 2880 return;
Chris@0 2881 }
Chris@0 2882
Chris@0 2883 PaneActionMap::iterator i = m_paneActions.find(action);
Chris@0 2884
Chris@0 2885 if (i == m_paneActions.end()) {
Chris@0 2886 std::cerr << "WARNING: MainWindow::addPane: unknown action "
Chris@0 2887 << action->objectName().toStdString() << std::endl;
Chris@0 2888 return;
Chris@0 2889 }
Chris@0 2890
Chris@69 2891 addPane(i->second, action->text());
Chris@69 2892 }
Chris@69 2893
Chris@69 2894 void
Chris@232 2895 MainWindow::addPane(const LayerConfiguration &configuration, QString text)
Chris@69 2896 {
Chris@69 2897 CommandHistory::getInstance()->startCompoundOperation(text, true);
Chris@0 2898
Chris@0 2899 AddPaneCommand *command = new AddPaneCommand(this);
Chris@0 2900 CommandHistory::getInstance()->addCommand(command);
Chris@0 2901
Chris@0 2902 Pane *pane = command->getPane();
Chris@0 2903
Chris@69 2904 if (configuration.layer == LayerFactory::Spectrum) {
Chris@109 2905 pane->setPlaybackFollow(PlaybackScrollContinuous);
Chris@110 2906 pane->setFollowGlobalZoom(false);
Chris@112 2907 pane->setZoomLevel(512);
Chris@7 2908 }
Chris@7 2909
Chris@69 2910 if (configuration.layer != LayerFactory::TimeRuler &&
Chris@69 2911 configuration.layer != LayerFactory::Spectrum) {
Chris@8 2912
Chris@0 2913 if (!m_timeRulerLayer) {
Chris@0 2914 // std::cerr << "no time ruler layer, creating one" << std::endl;
Chris@0 2915 m_timeRulerLayer = m_document->createMainModelLayer
Chris@0 2916 (LayerFactory::TimeRuler);
Chris@0 2917 }
Chris@0 2918
Chris@0 2919 // std::cerr << "adding time ruler layer " << m_timeRulerLayer << std::endl;
Chris@0 2920
Chris@0 2921 m_document->addLayerToView(pane, m_timeRulerLayer);
Chris@0 2922 }
Chris@0 2923
Chris@69 2924 Layer *newLayer = m_document->createLayer(configuration.layer);
Chris@69 2925
Chris@69 2926 Model *suggestedModel = configuration.sourceModel;
Chris@66 2927 Model *model = 0;
Chris@66 2928
Chris@66 2929 if (suggestedModel) {
Chris@66 2930
Chris@66 2931 // check its validity
Chris@224 2932 std::vector<Model *> inputModels = m_document->getTransformInputModels();
Chris@66 2933 for (size_t j = 0; j < inputModels.size(); ++j) {
Chris@66 2934 if (inputModels[j] == suggestedModel) {
Chris@66 2935 model = suggestedModel;
Chris@66 2936 break;
Chris@66 2937 }
Chris@66 2938 }
Chris@66 2939
Chris@66 2940 if (!model) {
Chris@66 2941 std::cerr << "WARNING: Model " << (void *)suggestedModel
Chris@66 2942 << " appears in pane action map, but is not reported "
Chris@66 2943 << "by document as a valid transform source" << std::endl;
Chris@66 2944 }
Chris@66 2945 }
Chris@66 2946
Chris@66 2947 if (!model) model = m_document->getMainModel();
Chris@66 2948
Chris@66 2949 m_document->setModel(newLayer, model);
Chris@66 2950
Chris@69 2951 m_document->setChannel(newLayer, configuration.channel);
Chris@0 2952 m_document->addLayerToView(pane, newLayer);
Chris@0 2953
Chris@0 2954 m_paneStack->setCurrentPane(pane);
Chris@70 2955 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 2956
Chris@130 2957 // std::cerr << "MainWindow::addPane: global centre frame is "
Chris@130 2958 // << m_viewManager->getGlobalCentreFrame() << std::endl;
Chris@130 2959 // pane->setCentreFrame(m_viewManager->getGlobalCentreFrame());
Chris@73 2960
Chris@0 2961 CommandHistory::getInstance()->endCompoundOperation();
Chris@0 2962
Chris@0 2963 updateMenuStates();
Chris@0 2964 }
Chris@0 2965
Chris@0 2966 void
Chris@0 2967 MainWindow::addLayer()
Chris@0 2968 {
Chris@0 2969 QObject *s = sender();
Chris@0 2970 QAction *action = dynamic_cast<QAction *>(s);
Chris@0 2971
Chris@0 2972 if (!action) {
Chris@0 2973 std::cerr << "WARNING: MainWindow::addLayer: sender is not an action"
Chris@0 2974 << std::endl;
Chris@0 2975 return;
Chris@0 2976 }
Chris@0 2977
Chris@0 2978 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 2979
Chris@0 2980 if (!pane) {
Chris@0 2981 std::cerr << "WARNING: MainWindow::addLayer: no current pane" << std::endl;
Chris@0 2982 return;
Chris@0 2983 }
Chris@0 2984
Chris@0 2985 ExistingLayerActionMap::iterator ei = m_existingLayerActions.find(action);
Chris@0 2986
Chris@0 2987 if (ei != m_existingLayerActions.end()) {
Chris@0 2988 Layer *newLayer = ei->second;
Chris@0 2989 m_document->addLayerToView(pane, newLayer);
Chris@0 2990 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 2991 return;
Chris@0 2992 }
Chris@0 2993
Chris@95 2994 ei = m_sliceActions.find(action);
Chris@95 2995
Chris@95 2996 if (ei != m_sliceActions.end()) {
Chris@95 2997 Layer *newLayer = m_document->createLayer(LayerFactory::Slice);
Chris@95 2998 // document->setModel(newLayer, ei->second->getModel());
Chris@95 2999 SliceableLayer *source = dynamic_cast<SliceableLayer *>(ei->second);
Chris@95 3000 SliceLayer *dest = dynamic_cast<SliceLayer *>(newLayer);
Chris@95 3001 if (source && dest) {
Chris@205 3002 //!!!???
Chris@95 3003 dest->setSliceableModel(source->getSliceableModel());
Chris@95 3004 connect(source, SIGNAL(sliceableModelReplaced(const Model *, const Model *)),
Chris@95 3005 dest, SLOT(sliceableModelReplaced(const Model *, const Model *)));
Chris@95 3006 connect(m_document, SIGNAL(modelAboutToBeDeleted(Model *)),
Chris@95 3007 dest, SLOT(modelAboutToBeDeleted(Model *)));
Chris@95 3008 }
Chris@95 3009 m_document->addLayerToView(pane, newLayer);
Chris@95 3010 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@95 3011 return;
Chris@95 3012 }
Chris@95 3013
Chris@211 3014 TransformActionMap::iterator i = m_transformActions.find(action);
Chris@34 3015
Chris@34 3016 if (i == m_transformActions.end()) {
Chris@0 3017
Chris@0 3018 LayerActionMap::iterator i = m_layerActions.find(action);
Chris@0 3019
Chris@0 3020 if (i == m_layerActions.end()) {
Chris@0 3021 std::cerr << "WARNING: MainWindow::addLayer: unknown action "
Chris@0 3022 << action->objectName().toStdString() << std::endl;
Chris@0 3023 return;
Chris@0 3024 }
Chris@0 3025
Chris@232 3026 LayerFactory::LayerType type = i->second.layer;
Chris@0 3027
Chris@0 3028 LayerFactory::LayerTypeSet emptyTypes =
Chris@0 3029 LayerFactory::getInstance()->getValidEmptyLayerTypes();
Chris@0 3030
Chris@0 3031 Layer *newLayer;
Chris@0 3032
Chris@0 3033 if (emptyTypes.find(type) != emptyTypes.end()) {
Chris@0 3034
Chris@0 3035 newLayer = m_document->createEmptyLayer(type);
Chris@217 3036 if (newLayer) {
Chris@217 3037 m_toolActions[ViewManager::DrawMode]->trigger();
Chris@217 3038 }
Chris@0 3039
Chris@0 3040 } else {
Chris@0 3041
Chris@238 3042 if (!i->second.sourceModel) {
Chris@238 3043 // e.g. time ruler
Chris@238 3044 newLayer = m_document->createMainModelLayer(type);
Chris@232 3045 } else {
Chris@238 3046 newLayer = m_document->createLayer(type);
Chris@238 3047 if (m_document->isKnownModel(i->second.sourceModel)) {
Chris@238 3048 m_document->setChannel(newLayer, i->second.channel);
Chris@238 3049 m_document->setModel(newLayer, i->second.sourceModel);
Chris@238 3050 } else {
Chris@238 3051 std::cerr << "WARNING: MainWindow::addLayer: unknown model "
Chris@238 3052 << i->second.sourceModel
Chris@238 3053 << " (\""
Chris@238 3054 << (i->second.sourceModel ? i->second.sourceModel->objectName().toStdString() : "")
Chris@238 3055 << "\") in layer action map"
Chris@238 3056 << std::endl;
Chris@238 3057 }
Chris@232 3058 }
Chris@238 3059 }
Chris@0 3060
Chris@217 3061 if (newLayer) {
Chris@217 3062 m_document->addLayerToView(pane, newLayer);
Chris@217 3063 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@217 3064 }
Chris@0 3065
Chris@0 3066 return;
Chris@0 3067 }
Chris@0 3068
Chris@224 3069 //!!! want to do something like this, but it's not supported in
Chris@224 3070 //ModelTransformerFactory yet
Chris@224 3071 /*
Chris@0 3072 int channel = -1;
Chris@0 3073 // pick up the default channel from any existing layers on the same pane
Chris@0 3074 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@0 3075 int c = LayerFactory::getInstance()->getChannel(pane->getLayer(j));
Chris@0 3076 if (c != -1) {
Chris@0 3077 channel = c;
Chris@0 3078 break;
Chris@0 3079 }
Chris@0 3080 }
Chris@224 3081 */
Chris@0 3082
Chris@33 3083 // We always ask for configuration, even if the plugin isn't
Chris@33 3084 // supposed to be configurable, because we need to let the user
Chris@33 3085 // change the execution context (block size etc).
Chris@0 3086
Chris@224 3087 QString transformId = i->second;
Chris@274 3088
Chris@274 3089 addLayer(transformId);
Chris@274 3090 }
Chris@274 3091
Chris@274 3092 void
Chris@274 3093 MainWindow::addLayer(QString transformId)
Chris@274 3094 {
Chris@274 3095 Pane *pane = m_paneStack->getCurrentPane();
Chris@274 3096 if (!pane) {
Chris@274 3097 std::cerr << "WARNING: MainWindow::addLayer: no current pane" << std::endl;
Chris@274 3098 return;
Chris@274 3099 }
Chris@274 3100
Chris@224 3101 Transform transform = TransformFactory::getInstance()->
Chris@224 3102 getDefaultTransformFor(transformId);
Chris@27 3103
Chris@66 3104 std::vector<Model *> candidateInputModels =
Chris@224 3105 m_document->getTransformInputModels();
Chris@53 3106
Chris@219 3107 Model *defaultInputModel = 0;
Chris@219 3108 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@219 3109 Layer *layer = pane->getLayer(j);
Chris@219 3110 if (!layer) continue;
Chris@243 3111 if (LayerFactory::getInstance()->getLayerType(layer) !=
Chris@243 3112 LayerFactory::Waveform &&
Chris@243 3113 !layer->isLayerOpaque()) continue;
Chris@219 3114 Model *model = layer->getModel();
Chris@219 3115 if (!model) continue;
Chris@219 3116 for (size_t k = 0; k < candidateInputModels.size(); ++k) {
Chris@219 3117 if (candidateInputModels[k] == model) {
Chris@219 3118 defaultInputModel = model;
Chris@219 3119 break;
Chris@219 3120 }
Chris@219 3121 }
Chris@219 3122 if (defaultInputModel) break;
Chris@219 3123 }
Chris@219 3124
Chris@184 3125 size_t startFrame = 0, duration = 0;
Chris@184 3126 size_t endFrame = 0;
Chris@184 3127 m_viewManager->getSelection().getExtents(startFrame, endFrame);
Chris@184 3128 if (endFrame > startFrame) duration = endFrame - startFrame;
Chris@184 3129 else startFrame = 0;
Chris@184 3130
Chris@224 3131 ModelTransformer::Input input = ModelTransformerFactory::getInstance()->
Chris@224 3132 getConfigurationForTransform
Chris@211 3133 (transform,
Chris@211 3134 candidateInputModels,
Chris@219 3135 defaultInputModel,
Chris@211 3136 m_playSource,
Chris@211 3137 startFrame,
Chris@211 3138 duration);
Chris@211 3139
Chris@224 3140 if (!input.getModel()) return;
Chris@224 3141
Chris@224 3142 // std::cerr << "MainWindow::addLayer: Input model is " << input.getModel() << " \"" << input.getModel()->objectName().toStdString() << "\"" << std::endl;
Chris@224 3143
Chris@224 3144 Layer *newLayer = m_document->createDerivedLayer(transform, input);
Chris@0 3145
Chris@0 3146 if (newLayer) {
Chris@0 3147 m_document->addLayerToView(pane, newLayer);
Chris@224 3148 m_document->setChannel(newLayer, input.getChannel());
Chris@224 3149 m_recentTransforms.add(transformId);
Chris@70 3150 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 3151 }
Chris@0 3152
Chris@0 3153 updateMenuStates();
Chris@0 3154 }
Chris@0 3155
Chris@0 3156 void
Chris@0 3157 MainWindow::renameCurrentLayer()
Chris@0 3158 {
Chris@0 3159 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 3160 if (pane) {
Chris@0 3161 Layer *layer = pane->getSelectedLayer();
Chris@0 3162 if (layer) {
Chris@0 3163 bool ok = false;
Chris@0 3164 QString newName = QInputDialog::getText
Chris@0 3165 (this, tr("Rename Layer"),
Chris@0 3166 tr("New name for this layer:"),
Chris@0 3167 QLineEdit::Normal, layer->objectName(), &ok);
Chris@0 3168 if (ok) {
Chris@239 3169 layer->setPresentationName(newName);
Chris@95 3170 setupExistingLayersMenus();
Chris@0 3171 }
Chris@0 3172 }
Chris@0 3173 }
Chris@0 3174 }
Chris@0 3175
Chris@0 3176 void
Chris@272 3177 MainWindow::findTransform()
Chris@272 3178 {
Chris@274 3179 TransformFinder *finder = new TransformFinder(this);
Chris@274 3180 if (!finder->exec()) {
Chris@274 3181 delete finder;
Chris@274 3182 return;
Chris@273 3183 }
Chris@274 3184 TransformId transform = finder->getTransform();
Chris@274 3185 delete finder;
Chris@287 3186
Chris@287 3187 if (getMainModel() != 0 && m_paneStack->getCurrentPane() != 0) {
Chris@287 3188 addLayer(transform);
Chris@287 3189 }
Chris@272 3190 }
Chris@272 3191
Chris@272 3192 void
Chris@207 3193 MainWindow::playSoloToggled()
Chris@207 3194 {
Chris@207 3195 MainWindowBase::playSoloToggled();
Chris@207 3196 m_soloModified = true;
Chris@207 3197 }
Chris@207 3198
Chris@207 3199 void
Chris@206 3200 MainWindow::alignToggled()
Chris@206 3201 {
Chris@206 3202 QAction *action = dynamic_cast<QAction *>(sender());
Chris@206 3203
Chris@207 3204 if (!m_viewManager) return;
Chris@207 3205
Chris@206 3206 if (action) {
Chris@206 3207 m_viewManager->setAlignMode(action->isChecked());
Chris@206 3208 } else {
Chris@206 3209 m_viewManager->setAlignMode(!m_viewManager->getAlignMode());
Chris@206 3210 }
Chris@206 3211
Chris@206 3212 if (m_viewManager->getAlignMode()) {
Chris@207 3213 m_prevSolo = m_soloAction->isChecked();
Chris@208 3214 if (!m_soloAction->isChecked()) {
Chris@208 3215 m_soloAction->setChecked(true);
Chris@208 3216 MainWindowBase::playSoloToggled();
Chris@208 3217 }
Chris@207 3218 m_soloModified = false;
Chris@207 3219 emit canChangeSolo(false);
Chris@206 3220 m_document->alignModels();
Chris@206 3221 m_document->setAutoAlignment(true);
Chris@206 3222 } else {
Chris@207 3223 if (!m_soloModified) {
Chris@208 3224 if (m_soloAction->isChecked() != m_prevSolo) {
Chris@208 3225 m_soloAction->setChecked(m_prevSolo);
Chris@208 3226 MainWindowBase::playSoloToggled();
Chris@208 3227 }
Chris@207 3228 }
Chris@207 3229 emit canChangeSolo(true);
Chris@206 3230 m_document->setAutoAlignment(false);
Chris@206 3231 }
Chris@206 3232
Chris@206 3233 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@206 3234
Chris@206 3235 Pane *pane = m_paneStack->getPane(i);
Chris@206 3236 if (!pane) continue;
Chris@206 3237
Chris@206 3238 pane->update();
Chris@206 3239 }
Chris@206 3240 }
Chris@206 3241
Chris@206 3242 void
Chris@59 3243 MainWindow::playSpeedChanged(int position)
Chris@0 3244 {
Chris@59 3245 PlaySpeedRangeMapper mapper(0, 200);
Chris@60 3246
Chris@60 3247 float percent = m_playSpeed->mappedValue();
Chris@60 3248 float factor = mapper.getFactorForValue(percent);
Chris@60 3249
Chris@267 3250 // std::cerr << "speed = " << position << " percent = " << percent << " factor = " << factor << std::endl;
Chris@60 3251
Chris@59 3252 bool something = (position != 100);
Chris@155 3253
Chris@59 3254 int pc = lrintf(percent);
Chris@21 3255
Chris@155 3256 if (!something) {
Chris@155 3257 contextHelpChanged(tr("Playback speed: Normal"));
Chris@155 3258 } else {
Chris@155 3259 contextHelpChanged(tr("Playback speed: %1%2%")
Chris@155 3260 .arg(position > 100 ? "+" : "")
Chris@155 3261 .arg(pc));
Chris@155 3262 }
Chris@155 3263
Chris@240 3264 m_playSource->setTimeStretch(factor);
Chris@155 3265
Chris@155 3266 updateMenuStates();
Chris@16 3267 }
Chris@16 3268
Chris@26 3269 void
Chris@155 3270 MainWindow::speedUpPlayback()
Chris@155 3271 {
Chris@155 3272 int value = m_playSpeed->value();
Chris@155 3273 value = value + m_playSpeed->pageStep();
Chris@155 3274 if (value > m_playSpeed->maximum()) value = m_playSpeed->maximum();
Chris@155 3275 m_playSpeed->setValue(value);
Chris@155 3276 }
Chris@155 3277
Chris@155 3278 void
Chris@155 3279 MainWindow::slowDownPlayback()
Chris@155 3280 {
Chris@155 3281 int value = m_playSpeed->value();
Chris@155 3282 value = value - m_playSpeed->pageStep();
Chris@155 3283 if (value < m_playSpeed->minimum()) value = m_playSpeed->minimum();
Chris@155 3284 m_playSpeed->setValue(value);
Chris@155 3285 }
Chris@155 3286
Chris@155 3287 void
Chris@155 3288 MainWindow::restoreNormalPlayback()
Chris@155 3289 {
Chris@155 3290 m_playSpeed->setValue(m_playSpeed->defaultValue());
Chris@155 3291 }
Chris@155 3292
Chris@155 3293 void
Chris@227 3294 MainWindow::currentPaneChanged(Pane *pane)
Chris@227 3295 {
Chris@228 3296 MainWindowBase::currentPaneChanged(pane);
Chris@228 3297
Chris@227 3298 if (!pane || !m_panLayer) return;
Chris@227 3299 for (int i = pane->getLayerCount(); i > 0; ) {
Chris@227 3300 --i;
Chris@227 3301 Layer *layer = pane->getLayer(i);
Chris@227 3302 if (LayerFactory::getInstance()->getLayerType(layer) ==
Chris@227 3303 LayerFactory::Waveform) {
Chris@227 3304 RangeSummarisableTimeValueModel *tvm =
Chris@227 3305 dynamic_cast<RangeSummarisableTimeValueModel *>(layer->getModel());
Chris@227 3306 if (tvm) {
Chris@227 3307 m_panLayer->setModel(tvm);
Chris@227 3308 return;
Chris@227 3309 }
Chris@227 3310 }
Chris@227 3311 }
Chris@227 3312 }
Chris@227 3313
Chris@227 3314 void
Chris@116 3315 MainWindow::updateVisibleRangeDisplay(Pane *p) const
Chris@116 3316 {
Chris@116 3317 if (!getMainModel() || !p) {
Chris@116 3318 return;
Chris@116 3319 }
Chris@116 3320
Chris@117 3321 bool haveSelection = false;
Chris@117 3322 size_t startFrame = 0, endFrame = 0;
Chris@117 3323
Chris@117 3324 if (m_viewManager && m_viewManager->haveInProgressSelection()) {
Chris@117 3325
Chris@117 3326 bool exclusive = false;
Chris@117 3327 Selection s = m_viewManager->getInProgressSelection(exclusive);
Chris@117 3328
Chris@117 3329 if (!s.isEmpty()) {
Chris@117 3330 haveSelection = true;
Chris@117 3331 startFrame = s.getStartFrame();
Chris@117 3332 endFrame = s.getEndFrame();
Chris@117 3333 }
Chris@117 3334 }
Chris@117 3335
Chris@117 3336 if (!haveSelection) {
Chris@117 3337 startFrame = p->getFirstVisibleFrame();
Chris@117 3338 endFrame = p->getLastVisibleFrame();
Chris@117 3339 }
Chris@117 3340
Chris@116 3341 RealTime start = RealTime::frame2RealTime
Chris@117 3342 (startFrame, getMainModel()->getSampleRate());
Chris@116 3343
Chris@116 3344 RealTime end = RealTime::frame2RealTime
Chris@117 3345 (endFrame, getMainModel()->getSampleRate());
Chris@116 3346
Chris@116 3347 RealTime duration = end - start;
Chris@116 3348
Chris@116 3349 QString startStr, endStr, durationStr;
Chris@116 3350 startStr = start.toText(true).c_str();
Chris@116 3351 endStr = end.toText(true).c_str();
Chris@116 3352 durationStr = duration.toText(true).c_str();
Chris@116 3353
Chris@117 3354 if (haveSelection) {
Chris@117 3355 m_myStatusMessage = tr("Selection: %1 to %2 (duration %3)")
Chris@117 3356 .arg(startStr).arg(endStr).arg(durationStr);
Chris@117 3357 } else {
Chris@117 3358 m_myStatusMessage = tr("Visible: %1 to %2 (duration %3)")
Chris@117 3359 .arg(startStr).arg(endStr).arg(durationStr);
Chris@117 3360 }
Chris@116 3361
Chris@116 3362 statusBar()->showMessage(m_myStatusMessage);
Chris@116 3363 }
Chris@116 3364
Chris@116 3365 void
Chris@0 3366 MainWindow::outputLevelsChanged(float left, float right)
Chris@0 3367 {
Chris@0 3368 m_fader->setPeakLeft(left);
Chris@0 3369 m_fader->setPeakRight(right);
Chris@0 3370 }
Chris@0 3371
Chris@0 3372 void
Chris@0 3373 MainWindow::sampleRateMismatch(size_t requested, size_t actual,
Chris@0 3374 bool willResample)
Chris@0 3375 {
Chris@0 3376 if (!willResample) {
Chris@247 3377 emit hideSplash();
Chris@0 3378 QMessageBox::information
Chris@0 3379 (this, tr("Sample rate mismatch"),
Chris@193 3380 tr("<b>Wrong sample rate</b><p>The sample rate of this audio file (%1 Hz) does not match\nthe current playback rate (%2 Hz).<p>The file will play at the wrong speed and pitch.<p>Change the <i>Resample mismatching files on import</i> option under <i>File</i> -> <i>Preferences</i> if you want to alter this behaviour.")
Chris@0 3381 .arg(requested).arg(actual));
Chris@0 3382 }
Chris@0 3383
Chris@0 3384 updateDescriptionLabel();
Chris@0 3385 }
Chris@0 3386
Chris@0 3387 void
Chris@42 3388 MainWindow::audioOverloadPluginDisabled()
Chris@42 3389 {
Chris@42 3390 QMessageBox::information
Chris@42 3391 (this, tr("Audio processing overload"),
Chris@193 3392 tr("<b>Overloaded</b><p>Audio effects plugin auditioning has been disabled due to a processing overload."));
Chris@42 3393 }
Chris@42 3394
Chris@42 3395 void
Chris@266 3396 MainWindow::audioTimeStretchMultiChannelDisabled()
Chris@266 3397 {
Chris@266 3398 static bool shownOnce = false;
Chris@266 3399 if (shownOnce) return;
Chris@266 3400 QMessageBox::information
Chris@266 3401 (this, tr("Audio processing overload"),
Chris@266 3402 tr("<b>Overloaded</b><p>Audio playback speed processing has been reduced to a single channel, due to a processing overload."));
Chris@266 3403 shownOnce = true;
Chris@266 3404 }
Chris@266 3405
Chris@266 3406 void
Chris@304 3407 MainWindow::midiEventsAvailable()
Chris@304 3408 {
Chris@304 3409 //!!! for now. but this won't do -- we are passing a signal/slot
Chris@304 3410 //!!! connection across threads here, so timing will not be good
Chris@304 3411 //!!! -- we do need to use the original midi event timestamp
Chris@304 3412 MIDIEvent ev(m_midiInput->readEvent());
Chris@304 3413 if (ev.getMessageType() == MIDIConstants::MIDI_NOTE_ON) {
Chris@304 3414 insertInstant();
Chris@304 3415 }
Chris@304 3416 }
Chris@304 3417
Chris@304 3418 void
Chris@200 3419 MainWindow::layerRemoved(Layer *layer)
Chris@0 3420 {
Chris@95 3421 setupExistingLayersMenus();
Chris@200 3422 MainWindowBase::layerRemoved(layer);
Chris@0 3423 }
Chris@0 3424
Chris@0 3425 void
Chris@0 3426 MainWindow::layerInAView(Layer *layer, bool inAView)
Chris@0 3427 {
Chris@95 3428 setupExistingLayersMenus();
Chris@200 3429 MainWindowBase::layerInAView(layer, inAView);
Chris@0 3430 }
Chris@0 3431
Chris@0 3432 void
Chris@0 3433 MainWindow::modelAdded(Model *model)
Chris@0 3434 {
Chris@200 3435 MainWindowBase::modelAdded(model);
Chris@66 3436 if (dynamic_cast<DenseTimeValueModel *>(model)) {
Chris@66 3437 setupPaneAndLayerMenus();
Chris@66 3438 }
Chris@0 3439 }
Chris@0 3440
Chris@0 3441 void
Chris@0 3442 MainWindow::mainModelChanged(WaveFileModel *model)
Chris@0 3443 {
Chris@0 3444 m_panLayer->setModel(model);
Chris@200 3445
Chris@200 3446 MainWindowBase::mainModelChanged(model);
Chris@200 3447
Chris@200 3448 if (m_playTarget) {
Chris@200 3449 connect(m_fader, SIGNAL(valueChanged(float)),
Chris@200 3450 m_playTarget, SLOT(setOutputGain(float)));
Chris@200 3451 }
Chris@0 3452 }
Chris@0 3453
Chris@0 3454 void
Chris@200 3455 MainWindow::setInstantsNumbering()
Chris@0 3456 {
Chris@200 3457 QAction *a = dynamic_cast<QAction *>(sender());
Chris@200 3458 if (!a) return;
Chris@200 3459
Chris@200 3460 int type = m_numberingActions[a];
Chris@200 3461
Chris@200 3462 if (m_labeller) m_labeller->setType(Labeller::ValueType(type));
Chris@200 3463
Chris@200 3464 QSettings settings;
Chris@200 3465 settings.beginGroup("MainWindow");
Chris@200 3466 settings.setValue("labellertype", type);
Chris@200 3467 settings.endGroup();
Chris@200 3468 }
Chris@200 3469
Chris@200 3470 void
Chris@200 3471 MainWindow::setInstantsCounterCycle()
Chris@200 3472 {
Chris@200 3473 QAction *a = dynamic_cast<QAction *>(sender());
Chris@200 3474 if (!a) return;
Chris@200 3475
Chris@200 3476 int cycle = a->text().toInt();
Chris@200 3477 if (cycle == 0) return;
Chris@200 3478
Chris@200 3479 if (m_labeller) m_labeller->setCounterCycleSize(cycle);
Chris@200 3480
Chris@200 3481 QSettings settings;
Chris@200 3482 settings.beginGroup("MainWindow");
Chris@200 3483 settings.setValue("labellercycle", cycle);
Chris@200 3484 settings.endGroup();
Chris@200 3485 }
Chris@200 3486
Chris@200 3487 void
Chris@200 3488 MainWindow::resetInstantsCounters()
Chris@200 3489 {
Chris@200 3490 LabelCounterInputDialog dialog(m_labeller, this);
Chris@241 3491 dialog.setWindowTitle(tr("Reset Counters"));
Chris@200 3492 dialog.exec();
Chris@0 3493 }
Chris@0 3494
Chris@0 3495 void
Chris@233 3496 MainWindow::modelGenerationFailed(QString transformName, QString message)
Chris@233 3497 {
Chris@247 3498 emit hideSplash();
Chris@247 3499
Chris@233 3500 if (message != "") {
Chris@233 3501
Chris@233 3502 QMessageBox::warning
Chris@233 3503 (this,
Chris@233 3504 tr("Failed to generate layer"),
Chris@233 3505 tr("<b>Layer generation failed</b><p>Failed to generate derived layer.<p>The layer transform \"%1\" failed:<p>%2")
Chris@233 3506 .arg(transformName).arg(message),
Chris@233 3507 QMessageBox::Ok);
Chris@233 3508 } else {
Chris@233 3509 QMessageBox::warning
Chris@233 3510 (this,
Chris@233 3511 tr("Failed to generate layer"),
Chris@233 3512 tr("<b>Layer generation failed</b><p>Failed to generate a derived layer.<p>The layer transform \"%1\" failed.<p>No error information is available.")
Chris@233 3513 .arg(transformName),
Chris@233 3514 QMessageBox::Ok);
Chris@233 3515 }
Chris@233 3516 }
Chris@233 3517
Chris@233 3518 void
Chris@233 3519 MainWindow::modelGenerationWarning(QString transformName, QString message)
Chris@233 3520 {
Chris@247 3521 emit hideSplash();
Chris@247 3522
Chris@233 3523 QMessageBox::warning
Chris@233 3524 (this, tr("Warning"), message, QMessageBox::Ok);
Chris@233 3525 }
Chris@233 3526
Chris@233 3527 void
Chris@233 3528 MainWindow::modelRegenerationFailed(QString layerName,
Chris@233 3529 QString transformName, QString message)
Chris@233 3530 {
Chris@247 3531 emit hideSplash();
Chris@247 3532
Chris@233 3533 if (message != "") {
Chris@233 3534
Chris@233 3535 QMessageBox::warning
Chris@233 3536 (this,
Chris@233 3537 tr("Failed to regenerate layer"),
Chris@233 3538 tr("<b>Layer generation failed</b><p>Failed to regenerate derived layer \"%1\" using new data model as input.<p>The layer transform \"%2\" failed:<p>%3")
Chris@233 3539 .arg(layerName).arg(transformName).arg(message),
Chris@233 3540 QMessageBox::Ok);
Chris@233 3541 } else {
Chris@233 3542 QMessageBox::warning
Chris@233 3543 (this,
Chris@233 3544 tr("Failed to regenerate layer"),
Chris@233 3545 tr("<b>Layer generation failed</b><p>Failed to regenerate derived layer \"%1\" using new data model as input.<p>The layer transform \"%2\" failed.<p>No error information is available.")
Chris@233 3546 .arg(layerName).arg(transformName),
Chris@233 3547 QMessageBox::Ok);
Chris@233 3548 }
Chris@233 3549 }
Chris@233 3550
Chris@233 3551 void
Chris@233 3552 MainWindow::modelRegenerationWarning(QString layerName,
Chris@233 3553 QString transformName, QString message)
Chris@233 3554 {
Chris@247 3555 emit hideSplash();
Chris@247 3556
Chris@233 3557 QMessageBox::warning
Chris@233 3558 (this, tr("Warning"), tr("<b>Warning when regenerating layer</b><p>When regenerating the derived layer \"%1\" using new data model as input:<p>%2").arg(layerName).arg(message), QMessageBox::Ok);
Chris@233 3559 }
Chris@233 3560
Chris@233 3561 void
Chris@233 3562 MainWindow::alignmentFailed(QString transformName, QString message)
Chris@0 3563 {
Chris@247 3564 emit hideSplash();
Chris@247 3565
Chris@0 3566 QMessageBox::warning
Chris@0 3567 (this,
Chris@233 3568 tr("Failed to calculate alignment"),
Chris@233 3569 tr("<b>Alignment calculation failed</b><p>Failed to calculate an audio alignment using transform \"%1\":<p>%2")
Chris@233 3570 .arg(transformName).arg(message),
Chris@165 3571 QMessageBox::Ok);
Chris@0 3572 }
Chris@0 3573
Chris@0 3574 void
Chris@0 3575 MainWindow::rightButtonMenuRequested(Pane *pane, QPoint position)
Chris@0 3576 {
Chris@0 3577 // std::cerr << "MainWindow::rightButtonMenuRequested(" << pane << ", " << position.x() << ", " << position.y() << ")" << std::endl;
Chris@0 3578 m_paneStack->setCurrentPane(pane);
Chris@0 3579 m_rightButtonMenu->popup(position);
Chris@0 3580 }
Chris@0 3581
Chris@0 3582 void
Chris@0 3583 MainWindow::showLayerTree()
Chris@0 3584 {
Chris@219 3585 if (!m_layerTreeDialog.isNull()) {
Chris@219 3586 m_layerTreeDialog->show();
Chris@219 3587 m_layerTreeDialog->raise();
Chris@177 3588 return;
Chris@177 3589 }
Chris@177 3590
Chris@219 3591 m_layerTreeDialog = new LayerTreeDialog(m_paneStack);
Chris@232 3592 m_layerTreeDialog->setAttribute(Qt::WA_DeleteOnClose); // see below
Chris@219 3593 m_layerTreeDialog->show();
Chris@0 3594 }
Chris@0 3595
Chris@0 3596 void
Chris@0 3597 MainWindow::preferences()
Chris@0 3598 {
Chris@0 3599 if (!m_preferencesDialog.isNull()) {
Chris@0 3600 m_preferencesDialog->show();
Chris@0 3601 m_preferencesDialog->raise();
Chris@0 3602 return;
Chris@0 3603 }
Chris@0 3604
Chris@0 3605 m_preferencesDialog = new PreferencesDialog(this);
Chris@0 3606
Chris@0 3607 // DeleteOnClose is safe here, because m_preferencesDialog is a
Chris@0 3608 // QPointer that will be zeroed when the dialog is deleted. We
Chris@0 3609 // use it in preference to leaving the dialog lying around because
Chris@0 3610 // if you Cancel the dialog, it resets the preferences state
Chris@0 3611 // without resetting its own widgets, so its state will be
Chris@0 3612 // incorrect when next shown unless we construct it afresh
Chris@0 3613 m_preferencesDialog->setAttribute(Qt::WA_DeleteOnClose);
Chris@0 3614
Chris@0 3615 m_preferencesDialog->show();
Chris@0 3616 }
Chris@0 3617
Chris@0 3618 void
Chris@90 3619 MainWindow::mouseEnteredWidget()
Chris@90 3620 {
Chris@90 3621 QWidget *w = dynamic_cast<QWidget *>(sender());
Chris@90 3622 if (!w) return;
Chris@90 3623
Chris@90 3624 if (w == m_fader) {
Chris@116 3625 contextHelpChanged(tr("Adjust the master playback level"));
Chris@90 3626 } else if (w == m_playSpeed) {
Chris@116 3627 contextHelpChanged(tr("Adjust the master playback speed"));
Chris@90 3628 }
Chris@90 3629 }
Chris@90 3630
Chris@90 3631 void
Chris@90 3632 MainWindow::mouseLeftWidget()
Chris@90 3633 {
Chris@116 3634 contextHelpChanged("");
Chris@116 3635 }
Chris@116 3636
Chris@116 3637 void
Chris@0 3638 MainWindow::website()
Chris@0 3639 {
Chris@0 3640 openHelpUrl(tr("http://www.sonicvisualiser.org/"));
Chris@0 3641 }
Chris@0 3642
Chris@0 3643 void
Chris@0 3644 MainWindow::help()
Chris@0 3645 {
Chris@285 3646 openHelpUrl(tr("http://www.sonicvisualiser.org/doc/reference/1.4/en/"));
Chris@0 3647 }
Chris@0 3648
Chris@0 3649 void
Chris@0 3650 MainWindow::about()
Chris@0 3651 {
Chris@0 3652 bool debug = false;
Chris@0 3653 QString version = "(unknown version)";
Chris@0 3654
Chris@0 3655 #ifdef BUILD_DEBUG
Chris@0 3656 debug = true;
Chris@285 3657 #endif // BUILD_DEBUG
Chris@0 3658 #ifdef SV_VERSION
Chris@0 3659 #ifdef SVNREV
Chris@0 3660 version = tr("Release %1 : Revision %2").arg(SV_VERSION).arg(SVNREV);
Chris@285 3661 #else // !SVNREV
Chris@0 3662 version = tr("Release %1").arg(SV_VERSION);
Chris@285 3663 #endif // SVNREV
Chris@285 3664 #else // !SV_VERSION
Chris@0 3665 #ifdef SVNREV
Chris@0 3666 version = tr("Unreleased : Revision %1").arg(SVNREV);
Chris@285 3667 #endif // SVNREV
Chris@285 3668 #endif // SV_VERSION
Chris@0 3669
Chris@0 3670 QString aboutText;
Chris@0 3671
Chris@0 3672 aboutText += tr("<h3>About Sonic Visualiser</h3>");
Chris@285 3673 aboutText += tr("<p>Sonic Visualiser is a program for viewing and exploring audio data for semantic music analysis and annotation.<br><a href=\"http://www.sonicvisualiser.org/\">http://www.sonicvisualiser.org/</a></p>");
Chris@285 3674 aboutText += tr("<p><small>%1 : %2 configuration</small></p>")
Chris@0 3675 .arg(version)
Chris@0 3676 .arg(debug ? tr("Debug") : tr("Release"));
Chris@0 3677
Chris@285 3678 aboutText += "<small>";
Chris@285 3679
Chris@285 3680 aboutText += tr("With Qt v%1 &copy; Nokia Corporation").arg(QT_VERSION_STR);
Chris@285 3681
Chris@0 3682 #ifdef HAVE_JACK
Chris@93 3683 #ifdef JACK_VERSION
Chris@285 3684 aboutText += tr("<br>With JACK audio output library v%1 &copy; Paul Davis and Jack O'Quin").arg(JACK_VERSION);
Chris@285 3685 #else // !JACK_VERSION
Chris@257 3686 aboutText += tr("<br>With JACK audio output library &copy; Paul Davis and Jack O'Quin");
Chris@285 3687 #endif // JACK_VERSION
Chris@285 3688 #endif // HAVE_JACK
Chris@0 3689 #ifdef HAVE_PORTAUDIO
Chris@257 3690 aboutText += tr("<br>With PortAudio audio output library &copy; Ross Bencina and Phil Burk");
Chris@285 3691 #endif // HAVE_PORTAUDIO
Chris@257 3692 #ifdef HAVE_LIBPULSE
Chris@285 3693 #ifdef LIBPULSE_VERSION
Chris@285 3694 aboutText += tr("<br>With PulseAudio audio output library v%1 &copy; Lennart Poettering and Pierre Ossman").arg(LIBPULSE_VERSION);
Chris@285 3695 #else // !LIBPULSE_VERSION
Chris@257 3696 aboutText += tr("<br>With PulseAudio audio output library &copy; Lennart Poettering and Pierre Ossman");
Chris@285 3697 #endif // LIBPULSE_VERSION
Chris@285 3698 #endif // HAVE_LIBPULSE
Chris@0 3699 #ifdef HAVE_OGGZ
Chris@93 3700 #ifdef OGGZ_VERSION
Chris@0 3701 aboutText += tr("<br>With Ogg file decoder (oggz v%1, fishsound v%2) &copy; CSIRO Australia").arg(OGGZ_VERSION).arg(FISHSOUND_VERSION);
Chris@285 3702 #else // !OGGZ_VERSION
Chris@93 3703 aboutText += tr("<br>With Ogg file decoder &copy; CSIRO Australia");
Chris@285 3704 #endif // OGGZ_VERSION
Chris@285 3705 #endif // HAVE_OGGZ
Chris@0 3706 #ifdef HAVE_MAD
Chris@93 3707 #ifdef MAD_VERSION
Chris@285 3708 aboutText += tr("<br>With MAD mp3 decoder v%1 &copy; Underbit Technologies Inc").arg(MAD_VERSION);
Chris@285 3709 #else // !MAD_VERSION
Chris@93 3710 aboutText += tr("<br>With MAD mp3 decoder &copy; Underbit Technologies Inc");
Chris@285 3711 #endif // MAD_VERSION
Chris@285 3712 #endif // HAVE_MAD
Chris@0 3713 #ifdef HAVE_SAMPLERATE
Chris@93 3714 #ifdef SAMPLERATE_VERSION
Chris@285 3715 aboutText += tr("<br>With libsamplerate v%1 &copy; Erik de Castro Lopo").arg(SAMPLERATE_VERSION);
Chris@285 3716 #else // !SAMPLERATE_VERSION
Chris@93 3717 aboutText += tr("<br>With libsamplerate &copy; Erik de Castro Lopo");
Chris@285 3718 #endif // SAMPLERATE_VERSION
Chris@285 3719 #endif // HAVE_SAMPLERATE
Chris@0 3720 #ifdef HAVE_SNDFILE
Chris@93 3721 #ifdef SNDFILE_VERSION
Chris@285 3722 aboutText += tr("<br>With libsndfile v%1 &copy; Erik de Castro Lopo").arg(SNDFILE_VERSION);
Chris@285 3723 #else // !SNDFILE_VERSION
Chris@93 3724 aboutText += tr("<br>With libsndfile &copy; Erik de Castro Lopo");
Chris@285 3725 #endif // SNDFILE_VERSION
Chris@285 3726 #endif // HAVE_SNDFILE
Chris@127 3727 #ifdef HAVE_FFTW3F
Chris@93 3728 #ifdef FFTW3_VERSION
Chris@285 3729 aboutText += tr("<br>With FFTW3 v%1 &copy; Matteo Frigo and MIT").arg(FFTW3_VERSION);
Chris@285 3730 #else // !FFTW3_VERSION
Chris@93 3731 aboutText += tr("<br>With FFTW3 &copy; Matteo Frigo and MIT");
Chris@285 3732 #endif // FFTW3_VERSION
Chris@285 3733 #endif // HAVE_FFTW3F
Chris@267 3734 #ifdef HAVE_RUBBERBAND
Chris@267 3735 #ifdef RUBBERBAND_VERSION
Chris@285 3736 aboutText += tr("<br>With Rubber Band v%1 &copy; Chris Cannam").arg(RUBBERBAND_VERSION);
Chris@285 3737 #else // !RUBBERBAND_VERSION
Chris@267 3738 aboutText += tr("<br>With Rubber Band &copy; Chris Cannam");
Chris@285 3739 #endif // RUBBERBAND_VERSION
Chris@285 3740 #endif // HAVE_RUBBERBAND
Chris@0 3741 #ifdef HAVE_VAMP
Chris@114 3742 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@285 3743 #endif // !HAVE_VAMP
Chris@0 3744 aboutText += tr("<br>With LADSPA plugin support (API v%1) &copy; Richard Furse, Paul Davis, Stefan Westerfeld").arg(LADSPA_VERSION);
Chris@0 3745 aboutText += tr("<br>With DSSI plugin support (API v%1) &copy; Chris Cannam, Steve Harris, Sean Bolton").arg(DSSI_VERSION);
Chris@285 3746 #ifdef RAPTOR_VERSION
Chris@285 3747 aboutText += tr("<br>With Raptor RDF parser v%1 &copy; Dave Beckett and the University of Bristol").arg(RAPTOR_VERSION);
Chris@285 3748 #else // !RAPTOR_VERSION
Chris@285 3749 aboutText += tr("<br>With Raptor RDF parser &copy; Dave Beckett and the University of Bristol");
Chris@285 3750 #endif // RAPTOR_VERSION
Chris@285 3751 #ifdef RASQAL_VERSION
Chris@285 3752 aboutText += tr("<br>With Rasqal RDF query engine v%1 &copy; Dave Beckett and the University of Bristol").arg(RASQAL_VERSION);
Chris@285 3753 #else // !RASQAL_VERSION
Chris@285 3754 aboutText += tr("<br>With Rasqal RDF query engine &copy; Dave Beckett and the University of Bristol");
Chris@285 3755 #endif // RASQAL_VERSION
Chris@285 3756 #ifdef HAVE_REDLAND
Chris@285 3757 #ifdef REDLAND_VERSION
Chris@285 3758 aboutText += tr("<br>With Redland RDF datastore v%1 &copy; Dave Beckett and the University of Bristol").arg(REDLAND_VERSION);
Chris@285 3759 #else // !REDLAND_VERSION
Chris@285 3760 aboutText += tr("<br>With Redland RDF datastore &copy; Dave Beckett and the University of Bristol");
Chris@285 3761 #endif // REDLAND_VERSION
Chris@285 3762 #endif // HAVE_REDLAND
Chris@285 3763
Chris@300 3764 aboutText += tr("<br>With RtMidi &copy; Gary P. Scavone");
Chris@300 3765
Chris@69 3766 #ifdef HAVE_LIBLO
Chris@93 3767 #ifdef LIBLO_VERSION
Chris@285 3768 aboutText += tr("<br>With liblo Lite OSC library v%1 &copy; Steve Harris").arg(LIBLO_VERSION);
Chris@285 3769 #else // !LIBLO_VERSION
Chris@93 3770 aboutText += tr("<br>With liblo Lite OSC library &copy; Steve Harris").arg(LIBLO_VERSION);
Chris@285 3771 #endif // LIBLO_VERSION
Chris@285 3772
Chris@285 3773 if (m_oscQueue && m_oscQueue->isOK()) {
Chris@285 3774 aboutText += tr("</small><p><small>The OSC URL for this instance is: \"%1\"").arg(m_oscQueue->getOSCURL());
Chris@285 3775 }
Chris@285 3776
Chris@285 3777 aboutText += "</small></p>";
Chris@285 3778 #endif // HAVE_LIBLO
Chris@285 3779
Chris@285 3780 #ifndef BUILD_STATIC
Chris@285 3781 aboutText.replace(tr("With "), tr("Using "));
Chris@93 3782 #endif
Chris@0 3783
Chris@0 3784 aboutText +=
Chris@300 3785 "<p><small>Sonic Visualiser Copyright &copy; 2005&ndash;2009 Chris Cannam and "
Chris@285 3786 "Queen Mary, University of London.</small></p>"
Chris@285 3787 "<p><small>This program is free software; you can redistribute it and/or "
Chris@231 3788 "modify it under the terms of the GNU General Public License as "
Chris@231 3789 "published by the Free Software Foundation; either version 2 of the "
Chris@0 3790 "License, or (at your option) any later version.<br>See the file "
Chris@285 3791 "COPYING included with this distribution for more information.</small></p>";
Chris@0 3792
Chris@0 3793 QMessageBox::about(this, tr("About Sonic Visualiser"), aboutText);
Chris@0 3794 }
Chris@0 3795
Chris@162 3796 void
Chris@162 3797 MainWindow::keyReference()
Chris@162 3798 {
Chris@162 3799 m_keyReference->show();
Chris@162 3800 }
Chris@162 3801
Chris@294 3802