annotate main/MainWindow.cpp @ 225:d7ded015af32

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