annotate main/MainWindow.cpp @ 308:4ad11b1cf050

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