annotate main/MainWindow.cpp @ 320:dfb586b4d50d

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