annotate main/MainWindow.cpp @ 332:b168df820681

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