annotate main/MainWindow.cpp @ 258:a31c65904a49

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