annotate main/MainWindow.cpp @ 257:6e8ebc86119a

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