annotate main/MainWindow.cpp @ 264:15e6c49c759e

* start play-tracking toggle in data editor dialog
author Chris Cannam
date Tue, 17 Jun 2008 16:24:50 +0000
parents 2b4a4b8c465a
children d55e4c0f7d9e
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@261 212 m_playSpeed->setFixedWidth(32);
Chris@261 213 m_playSpeed->setFixedHeight(32);
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@258 1183 QAction *eaction = new QAction(tr("Edit Layer Data"), this);
Chris@258 1184 eaction->setShortcut(tr("E"));
Chris@258 1185 eaction->setStatusTip(tr("Edit the currently active layer as a data grid"));
Chris@258 1186 connect(eaction, SIGNAL(triggered()), this, SLOT(editCurrentLayer()));
Chris@258 1187 connect(this, SIGNAL(canEditLayer(bool)), eaction, SLOT(setEnabled(bool)));
Chris@258 1188 menu->addAction(eaction);
Chris@258 1189 m_rightButtonLayerMenu->addAction(eaction);
Chris@258 1190
Chris@168 1191 action = new QAction(il.load("editdelete"), tr("&Delete Layer"), this);
Chris@155 1192 action->setShortcut(tr("Ctrl+D"));
Chris@66 1193 action->setStatusTip(tr("Delete the currently active layer"));
Chris@66 1194 connect(action, SIGNAL(triggered()), this, SLOT(deleteCurrentLayer()));
Chris@66 1195 connect(this, SIGNAL(canDeleteCurrentLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@162 1196 m_keyReference->registerShortcut(action);
Chris@66 1197 menu->addAction(action);
Chris@66 1198 m_rightButtonLayerMenu->addAction(action);
Chris@163 1199
Chris@163 1200 m_keyReference->registerShortcut(raction); // rename after delete, so delete layer goes next to delete pane
Chris@258 1201 m_keyReference->registerShortcut(eaction); // edit also after delete
Chris@66 1202 }
Chris@66 1203
Chris@66 1204 void
Chris@211 1205 MainWindow::setupTransformsMenu()
Chris@66 1206 {
Chris@34 1207 if (m_transformsMenu) {
Chris@34 1208 m_transformActions.clear();
Chris@34 1209 m_transformActionsReverse.clear();
Chris@34 1210 m_transformsMenu->clear();
Chris@34 1211 } else {
Chris@97 1212 m_transformsMenu = menuBar()->addMenu(tr("&Transform"));
Chris@97 1213 m_transformsMenu->setTearOffEnabled(true);
Chris@97 1214 }
Chris@34 1215
Chris@210 1216 TransformList transforms =
Chris@224 1217 TransformFactory::getInstance()->getAllTransformDescriptions();
Chris@0 1218
Chris@33 1219 vector<QString> types =
Chris@211 1220 TransformFactory::getInstance()->getAllTransformTypes();
Chris@0 1221
Chris@37 1222 map<QString, map<QString, SubdividingMenu *> > categoryMenus;
Chris@37 1223 map<QString, map<QString, SubdividingMenu *> > makerMenus;
Chris@33 1224
Chris@36 1225 map<QString, SubdividingMenu *> byPluginNameMenus;
Chris@33 1226 map<QString, map<QString, QMenu *> > pluginNameMenus;
Chris@33 1227
Chris@37 1228 set<SubdividingMenu *> pendingMenus;
Chris@37 1229
Chris@211 1230 m_recentTransformsMenu = m_transformsMenu->addMenu(tr("&Recent Transforms"));
Chris@211 1231 m_recentTransformsMenu->setTearOffEnabled(true);
Chris@211 1232 m_rightButtonTransformsMenu->addMenu(m_recentTransformsMenu);
Chris@211 1233 connect(&m_recentTransforms, SIGNAL(recentChanged()),
Chris@211 1234 this, SLOT(setupRecentTransformsMenu()));
Chris@34 1235
Chris@34 1236 m_transformsMenu->addSeparator();
Chris@211 1237 m_rightButtonTransformsMenu->addSeparator();
Chris@34 1238
Chris@33 1239 for (vector<QString>::iterator i = types.begin(); i != types.end(); ++i) {
Chris@33 1240
Chris@33 1241 if (i != types.begin()) {
Chris@34 1242 m_transformsMenu->addSeparator();
Chris@211 1243 m_rightButtonTransformsMenu->addSeparator();
Chris@33 1244 }
Chris@33 1245
Chris@33 1246 QString byCategoryLabel = tr("%1 by Category").arg(*i);
Chris@37 1247 SubdividingMenu *byCategoryMenu = new SubdividingMenu(byCategoryLabel,
Chris@37 1248 20, 40);
Chris@97 1249 byCategoryMenu->setTearOffEnabled(true);
Chris@37 1250 m_transformsMenu->addMenu(byCategoryMenu);
Chris@211 1251 m_rightButtonTransformsMenu->addMenu(byCategoryMenu);
Chris@37 1252 pendingMenus.insert(byCategoryMenu);
Chris@33 1253
Chris@33 1254 vector<QString> categories =
Chris@211 1255 TransformFactory::getInstance()->getTransformCategories(*i);
Chris@33 1256
Chris@33 1257 for (vector<QString>::iterator j = categories.begin();
Chris@33 1258 j != categories.end(); ++j) {
Chris@33 1259
Chris@33 1260 QString category = *j;
Chris@33 1261 if (category == "") category = tr("Unclassified");
Chris@33 1262
Chris@33 1263 if (categories.size() < 2) {
Chris@33 1264 categoryMenus[*i][category] = byCategoryMenu;
Chris@33 1265 continue;
Chris@33 1266 }
Chris@33 1267
Chris@33 1268 QStringList components = category.split(" > ");
Chris@33 1269 QString key;
Chris@33 1270
Chris@33 1271 for (QStringList::iterator k = components.begin();
Chris@33 1272 k != components.end(); ++k) {
Chris@33 1273
Chris@33 1274 QString parentKey = key;
Chris@33 1275 if (key != "") key += " > ";
Chris@33 1276 key += *k;
Chris@33 1277
Chris@33 1278 if (categoryMenus[*i].find(key) == categoryMenus[*i].end()) {
Chris@37 1279 SubdividingMenu *m = new SubdividingMenu(*k, 20, 40);
Chris@97 1280 m->setTearOffEnabled(true);
Chris@37 1281 pendingMenus.insert(m);
Chris@37 1282 categoryMenus[*i][key] = m;
Chris@33 1283 if (parentKey == "") {
Chris@37 1284 byCategoryMenu->addMenu(m);
Chris@33 1285 } else {
Chris@37 1286 categoryMenus[*i][parentKey]->addMenu(m);
Chris@33 1287 }
Chris@33 1288 }
Chris@33 1289 }
Chris@33 1290 }
Chris@33 1291
Chris@34 1292 QString byPluginNameLabel = tr("%1 by Plugin Name").arg(*i);
Chris@36 1293 byPluginNameMenus[*i] = new SubdividingMenu(byPluginNameLabel);
Chris@97 1294 byPluginNameMenus[*i]->setTearOffEnabled(true);
Chris@36 1295 m_transformsMenu->addMenu(byPluginNameMenus[*i]);
Chris@211 1296 m_rightButtonTransformsMenu->addMenu(byPluginNameMenus[*i]);
Chris@37 1297 pendingMenus.insert(byPluginNameMenus[*i]);
Chris@34 1298
Chris@33 1299 QString byMakerLabel = tr("%1 by Maker").arg(*i);
Chris@37 1300 SubdividingMenu *byMakerMenu = new SubdividingMenu(byMakerLabel, 20, 40);
Chris@97 1301 byMakerMenu->setTearOffEnabled(true);
Chris@37 1302 m_transformsMenu->addMenu(byMakerMenu);
Chris@211 1303 m_rightButtonTransformsMenu->addMenu(byMakerMenu);
Chris@37 1304 pendingMenus.insert(byMakerMenu);
Chris@33 1305
Chris@33 1306 vector<QString> makers =
Chris@211 1307 TransformFactory::getInstance()->getTransformMakers(*i);
Chris@37 1308
Chris@33 1309 for (vector<QString>::iterator j = makers.begin();
Chris@33 1310 j != makers.end(); ++j) {
Chris@33 1311
Chris@33 1312 QString maker = *j;
Chris@33 1313 if (maker == "") maker = tr("Unknown");
Chris@55 1314 maker.replace(QRegExp(tr(" [\\(<].*$")), "");
Chris@55 1315
Chris@37 1316 makerMenus[*i][maker] = new SubdividingMenu(maker, 30, 40);
Chris@97 1317 makerMenus[*i][maker]->setTearOffEnabled(true);
Chris@37 1318 byMakerMenu->addMenu(makerMenus[*i][maker]);
Chris@37 1319 pendingMenus.insert(makerMenus[*i][maker]);
Chris@33 1320 }
Chris@0 1321 }
Chris@0 1322
Chris@230 1323 // Names should only be duplicated here if they have the same
Chris@230 1324 // plugin name, output name and maker but are in different library
Chris@230 1325 // .so names -- that won't happen often I hope
Chris@230 1326 std::map<QString, QString> idNameSonameMap;
Chris@230 1327 std::set<QString> seenNames, duplicateNames;
Chris@230 1328 for (unsigned int i = 0; i < transforms.size(); ++i) {
Chris@230 1329 QString name = transforms[i].name;
Chris@230 1330 if (seenNames.find(name) != seenNames.end()) {
Chris@230 1331 duplicateNames.insert(name);
Chris@230 1332 } else {
Chris@230 1333 seenNames.insert(name);
Chris@230 1334 }
Chris@230 1335 }
Chris@230 1336
Chris@0 1337 for (unsigned int i = 0; i < transforms.size(); ++i) {
Chris@0 1338
Chris@107 1339 QString name = transforms[i].name;
Chris@107 1340 if (name == "") name = transforms[i].identifier;
Chris@107 1341
Chris@107 1342 // std::cerr << "Plugin Name: " << name.toStdString() << std::endl;
Chris@80 1343
Chris@33 1344 QString type = transforms[i].type;
Chris@33 1345
Chris@33 1346 QString category = transforms[i].category;
Chris@33 1347 if (category == "") category = tr("Unclassified");
Chris@33 1348
Chris@33 1349 QString maker = transforms[i].maker;
Chris@33 1350 if (maker == "") maker = tr("Unknown");
Chris@55 1351 maker.replace(QRegExp(tr(" [\\(<].*$")), "");
Chris@33 1352
Chris@107 1353 QString pluginName = name.section(": ", 0, 0);
Chris@107 1354 QString output = name.section(": ", 1);
Chris@107 1355
Chris@230 1356 if (duplicateNames.find(pluginName) != duplicateNames.end()) {
Chris@230 1357 pluginName = QString("%1 <%2>")
Chris@230 1358 .arg(pluginName)
Chris@230 1359 .arg(transforms[i].identifier.section(':', 1, 1));
Chris@230 1360 if (output == "") name = pluginName;
Chris@230 1361 else name = QString("%1: %2")
Chris@230 1362 .arg(pluginName)
Chris@230 1363 .arg(output);
Chris@230 1364 }
Chris@230 1365
Chris@107 1366 QAction *action = new QAction(tr("%1...").arg(name), this);
Chris@0 1367 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@107 1368 m_transformActions[action] = transforms[i].identifier;
Chris@107 1369 m_transformActionsReverse[transforms[i].identifier] = action;
Chris@0 1370 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@33 1371
Chris@108 1372 action->setStatusTip(transforms[i].description);
Chris@90 1373
Chris@33 1374 if (categoryMenus[type].find(category) == categoryMenus[type].end()) {
Chris@33 1375 std::cerr << "WARNING: MainWindow::setupMenus: Internal error: "
Chris@33 1376 << "No category menu for transform \""
Chris@107 1377 << name.toStdString() << "\" (category = \""
Chris@33 1378 << category.toStdString() << "\")" << std::endl;
Chris@33 1379 } else {
Chris@33 1380 categoryMenus[type][category]->addAction(action);
Chris@33 1381 }
Chris@33 1382
Chris@33 1383 if (makerMenus[type].find(maker) == makerMenus[type].end()) {
Chris@33 1384 std::cerr << "WARNING: MainWindow::setupMenus: Internal error: "
Chris@33 1385 << "No maker menu for transform \""
Chris@107 1386 << name.toStdString() << "\" (maker = \""
Chris@33 1387 << maker.toStdString() << "\")" << std::endl;
Chris@33 1388 } else {
Chris@80 1389 makerMenus[type][maker]->addAction(action);
Chris@33 1390 }
Chris@33 1391
Chris@33 1392 action = new QAction(tr("%1...").arg(output == "" ? pluginName : output), this);
Chris@33 1393 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@107 1394 m_transformActions[action] = transforms[i].identifier;
Chris@33 1395 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@108 1396 action->setStatusTip(transforms[i].description);
Chris@33 1397
Chris@211 1398 // cerr << "Transform: \"" << name.toStdString() << "\": plugin name \"" << pluginName.toStdString() << "\"" << endl;
Chris@34 1399
Chris@33 1400 if (pluginNameMenus[type].find(pluginName) ==
Chris@33 1401 pluginNameMenus[type].end()) {
Chris@33 1402
Chris@36 1403 SubdividingMenu *parentMenu = byPluginNameMenus[type];
Chris@97 1404 parentMenu->setTearOffEnabled(true);
Chris@34 1405
Chris@33 1406 if (output == "") {
Chris@36 1407 parentMenu->addAction(pluginName, action);
Chris@33 1408 } else {
Chris@34 1409 pluginNameMenus[type][pluginName] =
Chris@34 1410 parentMenu->addMenu(pluginName);
Chris@33 1411 connect(this, SIGNAL(canAddLayer(bool)),
Chris@33 1412 pluginNameMenus[type][pluginName],
Chris@33 1413 SLOT(setEnabled(bool)));
Chris@33 1414 }
Chris@33 1415 }
Chris@33 1416
Chris@33 1417 if (pluginNameMenus[type].find(pluginName) !=
Chris@33 1418 pluginNameMenus[type].end()) {
Chris@33 1419 pluginNameMenus[type][pluginName]->addAction(action);
Chris@33 1420 }
Chris@0 1421 }
Chris@0 1422
Chris@37 1423 for (set<SubdividingMenu *>::iterator i = pendingMenus.begin();
Chris@37 1424 i != pendingMenus.end(); ++i) {
Chris@37 1425 (*i)->entriesAdded();
Chris@37 1426 }
Chris@37 1427
Chris@211 1428 setupRecentTransformsMenu();
Chris@66 1429 }
Chris@66 1430
Chris@66 1431 void
Chris@66 1432 MainWindow::setupHelpMenu()
Chris@66 1433 {
Chris@66 1434 QMenu *menu = menuBar()->addMenu(tr("&Help"));
Chris@97 1435 menu->setTearOffEnabled(true);
Chris@66 1436
Chris@162 1437 m_keyReference->setCategory(tr("Help"));
Chris@162 1438
Chris@168 1439 IconLoader il;
Chris@168 1440
Chris@168 1441 QAction *action = new QAction(il.load("help"),
Chris@138 1442 tr("&Help Reference"), this);
Chris@162 1443 action->setShortcut(tr("F1"));
Chris@66 1444 action->setStatusTip(tr("Open the Sonic Visualiser reference manual"));
Chris@66 1445 connect(action, SIGNAL(triggered()), this, SLOT(help()));
Chris@162 1446 m_keyReference->registerShortcut(action);
Chris@0 1447 menu->addAction(action);
Chris@162 1448
Chris@163 1449 action = new QAction(tr("&Key and Mouse Reference"), this);
Chris@162 1450 action->setShortcut(tr("F2"));
Chris@162 1451 action->setStatusTip(tr("Open a window showing the keystrokes you can use in Sonic Visualiser"));
Chris@162 1452 connect(action, SIGNAL(triggered()), this, SLOT(keyReference()));
Chris@162 1453 m_keyReference->registerShortcut(action);
Chris@162 1454 menu->addAction(action);
Chris@66 1455
Chris@164 1456 action = new QAction(tr("Sonic Visualiser on the &Web"), this);
Chris@164 1457 action->setStatusTip(tr("Open the Sonic Visualiser website"));
Chris@164 1458 connect(action, SIGNAL(triggered()), this, SLOT(website()));
Chris@164 1459 menu->addAction(action);
Chris@164 1460
Chris@66 1461 action = new QAction(tr("&About Sonic Visualiser"), this);
Chris@66 1462 action->setStatusTip(tr("Show information about Sonic Visualiser"));
Chris@66 1463 connect(action, SIGNAL(triggered()), this, SLOT(about()));
Chris@0 1464 menu->addAction(action);
Chris@0 1465 }
Chris@0 1466
Chris@0 1467 void
Chris@0 1468 MainWindow::setupRecentFilesMenu()
Chris@0 1469 {
Chris@0 1470 m_recentFilesMenu->clear();
Chris@34 1471 vector<QString> files = m_recentFiles.getRecent();
Chris@0 1472 for (size_t i = 0; i < files.size(); ++i) {
Chris@0 1473 QAction *action = new QAction(files[i], this);
Chris@0 1474 connect(action, SIGNAL(triggered()), this, SLOT(openRecentFile()));
Chris@162 1475 if (i == 0) {
Chris@162 1476 action->setShortcut(tr("Ctrl+R"));
Chris@162 1477 m_keyReference->registerShortcut
Chris@163 1478 (tr("Re-open"),
Chris@163 1479 action->shortcut(),
Chris@163 1480 tr("Re-open the current or most recently opened file"));
Chris@162 1481 }
Chris@0 1482 m_recentFilesMenu->addAction(action);
Chris@0 1483 }
Chris@0 1484 }
Chris@0 1485
Chris@0 1486 void
Chris@211 1487 MainWindow::setupRecentTransformsMenu()
Chris@34 1488 {
Chris@211 1489 m_recentTransformsMenu->clear();
Chris@211 1490 vector<QString> transforms = m_recentTransforms.getRecent();
Chris@34 1491 for (size_t i = 0; i < transforms.size(); ++i) {
Chris@211 1492 TransformActionReverseMap::iterator ti =
Chris@34 1493 m_transformActionsReverse.find(transforms[i]);
Chris@34 1494 if (ti == m_transformActionsReverse.end()) {
Chris@211 1495 std::cerr << "WARNING: MainWindow::setupRecentTransformsMenu: "
Chris@34 1496 << "Unknown transform \"" << transforms[i].toStdString()
Chris@34 1497 << "\" in recent transforms list" << std::endl;
Chris@34 1498 continue;
Chris@34 1499 }
Chris@162 1500 if (i == 0) {
Chris@162 1501 ti->second->setShortcut(tr("Ctrl+T"));
Chris@162 1502 m_keyReference->registerShortcut
Chris@211 1503 (tr("Repeat Transform"),
Chris@162 1504 ti->second->shortcut(),
Chris@163 1505 tr("Re-select the most recently run transform"));
Chris@216 1506 } else {
Chris@216 1507 ti->second->setShortcut(QString(""));
Chris@162 1508 }
Chris@211 1509 m_recentTransformsMenu->addAction(ti->second);
Chris@34 1510 }
Chris@34 1511 }
Chris@34 1512
Chris@34 1513 void
Chris@95 1514 MainWindow::setupExistingLayersMenus()
Chris@0 1515 {
Chris@0 1516 if (!m_existingLayersMenu) return; // should have been created by setupMenus
Chris@0 1517
Chris@0 1518 // std::cerr << "MainWindow::setupExistingLayersMenu" << std::endl;
Chris@0 1519
Chris@0 1520 m_existingLayersMenu->clear();
Chris@0 1521 m_existingLayerActions.clear();
Chris@0 1522
Chris@95 1523 m_sliceMenu->clear();
Chris@95 1524 m_sliceActions.clear();
Chris@95 1525
Chris@168 1526 IconLoader il;
Chris@168 1527
Chris@33 1528 vector<Layer *> orderedLayers;
Chris@33 1529 set<Layer *> observedLayers;
Chris@95 1530 set<Layer *> sliceableLayers;
Chris@95 1531
Chris@95 1532 LayerFactory *factory = LayerFactory::getInstance();
Chris@0 1533
Chris@0 1534 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@0 1535
Chris@0 1536 Pane *pane = m_paneStack->getPane(i);
Chris@0 1537 if (!pane) continue;
Chris@0 1538
Chris@0 1539 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@0 1540
Chris@0 1541 Layer *layer = pane->getLayer(j);
Chris@0 1542 if (!layer) continue;
Chris@0 1543 if (observedLayers.find(layer) != observedLayers.end()) {
Chris@137 1544 // std::cerr << "found duplicate layer " << layer << std::endl;
Chris@0 1545 continue;
Chris@0 1546 }
Chris@0 1547
Chris@0 1548 // std::cerr << "found new layer " << layer << " (name = "
Chris@0 1549 // << layer->getLayerPresentationName().toStdString() << ")" << std::endl;
Chris@0 1550
Chris@0 1551 orderedLayers.push_back(layer);
Chris@0 1552 observedLayers.insert(layer);
Chris@95 1553
Chris@95 1554 if (factory->isLayerSliceable(layer)) {
Chris@95 1555 sliceableLayers.insert(layer);
Chris@95 1556 }
Chris@0 1557 }
Chris@0 1558 }
Chris@0 1559
Chris@33 1560 map<QString, int> observedNames;
Chris@0 1561
Chris@137 1562 for (size_t i = 0; i < orderedLayers.size(); ++i) {
Chris@0 1563
Chris@95 1564 Layer *layer = orderedLayers[i];
Chris@95 1565
Chris@95 1566 QString name = layer->getLayerPresentationName();
Chris@0 1567 int n = ++observedNames[name];
Chris@0 1568 if (n > 1) name = QString("%1 <%2>").arg(name).arg(n);
Chris@0 1569
Chris@168 1570 QIcon icon = il.load(factory->getLayerIconName
Chris@168 1571 (factory->getLayerType(layer)));
Chris@95 1572
Chris@95 1573 QAction *action = new QAction(icon, name, this);
Chris@0 1574 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@0 1575 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@95 1576 m_existingLayerActions[action] = layer;
Chris@0 1577
Chris@0 1578 m_existingLayersMenu->addAction(action);
Chris@95 1579
Chris@95 1580 if (sliceableLayers.find(layer) != sliceableLayers.end()) {
Chris@95 1581 action = new QAction(icon, name, this);
Chris@95 1582 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@95 1583 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@95 1584 m_sliceActions[action] = layer;
Chris@95 1585 m_sliceMenu->addAction(action);
Chris@95 1586 }
Chris@0 1587 }
Chris@95 1588
Chris@95 1589 m_sliceMenu->setEnabled(!m_sliceActions.empty());
Chris@0 1590 }
Chris@0 1591
Chris@0 1592 void
Chris@0 1593 MainWindow::setupToolbars()
Chris@0 1594 {
Chris@162 1595 m_keyReference->setCategory(tr("Playback and Transport Controls"));
Chris@162 1596
Chris@168 1597 IconLoader il;
Chris@168 1598
Chris@155 1599 QMenu *menu = m_playbackMenu = menuBar()->addMenu(tr("Play&back"));
Chris@155 1600 menu->setTearOffEnabled(true);
Chris@155 1601 m_rightButtonMenu->addSeparator();
Chris@155 1602 m_rightButtonPlaybackMenu = m_rightButtonMenu->addMenu(tr("Playback"));
Chris@155 1603
Chris@155 1604 QToolBar *toolbar = addToolBar(tr("Playback Toolbar"));
Chris@155 1605
Chris@168 1606 QAction *rwdStartAction = toolbar->addAction(il.load("rewind-start"),
Chris@155 1607 tr("Rewind to Start"));
Chris@155 1608 rwdStartAction->setShortcut(tr("Home"));
Chris@155 1609 rwdStartAction->setStatusTip(tr("Rewind to the start"));
Chris@155 1610 connect(rwdStartAction, SIGNAL(triggered()), this, SLOT(rewindStart()));
Chris@155 1611 connect(this, SIGNAL(canPlay(bool)), rwdStartAction, SLOT(setEnabled(bool)));
Chris@155 1612
Chris@168 1613 QAction *m_rwdAction = toolbar->addAction(il.load("rewind"),
Chris@155 1614 tr("Rewind"));
Chris@155 1615 m_rwdAction->setShortcut(tr("PgUp"));
Chris@163 1616 m_rwdAction->setStatusTip(tr("Rewind to the previous time instant or time ruler notch"));
Chris@155 1617 connect(m_rwdAction, SIGNAL(triggered()), this, SLOT(rewind()));
Chris@155 1618 connect(this, SIGNAL(canRewind(bool)), m_rwdAction, SLOT(setEnabled(bool)));
Chris@155 1619
Chris@168 1620 QAction *playAction = toolbar->addAction(il.load("playpause"),
Chris@155 1621 tr("Play / Pause"));
Chris@155 1622 playAction->setCheckable(true);
Chris@155 1623 playAction->setShortcut(tr("Space"));
Chris@155 1624 playAction->setStatusTip(tr("Start or stop playback from the current position"));
Chris@155 1625 connect(playAction, SIGNAL(triggered()), this, SLOT(play()));
Chris@0 1626 connect(m_playSource, SIGNAL(playStatusChanged(bool)),
Chris@155 1627 playAction, SLOT(setChecked(bool)));
Chris@155 1628 connect(this, SIGNAL(canPlay(bool)), playAction, SLOT(setEnabled(bool)));
Chris@155 1629
Chris@168 1630 m_ffwdAction = toolbar->addAction(il.load("ffwd"),
Chris@155 1631 tr("Fast Forward"));
Chris@155 1632 m_ffwdAction->setShortcut(tr("PgDown"));
Chris@163 1633 m_ffwdAction->setStatusTip(tr("Fast-forward to the next time instant or time ruler notch"));
Chris@155 1634 connect(m_ffwdAction, SIGNAL(triggered()), this, SLOT(ffwd()));
Chris@155 1635 connect(this, SIGNAL(canFfwd(bool)), m_ffwdAction, SLOT(setEnabled(bool)));
Chris@155 1636
Chris@168 1637 QAction *ffwdEndAction = toolbar->addAction(il.load("ffwd-end"),
Chris@155 1638 tr("Fast Forward to End"));
Chris@155 1639 ffwdEndAction->setShortcut(tr("End"));
Chris@155 1640 ffwdEndAction->setStatusTip(tr("Fast-forward to the end"));
Chris@155 1641 connect(ffwdEndAction, SIGNAL(triggered()), this, SLOT(ffwdEnd()));
Chris@155 1642 connect(this, SIGNAL(canPlay(bool)), ffwdEndAction, SLOT(setEnabled(bool)));
Chris@0 1643
Chris@0 1644 toolbar = addToolBar(tr("Play Mode Toolbar"));
Chris@0 1645
Chris@168 1646 QAction *psAction = toolbar->addAction(il.load("playselection"),
Chris@155 1647 tr("Constrain Playback to Selection"));
Chris@155 1648 psAction->setCheckable(true);
Chris@155 1649 psAction->setChecked(m_viewManager->getPlaySelectionMode());
Chris@155 1650 psAction->setShortcut(tr("s"));
Chris@163 1651 psAction->setStatusTip(tr("Constrain playback to the selected regions"));
Chris@69 1652 connect(m_viewManager, SIGNAL(playSelectionModeChanged(bool)),
Chris@155 1653 psAction, SLOT(setChecked(bool)));
Chris@155 1654 connect(psAction, SIGNAL(triggered()), this, SLOT(playSelectionToggled()));
Chris@155 1655 connect(this, SIGNAL(canPlaySelection(bool)), psAction, SLOT(setEnabled(bool)));
Chris@155 1656
Chris@168 1657 QAction *plAction = toolbar->addAction(il.load("playloop"),
Chris@155 1658 tr("Loop Playback"));
Chris@155 1659 plAction->setCheckable(true);
Chris@155 1660 plAction->setChecked(m_viewManager->getPlayLoopMode());
Chris@155 1661 plAction->setShortcut(tr("l"));
Chris@155 1662 plAction->setStatusTip(tr("Loop playback"));
Chris@69 1663 connect(m_viewManager, SIGNAL(playLoopModeChanged(bool)),
Chris@155 1664 plAction, SLOT(setChecked(bool)));
Chris@155 1665 connect(plAction, SIGNAL(triggered()), this, SLOT(playLoopToggled()));
Chris@155 1666 connect(this, SIGNAL(canPlay(bool)), plAction, SLOT(setEnabled(bool)));
Chris@155 1667
Chris@207 1668 m_soloAction = toolbar->addAction(il.load("solo"),
Chris@180 1669 tr("Solo Current Pane"));
Chris@207 1670 m_soloAction->setCheckable(true);
Chris@207 1671 m_soloAction->setChecked(m_viewManager->getPlaySoloMode());
Chris@207 1672 m_prevSolo = m_viewManager->getPlaySoloMode();
Chris@207 1673 m_soloAction->setShortcut(tr("o"));
Chris@207 1674 m_soloAction->setStatusTip(tr("Solo the current pane during playback"));
Chris@180 1675 connect(m_viewManager, SIGNAL(playSoloModeChanged(bool)),
Chris@207 1676 m_soloAction, SLOT(setChecked(bool)));
Chris@207 1677 connect(m_soloAction, SIGNAL(triggered()), this, SLOT(playSoloToggled()));
Chris@207 1678 connect(this, SIGNAL(canChangeSolo(bool)), m_soloAction, SLOT(setEnabled(bool)));
Chris@180 1679
Chris@208 1680 QAction *alAction = 0;
Chris@208 1681 if (Document::canAlign()) {
Chris@208 1682 alAction = toolbar->addAction(il.load("align"),
Chris@208 1683 tr("Align File Timelines"));
Chris@208 1684 alAction->setCheckable(true);
Chris@208 1685 alAction->setChecked(m_viewManager->getAlignMode());
Chris@208 1686 alAction->setStatusTip(tr("Treat multiple audio files as versions of the same work, and align their timelines"));
Chris@208 1687 connect(m_viewManager, SIGNAL(alignModeChanged(bool)),
Chris@208 1688 alAction, SLOT(setChecked(bool)));
Chris@208 1689 connect(alAction, SIGNAL(triggered()), this, SLOT(alignToggled()));
Chris@208 1690 connect(this, SIGNAL(canAlign(bool)), alAction, SLOT(setEnabled(bool)));
Chris@208 1691 }
Chris@206 1692
Chris@162 1693 m_keyReference->registerShortcut(playAction);
Chris@162 1694 m_keyReference->registerShortcut(psAction);
Chris@162 1695 m_keyReference->registerShortcut(plAction);
Chris@207 1696 m_keyReference->registerShortcut(m_soloAction);
Chris@208 1697 if (alAction) m_keyReference->registerShortcut(alAction);
Chris@162 1698 m_keyReference->registerShortcut(m_rwdAction);
Chris@162 1699 m_keyReference->registerShortcut(m_ffwdAction);
Chris@162 1700 m_keyReference->registerShortcut(rwdStartAction);
Chris@162 1701 m_keyReference->registerShortcut(ffwdEndAction);
Chris@162 1702
Chris@155 1703 menu->addAction(playAction);
Chris@155 1704 menu->addAction(psAction);
Chris@155 1705 menu->addAction(plAction);
Chris@207 1706 menu->addAction(m_soloAction);
Chris@208 1707 if (alAction) menu->addAction(alAction);
Chris@155 1708 menu->addSeparator();
Chris@155 1709 menu->addAction(m_rwdAction);
Chris@155 1710 menu->addAction(m_ffwdAction);
Chris@155 1711 menu->addSeparator();
Chris@155 1712 menu->addAction(rwdStartAction);
Chris@155 1713 menu->addAction(ffwdEndAction);
Chris@155 1714 menu->addSeparator();
Chris@155 1715
Chris@155 1716 m_rightButtonPlaybackMenu->addAction(playAction);
Chris@155 1717 m_rightButtonPlaybackMenu->addAction(psAction);
Chris@155 1718 m_rightButtonPlaybackMenu->addAction(plAction);
Chris@207 1719 m_rightButtonPlaybackMenu->addAction(m_soloAction);
Chris@208 1720 if (alAction) m_rightButtonPlaybackMenu->addAction(alAction);
Chris@155 1721 m_rightButtonPlaybackMenu->addSeparator();
Chris@155 1722 m_rightButtonPlaybackMenu->addAction(m_rwdAction);
Chris@155 1723 m_rightButtonPlaybackMenu->addAction(m_ffwdAction);
Chris@155 1724 m_rightButtonPlaybackMenu->addSeparator();
Chris@155 1725 m_rightButtonPlaybackMenu->addAction(rwdStartAction);
Chris@155 1726 m_rightButtonPlaybackMenu->addAction(ffwdEndAction);
Chris@155 1727 m_rightButtonPlaybackMenu->addSeparator();
Chris@155 1728
Chris@155 1729 QAction *fastAction = menu->addAction(tr("Speed Up"));
Chris@155 1730 fastAction->setShortcut(tr("Ctrl+PgUp"));
Chris@163 1731 fastAction->setStatusTip(tr("Time-stretch playback to speed it up without changing pitch"));
Chris@155 1732 connect(fastAction, SIGNAL(triggered()), this, SLOT(speedUpPlayback()));
Chris@155 1733 connect(this, SIGNAL(canSpeedUpPlayback(bool)), fastAction, SLOT(setEnabled(bool)));
Chris@155 1734
Chris@155 1735 QAction *slowAction = menu->addAction(tr("Slow Down"));
Chris@155 1736 slowAction->setShortcut(tr("Ctrl+PgDown"));
Chris@163 1737 slowAction->setStatusTip(tr("Time-stretch playback to slow it down without changing pitch"));
Chris@155 1738 connect(slowAction, SIGNAL(triggered()), this, SLOT(slowDownPlayback()));
Chris@155 1739 connect(this, SIGNAL(canSlowDownPlayback(bool)), slowAction, SLOT(setEnabled(bool)));
Chris@155 1740
Chris@155 1741 QAction *normalAction = menu->addAction(tr("Restore Normal Speed"));
Chris@155 1742 normalAction->setShortcut(tr("Ctrl+Home"));
Chris@163 1743 normalAction->setStatusTip(tr("Restore non-time-stretched playback"));
Chris@155 1744 connect(normalAction, SIGNAL(triggered()), this, SLOT(restoreNormalPlayback()));
Chris@155 1745 connect(this, SIGNAL(canChangePlaybackSpeed(bool)), normalAction, SLOT(setEnabled(bool)));
Chris@155 1746
Chris@162 1747 m_keyReference->registerShortcut(fastAction);
Chris@162 1748 m_keyReference->registerShortcut(slowAction);
Chris@162 1749 m_keyReference->registerShortcut(normalAction);
Chris@162 1750
Chris@155 1751 m_rightButtonPlaybackMenu->addAction(fastAction);
Chris@155 1752 m_rightButtonPlaybackMenu->addAction(slowAction);
Chris@155 1753 m_rightButtonPlaybackMenu->addAction(normalAction);
Chris@0 1754
Chris@0 1755 toolbar = addToolBar(tr("Edit Toolbar"));
Chris@0 1756 CommandHistory::getInstance()->registerToolbar(toolbar);
Chris@0 1757
Chris@162 1758 m_keyReference->setCategory(tr("Tool Selection"));
Chris@162 1759
Chris@0 1760 toolbar = addToolBar(tr("Tools Toolbar"));
Chris@0 1761 QActionGroup *group = new QActionGroup(this);
Chris@0 1762
Chris@168 1763 QAction *action = toolbar->addAction(il.load("navigate"),
Chris@155 1764 tr("Navigate"));
Chris@0 1765 action->setCheckable(true);
Chris@0 1766 action->setChecked(true);
Chris@0 1767 action->setShortcut(tr("1"));
Chris@90 1768 action->setStatusTip(tr("Navigate"));
Chris@0 1769 connect(action, SIGNAL(triggered()), this, SLOT(toolNavigateSelected()));
Chris@0 1770 group->addAction(action);
Chris@162 1771 m_keyReference->registerShortcut(action);
Chris@0 1772 m_toolActions[ViewManager::NavigateMode] = action;
Chris@0 1773
Chris@168 1774 action = toolbar->addAction(il.load("select"),
Chris@0 1775 tr("Select"));
Chris@0 1776 action->setCheckable(true);
Chris@0 1777 action->setShortcut(tr("2"));
Chris@90 1778 action->setStatusTip(tr("Select ranges"));
Chris@0 1779 connect(action, SIGNAL(triggered()), this, SLOT(toolSelectSelected()));
Chris@0 1780 group->addAction(action);
Chris@162 1781 m_keyReference->registerShortcut(action);
Chris@0 1782 m_toolActions[ViewManager::SelectMode] = action;
Chris@0 1783
Chris@168 1784 action = toolbar->addAction(il.load("move"),
Chris@0 1785 tr("Edit"));
Chris@0 1786 action->setCheckable(true);
Chris@0 1787 action->setShortcut(tr("3"));
Chris@90 1788 action->setStatusTip(tr("Edit items in layer"));
Chris@0 1789 connect(action, SIGNAL(triggered()), this, SLOT(toolEditSelected()));
Chris@0 1790 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1791 group->addAction(action);
Chris@162 1792 m_keyReference->registerShortcut(action);
Chris@0 1793 m_toolActions[ViewManager::EditMode] = action;
Chris@0 1794
Chris@168 1795 action = toolbar->addAction(il.load("draw"),
Chris@0 1796 tr("Draw"));
Chris@0 1797 action->setCheckable(true);
Chris@0 1798 action->setShortcut(tr("4"));
Chris@90 1799 action->setStatusTip(tr("Draw new items in layer"));
Chris@0 1800 connect(action, SIGNAL(triggered()), this, SLOT(toolDrawSelected()));
Chris@0 1801 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@0 1802 group->addAction(action);
Chris@162 1803 m_keyReference->registerShortcut(action);
Chris@0 1804 m_toolActions[ViewManager::DrawMode] = action;
Chris@0 1805
Chris@217 1806 action = toolbar->addAction(il.load("erase"),
Chris@217 1807 tr("Erase"));
Chris@217 1808 action->setCheckable(true);
Chris@217 1809 action->setShortcut(tr("5"));
Chris@217 1810 action->setStatusTip(tr("Erase items from layer"));
Chris@217 1811 connect(action, SIGNAL(triggered()), this, SLOT(toolEraseSelected()));
Chris@217 1812 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@217 1813 group->addAction(action);
Chris@217 1814 m_keyReference->registerShortcut(action);
Chris@217 1815 m_toolActions[ViewManager::EraseMode] = action;
Chris@217 1816
Chris@168 1817 action = toolbar->addAction(il.load("measure"),
Chris@151 1818 tr("Measure"));
Chris@151 1819 action->setCheckable(true);
Chris@217 1820 action->setShortcut(tr("6"));
Chris@151 1821 action->setStatusTip(tr("Make measurements in layer"));
Chris@151 1822 connect(action, SIGNAL(triggered()), this, SLOT(toolMeasureSelected()));
Chris@169 1823 connect(this, SIGNAL(canMeasureLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@151 1824 group->addAction(action);
Chris@162 1825 m_keyReference->registerShortcut(action);
Chris@151 1826 m_toolActions[ViewManager::MeasureMode] = action;
Chris@151 1827
Chris@0 1828 toolNavigateSelected();
Chris@163 1829
Chris@163 1830 Pane::registerShortcuts(*m_keyReference);
Chris@0 1831 }
Chris@0 1832
Chris@0 1833 void
Chris@0 1834 MainWindow::updateMenuStates()
Chris@0 1835 {
Chris@200 1836 MainWindowBase::updateMenuStates();
Chris@200 1837
Chris@117 1838 Pane *currentPane = 0;
Chris@117 1839 Layer *currentLayer = 0;
Chris@117 1840
Chris@117 1841 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
Chris@117 1842 if (currentPane) currentLayer = currentPane->getSelectedLayer();
Chris@117 1843
Chris@0 1844 bool haveCurrentPane =
Chris@117 1845 (currentPane != 0);
Chris@0 1846 bool haveCurrentLayer =
Chris@117 1847 (haveCurrentPane &&
Chris@117 1848 (currentLayer != 0));
Chris@206 1849 bool havePlayTarget =
Chris@206 1850 (m_playTarget != 0);
Chris@0 1851 bool haveSelection =
Chris@0 1852 (m_viewManager &&
Chris@0 1853 !m_viewManager->getSelections().empty());
Chris@0 1854 bool haveCurrentEditableLayer =
Chris@0 1855 (haveCurrentLayer &&
Chris@117 1856 currentLayer->isLayerEditable());
Chris@0 1857 bool haveCurrentTimeInstantsLayer =
Chris@0 1858 (haveCurrentLayer &&
Chris@117 1859 dynamic_cast<TimeInstantLayer *>(currentLayer));
Chris@0 1860 bool haveCurrentTimeValueLayer =
Chris@0 1861 (haveCurrentLayer &&
Chris@117 1862 dynamic_cast<TimeValueLayer *>(currentLayer));
Chris@207 1863
Chris@207 1864 emit canChangeSolo(havePlayTarget);
Chris@207 1865 emit canAlign(havePlayTarget && m_document && m_document->canAlign());
Chris@206 1866
Chris@200 1867 emit canChangePlaybackSpeed(true);
Chris@200 1868 int v = m_playSpeed->value();
Chris@200 1869 emit canSpeedUpPlayback(v < m_playSpeed->maximum());
Chris@200 1870 emit canSlowDownPlayback(v > m_playSpeed->minimum());
Chris@155 1871
Chris@164 1872 if (m_viewManager &&
Chris@164 1873 (m_viewManager->getToolMode() == ViewManager::MeasureMode)) {
Chris@164 1874 emit canDeleteSelection(haveCurrentLayer);
Chris@164 1875 m_deleteSelectedAction->setText(tr("&Delete Current Measurement"));
Chris@164 1876 m_deleteSelectedAction->setStatusTip(tr("Delete the measurement currently under the mouse pointer"));
Chris@164 1877 } else {
Chris@164 1878 emit canDeleteSelection(haveSelection && haveCurrentEditableLayer);
Chris@164 1879 m_deleteSelectedAction->setText(tr("&Delete Selected Items"));
Chris@164 1880 m_deleteSelectedAction->setStatusTip(tr("Delete items in current selection from the current layer"));
Chris@164 1881 }
Chris@164 1882
Chris@155 1883 if (m_ffwdAction && m_rwdAction) {
Chris@155 1884 if (haveCurrentTimeInstantsLayer) {
Chris@155 1885 m_ffwdAction->setText(tr("Fast Forward to Next Instant"));
Chris@155 1886 m_ffwdAction->setStatusTip(tr("Fast forward to the next time instant in the current layer"));
Chris@155 1887 m_rwdAction->setText(tr("Rewind to Previous Instant"));
Chris@155 1888 m_rwdAction->setStatusTip(tr("Rewind to the previous time instant in the current layer"));
Chris@155 1889 } else if (haveCurrentTimeValueLayer) {
Chris@155 1890 m_ffwdAction->setText(tr("Fast Forward to Next Point"));
Chris@155 1891 m_ffwdAction->setStatusTip(tr("Fast forward to the next point in the current layer"));
Chris@155 1892 m_rwdAction->setText(tr("Rewind to Previous Point"));
Chris@155 1893 m_rwdAction->setStatusTip(tr("Rewind to the previous point in the current layer"));
Chris@155 1894 } else {
Chris@155 1895 m_ffwdAction->setText(tr("Fast Forward"));
Chris@155 1896 m_ffwdAction->setStatusTip(tr("Fast forward"));
Chris@155 1897 m_rwdAction->setText(tr("Rewind"));
Chris@155 1898 m_rwdAction->setStatusTip(tr("Rewind"));
Chris@155 1899 }
Chris@155 1900 }
Chris@0 1901 }
Chris@0 1902
Chris@0 1903 void
Chris@0 1904 MainWindow::updateDescriptionLabel()
Chris@0 1905 {
Chris@0 1906 if (!getMainModel()) {
Chris@0 1907 m_descriptionLabel->setText(tr("No audio file loaded."));
Chris@0 1908 return;
Chris@0 1909 }
Chris@0 1910
Chris@0 1911 QString description;
Chris@0 1912
Chris@0 1913 size_t ssr = getMainModel()->getSampleRate();
Chris@0 1914 size_t tsr = ssr;
Chris@0 1915 if (m_playSource) tsr = m_playSource->getTargetSampleRate();
Chris@0 1916
Chris@0 1917 if (ssr != tsr) {
Chris@0 1918 description = tr("%1Hz (resampling to %2Hz)").arg(ssr).arg(tsr);
Chris@0 1919 } else {
Chris@0 1920 description = QString("%1Hz").arg(ssr);
Chris@0 1921 }
Chris@0 1922
Chris@0 1923 description = QString("%1 - %2")
Chris@0 1924 .arg(RealTime::frame2RealTime(getMainModel()->getEndFrame(), ssr)
Chris@0 1925 .toText(false).c_str())
Chris@0 1926 .arg(description);
Chris@0 1927
Chris@0 1928 m_descriptionLabel->setText(description);
Chris@0 1929 }
Chris@0 1930
Chris@0 1931 void
Chris@0 1932 MainWindow::documentModified()
Chris@0 1933 {
Chris@200 1934 //!!!
Chris@200 1935 MainWindowBase::documentModified();
Chris@0 1936 }
Chris@0 1937
Chris@0 1938 void
Chris@0 1939 MainWindow::documentRestored()
Chris@0 1940 {
Chris@200 1941 //!!!
Chris@200 1942 MainWindowBase::documentRestored();
Chris@0 1943 }
Chris@0 1944
Chris@0 1945 void
Chris@0 1946 MainWindow::toolNavigateSelected()
Chris@0 1947 {
Chris@0 1948 m_viewManager->setToolMode(ViewManager::NavigateMode);
Chris@0 1949 }
Chris@0 1950
Chris@0 1951 void
Chris@0 1952 MainWindow::toolSelectSelected()
Chris@0 1953 {
Chris@0 1954 m_viewManager->setToolMode(ViewManager::SelectMode);
Chris@0 1955 }
Chris@0 1956
Chris@0 1957 void
Chris@0 1958 MainWindow::toolEditSelected()
Chris@0 1959 {
Chris@0 1960 m_viewManager->setToolMode(ViewManager::EditMode);
Chris@0 1961 }
Chris@0 1962
Chris@0 1963 void
Chris@0 1964 MainWindow::toolDrawSelected()
Chris@0 1965 {
Chris@0 1966 m_viewManager->setToolMode(ViewManager::DrawMode);
Chris@0 1967 }
Chris@0 1968
Chris@151 1969 void
Chris@217 1970 MainWindow::toolEraseSelected()
Chris@217 1971 {
Chris@217 1972 m_viewManager->setToolMode(ViewManager::EraseMode);
Chris@217 1973 }
Chris@217 1974
Chris@217 1975 void
Chris@151 1976 MainWindow::toolMeasureSelected()
Chris@151 1977 {
Chris@151 1978 m_viewManager->setToolMode(ViewManager::MeasureMode);
Chris@151 1979 }
Chris@151 1980
Chris@0 1981 void
Chris@0 1982 MainWindow::importAudio()
Chris@0 1983 {
Chris@88 1984 QString path = getOpenFileName(FileFinder::AudioFile);
Chris@0 1985
Chris@0 1986 if (path != "") {
Chris@197 1987 if (openAudio(path, ReplaceMainModel) == FileOpenFailed) {
Chris@247 1988 emit hideSplash();
Chris@0 1989 QMessageBox::critical(this, tr("Failed to open file"),
Chris@193 1990 tr("<b>File open failed</b><p>Audio file \"%1\" could not be opened").arg(path));
Chris@0 1991 }
Chris@0 1992 }
Chris@0 1993 }
Chris@0 1994
Chris@0 1995 void
Chris@0 1996 MainWindow::importMoreAudio()
Chris@0 1997 {
Chris@88 1998 QString path = getOpenFileName(FileFinder::AudioFile);
Chris@0 1999
Chris@0 2000 if (path != "") {
Chris@197 2001 if (openAudio(path, CreateAdditionalModel) == FileOpenFailed) {
Chris@247 2002 emit hideSplash();
Chris@0 2003 QMessageBox::critical(this, tr("Failed to open file"),
Chris@193 2004 tr("<b>File open failed</b><p>Audio file \"%1\" could not be opened").arg(path));
Chris@0 2005 }
Chris@0 2006 }
Chris@0 2007 }
Chris@0 2008
Chris@0 2009 void
Chris@0 2010 MainWindow::exportAudio()
Chris@0 2011 {
Chris@0 2012 if (!getMainModel()) return;
Chris@0 2013
Chris@88 2014 QString path = getSaveFileName(FileFinder::AudioFile);
Chris@0 2015
Chris@0 2016 if (path == "") return;
Chris@0 2017
Chris@0 2018 bool ok = false;
Chris@0 2019 QString error;
Chris@0 2020
Chris@0 2021 MultiSelection ms = m_viewManager->getSelection();
Chris@0 2022 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@0 2023
Chris@0 2024 bool multiple = false;
Chris@0 2025
Chris@38 2026 MultiSelection *selectionToWrite = 0;
Chris@38 2027
Chris@38 2028 if (selections.size() == 1) {
Chris@0 2029
Chris@0 2030 QStringList items;
Chris@0 2031 items << tr("Export the selected region only")
Chris@0 2032 << tr("Export the whole audio file");
Chris@0 2033
Chris@0 2034 bool ok = false;
Chris@0 2035 QString item = ListInputDialog::getItem
Chris@0 2036 (this, tr("Select region to export"),
Chris@0 2037 tr("Which region from the original audio file do you want to export?"),
Chris@0 2038 items, 0, &ok);
Chris@0 2039
Chris@0 2040 if (!ok || item.isEmpty()) return;
Chris@0 2041
Chris@38 2042 if (item == items[0]) selectionToWrite = &ms;
Chris@38 2043
Chris@38 2044 } else if (selections.size() > 1) {
Chris@0 2045
Chris@0 2046 QStringList items;
Chris@0 2047 items << tr("Export the selected regions into a single audio file")
Chris@0 2048 << tr("Export the selected regions into separate files")
Chris@0 2049 << tr("Export the whole audio file");
Chris@0 2050
Chris@0 2051 QString item = ListInputDialog::getItem
Chris@0 2052 (this, tr("Select region to export"),
Chris@0 2053 tr("Multiple regions of the original audio file are selected.\nWhat do you want to export?"),
Chris@0 2054 items, 0, &ok);
Chris@0 2055
Chris@0 2056 if (!ok || item.isEmpty()) return;
Chris@0 2057
Chris@0 2058 if (item == items[0]) {
Chris@0 2059
Chris@38 2060 selectionToWrite = &ms;
Chris@38 2061
Chris@38 2062 } else if (item == items[1]) {
Chris@0 2063
Chris@0 2064 multiple = true;
Chris@0 2065
Chris@0 2066 int n = 1;
Chris@0 2067 QString base = path;
Chris@0 2068 base.replace(".wav", "");
Chris@0 2069
Chris@0 2070 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@0 2071 i != selections.end(); ++i) {
Chris@0 2072
Chris@0 2073 MultiSelection subms;
Chris@0 2074 subms.setSelection(*i);
Chris@0 2075
Chris@0 2076 QString subpath = QString("%1.%2.wav").arg(base).arg(n);
Chris@0 2077 ++n;
Chris@0 2078
Chris@0 2079 if (QFileInfo(subpath).exists()) {
Chris@0 2080 error = tr("Fragment file %1 already exists, aborting").arg(subpath);
Chris@0 2081 break;
Chris@0 2082 }
Chris@0 2083
Chris@38 2084 WavFileWriter subwriter(subpath,
Chris@38 2085 getMainModel()->getSampleRate(),
Chris@38 2086 getMainModel()->getChannelCount());
Chris@38 2087 subwriter.writeModel(getMainModel(), &subms);
Chris@0 2088 ok = subwriter.isOK();
Chris@0 2089
Chris@0 2090 if (!ok) {
Chris@0 2091 error = subwriter.getError();
Chris@0 2092 break;
Chris@0 2093 }
Chris@0 2094 }
Chris@0 2095 }
Chris@0 2096 }
Chris@0 2097
Chris@38 2098 if (!multiple) {
Chris@38 2099 WavFileWriter writer(path,
Chris@38 2100 getMainModel()->getSampleRate(),
Chris@38 2101 getMainModel()->getChannelCount());
Chris@38 2102 writer.writeModel(getMainModel(), selectionToWrite);
Chris@38 2103 ok = writer.isOK();
Chris@38 2104 error = writer.getError();
Chris@0 2105 }
Chris@0 2106
Chris@0 2107 if (ok) {
Chris@0 2108 if (!multiple) {
Chris@34 2109 m_recentFiles.addFile(path);
Chris@0 2110 }
Chris@0 2111 } else {
Chris@0 2112 QMessageBox::critical(this, tr("Failed to write file"), error);
Chris@0 2113 }
Chris@0 2114 }
Chris@0 2115
Chris@0 2116 void
Chris@0 2117 MainWindow::importLayer()
Chris@0 2118 {
Chris@0 2119 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 2120
Chris@0 2121 if (!pane) {
Chris@0 2122 // shouldn't happen, as the menu action should have been disabled
Chris@0 2123 std::cerr << "WARNING: MainWindow::importLayer: no current pane" << std::endl;
Chris@0 2124 return;
Chris@0 2125 }
Chris@0 2126
Chris@0 2127 if (!getMainModel()) {
Chris@0 2128 // shouldn't happen, as the menu action should have been disabled
Chris@0 2129 std::cerr << "WARNING: MainWindow::importLayer: No main model -- hence no default sample rate available" << std::endl;
Chris@0 2130 return;
Chris@0 2131 }
Chris@0 2132
Chris@88 2133 QString path = getOpenFileName(FileFinder::LayerFile);
Chris@0 2134
Chris@0 2135 if (path != "") {
Chris@0 2136
Chris@197 2137 FileOpenStatus status = openLayer(path);
Chris@193 2138
Chris@193 2139 if (status == FileOpenFailed) {
Chris@247 2140 emit hideSplash();
Chris@0 2141 QMessageBox::critical(this, tr("Failed to open file"),
Chris@193 2142 tr("<b>File open failed</b><p>Layer file %1 could not be opened.").arg(path));
Chris@0 2143 return;
Chris@193 2144 } else if (status == FileOpenWrongMode) {
Chris@247 2145 emit hideSplash();
Chris@193 2146 QMessageBox::critical(this, tr("Failed to open file"),
Chris@193 2147 tr("<b>Audio required</b><p>Please load at least one audio file before importing annotation data"));
Chris@0 2148 }
Chris@0 2149 }
Chris@0 2150 }
Chris@0 2151
Chris@0 2152 void
Chris@0 2153 MainWindow::exportLayer()
Chris@0 2154 {
Chris@0 2155 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 2156 if (!pane) return;
Chris@0 2157
Chris@0 2158 Layer *layer = pane->getSelectedLayer();
Chris@0 2159 if (!layer) return;
Chris@0 2160
Chris@0 2161 Model *model = layer->getModel();
Chris@0 2162 if (!model) return;
Chris@0 2163
Chris@185 2164 FileFinder::FileType type = FileFinder::LayerFileNoMidi;
Chris@185 2165
Chris@185 2166 if (dynamic_cast<NoteModel *>(model)) type = FileFinder::LayerFile;
Chris@185 2167
Chris@185 2168 QString path = getSaveFileName(type);
Chris@0 2169
Chris@0 2170 if (path == "") return;
Chris@0 2171
Chris@0 2172 if (QFileInfo(path).suffix() == "") path += ".svl";
Chris@0 2173
Chris@185 2174 QString suffix = QFileInfo(path).suffix().toLower();
Chris@185 2175
Chris@0 2176 QString error;
Chris@0 2177
Chris@185 2178 if (suffix == "xml" || suffix == "svl") {
Chris@0 2179
Chris@0 2180 QFile file(path);
Chris@0 2181 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
Chris@0 2182 error = tr("Failed to open file %1 for writing").arg(path);
Chris@0 2183 } else {
Chris@0 2184 QTextStream out(&file);
Chris@0 2185 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
Chris@0 2186 << "<!DOCTYPE sonic-visualiser>\n"
Chris@0 2187 << "<sv>\n"
Chris@0 2188 << " <data>\n";
Chris@0 2189
Chris@0 2190 model->toXml(out, " ");
Chris@0 2191
Chris@0 2192 out << " </data>\n"
Chris@0 2193 << " <display>\n";
Chris@0 2194
Chris@0 2195 layer->toXml(out, " ");
Chris@0 2196
Chris@0 2197 out << " </display>\n"
Chris@0 2198 << "</sv>\n";
Chris@0 2199 }
Chris@0 2200
Chris@185 2201 } else if (suffix == "mid" || suffix == "midi") {
Chris@185 2202
Chris@185 2203 NoteModel *nm = dynamic_cast<NoteModel *>(model);
Chris@185 2204
Chris@185 2205 if (!nm) {
Chris@185 2206 error = tr("Can't export non-note layers to MIDI");
Chris@185 2207 } else {
Chris@185 2208 MIDIFileWriter writer(path, nm);
Chris@185 2209 writer.write();
Chris@185 2210 if (!writer.isOK()) {
Chris@185 2211 error = writer.getError();
Chris@185 2212 }
Chris@185 2213 }
Chris@185 2214
Chris@0 2215 } else {
Chris@0 2216
Chris@0 2217 CSVFileWriter writer(path, model,
Chris@185 2218 ((suffix == "csv") ? "," : "\t"));
Chris@0 2219 writer.write();
Chris@0 2220
Chris@0 2221 if (!writer.isOK()) {
Chris@0 2222 error = writer.getError();
Chris@0 2223 }
Chris@0 2224 }
Chris@0 2225
Chris@0 2226 if (error != "") {
Chris@0 2227 QMessageBox::critical(this, tr("Failed to write file"), error);
Chris@0 2228 } else {
Chris@34 2229 m_recentFiles.addFile(path);
Chris@0 2230 }
Chris@0 2231 }
Chris@0 2232
Chris@121 2233 void
Chris@121 2234 MainWindow::exportImage()
Chris@121 2235 {
Chris@121 2236 Pane *pane = m_paneStack->getCurrentPane();
Chris@121 2237 if (!pane) return;
Chris@121 2238
Chris@121 2239 QString path = getSaveFileName(FileFinder::ImageFile);
Chris@121 2240
Chris@121 2241 if (path == "") return;
Chris@121 2242
Chris@121 2243 if (QFileInfo(path).suffix() == "") path += ".png";
Chris@121 2244
Chris@123 2245 bool haveSelection = m_viewManager && !m_viewManager->getSelections().empty();
Chris@123 2246
Chris@123 2247 QSize total, visible, selected;
Chris@123 2248 total = pane->getImageSize();
Chris@123 2249 visible = pane->getImageSize(pane->getFirstVisibleFrame(),
Chris@123 2250 pane->getLastVisibleFrame());
Chris@123 2251
Chris@123 2252 size_t sf0 = 0, sf1 = 0;
Chris@123 2253
Chris@123 2254 if (haveSelection) {
Chris@123 2255 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@123 2256 sf0 = selections.begin()->getStartFrame();
Chris@123 2257 MultiSelection::SelectionList::iterator e = selections.end();
Chris@123 2258 --e;
Chris@123 2259 sf1 = e->getEndFrame();
Chris@123 2260 selected = pane->getImageSize(sf0, sf1);
Chris@123 2261 }
Chris@123 2262
Chris@123 2263 QStringList items;
Chris@125 2264 items << tr("Export the whole pane (%1x%2 pixels)")
Chris@123 2265 .arg(total.width()).arg(total.height());
Chris@123 2266 items << tr("Export the visible area only (%1x%2 pixels)")
Chris@123 2267 .arg(visible.width()).arg(visible.height());
Chris@123 2268 if (haveSelection) {
Chris@123 2269 items << tr("Export the selection extent (%1x%2 pixels)")
Chris@123 2270 .arg(selected.width()).arg(selected.height());
Chris@124 2271 } else {
Chris@124 2272 items << tr("Export the selection extent");
Chris@123 2273 }
Chris@123 2274
Chris@123 2275 QSettings settings;
Chris@123 2276 settings.beginGroup("MainWindow");
Chris@123 2277 int deflt = settings.value("lastimageexportregion", 0).toInt();
Chris@123 2278 if (deflt == 2 && !haveSelection) deflt = 1;
Chris@124 2279 if (deflt == 0 && total.width() > 32767) deflt = 1;
Chris@124 2280
Chris@124 2281 ListInputDialog *lid = new ListInputDialog
Chris@123 2282 (this, tr("Select region to export"),
Chris@123 2283 tr("Which region of the current pane do you want to export as an image?"),
Chris@124 2284 items, deflt);
Chris@124 2285
Chris@124 2286 if (!haveSelection) {
Chris@124 2287 lid->setItemAvailability(2, false);
Chris@124 2288 }
Chris@124 2289 if (total.width() > 32767) { // appears to be the limit of a QImage
Chris@124 2290 lid->setItemAvailability(0, false);
Chris@124 2291 lid->setFootnote(tr("Note: the whole pane is too wide to be exported as a single image."));
Chris@124 2292 }
Chris@124 2293
Chris@124 2294 bool ok = lid->exec();
Chris@124 2295 QString item = lid->getCurrentString();
Chris@124 2296 delete lid;
Chris@123 2297
Chris@123 2298 if (!ok || item.isEmpty()) return;
Chris@123 2299
Chris@123 2300 settings.setValue("lastimageexportregion", deflt);
Chris@123 2301
Chris@123 2302 QImage *image = 0;
Chris@123 2303
Chris@123 2304 if (item == items[0]) {
Chris@123 2305 image = pane->toNewImage();
Chris@123 2306 } else if (item == items[1]) {
Chris@123 2307 image = pane->toNewImage(pane->getFirstVisibleFrame(),
Chris@123 2308 pane->getLastVisibleFrame());
Chris@123 2309 } else if (haveSelection) {
Chris@123 2310 image = pane->toNewImage(sf0, sf1);
Chris@123 2311 }
Chris@123 2312
Chris@121 2313 if (!image) return;
Chris@121 2314
Chris@121 2315 if (!image->save(path, "PNG")) {
Chris@121 2316 QMessageBox::critical(this, tr("Failed to save image file"),
Chris@121 2317 tr("Failed to save image file %1").arg(path));
Chris@121 2318 }
Chris@121 2319
Chris@121 2320 delete image;
Chris@121 2321 }
Chris@121 2322
Chris@0 2323 void
Chris@0 2324 MainWindow::newSession()
Chris@0 2325 {
Chris@0 2326 if (!checkSaveModified()) return;
Chris@0 2327
Chris@0 2328 closeSession();
Chris@0 2329 createDocument();
Chris@0 2330
Chris@0 2331 Pane *pane = m_paneStack->addPane();
Chris@0 2332
Chris@90 2333 connect(pane, SIGNAL(contextHelpChanged(const QString &)),
Chris@116 2334 this, SLOT(contextHelpChanged(const QString &)));
Chris@90 2335
Chris@0 2336 if (!m_timeRulerLayer) {
Chris@0 2337 m_timeRulerLayer = m_document->createMainModelLayer
Chris@0 2338 (LayerFactory::TimeRuler);
Chris@0 2339 }
Chris@0 2340
Chris@0 2341 m_document->addLayerToView(pane, m_timeRulerLayer);
Chris@0 2342
Chris@0 2343 Layer *waveform = m_document->createMainModelLayer(LayerFactory::Waveform);
Chris@0 2344 m_document->addLayerToView(pane, waveform);
Chris@0 2345
Chris@65 2346 m_overview->registerView(pane);
Chris@0 2347
Chris@0 2348 CommandHistory::getInstance()->clear();
Chris@0 2349 CommandHistory::getInstance()->documentSaved();
Chris@0 2350 documentRestored();
Chris@0 2351 updateMenuStates();
Chris@0 2352 }
Chris@0 2353
Chris@0 2354 void
Chris@0 2355 MainWindow::closeSession()
Chris@0 2356 {
Chris@0 2357 if (!checkSaveModified()) return;
Chris@0 2358
Chris@0 2359 while (m_paneStack->getPaneCount() > 0) {
Chris@0 2360
Chris@0 2361 Pane *pane = m_paneStack->getPane(m_paneStack->getPaneCount() - 1);
Chris@0 2362
Chris@0 2363 while (pane->getLayerCount() > 0) {
Chris@0 2364 m_document->removeLayerFromView
Chris@0 2365 (pane, pane->getLayer(pane->getLayerCount() - 1));
Chris@0 2366 }
Chris@0 2367
Chris@65 2368 m_overview->unregisterView(pane);
Chris@0 2369 m_paneStack->deletePane(pane);
Chris@0 2370 }
Chris@0 2371
Chris@0 2372 while (m_paneStack->getHiddenPaneCount() > 0) {
Chris@0 2373
Chris@0 2374 Pane *pane = m_paneStack->getHiddenPane
Chris@0 2375 (m_paneStack->getHiddenPaneCount() - 1);
Chris@0 2376
Chris@0 2377 while (pane->getLayerCount() > 0) {
Chris@0 2378 m_document->removeLayerFromView
Chris@0 2379 (pane, pane->getLayer(pane->getLayerCount() - 1));
Chris@0 2380 }
Chris@0 2381
Chris@65 2382 m_overview->unregisterView(pane);
Chris@0 2383 m_paneStack->deletePane(pane);
Chris@0 2384 }
Chris@0 2385
Chris@0 2386 delete m_document;
Chris@0 2387 m_document = 0;
Chris@0 2388 m_viewManager->clearSelections();
Chris@0 2389 m_timeRulerLayer = 0; // document owned this
Chris@0 2390
Chris@0 2391 m_sessionFile = "";
Chris@0 2392 setWindowTitle(tr("Sonic Visualiser"));
Chris@0 2393
Chris@0 2394 CommandHistory::getInstance()->clear();
Chris@0 2395 CommandHistory::getInstance()->documentSaved();
Chris@0 2396 documentRestored();
Chris@0 2397 }
Chris@0 2398
Chris@0 2399 void
Chris@0 2400 MainWindow::openSession()
Chris@0 2401 {
Chris@0 2402 if (!checkSaveModified()) return;
Chris@0 2403
Chris@0 2404 QString orig = m_audioFile;
Chris@0 2405 if (orig == "") orig = ".";
Chris@0 2406 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 2407
Chris@88 2408 QString path = getOpenFileName(FileFinder::SessionFile);
Chris@0 2409
Chris@0 2410 if (path.isEmpty()) return;
Chris@0 2411
Chris@200 2412 if (openSessionFile(path) == FileOpenFailed) {
Chris@247 2413 emit hideSplash();
Chris@0 2414 QMessageBox::critical(this, tr("Failed to open file"),
Chris@193 2415 tr("<b>File open failed</b><p>Session file \"%1\" could not be opened").arg(path));
Chris@0 2416 }
Chris@0 2417 }
Chris@0 2418
Chris@0 2419 void
Chris@0 2420 MainWindow::openSomething()
Chris@0 2421 {
Chris@0 2422 QString orig = m_audioFile;
Chris@0 2423 if (orig == "") orig = ".";
Chris@0 2424 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 2425
Chris@88 2426 QString path = getOpenFileName(FileFinder::AnyFile);
Chris@0 2427
Chris@0 2428 if (path.isEmpty()) return;
Chris@0 2429
Chris@197 2430 FileOpenStatus status = open(path, AskUser);
Chris@193 2431
Chris@193 2432 if (status == FileOpenFailed) {
Chris@247 2433 emit hideSplash();
Chris@193 2434 QMessageBox::critical(this, tr("Failed to open file"),
Chris@193 2435 tr("<b>File open failed</b><p>File \"%1\" could not be opened").arg(path));
Chris@193 2436 } else if (status == FileOpenWrongMode) {
Chris@247 2437 emit hideSplash();
Chris@193 2438 QMessageBox::critical(this, tr("Failed to open file"),
Chris@193 2439 tr("<b>Audio required</b><p>Please load at least one audio file before importing annotation data"));
Chris@0 2440 }
Chris@0 2441 }
Chris@0 2442
Chris@0 2443 void
Chris@86 2444 MainWindow::openLocation()
Chris@86 2445 {
Chris@103 2446 QSettings settings;
Chris@103 2447 settings.beginGroup("MainWindow");
Chris@103 2448 QString lastLocation = settings.value("lastremote", "").toString();
Chris@103 2449
Chris@86 2450 bool ok = false;
Chris@86 2451 QString text = QInputDialog::getText
Chris@86 2452 (this, tr("Open Location"),
Chris@86 2453 tr("Please enter the URL of the location to open:"),
Chris@103 2454 QLineEdit::Normal, lastLocation, &ok);
Chris@103 2455
Chris@103 2456 if (!ok) return;
Chris@103 2457
Chris@103 2458 settings.setValue("lastremote", text);
Chris@103 2459
Chris@103 2460 if (text.isEmpty()) return;
Chris@86 2461
Chris@197 2462 FileOpenStatus status = open(text);
Chris@193 2463
Chris@193 2464 if (status == FileOpenFailed) {
Chris@247 2465 emit hideSplash();
Chris@86 2466 QMessageBox::critical(this, tr("Failed to open location"),
Chris@193 2467 tr("<b>Open failed</b><p>URL \"%1\" could not be opened").arg(text));
Chris@193 2468 } else if (status == FileOpenWrongMode) {
Chris@247 2469 emit hideSplash();
Chris@193 2470 QMessageBox::critical(this, tr("Failed to open location"),
Chris@193 2471 tr("<b>Audio required</b><p>Please load at least one audio file before importing annotation data"));
Chris@86 2472 }
Chris@86 2473 }
Chris@86 2474
Chris@86 2475 void
Chris@0 2476 MainWindow::openRecentFile()
Chris@0 2477 {
Chris@0 2478 QObject *obj = sender();
Chris@0 2479 QAction *action = dynamic_cast<QAction *>(obj);
Chris@0 2480
Chris@0 2481 if (!action) {
Chris@0 2482 std::cerr << "WARNING: MainWindow::openRecentFile: sender is not an action"
Chris@0 2483 << std::endl;
Chris@0 2484 return;
Chris@0 2485 }
Chris@0 2486
Chris@0 2487 QString path = action->text();
Chris@0 2488 if (path == "") return;
Chris@0 2489
Chris@197 2490 FileOpenStatus status = open(path);
Chris@193 2491
Chris@193 2492 if (status == FileOpenFailed) {
Chris@247 2493 emit hideSplash();
Chris@193 2494 QMessageBox::critical(this, tr("Failed to open location"),
Chris@193 2495 tr("<b>Open failed</b><p>File or URL \"%1\" could not be opened").arg(path));
Chris@193 2496 } else if (status == FileOpenWrongMode) {
Chris@247 2497 emit hideSplash();
Chris@193 2498 QMessageBox::critical(this, tr("Failed to open location"),
Chris@193 2499 tr("<b>Audio required</b><p>Please load at least one audio file before importing annotation data"));
Chris@0 2500 }
Chris@0 2501 }
Chris@0 2502
Chris@0 2503 void
Chris@200 2504 MainWindow::paneAdded(Pane *pane)
Chris@200 2505 {
Chris@200 2506 if (m_overview) m_overview->registerView(pane);
Chris@200 2507 }
Chris@200 2508
Chris@200 2509 void
Chris@200 2510 MainWindow::paneHidden(Pane *pane)
Chris@200 2511 {
Chris@200 2512 if (m_overview) m_overview->unregisterView(pane);
Chris@200 2513 }
Chris@200 2514
Chris@200 2515 void
Chris@200 2516 MainWindow::paneAboutToBeDeleted(Pane *pane)
Chris@200 2517 {
Chris@200 2518 if (m_overview) m_overview->unregisterView(pane);
Chris@200 2519 }
Chris@200 2520
Chris@200 2521 void
Chris@193 2522 MainWindow::paneDropAccepted(Pane *pane, QStringList uriList)
Chris@193 2523 {
Chris@193 2524 if (pane) m_paneStack->setCurrentPane(pane);
Chris@193 2525
Chris@193 2526 for (QStringList::iterator i = uriList.begin(); i != uriList.end(); ++i) {
Chris@193 2527
Chris@197 2528 FileOpenStatus status = open(*i, ReplaceCurrentPane);
Chris@193 2529
Chris@193 2530 if (status == FileOpenFailed) {
Chris@247 2531 emit hideSplash();
Chris@193 2532 QMessageBox::critical(this, tr("Failed to open dropped URL"),
Chris@193 2533 tr("<b>Open failed</b><p>Dropped URL \"%1\" could not be opened").arg(*i));
Chris@193 2534 } else if (status == FileOpenWrongMode) {
Chris@247 2535 emit hideSplash();
Chris@193 2536 QMessageBox::critical(this, tr("Failed to open dropped URL"),
Chris@193 2537 tr("<b>Audio required</b><p>Please load at least one audio file before importing annotation data"));
Chris@193 2538 }
Chris@193 2539 }
Chris@193 2540 }
Chris@193 2541
Chris@193 2542 void
Chris@193 2543 MainWindow::paneDropAccepted(Pane *pane, QString text)
Chris@193 2544 {
Chris@193 2545 if (pane) m_paneStack->setCurrentPane(pane);
Chris@193 2546
Chris@193 2547 QUrl testUrl(text);
Chris@193 2548 if (testUrl.scheme() == "file" ||
Chris@193 2549 testUrl.scheme() == "http" ||
Chris@193 2550 testUrl.scheme() == "ftp") {
Chris@193 2551 QStringList list;
Chris@193 2552 list.push_back(text);
Chris@193 2553 paneDropAccepted(pane, list);
Chris@193 2554 return;
Chris@193 2555 }
Chris@193 2556
Chris@193 2557 //!!! open as text -- but by importing as if a CSV, or just adding
Chris@193 2558 //to a text layer?
Chris@193 2559 }
Chris@193 2560
Chris@193 2561 void
Chris@0 2562 MainWindow::closeEvent(QCloseEvent *e)
Chris@0 2563 {
Chris@137 2564 // std::cerr << "MainWindow::closeEvent" << std::endl;
Chris@118 2565
Chris@136 2566 if (m_openingAudioFile) {
Chris@137 2567 // std::cerr << "Busy - ignoring close event" << std::endl;
Chris@136 2568 e->ignore();
Chris@136 2569 return;
Chris@136 2570 }
Chris@136 2571
Chris@70 2572 if (!m_abandoning && !checkSaveModified()) {
Chris@137 2573 // std::cerr << "Ignoring close event" << std::endl;
Chris@0 2574 e->ignore();
Chris@0 2575 return;
Chris@0 2576 }
Chris@0 2577
Chris@5 2578 QSettings settings;
Chris@5 2579 settings.beginGroup("MainWindow");
Chris@5 2580 settings.setValue("size", size());
Chris@5 2581 settings.setValue("position", pos());
Chris@5 2582 settings.endGroup();
Chris@5 2583
Chris@163 2584 delete m_keyReference;
Chris@163 2585 m_keyReference = 0;
Chris@163 2586
Chris@163 2587 if (m_preferencesDialog &&
Chris@163 2588 m_preferencesDialog->isVisible()) {
Chris@164 2589 closeSession(); // otherwise we'll have to wait for prefs changes
Chris@163 2590 m_preferencesDialog->applicationClosing(false);
Chris@163 2591 }
Chris@163 2592
Chris@200 2593 closeSession();
Chris@200 2594
Chris@0 2595 e->accept();
Chris@0 2596 return;
Chris@0 2597 }
Chris@0 2598
Chris@0 2599 bool
Chris@11 2600 MainWindow::commitData(bool mayAskUser)
Chris@11 2601 {
Chris@11 2602 if (mayAskUser) {
Chris@163 2603 bool rv = checkSaveModified();
Chris@163 2604 if (rv) {
Chris@163 2605 if (m_preferencesDialog &&
Chris@163 2606 m_preferencesDialog->isVisible()) {
Chris@163 2607 m_preferencesDialog->applicationClosing(false);
Chris@163 2608 }
Chris@163 2609 }
Chris@163 2610 return rv;
Chris@11 2611 } else {
Chris@163 2612 if (m_preferencesDialog &&
Chris@163 2613 m_preferencesDialog->isVisible()) {
Chris@163 2614 m_preferencesDialog->applicationClosing(true);
Chris@163 2615 }
Chris@11 2616 if (!m_documentModified) return true;
Chris@11 2617
Chris@11 2618 // If we can't check with the user first, then we can't save
Chris@11 2619 // to the original session file (even if we have it) -- have
Chris@11 2620 // to use a temporary file
Chris@11 2621
Chris@11 2622 QString svDirBase = ".sv1";
Chris@11 2623 QString svDir = QDir::home().filePath(svDirBase);
Chris@11 2624
Chris@11 2625 if (!QFileInfo(svDir).exists()) {
Chris@11 2626 if (!QDir::home().mkdir(svDirBase)) return false;
Chris@11 2627 } else {
Chris@11 2628 if (!QFileInfo(svDir).isDir()) return false;
Chris@11 2629 }
Chris@11 2630
Chris@11 2631 // This name doesn't have to be unguessable
Chris@93 2632 #ifndef _WIN32
Chris@11 2633 QString fname = QString("tmp-%1-%2.sv")
Chris@11 2634 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"))
Chris@11 2635 .arg(QProcess().pid());
Chris@93 2636 #else
Chris@93 2637 QString fname = QString("tmp-%1.sv")
Chris@93 2638 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"));
Chris@93 2639 #endif
Chris@11 2640 QString fpath = QDir(svDir).filePath(fname);
Chris@11 2641 if (saveSessionFile(fpath)) {
Chris@34 2642 m_recentFiles.addFile(fpath);
Chris@11 2643 return true;
Chris@11 2644 } else {
Chris@11 2645 return false;
Chris@11 2646 }
Chris@11 2647 }
Chris@11 2648 }
Chris@11 2649
Chris@11 2650 bool
Chris@0 2651 MainWindow::checkSaveModified()
Chris@0 2652 {
Chris@0 2653 // Called before some destructive operation (e.g. new session,
Chris@0 2654 // exit program). Return true if we can safely proceed, false to
Chris@0 2655 // cancel.
Chris@0 2656
Chris@0 2657 if (!m_documentModified) return true;
Chris@0 2658
Chris@247 2659 emit hideSplash();
Chris@247 2660
Chris@0 2661 int button =
Chris@0 2662 QMessageBox::warning(this,
Chris@0 2663 tr("Session modified"),
Chris@207 2664 tr("<b>Session modified</b><p>The current session has been modified.<br>Do you want to save it?"),
Chris@165 2665 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
Chris@165 2666 QMessageBox::Yes);
Chris@0 2667
Chris@0 2668 if (button == QMessageBox::Yes) {
Chris@0 2669 saveSession();
Chris@0 2670 if (m_documentModified) { // save failed -- don't proceed!
Chris@0 2671 return false;
Chris@0 2672 } else {
Chris@0 2673 return true; // saved, so it's safe to continue now
Chris@0 2674 }
Chris@0 2675 } else if (button == QMessageBox::No) {
Chris@0 2676 m_documentModified = false; // so we know to abandon it
Chris@0 2677 return true;
Chris@0 2678 }
Chris@0 2679
Chris@0 2680 // else cancel
Chris@0 2681 return false;
Chris@0 2682 }
Chris@0 2683
Chris@0 2684 void
Chris@0 2685 MainWindow::saveSession()
Chris@0 2686 {
Chris@0 2687 if (m_sessionFile != "") {
Chris@0 2688 if (!saveSessionFile(m_sessionFile)) {
Chris@0 2689 QMessageBox::critical(this, tr("Failed to save file"),
Chris@193 2690 tr("<b>Save failed</b><p>Session file \"%1\" could not be saved.").arg(m_sessionFile));
Chris@0 2691 } else {
Chris@0 2692 CommandHistory::getInstance()->documentSaved();
Chris@0 2693 documentRestored();
Chris@0 2694 }
Chris@0 2695 } else {
Chris@0 2696 saveSessionAs();
Chris@0 2697 }
Chris@0 2698 }
Chris@0 2699
Chris@0 2700 void
Chris@0 2701 MainWindow::saveSessionAs()
Chris@0 2702 {
Chris@0 2703 QString orig = m_audioFile;
Chris@0 2704 if (orig == "") orig = ".";
Chris@0 2705 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 2706
Chris@88 2707 QString path = getSaveFileName(FileFinder::SessionFile);
Chris@81 2708
Chris@81 2709 if (path == "") return;
Chris@0 2710
Chris@0 2711 if (!saveSessionFile(path)) {
Chris@0 2712 QMessageBox::critical(this, tr("Failed to save file"),
Chris@193 2713 tr("<b>Save failed</b><p>Session file \"%1\" could not be saved.").arg(path));
Chris@0 2714 } else {
Chris@0 2715 setWindowTitle(tr("Sonic Visualiser: %1")
Chris@0 2716 .arg(QFileInfo(path).fileName()));
Chris@0 2717 m_sessionFile = path;
Chris@0 2718 CommandHistory::getInstance()->documentSaved();
Chris@0 2719 documentRestored();
Chris@34 2720 m_recentFiles.addFile(path);
Chris@0 2721 }
Chris@0 2722 }
Chris@0 2723
Chris@90 2724 void
Chris@72 2725 MainWindow::preferenceChanged(PropertyContainer::PropertyName name)
Chris@72 2726 {
Chris@200 2727 MainWindowBase::preferenceChanged(name);
Chris@200 2728
Chris@200 2729 if (name == "Background Mode" && m_viewManager) {
Chris@180 2730 if (m_viewManager->getGlobalDarkBackground()) {
Chris@180 2731 m_panLayer->setBaseColour
Chris@180 2732 (ColourDatabase::getInstance()->getColourIndex(tr("Bright Green")));
Chris@180 2733 } else {
Chris@180 2734 m_panLayer->setBaseColour
Chris@180 2735 (ColourDatabase::getInstance()->getColourIndex(tr("Green")));
Chris@180 2736 }
Chris@200 2737 }
Chris@0 2738 }
Chris@0 2739
Chris@0 2740 void
Chris@239 2741 MainWindow::propertyStacksResized(int width)
Chris@239 2742 {
Chris@251 2743 // std::cerr << "MainWindow::propertyStacksResized(" << width << ")" << std::endl;
Chris@239 2744
Chris@239 2745 if (!m_playControlsSpacer) return;
Chris@239 2746
Chris@239 2747 int spacerWidth = width - m_playControlsWidth - 4;
Chris@239 2748
Chris@251 2749 // std::cerr << "resizing spacer from " << m_playControlsSpacer->width() << " to " << spacerWidth << std::endl;
Chris@239 2750
Chris@239 2751 m_playControlsSpacer->setFixedSize(QSize(spacerWidth, 2));
Chris@239 2752 }
Chris@239 2753
Chris@239 2754 void
Chris@0 2755 MainWindow::addPane()
Chris@0 2756 {
Chris@0 2757 QObject *s = sender();
Chris@0 2758 QAction *action = dynamic_cast<QAction *>(s);
Chris@0 2759
Chris@0 2760 if (!action) {
Chris@0 2761 std::cerr << "WARNING: MainWindow::addPane: sender is not an action"
Chris@0 2762 << std::endl;
Chris@0 2763 return;
Chris@0 2764 }
Chris@0 2765
Chris@0 2766 PaneActionMap::iterator i = m_paneActions.find(action);
Chris@0 2767
Chris@0 2768 if (i == m_paneActions.end()) {
Chris@0 2769 std::cerr << "WARNING: MainWindow::addPane: unknown action "
Chris@0 2770 << action->objectName().toStdString() << std::endl;
Chris@0 2771 return;
Chris@0 2772 }
Chris@0 2773
Chris@69 2774 addPane(i->second, action->text());
Chris@69 2775 }
Chris@69 2776
Chris@69 2777 void
Chris@232 2778 MainWindow::addPane(const LayerConfiguration &configuration, QString text)
Chris@69 2779 {
Chris@69 2780 CommandHistory::getInstance()->startCompoundOperation(text, true);
Chris@0 2781
Chris@0 2782 AddPaneCommand *command = new AddPaneCommand(this);
Chris@0 2783 CommandHistory::getInstance()->addCommand(command);
Chris@0 2784
Chris@0 2785 Pane *pane = command->getPane();
Chris@0 2786
Chris@69 2787 if (configuration.layer == LayerFactory::Spectrum) {
Chris@109 2788 pane->setPlaybackFollow(PlaybackScrollContinuous);
Chris@110 2789 pane->setFollowGlobalZoom(false);
Chris@112 2790 pane->setZoomLevel(512);
Chris@7 2791 }
Chris@7 2792
Chris@69 2793 if (configuration.layer != LayerFactory::TimeRuler &&
Chris@69 2794 configuration.layer != LayerFactory::Spectrum) {
Chris@8 2795
Chris@0 2796 if (!m_timeRulerLayer) {
Chris@0 2797 // std::cerr << "no time ruler layer, creating one" << std::endl;
Chris@0 2798 m_timeRulerLayer = m_document->createMainModelLayer
Chris@0 2799 (LayerFactory::TimeRuler);
Chris@0 2800 }
Chris@0 2801
Chris@0 2802 // std::cerr << "adding time ruler layer " << m_timeRulerLayer << std::endl;
Chris@0 2803
Chris@0 2804 m_document->addLayerToView(pane, m_timeRulerLayer);
Chris@0 2805 }
Chris@0 2806
Chris@69 2807 Layer *newLayer = m_document->createLayer(configuration.layer);
Chris@69 2808
Chris@69 2809 Model *suggestedModel = configuration.sourceModel;
Chris@66 2810 Model *model = 0;
Chris@66 2811
Chris@66 2812 if (suggestedModel) {
Chris@66 2813
Chris@66 2814 // check its validity
Chris@224 2815 std::vector<Model *> inputModels = m_document->getTransformInputModels();
Chris@66 2816 for (size_t j = 0; j < inputModels.size(); ++j) {
Chris@66 2817 if (inputModels[j] == suggestedModel) {
Chris@66 2818 model = suggestedModel;
Chris@66 2819 break;
Chris@66 2820 }
Chris@66 2821 }
Chris@66 2822
Chris@66 2823 if (!model) {
Chris@66 2824 std::cerr << "WARNING: Model " << (void *)suggestedModel
Chris@66 2825 << " appears in pane action map, but is not reported "
Chris@66 2826 << "by document as a valid transform source" << std::endl;
Chris@66 2827 }
Chris@66 2828 }
Chris@66 2829
Chris@66 2830 if (!model) model = m_document->getMainModel();
Chris@66 2831
Chris@66 2832 m_document->setModel(newLayer, model);
Chris@66 2833
Chris@69 2834 m_document->setChannel(newLayer, configuration.channel);
Chris@0 2835 m_document->addLayerToView(pane, newLayer);
Chris@0 2836
Chris@0 2837 m_paneStack->setCurrentPane(pane);
Chris@70 2838 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 2839
Chris@130 2840 // std::cerr << "MainWindow::addPane: global centre frame is "
Chris@130 2841 // << m_viewManager->getGlobalCentreFrame() << std::endl;
Chris@130 2842 // pane->setCentreFrame(m_viewManager->getGlobalCentreFrame());
Chris@73 2843
Chris@0 2844 CommandHistory::getInstance()->endCompoundOperation();
Chris@0 2845
Chris@0 2846 updateMenuStates();
Chris@0 2847 }
Chris@0 2848
Chris@0 2849 void
Chris@0 2850 MainWindow::addLayer()
Chris@0 2851 {
Chris@0 2852 QObject *s = sender();
Chris@0 2853 QAction *action = dynamic_cast<QAction *>(s);
Chris@0 2854
Chris@0 2855 if (!action) {
Chris@0 2856 std::cerr << "WARNING: MainWindow::addLayer: sender is not an action"
Chris@0 2857 << std::endl;
Chris@0 2858 return;
Chris@0 2859 }
Chris@0 2860
Chris@0 2861 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 2862
Chris@0 2863 if (!pane) {
Chris@0 2864 std::cerr << "WARNING: MainWindow::addLayer: no current pane" << std::endl;
Chris@0 2865 return;
Chris@0 2866 }
Chris@0 2867
Chris@0 2868 ExistingLayerActionMap::iterator ei = m_existingLayerActions.find(action);
Chris@0 2869
Chris@0 2870 if (ei != m_existingLayerActions.end()) {
Chris@0 2871 Layer *newLayer = ei->second;
Chris@0 2872 m_document->addLayerToView(pane, newLayer);
Chris@0 2873 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 2874 return;
Chris@0 2875 }
Chris@0 2876
Chris@95 2877 ei = m_sliceActions.find(action);
Chris@95 2878
Chris@95 2879 if (ei != m_sliceActions.end()) {
Chris@95 2880 Layer *newLayer = m_document->createLayer(LayerFactory::Slice);
Chris@95 2881 // document->setModel(newLayer, ei->second->getModel());
Chris@95 2882 SliceableLayer *source = dynamic_cast<SliceableLayer *>(ei->second);
Chris@95 2883 SliceLayer *dest = dynamic_cast<SliceLayer *>(newLayer);
Chris@95 2884 if (source && dest) {
Chris@205 2885 //!!!???
Chris@95 2886 dest->setSliceableModel(source->getSliceableModel());
Chris@95 2887 connect(source, SIGNAL(sliceableModelReplaced(const Model *, const Model *)),
Chris@95 2888 dest, SLOT(sliceableModelReplaced(const Model *, const Model *)));
Chris@95 2889 connect(m_document, SIGNAL(modelAboutToBeDeleted(Model *)),
Chris@95 2890 dest, SLOT(modelAboutToBeDeleted(Model *)));
Chris@95 2891 }
Chris@95 2892 m_document->addLayerToView(pane, newLayer);
Chris@95 2893 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@95 2894 return;
Chris@95 2895 }
Chris@95 2896
Chris@211 2897 TransformActionMap::iterator i = m_transformActions.find(action);
Chris@34 2898
Chris@34 2899 if (i == m_transformActions.end()) {
Chris@0 2900
Chris@0 2901 LayerActionMap::iterator i = m_layerActions.find(action);
Chris@0 2902
Chris@0 2903 if (i == m_layerActions.end()) {
Chris@0 2904 std::cerr << "WARNING: MainWindow::addLayer: unknown action "
Chris@0 2905 << action->objectName().toStdString() << std::endl;
Chris@0 2906 return;
Chris@0 2907 }
Chris@0 2908
Chris@232 2909 LayerFactory::LayerType type = i->second.layer;
Chris@0 2910
Chris@0 2911 LayerFactory::LayerTypeSet emptyTypes =
Chris@0 2912 LayerFactory::getInstance()->getValidEmptyLayerTypes();
Chris@0 2913
Chris@0 2914 Layer *newLayer;
Chris@0 2915
Chris@0 2916 if (emptyTypes.find(type) != emptyTypes.end()) {
Chris@0 2917
Chris@0 2918 newLayer = m_document->createEmptyLayer(type);
Chris@217 2919 if (newLayer) {
Chris@217 2920 m_toolActions[ViewManager::DrawMode]->trigger();
Chris@217 2921 }
Chris@0 2922
Chris@0 2923 } else {
Chris@0 2924
Chris@238 2925 if (!i->second.sourceModel) {
Chris@238 2926 // e.g. time ruler
Chris@238 2927 newLayer = m_document->createMainModelLayer(type);
Chris@232 2928 } else {
Chris@238 2929 newLayer = m_document->createLayer(type);
Chris@238 2930 if (m_document->isKnownModel(i->second.sourceModel)) {
Chris@238 2931 m_document->setChannel(newLayer, i->second.channel);
Chris@238 2932 m_document->setModel(newLayer, i->second.sourceModel);
Chris@238 2933 } else {
Chris@238 2934 std::cerr << "WARNING: MainWindow::addLayer: unknown model "
Chris@238 2935 << i->second.sourceModel
Chris@238 2936 << " (\""
Chris@238 2937 << (i->second.sourceModel ? i->second.sourceModel->objectName().toStdString() : "")
Chris@238 2938 << "\") in layer action map"
Chris@238 2939 << std::endl;
Chris@238 2940 }
Chris@232 2941 }
Chris@238 2942 }
Chris@0 2943
Chris@217 2944 if (newLayer) {
Chris@217 2945 m_document->addLayerToView(pane, newLayer);
Chris@217 2946 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@217 2947 }
Chris@0 2948
Chris@0 2949 return;
Chris@0 2950 }
Chris@0 2951
Chris@224 2952 //!!! want to do something like this, but it's not supported in
Chris@224 2953 //ModelTransformerFactory yet
Chris@224 2954 /*
Chris@0 2955 int channel = -1;
Chris@0 2956 // pick up the default channel from any existing layers on the same pane
Chris@0 2957 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@0 2958 int c = LayerFactory::getInstance()->getChannel(pane->getLayer(j));
Chris@0 2959 if (c != -1) {
Chris@0 2960 channel = c;
Chris@0 2961 break;
Chris@0 2962 }
Chris@0 2963 }
Chris@224 2964 */
Chris@0 2965
Chris@33 2966 // We always ask for configuration, even if the plugin isn't
Chris@33 2967 // supposed to be configurable, because we need to let the user
Chris@33 2968 // change the execution context (block size etc).
Chris@0 2969
Chris@224 2970 QString transformId = i->second;
Chris@224 2971 Transform transform = TransformFactory::getInstance()->
Chris@224 2972 getDefaultTransformFor(transformId);
Chris@27 2973
Chris@66 2974 std::vector<Model *> candidateInputModels =
Chris@224 2975 m_document->getTransformInputModels();
Chris@53 2976
Chris@219 2977 Model *defaultInputModel = 0;
Chris@219 2978 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@219 2979 Layer *layer = pane->getLayer(j);
Chris@219 2980 if (!layer) continue;
Chris@243 2981 if (LayerFactory::getInstance()->getLayerType(layer) !=
Chris@243 2982 LayerFactory::Waveform &&
Chris@243 2983 !layer->isLayerOpaque()) continue;
Chris@219 2984 Model *model = layer->getModel();
Chris@219 2985 if (!model) continue;
Chris@219 2986 for (size_t k = 0; k < candidateInputModels.size(); ++k) {
Chris@219 2987 if (candidateInputModels[k] == model) {
Chris@219 2988 defaultInputModel = model;
Chris@219 2989 break;
Chris@219 2990 }
Chris@219 2991 }
Chris@219 2992 if (defaultInputModel) break;
Chris@219 2993 }
Chris@219 2994
Chris@184 2995 size_t startFrame = 0, duration = 0;
Chris@184 2996 size_t endFrame = 0;
Chris@184 2997 m_viewManager->getSelection().getExtents(startFrame, endFrame);
Chris@184 2998 if (endFrame > startFrame) duration = endFrame - startFrame;
Chris@184 2999 else startFrame = 0;
Chris@184 3000
Chris@224 3001 ModelTransformer::Input input = ModelTransformerFactory::getInstance()->
Chris@224 3002 getConfigurationForTransform
Chris@211 3003 (transform,
Chris@211 3004 candidateInputModels,
Chris@219 3005 defaultInputModel,
Chris@211 3006 m_playSource,
Chris@211 3007 startFrame,
Chris@211 3008 duration);
Chris@211 3009
Chris@224 3010 if (!input.getModel()) return;
Chris@224 3011
Chris@224 3012 // std::cerr << "MainWindow::addLayer: Input model is " << input.getModel() << " \"" << input.getModel()->objectName().toStdString() << "\"" << std::endl;
Chris@224 3013
Chris@224 3014 Layer *newLayer = m_document->createDerivedLayer(transform, input);
Chris@0 3015
Chris@0 3016 if (newLayer) {
Chris@0 3017 m_document->addLayerToView(pane, newLayer);
Chris@224 3018 m_document->setChannel(newLayer, input.getChannel());
Chris@224 3019 m_recentTransforms.add(transformId);
Chris@70 3020 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 3021 }
Chris@0 3022
Chris@0 3023 updateMenuStates();
Chris@0 3024 }
Chris@0 3025
Chris@0 3026 void
Chris@0 3027 MainWindow::renameCurrentLayer()
Chris@0 3028 {
Chris@0 3029 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 3030 if (pane) {
Chris@0 3031 Layer *layer = pane->getSelectedLayer();
Chris@0 3032 if (layer) {
Chris@0 3033 bool ok = false;
Chris@0 3034 QString newName = QInputDialog::getText
Chris@0 3035 (this, tr("Rename Layer"),
Chris@0 3036 tr("New name for this layer:"),
Chris@0 3037 QLineEdit::Normal, layer->objectName(), &ok);
Chris@0 3038 if (ok) {
Chris@239 3039 layer->setPresentationName(newName);
Chris@95 3040 setupExistingLayersMenus();
Chris@0 3041 }
Chris@0 3042 }
Chris@0 3043 }
Chris@0 3044 }
Chris@0 3045
Chris@0 3046 void
Chris@207 3047 MainWindow::playSoloToggled()
Chris@207 3048 {
Chris@207 3049 MainWindowBase::playSoloToggled();
Chris@207 3050 m_soloModified = true;
Chris@207 3051 }
Chris@207 3052
Chris@207 3053 void
Chris@206 3054 MainWindow::alignToggled()
Chris@206 3055 {
Chris@206 3056 QAction *action = dynamic_cast<QAction *>(sender());
Chris@206 3057
Chris@207 3058 if (!m_viewManager) return;
Chris@207 3059
Chris@206 3060 if (action) {
Chris@206 3061 m_viewManager->setAlignMode(action->isChecked());
Chris@206 3062 } else {
Chris@206 3063 m_viewManager->setAlignMode(!m_viewManager->getAlignMode());
Chris@206 3064 }
Chris@206 3065
Chris@206 3066 if (m_viewManager->getAlignMode()) {
Chris@207 3067 m_prevSolo = m_soloAction->isChecked();
Chris@208 3068 if (!m_soloAction->isChecked()) {
Chris@208 3069 m_soloAction->setChecked(true);
Chris@208 3070 MainWindowBase::playSoloToggled();
Chris@208 3071 }
Chris@207 3072 m_soloModified = false;
Chris@207 3073 emit canChangeSolo(false);
Chris@206 3074 m_document->alignModels();
Chris@206 3075 m_document->setAutoAlignment(true);
Chris@206 3076 } else {
Chris@207 3077 if (!m_soloModified) {
Chris@208 3078 if (m_soloAction->isChecked() != m_prevSolo) {
Chris@208 3079 m_soloAction->setChecked(m_prevSolo);
Chris@208 3080 MainWindowBase::playSoloToggled();
Chris@208 3081 }
Chris@207 3082 }
Chris@207 3083 emit canChangeSolo(true);
Chris@206 3084 m_document->setAutoAlignment(false);
Chris@206 3085 }
Chris@206 3086
Chris@206 3087 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@206 3088
Chris@206 3089 Pane *pane = m_paneStack->getPane(i);
Chris@206 3090 if (!pane) continue;
Chris@206 3091
Chris@206 3092 pane->update();
Chris@206 3093 }
Chris@206 3094 }
Chris@206 3095
Chris@206 3096 void
Chris@59 3097 MainWindow::playSpeedChanged(int position)
Chris@0 3098 {
Chris@59 3099 PlaySpeedRangeMapper mapper(0, 200);
Chris@60 3100
Chris@60 3101 float percent = m_playSpeed->mappedValue();
Chris@60 3102 float factor = mapper.getFactorForValue(percent);
Chris@60 3103
Chris@60 3104 std::cerr << "speed = " << position << " percent = " << percent << " factor = " << factor << std::endl;
Chris@60 3105
Chris@59 3106 bool something = (position != 100);
Chris@155 3107
Chris@59 3108 int pc = lrintf(percent);
Chris@21 3109
Chris@155 3110 if (!something) {
Chris@155 3111 contextHelpChanged(tr("Playback speed: Normal"));
Chris@155 3112 } else {
Chris@155 3113 contextHelpChanged(tr("Playback speed: %1%2%")
Chris@155 3114 .arg(position > 100 ? "+" : "")
Chris@155 3115 .arg(pc));
Chris@155 3116 }
Chris@155 3117
Chris@240 3118 m_playSource->setTimeStretch(factor);
Chris@155 3119
Chris@155 3120 updateMenuStates();
Chris@16 3121 }
Chris@16 3122
Chris@26 3123 void
Chris@155 3124 MainWindow::speedUpPlayback()
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->maximum()) value = m_playSpeed->maximum();
Chris@155 3129 m_playSpeed->setValue(value);
Chris@155 3130 }
Chris@155 3131
Chris@155 3132 void
Chris@155 3133 MainWindow::slowDownPlayback()
Chris@155 3134 {
Chris@155 3135 int value = m_playSpeed->value();
Chris@155 3136 value = value - m_playSpeed->pageStep();
Chris@155 3137 if (value < m_playSpeed->minimum()) value = m_playSpeed->minimum();
Chris@155 3138 m_playSpeed->setValue(value);
Chris@155 3139 }
Chris@155 3140
Chris@155 3141 void
Chris@155 3142 MainWindow::restoreNormalPlayback()
Chris@155 3143 {
Chris@155 3144 m_playSpeed->setValue(m_playSpeed->defaultValue());
Chris@155 3145 }
Chris@155 3146
Chris@155 3147 void
Chris@227 3148 MainWindow::currentPaneChanged(Pane *pane)
Chris@227 3149 {
Chris@228 3150 MainWindowBase::currentPaneChanged(pane);
Chris@228 3151
Chris@227 3152 if (!pane || !m_panLayer) return;
Chris@227 3153 for (int i = pane->getLayerCount(); i > 0; ) {
Chris@227 3154 --i;
Chris@227 3155 Layer *layer = pane->getLayer(i);
Chris@227 3156 if (LayerFactory::getInstance()->getLayerType(layer) ==
Chris@227 3157 LayerFactory::Waveform) {
Chris@227 3158 RangeSummarisableTimeValueModel *tvm =
Chris@227 3159 dynamic_cast<RangeSummarisableTimeValueModel *>(layer->getModel());
Chris@227 3160 if (tvm) {
Chris@227 3161 m_panLayer->setModel(tvm);
Chris@227 3162 return;
Chris@227 3163 }
Chris@227 3164 }
Chris@227 3165 }
Chris@227 3166 }
Chris@227 3167
Chris@227 3168 void
Chris@116 3169 MainWindow::updateVisibleRangeDisplay(Pane *p) const
Chris@116 3170 {
Chris@116 3171 if (!getMainModel() || !p) {
Chris@116 3172 return;
Chris@116 3173 }
Chris@116 3174
Chris@117 3175 bool haveSelection = false;
Chris@117 3176 size_t startFrame = 0, endFrame = 0;
Chris@117 3177
Chris@117 3178 if (m_viewManager && m_viewManager->haveInProgressSelection()) {
Chris@117 3179
Chris@117 3180 bool exclusive = false;
Chris@117 3181 Selection s = m_viewManager->getInProgressSelection(exclusive);
Chris@117 3182
Chris@117 3183 if (!s.isEmpty()) {
Chris@117 3184 haveSelection = true;
Chris@117 3185 startFrame = s.getStartFrame();
Chris@117 3186 endFrame = s.getEndFrame();
Chris@117 3187 }
Chris@117 3188 }
Chris@117 3189
Chris@117 3190 if (!haveSelection) {
Chris@117 3191 startFrame = p->getFirstVisibleFrame();
Chris@117 3192 endFrame = p->getLastVisibleFrame();
Chris@117 3193 }
Chris@117 3194
Chris@116 3195 RealTime start = RealTime::frame2RealTime
Chris@117 3196 (startFrame, getMainModel()->getSampleRate());
Chris@116 3197
Chris@116 3198 RealTime end = RealTime::frame2RealTime
Chris@117 3199 (endFrame, getMainModel()->getSampleRate());
Chris@116 3200
Chris@116 3201 RealTime duration = end - start;
Chris@116 3202
Chris@116 3203 QString startStr, endStr, durationStr;
Chris@116 3204 startStr = start.toText(true).c_str();
Chris@116 3205 endStr = end.toText(true).c_str();
Chris@116 3206 durationStr = duration.toText(true).c_str();
Chris@116 3207
Chris@117 3208 if (haveSelection) {
Chris@117 3209 m_myStatusMessage = tr("Selection: %1 to %2 (duration %3)")
Chris@117 3210 .arg(startStr).arg(endStr).arg(durationStr);
Chris@117 3211 } else {
Chris@117 3212 m_myStatusMessage = tr("Visible: %1 to %2 (duration %3)")
Chris@117 3213 .arg(startStr).arg(endStr).arg(durationStr);
Chris@117 3214 }
Chris@116 3215
Chris@116 3216 statusBar()->showMessage(m_myStatusMessage);
Chris@116 3217 }
Chris@116 3218
Chris@116 3219 void
Chris@0 3220 MainWindow::outputLevelsChanged(float left, float right)
Chris@0 3221 {
Chris@0 3222 m_fader->setPeakLeft(left);
Chris@0 3223 m_fader->setPeakRight(right);
Chris@0 3224 }
Chris@0 3225
Chris@0 3226 void
Chris@0 3227 MainWindow::sampleRateMismatch(size_t requested, size_t actual,
Chris@0 3228 bool willResample)
Chris@0 3229 {
Chris@0 3230 if (!willResample) {
Chris@247 3231 emit hideSplash();
Chris@0 3232 QMessageBox::information
Chris@0 3233 (this, tr("Sample rate mismatch"),
Chris@193 3234 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 3235 .arg(requested).arg(actual));
Chris@0 3236 }
Chris@0 3237
Chris@0 3238 updateDescriptionLabel();
Chris@0 3239 }
Chris@0 3240
Chris@0 3241 void
Chris@42 3242 MainWindow::audioOverloadPluginDisabled()
Chris@42 3243 {
Chris@42 3244 QMessageBox::information
Chris@42 3245 (this, tr("Audio processing overload"),
Chris@193 3246 tr("<b>Overloaded</b><p>Audio effects plugin auditioning has been disabled due to a processing overload."));
Chris@42 3247 }
Chris@42 3248
Chris@42 3249 void
Chris@200 3250 MainWindow::layerRemoved(Layer *layer)
Chris@0 3251 {
Chris@95 3252 setupExistingLayersMenus();
Chris@200 3253 MainWindowBase::layerRemoved(layer);
Chris@0 3254 }
Chris@0 3255
Chris@0 3256 void
Chris@0 3257 MainWindow::layerInAView(Layer *layer, bool inAView)
Chris@0 3258 {
Chris@95 3259 setupExistingLayersMenus();
Chris@200 3260 MainWindowBase::layerInAView(layer, inAView);
Chris@0 3261 }
Chris@0 3262
Chris@0 3263 void
Chris@0 3264 MainWindow::modelAdded(Model *model)
Chris@0 3265 {
Chris@200 3266 MainWindowBase::modelAdded(model);
Chris@66 3267 if (dynamic_cast<DenseTimeValueModel *>(model)) {
Chris@66 3268 setupPaneAndLayerMenus();
Chris@66 3269 }
Chris@0 3270 }
Chris@0 3271
Chris@0 3272 void
Chris@0 3273 MainWindow::mainModelChanged(WaveFileModel *model)
Chris@0 3274 {
Chris@0 3275 m_panLayer->setModel(model);
Chris@200 3276
Chris@200 3277 MainWindowBase::mainModelChanged(model);
Chris@200 3278
Chris@200 3279 if (m_playTarget) {
Chris@200 3280 connect(m_fader, SIGNAL(valueChanged(float)),
Chris@200 3281 m_playTarget, SLOT(setOutputGain(float)));
Chris@200 3282 }
Chris@0 3283 }
Chris@0 3284
Chris@0 3285 void
Chris@200 3286 MainWindow::setInstantsNumbering()
Chris@0 3287 {
Chris@200 3288 QAction *a = dynamic_cast<QAction *>(sender());
Chris@200 3289 if (!a) return;
Chris@200 3290
Chris@200 3291 int type = m_numberingActions[a];
Chris@200 3292
Chris@200 3293 if (m_labeller) m_labeller->setType(Labeller::ValueType(type));
Chris@200 3294
Chris@200 3295 QSettings settings;
Chris@200 3296 settings.beginGroup("MainWindow");
Chris@200 3297 settings.setValue("labellertype", type);
Chris@200 3298 settings.endGroup();
Chris@200 3299 }
Chris@200 3300
Chris@200 3301 void
Chris@200 3302 MainWindow::setInstantsCounterCycle()
Chris@200 3303 {
Chris@200 3304 QAction *a = dynamic_cast<QAction *>(sender());
Chris@200 3305 if (!a) return;
Chris@200 3306
Chris@200 3307 int cycle = a->text().toInt();
Chris@200 3308 if (cycle == 0) return;
Chris@200 3309
Chris@200 3310 if (m_labeller) m_labeller->setCounterCycleSize(cycle);
Chris@200 3311
Chris@200 3312 QSettings settings;
Chris@200 3313 settings.beginGroup("MainWindow");
Chris@200 3314 settings.setValue("labellercycle", cycle);
Chris@200 3315 settings.endGroup();
Chris@200 3316 }
Chris@200 3317
Chris@200 3318 void
Chris@200 3319 MainWindow::resetInstantsCounters()
Chris@200 3320 {
Chris@200 3321 LabelCounterInputDialog dialog(m_labeller, this);
Chris@241 3322 dialog.setWindowTitle(tr("Reset Counters"));
Chris@200 3323 dialog.exec();
Chris@0 3324 }
Chris@0 3325
Chris@0 3326 void
Chris@233 3327 MainWindow::modelGenerationFailed(QString transformName, QString message)
Chris@233 3328 {
Chris@247 3329 emit hideSplash();
Chris@247 3330
Chris@233 3331 if (message != "") {
Chris@233 3332
Chris@233 3333 QMessageBox::warning
Chris@233 3334 (this,
Chris@233 3335 tr("Failed to generate layer"),
Chris@233 3336 tr("<b>Layer generation failed</b><p>Failed to generate derived layer.<p>The layer transform \"%1\" failed:<p>%2")
Chris@233 3337 .arg(transformName).arg(message),
Chris@233 3338 QMessageBox::Ok);
Chris@233 3339 } else {
Chris@233 3340 QMessageBox::warning
Chris@233 3341 (this,
Chris@233 3342 tr("Failed to generate layer"),
Chris@233 3343 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 3344 .arg(transformName),
Chris@233 3345 QMessageBox::Ok);
Chris@233 3346 }
Chris@233 3347 }
Chris@233 3348
Chris@233 3349 void
Chris@233 3350 MainWindow::modelGenerationWarning(QString transformName, QString message)
Chris@233 3351 {
Chris@247 3352 emit hideSplash();
Chris@247 3353
Chris@233 3354 QMessageBox::warning
Chris@233 3355 (this, tr("Warning"), message, QMessageBox::Ok);
Chris@233 3356 }
Chris@233 3357
Chris@233 3358 void
Chris@233 3359 MainWindow::modelRegenerationFailed(QString layerName,
Chris@233 3360 QString transformName, QString message)
Chris@233 3361 {
Chris@247 3362 emit hideSplash();
Chris@247 3363
Chris@233 3364 if (message != "") {
Chris@233 3365
Chris@233 3366 QMessageBox::warning
Chris@233 3367 (this,
Chris@233 3368 tr("Failed to regenerate layer"),
Chris@233 3369 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 3370 .arg(layerName).arg(transformName).arg(message),
Chris@233 3371 QMessageBox::Ok);
Chris@233 3372 } else {
Chris@233 3373 QMessageBox::warning
Chris@233 3374 (this,
Chris@233 3375 tr("Failed to regenerate layer"),
Chris@233 3376 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 3377 .arg(layerName).arg(transformName),
Chris@233 3378 QMessageBox::Ok);
Chris@233 3379 }
Chris@233 3380 }
Chris@233 3381
Chris@233 3382 void
Chris@233 3383 MainWindow::modelRegenerationWarning(QString layerName,
Chris@233 3384 QString transformName, QString message)
Chris@233 3385 {
Chris@247 3386 emit hideSplash();
Chris@247 3387
Chris@233 3388 QMessageBox::warning
Chris@233 3389 (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 3390 }
Chris@233 3391
Chris@233 3392 void
Chris@233 3393 MainWindow::alignmentFailed(QString transformName, QString message)
Chris@0 3394 {
Chris@247 3395 emit hideSplash();
Chris@247 3396
Chris@0 3397 QMessageBox::warning
Chris@0 3398 (this,
Chris@233 3399 tr("Failed to calculate alignment"),
Chris@233 3400 tr("<b>Alignment calculation failed</b><p>Failed to calculate an audio alignment using transform \"%1\":<p>%2")
Chris@233 3401 .arg(transformName).arg(message),
Chris@165 3402 QMessageBox::Ok);
Chris@0 3403 }
Chris@0 3404
Chris@0 3405 void
Chris@0 3406 MainWindow::rightButtonMenuRequested(Pane *pane, QPoint position)
Chris@0 3407 {
Chris@0 3408 // std::cerr << "MainWindow::rightButtonMenuRequested(" << pane << ", " << position.x() << ", " << position.y() << ")" << std::endl;
Chris@0 3409 m_paneStack->setCurrentPane(pane);
Chris@0 3410 m_rightButtonMenu->popup(position);
Chris@0 3411 }
Chris@0 3412
Chris@0 3413 void
Chris@0 3414 MainWindow::showLayerTree()
Chris@0 3415 {
Chris@219 3416 if (!m_layerTreeDialog.isNull()) {
Chris@219 3417 m_layerTreeDialog->show();
Chris@219 3418 m_layerTreeDialog->raise();
Chris@177 3419 return;
Chris@177 3420 }
Chris@177 3421
Chris@219 3422 m_layerTreeDialog = new LayerTreeDialog(m_paneStack);
Chris@232 3423 m_layerTreeDialog->setAttribute(Qt::WA_DeleteOnClose); // see below
Chris@219 3424 m_layerTreeDialog->show();
Chris@0 3425 }
Chris@0 3426
Chris@0 3427 void
Chris@0 3428 MainWindow::preferences()
Chris@0 3429 {
Chris@0 3430 if (!m_preferencesDialog.isNull()) {
Chris@0 3431 m_preferencesDialog->show();
Chris@0 3432 m_preferencesDialog->raise();
Chris@0 3433 return;
Chris@0 3434 }
Chris@0 3435
Chris@0 3436 m_preferencesDialog = new PreferencesDialog(this);
Chris@0 3437
Chris@0 3438 // DeleteOnClose is safe here, because m_preferencesDialog is a
Chris@0 3439 // QPointer that will be zeroed when the dialog is deleted. We
Chris@0 3440 // use it in preference to leaving the dialog lying around because
Chris@0 3441 // if you Cancel the dialog, it resets the preferences state
Chris@0 3442 // without resetting its own widgets, so its state will be
Chris@0 3443 // incorrect when next shown unless we construct it afresh
Chris@0 3444 m_preferencesDialog->setAttribute(Qt::WA_DeleteOnClose);
Chris@0 3445
Chris@0 3446 m_preferencesDialog->show();
Chris@0 3447 }
Chris@0 3448
Chris@0 3449 void
Chris@90 3450 MainWindow::mouseEnteredWidget()
Chris@90 3451 {
Chris@90 3452 QWidget *w = dynamic_cast<QWidget *>(sender());
Chris@90 3453 if (!w) return;
Chris@90 3454
Chris@90 3455 if (w == m_fader) {
Chris@116 3456 contextHelpChanged(tr("Adjust the master playback level"));
Chris@90 3457 } else if (w == m_playSpeed) {
Chris@116 3458 contextHelpChanged(tr("Adjust the master playback speed"));
Chris@90 3459 }
Chris@90 3460 }
Chris@90 3461
Chris@90 3462 void
Chris@90 3463 MainWindow::mouseLeftWidget()
Chris@90 3464 {
Chris@116 3465 contextHelpChanged("");
Chris@116 3466 }
Chris@116 3467
Chris@116 3468 void
Chris@0 3469 MainWindow::website()
Chris@0 3470 {
Chris@0 3471 openHelpUrl(tr("http://www.sonicvisualiser.org/"));
Chris@0 3472 }
Chris@0 3473
Chris@0 3474 void
Chris@0 3475 MainWindow::help()
Chris@0 3476 {
Chris@236 3477 openHelpUrl(tr("http://www.sonicvisualiser.org/doc/reference/1.2/en/"));
Chris@0 3478 }
Chris@0 3479
Chris@0 3480 void
Chris@0 3481 MainWindow::about()
Chris@0 3482 {
Chris@0 3483 bool debug = false;
Chris@0 3484 QString version = "(unknown version)";
Chris@0 3485
Chris@0 3486 #ifdef BUILD_DEBUG
Chris@0 3487 debug = true;
Chris@0 3488 #endif
Chris@0 3489 #ifdef SV_VERSION
Chris@0 3490 #ifdef SVNREV
Chris@0 3491 version = tr("Release %1 : Revision %2").arg(SV_VERSION).arg(SVNREV);
Chris@0 3492 #else
Chris@0 3493 version = tr("Release %1").arg(SV_VERSION);
Chris@0 3494 #endif
Chris@0 3495 #else
Chris@0 3496 #ifdef SVNREV
Chris@0 3497 version = tr("Unreleased : Revision %1").arg(SVNREV);
Chris@0 3498 #endif
Chris@0 3499 #endif
Chris@0 3500
Chris@0 3501 QString aboutText;
Chris@0 3502
Chris@0 3503 aboutText += tr("<h3>About Sonic Visualiser</h3>");
Chris@231 3504 aboutText += tr("<p>Sonic Visualiser is a program for viewing and exploring audio data for semantic music analysis and annotation.</p>");
Chris@111 3505 aboutText += tr("<p>%1 : %2 configuration</p>")
Chris@0 3506 .arg(version)
Chris@0 3507 .arg(debug ? tr("Debug") : tr("Release"));
Chris@0 3508
Chris@132 3509 #ifndef BUILD_STATIC
Chris@132 3510 aboutText += tr("<br>Using Qt v%1 &copy; Trolltech AS").arg(QT_VERSION_STR);
Chris@132 3511 #else
Chris@132 3512 #ifdef QT_SHARED
Chris@132 3513 aboutText += tr("<br>Using Qt v%1 &copy; Trolltech AS").arg(QT_VERSION_STR);
Chris@132 3514 #endif
Chris@132 3515 #endif
Chris@132 3516
Chris@0 3517 #ifdef BUILD_STATIC
Chris@0 3518 aboutText += tr("<p>Statically linked");
Chris@0 3519 #ifndef QT_SHARED
Chris@0 3520 aboutText += tr("<br>With Qt (v%1) &copy; Trolltech AS").arg(QT_VERSION_STR);
Chris@0 3521 #endif
Chris@0 3522 #ifdef HAVE_JACK
Chris@93 3523 #ifdef JACK_VERSION
Chris@257 3524 aboutText += tr("<br>With JACK audio output library (v%1) &copy; Paul Davis and Jack O'Quin").arg(JACK_VERSION);
Chris@93 3525 #else
Chris@257 3526 aboutText += tr("<br>With JACK audio output library &copy; Paul Davis and Jack O'Quin");
Chris@93 3527 #endif
Chris@0 3528 #endif
Chris@0 3529 #ifdef HAVE_PORTAUDIO
Chris@257 3530 aboutText += tr("<br>With PortAudio audio output library &copy; Ross Bencina and Phil Burk");
Chris@257 3531 #endif
Chris@257 3532 #ifdef HAVE_LIBPULSE
Chris@257 3533 aboutText += tr("<br>With PulseAudio audio output library &copy; Lennart Poettering and Pierre Ossman");
Chris@0 3534 #endif
Chris@0 3535 #ifdef HAVE_OGGZ
Chris@93 3536 #ifdef OGGZ_VERSION
Chris@0 3537 aboutText += tr("<br>With Ogg file decoder (oggz v%1, fishsound v%2) &copy; CSIRO Australia").arg(OGGZ_VERSION).arg(FISHSOUND_VERSION);
Chris@93 3538 #else
Chris@93 3539 aboutText += tr("<br>With Ogg file decoder &copy; CSIRO Australia");
Chris@93 3540 #endif
Chris@0 3541 #endif
Chris@0 3542 #ifdef HAVE_MAD
Chris@93 3543 #ifdef MAD_VERSION
Chris@0 3544 aboutText += tr("<br>With MAD mp3 decoder (v%1) &copy; Underbit Technologies Inc").arg(MAD_VERSION);
Chris@93 3545 #else
Chris@93 3546 aboutText += tr("<br>With MAD mp3 decoder &copy; Underbit Technologies Inc");
Chris@93 3547 #endif
Chris@0 3548 #endif
Chris@0 3549 #ifdef HAVE_SAMPLERATE
Chris@93 3550 #ifdef SAMPLERATE_VERSION
Chris@0 3551 aboutText += tr("<br>With libsamplerate (v%1) &copy; Erik de Castro Lopo").arg(SAMPLERATE_VERSION);
Chris@93 3552 #else
Chris@93 3553 aboutText += tr("<br>With libsamplerate &copy; Erik de Castro Lopo");
Chris@93 3554 #endif
Chris@0 3555 #endif
Chris@0 3556 #ifdef HAVE_SNDFILE
Chris@93 3557 #ifdef SNDFILE_VERSION
Chris@0 3558 aboutText += tr("<br>With libsndfile (v%1) &copy; Erik de Castro Lopo").arg(SNDFILE_VERSION);
Chris@93 3559 #else
Chris@93 3560 aboutText += tr("<br>With libsndfile &copy; Erik de Castro Lopo");
Chris@93 3561 #endif
Chris@0 3562 #endif
Chris@127 3563 #ifdef HAVE_FFTW3F
Chris@93 3564 #ifdef FFTW3_VERSION
Chris@0 3565 aboutText += tr("<br>With FFTW3 (v%1) &copy; Matteo Frigo and MIT").arg(FFTW3_VERSION);
Chris@93 3566 #else
Chris@93 3567 aboutText += tr("<br>With FFTW3 &copy; Matteo Frigo and MIT");
Chris@93 3568 #endif
Chris@0 3569 #endif
Chris@0 3570 #ifdef HAVE_VAMP
Chris@114 3571 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 3572 #endif
Chris@0 3573 aboutText += tr("<br>With LADSPA plugin support (API v%1) &copy; Richard Furse, Paul Davis, Stefan Westerfeld").arg(LADSPA_VERSION);
Chris@0 3574 aboutText += tr("<br>With DSSI plugin support (API v%1) &copy; Chris Cannam, Steve Harris, Sean Bolton").arg(DSSI_VERSION);
Chris@69 3575 #ifdef HAVE_LIBLO
Chris@93 3576 #ifdef LIBLO_VERSION
Chris@69 3577 aboutText += tr("<br>With liblo Lite OSC library (v%1) &copy; Steve Harris").arg(LIBLO_VERSION);
Chris@93 3578 #else
Chris@93 3579 aboutText += tr("<br>With liblo Lite OSC library &copy; Steve Harris").arg(LIBLO_VERSION);
Chris@93 3580 #endif
Chris@70 3581 if (m_oscQueue && m_oscQueue->isOK()) {
Chris@69 3582 aboutText += tr("<p>The OSC URL for this instance is: \"%1\"").arg(m_oscQueue->getOSCURL());
Chris@69 3583 }
Chris@69 3584 #endif
Chris@0 3585 aboutText += "</p>";
Chris@0 3586 #endif
Chris@0 3587
Chris@0 3588 aboutText +=
Chris@231 3589 "<p>Sonic Visualiser Copyright &copy; 2005 - 2008 Chris Cannam and "
Chris@90 3590 "Queen Mary, University of London.</p>"
Chris@231 3591 "<p>This program is free software; you can redistribute it and/or "
Chris@231 3592 "modify it under the terms of the GNU General Public License as "
Chris@231 3593 "published by the Free Software Foundation; either version 2 of the "
Chris@0 3594 "License, or (at your option) any later version.<br>See the file "
Chris@0 3595 "COPYING included with this distribution for more information.</p>";
Chris@0 3596
Chris@0 3597 QMessageBox::about(this, tr("About Sonic Visualiser"), aboutText);
Chris@0 3598 }
Chris@0 3599
Chris@162 3600 void
Chris@162 3601 MainWindow::keyReference()
Chris@162 3602 {
Chris@162 3603 m_keyReference->show();
Chris@162 3604 }
Chris@162 3605