annotate main/MainWindow.cpp @ 220:474ddd0f4bb4

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