annotate main/MainWindow.cpp @ 265:d55e4c0f7d9e

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