annotate main/MainWindow.cpp @ 1150:5e6e1e074080 3.0-plus-imaf

Merge branches 3.0-integration and imaf_enc to 3.0-plus-imaf
author Chris Cannam
date Wed, 20 Apr 2016 12:06:28 +0100
parents b3b5885e7c2c b987cc23a26c
children
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@634 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@634 16
Chris@144 17 #include "../version.h"
Chris@0 18
Chris@0 19 #include "MainWindow.h"
Chris@0 20 #include "PreferencesDialog.h"
Chris@0 21
Chris@1 22 #include "view/Pane.h"
Chris@1 23 #include "view/PaneStack.h"
Chris@1 24 #include "data/model/WaveFileModel.h"
Chris@1 25 #include "data/model/SparseOneDimensionalModel.h"
Chris@415 26 #include "data/model/RangeSummarisableTimeValueModel.h"
Chris@185 27 #include "data/model/NoteModel.h"
Chris@895 28 #include "data/model/AggregateWaveModel.h"
Chris@189 29 #include "data/model/Labeller.h"
Chris@222 30 #include "data/osc/OSCQueue.h"
Chris@216 31 #include "framework/Document.h"
Chris@357 32 #include "framework/TransformUserConfigurator.h"
Chris@1 33 #include "view/ViewManager.h"
Chris@0 34 #include "base/Preferences.h"
Chris@423 35 #include "base/ResourceFinder.h"
Chris@0 36 #include "layer/WaveformLayer.h"
Chris@0 37 #include "layer/TimeRulerLayer.h"
Chris@0 38 #include "layer/TimeInstantLayer.h"
Chris@0 39 #include "layer/TimeValueLayer.h"
Chris@307 40 #include "layer/NoteLayer.h"
Chris@0 41 #include "layer/Colour3DPlotLayer.h"
Chris@95 42 #include "layer/SliceLayer.h"
Chris@95 43 #include "layer/SliceableLayer.h"
Chris@193 44 #include "layer/ImageLayer.h"
Chris@340 45 #include "layer/RegionLayer.h"
Chris@0 46 #include "widgets/Fader.h"
Chris@65 47 #include "view/Overview.h"
Chris@0 48 #include "widgets/PropertyBox.h"
Chris@0 49 #include "widgets/PropertyStack.h"
Chris@0 50 #include "widgets/AudioDial.h"
Chris@168 51 #include "widgets/IconLoader.h"
Chris@219 52 #include "widgets/LayerTreeDialog.h"
Chris@0 53 #include "widgets/ListInputDialog.h"
Chris@36 54 #include "widgets/SubdividingMenu.h"
Chris@90 55 #include "widgets/NotifyingPushButton.h"
Chris@162 56 #include "widgets/KeyReference.h"
Chris@273 57 #include "widgets/TransformFinder.h"
Chris@192 58 #include "widgets/LabelCounterInputDialog.h"
Chris@302 59 #include "widgets/ActivityLog.h"
Chris@891 60 #include "widgets/UnitConverter.h"
Chris@1035 61 #include "audio/AudioCallbackPlaySource.h"
Chris@1047 62 #include "audio/AudioRecordTarget.h"
Chris@1035 63 #include "audio/PlaySpeedRangeMapper.h"
Chris@1 64 #include "data/fileio/DataFileReaderFactory.h"
Chris@180 65 #include "data/fileio/PlaylistFileReader.h"
Chris@1 66 #include "data/fileio/WavFileWriter.h"
Chris@1 67 #include "data/fileio/CSVFileWriter.h"
Chris@185 68 #include "data/fileio/MIDIFileWriter.h"
Chris@1 69 #include "data/fileio/BZipFileDevice.h"
Chris@198 70 #include "data/fileio/FileSource.h"
Chris@304 71 #include "data/midi/MIDIInput.h"
Chris@1 72 #include "base/RecentFiles.h"
Chris@1145 73 #include "plugin/PluginScan.h"
Chris@249 74 #include "transform/TransformFactory.h"
Chris@249 75 #include "transform/ModelTransformerFactory.h"
Chris@0 76 #include "base/PlayParameterRepository.h"
Chris@0 77 #include "base/XmlExportable.h"
Chris@248 78 #include "widgets/CommandHistory.h"
Chris@0 79 #include "base/Profiler.h"
Chris@0 80 #include "base/Clipboard.h"
Chris@165 81 #include "base/UnitDatabase.h"
Chris@248 82 #include "layer/ColourDatabase.h"
Chris@265 83 #include "widgets/ModelDataTableDialog.h"
Chris@289 84 #include "rdf/PluginRDFIndexer.h"
Chris@291 85 #include "rdf/RDFExporter.h"
Chris@276 86
Chris@662 87 #include "Surveyer.h"
Chris@663 88 #include "NetworkPermissionTester.h"
Chris@334 89 #include "framework/VersionTester.h"
Chris@333 90
Chris@0 91 // For version information
Chris@280 92 #include <vamp/vamp.h>
Chris@280 93 #include <vamp-hostsdk/PluginBase.h>
Chris@0 94 #include "plugin/api/ladspa.h"
Chris@0 95 #include "plugin/api/dssi.h"
Chris@0 96
Chris@1035 97 #include <bqaudioio/SystemPlaybackTarget.h>
Chris@1055 98 #include <bqaudioio/SystemAudioIO.h>
Chris@1035 99
Chris@0 100 #include <QApplication>
Chris@0 101 #include <QMessageBox>
Chris@0 102 #include <QGridLayout>
Chris@0 103 #include <QLabel>
Chris@0 104 #include <QAction>
Chris@0 105 #include <QMenuBar>
Chris@0 106 #include <QToolBar>
Chris@0 107 #include <QInputDialog>
Chris@0 108 #include <QStatusBar>
Chris@0 109 #include <QTreeView>
Chris@0 110 #include <QFile>
Chris@88 111 #include <QFileInfo>
Chris@88 112 #include <QDir>
Chris@0 113 #include <QTextStream>
Chris@911 114 #include <QTextCodec>
Chris@0 115 #include <QProcess>
Chris@7 116 #include <QShortcut>
Chris@5 117 #include <QSettings>
Chris@11 118 #include <QDateTime>
Chris@11 119 #include <QProcess>
Chris@16 120 #include <QCheckBox>
Chris@55 121 #include <QRegExp>
Chris@158 122 #include <QScrollArea>
Chris@425 123 #include <QDesktopServices>
Chris@483 124 #include <QDialogButtonBox>
Chris@426 125 #include <QFileSystemWatcher>
Chris@0 126
Chris@0 127 #include <iostream>
Chris@0 128 #include <cstdio>
Chris@0 129 #include <errno.h>
Chris@0 130
Chris@33 131 using std::vector;
Chris@33 132 using std::map;
Chris@33 133 using std::set;
Chris@33 134
Chris@634 135 //IMAF REQUIRED LIBRARIES AND VARIABLES
Chris@634 136 #include "IMAFencoder.c"
Chris@634 137 #include "checkbox.h"
Chris@634 138 #include <QFileDialog>
Chris@634 139 #include "imafdecoder.cpp"
Chris@634 140
Chris@634 141 QString ImafFileName,ImageFileName,TextFileName; //name of the files
Chris@634 142 QString files_paths[maxtracks]; // change maxtracks in IMAFencoder.h
Chris@634 143 int ImafVolumeValues[maxtracks];
Chris@634 144 int numtracks;
Chris@634 145 bool has_image, has_lyrics;
Chris@634 146 int selrule_type, selrule_par1, selrule_par2;
Chris@634 147 int mixrule_type, mixrule_par1, mixrule_par2, mixrule_par3, mixrule_par4;
Chris@634 148 int group_tracks[maxtracks], group_volume;
Chris@634 149 QString group_descr, group_name;
Chris@634 150 int preset_type, fade_in;
Chris@634 151
Chris@636 152 bool isIMAF;
Chris@0 153
Chris@1045 154 MainWindow::MainWindow(SoundOptions options, bool withOSCSupport) :
Chris@1045 155 MainWindowBase(options),
Chris@65 156 m_overview(0),
Chris@0 157 m_mainMenusCreated(false),
Chris@0 158 m_paneMenu(0),
Chris@0 159 m_layerMenu(0),
Chris@34 160 m_transformsMenu(0),
Chris@155 161 m_playbackMenu(0),
Chris@0 162 m_existingLayersMenu(0),
Chris@95 163 m_sliceMenu(0),
Chris@34 164 m_recentFilesMenu(0),
Chris@211 165 m_recentTransformsMenu(0),
Chris@426 166 m_templatesMenu(0),
Chris@0 167 m_rightButtonMenu(0),
Chris@0 168 m_rightButtonLayerMenu(0),
Chris@211 169 m_rightButtonTransformsMenu(0),
Chris@155 170 m_rightButtonPlaybackMenu(0),
Chris@207 171 m_soloAction(0),
Chris@265 172 m_rwdStartAction(0),
Chris@323 173 m_rwdSimilarAction(0),
Chris@265 174 m_rwdAction(0),
Chris@155 175 m_ffwdAction(0),
Chris@323 176 m_ffwdSimilarAction(0),
Chris@265 177 m_ffwdEndAction(0),
Chris@265 178 m_playAction(0),
Chris@1047 179 m_recordAction(0),
Chris@265 180 m_playSelectionAction(0),
Chris@265 181 m_playLoopAction(0),
Chris@705 182 m_soloModified(false),
Chris@705 183 m_prevSolo(false),
Chris@239 184 m_playControlsSpacer(0),
Chris@239 185 m_playControlsWidth(0),
Chris@162 186 m_preferencesDialog(0),
Chris@219 187 m_layerTreeDialog(0),
Chris@302 188 m_activityLog(new ActivityLog()),
Chris@891 189 m_unitConverter(new UnitConverter()),
Chris@426 190 m_keyReference(new KeyReference()),
Chris@426 191 m_templateWatcher(0)
Chris@0 192 {
Chris@253 193 Profiler profiler("MainWindow::MainWindow");
Chris@253 194
Chris@518 195 setWindowTitle(QApplication::applicationName());
Chris@0 196
Chris@165 197 UnitDatabase *udb = UnitDatabase::getInstance();
Chris@165 198 udb->registerUnit("Hz");
Chris@165 199 udb->registerUnit("dB");
Chris@165 200 udb->registerUnit("s");
Chris@165 201
Chris@165 202 ColourDatabase *cdb = ColourDatabase::getInstance();
Chris@165 203 cdb->addColour(Qt::black, tr("Black"));
Chris@165 204 cdb->addColour(Qt::darkRed, tr("Red"));
Chris@165 205 cdb->addColour(Qt::darkBlue, tr("Blue"));
Chris@165 206 cdb->addColour(Qt::darkGreen, tr("Green"));
Chris@165 207 cdb->addColour(QColor(200, 50, 255), tr("Purple"));
Chris@165 208 cdb->addColour(QColor(255, 150, 50), tr("Orange"));
Chris@166 209 cdb->setUseDarkBackground(cdb->addColour(Qt::white, tr("White")), true);
Chris@166 210 cdb->setUseDarkBackground(cdb->addColour(Qt::red, tr("Bright Red")), true);
Chris@166 211 cdb->setUseDarkBackground(cdb->addColour(QColor(30, 150, 255), tr("Bright Blue")), true);
Chris@166 212 cdb->setUseDarkBackground(cdb->addColour(Qt::green, tr("Bright Green")), true);
Chris@166 213 cdb->setUseDarkBackground(cdb->addColour(QColor(225, 74, 255), tr("Bright Purple")), true);
Chris@166 214 cdb->setUseDarkBackground(cdb->addColour(QColor(255, 188, 80), tr("Bright Orange")), true);
Chris@0 215
Chris@0 216 QFrame *frame = new QFrame;
Chris@0 217 setCentralWidget(frame);
Chris@0 218
Chris@0 219 QGridLayout *layout = new QGridLayout;
Chris@180 220
Chris@519 221 m_descriptionLabel = new QLabel;
Chris@0 222
Chris@489 223 m_mainScroll = new QScrollArea(frame);
Chris@489 224 m_mainScroll->setWidgetResizable(true);
Chris@489 225 m_mainScroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
Chris@489 226 m_mainScroll->setFrameShape(QFrame::NoFrame);
Chris@489 227
Chris@489 228 m_mainScroll->setWidget(m_paneStack);
Chris@159 229
Chris@65 230 m_overview = new Overview(frame);
Chris@65 231 m_overview->setViewManager(m_viewManager);
Chris@65 232 m_overview->setFixedHeight(40);
Chris@144 233 #ifndef _WIN32
Chris@144 234 // For some reason, the contents of the overview never appear if we
Chris@144 235 // make this setting on Windows. I have no inclination at the moment
Chris@144 236 // to track down the reason why.
Chris@129 237 m_overview->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
Chris@144 238 #endif
Chris@90 239 connect(m_overview, SIGNAL(contextHelpChanged(const QString &)),
Chris@116 240 this, SLOT(contextHelpChanged(const QString &)));
Chris@0 241
Chris@0 242 m_panLayer = new WaveformLayer;
Chris@0 243 m_panLayer->setChannelMode(WaveformLayer::MergeChannels);
Chris@0 244 m_panLayer->setAggressiveCacheing(true);
Chris@65 245 m_overview->addLayer(m_panLayer);
Chris@174 246
Chris@174 247 if (m_viewManager->getGlobalDarkBackground()) {
Chris@174 248 m_panLayer->setBaseColour
Chris@174 249 (ColourDatabase::getInstance()->getColourIndex(tr("Bright Green")));
Chris@174 250 } else {
Chris@174 251 m_panLayer->setBaseColour
Chris@174 252 (ColourDatabase::getInstance()->getColourIndex(tr("Green")));
Chris@200 253 }
Chris@0 254
Chris@0 255 m_fader = new Fader(frame, false);
Chris@90 256 connect(m_fader, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
Chris@90 257 connect(m_fader, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
Chris@0 258
Chris@0 259 m_playSpeed = new AudioDial(frame);
Chris@12 260 m_playSpeed->setMinimum(0);
Chris@1031 261 m_playSpeed->setMaximum(120);
Chris@1031 262 m_playSpeed->setValue(60);
Chris@261 263 m_playSpeed->setFixedWidth(32);
Chris@261 264 m_playSpeed->setFixedHeight(32);
Chris@0 265 m_playSpeed->setNotchesVisible(true);
Chris@25 266 m_playSpeed->setPageStep(10);
Chris@1031 267 m_playSpeed->setObjectName(tr("Playback Speed"));
Chris@1031 268 m_playSpeed->setRangeMapper(new PlaySpeedRangeMapper);
Chris@1031 269 m_playSpeed->setDefaultValue(60);
Chris@60 270 m_playSpeed->setShowToolTip(true);
Chris@0 271 connect(m_playSpeed, SIGNAL(valueChanged(int)),
Chris@634 272 this, SLOT(playSpeedChanged(int)));
Chris@90 273 connect(m_playSpeed, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
Chris@90 274 connect(m_playSpeed, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
Chris@90 275
Chris@168 276 IconLoader il;
Chris@168 277
Chris@239 278 m_playControlsSpacer = new QFrame;
Chris@239 279
Chris@129 280 layout->setSpacing(4);
Chris@489 281 layout->addWidget(m_mainScroll, 0, 0, 1, 5);
Chris@239 282 layout->addWidget(m_overview, 1, 1);
Chris@239 283 layout->addWidget(m_playControlsSpacer, 1, 2);
Chris@239 284 layout->addWidget(m_playSpeed, 1, 3);
Chris@239 285 layout->addWidget(m_fader, 1, 4);
Chris@239 286
Chris@634 287 m_playControlsWidth =
Chris@240 288 m_fader->width() + m_playSpeed->width() + layout->spacing() * 2;
Chris@239 289
Chris@239 290 layout->setColumnMinimumWidth(0, 14);
Chris@239 291 layout->setColumnStretch(0, 0);
Chris@239 292
Chris@239 293 m_paneStack->setPropertyStackMinWidth(m_playControlsWidth
Chris@239 294 + 2 + layout->spacing());
Chris@239 295 m_playControlsSpacer->setFixedSize(QSize(2, 2));
Chris@239 296
Chris@239 297 layout->setColumnStretch(1, 10);
Chris@239 298
Chris@239 299 connect(m_paneStack, SIGNAL(propertyStacksResized(int)),
Chris@239 300 this, SLOT(propertyStacksResized(int)));
Chris@16 301
Chris@0 302 frame->setLayout(layout);
Chris@0 303
Chris@0 304 setupMenus();
Chris@0 305 setupToolbars();
Chris@155 306 setupHelpMenu();
Chris@0 307
Chris@90 308 statusBar();
Chris@340 309 m_currentLabel = new QLabel;
Chris@340 310 statusBar()->addPermanentWidget(m_currentLabel);
Chris@0 311
Chris@728 312 finaliseMenus();
Chris@728 313
Chris@302 314 connect(m_viewManager, SIGNAL(activity(QString)),
Chris@302 315 m_activityLog, SLOT(activityHappened(QString)));
Chris@302 316 connect(m_playSource, SIGNAL(activity(QString)),
Chris@302 317 m_activityLog, SLOT(activityHappened(QString)));
Chris@302 318 connect(CommandHistory::getInstance(), SIGNAL(activity(QString)),
Chris@302 319 m_activityLog, SLOT(activityHappened(QString)));
Chris@310 320 connect(this, SIGNAL(activity(QString)),
Chris@310 321 m_activityLog, SLOT(activityHappened(QString)));
Chris@303 322 connect(this, SIGNAL(replacedDocument()), this, SLOT(documentReplaced()));
Chris@1087 323
Chris@306 324 m_activityLog->hide();
Chris@303 325
Chris@891 326 m_unitConverter->hide();
Chris@1056 327
Chris@1056 328 setAudioRecordMode(RecordCreateAdditionalModel);
Chris@891 329
Chris@303 330 newSession();
Chris@303 331
Chris@304 332 connect(m_midiInput, SIGNAL(eventsAvailable()),
Chris@304 333 this, SLOT(midiEventsAvailable()));
Chris@663 334
Chris@665 335 NetworkPermissionTester tester;
Chris@663 336 bool networkPermission = tester.havePermission();
Chris@663 337 if (networkPermission) {
Chris@686 338 if (withOSCSupport) {
Chris@686 339 startOSCQueue();
Chris@686 340 }
Chris@663 341 TransformFactory::getInstance()->startPopulationThread();
Chris@677 342 m_surveyer = 0;
Chris@677 343 m_versionTester = 0;
Chris@677 344 /*
Chris@663 345 m_surveyer = new Surveyer
Chris@663 346 ("sonicvisualiser.org", "survey23-present.txt", "survey23.php");
Chris@663 347 m_versionTester = new VersionTester
Chris@663 348 ("sonicvisualiser.org", "latest-version.txt", SV_VERSION);
Chris@663 349 connect(m_versionTester, SIGNAL(newerVersionAvailable(QString)),
Chris@663 350 this, SLOT(newerVersionAvailable(QString)));
Chris@677 351 */
Chris@663 352 } else {
Chris@663 353 m_surveyer = 0;
Chris@663 354 m_versionTester = 0;
Chris@663 355 }
Chris@1087 356
Chris@1145 357 QString warning = PluginScan::getInstance()->getStartupFailureReport();
Chris@1148 358 if (warning != "") {
Chris@1148 359 QTimer::singleShot(500, this, SLOT(pluginPopulationWarning()));
Chris@1148 360 }
Chris@0 361 }
Chris@0 362
Chris@0 363 MainWindow::~MainWindow()
Chris@0 364 {
Chris@438 365 // SVDEBUG << "MainWindow::~MainWindow" << endl;
Chris@162 366 delete m_keyReference;
Chris@504 367 delete m_activityLog;
Chris@891 368 delete m_unitConverter;
Chris@163 369 delete m_preferencesDialog;
Chris@219 370 delete m_layerTreeDialog;
Chris@573 371 delete m_versionTester;
Chris@662 372 delete m_surveyer;
Chris@0 373 Profiles::getInstance()->dump();
Chris@438 374 // SVDEBUG << "MainWindow::~MainWindow finishing" << endl;
Chris@0 375 }
Chris@0 376
Chris@81 377 void
Chris@0 378 MainWindow::setupMenus()
Chris@0 379 {
Chris@0 380 if (!m_mainMenusCreated) {
Chris@779 381
Chris@779 382 #ifdef Q_OS_LINUX
Chris@779 383 // In Ubuntu 14.04 the window's menu bar goes missing entirely
Chris@779 384 // if the user is running any desktop environment other than Unity
Chris@779 385 // (in which the faux single-menubar appears). The user has a
Chris@779 386 // workaround, to remove the appmenu-qt5 package, but that is
Chris@779 387 // awkward and the problem is so severe that it merits disabling
Chris@779 388 // the system menubar integration altogether. Like this:
Chris@779 389 menuBar()->setNativeMenuBar(false); // fix #1039
Chris@779 390 #endif
Chris@779 391
Chris@0 392 m_rightButtonMenu = new QMenu();
Chris@104 393
Chris@104 394 // No -- we don't want tear-off enabled on the right-button
Chris@104 395 // menu. If it is enabled, then simply right-clicking and
Chris@104 396 // releasing will pop up the menu, activate the tear-off, and
Chris@104 397 // leave the torn-off menu window in front of the main window.
Chris@104 398 // That isn't desirable. I'm not sure it ever would be, in a
Chris@104 399 // context menu -- perhaps technically a Qt bug?
Chris@104 400 // m_rightButtonMenu->setTearOffEnabled(true);
Chris@0 401 }
Chris@0 402
Chris@211 403 if (m_rightButtonTransformsMenu) {
Chris@211 404 m_rightButtonTransformsMenu->clear();
Chris@34 405 } else {
Chris@211 406 m_rightButtonTransformsMenu = m_rightButtonMenu->addMenu(tr("&Transform"));
Chris@211 407 m_rightButtonTransformsMenu->setTearOffEnabled(true);
Chris@34 408 m_rightButtonMenu->addSeparator();
Chris@34 409 }
Chris@34 410
Chris@346 411 // This will be created (if not found) or cleared (if found) in
Chris@346 412 // setupPaneAndLayerMenus, but we want to ensure it's created
Chris@346 413 // sooner so it can go nearer the top of the right button menu
Chris@346 414 if (m_rightButtonLayerMenu) {
Chris@346 415 m_rightButtonLayerMenu->clear();
Chris@346 416 } else {
Chris@346 417 m_rightButtonLayerMenu = m_rightButtonMenu->addMenu(tr("&Layer"));
Chris@346 418 m_rightButtonLayerMenu->setTearOffEnabled(true);
Chris@346 419 m_rightButtonMenu->addSeparator();
Chris@346 420 }
Chris@346 421
Chris@0 422 if (!m_mainMenusCreated) {
Chris@0 423 CommandHistory::getInstance()->registerMenu(m_rightButtonMenu);
Chris@0 424 m_rightButtonMenu->addSeparator();
Chris@66 425 }
Chris@66 426
Chris@66 427 setupFileMenu();
Chris@66 428 setupEditMenu();
Chris@66 429 setupViewMenu();
Chris@66 430 setupPaneAndLayerMenus();
Chris@211 431 setupTransformsMenu();
Chris@66 432
Chris@66 433 m_mainMenusCreated = true;
Chris@66 434 }
Chris@66 435
Chris@66 436 void
Chris@489 437 MainWindow::goFullScreen()
Chris@489 438 {
Chris@588 439 if (m_viewManager->getZoomWheelsEnabled()) {
Chris@588 440 // The wheels seem to end up in the wrong place in full-screen mode
Chris@588 441 toggleZoomWheels();
Chris@588 442 }
Chris@588 443
Chris@492 444 QWidget *ps = m_mainScroll->takeWidget();
Chris@492 445 ps->setParent(0);
Chris@494 446
Chris@494 447 QShortcut *sc;
Chris@494 448
Chris@494 449 sc = new QShortcut(QKeySequence("Esc"), ps);
Chris@494 450 connect(sc, SIGNAL(activated()), this, SLOT(endFullScreen()));
Chris@494 451
Chris@494 452 sc = new QShortcut(QKeySequence("F11"), ps);
Chris@494 453 connect(sc, SIGNAL(activated()), this, SLOT(endFullScreen()));
Chris@494 454
Chris@494 455 QAction *acts[] = {
Chris@494 456 m_playAction, m_zoomInAction, m_zoomOutAction, m_zoomFitAction,
Chris@494 457 m_scrollLeftAction, m_scrollRightAction, m_showPropertyBoxesAction
Chris@494 458 };
Chris@494 459
Chris@705 460 for (int i = 0; i < int(sizeof(acts)/sizeof(acts[0])); ++i) {
Chris@494 461 sc = new QShortcut(acts[i]->shortcut(), ps);
Chris@494 462 connect(sc, SIGNAL(activated()), acts[i], SLOT(trigger()));
Chris@494 463 }
Chris@494 464
Chris@492 465 ps->showFullScreen();
Chris@492 466 }
Chris@492 467
Chris@492 468 void
Chris@492 469 MainWindow::endFullScreen()
Chris@492 470 {
Chris@494 471 // these were only created in goFullScreen:
Chris@494 472 QObjectList cl = m_paneStack->children();
Chris@494 473 foreach (QObject *o, cl) {
Chris@494 474 QShortcut *sc = qobject_cast<QShortcut *>(o);
Chris@494 475 if (sc) delete sc;
Chris@494 476 }
Chris@494 477
Chris@588 478 m_paneStack->showNormal();
Chris@492 479 m_mainScroll->setWidget(m_paneStack);
Chris@489 480 }
Chris@489 481
Chris@489 482 void
Chris@66 483 MainWindow::setupFileMenu()
Chris@66 484 {
Chris@66 485 if (m_mainMenusCreated) return;
Chris@66 486
Chris@66 487 QMenu *menu = menuBar()->addMenu(tr("&File"));
Chris@97 488 menu->setTearOffEnabled(true);
Chris@66 489 QToolBar *toolbar = addToolBar(tr("File Toolbar"));
Chris@66 490
Chris@162 491 m_keyReference->setCategory(tr("File and Session Management"));
Chris@162 492
Chris@168 493 IconLoader il;
Chris@168 494
Chris@168 495 QIcon icon = il.load("filenew");
Chris@66 496 QAction *action = new QAction(icon, tr("&New Session"), this);
Chris@66 497 action->setShortcut(tr("Ctrl+N"));
Chris@518 498 action->setStatusTip(tr("Abandon the current %1 session and start a new one").arg(QApplication::applicationName()));
Chris@66 499 connect(action, SIGNAL(triggered()), this, SLOT(newSession()));
Chris@162 500 m_keyReference->registerShortcut(action);
Chris@66 501 menu->addAction(action);
Chris@66 502 toolbar->addAction(action);
Chris@518 503
Chris@168 504 icon = il.load("fileopen");
Chris@66 505 action = new QAction(icon, tr("&Open..."), this);
Chris@418 506 action->setShortcut(tr("Ctrl+O"));
Chris@66 507 action->setStatusTip(tr("Open a session file, audio file, or layer"));
Chris@66 508 connect(action, SIGNAL(triggered()), this, SLOT(openSomething()));
Chris@705 509 m_keyReference->registerShortcut(action);
Chris@66 510 toolbar->addAction(action);
Chris@418 511 menu->addAction(action);
Chris@418 512
Chris@418 513 // We want this one to go on the toolbar now, if we add it at all,
Chris@418 514 // but on the menu later
Chris@418 515 QAction *iaction = new QAction(tr("&Import More Audio..."), this);
Chris@418 516 iaction->setShortcut(tr("Ctrl+I"));
Chris@418 517 iaction->setStatusTip(tr("Import an extra audio file into a new pane"));
Chris@418 518 connect(iaction, SIGNAL(triggered()), this, SLOT(importMoreAudio()));
Chris@418 519 connect(this, SIGNAL(canImportMoreAudio(bool)), iaction, SLOT(setEnabled(bool)));
Chris@418 520 m_keyReference->registerShortcut(iaction);
Chris@418 521
Chris@508 522 // We want this one to go on the toolbar now, if we add it at all,
Chris@508 523 // but on the menu later
Chris@508 524 QAction *raction = new QAction(tr("Replace &Main Audio..."), this);
Chris@508 525 raction->setStatusTip(tr("Replace the main audio file of the session with a different file"));
Chris@508 526 connect(raction, SIGNAL(triggered()), this, SLOT(replaceMainAudio()));
Chris@508 527 connect(this, SIGNAL(canReplaceMainAudio(bool)), raction, SLOT(setEnabled(bool)));
Chris@508 528
Chris@418 529 action = new QAction(tr("Open Lo&cation..."), this);
Chris@418 530 action->setShortcut(tr("Ctrl+Shift+O"));
Chris@418 531 action->setStatusTip(tr("Open or import a file from a remote URL"));
Chris@418 532 connect(action, SIGNAL(triggered()), this, SLOT(openLocation()));
Chris@418 533 m_keyReference->registerShortcut(action);
Chris@418 534 menu->addAction(action);
Chris@418 535
Chris@420 536 m_recentFilesMenu = menu->addMenu(tr("Open &Recent"));
Chris@418 537 m_recentFilesMenu->setTearOffEnabled(true);
Chris@418 538 setupRecentFilesMenu();
Chris@418 539 connect(&m_recentFiles, SIGNAL(recentChanged()),
Chris@418 540 this, SLOT(setupRecentFilesMenu()));
Chris@418 541
Chris@418 542 menu->addSeparator();
Chris@415 543
Chris@168 544 icon = il.load("filesave");
Chris@66 545 action = new QAction(icon, tr("&Save Session"), this);
Chris@66 546 action->setShortcut(tr("Ctrl+S"));
Chris@518 547 action->setStatusTip(tr("Save the current session into a %1 session file").arg(QApplication::applicationName()));
Chris@66 548 connect(action, SIGNAL(triggered()), this, SLOT(saveSession()));
Chris@66 549 connect(this, SIGNAL(canSave(bool)), action, SLOT(setEnabled(bool)));
Chris@162 550 m_keyReference->registerShortcut(action);
Chris@66 551 menu->addAction(action);
Chris@66 552 toolbar->addAction(action);
Chris@634 553
Chris@168 554 icon = il.load("filesaveas");
Chris@66 555 action = new QAction(icon, tr("Save Session &As..."), this);
Chris@336 556 action->setShortcut(tr("Ctrl+Shift+S"));
Chris@518 557 action->setStatusTip(tr("Save the current session into a new %1 session file").arg(QApplication::applicationName()));
Chris@66 558 connect(action, SIGNAL(triggered()), this, SLOT(saveSessionAs()));
Chris@66 559 menu->addAction(action);
Chris@66 560 toolbar->addAction(action);
Chris@66 561
Chris@66 562 menu->addSeparator();
Chris@66 563
Chris@418 564 /*
Chris@168 565 icon = il.load("fileopenaudio");
Chris@138 566 action = new QAction(icon, tr("&Import Audio File..."), this);
Chris@66 567 action->setShortcut(tr("Ctrl+I"));
Chris@66 568 action->setStatusTip(tr("Import an existing audio file"));
Chris@66 569 connect(action, SIGNAL(triggered()), this, SLOT(importAudio()));
Chris@162 570 m_keyReference->registerShortcut(action);
Chris@66 571 menu->addAction(action);
Chris@418 572 */
Chris@418 573
Chris@508 574 // the Replace action we made earlier
Chris@508 575 menu->addAction(raction);
Chris@508 576
Chris@418 577 // the Import action we made earlier
Chris@418 578 menu->addAction(iaction);
Chris@66 579
Chris@66 580 action = new QAction(tr("&Export Audio File..."), this);
Chris@66 581 action->setStatusTip(tr("Export selection as an audio file"));
Chris@66 582 connect(action, SIGNAL(triggered()), this, SLOT(exportAudio()));
Chris@66 583 connect(this, SIGNAL(canExportAudio(bool)), action, SLOT(setEnabled(bool)));
Chris@66 584 menu->addAction(action);
Chris@66 585
Chris@674 586 action = new QAction(tr("Export Audio Data..."), this);
Chris@631 587 action->setStatusTip(tr("Export audio from selection into a data file"));
Chris@631 588 connect(action, SIGNAL(triggered()), this, SLOT(exportAudioData()));
Chris@631 589 connect(this, SIGNAL(canExportAudio(bool)), action, SLOT(setEnabled(bool)));
Chris@631 590 menu->addAction(action);
Chris@631 591
Chris@677 592 QAction *actionCreateIMAF = new QAction(tr("Export IMAF File..."), this);
Chris@634 593 actionCreateIMAF->setStatusTip(tr("Export selection as an IMAF file"));
Chris@634 594 menu->addAction(actionCreateIMAF);
Chris@634 595 connect(actionCreateIMAF,SIGNAL(triggered()),this,SLOT(exportIMAF()));
Chris@634 596
Chris@677 597 QAction *actionOpenIMAF = new QAction(tr("Import IMAF File..."), this);
Chris@634 598 actionOpenIMAF->setStatusTip(tr("Import IMAF file"));
Chris@634 599 menu->addAction(actionOpenIMAF);
Chris@634 600 connect(actionOpenIMAF,SIGNAL(triggered()),this,SLOT(importIMAF()));
Chris@634 601
Chris@66 602 menu->addSeparator();
Chris@66 603
Chris@66 604 action = new QAction(tr("Import Annotation &Layer..."), this);
Chris@66 605 action->setShortcut(tr("Ctrl+L"));
Chris@66 606 action->setStatusTip(tr("Import layer data from an existing file"));
Chris@66 607 connect(action, SIGNAL(triggered()), this, SLOT(importLayer()));
Chris@66 608 connect(this, SIGNAL(canImportLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@162 609 m_keyReference->registerShortcut(action);
Chris@66 610 menu->addAction(action);
Chris@66 611
Chris@977 612 action = new QAction(tr("Export Annotation La&yer..."), this);
Chris@977 613 action->setShortcut(tr("Ctrl+Y"));
Chris@66 614 action->setStatusTip(tr("Export layer data to a file"));
Chris@66 615 connect(action, SIGNAL(triggered()), this, SLOT(exportLayer()));
Chris@66 616 connect(this, SIGNAL(canExportLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@977 617 m_keyReference->registerShortcut(action);
Chris@66 618 menu->addAction(action);
Chris@66 619
Chris@66 620 menu->addSeparator();
Chris@86 621
Chris@121 622 action = new QAction(tr("Export Image File..."), this);
Chris@121 623 action->setStatusTip(tr("Export a single pane to an image file"));
Chris@121 624 connect(action, SIGNAL(triggered()), this, SLOT(exportImage()));
Chris@121 625 connect(this, SIGNAL(canExportImage(bool)), action, SLOT(setEnabled(bool)));
Chris@121 626 menu->addAction(action);
Chris@121 627
Chris@121 628 menu->addSeparator();
Chris@121 629
Chris@1056 630 action = new QAction(tr("Browse Recorded Audio Folder"), this);
Chris@1056 631 action->setStatusTip(tr("Open the Recorded Audio folder in the system file browser"));
Chris@1056 632 connect(action, SIGNAL(triggered()), this, SLOT(browseRecordedAudio()));
Chris@1056 633 menu->addAction(action);
Chris@1056 634
Chris@1056 635 menu->addSeparator();
Chris@1056 636
Chris@435 637 QString templatesMenuLabel = tr("Apply Session Template");
Chris@425 638 m_templatesMenu = menu->addMenu(templatesMenuLabel);
Chris@425 639 m_templatesMenu->setTearOffEnabled(true);
Chris@436 640 // We need to have a main model for this option to be useful:
Chris@436 641 // canExportAudio captures that
Chris@436 642 connect(this, SIGNAL(canExportAudio(bool)), m_templatesMenu, SLOT(setEnabled(bool)));
Chris@436 643
Chris@436 644 // Set up the menu in a moment, after m_manageTemplatesAction constructed
Chris@435 645
Chris@435 646 action = new QAction(tr("Export Session as Template..."), this);
Chris@435 647 connect(action, SIGNAL(triggered()), this, SLOT(saveSessionAsTemplate()));
Chris@436 648 // We need to have something in the session for this to be useful:
Chris@436 649 // canDeleteCurrentLayer captures that
Chris@436 650 connect(this, SIGNAL(canExportAudio(bool)), action, SLOT(setEnabled(bool)));
Chris@435 651 menu->addAction(action);
Chris@435 652
Chris@436 653 m_manageTemplatesAction = new QAction(tr("Manage Exported Templates"), this);
Chris@436 654 connect(m_manageTemplatesAction, SIGNAL(triggered()), this, SLOT(manageSavedTemplates()));
Chris@436 655 menu->addAction(m_manageTemplatesAction);
Chris@436 656
Chris@436 657 setupTemplatesMenu();
Chris@425 658
Chris@66 659 action = new QAction(tr("&Preferences..."), this);
Chris@66 660 action->setStatusTip(tr("Adjust the application preferences"));
Chris@66 661 connect(action, SIGNAL(triggered()), this, SLOT(preferences()));
Chris@66 662 menu->addAction(action);
Chris@634 663
Chris@66 664 menu->addSeparator();
Chris@168 665 action = new QAction(il.load("exit"),
Chris@66 666 tr("&Quit"), this);
Chris@66 667 action->setShortcut(tr("Ctrl+Q"));
Chris@518 668 action->setStatusTip(tr("Exit %1").arg(QApplication::applicationName()));
Chris@500 669 connect(action, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
Chris@162 670 m_keyReference->registerShortcut(action);
Chris@66 671 menu->addAction(action);
Chris@66 672 }
Chris@66 673
Chris@66 674 void
Chris@66 675 MainWindow::setupEditMenu()
Chris@66 676 {
Chris@66 677 if (m_mainMenusCreated) return;
Chris@66 678
Chris@66 679 QMenu *menu = menuBar()->addMenu(tr("&Edit"));
Chris@97 680 menu->setTearOffEnabled(true);
Chris@66 681 CommandHistory::getInstance()->registerMenu(menu);
Chris@66 682
Chris@162 683 m_keyReference->setCategory(tr("Editing"));
Chris@162 684
Chris@66 685 menu->addSeparator();
Chris@66 686
Chris@168 687 IconLoader il;
Chris@168 688
Chris@168 689 QAction *action = new QAction(il.load("editcut"),
Chris@66 690 tr("Cu&t"), this);
Chris@66 691 action->setShortcut(tr("Ctrl+X"));
Chris@90 692 action->setStatusTip(tr("Cut the selection from the current layer to the clipboard"));
Chris@66 693 connect(action, SIGNAL(triggered()), this, SLOT(cut()));
Chris@66 694 connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@162 695 m_keyReference->registerShortcut(action);
Chris@66 696 menu->addAction(action);
Chris@66 697 m_rightButtonMenu->addAction(action);
Chris@66 698
Chris@168 699 action = new QAction(il.load("editcopy"),
Chris@66 700 tr("&Copy"), this);
Chris@66 701 action->setShortcut(tr("Ctrl+C"));
Chris@90 702 action->setStatusTip(tr("Copy the selection from the current layer to the clipboard"));
Chris@66 703 connect(action, SIGNAL(triggered()), this, SLOT(copy()));
Chris@66 704 connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@162 705 m_keyReference->registerShortcut(action);
Chris@66 706 menu->addAction(action);
Chris@66 707 m_rightButtonMenu->addAction(action);
Chris@66 708
Chris@168 709 action = new QAction(il.load("editpaste"),
Chris@66 710 tr("&Paste"), this);
Chris@66 711 action->setShortcut(tr("Ctrl+V"));
Chris@90 712 action->setStatusTip(tr("Paste from the clipboard to the current layer"));
Chris@66 713 connect(action, SIGNAL(triggered()), this, SLOT(paste()));
Chris@66 714 connect(this, SIGNAL(canPaste(bool)), action, SLOT(setEnabled(bool)));
Chris@162 715 m_keyReference->registerShortcut(action);
Chris@66 716 menu->addAction(action);
Chris@66 717 m_rightButtonMenu->addAction(action);
Chris@66 718
Chris@395 719 action = new QAction(tr("Paste at Playback Position"), this);
Chris@395 720 action->setShortcut(tr("Ctrl+Shift+V"));
Chris@395 721 action->setStatusTip(tr("Paste from the clipboard to the current layer, placing the first item at the playback position"));
Chris@395 722 connect(action, SIGNAL(triggered()), this, SLOT(pasteAtPlaybackPosition()));
Chris@395 723 connect(this, SIGNAL(canPaste(bool)), action, SLOT(setEnabled(bool)));
Chris@395 724 m_keyReference->registerShortcut(action);
Chris@395 725 menu->addAction(action);
Chris@395 726 m_rightButtonMenu->addAction(action);
Chris@395 727
Chris@164 728 m_deleteSelectedAction = new QAction(tr("&Delete Selected Items"), this);
Chris@164 729 m_deleteSelectedAction->setShortcut(tr("Del"));
Chris@164 730 m_deleteSelectedAction->setStatusTip(tr("Delete items in current selection from the current layer"));
Chris@164 731 connect(m_deleteSelectedAction, SIGNAL(triggered()), this, SLOT(deleteSelected()));
Chris@164 732 connect(this, SIGNAL(canDeleteSelection(bool)), m_deleteSelectedAction, SLOT(setEnabled(bool)));
Chris@164 733 m_keyReference->registerShortcut(m_deleteSelectedAction);
Chris@164 734 menu->addAction(m_deleteSelectedAction);
Chris@164 735 m_rightButtonMenu->addAction(m_deleteSelectedAction);
Chris@66 736
Chris@66 737 menu->addSeparator();
Chris@66 738 m_rightButtonMenu->addSeparator();
Chris@162 739
Chris@162 740 m_keyReference->setCategory(tr("Selection"));
Chris@162 741
Chris@66 742 action = new QAction(tr("Select &All"), this);
Chris@66 743 action->setShortcut(tr("Ctrl+A"));
Chris@90 744 action->setStatusTip(tr("Select the whole duration of the current session"));
Chris@66 745 connect(action, SIGNAL(triggered()), this, SLOT(selectAll()));
Chris@66 746 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
Chris@162 747 m_keyReference->registerShortcut(action);
Chris@66 748 menu->addAction(action);
Chris@66 749 m_rightButtonMenu->addAction(action);
Chris@634 750
Chris@66 751 action = new QAction(tr("Select &Visible Range"), this);
Chris@66 752 action->setShortcut(tr("Ctrl+Shift+A"));
Chris@90 753 action->setStatusTip(tr("Select the time range corresponding to the current window width"));
Chris@66 754 connect(action, SIGNAL(triggered()), this, SLOT(selectVisible()));
Chris@66 755 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
Chris@162 756 m_keyReference->registerShortcut(action);
Chris@66 757 menu->addAction(action);
Chris@634 758
Chris@66 759 action = new QAction(tr("Select to &Start"), this);
Chris@66 760 action->setShortcut(tr("Shift+Left"));
Chris@90 761 action->setStatusTip(tr("Select from the start of the session to the current playback position"));
Chris@66 762 connect(action, SIGNAL(triggered()), this, SLOT(selectToStart()));
Chris@66 763 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
Chris@162 764 m_keyReference->registerShortcut(action);
Chris@66 765 menu->addAction(action);
Chris@634 766
Chris@66 767 action = new QAction(tr("Select to &End"), this);
Chris@66 768 action->setShortcut(tr("Shift+Right"));
Chris@90 769 action->setStatusTip(tr("Select from the current playback position to the end of the session"));
Chris@66 770 connect(action, SIGNAL(triggered()), this, SLOT(selectToEnd()));
Chris@66 771 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
Chris@162 772 m_keyReference->registerShortcut(action);
Chris@66 773 menu->addAction(action);
Chris@66 774
Chris@66 775 action = new QAction(tr("C&lear Selection"), this);
Chris@66 776 action->setShortcut(tr("Esc"));
Chris@90 777 action->setStatusTip(tr("Clear the selection"));
Chris@66 778 connect(action, SIGNAL(triggered()), this, SLOT(clearSelection()));
Chris@66 779 connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@162 780 m_keyReference->registerShortcut(action);
Chris@66 781 menu->addAction(action);
Chris@66 782 m_rightButtonMenu->addAction(action);
Chris@66 783
Chris@66 784 menu->addSeparator();
Chris@66 785
Chris@162 786 m_keyReference->setCategory(tr("Tapping Time Instants"));
Chris@162 787
Chris@66 788 action = new QAction(tr("&Insert Instant at Playback Position"), this);
Chris@66 789 action->setShortcut(tr("Enter"));
Chris@90 790 action->setStatusTip(tr("Insert a new time instant at the current playback position, in a new layer if necessary"));
Chris@66 791 connect(action, SIGNAL(triggered()), this, SLOT(insertInstant()));
Chris@66 792 connect(this, SIGNAL(canInsertInstant(bool)), action, SLOT(setEnabled(bool)));
Chris@162 793 m_keyReference->registerShortcut(action);
Chris@66 794 menu->addAction(action);
Chris@66 795
Chris@162 796 // Laptop shortcut (no keypad Enter key)
Chris@162 797 QString shortcut(tr(";"));
Chris@162 798 connect(new QShortcut(shortcut, this), SIGNAL(activated()),
Chris@162 799 this, SLOT(insertInstant()));
Chris@162 800 m_keyReference->registerAlternativeShortcut(action, shortcut);
Chris@162 801
Chris@81 802 action = new QAction(tr("Insert Instants at Selection &Boundaries"), this);
Chris@81 803 action->setShortcut(tr("Shift+Enter"));
Chris@163 804 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 805 connect(action, SIGNAL(triggered()), this, SLOT(insertInstantsAtBoundaries()));
Chris@81 806 connect(this, SIGNAL(canInsertInstantsAtBoundaries(bool)), action, SLOT(setEnabled(bool)));
Chris@162 807 m_keyReference->registerShortcut(action);
Chris@81 808 menu->addAction(action);
Chris@189 809
Chris@338 810 action = new QAction(tr("Insert Item at Selection"), this);
Chris@798 811 action->setShortcut(tr("Ctrl+Shift+Return"));
Chris@338 812 action->setStatusTip(tr("Insert a new note or region item corresponding to the current selection"));
Chris@338 813 connect(action, SIGNAL(triggered()), this, SLOT(insertItemAtSelection()));
Chris@338 814 connect(this, SIGNAL(canInsertItemAtSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@338 815 m_keyReference->registerShortcut(action);
Chris@338 816 menu->addAction(action);
Chris@338 817
Chris@338 818 menu->addSeparator();
Chris@338 819
Chris@190 820 QMenu *numberingMenu = menu->addMenu(tr("Number New Instants with"));
Chris@225 821 numberingMenu->setTearOffEnabled(true);
Chris@189 822 QActionGroup *numberingGroup = new QActionGroup(this);
Chris@189 823
Chris@189 824 Labeller::TypeNameMap types = m_labeller->getTypeNames();
Chris@189 825 for (Labeller::TypeNameMap::iterator i = types.begin(); i != types.end(); ++i) {
Chris@190 826
Chris@190 827 if (i->first == Labeller::ValueFromLabel ||
Chris@190 828 i->first == Labeller::ValueFromExistingNeighbour) continue;
Chris@190 829
Chris@189 830 action = new QAction(i->second, this);
Chris@189 831 connect(action, SIGNAL(triggered()), this, SLOT(setInstantsNumbering()));
Chris@189 832 action->setCheckable(true);
Chris@189 833 action->setChecked(m_labeller->getType() == i->first);
Chris@189 834 numberingGroup->addAction(action);
Chris@189 835 numberingMenu->addAction(action);
Chris@189 836 m_numberingActions[action] = (int)i->first;
Chris@190 837
Chris@190 838 if (i->first == Labeller::ValueFromTwoLevelCounter) {
Chris@192 839
Chris@190 840 QMenu *cycleMenu = numberingMenu->addMenu(tr("Cycle size"));
Chris@190 841 QActionGroup *cycleGroup = new QActionGroup(this);
Chris@190 842
Chris@229 843 int cycles[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 16 };
Chris@200 844 for (int i = 0; i < int(sizeof(cycles)/sizeof(cycles[0])); ++i) {
Chris@190 845 action = new QAction(QString("%1").arg(cycles[i]), this);
Chris@190 846 connect(action, SIGNAL(triggered()), this, SLOT(setInstantsCounterCycle()));
Chris@190 847 action->setCheckable(true);
Chris@190 848 action->setChecked(cycles[i] == m_labeller->getCounterCycleSize());
Chris@190 849 cycleGroup->addAction(action);
Chris@190 850 cycleMenu->addAction(action);
Chris@190 851 }
Chris@190 852 }
Chris@190 853
Chris@190 854 if (i->first == Labeller::ValueNone ||
Chris@190 855 i->first == Labeller::ValueFromTwoLevelCounter ||
Chris@190 856 i->first == Labeller::ValueFromRealTime) {
Chris@190 857 numberingMenu->addSeparator();
Chris@190 858 }
Chris@189 859 }
Chris@189 860
Chris@597 861 action = new QAction(tr("Reset Numbering Counters"), this);
Chris@597 862 action->setStatusTip(tr("Reset to 1 all the counters used for counter-based labelling"));
Chris@597 863 connect(action, SIGNAL(triggered()), this, SLOT(resetInstantsCounters()));
Chris@597 864 connect(this, SIGNAL(replacedDocument()), action, SLOT(trigger()));
Chris@597 865 menu->addAction(action);
Chris@597 866
Chris@241 867 action = new QAction(tr("Set Numbering Counters..."), this);
Chris@241 868 action->setStatusTip(tr("Set the counters used for counter-based labelling"));
Chris@597 869 connect(action, SIGNAL(triggered()), this, SLOT(setInstantsCounters()));
Chris@241 870 menu->addAction(action);
Chris@634 871
Chris@241 872 action = new QAction(tr("Renumber Selected Instants"), this);
Chris@241 873 action->setStatusTip(tr("Renumber the selected instants using the current labelling scheme"));
Chris@189 874 connect(action, SIGNAL(triggered()), this, SLOT(renumberInstants()));
Chris@189 875 connect(this, SIGNAL(canRenumberInstants(bool)), action, SLOT(setEnabled(bool)));
Chris@189 876 // m_keyReference->registerShortcut(action);
Chris@189 877 menu->addAction(action);
Chris@66 878 }
Chris@66 879
Chris@66 880 void
Chris@66 881 MainWindow::setupViewMenu()
Chris@66 882 {
Chris@66 883 if (m_mainMenusCreated) return;
Chris@66 884
Chris@168 885 IconLoader il;
Chris@168 886
Chris@90 887 QAction *action = 0;
Chris@90 888
Chris@162 889 m_keyReference->setCategory(tr("Panning and Navigation"));
Chris@162 890
Chris@66 891 QMenu *menu = menuBar()->addMenu(tr("&View"));
Chris@97 892 menu->setTearOffEnabled(true);
Chris@494 893 m_scrollLeftAction = new QAction(tr("Scroll &Left"), this);
Chris@494 894 m_scrollLeftAction->setShortcut(tr("Left"));
Chris@494 895 m_scrollLeftAction->setStatusTip(tr("Scroll the current pane to the left"));
Chris@494 896 connect(m_scrollLeftAction, SIGNAL(triggered()), this, SLOT(scrollLeft()));
Chris@494 897 connect(this, SIGNAL(canScroll(bool)), m_scrollLeftAction, SLOT(setEnabled(bool)));
Chris@494 898 m_keyReference->registerShortcut(m_scrollLeftAction);
Chris@494 899 menu->addAction(m_scrollLeftAction);
Chris@634 900
Chris@494 901 m_scrollRightAction = new QAction(tr("Scroll &Right"), this);
Chris@494 902 m_scrollRightAction->setShortcut(tr("Right"));
Chris@494 903 m_scrollRightAction->setStatusTip(tr("Scroll the current pane to the right"));
Chris@494 904 connect(m_scrollRightAction, SIGNAL(triggered()), this, SLOT(scrollRight()));
Chris@494 905 connect(this, SIGNAL(canScroll(bool)), m_scrollRightAction, SLOT(setEnabled(bool)));
Chris@494 906 m_keyReference->registerShortcut(m_scrollRightAction);
Chris@494 907 menu->addAction(m_scrollRightAction);
Chris@634 908
Chris@90 909 action = new QAction(tr("&Jump Left"), this);
Chris@66 910 action->setShortcut(tr("Ctrl+Left"));
Chris@66 911 action->setStatusTip(tr("Scroll the current pane a big step to the left"));
Chris@66 912 connect(action, SIGNAL(triggered()), this, SLOT(jumpLeft()));
Chris@66 913 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@162 914 m_keyReference->registerShortcut(action);
Chris@66 915 menu->addAction(action);
Chris@634 916
Chris@90 917 action = new QAction(tr("J&ump Right"), this);
Chris@66 918 action->setShortcut(tr("Ctrl+Right"));
Chris@66 919 action->setStatusTip(tr("Scroll the current pane a big step to the right"));
Chris@66 920 connect(action, SIGNAL(triggered()), this, SLOT(jumpRight()));
Chris@66 921 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@162 922 m_keyReference->registerShortcut(action);
Chris@66 923 menu->addAction(action);
Chris@66 924
Chris@308 925 action = new QAction(tr("Peek Left"), this);
Chris@308 926 action->setShortcut(tr("Alt+Left"));
Chris@308 927 action->setStatusTip(tr("Scroll the current pane to the left without moving the playback cursor or other panes"));
Chris@308 928 connect(action, SIGNAL(triggered()), this, SLOT(peekLeft()));
Chris@308 929 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@308 930 m_keyReference->registerShortcut(action);
Chris@308 931 menu->addAction(action);
Chris@634 932
Chris@308 933 action = new QAction(tr("Peek Right"), this);
Chris@308 934 action->setShortcut(tr("Alt+Right"));
Chris@308 935 action->setStatusTip(tr("Scroll the current pane to the right without moving the playback cursor or other panes"));
Chris@308 936 connect(action, SIGNAL(triggered()), this, SLOT(peekRight()));
Chris@308 937 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@308 938 m_keyReference->registerShortcut(action);
Chris@308 939 menu->addAction(action);
Chris@308 940
Chris@66 941 menu->addSeparator();
Chris@66 942
Chris@162 943 m_keyReference->setCategory(tr("Zoom"));
Chris@162 944
Chris@494 945 m_zoomInAction = new QAction(il.load("zoom-in"),
Chris@494 946 tr("Zoom &In"), this);
Chris@494 947 m_zoomInAction->setShortcut(tr("Up"));
Chris@494 948 m_zoomInAction->setStatusTip(tr("Increase the zoom level"));
Chris@494 949 connect(m_zoomInAction, SIGNAL(triggered()), this, SLOT(zoomIn()));
Chris@494 950 connect(this, SIGNAL(canZoom(bool)), m_zoomInAction, SLOT(setEnabled(bool)));
Chris@494 951 m_keyReference->registerShortcut(m_zoomInAction);
Chris@494 952 menu->addAction(m_zoomInAction);
Chris@634 953
Chris@494 954 m_zoomOutAction = new QAction(il.load("zoom-out"),
Chris@494 955 tr("Zoom &Out"), this);
Chris@494 956 m_zoomOutAction->setShortcut(tr("Down"));
Chris@494 957 m_zoomOutAction->setStatusTip(tr("Decrease the zoom level"));
Chris@494 958 connect(m_zoomOutAction, SIGNAL(triggered()), this, SLOT(zoomOut()));
Chris@494 959 connect(this, SIGNAL(canZoom(bool)), m_zoomOutAction, SLOT(setEnabled(bool)));
Chris@494 960 m_keyReference->registerShortcut(m_zoomOutAction);
Chris@494 961 menu->addAction(m_zoomOutAction);
Chris@634 962
Chris@66 963 action = new QAction(tr("Restore &Default Zoom"), this);
Chris@90 964 action->setStatusTip(tr("Restore the zoom level to the default"));
Chris@66 965 connect(action, SIGNAL(triggered()), this, SLOT(zoomDefault()));
Chris@66 966 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@66 967 menu->addAction(action);
Chris@66 968
Chris@494 969 m_zoomFitAction = new QAction(il.load("zoom-fit"),
Chris@494 970 tr("Zoom to &Fit"), this);
Chris@494 971 m_zoomFitAction->setShortcut(tr("F"));
Chris@494 972 m_zoomFitAction->setStatusTip(tr("Zoom to show the whole file"));
Chris@494 973 connect(m_zoomFitAction, SIGNAL(triggered()), this, SLOT(zoomToFit()));
Chris@494 974 connect(this, SIGNAL(canZoom(bool)), m_zoomFitAction, SLOT(setEnabled(bool)));
Chris@494 975 m_keyReference->registerShortcut(m_zoomFitAction);
Chris@494 976 menu->addAction(m_zoomFitAction);
Chris@90 977
Chris@90 978 menu->addSeparator();
Chris@90 979
Chris@162 980 m_keyReference->setCategory(tr("Display Features"));
Chris@162 981
Chris@497 982 action = new QAction(tr("Show &Centre Line"), this);
Chris@497 983 action->setShortcut(tr("'"));
Chris@497 984 action->setStatusTip(tr("Show or hide the centre line"));
Chris@497 985 connect(action, SIGNAL(triggered()), this, SLOT(toggleCentreLine()));
Chris@497 986 action->setCheckable(true);
Chris@703 987 action->setChecked(m_viewManager->shouldShowCentreLine());
Chris@497 988 m_keyReference->registerShortcut(action);
Chris@497 989 menu->addAction(action);
Chris@497 990
Chris@497 991 action = new QAction(tr("Toggle All Time Rulers"), this);
Chris@497 992 action->setShortcut(tr("#"));
Chris@497 993 action->setStatusTip(tr("Show or hide all time rulers"));
Chris@497 994 connect(action, SIGNAL(triggered()), this, SLOT(toggleTimeRulers()));
Chris@497 995 m_keyReference->registerShortcut(action);
Chris@497 996 menu->addAction(action);
Chris@497 997
Chris@497 998 menu->addSeparator();
Chris@497 999
Chris@90 1000 QActionGroup *overlayGroup = new QActionGroup(this);
Chris@674 1001
Chris@703 1002 ViewManager::OverlayMode mode = m_viewManager->getOverlayMode();
Chris@634 1003
Chris@90 1004 action = new QAction(tr("Show &No Overlays"), this);
Chris@90 1005 action->setShortcut(tr("0"));
Chris@497 1006 action->setStatusTip(tr("Hide times, layer names, and scale"));
Chris@90 1007 connect(action, SIGNAL(triggered()), this, SLOT(showNoOverlays()));
Chris@90 1008 action->setCheckable(true);
Chris@703 1009 action->setChecked(mode == ViewManager::NoOverlays);
Chris@90 1010 overlayGroup->addAction(action);
Chris@162 1011 m_keyReference->registerShortcut(action);
Chris@90 1012 menu->addAction(action);
Chris@634 1013
Chris@90 1014 action = new QAction(tr("Show &Minimal Overlays"), this);
Chris@90 1015 action->setShortcut(tr("9"));
Chris@497 1016 action->setStatusTip(tr("Show times and basic scale"));
Chris@90 1017 connect(action, SIGNAL(triggered()), this, SLOT(showMinimalOverlays()));
Chris@90 1018 action->setCheckable(true);
Chris@715 1019 action->setChecked(mode == ViewManager::StandardOverlays);
Chris@90 1020 overlayGroup->addAction(action);
Chris@162 1021 m_keyReference->registerShortcut(action);
Chris@90 1022 menu->addAction(action);
Chris@634 1023
Chris@90 1024 action = new QAction(tr("Show &All Overlays"), this);
Chris@497 1025 action->setShortcut(tr("8"));
Chris@497 1026 action->setStatusTip(tr("Show times, layer names, and scale"));
Chris@90 1027 connect(action, SIGNAL(triggered()), this, SLOT(showAllOverlays()));
Chris@90 1028 action->setCheckable(true);
Chris@703 1029 action->setChecked(mode == ViewManager::AllOverlays);
Chris@90 1030 overlayGroup->addAction(action);
Chris@162 1031 m_keyReference->registerShortcut(action);
Chris@90 1032 menu->addAction(action);
Chris@387 1033
Chris@387 1034 menu->addSeparator();
Chris@634 1035
Chris@66 1036 action = new QAction(tr("Show &Zoom Wheels"), this);
Chris@66 1037 action->setShortcut(tr("Z"));
Chris@66 1038 action->setStatusTip(tr("Show thumbwheels for zooming horizontally and vertically"));
Chris@66 1039 connect(action, SIGNAL(triggered()), this, SLOT(toggleZoomWheels()));
Chris@66 1040 action->setCheckable(true);
Chris@66 1041 action->setChecked(m_viewManager->getZoomWheelsEnabled());
Chris@162 1042 m_keyReference->registerShortcut(action);
Chris@66 1043 menu->addAction(action);
Chris@387 1044
Chris@494 1045 m_showPropertyBoxesAction = new QAction(tr("Show Property Bo&xes"), this);
Chris@494 1046 m_showPropertyBoxesAction->setShortcut(tr("X"));
Chris@494 1047 m_showPropertyBoxesAction->setStatusTip(tr("Show the layer property boxes at the side of the main window"));
Chris@494 1048 connect(m_showPropertyBoxesAction, SIGNAL(triggered()), this, SLOT(togglePropertyBoxes()));
Chris@494 1049 m_showPropertyBoxesAction->setCheckable(true);
Chris@494 1050 m_showPropertyBoxesAction->setChecked(true);
Chris@494 1051 m_keyReference->registerShortcut(m_showPropertyBoxesAction);
Chris@494 1052 menu->addAction(m_showPropertyBoxesAction);
Chris@0 1053
Chris@90 1054 action = new QAction(tr("Show Status &Bar"), this);
Chris@90 1055 action->setStatusTip(tr("Show context help information in the status bar at the bottom of the window"));
Chris@90 1056 connect(action, SIGNAL(triggered()), this, SLOT(toggleStatusBar()));
Chris@90 1057 action->setCheckable(true);
Chris@90 1058 action->setChecked(true);
Chris@90 1059 menu->addAction(action);
Chris@90 1060
Chris@90 1061 QSettings settings;
Chris@90 1062 settings.beginGroup("MainWindow");
Chris@90 1063 bool sb = settings.value("showstatusbar", true).toBool();
Chris@90 1064 if (!sb) {
Chris@90 1065 action->setChecked(false);
Chris@90 1066 statusBar()->hide();
Chris@90 1067 }
Chris@90 1068 settings.endGroup();
Chris@90 1069
Chris@66 1070 menu->addSeparator();
Chris@66 1071
Chris@219 1072 action = new QAction(tr("Show La&yer Summary"), this);
Chris@219 1073 action->setShortcut(tr("Y"));
Chris@90 1074 action->setStatusTip(tr("Open a window displaying the hierarchy of panes and layers in this session"));
Chris@66 1075 connect(action, SIGNAL(triggered()), this, SLOT(showLayerTree()));
Chris@162 1076 m_keyReference->registerShortcut(action);
Chris@66 1077 menu->addAction(action);
Chris@306 1078
Chris@306 1079 action = new QAction(tr("Show Acti&vity Log"), this);
Chris@306 1080 action->setStatusTip(tr("Open a window listing interactions and other events"));
Chris@306 1081 connect(action, SIGNAL(triggered()), this, SLOT(showActivityLog()));
Chris@306 1082 menu->addAction(action);
Chris@493 1083
Chris@891 1084 action = new QAction(tr("Show &Unit Converter"), this);
Chris@891 1085 action->setStatusTip(tr("Open a window of pitch and timing conversion utilities"));
Chris@891 1086 connect(action, SIGNAL(triggered()), this, SLOT(showUnitConverter()));
Chris@891 1087 menu->addAction(action);
Chris@891 1088
Chris@494 1089 menu->addSeparator();
Chris@494 1090
Chris@493 1091 action = new QAction(tr("Go Full-Screen"), this);
Chris@494 1092 action->setShortcut(tr("F11"));
Chris@494 1093 action->setStatusTip(tr("Expand the pane area to the whole screen"));
Chris@493 1094 connect(action, SIGNAL(triggered()), this, SLOT(goFullScreen()));
Chris@494 1095 m_keyReference->registerShortcut(action);
Chris@493 1096 menu->addAction(action);
Chris@66 1097 }
Chris@66 1098
Chris@66 1099 void
Chris@66 1100 MainWindow::setupPaneAndLayerMenus()
Chris@66 1101 {
Chris@0 1102 if (m_paneMenu) {
Chris@634 1103 m_paneActions.clear();
Chris@634 1104 m_paneMenu->clear();
Chris@0 1105 } else {
Chris@634 1106 m_paneMenu = menuBar()->addMenu(tr("&Pane"));
Chris@97 1107 m_paneMenu->setTearOffEnabled(true);
Chris@0 1108 }
Chris@0 1109
Chris@0 1110 if (m_layerMenu) {
Chris@634 1111 m_layerActions.clear();
Chris@634 1112 m_layerMenu->clear();
Chris@0 1113 } else {
Chris@634 1114 m_layerMenu = menuBar()->addMenu(tr("&Layer"));
Chris@97 1115 m_layerMenu->setTearOffEnabled(true);
Chris@0 1116 }
Chris@0 1117
Chris@345 1118 if (m_rightButtonLayerMenu) {
Chris@345 1119 m_rightButtonLayerMenu->clear();
Chris@345 1120 } else {
Chris@345 1121 m_rightButtonLayerMenu = m_rightButtonMenu->addMenu(tr("&Layer"));
Chris@345 1122 m_rightButtonLayerMenu->setTearOffEnabled(true);
Chris@345 1123 m_rightButtonMenu->addSeparator();
Chris@345 1124 }
Chris@345 1125
Chris@66 1126 QMenu *menu = m_paneMenu;
Chris@66 1127
Chris@168 1128 IconLoader il;
Chris@168 1129
Chris@162 1130 m_keyReference->setCategory(tr("Managing Panes and Layers"));
Chris@162 1131
Chris@168 1132 QAction *action = new QAction(il.load("pane"), tr("Add &New Pane"), this);
Chris@155 1133 action->setShortcut(tr("N"));
Chris@66 1134 action->setStatusTip(tr("Add a new pane containing only a time ruler"));
Chris@66 1135 connect(action, SIGNAL(triggered()), this, SLOT(addPane()));
Chris@66 1136 connect(this, SIGNAL(canAddPane(bool)), action, SLOT(setEnabled(bool)));
Chris@232 1137 m_paneActions[action] = LayerConfiguration(LayerFactory::TimeRuler);
Chris@162 1138 m_keyReference->registerShortcut(action);
Chris@66 1139 menu->addAction(action);
Chris@66 1140
Chris@66 1141 menu->addSeparator();
Chris@66 1142
Chris@66 1143 menu = m_layerMenu;
Chris@66 1144
Chris@66 1145 // menu->addSeparator();
Chris@66 1146
Chris@66 1147 LayerFactory::LayerTypeSet emptyLayerTypes =
Chris@634 1148 LayerFactory::getInstance()->getValidEmptyLayerTypes();
Chris@66 1149
Chris@66 1150 for (LayerFactory::LayerTypeSet::iterator i = emptyLayerTypes.begin();
Chris@634 1151 i != emptyLayerTypes.end(); ++i) {
Chris@634 1152
Chris@634 1153 QIcon icon;
Chris@634 1154 QString mainText, tipText, channelText;
Chris@634 1155 LayerFactory::LayerType type = *i;
Chris@634 1156 QString name = LayerFactory::getInstance()->getLayerPresentationName(type);
Chris@634 1157
Chris@634 1158 icon = il.load(LayerFactory::getInstance()->getLayerIconName(type));
Chris@634 1159
Chris@634 1160 mainText = tr("Add New %1 Layer").arg(name);
Chris@634 1161 tipText = tr("Add a new empty layer of type %1").arg(name);
Chris@634 1162
Chris@634 1163 action = new QAction(icon, mainText, this);
Chris@634 1164 action->setStatusTip(tipText);
Chris@634 1165
Chris@634 1166 if (type == LayerFactory::Text) {
Chris@634 1167 action->setShortcut(tr("T"));
Chris@162 1168 m_keyReference->registerShortcut(action);
Chris@66 1169 }
Chris@634 1170 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@634 1171 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@634 1172 m_layerActions[action] = LayerConfiguration(type);
Chris@634 1173 menu->addAction(action);
Chris@634 1174 m_rightButtonLayerMenu->addAction(action);
Chris@634 1175 }
Chris@634 1176
Chris@66 1177 m_rightButtonLayerMenu->addSeparator();
Chris@66 1178 menu->addSeparator();
Chris@66 1179
Chris@66 1180 LayerFactory::LayerType backgroundTypes[] = {
Chris@634 1181 LayerFactory::Waveform,
Chris@634 1182 LayerFactory::Spectrogram,
Chris@634 1183 LayerFactory::MelodicRangeSpectrogram,
Chris@634 1184 LayerFactory::PeakFrequencySpectrogram,
Chris@66 1185 LayerFactory::Spectrum
Chris@66 1186 };
Chris@66 1187
Chris@66 1188 std::vector<Model *> models;
Chris@224 1189 if (m_document) models = m_document->getTransformInputModels();
Chris@66 1190 bool plural = (models.size() > 1);
Chris@66 1191 if (models.empty()) {
Chris@67 1192 models.push_back(getMainModel()); // probably 0
Chris@66 1193 }
Chris@66 1194
Chris@66 1195 for (unsigned int i = 0;
Chris@634 1196 i < sizeof(backgroundTypes)/sizeof(backgroundTypes[0]); ++i) {
Chris@66 1197
Chris@231 1198 const int paneMenuType = 0, layerMenuType = 1;
Chris@231 1199
Chris@634 1200 for (int menuType = paneMenuType; menuType <= layerMenuType; ++menuType) {
Chris@634 1201
Chris@634 1202 if (menuType == paneMenuType) menu = m_paneMenu;
Chris@634 1203 else menu = m_layerMenu;
Chris@634 1204
Chris@634 1205 QMenu *submenu = 0;
Chris@66 1206
Chris@66 1207 QIcon icon;
Chris@66 1208 QString mainText, shortcutText, tipText, channelText;
Chris@66 1209 LayerFactory::LayerType type = backgroundTypes[i];
Chris@66 1210 bool mono = true;
Chris@634 1211
Chris@730 1212 // Avoid warnings/errors with -Wextra because we aren't explicitly
Chris@730 1213 // handling all layer types (-Wall is OK with this because of the
Chris@730 1214 // default but the stricter level insists)
Chris@730 1215 #pragma GCC diagnostic ignored "-Wswitch-enum"
Chris@674 1216
Chris@66 1217 switch (type) {
Chris@634 1218
Chris@66 1219 case LayerFactory::Waveform:
Chris@168 1220 icon = il.load("waveform");
Chris@66 1221 mainText = tr("Add &Waveform");
Chris@231 1222 if (menuType == paneMenuType) {
Chris@155 1223 shortcutText = tr("W");
Chris@66 1224 tipText = tr("Add a new pane showing a waveform view");
Chris@66 1225 } else {
Chris@348 1226 shortcutText = tr("Shift+W");
Chris@66 1227 tipText = tr("Add a new layer showing a waveform view");
Chris@66 1228 }
Chris@66 1229 mono = false;
Chris@66 1230 break;
Chris@634 1231
Chris@66 1232 case LayerFactory::Spectrogram:
Chris@168 1233 icon = il.load("spectrogram");
Chris@161 1234 mainText = tr("Add Spectro&gram");
Chris@231 1235 if (menuType == paneMenuType) {
Chris@155 1236 shortcutText = tr("G");
Chris@90 1237 tipText = tr("Add a new pane showing a spectrogram");
Chris@66 1238 } else {
Chris@348 1239 shortcutText = tr("Shift+G");
Chris@90 1240 tipText = tr("Add a new layer showing a spectrogram");
Chris@66 1241 }
Chris@66 1242 break;
Chris@634 1243
Chris@66 1244 case LayerFactory::MelodicRangeSpectrogram:
Chris@168 1245 icon = il.load("spectrogram");
Chris@66 1246 mainText = tr("Add &Melodic Range Spectrogram");
Chris@231 1247 if (menuType == paneMenuType) {
Chris@155 1248 shortcutText = tr("M");
Chris@90 1249 tipText = tr("Add a new pane showing a spectrogram set up for an overview of note pitches");
Chris@66 1250 } else {
Chris@348 1251 shortcutText = tr("Shift+M");
Chris@90 1252 tipText = tr("Add a new layer showing a spectrogram set up for an overview of note pitches");
Chris@66 1253 }
Chris@66 1254 break;
Chris@634 1255
Chris@66 1256 case LayerFactory::PeakFrequencySpectrogram:
Chris@168 1257 icon = il.load("spectrogram");
Chris@155 1258 mainText = tr("Add Pea&k Frequency Spectrogram");
Chris@231 1259 if (menuType == paneMenuType) {
Chris@155 1260 shortcutText = tr("K");
Chris@66 1261 tipText = tr("Add a new pane showing a spectrogram set up for tracking frequencies");
Chris@66 1262 } else {
Chris@348 1263 shortcutText = tr("Shift+K");
Chris@66 1264 tipText = tr("Add a new layer showing a spectrogram set up for tracking frequencies");
Chris@66 1265 }
Chris@66 1266 break;
Chris@634 1267
Chris@66 1268 case LayerFactory::Spectrum:
Chris@168 1269 icon = il.load("spectrum");
Chris@66 1270 mainText = tr("Add Spectr&um");
Chris@231 1271 if (menuType == paneMenuType) {
Chris@155 1272 shortcutText = tr("U");
Chris@66 1273 tipText = tr("Add a new pane showing a frequency spectrum");
Chris@66 1274 } else {
Chris@348 1275 shortcutText = tr("Shift+U");
Chris@66 1276 tipText = tr("Add a new layer showing a frequency spectrum");
Chris@66 1277 }
Chris@66 1278 break;
Chris@634 1279
Chris@66 1280 default: break;
Chris@66 1281 }
Chris@66 1282
Chris@346 1283 std::vector<Model *> candidateModels = models;
Chris@634 1284
Chris@66 1285 for (std::vector<Model *>::iterator mi =
Chris@66 1286 candidateModels.begin();
Chris@66 1287 mi != candidateModels.end(); ++mi) {
Chris@634 1288
Chris@66 1289 Model *model = *mi;
Chris@66 1290
Chris@66 1291 int channels = 0;
Chris@66 1292 if (model) {
Chris@66 1293 DenseTimeValueModel *dtvm =
Chris@66 1294 dynamic_cast<DenseTimeValueModel *>(model);
Chris@66 1295 if (dtvm) channels = dtvm->getChannelCount();
Chris@66 1296 }
Chris@66 1297 if (channels < 1 && getMainModel()) {
Chris@66 1298 channels = getMainModel()->getChannelCount();
Chris@66 1299 }
Chris@66 1300 if (channels < 1) channels = 1;
Chris@66 1301
Chris@66 1302 for (int c = 0; c <= channels; ++c) {
Chris@66 1303
Chris@66 1304 if (c == 1 && channels == 1) continue;
Chris@66 1305 bool isDefault = (c == 0);
Chris@66 1306 bool isOnly = (isDefault && (channels == 1));
Chris@66 1307
Chris@346 1308 if (isOnly && !plural) {
Chris@346 1309
Chris@346 1310 action = new QAction(icon, mainText, this);
Chris@67 1311
Chris@66 1312 action->setShortcut(shortcutText);
Chris@66 1313 action->setStatusTip(tipText);
Chris@231 1314 if (menuType == paneMenuType) {
Chris@66 1315 connect(action, SIGNAL(triggered()),
Chris@66 1316 this, SLOT(addPane()));
Chris@66 1317 connect(this, SIGNAL(canAddPane(bool)),
Chris@66 1318 action, SLOT(setEnabled(bool)));
Chris@346 1319 m_paneActions[action] =
Chris@346 1320 LayerConfiguration(type, model);
Chris@66 1321 } else {
Chris@66 1322 connect(action, SIGNAL(triggered()),
Chris@66 1323 this, SLOT(addLayer()));
Chris@66 1324 connect(this, SIGNAL(canAddLayer(bool)),
Chris@66 1325 action, SLOT(setEnabled(bool)));
Chris@346 1326 m_layerActions[action] =
Chris@346 1327 LayerConfiguration(type, model);
Chris@66 1328 }
Chris@162 1329 if (shortcutText != "") {
Chris@162 1330 m_keyReference->registerShortcut(action);
Chris@162 1331 }
Chris@66 1332 menu->addAction(action);
Chris@634 1333
Chris@66 1334 } else {
Chris@634 1335
Chris@66 1336 if (!submenu) {
Chris@66 1337 submenu = menu->addMenu(mainText);
Chris@97 1338 submenu->setTearOffEnabled(true);
Chris@67 1339 } else if (isDefault) {
Chris@67 1340 submenu->addSeparator();
Chris@66 1341 }
Chris@66 1342
Chris@66 1343 QString actionText;
Chris@66 1344 if (c == 0) {
Chris@66 1345 if (mono) {
Chris@66 1346 actionText = tr("&All Channels Mixed");
Chris@66 1347 } else {
Chris@66 1348 actionText = tr("&All Channels");
Chris@66 1349 }
Chris@66 1350 } else {
Chris@66 1351 actionText = tr("Channel &%1").arg(c);
Chris@66 1352 }
Chris@66 1353
Chris@66 1354 if (model) {
Chris@66 1355 actionText = tr("%1: %2")
Chris@66 1356 .arg(model->objectName())
Chris@66 1357 .arg(actionText);
Chris@66 1358 }
Chris@67 1359
Chris@67 1360 if (isDefault) {
Chris@67 1361 action = new QAction(icon, actionText, this);
Chris@67 1362 if (!model || model == getMainModel()) {
Chris@634 1363 action->setShortcut(shortcutText);
Chris@67 1364 }
Chris@67 1365 } else {
Chris@67 1366 action = new QAction(actionText, this);
Chris@67 1367 }
Chris@67 1368
Chris@66 1369 action->setStatusTip(tipText);
Chris@66 1370
Chris@231 1371 if (menuType == paneMenuType) {
Chris@66 1372 connect(action, SIGNAL(triggered()),
Chris@66 1373 this, SLOT(addPane()));
Chris@66 1374 connect(this, SIGNAL(canAddPane(bool)),
Chris@66 1375 action, SLOT(setEnabled(bool)));
Chris@66 1376 m_paneActions[action] =
Chris@232 1377 LayerConfiguration(type, model, c - 1);
Chris@66 1378 } else {
Chris@66 1379 connect(action, SIGNAL(triggered()),
Chris@66 1380 this, SLOT(addLayer()));
Chris@66 1381 connect(this, SIGNAL(canAddLayer(bool)),
Chris@66 1382 action, SLOT(setEnabled(bool)));
Chris@232 1383 m_layerActions[action] =
Chris@232 1384 LayerConfiguration(type, model, c - 1);
Chris@66 1385 }
Chris@66 1386
Chris@66 1387 submenu->addAction(action);
Chris@66 1388 }
Chris@346 1389
Chris@415 1390 if (isDefault && menuType == layerMenuType &&
Chris@415 1391 mi == candidateModels.begin()) {
Chris@415 1392 // only add for one model, one channel, one menu on
Chris@415 1393 // right button -- the action itself will discover
Chris@415 1394 // which model is the correct one (based on pane)
Chris@346 1395 action = new QAction(icon, mainText, this);
Chris@346 1396 action->setStatusTip(tipText);
Chris@346 1397 connect(action, SIGNAL(triggered()),
Chris@346 1398 this, SLOT(addLayer()));
Chris@346 1399 connect(this, SIGNAL(canAddLayer(bool)),
Chris@346 1400 action, SLOT(setEnabled(bool)));
Chris@346 1401 m_layerActions[action] = LayerConfiguration(type, 0, 0);
Chris@346 1402 m_rightButtonLayerMenu->addAction(action);
Chris@346 1403 }
Chris@634 1404 }
Chris@634 1405 }
Chris@634 1406 }
Chris@66 1407 }
Chris@66 1408
Chris@347 1409 m_rightButtonLayerMenu->addSeparator();
Chris@347 1410
Chris@66 1411 menu = m_paneMenu;
Chris@225 1412 menu->addSeparator();
Chris@225 1413
Chris@225 1414 action = new QAction(tr("Switch to Previous Pane"), this);
Chris@225 1415 action->setShortcut(tr("["));
Chris@225 1416 action->setStatusTip(tr("Make the next pane up in the pane stack current"));
Chris@225 1417 connect(action, SIGNAL(triggered()), this, SLOT(previousPane()));
Chris@225 1418 connect(this, SIGNAL(canSelectPreviousPane(bool)), action, SLOT(setEnabled(bool)));
Chris@225 1419 m_keyReference->registerShortcut(action);
Chris@225 1420 menu->addAction(action);
Chris@225 1421
Chris@225 1422 action = new QAction(tr("Switch to Next Pane"), this);
Chris@225 1423 action->setShortcut(tr("]"));
Chris@225 1424 action->setStatusTip(tr("Make the next pane down in the pane stack current"));
Chris@225 1425 connect(action, SIGNAL(triggered()), this, SLOT(nextPane()));
Chris@225 1426 connect(this, SIGNAL(canSelectNextPane(bool)), action, SLOT(setEnabled(bool)));
Chris@225 1427 m_keyReference->registerShortcut(action);
Chris@225 1428 menu->addAction(action);
Chris@66 1429
Chris@66 1430 menu->addSeparator();
Chris@66 1431
Chris@168 1432 action = new QAction(il.load("editdelete"), tr("&Delete Pane"), this);
Chris@155 1433 action->setShortcut(tr("Ctrl+Shift+D"));
Chris@90 1434 action->setStatusTip(tr("Delete the currently active pane"));
Chris@66 1435 connect(action, SIGNAL(triggered()), this, SLOT(deleteCurrentPane()));
Chris@66 1436 connect(this, SIGNAL(canDeleteCurrentPane(bool)), action, SLOT(setEnabled(bool)));
Chris@162 1437 m_keyReference->registerShortcut(action);
Chris@66 1438 menu->addAction(action);
Chris@66 1439
Chris@66 1440 menu = m_layerMenu;
Chris@66 1441
Chris@168 1442 action = new QAction(il.load("timeruler"), tr("Add &Time Ruler"), this);
Chris@66 1443 action->setStatusTip(tr("Add a new layer showing a time ruler"));
Chris@66 1444 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@66 1445 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@232 1446 m_layerActions[action] = LayerConfiguration(LayerFactory::TimeRuler);
Chris@66 1447 menu->addAction(action);
Chris@66 1448
Chris@66 1449 menu->addSeparator();
Chris@66 1450
Chris@66 1451 m_existingLayersMenu = menu->addMenu(tr("Add &Existing Layer"));
Chris@97 1452 m_existingLayersMenu->setTearOffEnabled(true);
Chris@66 1453 m_rightButtonLayerMenu->addMenu(m_existingLayersMenu);
Chris@95 1454
Chris@95 1455 m_sliceMenu = menu->addMenu(tr("Add S&lice of Layer"));
Chris@97 1456 m_sliceMenu->setTearOffEnabled(true);
Chris@95 1457 m_rightButtonLayerMenu->addMenu(m_sliceMenu);
Chris@95 1458
Chris@95 1459 setupExistingLayersMenus();
Chris@66 1460
Chris@225 1461 menu->addSeparator();
Chris@225 1462
Chris@225 1463 action = new QAction(tr("Switch to Previous Layer"), this);
Chris@225 1464 action->setShortcut(tr("{"));
Chris@225 1465 action->setStatusTip(tr("Make the previous layer in the pane current"));
Chris@225 1466 connect(action, SIGNAL(triggered()), this, SLOT(previousLayer()));
Chris@225 1467 connect(this, SIGNAL(canSelectPreviousLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@225 1468 m_keyReference->registerShortcut(action);
Chris@225 1469 menu->addAction(action);
Chris@225 1470
Chris@225 1471 action = new QAction(tr("Switch to Next Layer"), this);
Chris@225 1472 action->setShortcut(tr("}"));
Chris@225 1473 action->setStatusTip(tr("Make the next layer in the pane current"));
Chris@225 1474 connect(action, SIGNAL(triggered()), this, SLOT(nextLayer()));
Chris@225 1475 connect(this, SIGNAL(canSelectNextLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@225 1476 m_keyReference->registerShortcut(action);
Chris@225 1477 menu->addAction(action);
Chris@785 1478
Chris@66 1479 m_rightButtonLayerMenu->addSeparator();
Chris@66 1480 menu->addSeparator();
Chris@66 1481
Chris@163 1482 QAction *raction = new QAction(tr("&Rename Layer..."), this);
Chris@163 1483 raction->setShortcut(tr("R"));
Chris@163 1484 raction->setStatusTip(tr("Rename the currently active layer"));
Chris@163 1485 connect(raction, SIGNAL(triggered()), this, SLOT(renameCurrentLayer()));
Chris@163 1486 connect(this, SIGNAL(canRenameLayer(bool)), raction, SLOT(setEnabled(bool)));
Chris@163 1487 menu->addAction(raction);
Chris@163 1488 m_rightButtonLayerMenu->addAction(raction);
Chris@66 1489
Chris@258 1490 QAction *eaction = new QAction(tr("Edit Layer Data"), this);
Chris@258 1491 eaction->setShortcut(tr("E"));
Chris@258 1492 eaction->setStatusTip(tr("Edit the currently active layer as a data grid"));
Chris@258 1493 connect(eaction, SIGNAL(triggered()), this, SLOT(editCurrentLayer()));
Chris@291 1494 connect(this, SIGNAL(canEditLayerTabular(bool)), eaction, SLOT(setEnabled(bool)));
Chris@258 1495 menu->addAction(eaction);
Chris@258 1496 m_rightButtonLayerMenu->addAction(eaction);
Chris@258 1497
Chris@168 1498 action = new QAction(il.load("editdelete"), tr("&Delete Layer"), this);
Chris@155 1499 action->setShortcut(tr("Ctrl+D"));
Chris@66 1500 action->setStatusTip(tr("Delete the currently active layer"));
Chris@66 1501 connect(action, SIGNAL(triggered()), this, SLOT(deleteCurrentLayer()));
Chris@66 1502 connect(this, SIGNAL(canDeleteCurrentLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@162 1503 m_keyReference->registerShortcut(action);
Chris@66 1504 menu->addAction(action);
Chris@66 1505 m_rightButtonLayerMenu->addAction(action);
Chris@163 1506
Chris@163 1507 m_keyReference->registerShortcut(raction); // rename after delete, so delete layer goes next to delete pane
Chris@258 1508 m_keyReference->registerShortcut(eaction); // edit also after delete
Chris@755 1509
Chris@755 1510 finaliseMenus();
Chris@66 1511 }
Chris@66 1512
Chris@66 1513 void
Chris@211 1514 MainWindow::setupTransformsMenu()
Chris@66 1515 {
Chris@34 1516 if (m_transformsMenu) {
Chris@34 1517 m_transformActions.clear();
Chris@34 1518 m_transformActionsReverse.clear();
Chris@34 1519 m_transformsMenu->clear();
Chris@34 1520 } else {
Chris@634 1521 m_transformsMenu = menuBar()->addMenu(tr("&Transform"));
Chris@97 1522 m_transformsMenu->setTearOffEnabled(true);
Chris@286 1523 m_transformsMenu->setSeparatorsCollapsible(true);
Chris@272 1524 }
Chris@34 1525
Chris@288 1526 TransformFactory *factory = TransformFactory::getInstance();
Chris@288 1527
Chris@288 1528 TransformList transforms = factory->getAllTransformDescriptions();
Chris@288 1529 vector<TransformDescription::Type> types = factory->getAllTransformTypes();
Chris@288 1530
Chris@288 1531 map<TransformDescription::Type, map<QString, SubdividingMenu *> > categoryMenus;
Chris@288 1532 map<TransformDescription::Type, map<QString, SubdividingMenu *> > makerMenus;
Chris@288 1533
Chris@288 1534 map<TransformDescription::Type, SubdividingMenu *> byPluginNameMenus;
Chris@288 1535 map<TransformDescription::Type, map<QString, QMenu *> > pluginNameMenus;
Chris@33 1536
Chris@37 1537 set<SubdividingMenu *> pendingMenus;
Chris@37 1538
Chris@211 1539 m_recentTransformsMenu = m_transformsMenu->addMenu(tr("&Recent Transforms"));
Chris@211 1540 m_recentTransformsMenu->setTearOffEnabled(true);
Chris@211 1541 m_rightButtonTransformsMenu->addMenu(m_recentTransformsMenu);
Chris@211 1542 connect(&m_recentTransforms, SIGNAL(recentChanged()),
Chris@211 1543 this, SLOT(setupRecentTransformsMenu()));
Chris@34 1544
Chris@34 1545 m_transformsMenu->addSeparator();
Chris@211 1546 m_rightButtonTransformsMenu->addSeparator();
Chris@634 1547
Chris@288 1548 for (vector<TransformDescription::Type>::iterator i = types.begin();
Chris@288 1549 i != types.end(); ++i) {
Chris@33 1550
Chris@33 1551 if (i != types.begin()) {
Chris@34 1552 m_transformsMenu->addSeparator();
Chris@211 1553 m_rightButtonTransformsMenu->addSeparator();
Chris@33 1554 }
Chris@33 1555
Chris@288 1556 QString byCategoryLabel = tr("%1 by Category")
Chris@288 1557 .arg(factory->getTransformTypeName(*i));
Chris@37 1558 SubdividingMenu *byCategoryMenu = new SubdividingMenu(byCategoryLabel,
Chris@37 1559 20, 40);
Chris@97 1560 byCategoryMenu->setTearOffEnabled(true);
Chris@37 1561 m_transformsMenu->addMenu(byCategoryMenu);
Chris@211 1562 m_rightButtonTransformsMenu->addMenu(byCategoryMenu);
Chris@37 1563 pendingMenus.insert(byCategoryMenu);
Chris@33 1564
Chris@288 1565 vector<QString> categories = factory->getTransformCategories(*i);
Chris@33 1566
Chris@33 1567 for (vector<QString>::iterator j = categories.begin();
Chris@33 1568 j != categories.end(); ++j) {
Chris@33 1569
Chris@33 1570 QString category = *j;
Chris@33 1571 if (category == "") category = tr("Unclassified");
Chris@33 1572
Chris@33 1573 if (categories.size() < 2) {
Chris@33 1574 categoryMenus[*i][category] = byCategoryMenu;
Chris@33 1575 continue;
Chris@33 1576 }
Chris@33 1577
Chris@33 1578 QStringList components = category.split(" > ");
Chris@33 1579 QString key;
Chris@33 1580
Chris@33 1581 for (QStringList::iterator k = components.begin();
Chris@33 1582 k != components.end(); ++k) {
Chris@33 1583
Chris@33 1584 QString parentKey = key;
Chris@33 1585 if (key != "") key += " > ";
Chris@33 1586 key += *k;
Chris@33 1587
Chris@33 1588 if (categoryMenus[*i].find(key) == categoryMenus[*i].end()) {
Chris@37 1589 SubdividingMenu *m = new SubdividingMenu(*k, 20, 40);
Chris@97 1590 m->setTearOffEnabled(true);
Chris@37 1591 pendingMenus.insert(m);
Chris@37 1592 categoryMenus[*i][key] = m;
Chris@33 1593 if (parentKey == "") {
Chris@37 1594 byCategoryMenu->addMenu(m);
Chris@33 1595 } else {
Chris@37 1596 categoryMenus[*i][parentKey]->addMenu(m);
Chris@33 1597 }
Chris@33 1598 }
Chris@33 1599 }
Chris@33 1600 }
Chris@33 1601
Chris@288 1602 QString byPluginNameLabel = tr("%1 by Plugin Name")
Chris@288 1603 .arg(factory->getTransformTypeName(*i));
Chris@36 1604 byPluginNameMenus[*i] = new SubdividingMenu(byPluginNameLabel);
Chris@97 1605 byPluginNameMenus[*i]->setTearOffEnabled(true);
Chris@36 1606 m_transformsMenu->addMenu(byPluginNameMenus[*i]);
Chris@211 1607 m_rightButtonTransformsMenu->addMenu(byPluginNameMenus[*i]);
Chris@37 1608 pendingMenus.insert(byPluginNameMenus[*i]);
Chris@34 1609
Chris@288 1610 QString byMakerLabel = tr("%1 by Maker")
Chris@288 1611 .arg(factory->getTransformTypeName(*i));
Chris@37 1612 SubdividingMenu *byMakerMenu = new SubdividingMenu(byMakerLabel, 20, 40);
Chris@97 1613 byMakerMenu->setTearOffEnabled(true);
Chris@37 1614 m_transformsMenu->addMenu(byMakerMenu);
Chris@211 1615 m_rightButtonTransformsMenu->addMenu(byMakerMenu);
Chris@37 1616 pendingMenus.insert(byMakerMenu);
Chris@33 1617
Chris@288 1618 vector<QString> makers = factory->getTransformMakers(*i);
Chris@37 1619
Chris@33 1620 for (vector<QString>::iterator j = makers.begin();
Chris@33 1621 j != makers.end(); ++j) {
Chris@33 1622
Chris@33 1623 QString maker = *j;
Chris@33 1624 if (maker == "") maker = tr("Unknown");
Chris@55 1625 maker.replace(QRegExp(tr(" [\\(<].*$")), "");
Chris@55 1626
Chris@37 1627 makerMenus[*i][maker] = new SubdividingMenu(maker, 30, 40);
Chris@97 1628 makerMenus[*i][maker]->setTearOffEnabled(true);
Chris@37 1629 byMakerMenu->addMenu(makerMenus[*i][maker]);
Chris@37 1630 pendingMenus.insert(makerMenus[*i][maker]);
Chris@33 1631 }
Chris@0 1632 }
Chris@0 1633
Chris@230 1634 // Names should only be duplicated here if they have the same
Chris@230 1635 // plugin name, output name and maker but are in different library
Chris@230 1636 // .so names -- that won't happen often I hope
Chris@230 1637 std::map<QString, QString> idNameSonameMap;
Chris@230 1638 std::set<QString> seenNames, duplicateNames;
Chris@230 1639 for (unsigned int i = 0; i < transforms.size(); ++i) {
Chris@230 1640 QString name = transforms[i].name;
Chris@230 1641 if (seenNames.find(name) != seenNames.end()) {
Chris@230 1642 duplicateNames.insert(name);
Chris@230 1643 } else {
Chris@230 1644 seenNames.insert(name);
Chris@230 1645 }
Chris@230 1646 }
Chris@230 1647
Chris@0 1648 for (unsigned int i = 0; i < transforms.size(); ++i) {
Chris@634 1649
Chris@634 1650 QString name = transforms[i].name;
Chris@634 1651 if (name == "") name = transforms[i].identifier;
Chris@107 1652
Chris@665 1653 // cerr << "Plugin Name: " << name << endl;
Chris@80 1654
Chris@288 1655 TransformDescription::Type type = transforms[i].type;
Chris@288 1656 QString typeStr = factory->getTransformTypeName(type);
Chris@33 1657
Chris@33 1658 QString category = transforms[i].category;
Chris@33 1659 if (category == "") category = tr("Unclassified");
Chris@33 1660
Chris@33 1661 QString maker = transforms[i].maker;
Chris@33 1662 if (maker == "") maker = tr("Unknown");
Chris@55 1663 maker.replace(QRegExp(tr(" [\\(<].*$")), "");
Chris@33 1664
Chris@107 1665 QString pluginName = name.section(": ", 0, 0);
Chris@107 1666 QString output = name.section(": ", 1);
Chris@107 1667
Chris@230 1668 if (duplicateNames.find(pluginName) != duplicateNames.end()) {
Chris@230 1669 pluginName = QString("%1 <%2>")
Chris@230 1670 .arg(pluginName)
Chris@230 1671 .arg(transforms[i].identifier.section(':', 1, 1));
Chris@230 1672 if (output == "") name = pluginName;
Chris@230 1673 else name = QString("%1: %2")
Chris@230 1674 .arg(pluginName)
Chris@230 1675 .arg(output);
Chris@230 1676 }
Chris@230 1677
Chris@634 1678 QAction *action = new QAction(tr("%1...").arg(name), this);
Chris@634 1679 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@634 1680 m_transformActions[action] = transforms[i].identifier;
Chris@107 1681 m_transformActionsReverse[transforms[i].identifier] = action;
Chris@634 1682 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@33 1683
Chris@272 1684 action->setStatusTip(transforms[i].longDescription);
Chris@90 1685
Chris@33 1686 if (categoryMenus[type].find(category) == categoryMenus[type].end()) {
Chris@665 1687 cerr << "WARNING: MainWindow::setupMenus: Internal error: "
Chris@33 1688 << "No category menu for transform \""
Chris@432 1689 << name << "\" (category = \""
Chris@665 1690 << category << "\")" << endl;
Chris@33 1691 } else {
Chris@33 1692 categoryMenus[type][category]->addAction(action);
Chris@33 1693 }
Chris@33 1694
Chris@33 1695 if (makerMenus[type].find(maker) == makerMenus[type].end()) {
Chris@665 1696 cerr << "WARNING: MainWindow::setupMenus: Internal error: "
Chris@33 1697 << "No maker menu for transform \""
Chris@432 1698 << name << "\" (maker = \""
Chris@665 1699 << maker << "\")" << endl;
Chris@33 1700 } else {
Chris@80 1701 makerMenus[type][maker]->addAction(action);
Chris@33 1702 }
Chris@33 1703
Chris@33 1704 action = new QAction(tr("%1...").arg(output == "" ? pluginName : output), this);
Chris@33 1705 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@107 1706 m_transformActions[action] = transforms[i].identifier;
Chris@33 1707 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@272 1708 action->setStatusTip(transforms[i].longDescription);
Chris@33 1709
Chris@432 1710 // cerr << "Transform: \"" << name << "\": plugin name \"" << pluginName << "\"" << endl;
Chris@34 1711
Chris@33 1712 if (pluginNameMenus[type].find(pluginName) ==
Chris@33 1713 pluginNameMenus[type].end()) {
Chris@33 1714
Chris@36 1715 SubdividingMenu *parentMenu = byPluginNameMenus[type];
Chris@97 1716 parentMenu->setTearOffEnabled(true);
Chris@34 1717
Chris@33 1718 if (output == "") {
Chris@36 1719 parentMenu->addAction(pluginName, action);
Chris@33 1720 } else {
Chris@634 1721 pluginNameMenus[type][pluginName] =
Chris@34 1722 parentMenu->addMenu(pluginName);
Chris@33 1723 connect(this, SIGNAL(canAddLayer(bool)),
Chris@33 1724 pluginNameMenus[type][pluginName],
Chris@33 1725 SLOT(setEnabled(bool)));
Chris@33 1726 }
Chris@33 1727 }
Chris@33 1728
Chris@33 1729 if (pluginNameMenus[type].find(pluginName) !=
Chris@33 1730 pluginNameMenus[type].end()) {
Chris@33 1731 pluginNameMenus[type][pluginName]->addAction(action);
Chris@33 1732 }
Chris@0 1733 }
Chris@0 1734
Chris@37 1735 for (set<SubdividingMenu *>::iterator i = pendingMenus.begin();
Chris@37 1736 i != pendingMenus.end(); ++i) {
Chris@37 1737 (*i)->entriesAdded();
Chris@37 1738 }
Chris@37 1739
Chris@273 1740 m_transformsMenu->addSeparator();
Chris@273 1741 m_rightButtonTransformsMenu->addSeparator();
Chris@273 1742
Chris@273 1743 QAction *action = new QAction(tr("Find a Transform..."), this);
Chris@273 1744 action->setStatusTip(tr("Search for a transform from the installed plugins, by name or description"));
Chris@275 1745 action->setShortcut(tr("Ctrl+M"));
Chris@273 1746 connect(action, SIGNAL(triggered()), this, SLOT(findTransform()));
Chris@287 1747 // connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@275 1748 m_keyReference->registerShortcut(action);
Chris@273 1749 m_transformsMenu->addAction(action);
Chris@273 1750 m_rightButtonTransformsMenu->addAction(action);
Chris@273 1751
Chris@211 1752 setupRecentTransformsMenu();
Chris@66 1753 }
Chris@66 1754
Chris@66 1755 void
Chris@66 1756 MainWindow::setupHelpMenu()
Chris@66 1757 {
Chris@66 1758 QMenu *menu = menuBar()->addMenu(tr("&Help"));
Chris@97 1759 menu->setTearOffEnabled(true);
Chris@634 1760
Chris@162 1761 m_keyReference->setCategory(tr("Help"));
Chris@162 1762
Chris@168 1763 IconLoader il;
Chris@168 1764
Chris@518 1765 QString name = QApplication::applicationName();
Chris@518 1766
Chris@168 1767 QAction *action = new QAction(il.load("help"),
Chris@634 1768 tr("&Help Reference"), this);
Chris@162 1769 action->setShortcut(tr("F1"));
Chris@634 1770 action->setStatusTip(tr("Open the %1 reference manual").arg(name));
Chris@66 1771 connect(action, SIGNAL(triggered()), this, SLOT(help()));
Chris@162 1772 m_keyReference->registerShortcut(action);
Chris@0 1773 menu->addAction(action);
Chris@162 1774
Chris@163 1775 action = new QAction(tr("&Key and Mouse Reference"), this);
Chris@162 1776 action->setShortcut(tr("F2"));
Chris@518 1777 action->setStatusTip(tr("Open a window showing the keystrokes you can use in %1").arg(name));
Chris@162 1778 connect(action, SIGNAL(triggered()), this, SLOT(keyReference()));
Chris@162 1779 m_keyReference->registerShortcut(action);
Chris@162 1780 menu->addAction(action);
Chris@634 1781
Chris@634 1782 action = new QAction(tr("%1 on the &Web").arg(name), this);
Chris@634 1783 action->setStatusTip(tr("Open the %1 website").arg(name));
Chris@164 1784 connect(action, SIGNAL(triggered()), this, SLOT(website()));
Chris@164 1785 menu->addAction(action);
Chris@634 1786
Chris@634 1787 action = new QAction(tr("&About %1").arg(name), this);
Chris@634 1788 action->setStatusTip(tr("Show information about %1").arg(name));
Chris@66 1789 connect(action, SIGNAL(triggered()), this, SLOT(about()));
Chris@0 1790 menu->addAction(action);
Chris@0 1791 }
Chris@0 1792
Chris@0 1793 void
Chris@0 1794 MainWindow::setupRecentFilesMenu()
Chris@0 1795 {
Chris@0 1796 m_recentFilesMenu->clear();
Chris@34 1797 vector<QString> files = m_recentFiles.getRecent();
Chris@0 1798 for (size_t i = 0; i < files.size(); ++i) {
Chris@634 1799 QAction *action = new QAction(files[i], this);
Chris@634 1800 connect(action, SIGNAL(triggered()), this, SLOT(openRecentFile()));
Chris@162 1801 if (i == 0) {
Chris@162 1802 action->setShortcut(tr("Ctrl+R"));
Chris@162 1803 m_keyReference->registerShortcut
Chris@163 1804 (tr("Re-open"),
Chris@528 1805 action->shortcut().toString(),
Chris@163 1806 tr("Re-open the current or most recently opened file"));
Chris@162 1807 }
Chris@634 1808 m_recentFilesMenu->addAction(action);
Chris@0 1809 }
Chris@0 1810 }
Chris@0 1811
Chris@0 1812 void
Chris@423 1813 MainWindow::setupTemplatesMenu()
Chris@423 1814 {
Chris@423 1815 m_templatesMenu->clear();
Chris@423 1816
Chris@455 1817 QAction *defaultAction = new QAction(tr("Standard Waveform"), this);
Chris@435 1818 defaultAction->setObjectName("default");
Chris@435 1819 connect(defaultAction, SIGNAL(triggered()), this, SLOT(applyTemplate()));
Chris@435 1820 m_templatesMenu->addAction(defaultAction);
Chris@435 1821
Chris@435 1822 m_templatesMenu->addSeparator();
Chris@435 1823
Chris@435 1824 QAction *action = 0;
Chris@435 1825
Chris@435 1826 QStringList templates = ResourceFinder().getResourceFiles("templates", "svt");
Chris@435 1827
Chris@436 1828 bool havePersonal = false;
Chris@436 1829
Chris@435 1830 // (ordered by name)
Chris@435 1831 std::set<QString> byName;
Chris@435 1832 foreach (QString t, templates) {
Chris@436 1833 if (!t.startsWith(":")) havePersonal = true;
Chris@435 1834 byName.insert(QFileInfo(t).baseName());
Chris@435 1835 }
Chris@435 1836
Chris@435 1837 foreach (QString t, byName) {
Chris@435 1838 if (t.toLower() == "default") continue;
Chris@435 1839 action = new QAction(t, this);
Chris@435 1840 connect(action, SIGNAL(triggered()), this, SLOT(applyTemplate()));
Chris@435 1841 m_templatesMenu->addAction(action);
Chris@435 1842 }
Chris@435 1843
Chris@435 1844 if (!templates.empty()) m_templatesMenu->addSeparator();
Chris@435 1845
Chris@435 1846 if (!m_templateWatcher) {
Chris@435 1847 m_templateWatcher = new QFileSystemWatcher(this);
Chris@435 1848 m_templateWatcher->addPath(ResourceFinder().getResourceSaveDir("templates"));
Chris@435 1849 connect(m_templateWatcher, SIGNAL(directoryChanged(const QString &)),
Chris@435 1850 this, SLOT(setupTemplatesMenu()));
Chris@435 1851 }
Chris@436 1852
Chris@436 1853 QAction *setDefaultAction = new QAction(tr("Choose Default Template..."), this);
Chris@436 1854 setDefaultAction->setObjectName("set_default_template");
Chris@436 1855 connect(setDefaultAction, SIGNAL(triggered()), this, SLOT(preferences()));
Chris@436 1856 m_templatesMenu->addSeparator();
Chris@436 1857 m_templatesMenu->addAction(setDefaultAction);
Chris@436 1858
Chris@436 1859 m_manageTemplatesAction->setEnabled(havePersonal);
Chris@435 1860 }
Chris@435 1861
Chris@423 1862
Chris@423 1863 void
Chris@211 1864 MainWindow::setupRecentTransformsMenu()
Chris@34 1865 {
Chris@211 1866 m_recentTransformsMenu->clear();
Chris@211 1867 vector<QString> transforms = m_recentTransforms.getRecent();
Chris@34 1868 for (size_t i = 0; i < transforms.size(); ++i) {
Chris@211 1869 TransformActionReverseMap::iterator ti =
Chris@34 1870 m_transformActionsReverse.find(transforms[i]);
Chris@34 1871 if (ti == m_transformActionsReverse.end()) {
Chris@665 1872 cerr << "WARNING: MainWindow::setupRecentTransformsMenu: "
Chris@665 1873 << "Unknown transform \"" << transforms[i]
Chris@665 1874 << "\" in recent transforms list" << endl;
Chris@34 1875 continue;
Chris@34 1876 }
Chris@162 1877 if (i == 0) {
Chris@162 1878 ti->second->setShortcut(tr("Ctrl+T"));
Chris@162 1879 m_keyReference->registerShortcut
Chris@211 1880 (tr("Repeat Transform"),
Chris@528 1881 ti->second->shortcut().toString(),
Chris@163 1882 tr("Re-select the most recently run transform"));
Chris@216 1883 } else {
Chris@216 1884 ti->second->setShortcut(QString(""));
Chris@162 1885 }
Chris@634 1886 m_recentTransformsMenu->addAction(ti->second);
Chris@34 1887 }
Chris@34 1888 }
Chris@34 1889
Chris@34 1890 void
Chris@95 1891 MainWindow::setupExistingLayersMenus()
Chris@0 1892 {
Chris@0 1893 if (!m_existingLayersMenu) return; // should have been created by setupMenus
Chris@0 1894
Chris@438 1895 // SVDEBUG << "MainWindow::setupExistingLayersMenu" << endl;
Chris@0 1896
Chris@0 1897 m_existingLayersMenu->clear();
Chris@0 1898 m_existingLayerActions.clear();
Chris@0 1899
Chris@95 1900 m_sliceMenu->clear();
Chris@95 1901 m_sliceActions.clear();
Chris@95 1902
Chris@168 1903 IconLoader il;
Chris@168 1904
Chris@33 1905 vector<Layer *> orderedLayers;
Chris@33 1906 set<Layer *> observedLayers;
Chris@95 1907 set<Layer *> sliceableLayers;
Chris@95 1908
Chris@95 1909 LayerFactory *factory = LayerFactory::getInstance();
Chris@0 1910
Chris@0 1911 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@0 1912
Chris@0 1913 Pane *pane = m_paneStack->getPane(i);
Chris@0 1914 if (!pane) continue;
Chris@0 1915
Chris@0 1916 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@0 1917
Chris@0 1918 Layer *layer = pane->getLayer(j);
Chris@0 1919 if (!layer) continue;
Chris@0 1920 if (observedLayers.find(layer) != observedLayers.end()) {
Chris@665 1921 // cerr << "found duplicate layer " << layer << endl;
Chris@0 1922 continue;
Chris@0 1923 }
Chris@0 1924
Chris@665 1925 // cerr << "found new layer " << layer << " (name = "
Chris@665 1926 // << layer->getLayerPresentationName() << ")" << endl;
Chris@677 1927
Chris@677 1928 orderedLayers.push_back(layer);
Chris@677 1929 observedLayers.insert(layer);
Chris@95 1930
Chris@95 1931 if (factory->isLayerSliceable(layer)) {
Chris@95 1932 sliceableLayers.insert(layer);
Chris@95 1933 }
Chris@677 1934 }
Chris@0 1935 }
Chris@0 1936
Chris@33 1937 map<QString, int> observedNames;
Chris@0 1938
Chris@137 1939 for (size_t i = 0; i < orderedLayers.size(); ++i) {
Chris@634 1940
Chris@95 1941 Layer *layer = orderedLayers[i];
Chris@95 1942
Chris@634 1943 QString name = layer->getLayerPresentationName();
Chris@634 1944 int n = ++observedNames[name];
Chris@634 1945 if (n > 1) name = QString("%1 <%2>").arg(name).arg(n);
Chris@634 1946
Chris@634 1947 QIcon icon = il.load(factory->getLayerIconName
Chris@168 1948 (factory->getLayerType(layer)));
Chris@95 1949
Chris@634 1950 QAction *action = new QAction(icon, name, this);
Chris@634 1951 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@634 1952 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@634 1953 m_existingLayerActions[action] = layer;
Chris@634 1954
Chris@634 1955 m_existingLayersMenu->addAction(action);
Chris@95 1956
Chris@95 1957 if (sliceableLayers.find(layer) != sliceableLayers.end()) {
Chris@95 1958 action = new QAction(icon, name, this);
Chris@95 1959 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@95 1960 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@95 1961 m_sliceActions[action] = layer;
Chris@95 1962 m_sliceMenu->addAction(action);
Chris@95 1963 }
Chris@0 1964 }
Chris@95 1965
Chris@95 1966 m_sliceMenu->setEnabled(!m_sliceActions.empty());
Chris@0 1967 }
Chris@0 1968
Chris@0 1969 void
Chris@0 1970 MainWindow::setupToolbars()
Chris@0 1971 {
Chris@162 1972 m_keyReference->setCategory(tr("Playback and Transport Controls"));
Chris@162 1973
Chris@168 1974 IconLoader il;
Chris@168 1975
Chris@155 1976 QMenu *menu = m_playbackMenu = menuBar()->addMenu(tr("Play&back"));
Chris@155 1977 menu->setTearOffEnabled(true);
Chris@155 1978 m_rightButtonMenu->addSeparator();
Chris@155 1979 m_rightButtonPlaybackMenu = m_rightButtonMenu->addMenu(tr("Playback"));
Chris@155 1980
Chris@155 1981 QToolBar *toolbar = addToolBar(tr("Playback Toolbar"));
Chris@155 1982
Chris@265 1983 m_rwdStartAction = toolbar->addAction(il.load("rewind-start"),
Chris@265 1984 tr("Rewind to Start"));
Chris@265 1985 m_rwdStartAction->setShortcut(tr("Home"));
Chris@265 1986 m_rwdStartAction->setStatusTip(tr("Rewind to the start"));
Chris@265 1987 connect(m_rwdStartAction, SIGNAL(triggered()), this, SLOT(rewindStart()));
Chris@265 1988 connect(this, SIGNAL(canPlay(bool)), m_rwdStartAction, SLOT(setEnabled(bool)));
Chris@265 1989
Chris@265 1990 m_rwdAction = toolbar->addAction(il.load("rewind"), tr("Rewind"));
Chris@155 1991 m_rwdAction->setShortcut(tr("PgUp"));
Chris@163 1992 m_rwdAction->setStatusTip(tr("Rewind to the previous time instant or time ruler notch"));
Chris@155 1993 connect(m_rwdAction, SIGNAL(triggered()), this, SLOT(rewind()));
Chris@155 1994 connect(this, SIGNAL(canRewind(bool)), m_rwdAction, SLOT(setEnabled(bool)));
Chris@155 1995
Chris@323 1996 m_rwdSimilarAction = new QAction(tr("Rewind to Similar Point"), this);
Chris@323 1997 m_rwdSimilarAction->setShortcut(tr("Shift+PgUp"));
Chris@323 1998 m_rwdSimilarAction->setStatusTip(tr("Rewind to the previous similarly valued time instant"));
Chris@323 1999 connect(m_rwdSimilarAction, SIGNAL(triggered()), this, SLOT(rewindSimilar()));
Chris@323 2000 connect(this, SIGNAL(canRewind(bool)), m_rwdSimilarAction, SLOT(setEnabled(bool)));
Chris@323 2001
Chris@265 2002 m_playAction = toolbar->addAction(il.load("playpause"),
Chris@265 2003 tr("Play / Pause"));
Chris@265 2004 m_playAction->setCheckable(true);
Chris@265 2005 m_playAction->setShortcut(tr("Space"));
Chris@265 2006 m_playAction->setStatusTip(tr("Start or stop playback from the current position"));
Chris@265 2007 connect(m_playAction, SIGNAL(triggered()), this, SLOT(play()));
Chris@0 2008 connect(m_playSource, SIGNAL(playStatusChanged(bool)),
Chris@634 2009 m_playAction, SLOT(setChecked(bool)));
Chris@305 2010 connect(m_playSource, SIGNAL(playStatusChanged(bool)),
Chris@305 2011 this, SLOT(playStatusChanged(bool)));
Chris@265 2012 connect(this, SIGNAL(canPlay(bool)), m_playAction, SLOT(setEnabled(bool)));
Chris@155 2013
Chris@168 2014 m_ffwdAction = toolbar->addAction(il.load("ffwd"),
Chris@286 2015 tr("Fast Forward"));
Chris@155 2016 m_ffwdAction->setShortcut(tr("PgDown"));
Chris@163 2017 m_ffwdAction->setStatusTip(tr("Fast-forward to the next time instant or time ruler notch"));
Chris@155 2018 connect(m_ffwdAction, SIGNAL(triggered()), this, SLOT(ffwd()));
Chris@155 2019 connect(this, SIGNAL(canFfwd(bool)), m_ffwdAction, SLOT(setEnabled(bool)));
Chris@155 2020
Chris@323 2021 m_ffwdSimilarAction = new QAction(tr("Fast Forward to Similar Point"), this);
Chris@323 2022 m_ffwdSimilarAction->setShortcut(tr("Shift+PgDown"));
Chris@323 2023 m_ffwdSimilarAction->setStatusTip(tr("Fast-forward to the next similarly valued time instant"));
Chris@323 2024 connect(m_ffwdSimilarAction, SIGNAL(triggered()), this, SLOT(ffwdSimilar()));
Chris@323 2025 connect(this, SIGNAL(canFfwd(bool)), m_ffwdSimilarAction, SLOT(setEnabled(bool)));
Chris@323 2026
Chris@265 2027 m_ffwdEndAction = toolbar->addAction(il.load("ffwd-end"),
Chris@265 2028 tr("Fast Forward to End"));
Chris@265 2029 m_ffwdEndAction->setShortcut(tr("End"));
Chris@265 2030 m_ffwdEndAction->setStatusTip(tr("Fast-forward to the end"));
Chris@265 2031 connect(m_ffwdEndAction, SIGNAL(triggered()), this, SLOT(ffwdEnd()));
Chris@265 2032 connect(this, SIGNAL(canPlay(bool)), m_ffwdEndAction, SLOT(setEnabled(bool)));
Chris@0 2033
Chris@1047 2034 m_recordAction = toolbar->addAction(il.load("record"),
Chris@1047 2035 tr("Record"));
Chris@1047 2036 m_recordAction->setCheckable(true);
Chris@1047 2037 m_recordAction->setShortcut(tr("Ctrl+Space"));
Chris@1047 2038 m_recordAction->setStatusTip(tr("Record a new audio file"));
Chris@1047 2039 connect(m_recordAction, SIGNAL(triggered()), this, SLOT(record()));
Chris@1047 2040 connect(m_recordTarget, SIGNAL(recordStatusChanged(bool)),
Chris@1047 2041 m_recordAction, SLOT(setChecked(bool)));
Chris@1047 2042 connect(this, SIGNAL(canRecord(bool)),
Chris@1047 2043 m_recordAction, SLOT(setEnabled(bool)));
Chris@1047 2044
Chris@0 2045 toolbar = addToolBar(tr("Play Mode Toolbar"));
Chris@0 2046
Chris@265 2047 m_playSelectionAction = toolbar->addAction(il.load("playselection"),
Chris@265 2048 tr("Constrain Playback to Selection"));
Chris@265 2049 m_playSelectionAction->setCheckable(true);
Chris@265 2050 m_playSelectionAction->setChecked(m_viewManager->getPlaySelectionMode());
Chris@265 2051 m_playSelectionAction->setShortcut(tr("s"));
Chris@265 2052 m_playSelectionAction->setStatusTip(tr("Constrain playback to the selected regions"));
Chris@69 2053 connect(m_viewManager, SIGNAL(playSelectionModeChanged(bool)),
Chris@265 2054 m_playSelectionAction, SLOT(setChecked(bool)));
Chris@265 2055 connect(m_playSelectionAction, SIGNAL(triggered()), this, SLOT(playSelectionToggled()));
Chris@265 2056 connect(this, SIGNAL(canPlaySelection(bool)), m_playSelectionAction, SLOT(setEnabled(bool)));
Chris@265 2057
Chris@265 2058 m_playLoopAction = toolbar->addAction(il.load("playloop"),
Chris@265 2059 tr("Loop Playback"));
Chris@265 2060 m_playLoopAction->setCheckable(true);
Chris@265 2061 m_playLoopAction->setChecked(m_viewManager->getPlayLoopMode());
Chris@265 2062 m_playLoopAction->setShortcut(tr("l"));
Chris@265 2063 m_playLoopAction->setStatusTip(tr("Loop playback"));
Chris@69 2064 connect(m_viewManager, SIGNAL(playLoopModeChanged(bool)),
Chris@265 2065 m_playLoopAction, SLOT(setChecked(bool)));
Chris@265 2066 connect(m_playLoopAction, SIGNAL(triggered()), this, SLOT(playLoopToggled()));
Chris@265 2067 connect(this, SIGNAL(canPlay(bool)), m_playLoopAction, SLOT(setEnabled(bool)));
Chris@155 2068
Chris@207 2069 m_soloAction = toolbar->addAction(il.load("solo"),
Chris@323 2070 tr("Solo Current Pane"));
Chris@207 2071 m_soloAction->setCheckable(true);
Chris@207 2072 m_soloAction->setChecked(m_viewManager->getPlaySoloMode());
Chris@207 2073 m_prevSolo = m_viewManager->getPlaySoloMode();
Chris@207 2074 m_soloAction->setShortcut(tr("o"));
Chris@207 2075 m_soloAction->setStatusTip(tr("Solo the current pane during playback"));
Chris@180 2076 connect(m_viewManager, SIGNAL(playSoloModeChanged(bool)),
Chris@207 2077 m_soloAction, SLOT(setChecked(bool)));
Chris@207 2078 connect(m_soloAction, SIGNAL(triggered()), this, SLOT(playSoloToggled()));
Chris@207 2079 connect(this, SIGNAL(canChangeSolo(bool)), m_soloAction, SLOT(setEnabled(bool)));
Chris@180 2080
Chris@208 2081 QAction *alAction = 0;
Chris@208 2082 if (Document::canAlign()) {
Chris@208 2083 alAction = toolbar->addAction(il.load("align"),
Chris@208 2084 tr("Align File Timelines"));
Chris@208 2085 alAction->setCheckable(true);
Chris@208 2086 alAction->setChecked(m_viewManager->getAlignMode());
Chris@208 2087 alAction->setStatusTip(tr("Treat multiple audio files as versions of the same work, and align their timelines"));
Chris@208 2088 connect(m_viewManager, SIGNAL(alignModeChanged(bool)),
Chris@208 2089 alAction, SLOT(setChecked(bool)));
Chris@208 2090 connect(alAction, SIGNAL(triggered()), this, SLOT(alignToggled()));
Chris@208 2091 connect(this, SIGNAL(canAlign(bool)), alAction, SLOT(setEnabled(bool)));
Chris@208 2092 }
Chris@206 2093
Chris@265 2094 m_keyReference->registerShortcut(m_playAction);
Chris@1056 2095 m_keyReference->registerShortcut(m_recordAction);
Chris@265 2096 m_keyReference->registerShortcut(m_playSelectionAction);
Chris@265 2097 m_keyReference->registerShortcut(m_playLoopAction);
Chris@207 2098 m_keyReference->registerShortcut(m_soloAction);
Chris@208 2099 if (alAction) m_keyReference->registerShortcut(alAction);
Chris@162 2100 m_keyReference->registerShortcut(m_rwdAction);
Chris@162 2101 m_keyReference->registerShortcut(m_ffwdAction);
Chris@323 2102 m_keyReference->registerShortcut(m_rwdSimilarAction);
Chris@323 2103 m_keyReference->registerShortcut(m_ffwdSimilarAction);
Chris@265 2104 m_keyReference->registerShortcut(m_rwdStartAction);
Chris@265 2105 m_keyReference->registerShortcut(m_ffwdEndAction);
Chris@265 2106
Chris@265 2107 menu->addAction(m_playAction);
Chris@1056 2108 menu->addAction(m_recordAction);
Chris@265 2109 menu->addAction(m_playSelectionAction);
Chris@265 2110 menu->addAction(m_playLoopAction);
Chris@207 2111 menu->addAction(m_soloAction);
Chris@208 2112 if (alAction) menu->addAction(alAction);
Chris@155 2113 menu->addSeparator();
Chris@155 2114 menu->addAction(m_rwdAction);
Chris@155 2115 menu->addAction(m_ffwdAction);
Chris@155 2116 menu->addSeparator();
Chris@323 2117 menu->addAction(m_rwdSimilarAction);
Chris@323 2118 menu->addAction(m_ffwdSimilarAction);
Chris@323 2119 menu->addSeparator();
Chris@265 2120 menu->addAction(m_rwdStartAction);
Chris@265 2121 menu->addAction(m_ffwdEndAction);
Chris@155 2122 menu->addSeparator();
Chris@1055 2123 menu->addAction(m_recordAction);
Chris@1055 2124 menu->addSeparator();
Chris@155 2125
Chris@265 2126 m_rightButtonPlaybackMenu->addAction(m_playAction);
Chris@1056 2127 m_rightButtonPlaybackMenu->addAction(m_recordAction);
Chris@265 2128 m_rightButtonPlaybackMenu->addAction(m_playSelectionAction);
Chris@265 2129 m_rightButtonPlaybackMenu->addAction(m_playLoopAction);
Chris@207 2130 m_rightButtonPlaybackMenu->addAction(m_soloAction);
Chris@208 2131 if (alAction) m_rightButtonPlaybackMenu->addAction(alAction);
Chris@155 2132 m_rightButtonPlaybackMenu->addSeparator();
Chris@155 2133 m_rightButtonPlaybackMenu->addAction(m_rwdAction);
Chris@155 2134 m_rightButtonPlaybackMenu->addAction(m_ffwdAction);
Chris@155 2135 m_rightButtonPlaybackMenu->addSeparator();
Chris@265 2136 m_rightButtonPlaybackMenu->addAction(m_rwdStartAction);
Chris@265 2137 m_rightButtonPlaybackMenu->addAction(m_ffwdEndAction);
Chris@155 2138 m_rightButtonPlaybackMenu->addSeparator();
Chris@1055 2139 m_rightButtonPlaybackMenu->addAction(m_recordAction);
Chris@1055 2140 m_rightButtonPlaybackMenu->addSeparator();
Chris@155 2141
Chris@155 2142 QAction *fastAction = menu->addAction(tr("Speed Up"));
Chris@155 2143 fastAction->setShortcut(tr("Ctrl+PgUp"));
Chris@163 2144 fastAction->setStatusTip(tr("Time-stretch playback to speed it up without changing pitch"));
Chris@155 2145 connect(fastAction, SIGNAL(triggered()), this, SLOT(speedUpPlayback()));
Chris@155 2146 connect(this, SIGNAL(canSpeedUpPlayback(bool)), fastAction, SLOT(setEnabled(bool)));
Chris@634 2147
Chris@155 2148 QAction *slowAction = menu->addAction(tr("Slow Down"));
Chris@155 2149 slowAction->setShortcut(tr("Ctrl+PgDown"));
Chris@163 2150 slowAction->setStatusTip(tr("Time-stretch playback to slow it down without changing pitch"));
Chris@155 2151 connect(slowAction, SIGNAL(triggered()), this, SLOT(slowDownPlayback()));
Chris@155 2152 connect(this, SIGNAL(canSlowDownPlayback(bool)), slowAction, SLOT(setEnabled(bool)));
Chris@155 2153
Chris@155 2154 QAction *normalAction = menu->addAction(tr("Restore Normal Speed"));
Chris@155 2155 normalAction->setShortcut(tr("Ctrl+Home"));
Chris@163 2156 normalAction->setStatusTip(tr("Restore non-time-stretched playback"));
Chris@155 2157 connect(normalAction, SIGNAL(triggered()), this, SLOT(restoreNormalPlayback()));
Chris@155 2158 connect(this, SIGNAL(canChangePlaybackSpeed(bool)), normalAction, SLOT(setEnabled(bool)));
Chris@155 2159
Chris@162 2160 m_keyReference->registerShortcut(fastAction);
Chris@162 2161 m_keyReference->registerShortcut(slowAction);
Chris@162 2162 m_keyReference->registerShortcut(normalAction);
Chris@162 2163
Chris@155 2164 m_rightButtonPlaybackMenu->addAction(fastAction);
Chris@155 2165 m_rightButtonPlaybackMenu->addAction(slowAction);
Chris@155 2166 m_rightButtonPlaybackMenu->addAction(normalAction);
Chris@0 2167
Chris@0 2168 toolbar = addToolBar(tr("Edit Toolbar"));
Chris@0 2169 CommandHistory::getInstance()->registerToolbar(toolbar);
Chris@0 2170
Chris@0 2171 toolbar = addToolBar(tr("Tools Toolbar"));
Chris@0 2172 QActionGroup *group = new QActionGroup(this);
Chris@0 2173
Chris@705 2174 m_keyReference->setCategory(tr("Tool Selection"));
Chris@168 2175 QAction *action = toolbar->addAction(il.load("navigate"),
Chris@155 2176 tr("Navigate"));
Chris@0 2177 action->setCheckable(true);
Chris@0 2178 action->setChecked(true);
Chris@0 2179 action->setShortcut(tr("1"));
Chris@90 2180 action->setStatusTip(tr("Navigate"));
Chris@0 2181 connect(action, SIGNAL(triggered()), this, SLOT(toolNavigateSelected()));
Chris@596 2182 connect(this, SIGNAL(replacedDocument()), action, SLOT(trigger()));
Chris@0 2183 group->addAction(action);
Chris@162 2184 m_keyReference->registerShortcut(action);
Chris@0 2185 m_toolActions[ViewManager::NavigateMode] = action;
Chris@705 2186
Chris@705 2187 m_keyReference->setCategory
Chris@705 2188 (tr("Navigate Tool Mouse Actions"));
Chris@705 2189 m_keyReference->registerShortcut
Chris@705 2190 (tr("Navigate"), tr("Left"),
Chris@705 2191 tr("Click left button and drag to move around"));
Chris@705 2192 m_keyReference->registerShortcut
Chris@705 2193 (tr("Zoom to Area"), tr("Shift+Left"),
Chris@705 2194 tr("Shift-click left button and drag to zoom to a rectangular area"));
Chris@705 2195 m_keyReference->registerShortcut
Chris@705 2196 (tr("Relocate"), tr("Double-Click Left"),
Chris@705 2197 tr("Double-click left button to jump to clicked location"));
Chris@705 2198 m_keyReference->registerShortcut
Chris@705 2199 (tr("Edit"), tr("Double-Click Left"),
Chris@705 2200 tr("Double-click left button on an item to edit it"));
Chris@705 2201
Chris@705 2202 m_keyReference->setCategory(tr("Tool Selection"));
Chris@168 2203 action = toolbar->addAction(il.load("select"),
Chris@634 2204 tr("Select"));
Chris@0 2205 action->setCheckable(true);
Chris@0 2206 action->setShortcut(tr("2"));
Chris@90 2207 action->setStatusTip(tr("Select ranges"));
Chris@0 2208 connect(action, SIGNAL(triggered()), this, SLOT(toolSelectSelected()));
Chris@0 2209 group->addAction(action);
Chris@162 2210 m_keyReference->registerShortcut(action);
Chris@0 2211 m_toolActions[ViewManager::SelectMode] = action;
Chris@705 2212
Chris@705 2213 m_keyReference->setCategory
Chris@705 2214 (tr("Select Tool Mouse Actions"));
Chris@705 2215 m_keyReference->registerShortcut
Chris@705 2216 (tr("Select"), tr("Left"),
Chris@705 2217 tr("Click left button and drag to select region; drag region edge to resize"));
Chris@705 2218 #ifdef Q_OS_MAC
Chris@705 2219 m_keyReference->registerShortcut
Chris@705 2220 (tr("Multi Select"), tr("Ctrl+Left"),
Chris@705 2221 tr("Cmd-click left button and drag to select an additional region"));
Chris@705 2222 #else
Chris@705 2223 m_keyReference->registerShortcut
Chris@705 2224 (tr("Multi Select"), tr("Ctrl+Left"),
Chris@705 2225 tr("Ctrl-click left button and drag to select an additional region"));
Chris@705 2226 #endif
Chris@705 2227 m_keyReference->registerShortcut
Chris@705 2228 (tr("Fine Select"), tr("Shift+Left"),
Chris@705 2229 tr("Shift-click left button and drag to select without snapping to items or grid"));
Chris@705 2230
Chris@705 2231 m_keyReference->setCategory(tr("Tool Selection"));
Chris@168 2232 action = toolbar->addAction(il.load("move"),
Chris@634 2233 tr("Edit"));
Chris@0 2234 action->setCheckable(true);
Chris@0 2235 action->setShortcut(tr("3"));
Chris@90 2236 action->setStatusTip(tr("Edit items in layer"));
Chris@0 2237 connect(action, SIGNAL(triggered()), this, SLOT(toolEditSelected()));
Chris@0 2238 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@0 2239 group->addAction(action);
Chris@162 2240 m_keyReference->registerShortcut(action);
Chris@0 2241 m_toolActions[ViewManager::EditMode] = action;
Chris@705 2242
Chris@705 2243 m_keyReference->setCategory
Chris@705 2244 (tr("Edit Tool Mouse Actions"));
Chris@705 2245 m_keyReference->registerShortcut
Chris@705 2246 (tr("Move"), tr("Left"),
Chris@705 2247 tr("Click left button on an item or selected region and drag to move"));
Chris@705 2248 m_keyReference->registerShortcut
Chris@705 2249 (tr("Edit"), tr("Double-Click Left"),
Chris@705 2250 tr("Double-click left button on an item to edit it"));
Chris@705 2251
Chris@705 2252 m_keyReference->setCategory(tr("Tool Selection"));
Chris@168 2253 action = toolbar->addAction(il.load("draw"),
Chris@634 2254 tr("Draw"));
Chris@0 2255 action->setCheckable(true);
Chris@0 2256 action->setShortcut(tr("4"));
Chris@90 2257 action->setStatusTip(tr("Draw new items in layer"));
Chris@0 2258 connect(action, SIGNAL(triggered()), this, SLOT(toolDrawSelected()));
Chris@0 2259 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@0 2260 group->addAction(action);
Chris@162 2261 m_keyReference->registerShortcut(action);
Chris@0 2262 m_toolActions[ViewManager::DrawMode] = action;
Chris@0 2263
Chris@705 2264 m_keyReference->setCategory
Chris@705 2265 (tr("Draw Tool Mouse Actions"));
Chris@705 2266 m_keyReference->registerShortcut
Chris@705 2267 (tr("Draw"), tr("Left"),
Chris@705 2268 tr("Click left button and drag to create new item"));
Chris@705 2269
Chris@705 2270 m_keyReference->setCategory(tr("Tool Selection"));
Chris@217 2271 action = toolbar->addAction(il.load("erase"),
Chris@634 2272 tr("Erase"));
Chris@217 2273 action->setCheckable(true);
Chris@217 2274 action->setShortcut(tr("5"));
Chris@217 2275 action->setStatusTip(tr("Erase items from layer"));
Chris@217 2276 connect(action, SIGNAL(triggered()), this, SLOT(toolEraseSelected()));
Chris@217 2277 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@217 2278 group->addAction(action);
Chris@217 2279 m_keyReference->registerShortcut(action);
Chris@217 2280 m_toolActions[ViewManager::EraseMode] = action;
Chris@217 2281
Chris@705 2282 m_keyReference->setCategory
Chris@705 2283 (tr("Erase Tool Mouse Actions"));
Chris@705 2284 m_keyReference->registerShortcut
Chris@705 2285 (tr("Erase"), tr("Left"),
Chris@705 2286 tr("Click left button on an item to remove it from the layer"));
Chris@705 2287
Chris@705 2288 m_keyReference->setCategory(tr("Tool Selection"));
Chris@265 2289 action = toolbar->addAction(il.load("measure"), tr("Measure"));
Chris@151 2290 action->setCheckable(true);
Chris@217 2291 action->setShortcut(tr("6"));
Chris@151 2292 action->setStatusTip(tr("Make measurements in layer"));
Chris@151 2293 connect(action, SIGNAL(triggered()), this, SLOT(toolMeasureSelected()));
Chris@169 2294 connect(this, SIGNAL(canMeasureLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@151 2295 group->addAction(action);
Chris@162 2296 m_keyReference->registerShortcut(action);
Chris@151 2297 m_toolActions[ViewManager::MeasureMode] = action;
Chris@151 2298
Chris@705 2299 m_keyReference->setCategory
Chris@705 2300 (tr("Measure Tool Mouse Actions"));
Chris@705 2301 m_keyReference->registerShortcut
Chris@705 2302 (tr("Measure Area"), tr("Left"),
Chris@705 2303 tr("Click left button and drag to measure a rectangular area"));
Chris@705 2304 m_keyReference->registerShortcut
Chris@705 2305 (tr("Measure Item"), tr("Double-Click Left"),
Chris@705 2306 tr("Click left button and drag to measure extents of an item or shape"));
Chris@705 2307 m_keyReference->registerShortcut
Chris@705 2308 (tr("Zoom to Area"), tr("Shift+Left"),
Chris@705 2309 tr("Shift-click left button and drag to zoom to a rectangular area"));
Chris@705 2310
Chris@0 2311 toolNavigateSelected();
Chris@163 2312
Chris@163 2313 Pane::registerShortcuts(*m_keyReference);
Chris@0 2314 }
Chris@0 2315
Chris@0 2316 void
Chris@265 2317 MainWindow::connectLayerEditDialog(ModelDataTableDialog *dialog)
Chris@265 2318 {
Chris@265 2319 MainWindowBase::connectLayerEditDialog(dialog);
Chris@265 2320 QToolBar *toolbar = dialog->getPlayToolbar();
Chris@265 2321 if (toolbar) {
Chris@265 2322 toolbar->addAction(m_rwdStartAction);
Chris@265 2323 toolbar->addAction(m_rwdAction);
Chris@265 2324 toolbar->addAction(m_playAction);
Chris@265 2325 toolbar->addAction(m_ffwdAction);
Chris@265 2326 toolbar->addAction(m_ffwdEndAction);
Chris@265 2327 }
Chris@265 2328 }
Chris@265 2329
Chris@265 2330 void
Chris@0 2331 MainWindow::updateMenuStates()
Chris@0 2332 {
Chris@200 2333 MainWindowBase::updateMenuStates();
Chris@200 2334
Chris@117 2335 Pane *currentPane = 0;
Chris@117 2336 Layer *currentLayer = 0;
Chris@117 2337
Chris@117 2338 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
Chris@117 2339 if (currentPane) currentLayer = currentPane->getSelectedLayer();
Chris@117 2340
Chris@0 2341 bool haveCurrentPane =
Chris@117 2342 (currentPane != 0);
Chris@0 2343 bool haveCurrentLayer =
Chris@117 2344 (haveCurrentPane &&
Chris@117 2345 (currentLayer != 0));
Chris@206 2346 bool havePlayTarget =
Chris@1055 2347 (m_playTarget != 0 || m_audioIO != 0);
Chris@674 2348 bool haveSelection =
Chris@674 2349 (m_viewManager &&
Chris@674 2350 !m_viewManager->getSelections().empty());
Chris@0 2351 bool haveCurrentEditableLayer =
Chris@634 2352 (haveCurrentLayer &&
Chris@634 2353 currentLayer->isLayerEditable());
Chris@634 2354 bool haveCurrentTimeInstantsLayer =
Chris@634 2355 (haveCurrentLayer &&
Chris@634 2356 dynamic_cast<TimeInstantLayer *>(currentLayer));
Chris@634 2357 bool haveCurrentTimeValueLayer =
Chris@634 2358 (haveCurrentLayer &&
Chris@634 2359 dynamic_cast<TimeValueLayer *>(currentLayer));
Chris@634 2360
Chris@314 2361 bool alignMode = m_viewManager && m_viewManager->getAlignMode();
Chris@314 2362 emit canChangeSolo(havePlayTarget && !alignMode);
Chris@207 2363 emit canAlign(havePlayTarget && m_document && m_document->canAlign());
Chris@206 2364
Chris@200 2365 emit canChangePlaybackSpeed(true);
Chris@200 2366 int v = m_playSpeed->value();
Chris@200 2367 emit canSpeedUpPlayback(v < m_playSpeed->maximum());
Chris@200 2368 emit canSlowDownPlayback(v > m_playSpeed->minimum());
Chris@155 2369
Chris@634 2370 if (m_viewManager &&
Chris@164 2371 (m_viewManager->getToolMode() == ViewManager::MeasureMode)) {
Chris@164 2372 emit canDeleteSelection(haveCurrentLayer);
Chris@164 2373 m_deleteSelectedAction->setText(tr("&Delete Current Measurement"));
Chris@164 2374 m_deleteSelectedAction->setStatusTip(tr("Delete the measurement currently under the mouse pointer"));
Chris@164 2375 } else {
Chris@164 2376 emit canDeleteSelection(haveSelection && haveCurrentEditableLayer);
Chris@164 2377 m_deleteSelectedAction->setText(tr("&Delete Selected Items"));
Chris@164 2378 m_deleteSelectedAction->setStatusTip(tr("Delete items in current selection from the current layer"));
Chris@164 2379 }
Chris@164 2380
Chris@155 2381 if (m_ffwdAction && m_rwdAction) {
Chris@155 2382 if (haveCurrentTimeInstantsLayer) {
Chris@155 2383 m_ffwdAction->setText(tr("Fast Forward to Next Instant"));
Chris@155 2384 m_ffwdAction->setStatusTip(tr("Fast forward to the next time instant in the current layer"));
Chris@155 2385 m_rwdAction->setText(tr("Rewind to Previous Instant"));
Chris@155 2386 m_rwdAction->setStatusTip(tr("Rewind to the previous time instant in the current layer"));
Chris@155 2387 } else if (haveCurrentTimeValueLayer) {
Chris@155 2388 m_ffwdAction->setText(tr("Fast Forward to Next Point"));
Chris@155 2389 m_ffwdAction->setStatusTip(tr("Fast forward to the next point in the current layer"));
Chris@155 2390 m_rwdAction->setText(tr("Rewind to Previous Point"));
Chris@155 2391 m_rwdAction->setStatusTip(tr("Rewind to the previous point in the current layer"));
Chris@155 2392 } else {
Chris@155 2393 m_ffwdAction->setText(tr("Fast Forward"));
Chris@155 2394 m_ffwdAction->setStatusTip(tr("Fast forward"));
Chris@155 2395 m_rwdAction->setText(tr("Rewind"));
Chris@155 2396 m_rwdAction->setStatusTip(tr("Rewind"));
Chris@155 2397 }
Chris@155 2398 }
Chris@0 2399 }
Chris@0 2400
Chris@0 2401 void
Chris@0 2402 MainWindow::updateDescriptionLabel()
Chris@0 2403 {
Chris@0 2404 if (!getMainModel()) {
Chris@634 2405 m_descriptionLabel->setText(tr("No audio file loaded."));
Chris@634 2406 return;
Chris@0 2407 }
Chris@0 2408
Chris@0 2409 QString description;
Chris@0 2410
Chris@922 2411 sv_samplerate_t ssr = getMainModel()->getSampleRate();
Chris@922 2412 sv_samplerate_t tsr = ssr;
Chris@0 2413 if (m_playSource) tsr = m_playSource->getTargetSampleRate();
Chris@0 2414
Chris@0 2415 if (ssr != tsr) {
Chris@634 2416 description = tr("%1Hz (resampling to %2Hz)").arg(ssr).arg(tsr);
Chris@0 2417 } else {
Chris@634 2418 description = QString("%1Hz").arg(ssr);
Chris@0 2419 }
Chris@0 2420
Chris@0 2421 description = QString("%1 - %2")
Chris@634 2422 .arg(RealTime::frame2RealTime(getMainModel()->getEndFrame(), ssr)
Chris@634 2423 .toText(false).c_str())
Chris@634 2424 .arg(description);
Chris@0 2425
Chris@0 2426 m_descriptionLabel->setText(description);
Chris@0 2427 }
Chris@0 2428
Chris@0 2429 void
Chris@0 2430 MainWindow::documentModified()
Chris@0 2431 {
Chris@200 2432 //!!!
Chris@200 2433 MainWindowBase::documentModified();
Chris@0 2434 }
Chris@0 2435
Chris@0 2436 void
Chris@0 2437 MainWindow::documentRestored()
Chris@0 2438 {
Chris@200 2439 //!!!
Chris@200 2440 MainWindowBase::documentRestored();
Chris@0 2441 }
Chris@0 2442
Chris@0 2443 void
Chris@0 2444 MainWindow::toolNavigateSelected()
Chris@0 2445 {
Chris@0 2446 m_viewManager->setToolMode(ViewManager::NavigateMode);
Chris@0 2447 }
Chris@0 2448
Chris@0 2449 void
Chris@0 2450 MainWindow::toolSelectSelected()
Chris@0 2451 {
Chris@0 2452 m_viewManager->setToolMode(ViewManager::SelectMode);
Chris@0 2453 }
Chris@0 2454
Chris@0 2455 void
Chris@0 2456 MainWindow::toolEditSelected()
Chris@0 2457 {
Chris@0 2458 m_viewManager->setToolMode(ViewManager::EditMode);
Chris@0 2459 }
Chris@0 2460
Chris@0 2461 void
Chris@0 2462 MainWindow::toolDrawSelected()
Chris@0 2463 {
Chris@0 2464 m_viewManager->setToolMode(ViewManager::DrawMode);
Chris@0 2465 }
Chris@0 2466
Chris@151 2467 void
Chris@217 2468 MainWindow::toolEraseSelected()
Chris@217 2469 {
Chris@217 2470 m_viewManager->setToolMode(ViewManager::EraseMode);
Chris@217 2471 }
Chris@217 2472
Chris@217 2473 void
Chris@151 2474 MainWindow::toolMeasureSelected()
Chris@151 2475 {
Chris@151 2476 m_viewManager->setToolMode(ViewManager::MeasureMode);
Chris@151 2477 }
Chris@151 2478
Chris@0 2479 void
Chris@0 2480 MainWindow::importAudio()
Chris@0 2481 {
Chris@88 2482 QString path = getOpenFileName(FileFinder::AudioFile);
Chris@0 2483
Chris@0 2484 if (path != "") {
Chris@634 2485 if (openAudio(path, ReplaceSession) == FileOpenFailed) {
Chris@247 2486 emit hideSplash();
Chris@634 2487 QMessageBox::critical(this, tr("Failed to open file"),
Chris@634 2488 tr("<b>File open failed</b><p>Audio file \"%1\" could not be opened").arg(path));
Chris@634 2489 }
Chris@0 2490 }
Chris@0 2491 }
Chris@0 2492
Chris@0 2493 void
Chris@0 2494 MainWindow::importMoreAudio()
Chris@0 2495 {
Chris@88 2496 QString path = getOpenFileName(FileFinder::AudioFile);
Chris@0 2497
Chris@0 2498 if (path != "") {
Chris@634 2499 if (openAudio(path, CreateAdditionalModel) == FileOpenFailed) {
Chris@247 2500 emit hideSplash();
Chris@634 2501 QMessageBox::critical(this, tr("Failed to open file"),
Chris@634 2502 tr("<b>File open failed</b><p>Audio file \"%1\" could not be opened").arg(path));
Chris@634 2503 }
Chris@0 2504 }
Chris@634 2505
Chris@634 2506 files_paths[int(m_paneStack->getPaneCount())-1] = path;
Chris@0 2507 }
Chris@0 2508
Chris@0 2509 void
Chris@508 2510 MainWindow::replaceMainAudio()
Chris@508 2511 {
Chris@508 2512 QString path = getOpenFileName(FileFinder::AudioFile);
Chris@508 2513
Chris@508 2514 if (path != "") {
Chris@634 2515 if (openAudio(path, ReplaceMainModel) == FileOpenFailed) {
Chris@508 2516 emit hideSplash();
Chris@634 2517 QMessageBox::critical(this, tr("Failed to open file"),
Chris@634 2518 tr("<b>File open failed</b><p>Audio file \"%1\" could not be opened").arg(path));
Chris@634 2519 }
Chris@508 2520 }
Chris@508 2521 }
Chris@508 2522
Chris@508 2523 void
Chris@0 2524 MainWindow::exportAudio()
Chris@0 2525 {
Chris@631 2526 exportAudio(false);
Chris@631 2527 }
Chris@631 2528
Chris@631 2529 void
Chris@631 2530 MainWindow::exportAudioData()
Chris@631 2531 {
Chris@631 2532 exportAudio(true);
Chris@631 2533 }
Chris@631 2534
Chris@631 2535 void
Chris@631 2536 MainWindow::exportAudio(bool asData)
Chris@631 2537 {
Chris@0 2538 if (!getMainModel()) return;
Chris@0 2539
Chris@320 2540 RangeSummarisableTimeValueModel *model = getMainModel();
Chris@320 2541 std::set<RangeSummarisableTimeValueModel *> otherModels;
Chris@320 2542 RangeSummarisableTimeValueModel *current = model;
Chris@320 2543 if (m_paneStack) {
Chris@320 2544 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@320 2545 Pane *pane = m_paneStack->getPane(i);
Chris@320 2546 if (!pane) continue;
Chris@320 2547 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@320 2548 Layer *layer = pane->getLayer(j);
Chris@320 2549 if (!layer) continue;
Chris@432 2550 cerr << "layer = " << layer->objectName() << endl;
Chris@320 2551 Model *m = layer->getModel();
Chris@634 2552 RangeSummarisableTimeValueModel *wm =
Chris@320 2553 dynamic_cast<RangeSummarisableTimeValueModel *>(m);
Chris@320 2554 if (wm) {
Chris@432 2555 cerr << "found: " << wm->objectName() << endl;
Chris@320 2556 otherModels.insert(wm);
Chris@320 2557 if (pane == m_paneStack->getCurrentPane()) {
Chris@320 2558 current = wm;
Chris@320 2559 }
Chris@320 2560 }
Chris@320 2561 }
Chris@320 2562 }
Chris@320 2563 }
Chris@320 2564 if (!otherModels.empty()) {
Chris@320 2565 std::map<QString, RangeSummarisableTimeValueModel *> m;
Chris@320 2566 m[tr("1. %2").arg(model->objectName())] = model;
Chris@320 2567 int n = 2;
Chris@320 2568 int c = 0;
Chris@320 2569 for (std::set<RangeSummarisableTimeValueModel *>::const_iterator i
Chris@320 2570 = otherModels.begin();
Chris@320 2571 i != otherModels.end(); ++i) {
Chris@320 2572 if (*i == model) continue;
Chris@320 2573 m[tr("%1. %2").arg(n).arg((*i)->objectName())] = *i;
Chris@320 2574 ++n;
Chris@320 2575 if (*i == current) c = n-1;
Chris@320 2576 }
Chris@320 2577 QStringList items;
Chris@320 2578 for (std::map<QString, RangeSummarisableTimeValueModel *>
Chris@320 2579 ::const_iterator i = m.begin();
Chris@320 2580 i != m.end(); ++i) {
Chris@320 2581 items << i->first;
Chris@320 2582 }
Chris@325 2583 if (items.size() > 1) {
Chris@325 2584 bool ok = false;
Chris@325 2585 QString item = QInputDialog::getItem
Chris@325 2586 (this, tr("Select audio file to export"),
Chris@325 2587 tr("Which audio file do you want to export from?"),
Chris@325 2588 items, c, false, &ok);
Chris@325 2589 if (!ok || item.isEmpty()) return;
Chris@325 2590 if (m.find(item) == m.end()) {
Chris@665 2591 cerr << "WARNING: Model " << item
Chris@325 2592 << " not found in list!" << endl;
Chris@325 2593 } else {
Chris@325 2594 model = m[item];
Chris@325 2595 }
Chris@320 2596 }
Chris@320 2597 }
Chris@320 2598
Chris@631 2599 QString path;
Chris@631 2600 if (asData) {
Chris@631 2601 path = getSaveFileName(FileFinder::CSVFile);
Chris@631 2602 } else {
Chris@631 2603 path = getSaveFileName(FileFinder::AudioFile);
Chris@631 2604 }
Chris@0 2605 if (path == "") return;
Chris@0 2606
Chris@0 2607 bool ok = false;
Chris@0 2608 QString error;
Chris@0 2609
Chris@0 2610 MultiSelection ms = m_viewManager->getSelection();
Chris@0 2611 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@0 2612
Chris@0 2613 bool multiple = false;
Chris@0 2614
Chris@38 2615 MultiSelection *selectionToWrite = 0;
Chris@38 2616
Chris@38 2617 if (selections.size() == 1) {
Chris@0 2618
Chris@634 2619 QStringList items;
Chris@634 2620 items << tr("Export the selected region only")
Chris@634 2621 << tr("Export the whole audio file");
Chris@634 2622
Chris@634 2623 bool ok = false;
Chris@634 2624 QString item = ListInputDialog::getItem
Chris@634 2625 (this, tr("Select region to export"),
Chris@634 2626 tr("Which region from the original audio file do you want to export?"),
Chris@634 2627 items, 0, &ok);
Chris@634 2628
Chris@634 2629 if (!ok || item.isEmpty()) return;
Chris@634 2630
Chris@634 2631 if (item == items[0]) selectionToWrite = &ms;
Chris@38 2632
Chris@38 2633 } else if (selections.size() > 1) {
Chris@0 2634
Chris@631 2635 if (!asData) { // Multi-file export not supported for data
Chris@631 2636
Chris@631 2637 QStringList items;
Chris@631 2638 items << tr("Export the selected regions into a single file")
Chris@631 2639 << tr("Export the selected regions into separate files")
Chris@631 2640 << tr("Export the whole file");
Chris@631 2641
Chris@631 2642 QString item = ListInputDialog::getItem
Chris@631 2643 (this, tr("Select region to export"),
Chris@631 2644 tr("Multiple regions of the original audio file are selected.\nWhat do you want to export?"),
Chris@631 2645 items, 0, &ok);
Chris@0 2646
Chris@631 2647 if (!ok || item.isEmpty()) return;
Chris@631 2648
Chris@631 2649 if (item == items[0]) {
Chris@631 2650 selectionToWrite = &ms;
Chris@631 2651 } else if (item == items[1]) {
Chris@631 2652 multiple = true;
Chris@631 2653 }
Chris@631 2654 } else { // asData
Chris@38 2655 selectionToWrite = &ms;
Chris@631 2656 }
Chris@631 2657
Chris@631 2658 if (multiple) { // Can only happen when asData false
Chris@0 2659
Chris@634 2660 int n = 1;
Chris@634 2661 QString base = path;
Chris@634 2662 base.replace(".wav", "");
Chris@634 2663
Chris@634 2664 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@634 2665 i != selections.end(); ++i) {
Chris@634 2666
Chris@634 2667 MultiSelection subms;
Chris@634 2668 subms.setSelection(*i);
Chris@634 2669
Chris@634 2670 QString subpath = QString("%1.%2.wav").arg(base).arg(n);
Chris@634 2671 ++n;
Chris@634 2672
Chris@634 2673 if (QFileInfo(subpath).exists()) {
Chris@634 2674 error = tr("Fragment file %1 already exists, aborting").arg(subpath);
Chris@634 2675 break;
Chris@634 2676 }
Chris@634 2677
Chris@634 2678 WavFileWriter subwriter(subpath,
Chris@320 2679 model->getSampleRate(),
Chris@428 2680 model->getChannelCount(),
Chris@428 2681 WavFileWriter::WriteToTemporary);
Chris@320 2682 subwriter.writeModel(model, &subms);
Chris@634 2683 ok = subwriter.isOK();
Chris@634 2684
Chris@634 2685 if (!ok) {
Chris@634 2686 error = subwriter.getError();
Chris@634 2687 break;
Chris@634 2688 }
Chris@634 2689 }
Chris@634 2690 }
Chris@0 2691 }
Chris@0 2692
Chris@38 2693 if (!multiple) {
Chris@631 2694 if (asData) {
Chris@631 2695 CSVFileWriter writer(path, model,
Chris@631 2696 ((QFileInfo(path).suffix() == "csv") ?
Chris@631 2697 "," : "\t"));
Chris@631 2698 if (selectionToWrite) {
Chris@631 2699 writer.writeSelection(selectionToWrite);
Chris@631 2700 } else {
Chris@631 2701 writer.write();
Chris@631 2702 }
Chris@631 2703 ok = writer.isOK();
Chris@631 2704 error = writer.getError();
Chris@631 2705 } else {
Chris@631 2706 WavFileWriter writer(path,
Chris@631 2707 model->getSampleRate(),
Chris@631 2708 model->getChannelCount(),
Chris@631 2709 WavFileWriter::WriteToTemporary);
Chris@631 2710 writer.writeModel(model, selectionToWrite);
Chris@631 2711 ok = writer.isOK();
Chris@631 2712 error = writer.getError();
Chris@631 2713 }
Chris@0 2714 }
Chris@0 2715
Chris@0 2716 if (ok) {
Chris@310 2717 if (multiple) {
Chris@310 2718 emit activity(tr("Export multiple audio files"));
Chris@310 2719 } else {
Chris@310 2720 emit activity(tr("Export audio to \"%1\"").arg(path));
Chris@34 2721 m_recentFiles.addFile(path);
Chris@0 2722 }
Chris@0 2723 } else {
Chris@637 2724 QMessageBox::critical(this, tr("Failed to write file"), error);
Chris@0 2725 }
Chris@0 2726 }
Chris@0 2727
Chris@634 2728
Chris@634 2729
Chris@634 2730
Chris@0 2731 void
Chris@0 2732 MainWindow::importLayer()
Chris@0 2733 {
Chris@0 2734 Pane *pane = m_paneStack->getCurrentPane();
Chris@634 2735
Chris@0 2736 if (!pane) {
Chris@0 2737 // shouldn't happen, as the menu action should have been disabled
Chris@665 2738 cerr << "WARNING: MainWindow::importLayer: no current pane" << endl;
Chris@0 2739 return;
Chris@0 2740 }
Chris@0 2741
Chris@0 2742 if (!getMainModel()) {
Chris@0 2743 // shouldn't happen, as the menu action should have been disabled
Chris@665 2744 cerr << "WARNING: MainWindow::importLayer: No main model -- hence no default sample rate available" << endl;
Chris@0 2745 return;
Chris@0 2746 }
Chris@0 2747
Chris@88 2748 QString path = getOpenFileName(FileFinder::LayerFile);
Chris@0 2749
Chris@0 2750 if (path != "") {
Chris@0 2751
Chris@197 2752 FileOpenStatus status = openLayer(path);
Chris@634 2753
Chris@193 2754 if (status == FileOpenFailed) {
Chris@247 2755 emit hideSplash();
Chris@0 2756 QMessageBox::critical(this, tr("Failed to open file"),
Chris@193 2757 tr("<b>File open failed</b><p>Layer file %1 could not be opened.").arg(path));
Chris@0 2758 return;
Chris@193 2759 } else if (status == FileOpenWrongMode) {
Chris@247 2760 emit hideSplash();
Chris@193 2761 QMessageBox::critical(this, tr("Failed to open file"),
Chris@294 2762 tr("<b>Audio required</b><p>Unable to load layer data from \"%1\" without an audio file.<br>Please load at least one audio file before importing annotations.").arg(path));
Chris@0 2763 }
Chris@0 2764 }
Chris@0 2765 }
Chris@0 2766
Chris@0 2767 void
Chris@0 2768 MainWindow::exportLayer()
Chris@0 2769 {
Chris@0 2770 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 2771 if (!pane) return;
Chris@0 2772
Chris@0 2773 Layer *layer = pane->getSelectedLayer();
Chris@0 2774 if (!layer) return;
Chris@0 2775
Chris@0 2776 Model *model = layer->getModel();
Chris@0 2777 if (!model) return;
Chris@0 2778
Chris@185 2779 FileFinder::FileType type = FileFinder::LayerFileNoMidi;
Chris@185 2780
Chris@185 2781 if (dynamic_cast<NoteModel *>(model)) type = FileFinder::LayerFile;
Chris@185 2782
Chris@185 2783 QString path = getSaveFileName(type);
Chris@0 2784
Chris@0 2785 if (path == "") return;
Chris@0 2786
Chris@0 2787 if (QFileInfo(path).suffix() == "") path += ".svl";
Chris@0 2788
Chris@185 2789 QString suffix = QFileInfo(path).suffix().toLower();
Chris@185 2790
Chris@0 2791 QString error;
Chris@0 2792
Chris@185 2793 if (suffix == "xml" || suffix == "svl") {
Chris@0 2794
Chris@0 2795 QFile file(path);
Chris@0 2796 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
Chris@0 2797 error = tr("Failed to open file %1 for writing").arg(path);
Chris@0 2798 } else {
Chris@0 2799 QTextStream out(&file);
Chris@911 2800 out.setCodec(QTextCodec::codecForName("UTF-8"));
Chris@0 2801 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
Chris@0 2802 << "<!DOCTYPE sonic-visualiser>\n"
Chris@0 2803 << "<sv>\n"
Chris@0 2804 << " <data>\n";
Chris@0 2805
Chris@0 2806 model->toXml(out, " ");
Chris@0 2807
Chris@0 2808 out << " </data>\n"
Chris@0 2809 << " <display>\n";
Chris@0 2810
Chris@0 2811 layer->toXml(out, " ");
Chris@0 2812
Chris@0 2813 out << " </display>\n"
Chris@0 2814 << "</sv>\n";
Chris@0 2815 }
Chris@0 2816
Chris@185 2817 } else if (suffix == "mid" || suffix == "midi") {
Chris@185 2818
Chris@185 2819 NoteModel *nm = dynamic_cast<NoteModel *>(model);
Chris@185 2820
Chris@185 2821 if (!nm) {
Chris@185 2822 error = tr("Can't export non-note layers to MIDI");
Chris@185 2823 } else {
Chris@694 2824 MIDIFileWriter writer(path, nm, nm->getSampleRate());
Chris@185 2825 writer.write();
Chris@185 2826 if (!writer.isOK()) {
Chris@185 2827 error = writer.getError();
Chris@185 2828 }
Chris@185 2829 }
Chris@185 2830
Chris@291 2831 } else if (suffix == "ttl" || suffix == "n3") {
Chris@291 2832
Chris@522 2833 if (!RDFExporter::canExportModel(model)) {
Chris@522 2834 error = tr("Sorry, cannot export this layer type to RDF (supported types are: region, note, text, time instants, time values)");
Chris@522 2835 } else {
Chris@522 2836 RDFExporter exporter(path, model);
Chris@522 2837 exporter.write();
Chris@522 2838 if (!exporter.isOK()) {
Chris@522 2839 error = exporter.getError();
Chris@522 2840 }
Chris@291 2841 }
Chris@291 2842
Chris@0 2843 } else {
Chris@0 2844
Chris@0 2845 CSVFileWriter writer(path, model,
Chris@185 2846 ((suffix == "csv") ? "," : "\t"));
Chris@0 2847 writer.write();
Chris@0 2848
Chris@0 2849 if (!writer.isOK()) {
Chris@0 2850 error = writer.getError();
Chris@0 2851 }
Chris@0 2852 }
Chris@0 2853
Chris@0 2854 if (error != "") {
Chris@0 2855 QMessageBox::critical(this, tr("Failed to write file"), error);
Chris@0 2856 } else {
Chris@34 2857 m_recentFiles.addFile(path);
Chris@310 2858 emit activity(tr("Export layer to \"%1\"").arg(path));
Chris@0 2859 }
Chris@0 2860 }
Chris@0 2861
Chris@121 2862 void
Chris@121 2863 MainWindow::exportImage()
Chris@121 2864 {
Chris@121 2865 Pane *pane = m_paneStack->getCurrentPane();
Chris@121 2866 if (!pane) return;
Chris@634 2867
Chris@121 2868 QString path = getSaveFileName(FileFinder::ImageFile);
Chris@121 2869
Chris@121 2870 if (path == "") return;
Chris@121 2871
Chris@121 2872 if (QFileInfo(path).suffix() == "") path += ".png";
Chris@121 2873
Chris@123 2874 bool haveSelection = m_viewManager && !m_viewManager->getSelections().empty();
Chris@123 2875
Chris@123 2876 QSize total, visible, selected;
Chris@123 2877 total = pane->getImageSize();
Chris@123 2878 visible = pane->getImageSize(pane->getFirstVisibleFrame(),
Chris@123 2879 pane->getLastVisibleFrame());
Chris@123 2880
Chris@922 2881 sv_frame_t sf0 = 0, sf1 = 0;
Chris@674 2882
Chris@123 2883 if (haveSelection) {
Chris@123 2884 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@123 2885 sf0 = selections.begin()->getStartFrame();
Chris@123 2886 MultiSelection::SelectionList::iterator e = selections.end();
Chris@123 2887 --e;
Chris@123 2888 sf1 = e->getEndFrame();
Chris@123 2889 selected = pane->getImageSize(sf0, sf1);
Chris@123 2890 }
Chris@123 2891
Chris@123 2892 QStringList items;
Chris@125 2893 items << tr("Export the whole pane (%1x%2 pixels)")
Chris@123 2894 .arg(total.width()).arg(total.height());
Chris@123 2895 items << tr("Export the visible area only (%1x%2 pixels)")
Chris@123 2896 .arg(visible.width()).arg(visible.height());
Chris@123 2897 if (haveSelection) {
Chris@123 2898 items << tr("Export the selection extent (%1x%2 pixels)")
Chris@123 2899 .arg(selected.width()).arg(selected.height());
Chris@124 2900 } else {
Chris@124 2901 items << tr("Export the selection extent");
Chris@123 2902 }
Chris@123 2903
Chris@123 2904 QSettings settings;
Chris@123 2905 settings.beginGroup("MainWindow");
Chris@123 2906 int deflt = settings.value("lastimageexportregion", 0).toInt();
Chris@123 2907 if (deflt == 2 && !haveSelection) deflt = 1;
Chris@124 2908 if (deflt == 0 && total.width() > 32767) deflt = 1;
Chris@124 2909
Chris@124 2910 ListInputDialog *lid = new ListInputDialog
Chris@123 2911 (this, tr("Select region to export"),
Chris@123 2912 tr("Which region of the current pane do you want to export as an image?"),
Chris@124 2913 items, deflt);
Chris@124 2914
Chris@124 2915 if (!haveSelection) {
Chris@124 2916 lid->setItemAvailability(2, false);
Chris@124 2917 }
Chris@124 2918 if (total.width() > 32767) { // appears to be the limit of a QImage
Chris@124 2919 lid->setItemAvailability(0, false);
Chris@124 2920 lid->setFootnote(tr("Note: the whole pane is too wide to be exported as a single image."));
Chris@124 2921 }
Chris@124 2922
Chris@124 2923 bool ok = lid->exec();
Chris@124 2924 QString item = lid->getCurrentString();
Chris@124 2925 delete lid;
Chris@634 2926
Chris@123 2927 if (!ok || item.isEmpty()) return;
Chris@123 2928
Chris@123 2929 settings.setValue("lastimageexportregion", deflt);
Chris@123 2930
Chris@123 2931 QImage *image = 0;
Chris@123 2932
Chris@123 2933 if (item == items[0]) {
Chris@123 2934 image = pane->toNewImage();
Chris@123 2935 } else if (item == items[1]) {
Chris@123 2936 image = pane->toNewImage(pane->getFirstVisibleFrame(),
Chris@123 2937 pane->getLastVisibleFrame());
Chris@123 2938 } else if (haveSelection) {
Chris@123 2939 image = pane->toNewImage(sf0, sf1);
Chris@123 2940 }
Chris@123 2941
Chris@121 2942 if (!image) return;
Chris@121 2943
Chris@121 2944 if (!image->save(path, "PNG")) {
Chris@121 2945 QMessageBox::critical(this, tr("Failed to save image file"),
Chris@121 2946 tr("Failed to save image file %1").arg(path));
Chris@121 2947 }
Chris@634 2948
Chris@121 2949 delete image;
Chris@121 2950 }
Chris@121 2951
Chris@0 2952 void
Chris@1056 2953 MainWindow::browseRecordedAudio()
Chris@1056 2954 {
Chris@1056 2955 if (!m_recordTarget) return;
Chris@1056 2956
Chris@1056 2957 QString path = m_recordTarget->getRecordFolder();
Chris@1056 2958 if (path == "") return;
Chris@1056 2959
Chris@1056 2960 openLocalFolder(path);
Chris@1056 2961 }
Chris@1056 2962
Chris@1056 2963 void
Chris@0 2964 MainWindow::newSession()
Chris@0 2965 {
Chris@0 2966 if (!checkSaveModified()) return;
Chris@0 2967
Chris@0 2968 closeSession();
Chris@0 2969 createDocument();
Chris@0 2970
Chris@0 2971 Pane *pane = m_paneStack->addPane();
Chris@0 2972
Chris@90 2973 connect(pane, SIGNAL(contextHelpChanged(const QString &)),
Chris@116 2974 this, SLOT(contextHelpChanged(const QString &)));
Chris@90 2975
Chris@0 2976 if (!m_timeRulerLayer) {
Chris@634 2977 m_timeRulerLayer = m_document->createMainModelLayer
Chris@634 2978 (LayerFactory::TimeRuler);
Chris@0 2979 }
Chris@0 2980
Chris@0 2981 m_document->addLayerToView(pane, m_timeRulerLayer);
Chris@0 2982
Chris@0 2983 Layer *waveform = m_document->createMainModelLayer(LayerFactory::Waveform);
Chris@0 2984 m_document->addLayerToView(pane, waveform);
Chris@0 2985
Chris@65 2986 m_overview->registerView(pane);
Chris@0 2987
Chris@0 2988 CommandHistory::getInstance()->clear();
Chris@0 2989 CommandHistory::getInstance()->documentSaved();
Chris@0 2990 documentRestored();
Chris@0 2991 updateMenuStates();
Chris@0 2992 }
Chris@0 2993
Chris@0 2994 void
Chris@303 2995 MainWindow::documentReplaced()
Chris@303 2996 {
Chris@303 2997 if (m_document) {
Chris@303 2998 connect(m_document, SIGNAL(activity(QString)),
Chris@303 2999 m_activityLog, SLOT(activityHappened(QString)));
Chris@303 3000 }
Chris@303 3001 }
Chris@303 3002
Chris@303 3003 void
Chris@0 3004 MainWindow::closeSession()
Chris@0 3005 {
Chris@0 3006 if (!checkSaveModified()) return;
Chris@0 3007
Chris@0 3008 while (m_paneStack->getPaneCount() > 0) {
Chris@0 3009
Chris@634 3010 Pane *pane = m_paneStack->getPane(m_paneStack->getPaneCount() - 1);
Chris@634 3011
Chris@634 3012 while (pane->getLayerCount() > 0) {
Chris@634 3013 m_document->removeLayerFromView
Chris@634 3014 (pane, pane->getLayer(pane->getLayerCount() - 1));
Chris@0 3015 }
Chris@0 3016
Chris@634 3017 m_overview->unregisterView(pane);
Chris@634 3018 m_paneStack->deletePane(pane);
Chris@634 3019 }
Chris@634 3020
Chris@0 3021 while (m_paneStack->getHiddenPaneCount() > 0) {
Chris@0 3022
Chris@634 3023 Pane *pane = m_paneStack->getHiddenPane
Chris@634 3024 (m_paneStack->getHiddenPaneCount() - 1);
Chris@634 3025
Chris@634 3026 while (pane->getLayerCount() > 0) {
Chris@634 3027 m_document->removeLayerFromView
Chris@634 3028 (pane, pane->getLayer(pane->getLayerCount() - 1));
Chris@634 3029 }
Chris@634 3030
Chris@634 3031 m_overview->unregisterView(pane);
Chris@634 3032 m_paneStack->deletePane(pane);
Chris@0 3033 }
Chris@0 3034
Chris@504 3035 delete m_layerTreeDialog.data();
Chris@504 3036 delete m_preferencesDialog.data();
Chris@504 3037
Chris@504 3038 m_activityLog->hide();
Chris@891 3039 m_unitConverter->hide();
Chris@504 3040 m_keyReference->hide();
Chris@504 3041
Chris@0 3042 delete m_document;
Chris@0 3043 m_document = 0;
Chris@0 3044 m_viewManager->clearSelections();
Chris@0 3045 m_timeRulerLayer = 0; // document owned this
Chris@0 3046
Chris@0 3047 m_sessionFile = "";
Chris@518 3048 setWindowTitle(QApplication::applicationName());
Chris@0 3049
Chris@0 3050 CommandHistory::getInstance()->clear();
Chris@0 3051 CommandHistory::getInstance()->documentSaved();
Chris@0 3052 documentRestored();
Chris@0 3053 }
Chris@0 3054
Chris@0 3055 void
Chris@0 3056 MainWindow::openSomething()
Chris@0 3057 {
Chris@0 3058 QString orig = m_audioFile;
Chris@0 3059 if (orig == "") orig = ".";
Chris@0 3060 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 3061
Chris@88 3062 QString path = getOpenFileName(FileFinder::AnyFile);
Chris@0 3063
alo@1032 3064 if (path.isEmpty()) return;
Chris@0 3065
Chris@844 3066 FileOpenStatus status = openPath(path, ReplaceSession);
Chris@193 3067
Chris@193 3068 if (status == FileOpenFailed) {
Chris@247 3069 emit hideSplash();
Chris@193 3070 QMessageBox::critical(this, tr("Failed to open file"),
Chris@193 3071 tr("<b>File open failed</b><p>File \"%1\" could not be opened").arg(path));
Chris@193 3072 } else if (status == FileOpenWrongMode) {
Chris@247 3073 emit hideSplash();
Chris@193 3074 QMessageBox::critical(this, tr("Failed to open file"),
Chris@294 3075 tr("<b>Audio required</b><p>Unable to load layer data from \"%1\" without an audio file.<br>Please load at least one audio file before importing annotations.").arg(path));
Chris@0 3076 }
Chris@634 3077
alo@1032 3078 files_paths[0] = path;
alo@1032 3079 QTextStream out(stdout);
alo@1032 3080 out << path;
Chris@634 3081
Chris@0 3082 }
Chris@0 3083
Chris@0 3084 void
Chris@86 3085 MainWindow::openLocation()
Chris@86 3086 {
Chris@103 3087 QSettings settings;
Chris@103 3088 settings.beginGroup("MainWindow");
Chris@103 3089 QString lastLocation = settings.value("lastremote", "").toString();
Chris@103 3090
Chris@86 3091 bool ok = false;
Chris@86 3092 QString text = QInputDialog::getText
Chris@86 3093 (this, tr("Open Location"),
Chris@86 3094 tr("Please enter the URL of the location to open:"),
Chris@103 3095 QLineEdit::Normal, lastLocation, &ok);
Chris@103 3096
Chris@103 3097 if (!ok) return;
Chris@103 3098
Chris@103 3099 settings.setValue("lastremote", text);
Chris@103 3100
Chris@103 3101 if (text.isEmpty()) return;
Chris@86 3102
Chris@844 3103 FileOpenStatus status = openPath(text, AskUser);
Chris@193 3104
Chris@193 3105 if (status == FileOpenFailed) {
Chris@247 3106 emit hideSplash();
Chris@86 3107 QMessageBox::critical(this, tr("Failed to open location"),
Chris@193 3108 tr("<b>Open failed</b><p>URL \"%1\" could not be opened").arg(text));
Chris@193 3109 } else if (status == FileOpenWrongMode) {
Chris@247 3110 emit hideSplash();
Chris@193 3111 QMessageBox::critical(this, tr("Failed to open location"),
Chris@294 3112 tr("<b>Audio required</b><p>Unable to load layer data from \"%1\" without an audio file.<br>Please load at least one audio file before importing annotations.").arg(text));
Chris@86 3113 }
Chris@86 3114 }
Chris@86 3115
Chris@86 3116 void
Chris@0 3117 MainWindow::openRecentFile()
Chris@0 3118 {
Chris@0 3119 QObject *obj = sender();
Chris@0 3120 QAction *action = dynamic_cast<QAction *>(obj);
Chris@634 3121
Chris@0 3122 if (!action) {
Chris@665 3123 cerr << "WARNING: MainWindow::openRecentFile: sender is not an action"
Chris@665 3124 << endl;
Chris@0 3125 return;
Chris@0 3126 }
Chris@0 3127
Chris@0 3128 QString path = action->text();
Chris@0 3129 if (path == "") return;
Chris@0 3130
Chris@844 3131 FileOpenStatus status = openPath(path, ReplaceSession);
Chris@193 3132
Chris@193 3133 if (status == FileOpenFailed) {
Chris@247 3134 emit hideSplash();
Chris@193 3135 QMessageBox::critical(this, tr("Failed to open location"),
Chris@193 3136 tr("<b>Open failed</b><p>File or URL \"%1\" could not be opened").arg(path));
Chris@193 3137 } else if (status == FileOpenWrongMode) {
Chris@247 3138 emit hideSplash();
Chris@193 3139 QMessageBox::critical(this, tr("Failed to open location"),
Chris@294 3140 tr("<b>Audio required</b><p>Unable to load layer data from \"%1\" without an audio file.<br>Please load at least one audio file before importing annotations.").arg(path));
Chris@0 3141 }
Chris@0 3142 }
Chris@0 3143
Chris@0 3144 void
Chris@435 3145 MainWindow::applyTemplate()
Chris@435 3146 {
Chris@435 3147 QObject *s = sender();
Chris@435 3148 QAction *action = qobject_cast<QAction *>(s);
Chris@435 3149
Chris@435 3150 if (!action) {
Chris@665 3151 cerr << "WARNING: MainWindow::applyTemplate: sender is not an action"
Chris@665 3152 << endl;
Chris@435 3153 return;
Chris@435 3154 }
Chris@435 3155
Chris@435 3156 QString n = action->objectName();
Chris@435 3157 if (n == "") n = action->text();
Chris@435 3158
Chris@435 3159 if (n == "") {
Chris@665 3160 cerr << "WARNING: MainWindow::applyTemplate: sender has no name"
Chris@665 3161 << endl;
Chris@435 3162 return;
Chris@435 3163 }
Chris@435 3164
Chris@435 3165 QString mainModelLocation;
Chris@435 3166 WaveFileModel *mm = getMainModel();
Chris@435 3167 if (mm) mainModelLocation = mm->getLocation();
Chris@435 3168 if (mainModelLocation != "") {
Chris@435 3169 openAudio(mainModelLocation, ReplaceSession, n);
Chris@435 3170 } else {
Chris@435 3171 openSessionTemplate(n);
Chris@435 3172 }
Chris@435 3173 }
Chris@435 3174
Chris@435 3175 void
Chris@425 3176 MainWindow::saveSessionAsTemplate()
Chris@425 3177 {
Chris@762 3178 QDialog *d = new QDialog(this);
Chris@483 3179 d->setWindowTitle(tr("Enter template name"));
Chris@483 3180
Chris@483 3181 QGridLayout *layout = new QGridLayout;
Chris@483 3182 d->setLayout(layout);
Chris@483 3183
Chris@483 3184 layout->addWidget(new QLabel(tr("Please enter a name for the saved template:")),
Chris@483 3185 0, 0);
Chris@483 3186 QLineEdit *lineEdit = new QLineEdit;
Chris@483 3187 layout->addWidget(lineEdit, 1, 0);
Chris@483 3188 QCheckBox *makeDefault = new QCheckBox(tr("Set as default template for future audio files"));
Chris@483 3189 layout->addWidget(makeDefault, 2, 0);
Chris@634 3190
Chris@483 3191 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok |
Chris@483 3192 QDialogButtonBox::Cancel);
Chris@483 3193 layout->addWidget(bb, 3, 0);
Chris@483 3194 connect(bb, SIGNAL(accepted()), d, SLOT(accept()));
Chris@483 3195 connect(bb, SIGNAL(accepted()), d, SLOT(accept()));
Chris@483 3196 connect(bb, SIGNAL(rejected()), d, SLOT(reject()));
Chris@634 3197
Chris@483 3198 if (d->exec() == QDialog::Accepted) {
Chris@483 3199
Chris@483 3200 QString name = lineEdit->text();
Chris@483 3201 name.replace(QRegExp("[^\\w\\s\\.\"'-]"), "_");
Chris@483 3202
Chris@483 3203 ResourceFinder rf;
Chris@483 3204 QString dir = rf.getResourceSaveDir("templates");
Chris@483 3205 QString filename = QString("%1/%2.svt").arg(dir).arg(name);
Chris@483 3206 if (QFile(filename).exists()) {
Chris@483 3207 if (QMessageBox::warning(this,
Chris@483 3208 tr("Template file exists"),
Chris@483 3209 tr("<b>Template file exists</b><p>The template \"%1\" already exists.<br>Overwrite it?").arg(name),
Chris@483 3210 QMessageBox::Ok | QMessageBox::Cancel,
Chris@483 3211 QMessageBox::Cancel) != QMessageBox::Ok) {
Chris@483 3212 return;
Chris@483 3213 }
Chris@483 3214 }
Chris@483 3215
Chris@483 3216 if (saveSessionTemplate(filename)) {
Chris@483 3217 if (makeDefault->isChecked()) {
Chris@483 3218 setDefaultSessionTemplate(name);
Chris@483 3219 }
Chris@431 3220 }
Chris@431 3221 }
Chris@425 3222 }
Chris@425 3223
Chris@425 3224 void
Chris@425 3225 MainWindow::manageSavedTemplates()
Chris@425 3226 {
Chris@425 3227 ResourceFinder rf;
Chris@425 3228 QDesktopServices::openUrl("file:" + rf.getResourceSaveDir("templates"));
Chris@423 3229 }
Chris@423 3230
Chris@423 3231 void
Chris@200 3232 MainWindow::paneAdded(Pane *pane)
Chris@200 3233 {
Chris@200 3234 if (m_overview) m_overview->registerView(pane);
Chris@634 3235 }
Chris@200 3236
Chris@200 3237 void
Chris@200 3238 MainWindow::paneHidden(Pane *pane)
Chris@200 3239 {
Chris@634 3240 if (m_overview) m_overview->unregisterView(pane);
Chris@634 3241 }
Chris@200 3242
Chris@200 3243 void
Chris@200 3244 MainWindow::paneAboutToBeDeleted(Pane *pane)
Chris@200 3245 {
Chris@634 3246 if (m_overview) m_overview->unregisterView(pane);
Chris@634 3247 }
Chris@200 3248
Chris@200 3249 void
Chris@193 3250 MainWindow::paneDropAccepted(Pane *pane, QStringList uriList)
Chris@193 3251 {
Chris@193 3252 if (pane) m_paneStack->setCurrentPane(pane);
Chris@193 3253
Chris@193 3254 for (QStringList::iterator i = uriList.begin(); i != uriList.end(); ++i) {
Chris@193 3255
Chris@295 3256 FileOpenStatus status;
Chris@295 3257
Chris@295 3258 if (i == uriList.begin()) {
Chris@844 3259 status = openPath(*i, ReplaceCurrentPane);
Chris@295 3260 } else {
Chris@844 3261 status = openPath(*i, CreateAdditionalModel);
Chris@295 3262 }
Chris@193 3263
Chris@193 3264 if (status == FileOpenFailed) {
Chris@247 3265 emit hideSplash();
Chris@193 3266 QMessageBox::critical(this, tr("Failed to open dropped URL"),
Chris@193 3267 tr("<b>Open failed</b><p>Dropped URL \"%1\" could not be opened").arg(*i));
Chris@295 3268 break;
Chris@193 3269 } else if (status == FileOpenWrongMode) {
Chris@247 3270 emit hideSplash();
Chris@193 3271 QMessageBox::critical(this, tr("Failed to open dropped URL"),
Chris@294 3272 tr("<b>Audio required</b><p>Unable to load layer data from \"%1\" without an audio file.<br>Please load at least one audio file before importing annotations.").arg(*i));
Chris@295 3273 break;
Chris@295 3274 } else if (status == FileOpenCancelled) {
Chris@295 3275 break;
Chris@193 3276 }
Chris@193 3277 }
Chris@193 3278 }
Chris@193 3279
Chris@193 3280 void
Chris@193 3281 MainWindow::paneDropAccepted(Pane *pane, QString text)
Chris@193 3282 {
Chris@193 3283 if (pane) m_paneStack->setCurrentPane(pane);
Chris@193 3284
Chris@193 3285 QUrl testUrl(text);
Chris@634 3286 if (testUrl.scheme() == "file" ||
Chris@634 3287 testUrl.scheme() == "http" ||
Chris@193 3288 testUrl.scheme() == "ftp") {
Chris@193 3289 QStringList list;
Chris@193 3290 list.push_back(text);
Chris@193 3291 paneDropAccepted(pane, list);
Chris@193 3292 return;
Chris@193 3293 }
Chris@193 3294
Chris@193 3295 //!!! open as text -- but by importing as if a CSV, or just adding
Chris@193 3296 //to a text layer?
Chris@193 3297 }
Chris@193 3298
Chris@193 3299 void
Chris@0 3300 MainWindow::closeEvent(QCloseEvent *e)
Chris@0 3301 {
Chris@665 3302 // cerr << "MainWindow::closeEvent" << endl;
Chris@118 3303
Chris@136 3304 if (m_openingAudioFile) {
Chris@665 3305 // cerr << "Busy - ignoring close event" << endl;
Chris@136 3306 e->ignore();
Chris@136 3307 return;
Chris@136 3308 }
Chris@136 3309
Chris@70 3310 if (!m_abandoning && !checkSaveModified()) {
Chris@665 3311 // cerr << "Close refused by user - ignoring close event" << endl;
Chris@0 3312 e->ignore();
Chris@0 3313 return;
Chris@0 3314 }
Chris@0 3315
Chris@5 3316 QSettings settings;
Chris@5 3317 settings.beginGroup("MainWindow");
Chris@624 3318 settings.setValue("maximised", isMaximized());
Chris@624 3319 if (!isMaximized()) {
Chris@624 3320 settings.setValue("size", size());
Chris@624 3321 settings.setValue("position", pos());
Chris@624 3322 }
Chris@5 3323 settings.endGroup();
Chris@5 3324
Chris@163 3325 if (m_preferencesDialog &&
Chris@163 3326 m_preferencesDialog->isVisible()) {
Chris@164 3327 closeSession(); // otherwise we'll have to wait for prefs changes
Chris@163 3328 m_preferencesDialog->applicationClosing(false);
Chris@163 3329 }
Chris@163 3330
Chris@200 3331 closeSession();
Chris@200 3332
Chris@0 3333 e->accept();
Chris@489 3334
Chris@0 3335 return;
Chris@0 3336 }
Chris@0 3337
Chris@0 3338 bool
Chris@11 3339 MainWindow::commitData(bool mayAskUser)
Chris@11 3340 {
Chris@11 3341 if (mayAskUser) {
Chris@163 3342 bool rv = checkSaveModified();
Chris@163 3343 if (rv) {
Chris@163 3344 if (m_preferencesDialog &&
Chris@163 3345 m_preferencesDialog->isVisible()) {
Chris@163 3346 m_preferencesDialog->applicationClosing(false);
Chris@163 3347 }
Chris@163 3348 }
Chris@163 3349 return rv;
Chris@11 3350 } else {
Chris@163 3351 if (m_preferencesDialog &&
Chris@163 3352 m_preferencesDialog->isVisible()) {
Chris@163 3353 m_preferencesDialog->applicationClosing(true);
Chris@163 3354 }
Chris@11 3355 if (!m_documentModified) return true;
Chris@11 3356
Chris@11 3357 // If we can't check with the user first, then we can't save
Chris@11 3358 // to the original session file (even if we have it) -- have
Chris@11 3359 // to use a temporary file
Chris@11 3360
Chris@11 3361 QString svDirBase = ".sv1";
Chris@11 3362 QString svDir = QDir::home().filePath(svDirBase);
Chris@11 3363
Chris@11 3364 if (!QFileInfo(svDir).exists()) {
Chris@11 3365 if (!QDir::home().mkdir(svDirBase)) return false;
Chris@11 3366 } else {
Chris@11 3367 if (!QFileInfo(svDir).isDir()) return false;
Chris@11 3368 }
Chris@634 3369
Chris@11 3370 // This name doesn't have to be unguessable
Chris@93 3371 #ifndef _WIN32
Chris@11 3372 QString fname = QString("tmp-%1-%2.sv")
Chris@11 3373 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"))
Chris@11 3374 .arg(QProcess().pid());
Chris@93 3375 #else
Chris@93 3376 QString fname = QString("tmp-%1.sv")
Chris@93 3377 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"));
Chris@93 3378 #endif
Chris@11 3379 QString fpath = QDir(svDir).filePath(fname);
Chris@11 3380 if (saveSessionFile(fpath)) {
Chris@34 3381 m_recentFiles.addFile(fpath);
Chris@310 3382 emit activity(tr("Export image to \"%1\"").arg(fpath));
Chris@11 3383 return true;
Chris@11 3384 } else {
Chris@11 3385 return false;
Chris@11 3386 }
Chris@11 3387 }
Chris@11 3388 }
Chris@11 3389
Chris@11 3390 bool
Chris@0 3391 MainWindow::checkSaveModified()
Chris@0 3392 {
Chris@0 3393 // Called before some destructive operation (e.g. new session,
Chris@0 3394 // exit program). Return true if we can safely proceed, false to
Chris@0 3395 // cancel.
Chris@0 3396
Chris@0 3397 if (!m_documentModified) return true;
Chris@0 3398
Chris@247 3399 emit hideSplash();
Chris@247 3400
Chris@634 3401 int button =
Chris@634 3402 QMessageBox::warning(this,
Chris@634 3403 tr("Session modified"),
Chris@634 3404 tr("<b>Session modified</b><p>The current session has been modified.<br>Do you want to save it?"),
Chris@634 3405 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
Chris@165 3406 QMessageBox::Yes);
Chris@0 3407
Chris@0 3408 if (button == QMessageBox::Yes) {
Chris@634 3409 saveSession();
Chris@634 3410 if (m_documentModified) { // save failed -- don't proceed!
Chris@634 3411 return false;
Chris@634 3412 } else {
Chris@0 3413 return true; // saved, so it's safe to continue now
Chris@0 3414 }
Chris@0 3415 } else if (button == QMessageBox::No) {
Chris@634 3416 m_documentModified = false; // so we know to abandon it
Chris@634 3417 return true;
Chris@0 3418 }
Chris@0 3419
Chris@0 3420 // else cancel
Chris@0 3421 return false;
Chris@0 3422 }
Chris@0 3423
Chris@290 3424 bool
Chris@294 3425 MainWindow::shouldCreateNewSessionForRDFAudio(bool *cancel)
Chris@290 3426 {
Chris@294 3427 //!!! This is very similar to part of MainWindowBase::openAudio --
Chris@294 3428 //!!! make them a bit more uniform
Chris@294 3429
Chris@294 3430 QSettings settings;
Chris@294 3431 settings.beginGroup("MainWindow");
Chris@294 3432 bool prevNewSession = settings.value("newsessionforrdfaudio", true).toBool();
Chris@294 3433 settings.endGroup();
Chris@294 3434 bool newSession = true;
Chris@634 3435
Chris@294 3436 QStringList items;
Chris@294 3437 items << tr("Close the current session and create a new one")
Chris@294 3438 << tr("Add this data to the current session");
Chris@294 3439
Chris@294 3440 bool ok = false;
Chris@294 3441 QString item = ListInputDialog::getItem
Chris@294 3442 (this, tr("Select target for import"),
Chris@294 3443 tr("<b>Select a target for import</b><p>This RDF document refers to one or more audio files.<br>You already have an audio waveform loaded.<br>What would you like to do with the new data?"),
Chris@294 3444 items, prevNewSession ? 0 : 1, &ok);
Chris@634 3445
Chris@294 3446 if (!ok || item.isEmpty()) {
Chris@294 3447 *cancel = true;
Chris@290 3448 return false;
Chris@290 3449 }
Chris@634 3450
Chris@294 3451 newSession = (item == items[0]);
Chris@294 3452 settings.beginGroup("MainWindow");
Chris@294 3453 settings.setValue("newsessionforrdfaudio", newSession);
Chris@294 3454 settings.endGroup();
Chris@294 3455
Chris@294 3456 if (newSession) return true;
Chris@294 3457 else return false;
Chris@290 3458 }
Chris@290 3459
Chris@0 3460 void
Chris@0 3461 MainWindow::saveSession()
Chris@0 3462 {
Chris@0 3463 if (m_sessionFile != "") {
Chris@634 3464 if (!saveSessionFile(m_sessionFile)) {
Chris@634 3465 QMessageBox::critical(this, tr("Failed to save file"),
Chris@634 3466 tr("<b>Save failed</b><p>Session file \"%1\" could not be saved.").arg(m_sessionFile));
Chris@0 3467 } else {
Chris@634 3468 CommandHistory::getInstance()->documentSaved();
Chris@634 3469 documentRestored();
Chris@634 3470 }
Chris@634 3471 } else {
Chris@634 3472 saveSessionAs();
Chris@0 3473 }
Chris@0 3474 }
Chris@0 3475
Chris@0 3476 void
Chris@0 3477 MainWindow::saveSessionAs()
Chris@0 3478 {
Chris@0 3479 QString orig = m_audioFile;
Chris@0 3480 if (orig == "") orig = ".";
Chris@0 3481 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 3482
Chris@88 3483 QString path = getSaveFileName(FileFinder::SessionFile);
Chris@81 3484
Chris@81 3485 if (path == "") return;
Chris@0 3486
Chris@0 3487 if (!saveSessionFile(path)) {
Chris@634 3488 QMessageBox::critical(this, tr("Failed to save file"),
Chris@634 3489 tr("<b>Save failed</b><p>Session file \"%1\" could not be saved.").arg(path));
Chris@0 3490 } else {
Chris@902 3491 setWindowTitle(tr("%1: %2")
Chris@518 3492 .arg(QApplication::applicationName())
Chris@1150 3493 .arg(QFileInfo(path).fileName()));
Chris@634 3494 m_sessionFile = path;
Chris@634 3495 CommandHistory::getInstance()->documentSaved();
Chris@634 3496 documentRestored();
Chris@34 3497 m_recentFiles.addFile(path);
Chris@310 3498 emit activity(tr("Save session as \"%1\"").arg(path));
Chris@0 3499 }
Chris@0 3500 }
Chris@0 3501
Chris@90 3502 void
Chris@72 3503 MainWindow::preferenceChanged(PropertyContainer::PropertyName name)
Chris@72 3504 {
Chris@200 3505 MainWindowBase::preferenceChanged(name);
Chris@200 3506
Chris@200 3507 if (name == "Background Mode" && m_viewManager) {
Chris@180 3508 if (m_viewManager->getGlobalDarkBackground()) {
Chris@180 3509 m_panLayer->setBaseColour
Chris@180 3510 (ColourDatabase::getInstance()->getColourIndex(tr("Bright Green")));
Chris@180 3511 } else {
Chris@180 3512 m_panLayer->setBaseColour
Chris@180 3513 (ColourDatabase::getInstance()->getColourIndex(tr("Green")));
Chris@634 3514 }
Chris@634 3515 }
Chris@0 3516 }
Chris@0 3517
Chris@0 3518 void
Chris@239 3519 MainWindow::propertyStacksResized(int width)
Chris@239 3520 {
Chris@438 3521 // SVDEBUG << "MainWindow::propertyStacksResized(" << width << ")" << endl;
Chris@239 3522
Chris@239 3523 if (!m_playControlsSpacer) return;
Chris@239 3524
Chris@239 3525 int spacerWidth = width - m_playControlsWidth - 4;
Chris@634 3526
Chris@438 3527 // SVDEBUG << "resizing spacer from " << m_playControlsSpacer->width() << " to " << spacerWidth << endl;
Chris@239 3528
Chris@239 3529 m_playControlsSpacer->setFixedSize(QSize(spacerWidth, 2));
Chris@239 3530 }
Chris@239 3531
Chris@239 3532 void
Chris@0 3533 MainWindow::addPane()
Chris@0 3534 {
Chris@0 3535 QObject *s = sender();
Chris@0 3536 QAction *action = dynamic_cast<QAction *>(s);
Chris@634 3537
Chris@753 3538 cerr << "addPane: sender is " << s << ", action is " << action << ", name " << action->text() << endl;
Chris@674 3539
Chris@0 3540 if (!action) {
Chris@665 3541 cerr << "WARNING: MainWindow::addPane: sender is not an action"
Chris@665 3542 << endl;
Chris@0 3543 return;
Chris@0 3544 }
Chris@0 3545
Chris@0 3546 PaneActionMap::iterator i = m_paneActions.find(action);
Chris@0 3547
Chris@0 3548 if (i == m_paneActions.end()) {
Chris@665 3549 cerr << "WARNING: MainWindow::addPane: unknown action "
Chris@665 3550 << action->objectName() << endl;
Chris@753 3551 cerr << "known actions are:" << endl;
Chris@753 3552 for (PaneActionMap::const_iterator i = m_paneActions.begin();
Chris@753 3553 i != m_paneActions.end(); ++i) {
Chris@753 3554 cerr << i->first << ", name " << i->first->text() << endl;
Chris@753 3555 }
Chris@0 3556 return;
Chris@0 3557 }
Chris@0 3558
Chris@69 3559 addPane(i->second, action->text());
Chris@69 3560 }
Chris@69 3561
Chris@69 3562 void
Chris@232 3563 MainWindow::addPane(const LayerConfiguration &configuration, QString text)
Chris@69 3564 {
Chris@69 3565 CommandHistory::getInstance()->startCompoundOperation(text, true);
Chris@0 3566
Chris@0 3567 AddPaneCommand *command = new AddPaneCommand(this);
Chris@0 3568 CommandHistory::getInstance()->addCommand(command);
Chris@0 3569
Chris@0 3570 Pane *pane = command->getPane();
Chris@0 3571
Chris@69 3572 if (configuration.layer == LayerFactory::Spectrum) {
Chris@109 3573 pane->setPlaybackFollow(PlaybackScrollContinuous);
Chris@110 3574 pane->setFollowGlobalZoom(false);
Chris@112 3575 pane->setZoomLevel(512);
Chris@7 3576 }
Chris@7 3577
Chris@69 3578 if (configuration.layer != LayerFactory::TimeRuler &&
Chris@69 3579 configuration.layer != LayerFactory::Spectrum) {
Chris@8 3580
Chris@0 3581 if (!m_timeRulerLayer) {
Chris@665 3582 // cerr << "no time ruler layer, creating one" << endl;
Chris@0 3583 m_timeRulerLayer = m_document->createMainModelLayer
Chris@0 3584 (LayerFactory::TimeRuler);
Chris@0 3585 }
Chris@0 3586
Chris@438 3587 // SVDEBUG << "adding time ruler layer " << m_timeRulerLayer << endl;
Chris@0 3588
Chris@677 3589 m_document->addLayerToView(pane, m_timeRulerLayer);
Chris@0 3590 }
Chris@0 3591
Chris@69 3592 Layer *newLayer = m_document->createLayer(configuration.layer);
Chris@69 3593
Chris@69 3594 Model *suggestedModel = configuration.sourceModel;
Chris@66 3595 Model *model = 0;
Chris@66 3596
Chris@66 3597 if (suggestedModel) {
Chris@66 3598
Chris@66 3599 // check its validity
Chris@224 3600 std::vector<Model *> inputModels = m_document->getTransformInputModels();
Chris@66 3601 for (size_t j = 0; j < inputModels.size(); ++j) {
Chris@66 3602 if (inputModels[j] == suggestedModel) {
Chris@66 3603 model = suggestedModel;
Chris@66 3604 break;
Chris@66 3605 }
Chris@66 3606 }
Chris@66 3607
Chris@66 3608 if (!model) {
Chris@665 3609 cerr << "WARNING: Model " << (void *)suggestedModel
Chris@66 3610 << " appears in pane action map, but is not reported "
Chris@665 3611 << "by document as a valid transform source" << endl;
Chris@66 3612 }
Chris@66 3613 }
Chris@66 3614
Chris@346 3615 if (!model) {
Chris@346 3616 model = m_document->getMainModel();
Chris@346 3617 }
Chris@66 3618
Chris@66 3619 m_document->setModel(newLayer, model);
Chris@66 3620
Chris@69 3621 m_document->setChannel(newLayer, configuration.channel);
Chris@0 3622 m_document->addLayerToView(pane, newLayer);
Chris@0 3623
Chris@0 3624 m_paneStack->setCurrentPane(pane);
Chris@70 3625 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 3626
Chris@438 3627 // SVDEBUG << "MainWindow::addPane: global centre frame is "
Chris@433 3628 // << m_viewManager->getGlobalCentreFrame() << endl;
Chris@130 3629 // pane->setCentreFrame(m_viewManager->getGlobalCentreFrame());
Chris@73 3630
Chris@0 3631 CommandHistory::getInstance()->endCompoundOperation();
Chris@0 3632
Chris@0 3633 updateMenuStates();
Chris@0 3634 }
Chris@0 3635
Chris@0 3636 void
Chris@0 3637 MainWindow::addLayer()
Chris@0 3638 {
Chris@0 3639 QObject *s = sender();
Chris@0 3640 QAction *action = dynamic_cast<QAction *>(s);
Chris@634 3641
Chris@0 3642 if (!action) {
Chris@665 3643 cerr << "WARNING: MainWindow::addLayer: sender is not an action"
Chris@665 3644 << endl;
Chris@0 3645 return;
Chris@0 3646 }
Chris@0 3647
Chris@0 3648 Pane *pane = m_paneStack->getCurrentPane();
Chris@634 3649
Chris@0 3650 if (!pane) {
Chris@665 3651 cerr << "WARNING: MainWindow::addLayer: no current pane" << endl;
Chris@0 3652 return;
Chris@0 3653 }
Chris@0 3654
Chris@0 3655 ExistingLayerActionMap::iterator ei = m_existingLayerActions.find(action);
Chris@0 3656
Chris@0 3657 if (ei != m_existingLayerActions.end()) {
Chris@634 3658 Layer *newLayer = ei->second;
Chris@634 3659 m_document->addLayerToView(pane, newLayer);
Chris@634 3660 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@634 3661 return;
Chris@0 3662 }
Chris@0 3663
Chris@95 3664 ei = m_sliceActions.find(action);
Chris@95 3665
Chris@95 3666 if (ei != m_sliceActions.end()) {
Chris@95 3667 Layer *newLayer = m_document->createLayer(LayerFactory::Slice);
Chris@95 3668 // document->setModel(newLayer, ei->second->getModel());
Chris@95 3669 SliceableLayer *source = dynamic_cast<SliceableLayer *>(ei->second);
Chris@95 3670 SliceLayer *dest = dynamic_cast<SliceLayer *>(newLayer);
Chris@95 3671 if (source && dest) {
Chris@205 3672 //!!!???
Chris@95 3673 dest->setSliceableModel(source->getSliceableModel());
Chris@95 3674 connect(source, SIGNAL(sliceableModelReplaced(const Model *, const Model *)),
Chris@95 3675 dest, SLOT(sliceableModelReplaced(const Model *, const Model *)));
Chris@95 3676 connect(m_document, SIGNAL(modelAboutToBeDeleted(Model *)),
Chris@95 3677 dest, SLOT(modelAboutToBeDeleted(Model *)));
Chris@634 3678
Chris@95 3679 }
Chris@634 3680 m_document->addLayerToView(pane, newLayer);
Chris@634 3681 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@634 3682 return;
Chris@95 3683 }
Chris@95 3684
Chris@211 3685 TransformActionMap::iterator i = m_transformActions.find(action);
Chris@34 3686
Chris@34 3687 if (i == m_transformActions.end()) {
Chris@0 3688
Chris@0 3689 LayerActionMap::iterator i = m_layerActions.find(action);
Chris@0 3690
Chris@0 3691 if (i == m_layerActions.end()) {
Chris@665 3692 cerr << "WARNING: MainWindow::addLayer: unknown action "
Chris@665 3693 << action->objectName() << endl;
Chris@0 3694 return;
Chris@0 3695 }
Chris@0 3696
Chris@232 3697 LayerFactory::LayerType type = i->second.layer;
Chris@0 3698
Chris@0 3699 LayerFactory::LayerTypeSet emptyTypes =
Chris@0 3700 LayerFactory::getInstance()->getValidEmptyLayerTypes();
Chris@0 3701
Chris@499 3702 Layer *newLayer = 0;
Chris@0 3703
Chris@0 3704 if (emptyTypes.find(type) != emptyTypes.end()) {
Chris@0 3705
Chris@0 3706 newLayer = m_document->createEmptyLayer(type);
Chris@677 3707
Chris@217 3708 if (newLayer) {
Chris@217 3709 m_toolActions[ViewManager::DrawMode]->trigger();
Chris@217 3710 }
Chris@0 3711
Chris@677 3712 } else {
Chris@0 3713
Chris@346 3714 Model *model = i->second.sourceModel;
Chris@346 3715
Chris@415 3716 cerr << "model = "<< model << endl;
Chris@415 3717
Chris@346 3718 if (!model) {
Chris@346 3719 if (type == LayerFactory::TimeRuler) {
Chris@346 3720 newLayer = m_document->createMainModelLayer(type);
Chris@346 3721 } else {
Chris@346 3722 // if model is unspecified and this is not a
Chris@415 3723 // time-ruler layer, use any plausible model from
Chris@415 3724 // the current pane -- this is the case for
Chris@415 3725 // right-button menu layer additions
Chris@415 3726 Pane::ModelSet ms = pane->getModels();
Chris@415 3727 foreach (Model *m, ms) {
Chris@415 3728 RangeSummarisableTimeValueModel *r =
Chris@415 3729 dynamic_cast<RangeSummarisableTimeValueModel *>(m);
Chris@415 3730 if (r) model = m;
Chris@346 3731 }
Chris@346 3732 if (!model) model = getMainModel();
Chris@346 3733 }
Chris@346 3734 }
Chris@346 3735
Chris@346 3736 if (model) {
Chris@238 3737 newLayer = m_document->createLayer(type);
Chris@346 3738 if (m_document->isKnownModel(model)) {
Chris@238 3739 m_document->setChannel(newLayer, i->second.channel);
Chris@346 3740 m_document->setModel(newLayer, model);
Chris@238 3741 } else {
Chris@665 3742 cerr << "WARNING: MainWindow::addLayer: unknown model "
Chris@346 3743 << model
Chris@238 3744 << " (\""
Chris@838 3745 << model->objectName()
Chris@238 3746 << "\") in layer action map"
Chris@665 3747 << endl;
Chris@238 3748 }
Chris@232 3749 }
Chris@238 3750 }
Chris@0 3751
Chris@217 3752 if (newLayer) {
Chris@217 3753 m_document->addLayerToView(pane, newLayer);
Chris@217 3754 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@217 3755 }
Chris@0 3756
Chris@634 3757 return;
Chris@0 3758 }
Chris@0 3759
Chris@224 3760 //!!! want to do something like this, but it's not supported in
Chris@224 3761 //ModelTransformerFactory yet
Chris@224 3762 /*
Chris@0 3763 int channel = -1;
Chris@0 3764 // pick up the default channel from any existing layers on the same pane
Chris@0 3765 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@634 3766 int c = LayerFactory::getInstance()->getChannel(pane->getLayer(j));
Chris@634 3767 if (c != -1) {
Chris@634 3768 channel = c;
Chris@634 3769 break;
Chris@634 3770 }
Chris@0 3771 }
Chris@224 3772 */
Chris@0 3773
Chris@33 3774 // We always ask for configuration, even if the plugin isn't
Chris@33 3775 // supposed to be configurable, because we need to let the user
Chris@33 3776 // change the execution context (block size etc).
Chris@0 3777
Chris@224 3778 QString transformId = i->second;
Chris@274 3779
Chris@274 3780 addLayer(transformId);
Chris@274 3781 }
Chris@274 3782
Chris@274 3783 void
Chris@634 3784 MainWindow:: addLayer(QString transformId)
Chris@274 3785 {
Chris@274 3786 Pane *pane = m_paneStack->getCurrentPane();
Chris@274 3787 if (!pane) {
Chris@665 3788 cerr << "WARNING: MainWindow::addLayer: no current pane" << endl;
Chris@274 3789 return;
Chris@274 3790 }
Chris@274 3791
Chris@224 3792 Transform transform = TransformFactory::getInstance()->
Chris@224 3793 getDefaultTransformFor(transformId);
Chris@27 3794
Chris@66 3795 std::vector<Model *> candidateInputModels =
Chris@224 3796 m_document->getTransformInputModels();
Chris@53 3797
Chris@219 3798 Model *defaultInputModel = 0;
Chris@895 3799
Chris@219 3800 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@895 3801
Chris@219 3802 Layer *layer = pane->getLayer(j);
Chris@219 3803 if (!layer) continue;
Chris@895 3804
Chris@243 3805 if (LayerFactory::getInstance()->getLayerType(layer) !=
Chris@243 3806 LayerFactory::Waveform &&
Chris@243 3807 !layer->isLayerOpaque()) continue;
Chris@895 3808
Chris@219 3809 Model *model = layer->getModel();
Chris@219 3810 if (!model) continue;
Chris@895 3811
Chris@219 3812 for (size_t k = 0; k < candidateInputModels.size(); ++k) {
Chris@219 3813 if (candidateInputModels[k] == model) {
Chris@219 3814 defaultInputModel = model;
Chris@219 3815 break;
Chris@219 3816 }
Chris@219 3817 }
Chris@895 3818
Chris@219 3819 if (defaultInputModel) break;
Chris@219 3820 }
Chris@634 3821
Chris@895 3822 if (candidateInputModels.size() > 1) {
Chris@895 3823 // Add an aggregate model as another option
Chris@895 3824 AggregateWaveModel::ChannelSpecList sl;
Chris@895 3825 foreach (Model *m, candidateInputModels) {
Chris@895 3826 RangeSummarisableTimeValueModel *r =
Chris@895 3827 qobject_cast<RangeSummarisableTimeValueModel *>(m);
Chris@895 3828 if (r) {
Chris@895 3829 sl.push_back(AggregateWaveModel::ModelChannelSpec(r, -1));
Chris@895 3830 }
Chris@895 3831 }
Chris@895 3832 if (!sl.empty()) {
Chris@895 3833 AggregateWaveModel *aggregate = new AggregateWaveModel(sl);
Chris@895 3834 aggregate->setObjectName(tr("Multiplex all of the above"));
Chris@895 3835 candidateInputModels.push_back(aggregate);
Chris@895 3836 //!!! but it leaks
Chris@895 3837 }
Chris@895 3838 }
Chris@674 3839
Chris@914 3840 sv_frame_t startFrame = 0, duration = 0;
Chris@914 3841 sv_frame_t endFrame = 0;
Chris@1150 3842
Chris@184 3843 m_viewManager->getSelection().getExtents(startFrame, endFrame);
Chris@184 3844 if (endFrame > startFrame) duration = endFrame - startFrame;
Chris@184 3845 else startFrame = 0;
Chris@184 3846
Chris@357 3847 TransformUserConfigurator configurator;
Chris@357 3848
Chris@224 3849 ModelTransformer::Input input = ModelTransformerFactory::getInstance()->
Chris@224 3850 getConfigurationForTransform
Chris@211 3851 (transform,
Chris@211 3852 candidateInputModels,
Chris@219 3853 defaultInputModel,
Chris@211 3854 m_playSource,
Chris@211 3855 startFrame,
Chris@357 3856 duration,
Chris@357 3857 &configurator);
Chris@211 3858
Chris@224 3859 if (!input.getModel()) return;
Chris@224 3860
Chris@438 3861 // SVDEBUG << "MainWindow::addLayer: Input model is " << input.getModel() << " \"" << input.getModel()->objectName() << "\"" << endl << "transform:" << endl << transform.toXmlString() << endl;
Chris@224 3862
Chris@224 3863 Layer *newLayer = m_document->createDerivedLayer(transform, input);
Chris@0 3864
Chris@0 3865 if (newLayer) {
Chris@0 3866 m_document->addLayerToView(pane, newLayer);
Chris@224 3867 m_document->setChannel(newLayer, input.getChannel());
Chris@224 3868 m_recentTransforms.add(transformId);
Chris@70 3869 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 3870 }
Chris@0 3871
Chris@0 3872 updateMenuStates();
Chris@0 3873 }
Chris@0 3874
Chris@0 3875 void
Chris@0 3876 MainWindow::renameCurrentLayer()
Chris@0 3877 {
Chris@0 3878 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 3879 if (pane) {
Chris@634 3880 Layer *layer = pane->getSelectedLayer();
Chris@634 3881 if (layer) {
Chris@634 3882 bool ok = false;
Chris@634 3883 QString newName = QInputDialog::getText
Chris@634 3884 (this, tr("Rename Layer"),
Chris@634 3885 tr("New name for this layer:"),
Chris@634 3886 QLineEdit::Normal, layer->objectName(), &ok);
Chris@634 3887 if (ok) {
Chris@634 3888 layer->setPresentationName(newName);
Chris@634 3889 setupExistingLayersMenus();
Chris@634 3890 }
Chris@634 3891 }
Chris@0 3892 }
Chris@0 3893 }
Chris@0 3894
Chris@0 3895 void
Chris@272 3896 MainWindow::findTransform()
Chris@272 3897 {
Chris@274 3898 TransformFinder *finder = new TransformFinder(this);
Chris@274 3899 if (!finder->exec()) {
Chris@274 3900 delete finder;
Chris@274 3901 return;
Chris@273 3902 }
Chris@274 3903 TransformId transform = finder->getTransform();
Chris@274 3904 delete finder;
Chris@634 3905
Chris@287 3906 if (getMainModel() != 0 && m_paneStack->getCurrentPane() != 0) {
Chris@287 3907 addLayer(transform);
Chris@287 3908 }
Chris@272 3909 }
Chris@272 3910
Chris@272 3911 void
Chris@207 3912 MainWindow::playSoloToggled()
Chris@207 3913 {
Chris@207 3914 MainWindowBase::playSoloToggled();
Chris@207 3915 m_soloModified = true;
Chris@207 3916 }
Chris@207 3917
Chris@207 3918 void
Chris@206 3919 MainWindow::alignToggled()
Chris@206 3920 {
Chris@206 3921 QAction *action = dynamic_cast<QAction *>(sender());
Chris@634 3922
Chris@207 3923 if (!m_viewManager) return;
Chris@207 3924
Chris@206 3925 if (action) {
Chris@634 3926 m_viewManager->setAlignMode(action->isChecked());
Chris@206 3927 } else {
Chris@634 3928 m_viewManager->setAlignMode(!m_viewManager->getAlignMode());
Chris@206 3929 }
Chris@206 3930
Chris@206 3931 if (m_viewManager->getAlignMode()) {
Chris@207 3932 m_prevSolo = m_soloAction->isChecked();
Chris@208 3933 if (!m_soloAction->isChecked()) {
Chris@208 3934 m_soloAction->setChecked(true);
Chris@208 3935 MainWindowBase::playSoloToggled();
Chris@208 3936 }
Chris@207 3937 m_soloModified = false;
Chris@207 3938 emit canChangeSolo(false);
Chris@206 3939 m_document->alignModels();
Chris@206 3940 m_document->setAutoAlignment(true);
Chris@206 3941 } else {
Chris@207 3942 if (!m_soloModified) {
Chris@208 3943 if (m_soloAction->isChecked() != m_prevSolo) {
Chris@208 3944 m_soloAction->setChecked(m_prevSolo);
Chris@208 3945 MainWindowBase::playSoloToggled();
Chris@208 3946 }
Chris@207 3947 }
Chris@207 3948 emit canChangeSolo(true);
Chris@206 3949 m_document->setAutoAlignment(false);
Chris@206 3950 }
Chris@206 3951
Chris@206 3952 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@206 3953
Chris@634 3954 Pane *pane = m_paneStack->getPane(i);
Chris@634 3955 if (!pane) continue;
Chris@206 3956
Chris@206 3957 pane->update();
Chris@206 3958 }
Chris@206 3959 }
Chris@206 3960
Chris@206 3961 void
Chris@59 3962 MainWindow::playSpeedChanged(int position)
Chris@0 3963 {
Chris@1031 3964 PlaySpeedRangeMapper mapper;
Chris@674 3965
Chris@922 3966 double percent = m_playSpeed->mappedValue();
Chris@922 3967 double factor = mapper.getFactorForValue(percent);
Chris@674 3968
Chris@1031 3969 // cerr << "play speed position = " << position << " (range 0-120) percent = " << percent << " factor = " << factor << endl;
Chris@1031 3970
Chris@1031 3971 int centre = m_playSpeed->defaultValue();
Chris@1031 3972
Chris@1031 3973 // Percentage is shown to 0dp if >100, to 1dp if <100; factor is
Chris@1031 3974 // shown to 3sf
Chris@1031 3975
Chris@1031 3976 char pcbuf[30];
Chris@1031 3977 char facbuf[30];
Chris@1031 3978
Chris@1031 3979 if (position == centre) {
Chris@155 3980 contextHelpChanged(tr("Playback speed: Normal"));
Chris@1031 3981 } else if (position < centre) {
Chris@1031 3982 sprintf(pcbuf, "%.1f", percent);
Chris@1031 3983 sprintf(facbuf, "%.3g", 1.0 / factor);
Chris@1031 3984 contextHelpChanged(tr("Playback speed: %1% (%2x slower)")
Chris@1031 3985 .arg(pcbuf)
Chris@1031 3986 .arg(facbuf));
Chris@155 3987 } else {
Chris@1031 3988 sprintf(pcbuf, "%.0f", percent);
Chris@1031 3989 sprintf(facbuf, "%.3g", factor);
Chris@1031 3990 contextHelpChanged(tr("Playback speed: %1% (%2x faster)")
Chris@1031 3991 .arg(pcbuf)
Chris@1031 3992 .arg(facbuf));
Chris@155 3993 }
Chris@155 3994
Chris@1031 3995 m_playSource->setTimeStretch(1.0 / factor); // factor is a speedup
Chris@155 3996
Chris@155 3997 updateMenuStates();
Chris@16 3998 }
Chris@16 3999
Chris@26 4000 void
Chris@155 4001 MainWindow::speedUpPlayback()
Chris@155 4002 {
Chris@155 4003 int value = m_playSpeed->value();
Chris@155 4004 value = value + m_playSpeed->pageStep();
Chris@155 4005 if (value > m_playSpeed->maximum()) value = m_playSpeed->maximum();
Chris@155 4006 m_playSpeed->setValue(value);
Chris@155 4007 }
Chris@155 4008
Chris@155 4009 void
Chris@155 4010 MainWindow::slowDownPlayback()
Chris@155 4011 {
Chris@155 4012 int value = m_playSpeed->value();
Chris@155 4013 value = value - m_playSpeed->pageStep();
Chris@155 4014 if (value < m_playSpeed->minimum()) value = m_playSpeed->minimum();
Chris@155 4015 m_playSpeed->setValue(value);
Chris@155 4016 }
Chris@155 4017
Chris@155 4018 void
Chris@155 4019 MainWindow::restoreNormalPlayback()
Chris@155 4020 {
Chris@155 4021 m_playSpeed->setValue(m_playSpeed->defaultValue());
Chris@155 4022 }
Chris@155 4023
Chris@155 4024 void
Chris@227 4025 MainWindow::currentPaneChanged(Pane *pane)
Chris@227 4026 {
Chris@228 4027 MainWindowBase::currentPaneChanged(pane);
Chris@228 4028
Chris@227 4029 if (!pane || !m_panLayer) return;
Chris@761 4030
Chris@761 4031 // If this pane contains the main model, it usually makes sense to
Chris@761 4032 // show the main model in the pan layer even if it isn't the top
Chris@761 4033 // layer in the pane (e.g. if the top layer is one derived from
Chris@761 4034 // the main model).
Chris@761 4035 bool containsMainModel = false;
Chris@761 4036 for (int i = pane->getLayerCount(); i > 0; ) {
Chris@761 4037 --i;
Chris@761 4038 Layer *layer = pane->getLayer(i);
Chris@761 4039 if (layer &&
Chris@761 4040 LayerFactory::getInstance()->getLayerType(layer) ==
Chris@761 4041 LayerFactory::Waveform &&
Chris@761 4042 layer->getModel() == getMainModel()) {
Chris@761 4043 containsMainModel = true;
Chris@761 4044 break;
Chris@761 4045 }
Chris@761 4046 }
Chris@761 4047
Chris@761 4048 if (containsMainModel) {
Chris@761 4049 m_panLayer->setModel(getMainModel());
Chris@761 4050 return;
Chris@761 4051 }
Chris@761 4052
Chris@227 4053 for (int i = pane->getLayerCount(); i > 0; ) {
Chris@227 4054 --i;
Chris@227 4055 Layer *layer = pane->getLayer(i);
Chris@227 4056 if (LayerFactory::getInstance()->getLayerType(layer) ==
Chris@227 4057 LayerFactory::Waveform) {
Chris@634 4058 RangeSummarisableTimeValueModel *tvm =
Chris@227 4059 dynamic_cast<RangeSummarisableTimeValueModel *>(layer->getModel());
Chris@227 4060 if (tvm) {
Chris@227 4061 m_panLayer->setModel(tvm);
Chris@227 4062 return;
Chris@227 4063 }
Chris@227 4064 }
Chris@227 4065 }
Chris@227 4066 }
Chris@227 4067
Chris@227 4068 void
Chris@116 4069 MainWindow::updateVisibleRangeDisplay(Pane *p) const
Chris@116 4070 {
Chris@116 4071 if (!getMainModel() || !p) {
Chris@116 4072 return;
Chris@116 4073 }
Chris@116 4074
Chris@117 4075 bool haveSelection = false;
Chris@922 4076 sv_frame_t startFrame = 0, endFrame = 0;
Chris@117 4077
Chris@117 4078 if (m_viewManager && m_viewManager->haveInProgressSelection()) {
Chris@117 4079
Chris@117 4080 bool exclusive = false;
Chris@117 4081 Selection s = m_viewManager->getInProgressSelection(exclusive);
Chris@117 4082
Chris@117 4083 if (!s.isEmpty()) {
Chris@117 4084 haveSelection = true;
Chris@117 4085 startFrame = s.getStartFrame();
Chris@117 4086 endFrame = s.getEndFrame();
Chris@117 4087 }
Chris@117 4088 }
Chris@117 4089
Chris@117 4090 if (!haveSelection) {
Chris@117 4091 startFrame = p->getFirstVisibleFrame();
Chris@117 4092 endFrame = p->getLastVisibleFrame();
Chris@117 4093 }
Chris@117 4094
Chris@116 4095 RealTime start = RealTime::frame2RealTime
Chris@117 4096 (startFrame, getMainModel()->getSampleRate());
Chris@116 4097
Chris@116 4098 RealTime end = RealTime::frame2RealTime
Chris@117 4099 (endFrame, getMainModel()->getSampleRate());
Chris@116 4100
Chris@116 4101 RealTime duration = end - start;
Chris@116 4102
Chris@116 4103 QString startStr, endStr, durationStr;
Chris@116 4104 startStr = start.toText(true).c_str();
Chris@116 4105 endStr = end.toText(true).c_str();
Chris@116 4106 durationStr = duration.toText(true).c_str();
Chris@116 4107
Chris@117 4108 if (haveSelection) {
Chris@117 4109 m_myStatusMessage = tr("Selection: %1 to %2 (duration %3)")
Chris@117 4110 .arg(startStr).arg(endStr).arg(durationStr);
Chris@117 4111 } else {
Chris@117 4112 m_myStatusMessage = tr("Visible: %1 to %2 (duration %3)")
Chris@117 4113 .arg(startStr).arg(endStr).arg(durationStr);
Chris@117 4114 }
Chris@116 4115
Chris@739 4116 if (getStatusLabel()->text() != m_myStatusMessage) {
Chris@739 4117 getStatusLabel()->setText(m_myStatusMessage);
Chris@737 4118 }
Chris@340 4119
Chris@340 4120 updatePositionStatusDisplays();
Chris@340 4121 }
Chris@340 4122
Chris@340 4123 void
Chris@340 4124 MainWindow::updatePositionStatusDisplays() const
Chris@340 4125 {
Chris@340 4126 if (!statusBar()->isVisible()) return;
Chris@340 4127
Chris@340 4128 Pane *pane = 0;
Chris@922 4129 sv_frame_t frame = m_viewManager->getPlaybackFrame();
Chris@340 4130
Chris@340 4131 if (m_paneStack) pane = m_paneStack->getCurrentPane();
Chris@340 4132 if (!pane) return;
Chris@340 4133
Chris@340 4134 int layers = pane->getLayerCount();
Chris@340 4135 if (layers == 0) m_currentLabel->setText("");
Chris@340 4136
Chris@340 4137 for (int i = layers-1; i >= 0; --i) {
Chris@340 4138 Layer *layer = pane->getLayer(i);
Chris@340 4139 if (!layer) continue;
Chris@340 4140 if (!layer->isLayerEditable()) continue;
Chris@340 4141 QString label = layer->getLabelPreceding
Chris@340 4142 (pane->alignFromReference(frame));
Chris@340 4143 m_currentLabel->setText(label);
Chris@340 4144 break;
Chris@340 4145 }
Chris@116 4146 }
Chris@116 4147
Chris@116 4148 void
Chris@0 4149 MainWindow::outputLevelsChanged(float left, float right)
Chris@0 4150 {
Chris@0 4151 m_fader->setPeakLeft(left);
Chris@0 4152 m_fader->setPeakRight(right);
Chris@0 4153 }
Chris@0 4154
Chris@0 4155 void
Chris@921 4156 MainWindow::sampleRateMismatch(sv_samplerate_t requested,
Chris@921 4157 sv_samplerate_t actual,
Chris@0 4158 bool willResample)
Chris@0 4159 {
Chris@0 4160 if (!willResample) {
Chris@247 4161 emit hideSplash();
Chris@0 4162 QMessageBox::information
Chris@0 4163 (this, tr("Sample rate mismatch"),
Chris@193 4164 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 4165 .arg(requested).arg(actual));
Chris@634 4166 }
Chris@0 4167
Chris@0 4168 updateDescriptionLabel();
Chris@0 4169 }
Chris@0 4170
Chris@0 4171 void
Chris@42 4172 MainWindow::audioOverloadPluginDisabled()
Chris@42 4173 {
Chris@42 4174 QMessageBox::information
Chris@42 4175 (this, tr("Audio processing overload"),
Chris@193 4176 tr("<b>Overloaded</b><p>Audio effects plugin auditioning has been disabled due to a processing overload."));
Chris@42 4177 }
Chris@42 4178
Chris@42 4179 void
Chris@266 4180 MainWindow::audioTimeStretchMultiChannelDisabled()
Chris@266 4181 {
Chris@266 4182 static bool shownOnce = false;
Chris@266 4183 if (shownOnce) return;
Chris@266 4184 QMessageBox::information
Chris@266 4185 (this, tr("Audio processing overload"),
Chris@266 4186 tr("<b>Overloaded</b><p>Audio playback speed processing has been reduced to a single channel, due to a processing overload."));
Chris@266 4187 shownOnce = true;
Chris@266 4188 }
Chris@266 4189
Chris@266 4190 void
Chris@1148 4191 MainWindow::pluginPopulationWarning()
Chris@1087 4192 {
Chris@1148 4193 QString warning = PluginScan::getInstance()->getStartupFailureReport();
Chris@1087 4194 QMessageBox::warning(this, tr("Problems loading plugins"), warning);
Chris@1087 4195 }
Chris@1087 4196
Chris@1087 4197 void
Chris@304 4198 MainWindow::midiEventsAvailable()
Chris@304 4199 {
Chris@307 4200 Pane *currentPane = 0;
Chris@307 4201 NoteLayer *currentNoteLayer = 0;
Chris@309 4202 TimeValueLayer *currentTimeValueLayer = 0;
Chris@307 4203
Chris@793 4204 if (m_paneStack) {
Chris@793 4205 currentPane = m_paneStack->getCurrentPane();
Chris@793 4206 }
Chris@793 4207
Chris@307 4208 if (currentPane) {
Chris@307 4209 currentNoteLayer = dynamic_cast<NoteLayer *>
Chris@307 4210 (currentPane->getSelectedLayer());
Chris@309 4211 currentTimeValueLayer = dynamic_cast<TimeValueLayer *>
Chris@309 4212 (currentPane->getSelectedLayer());
Chris@838 4213 } else {
Chris@793 4214 // discard these events
Chris@793 4215 while (m_midiInput->getEventsAvailable() > 0) {
Chris@793 4216 (void)m_midiInput->readEvent();
Chris@793 4217 }
Chris@793 4218 return;
Chris@307 4219 }
Chris@307 4220
Chris@305 4221 // This is called through a serialised signal/slot invocation
Chris@305 4222 // (across threads). It could happen quite some time after the
Chris@305 4223 // event was actually received, which is why event timestamping
Chris@305 4224 // happens in the MIDI input class and not here.
Chris@307 4225
Chris@305 4226 while (m_midiInput->getEventsAvailable() > 0) {
Chris@308 4227
Chris@305 4228 MIDIEvent ev(m_midiInput->readEvent());
Chris@307 4229
Chris@922 4230 sv_frame_t frame = currentPane->alignFromReference(ev.getTime());
Chris@309 4231
Chris@308 4232 bool noteOn = (ev.getMessageType() == MIDIConstants::MIDI_NOTE_ON &&
Chris@308 4233 ev.getVelocity() > 0);
Chris@308 4234
Chris@308 4235 bool noteOff = (ev.getMessageType() == MIDIConstants::MIDI_NOTE_OFF ||
Chris@308 4236 (ev.getMessageType() == MIDIConstants::MIDI_NOTE_ON &&
Chris@308 4237 ev.getVelocity() == 0));
Chris@308 4238
Chris@307 4239 if (currentNoteLayer) {
Chris@307 4240
Chris@310 4241 if (!m_playSource || !m_playSource->isPlaying()) continue;
Chris@310 4242
Chris@308 4243 if (noteOn) {
Chris@307 4244
Chris@309 4245 currentNoteLayer->addNoteOn(frame,
Chris@307 4246 ev.getPitch(),
Chris@307 4247 ev.getVelocity());
Chris@307 4248
Chris@308 4249 } else if (noteOff) {
Chris@307 4250
Chris@309 4251 currentNoteLayer->addNoteOff(frame,
Chris@307 4252 ev.getPitch());
Chris@307 4253
Chris@307 4254 }
Chris@307 4255
Chris@309 4256 continue;
Chris@309 4257 }
Chris@309 4258
Chris@309 4259 if (currentTimeValueLayer) {
Chris@308 4260
Chris@308 4261 if (!noteOn) continue;
Chris@310 4262
Chris@310 4263 if (!m_playSource || !m_playSource->isPlaying()) continue;
Chris@310 4264
Chris@309 4265 Model *model = static_cast<Layer *>(currentTimeValueLayer)->getModel();
Chris@309 4266 SparseTimeValueModel *tvm =
Chris@309 4267 dynamic_cast<SparseTimeValueModel *>(model);
Chris@309 4268 if (tvm) {
Chris@309 4269 SparseTimeValueModel::Point point(frame, ev.getPitch() % 12, "");
Chris@309 4270 SparseTimeValueModel::AddPointCommand *command =
Chris@309 4271 new SparseTimeValueModel::AddPointCommand
Chris@309 4272 (tvm, point, tr("Add Point"));
Chris@309 4273 CommandHistory::getInstance()->addCommand(command);
Chris@309 4274 }
Chris@838 4275
Chris@309 4276 continue;
Chris@305 4277 }
Chris@309 4278
Chris@838 4279 // This is reached only if !currentNoteLayer and
Chris@838 4280 // !currentTimeValueLayer, i.e. there is some other sort of
Chris@838 4281 // layer that may be insertable-into
Chris@838 4282
Chris@309 4283 if (!noteOn) continue;
Chris@309 4284 insertInstantAt(ev.getTime());
Chris@304 4285 }
Chris@634 4286 }
Chris@304 4287
Chris@304 4288 void
Chris@730 4289 MainWindow::playStatusChanged(bool )
Chris@305 4290 {
Chris@307 4291 Pane *currentPane = 0;
Chris@307 4292 NoteLayer *currentNoteLayer = 0;
Chris@307 4293
Chris@307 4294 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
Chris@307 4295 if (currentPane) {
Chris@307 4296 currentNoteLayer = dynamic_cast<NoteLayer *>(currentPane->getSelectedLayer());
Chris@307 4297 }
Chris@307 4298
Chris@307 4299 if (currentNoteLayer) {
Chris@307 4300 currentNoteLayer->abandonNoteOns();
Chris@307 4301 }
Chris@305 4302 }
Chris@305 4303
Chris@305 4304 void
Chris@200 4305 MainWindow::layerRemoved(Layer *layer)
Chris@0 4306 {
Chris@95 4307 setupExistingLayersMenus();
Chris@200 4308 MainWindowBase::layerRemoved(layer);
Chris@0 4309 }
Chris@0 4310
Chris@0 4311 void
Chris@0 4312 MainWindow::layerInAView(Layer *layer, bool inAView)
Chris@0 4313 {
Chris@95 4314 setupExistingLayersMenus();
Chris@200 4315 MainWindowBase::layerInAView(layer, inAView);
Chris@0 4316 }
Chris@0 4317
Chris@0 4318 void
Chris@0 4319 MainWindow::modelAdded(Model *model)
Chris@0 4320 {
Chris@200 4321 MainWindowBase::modelAdded(model);
Chris@66 4322 if (dynamic_cast<DenseTimeValueModel *>(model)) {
Chris@66 4323 setupPaneAndLayerMenus();
Chris@66 4324 }
Chris@0 4325 }
Chris@0 4326
Chris@0 4327 void
Chris@0 4328 MainWindow::mainModelChanged(WaveFileModel *model)
Chris@0 4329 {
Chris@0 4330 m_panLayer->setModel(model);
Chris@200 4331
Chris@200 4332 MainWindowBase::mainModelChanged(model);
Chris@200 4333
Chris@1055 4334 if (m_playTarget || m_audioIO) {
Chris@674 4335 connect(m_fader, SIGNAL(valueChanged(float)),
Chris@1035 4336 this, SLOT(mainModelGainChanged(float)));
Chris@1035 4337 }
Chris@1035 4338 }
Chris@1035 4339
Chris@1035 4340 void
Chris@1035 4341 MainWindow::mainModelGainChanged(float gain)
Chris@1035 4342 {
Chris@200 4343 if (m_playTarget) {
Chris@1035 4344 m_playTarget->setOutputGain(gain);
Chris@1055 4345 } else if (m_audioIO) {
Chris@1055 4346 m_audioIO->setOutputGain(gain);
Chris@200 4347 }
Chris@0 4348 }
Chris@0 4349
Chris@0 4350 void
Chris@760 4351 MainWindow::modelAboutToBeDeleted(Model *model)
Chris@760 4352 {
Chris@760 4353 if (model == m_panLayer->getModel()) {
Chris@760 4354 if (model == getMainModel()) {
Chris@760 4355 m_panLayer->setModel(0);
Chris@760 4356 } else {
Chris@760 4357 m_panLayer->setModel(getMainModel());
Chris@760 4358 }
Chris@760 4359 }
Chris@760 4360 MainWindowBase::modelAboutToBeDeleted(model);
Chris@760 4361 }
Chris@760 4362
Chris@760 4363 void
Chris@200 4364 MainWindow::setInstantsNumbering()
Chris@0 4365 {
Chris@200 4366 QAction *a = dynamic_cast<QAction *>(sender());
Chris@200 4367 if (!a) return;
Chris@200 4368
Chris@200 4369 int type = m_numberingActions[a];
Chris@634 4370
Chris@200 4371 if (m_labeller) m_labeller->setType(Labeller::ValueType(type));
Chris@200 4372
Chris@200 4373 QSettings settings;
Chris@200 4374 settings.beginGroup("MainWindow");
Chris@200 4375 settings.setValue("labellertype", type);
Chris@200 4376 settings.endGroup();
Chris@200 4377 }
Chris@200 4378
Chris@200 4379 void
Chris@200 4380 MainWindow::setInstantsCounterCycle()
Chris@200 4381 {
Chris@200 4382 QAction *a = dynamic_cast<QAction *>(sender());
Chris@200 4383 if (!a) return;
Chris@634 4384
Chris@200 4385 int cycle = a->text().toInt();
Chris@200 4386 if (cycle == 0) return;
Chris@200 4387
Chris@200 4388 if (m_labeller) m_labeller->setCounterCycleSize(cycle);
Chris@634 4389
Chris@200 4390 QSettings settings;
Chris@200 4391 settings.beginGroup("MainWindow");
Chris@200 4392 settings.setValue("labellercycle", cycle);
Chris@200 4393 settings.endGroup();
Chris@200 4394 }
Chris@200 4395
Chris@200 4396 void
Chris@597 4397 MainWindow::setInstantsCounters()
Chris@200 4398 {
Chris@200 4399 LabelCounterInputDialog dialog(m_labeller, this);
Chris@241 4400 dialog.setWindowTitle(tr("Reset Counters"));
Chris@200 4401 dialog.exec();
Chris@0 4402 }
Chris@0 4403
Chris@0 4404 void
Chris@597 4405 MainWindow::resetInstantsCounters()
Chris@597 4406 {
Chris@597 4407 if (m_labeller) m_labeller->resetCounters();
Chris@597 4408 }
Chris@597 4409
Chris@597 4410 void
Chris@233 4411 MainWindow::modelGenerationFailed(QString transformName, QString message)
Chris@233 4412 {
Chris@247 4413 emit hideSplash();
Chris@247 4414
Chris@983 4415 QString quoted;
Chris@983 4416 if (transformName != "") {
Chris@983 4417 quoted = QString("\"%1\" ").arg(transformName);
Chris@983 4418 }
Chris@983 4419
Chris@233 4420 if (message != "") {
Chris@233 4421
Chris@233 4422 QMessageBox::warning
Chris@233 4423 (this,
Chris@233 4424 tr("Failed to generate layer"),
Chris@983 4425 tr("<b>Layer generation failed</b><p>Failed to generate derived layer.<p>The layer transform %1failed:<p>%2")
Chris@983 4426 .arg(quoted).arg(message),
Chris@233 4427 QMessageBox::Ok);
Chris@233 4428 } else {
Chris@233 4429 QMessageBox::warning
Chris@233 4430 (this,
Chris@233 4431 tr("Failed to generate layer"),
Chris@983 4432 tr("<b>Layer generation failed</b><p>Failed to generate a derived layer.<p>The layer transform %1failed.<p>No error information is available.")
Chris@983 4433 .arg(quoted),
Chris@233 4434 QMessageBox::Ok);
Chris@233 4435 }
Chris@233 4436 }
Chris@233 4437
Chris@233 4438 void
Chris@730 4439 MainWindow::modelGenerationWarning(QString /* transformName */, QString message)
Chris@233 4440 {
Chris@247 4441 emit hideSplash();
Chris@247 4442
Chris@233 4443 QMessageBox::warning
Chris@233 4444 (this, tr("Warning"), message, QMessageBox::Ok);
Chris@233 4445 }
Chris@233 4446
Chris@233 4447 void
Chris@233 4448 MainWindow::modelRegenerationFailed(QString layerName,
Chris@233 4449 QString transformName, QString message)
Chris@233 4450 {
Chris@247 4451 emit hideSplash();
Chris@247 4452
Chris@233 4453 if (message != "") {
Chris@233 4454
Chris@233 4455 QMessageBox::warning
Chris@233 4456 (this,
Chris@233 4457 tr("Failed to regenerate layer"),
Chris@233 4458 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 4459 .arg(layerName).arg(transformName).arg(message),
Chris@233 4460 QMessageBox::Ok);
Chris@233 4461 } else {
Chris@233 4462 QMessageBox::warning
Chris@233 4463 (this,
Chris@233 4464 tr("Failed to regenerate layer"),
Chris@233 4465 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 4466 .arg(layerName).arg(transformName),
Chris@233 4467 QMessageBox::Ok);
Chris@233 4468 }
Chris@233 4469 }
Chris@233 4470
Chris@233 4471 void
Chris@233 4472 MainWindow::modelRegenerationWarning(QString layerName,
Chris@730 4473 QString /* transformName */,
Chris@730 4474 QString message)
Chris@233 4475 {
Chris@247 4476 emit hideSplash();
Chris@247 4477
Chris@233 4478 QMessageBox::warning
Chris@233 4479 (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 4480 }
Chris@233 4481
Chris@233 4482 void
Chris@233 4483 MainWindow::alignmentFailed(QString transformName, QString message)
Chris@0 4484 {
Chris@247 4485 emit hideSplash();
Chris@247 4486
Chris@0 4487 QMessageBox::warning
Chris@0 4488 (this,
Chris@233 4489 tr("Failed to calculate alignment"),
Chris@233 4490 tr("<b>Alignment calculation failed</b><p>Failed to calculate an audio alignment using transform \"%1\":<p>%2")
Chris@233 4491 .arg(transformName).arg(message),
Chris@165 4492 QMessageBox::Ok);
Chris@0 4493 }
Chris@0 4494
Chris@0 4495 void
Chris@0 4496 MainWindow::rightButtonMenuRequested(Pane *pane, QPoint position)
Chris@0 4497 {
Chris@438 4498 // SVDEBUG << "MainWindow::rightButtonMenuRequested(" << pane << ", " << position.x() << ", " << position.y() << ")" << endl;
Chris@0 4499 m_paneStack->setCurrentPane(pane);
Chris@0 4500 m_rightButtonMenu->popup(position);
Chris@0 4501 }
Chris@0 4502
Chris@0 4503 void
Chris@0 4504 MainWindow::showLayerTree()
Chris@0 4505 {
Chris@219 4506 if (!m_layerTreeDialog.isNull()) {
Chris@219 4507 m_layerTreeDialog->show();
Chris@219 4508 m_layerTreeDialog->raise();
Chris@177 4509 return;
Chris@177 4510 }
Chris@177 4511
Chris@762 4512 m_layerTreeDialog = new LayerTreeDialog(m_paneStack, this);
Chris@232 4513 m_layerTreeDialog->setAttribute(Qt::WA_DeleteOnClose); // see below
Chris@219 4514 m_layerTreeDialog->show();
Chris@0 4515 }
Chris@0 4516
Chris@0 4517 void
Chris@306 4518 MainWindow::showActivityLog()
Chris@306 4519 {
Chris@306 4520 m_activityLog->show();
Chris@306 4521 m_activityLog->raise();
Chris@306 4522 m_activityLog->scrollToEnd();
Chris@306 4523 }
Chris@306 4524
Chris@306 4525 void
Chris@891 4526 MainWindow::showUnitConverter()
Chris@891 4527 {
Chris@891 4528 m_unitConverter->show();
Chris@891 4529 m_unitConverter->raise();
Chris@891 4530 }
Chris@891 4531
Chris@891 4532 void
Chris@0 4533 MainWindow::preferences()
Chris@0 4534 {
Chris@436 4535 bool goToTemplateTab =
Chris@436 4536 (sender() && sender()->objectName() == "set_default_template");
Chris@436 4537
Chris@0 4538 if (!m_preferencesDialog.isNull()) {
Chris@0 4539 m_preferencesDialog->show();
Chris@0 4540 m_preferencesDialog->raise();
Chris@436 4541 if (goToTemplateTab) {
Chris@436 4542 m_preferencesDialog->switchToTab(PreferencesDialog::TemplateTab);
Chris@436 4543 }
Chris@0 4544 return;
Chris@0 4545 }
Chris@0 4546
Chris@0 4547 m_preferencesDialog = new PreferencesDialog(this);
Chris@0 4548
Chris@0 4549 // DeleteOnClose is safe here, because m_preferencesDialog is a
Chris@0 4550 // QPointer that will be zeroed when the dialog is deleted. We
Chris@0 4551 // use it in preference to leaving the dialog lying around because
Chris@0 4552 // if you Cancel the dialog, it resets the preferences state
Chris@0 4553 // without resetting its own widgets, so its state will be
Chris@0 4554 // incorrect when next shown unless we construct it afresh
Chris@0 4555 m_preferencesDialog->setAttribute(Qt::WA_DeleteOnClose);
Chris@0 4556
Chris@0 4557 m_preferencesDialog->show();
Chris@436 4558 if (goToTemplateTab) {
Chris@436 4559 m_preferencesDialog->switchToTab(PreferencesDialog::TemplateTab);
Chris@436 4560 }
Chris@0 4561 }
Chris@0 4562
Chris@0 4563 void
Chris@90 4564 MainWindow::mouseEnteredWidget()
Chris@90 4565 {
Chris@90 4566 QWidget *w = dynamic_cast<QWidget *>(sender());
Chris@90 4567 if (!w) return;
Chris@90 4568
Chris@90 4569 if (w == m_fader) {
Chris@116 4570 contextHelpChanged(tr("Adjust the master playback level"));
Chris@90 4571 } else if (w == m_playSpeed) {
Chris@116 4572 contextHelpChanged(tr("Adjust the master playback speed"));
Chris@90 4573 }
Chris@90 4574 }
Chris@90 4575
Chris@90 4576 void
Chris@90 4577 MainWindow::mouseLeftWidget()
Chris@90 4578 {
Chris@116 4579 contextHelpChanged("");
Chris@116 4580 }
Chris@116 4581
Chris@116 4582 void
Chris@0 4583 MainWindow::website()
Chris@0 4584 {
Chris@0 4585 openHelpUrl(tr("http://www.sonicvisualiser.org/"));
Chris@0 4586 }
Chris@0 4587
Chris@0 4588 void
Chris@0 4589 MainWindow::help()
Chris@0 4590 {
Chris@318 4591 openHelpUrl(tr("http://www.sonicvisualiser.org/doc/reference/%1/en/").arg(SV_VERSION));
Chris@0 4592 }
Chris@0 4593
Chris@0 4594 void
Chris@0 4595 MainWindow::about()
Chris@0 4596 {
Chris@0 4597 bool debug = false;
Chris@0 4598 QString version = "(unknown version)";
Chris@0 4599
Chris@0 4600 #ifdef BUILD_DEBUG
Chris@0 4601 debug = true;
Chris@285 4602 #endif // BUILD_DEBUG
Chris@0 4603 #ifdef SV_VERSION
Chris@0 4604 #ifdef SVNREV
Chris@0 4605 version = tr("Release %1 : Revision %2").arg(SV_VERSION).arg(SVNREV);
Chris@285 4606 #else // !SVNREV
Chris@0 4607 version = tr("Release %1").arg(SV_VERSION);
Chris@285 4608 #endif // SVNREV
Chris@285 4609 #else // !SV_VERSION
Chris@0 4610 #ifdef SVNREV
Chris@0 4611 version = tr("Unreleased : Revision %1").arg(SVNREV);
Chris@285 4612 #endif // SVNREV
Chris@285 4613 #endif // SV_VERSION
Chris@0 4614
Chris@0 4615 QString aboutText;
Chris@0 4616
Chris@0 4617 aboutText += tr("<h3>About Sonic Visualiser</h3>");
Chris@285 4618 aboutText += tr("<p>Sonic Visualiser is a program for viewing and exploring audio data for semantic music analysis and annotation.<br><a href=\"http://www.sonicvisualiser.org/\">http://www.sonicvisualiser.org/</a></p>");
Chris@285 4619 aboutText += tr("<p><small>%1 : %2 configuration</small></p>")
Chris@0 4620 .arg(version)
Chris@0 4621 .arg(debug ? tr("Debug") : tr("Release"));
Chris@0 4622
Chris@285 4623 aboutText += "<small>";
Chris@285 4624
Chris@285 4625 aboutText += tr("With Qt v%1 &copy; Nokia Corporation").arg(QT_VERSION_STR);
Chris@285 4626
Chris@0 4627 #ifdef HAVE_JACK
Chris@93 4628 #ifdef JACK_VERSION
Chris@285 4629 aboutText += tr("<br>With JACK audio output library v%1 &copy; Paul Davis and Jack O'Quin").arg(JACK_VERSION);
Chris@285 4630 #else // !JACK_VERSION
Chris@257 4631 aboutText += tr("<br>With JACK audio output library &copy; Paul Davis and Jack O'Quin");
Chris@285 4632 #endif // JACK_VERSION
Chris@285 4633 #endif // HAVE_JACK
Chris@0 4634 #ifdef HAVE_PORTAUDIO
Chris@257 4635 aboutText += tr("<br>With PortAudio audio output library &copy; Ross Bencina and Phil Burk");
Chris@285 4636 #endif // HAVE_PORTAUDIO
Chris@257 4637 #ifdef HAVE_LIBPULSE
Chris@285 4638 #ifdef LIBPULSE_VERSION
Chris@285 4639 aboutText += tr("<br>With PulseAudio audio output library v%1 &copy; Lennart Poettering and Pierre Ossman").arg(LIBPULSE_VERSION);
Chris@285 4640 #else // !LIBPULSE_VERSION
Chris@257 4641 aboutText += tr("<br>With PulseAudio audio output library &copy; Lennart Poettering and Pierre Ossman");
Chris@285 4642 #endif // LIBPULSE_VERSION
Chris@285 4643 #endif // HAVE_LIBPULSE
Chris@0 4644 #ifdef HAVE_OGGZ
Chris@93 4645 #ifdef OGGZ_VERSION
Chris@0 4646 aboutText += tr("<br>With Ogg file decoder (oggz v%1, fishsound v%2) &copy; CSIRO Australia").arg(OGGZ_VERSION).arg(FISHSOUND_VERSION);
Chris@285 4647 #else // !OGGZ_VERSION
Chris@93 4648 aboutText += tr("<br>With Ogg file decoder &copy; CSIRO Australia");
Chris@285 4649 #endif // OGGZ_VERSION
Chris@285 4650 #endif // HAVE_OGGZ
Chris@0 4651 #ifdef HAVE_MAD
Chris@93 4652 #ifdef MAD_VERSION
Chris@285 4653 aboutText += tr("<br>With MAD mp3 decoder v%1 &copy; Underbit Technologies Inc").arg(MAD_VERSION);
Chris@285 4654 #else // !MAD_VERSION
Chris@93 4655 aboutText += tr("<br>With MAD mp3 decoder &copy; Underbit Technologies Inc");
Chris@285 4656 #endif // MAD_VERSION
Chris@285 4657 #endif // HAVE_MAD
Chris@0 4658 #ifdef HAVE_SAMPLERATE
Chris@93 4659 #ifdef SAMPLERATE_VERSION
Chris@285 4660 aboutText += tr("<br>With libsamplerate v%1 &copy; Erik de Castro Lopo").arg(SAMPLERATE_VERSION);
Chris@285 4661 #else // !SAMPLERATE_VERSION
Chris@93 4662 aboutText += tr("<br>With libsamplerate &copy; Erik de Castro Lopo");
Chris@285 4663 #endif // SAMPLERATE_VERSION
Chris@285 4664 #endif // HAVE_SAMPLERATE
Chris@0 4665 #ifdef HAVE_SNDFILE
Chris@93 4666 #ifdef SNDFILE_VERSION
Chris@285 4667 aboutText += tr("<br>With libsndfile v%1 &copy; Erik de Castro Lopo").arg(SNDFILE_VERSION);
Chris@285 4668 #else // !SNDFILE_VERSION
Chris@93 4669 aboutText += tr("<br>With libsndfile &copy; Erik de Castro Lopo");
Chris@285 4670 #endif // SNDFILE_VERSION
Chris@285 4671 #endif // HAVE_SNDFILE
Chris@127 4672 #ifdef HAVE_FFTW3F
Chris@93 4673 #ifdef FFTW3_VERSION
Chris@285 4674 aboutText += tr("<br>With FFTW3 v%1 &copy; Matteo Frigo and MIT").arg(FFTW3_VERSION);
Chris@285 4675 #else // !FFTW3_VERSION
Chris@93 4676 aboutText += tr("<br>With FFTW3 &copy; Matteo Frigo and MIT");
Chris@285 4677 #endif // FFTW3_VERSION
Chris@285 4678 #endif // HAVE_FFTW3F
Chris@267 4679 #ifdef HAVE_RUBBERBAND
Chris@267 4680 #ifdef RUBBERBAND_VERSION
Chris@285 4681 aboutText += tr("<br>With Rubber Band v%1 &copy; Chris Cannam").arg(RUBBERBAND_VERSION);
Chris@285 4682 #else // !RUBBERBAND_VERSION
Chris@267 4683 aboutText += tr("<br>With Rubber Band &copy; Chris Cannam");
Chris@285 4684 #endif // RUBBERBAND_VERSION
Chris@285 4685 #endif // HAVE_RUBBERBAND
Chris@0 4686 #ifdef HAVE_VAMP
Chris@114 4687 aboutText += tr("<br>With Vamp plugin support (API v%1, host SDK v%2) &copy; Chris Cannam").arg(VAMP_API_VERSION).arg(VAMP_SDK_VERSION);
Chris@285 4688 #endif // !HAVE_VAMP
Chris@0 4689 aboutText += tr("<br>With LADSPA plugin support (API v%1) &copy; Richard Furse, Paul Davis, Stefan Westerfeld").arg(LADSPA_VERSION);
Chris@0 4690 aboutText += tr("<br>With DSSI plugin support (API v%1) &copy; Chris Cannam, Steve Harris, Sean Bolton").arg(DSSI_VERSION);
Chris@285 4691 #ifdef REDLAND_VERSION
Chris@285 4692 aboutText += tr("<br>With Redland RDF datastore v%1 &copy; Dave Beckett and the University of Bristol").arg(REDLAND_VERSION);
Chris@285 4693 #else // !REDLAND_VERSION
Chris@285 4694 aboutText += tr("<br>With Redland RDF datastore &copy; Dave Beckett and the University of Bristol");
Chris@285 4695 #endif // REDLAND_VERSION
Chris@523 4696 aboutText += tr("<br>With Serd and Sord RDF parser and store &copy; David Robillard");
Chris@523 4697 aboutText += tr("<br>With Dataquay Qt/RDF library &copy; Chris Cannam");
Chris@285 4698
Chris@300 4699 aboutText += tr("<br>With RtMidi &copy; Gary P. Scavone");
Chris@300 4700
Chris@69 4701 #ifdef HAVE_LIBLO
Chris@93 4702 #ifdef LIBLO_VERSION
Chris@285 4703 aboutText += tr("<br>With liblo Lite OSC library v%1 &copy; Steve Harris").arg(LIBLO_VERSION);
Chris@285 4704 #else // !LIBLO_VERSION
Chris@327 4705 aboutText += tr("<br>With liblo Lite OSC library &copy; Steve Harris");
Chris@285 4706 #endif // LIBLO_VERSION
Chris@285 4707
Chris@285 4708 if (m_oscQueue && m_oscQueue->isOK()) {
Chris@285 4709 aboutText += tr("</small><p><small>The OSC URL for this instance is: \"%1\"").arg(m_oscQueue->getOSCURL());
Chris@285 4710 }
Chris@285 4711
Chris@285 4712 aboutText += "</small></p>";
Chris@285 4713 #endif // HAVE_LIBLO
Chris@285 4714
Chris@285 4715 #ifndef BUILD_STATIC
Chris@285 4716 aboutText.replace(tr("With "), tr("Using "));
Chris@93 4717 #endif
Chris@0 4718
Chris@674 4719 aboutText +=
Chris@962 4720 "<p><small>Sonic Visualiser Copyright &copy; 2005&ndash;2015 Chris Cannam and "
Chris@285 4721 "Queen Mary, University of London.</small></p>"
Chris@285 4722 "<p><small>This program is free software; you can redistribute it and/or "
Chris@231 4723 "modify it under the terms of the GNU General Public License as "
Chris@231 4724 "published by the Free Software Foundation; either version 2 of the "
Chris@0 4725 "License, or (at your option) any later version.<br>See the file "
Chris@285 4726 "COPYING included with this distribution for more information.</small></p>";
Chris@634 4727
Chris@0 4728 QMessageBox::about(this, tr("About Sonic Visualiser"), aboutText);
Chris@0 4729 }
Chris@0 4730
Chris@162 4731 void
Chris@162 4732 MainWindow::keyReference()
Chris@162 4733 {
Chris@162 4734 m_keyReference->show();
Chris@162 4735 }
Chris@162 4736
Chris@333 4737 void
Chris@333 4738 MainWindow::newerVersionAvailable(QString version)
Chris@333 4739 {
Chris@334 4740 QSettings settings;
Chris@334 4741 settings.beginGroup("NewerVersionWarning");
Chris@334 4742 QString tag = QString("version-%1-available-show").arg(version);
Chris@334 4743 if (settings.value(tag, true).toBool()) {
Chris@334 4744 QString title(tr("Newer version available"));
Chris@663 4745 QString text(tr("<h3>Newer version available</h3><p>You are using version %1 of Sonic Visualiser, but version %2 is now available.</p><p>Please see the <a href=\"http://sonicvisualiser.org/\">Sonic Visualiser website</a> for more information.</p>").arg(SV_VERSION).arg(version));
Chris@334 4746 QMessageBox::information(this, title, text);
Chris@334 4747 settings.setValue(tag, false);
Chris@334 4748 }
Chris@334 4749 settings.endGroup();
Chris@333 4750 }
Chris@333 4751
Chris@333 4752
Chris@634 4753
Chris@634 4754 CheckBox::CheckBox(QWidget *parent)
Chris@634 4755 : QWidget(parent)
Chris@634 4756 {
Chris@634 4757 // SELECTION RULES
Chris@634 4758 QGroupBox *selrule_box = new QGroupBox(QString::fromUtf8("SELECTION RULES"),this);
Chris@634 4759 selrule_box->setFont(QFont("Times", 9, QFont::Bold));
Chris@634 4760 selrule_box->move(5,5);
Chris@634 4761 selrule_box->resize(235,130);
Chris@634 4762 QButtonGroup *selrule_group = new QButtonGroup(this);
Chris@634 4763 selrule_group->setObjectName("Selection Rule");
Chris@634 4764
Chris@634 4765 QRadioButton *minmax_rule = new QRadioButton(QString::fromUtf8("Min/Max Rule"),this);
Chris@634 4766 minmax_rule->move(20,25);
Chris@634 4767 minmax_rule->setObjectName("0");
Chris@634 4768 QRadioButton *exclusion_rule = new QRadioButton(QString::fromUtf8("Exclusion Rule"),this);
Chris@634 4769 exclusion_rule->move(20,45);
Chris@634 4770 exclusion_rule->setObjectName("1");
Chris@634 4771 QRadioButton *notmute_rule = new QRadioButton(QString::fromUtf8("Not Mute Rule"),this);
Chris@634 4772 notmute_rule->move(130,25);
Chris@634 4773 notmute_rule->setObjectName("2");
Chris@634 4774 QRadioButton *implication_rule = new QRadioButton(QString::fromUtf8("Implication Rule"),this);
Chris@634 4775 implication_rule->move(130,45);
Chris@634 4776 implication_rule->setObjectName("3");
Chris@634 4777
Chris@634 4778 selrule_group->addButton(minmax_rule);
Chris@634 4779 selrule_group->addButton(exclusion_rule);
Chris@634 4780 selrule_group->addButton(notmute_rule);
Chris@634 4781 selrule_group->addButton(implication_rule);
Chris@634 4782
Chris@634 4783 QSpinBox *sel_par1 = new QSpinBox(this);
Chris@634 4784 sel_par1->setEnabled(true);
Chris@634 4785 sel_par1->setGeometry(QRect(20, 75, 40, 20));
Chris@634 4786 sel_par1->setMinimum(1);
Chris@634 4787 sel_par1->setMaximum(numtracks);
Chris@634 4788 selrule_par1 = sel_par1->value();
Chris@634 4789
Chris@634 4790 sel_rule1 = new QLabel(this);
Chris@634 4791 sel_rule1->setText("Parameter 1");
Chris@634 4792 sel_rule1->setGeometry(70, 75, 100, 20);
Chris@634 4793
Chris@634 4794 QSpinBox *sel_par2 = new QSpinBox(this);
Chris@634 4795 sel_par2->setEnabled(true);
Chris@634 4796 sel_par2->setGeometry(QRect(20, 100, 40, 20));
Chris@634 4797 sel_par2->setMinimum(1);
Chris@634 4798 sel_par2->setMaximum(numtracks);
Chris@634 4799 selrule_par2 = sel_par2->value();
Chris@634 4800
Chris@634 4801 sel_rule2 = new QLabel(this);
Chris@634 4802 sel_rule2->setText("Parameter 2");
Chris@634 4803 sel_rule2->setGeometry(70, 100, 100, 20);
Chris@634 4804
Chris@634 4805 connect(selrule_group, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(set_selruleType(QAbstractButton*)));
Chris@634 4806 connect(sel_par1, SIGNAL(valueChanged(int)), this, SLOT(set_selrulePAR1(int)));
Chris@634 4807 connect(sel_par2, SIGNAL(valueChanged(int)), this, SLOT(set_selrulePAR2(int)));
Chris@634 4808
Chris@634 4809 // MIXING RULES (yet to implement)
Chris@634 4810 QGroupBox *mixrule_box = new QGroupBox(QString::fromUtf8("MIXING RULES"),this);
Chris@634 4811 mixrule_box->setFont(QFont("Times", 9, QFont::Bold));
Chris@634 4812 mixrule_box->move(255,5);
Chris@634 4813 mixrule_box->resize(330,130);
Chris@634 4814 QButtonGroup *mixrule_group = new QButtonGroup(this);
Chris@634 4815 mixrule_group->setObjectName("Mixing Rule");
Chris@634 4816
Chris@634 4817 QRadioButton *equivalence_rule = new QRadioButton(QString::fromUtf8("Equivalence Rule"),this);
Chris@634 4818 equivalence_rule->move(270,25);
Chris@634 4819 equivalence_rule->setObjectName("0");
Chris@634 4820 QRadioButton *upper_rule = new QRadioButton(QString::fromUtf8("Upper Rule"),this);
Chris@634 4821 upper_rule->move(270,45);
Chris@634 4822 upper_rule->setObjectName("1");
Chris@634 4823 QRadioButton *lower_rule = new QRadioButton(QString::fromUtf8("Lower Rule"),this);
Chris@634 4824 lower_rule->move(380,25);
Chris@634 4825 lower_rule->setObjectName("2");
Chris@634 4826 QRadioButton *limit_rule = new QRadioButton(QString::fromUtf8("Limit Rule"),this);
Chris@634 4827 limit_rule->move(380,45);
Chris@634 4828 limit_rule->setObjectName("3");
Chris@634 4829
Chris@634 4830 mixrule_group->addButton(equivalence_rule);
Chris@634 4831 mixrule_group->addButton(upper_rule);
Chris@634 4832 mixrule_group->addButton(lower_rule);
Chris@634 4833 mixrule_group->addButton(limit_rule);
Chris@634 4834
Chris@634 4835 QSpinBox *mix_par1 = new QSpinBox(this);
Chris@634 4836 mix_par1->setEnabled(true);
Chris@634 4837 mix_par1->setGeometry(QRect(270, 75, 40, 20));
Chris@634 4838 mix_par1->setMinimum(1);
Chris@634 4839 mix_par1->setMaximum(numtracks);
Chris@634 4840 mixrule_par1 = mix_par1->value();
Chris@634 4841
Chris@634 4842 mix_rule1 = new QLabel(this);
Chris@634 4843 mix_rule1->setText("Parameter 1");
Chris@634 4844 mix_rule1->setGeometry(320, 75, 100, 20);
Chris@634 4845
Chris@634 4846 QSpinBox *mix_par2 = new QSpinBox(this);
Chris@634 4847 mix_par2->setEnabled(true);
Chris@634 4848 mix_par2->setGeometry(QRect(270, 100, 40, 20));
Chris@634 4849 mix_par2->setMinimum(1);
Chris@634 4850 mix_par2->setMaximum(numtracks);
Chris@634 4851 mixrule_par2 = mix_par2->value();
Chris@634 4852
Chris@634 4853 mix_rule2 = new QLabel(this);
Chris@634 4854 mix_rule2->setText("Parameter 2");
Chris@634 4855 mix_rule2->setGeometry(320, 100, 100, 20);
Chris@634 4856
Chris@634 4857 QSpinBox *mix_par3 = new QSpinBox(this);
Chris@634 4858 mix_par3->setEnabled(true);
Chris@634 4859 mix_par3->setGeometry(QRect(410, 75, 40, 20));
Chris@634 4860 mix_par3->setMinimum(0);
Chris@634 4861 mix_par3->setMaximum(100);
Chris@634 4862 mixrule_par3 = mix_par3->value();
Chris@634 4863
Chris@634 4864 mix_rule3 = new QLabel(this);
Chris@634 4865 mix_rule3->setText("Parameter 3");
Chris@634 4866 mix_rule3->setGeometry(460, 75, 100, 20);
Chris@634 4867
Chris@634 4868 QSpinBox *mix_par4 = new QSpinBox(this);
Chris@634 4869 mix_par4->setEnabled(true);
Chris@634 4870 mix_par4->setGeometry(QRect(410, 100, 40, 20));
Chris@634 4871 mix_par4->setMinimum(0);
Chris@634 4872 mix_par4->setMaximum(100);
Chris@634 4873 mixrule_par4 = mix_par4->value();
Chris@634 4874
Chris@634 4875 mix_rule4 = new QLabel(this);
Chris@634 4876 mix_rule4->setText("Parameter 4");
Chris@634 4877 mix_rule4->setGeometry(460, 100, 100, 20);
Chris@634 4878
Chris@634 4879 connect(mixrule_group, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(set_mixruleType(QAbstractButton*)));
Chris@634 4880 connect(mix_par1, SIGNAL(valueChanged(int)), this, SLOT(set_mixrulePAR1(int)));
Chris@634 4881 connect(mix_par2, SIGNAL(valueChanged(int)), this, SLOT(set_mixrulePAR2(int)));
Chris@634 4882 connect(mix_par3, SIGNAL(valueChanged(int)), this, SLOT(set_mixrulePAR3(int)));
Chris@634 4883 connect(mix_par4, SIGNAL(valueChanged(int)), this, SLOT(set_mixrulePAR4(int)));
Chris@634 4884 // connect(equivalence_rule, SIGNAL(toggled(bool)), mix_rule1, SLOT()
Chris@634 4885
Chris@634 4886 // GROUPS
Chris@634 4887 QGroupBox *group_box = new QGroupBox(QString::fromUtf8("GROUPS"),this);
Chris@634 4888 group_box->setFont(QFont("Times", 9, QFont::Bold));
Chris@634 4889 group_box->move(5,150);
Chris@634 4890 group_box->resize(580,100);
Chris@634 4891
Chris@634 4892 group_label = new QLabel(this);
Chris@634 4893 group_label->setText("Select tracks for the group:");
Chris@634 4894 group_label->setGeometry(20, 165, 200, 20);
Chris@634 4895
Chris@634 4896 QButtonGroup *group_cb = new QButtonGroup(this);
Chris@634 4897 group_cb->setObjectName("Group");
Chris@634 4898
Chris@634 4899 for (int i=1; i<=numtracks; i++) {
Chris@634 4900 QCheckBox *track_cb = new QCheckBox(QString::number(i), this);
Chris@634 4901 track_cb->setGeometry(80*i,185,95,30);
Chris@634 4902 track_cb->setObjectName(QString::number(i));
Chris@634 4903 group_cb->setExclusive(false);
Chris@634 4904 group_cb->addButton(track_cb);
Chris@634 4905 }
Chris@634 4906
Chris@634 4907 QSpinBox *group_vol = new QSpinBox(this);
Chris@634 4908 group_vol->setEnabled(true);
Chris@634 4909 group_vol->setGeometry(QRect(280, 220, 40, 20));
Chris@634 4910 group_vol->setMinimum(0);
Chris@634 4911 group_vol->setMaximum(100);
Chris@634 4912 group_vol->setValue(100);
Chris@634 4913 group_volume = group_vol->value();
Chris@634 4914
Chris@634 4915 grp_vol = new QLabel(this);
Chris@634 4916 grp_vol->setText("Group Volume");
Chris@634 4917 grp_vol->setGeometry(330, 220, 100, 20);
Chris@634 4918
Chris@634 4919 group_name_line = new QLineEdit(this);
Chris@634 4920 group_name_line->setGeometry(25,220,150,20);
Chris@634 4921 group_name_line->setText("Insert a name");
Chris@634 4922 group_name_line->setMaxLength(20);
Chris@634 4923
Chris@634 4924 grp_name = new QLabel(this);
Chris@634 4925 grp_name->setText("Group Name");
Chris@634 4926 grp_name->setGeometry(180,220,100,20);
Chris@634 4927
Chris@634 4928 connect(group_cb, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(set_TrackInGroup(QAbstractButton*)));
Chris@634 4929 connect(group_name_line, SIGNAL(textChanged(QString)), this, SLOT(set_GroupName(QString)));
Chris@634 4930 connect(group_vol, SIGNAL(valueChanged(int)), this, SLOT(set_GroupVolume(int)));
Chris@634 4931
Chris@634 4932 // PRESETS
Chris@634 4933 QGroupBox *preset_box = new QGroupBox(QString::fromUtf8("PRESETS"),this);
Chris@634 4934 preset_box->setFont(QFont("Times", 9, QFont::Bold));
Chris@634 4935 preset_box->move(5,270);
Chris@634 4936 preset_box->resize(580,90);
Chris@634 4937
Chris@634 4938 QButtonGroup *preset_group = new QButtonGroup(this);
Chris@634 4939 preset_group->setObjectName("Presets");
Chris@634 4940
Chris@634 4941 QRadioButton *static_preset = new QRadioButton(QString::fromUtf8("Static Volume"),this);
Chris@634 4942 static_preset->move(20,290);
Chris@634 4943 static_preset->setObjectName("0");
Chris@634 4944
Chris@634 4945 QRadioButton *dynamic_preset = new QRadioButton(QString::fromUtf8("Dynamic Volume"),this);
Chris@634 4946 dynamic_preset->move(150,290);
Chris@634 4947 dynamic_preset->setObjectName("4");
Chris@634 4948
Chris@634 4949 preset_group->addButton(static_preset);
Chris@634 4950 preset_group->addButton(dynamic_preset);
Chris@634 4951
Chris@634 4952 QButtonGroup *fade_group = new QButtonGroup(this);
Chris@634 4953 fade_group->setObjectName("Fade IN/OUT");
Chris@634 4954
Chris@634 4955 QRadioButton *fade_in = new QRadioButton(QString::fromUtf8("Fade IN"),this);
Chris@634 4956 fade_in->move(170,310);
Chris@634 4957 fade_in->setObjectName("1");
Chris@634 4958 fade_in->setDisabled(true);
Chris@634 4959
Chris@634 4960 QRadioButton *fade_out = new QRadioButton(QString::fromUtf8("Fade OUT"),this);
Chris@634 4961 fade_out->move(170,330);
Chris@634 4962 fade_out->setObjectName("0");
Chris@634 4963 fade_out->setDisabled(true);
Chris@634 4964
Chris@634 4965 fade_group->addButton(fade_in);
Chris@634 4966 fade_group->addButton(fade_out);
Chris@634 4967
Chris@634 4968 connect(preset_group, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(set_presetType(QAbstractButton*)));
Chris@634 4969 connect(dynamic_preset, SIGNAL(toggled(bool)), fade_in, SLOT(setEnabled(bool)));
Chris@634 4970 connect(dynamic_preset, SIGNAL(toggled(bool)), fade_out, SLOT(setEnabled(bool)));
Chris@634 4971 connect(fade_group, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(set_fade(QAbstractButton*)));
Chris@634 4972
Chris@634 4973
Chris@634 4974 // IMAGE AND LYRICS
Chris@634 4975 QCheckBox *text_cb = new QCheckBox("Include lyrics", this);
Chris@634 4976 text_cb->setGeometry(20, 380, 95, 30);
Chris@634 4977 QCheckBox *jpeg_cb = new QCheckBox("Include picture", this);
Chris@634 4978 jpeg_cb->setGeometry(20, 430, 95, 30);
Chris@634 4979
Chris@634 4980 line->setGeometry(120, 380, 320, 30);
Chris@634 4981 line2->setGeometry(120, 430, 320, 30);
Chris@634 4982
Chris@634 4983 QPushButton *create = new QPushButton("Export", this);
Chris@634 4984 create->setGeometry(20, 500, 95, 30);
Chris@634 4985
Chris@634 4986 QPushButton *TextFilePath = new QPushButton("Select text file", this);
Chris@634 4987 TextFilePath->setGeometry(460, 380, 95, 30);
Chris@634 4988 TextFilePath->setDisabled(true);
Chris@634 4989
Chris@634 4990 QPushButton *JpegFilePath = new QPushButton("Select JPEG file", this);
Chris@634 4991 JpegFilePath->setGeometry(460, 430, 95, 30);
Chris@634 4992 JpegFilePath->setDisabled(true);
Chris@634 4993
Chris@634 4994 // Enable/disable push buttons
Chris@634 4995 connect(text_cb, SIGNAL(toggled(bool)), TextFilePath, SLOT(setEnabled(bool)));
Chris@634 4996 connect(jpeg_cb, SIGNAL(toggled(bool)), JpegFilePath, SLOT(setEnabled(bool)));
Chris@634 4997 // Check the inclusion of image and text
Chris@634 4998 connect(text_cb, SIGNAL(stateChanged(int)), this, SLOT(insertLyrics(int))); // yet to implement
Chris@634 4999 connect(jpeg_cb, SIGNAL(stateChanged(int)), this, SLOT(insertImage(int)));
Chris@634 5000 // Set image and text paths
Chris@634 5001 connect(TextFilePath, SIGNAL(clicked()), this , SLOT(defineImafTextFile()));
Chris@634 5002 connect(JpegFilePath, SIGNAL(clicked()), this , SLOT(defineImafImageFile()));
Chris@634 5003 // Create the file
Chris@634 5004 connect(create, SIGNAL(clicked()), this , SLOT(saveImafFile()));
Chris@634 5005 connect(create, SIGNAL(clicked()), this, SLOT(close()));
Chris@634 5006 }
Chris@634 5007
Chris@634 5008 void CheckBox::insertImage(int state)
Chris@634 5009 {
Chris@634 5010 if (state) {
Chris@634 5011 has_image = true;
Chris@634 5012 } else{
Chris@634 5013 has_image = false;
Chris@634 5014 }
Chris@634 5015 }
Chris@634 5016
Chris@634 5017 void CheckBox::insertLyrics(int state)
Chris@634 5018 {
Chris@634 5019 if (state) {
Chris@634 5020 has_lyrics = true;
Chris@634 5021 } else{
Chris@634 5022 has_lyrics = false;
Chris@634 5023 }
Chris@634 5024 }
Chris@634 5025
Chris@634 5026 void CheckBox::saveImafFile()
Chris@634 5027 {
Chris@634 5028 ImafFileName = QFileDialog::getSaveFileName(this, tr("Save IMAF"), "/", tr("IMAF (*.ima)"));
Chris@634 5029
Chris@634 5030 group_descr = "Thisgroup";
Chris@634 5031
Chris@634 5032 if( ImafFileName != "" ){ //if the user press cancel the function mainIMAFencoder won´t be called
Chris@634 5033 mainIMAFencoder(numtracks, files_paths, ImafFileName, ImageFileName, TextFileName,
Chris@636 5034 ImafVolumeValues, has_image, has_lyrics, selrule_type, selrule_par1, selrule_par2,
Chris@634 5035 mixrule_type, mixrule_par1, mixrule_par2, mixrule_par3, mixrule_par4,
Chris@634 5036 group_tracks, group_volume, group_name, group_descr, preset_type, fade_in);
Chris@634 5037 }
Chris@634 5038 }
Chris@634 5039
Chris@634 5040 void CheckBox::defineImafImageFile()
Chris@634 5041 {
Chris@634 5042 ImageFileName = QFileDialog::getOpenFileName(this, tr("Select JPEG"), "/", tr("JPEG (*.jpg)"));
Chris@634 5043 line2->setText(ImageFileName);
Chris@634 5044 }
Chris@634 5045
Chris@634 5046 void CheckBox::defineImafTextFile()
Chris@634 5047 {
Chris@634 5048 TextFileName = QFileDialog::getOpenFileName(this, tr("Select text file"), "/", tr("Text File (*.3gp)"));
Chris@634 5049 line->setText(TextFileName);
Chris@634 5050 }
Chris@634 5051
Chris@634 5052 void
Chris@634 5053 MainWindow::exportIMAF()
Chris@634 5054 {
Chris@634 5055 numtracks = m_paneStack->getPaneCount();
Chris@634 5056
Chris@634 5057 for (int i = 0; i < numtracks; ++i) {
Chris@634 5058 //ImafVolumeValues[i] = int(m_paneStack->getPane(i)->getLayer(0)->getPlayParameters()->getVolImaf())/2;
Chris@634 5059 }
Chris@634 5060
Chris@634 5061 CheckBox *imaf_window = new CheckBox();
Chris@634 5062
Chris@634 5063 imaf_window->resize(600,540);
Chris@634 5064 imaf_window->move(100,100);
Chris@634 5065 imaf_window->setWindowTitle("Export IMAF");
Chris@634 5066 imaf_window->show();
Chris@634 5067 }
Chris@634 5068
Chris@634 5069
Chris@634 5070
Chris@634 5071 void MainWindow::insertLyrics(size_t frame, QString text){
Chris@634 5072 Pane *pane = m_paneStack->getCurrentPane();
Chris@634 5073
Chris@634 5074
Chris@634 5075 pane = m_paneStack->getCurrentPane();
Chris@634 5076 if (!pane) {
Chris@634 5077 return;
Chris@634 5078 }
Chris@634 5079
Chris@634 5080 frame = pane->alignFromReference(frame);
Chris@634 5081
Chris@634 5082 Layer *layer = dynamic_cast<TimeInstantLayer *>
Chris@634 5083 (pane->getSelectedLayer());
Chris@634 5084
Chris@634 5085 if (!layer) {
Chris@634 5086 for (int i = pane->getLayerCount(); i > 0; --i) {
Chris@634 5087 layer = dynamic_cast<TimeInstantLayer *>(pane->getLayer(i - 1));
Chris@634 5088 if (layer) break;
Chris@634 5089 }
Chris@634 5090
Chris@634 5091 if (!layer) {
Chris@634 5092 CommandHistory::getInstance()->startCompoundOperation
Chris@634 5093 (tr("Add Point"), true);
Chris@634 5094 layer = m_document->createEmptyLayer(LayerFactory::TimeInstants);
Chris@634 5095 if (layer) {
Chris@634 5096 m_document->addLayerToView(pane, layer);
Chris@634 5097 m_paneStack->setCurrentLayer(pane, layer);
Chris@634 5098 }
Chris@634 5099 CommandHistory::getInstance()->endCompoundOperation();
Chris@634 5100 }
Chris@634 5101 }
Chris@634 5102
Chris@634 5103 if (layer) {
Chris@634 5104
Chris@634 5105 Model *model = layer->getModel();
Chris@634 5106 SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *>
Chris@634 5107 (model);
Chris@634 5108
Chris@634 5109 if (sodm) {
Chris@634 5110 SparseOneDimensionalModel::Point point(frame, "");
Chris@634 5111
Chris@634 5112 SparseOneDimensionalModel::Point prevPoint(0);
Chris@634 5113 bool havePrevPoint = false;
Chris@634 5114
Chris@634 5115 SparseOneDimensionalModel::EditCommand *command =
Chris@634 5116 new SparseOneDimensionalModel::EditCommand(sodm, tr("Add Point"));
Chris@634 5117
Chris@634 5118 if (m_labeller->requiresPrevPoint()) {
Chris@634 5119
Chris@634 5120 SparseOneDimensionalModel::PointList prevPoints =
Chris@634 5121 sodm->getPreviousPoints(frame);
Chris@634 5122
Chris@634 5123 if (!prevPoints.empty()) {
Chris@634 5124 prevPoint = *prevPoints.begin();
Chris@634 5125 havePrevPoint = true;
Chris@634 5126 }
Chris@634 5127 }
Chris@634 5128
Chris@634 5129 if (m_labeller) {
Chris@634 5130
Chris@634 5131 m_labeller->setSampleRate(sodm->getSampleRate());
Chris@634 5132
Chris@634 5133 if (m_labeller->actingOnPrevPoint()) {
Chris@634 5134 command->deletePoint(prevPoint);
Chris@634 5135 }
Chris@634 5136
Chris@634 5137 m_labeller->label<SparseOneDimensionalModel::Point>
Chris@634 5138 (point, havePrevPoint ? &prevPoint : 0);
Chris@634 5139
Chris@634 5140 if (m_labeller->actingOnPrevPoint()) {
Chris@634 5141 command->addPoint(prevPoint);
Chris@634 5142 }
Chris@634 5143 }
Chris@634 5144 point.label=text;
Chris@634 5145 command->addPoint(point);
Chris@634 5146
Chris@634 5147 command->setName(tr("Add Point at %1 s")
Chris@634 5148 .arg(RealTime::frame2RealTime
Chris@634 5149 (frame,
Chris@634 5150 sodm->getSampleRate())
Chris@634 5151 .toText(false).c_str()));
Chris@634 5152
Chris@634 5153 Command *c = command->finish();
Chris@634 5154 if (c) CommandHistory::getInstance()->addCommand(c, false);
Chris@634 5155 }
Chris@634 5156 }
Chris@634 5157
Chris@634 5158 }
Chris@634 5159
Chris@634 5160 void MainWindow::importIMAF()
Chris@634 5161 {
Chris@634 5162
Chris@634 5163 int haslyrics; // if this variable != 2 -> there are lyrics
alo@1032 5164 QString path = getOpenFileName(FileFinder::IMAFile);
alo@1032 5165
alo@1032 5166 if (path.isEmpty()) return;
Chris@636 5167 isIMAF = true;
Chris@636 5168
alo@1032 5169 haslyrics = mainIMAFdecoder(path);
Chris@634 5170
Chris@634 5171 openMP3IMAF();
Chris@634 5172
Chris@634 5173 if (haslyrics!=2){
Chris@634 5174 addPaneToStack();//it creates a new pane to show the lyrics
Chris@634 5175
Chris@634 5176 Pane *pane = m_paneStack->getCurrentPane();
Chris@634 5177 LayerFactory::LayerType type ; //set the type of layer
Chris@634 5178 type = LayerFactory::TimeInstants;
Chris@634 5179 //create a new layer
Chris@634 5180 Layer *newLayer = 0;
Chris@634 5181 newLayer = m_document->createEmptyLayer(type);
Chris@634 5182 m_toolActions[ViewManager::DrawMode]->trigger();
Chris@634 5183 m_document->addLayerToView(pane, newLayer);
Chris@634 5184
Chris@634 5185 //create a new layer
Chris@634 5186 Layer *newLayer1 = 0;
Chris@634 5187 newLayer1 = m_document->createEmptyLayer(type);
Chris@634 5188 m_toolActions[ViewManager::DrawMode]->trigger();
Chris@634 5189 m_document->addLayerToView(pane, newLayer1);
Chris@634 5190 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@634 5191
Chris@634 5192 //editCurrentLayer();
Chris@634 5193
Chris@634 5194 //text decoder
Chris@634 5195 unsigned char dat,dat1,dat2,dat3;
Chris@634 5196 FILE *imf;
alo@1032 5197 imf = fopen (path.toStdString().c_str(),"rb");
Chris@634 5198
Chris@634 5199 fseek (imf,0,SEEK_SET);
Chris@634 5200 fseek (imf,24,SEEK_CUR); //jump to 'mdat'
Chris@634 5201 fread(&dat, sizeof(unsigned char), 1, imf);
Chris@634 5202 fread(&dat1, sizeof(unsigned char), 1, imf);
Chris@634 5203 fread(&dat2, sizeof(unsigned char), 1, imf);
Chris@634 5204 fread(&dat3, sizeof(unsigned char), 1, imf);
Chris@634 5205 int sizemdat = (dat<<24) | (dat1<<16) | (dat2<<8) | (dat3);
Chris@634 5206 fseek(imf, sizemdat-4, SEEK_CUR); // -4 because we have to sub the 4 bytes of size
Chris@634 5207
Chris@634 5208 fseek (imf,16,SEEK_CUR);
Chris@634 5209 fseek (imf,96,SEEK_CUR); // next track id is placed 96 bytes after the last byte of type 'mvhd'
Chris@634 5210
Chris@634 5211 fread(&dat, sizeof(unsigned char), 1, imf);
Chris@634 5212 fread(&dat1, sizeof(unsigned char), 1, imf);
Chris@634 5213 fread(&dat2, sizeof(unsigned char), 1, imf);
Chris@634 5214 fread(&dat3, sizeof(unsigned char), 1, imf);
Chris@634 5215
Chris@634 5216
Chris@634 5217 audiotracks = ((dat<<24) | (dat1<<16) | (dat2<<8) | (dat3)) -1 ; //read the number of audio tracks.It is ´-1´ because the field indicates the number of tracks +1
Chris@634 5218
Chris@634 5219 fread(&dat, sizeof(unsigned char), 1, imf);//read the size of trak.Every track must be the same size
Chris@634 5220 fread(&dat1, sizeof(unsigned char), 1, imf);
Chris@634 5221 fread(&dat2, sizeof(unsigned char), 1, imf);
Chris@634 5222 fread(&dat3, sizeof(unsigned char), 1, imf);
Chris@634 5223
Chris@634 5224 int sizetrak = ((dat<<24) | (dat1<<16) | (dat2<<8) | (dat3));
Chris@634 5225
Chris@634 5226 fseek(imf, (sizetrak-4)*audiotracks, SEEK_CUR);
Chris@634 5227
Chris@634 5228 int d=0;
Chris@634 5229 while (d==0){
Chris@634 5230
Chris@634 5231 fread(&dat, sizeof(unsigned char), 1, imf);
Chris@634 5232 fread(&dat1, sizeof(unsigned char), 1, imf);
Chris@634 5233 fread(&dat2, sizeof(unsigned char), 1, imf);
Chris@634 5234 fread(&dat3, sizeof(unsigned char), 1, imf);
Chris@634 5235
Chris@634 5236
Chris@634 5237 if (dat == 0x73 && dat1 == 0x74 && dat2 == 0x74 && dat3 == 0x73) { // 73 74 74 73 = s t t s
Chris@634 5238 d=1;
Chris@634 5239 }
Chris@634 5240
Chris@634 5241 else{
Chris@634 5242 fseek(imf, -3, SEEK_CUR); //if we have not readen ´stts´
Chris@634 5243 }
Chris@634 5244
Chris@634 5245 } //close while
Chris@634 5246
Chris@634 5247 fread(&dat, sizeof(unsigned char), 1, imf);//avanzamos 4 bytes (son los 4 bytes de version)
Chris@634 5248 fread(&dat, sizeof(unsigned char), 1, imf);
Chris@634 5249 fread(&dat, sizeof(unsigned char), 1, imf);
Chris@634 5250 fread(&dat, sizeof(unsigned char), 1, imf);
Chris@634 5251
Chris@634 5252 fread(&dat, sizeof(unsigned char), 1, imf);//estos 4 bytes son los de número de entradas de la tabla (entry_count)
Chris@634 5253 fread(&dat1, sizeof(unsigned char), 1, imf);
Chris@634 5254 fread(&dat2, sizeof(unsigned char), 1, imf);
Chris@634 5255 fread(&dat3, sizeof(unsigned char), 1, imf);
Chris@634 5256
Chris@634 5257 int entry_count = ((dat<<24) | (dat1<<16) | (dat2<<8) | (dat3));
Chris@634 5258
Chris@634 5259 int sample_count [entry_count];
Chris@634 5260 int sample_delta [entry_count];
Chris@634 5261
Chris@634 5262 for (int i=0;i<entry_count;i++){
Chris@634 5263
Chris@634 5264
Chris@634 5265 fread(&dat, sizeof(unsigned char), 1, imf);
Chris@634 5266 fread(&dat1, sizeof(unsigned char), 1, imf);
Chris@634 5267 fread(&dat2, sizeof(unsigned char), 1, imf);
Chris@634 5268 fread(&dat3, sizeof(unsigned char), 1, imf);
Chris@634 5269
Chris@634 5270 sample_count[i] = ((dat<<24) | (dat1<<16) | (dat2<<8) | (dat3));
Chris@634 5271
Chris@634 5272 fread(&dat, sizeof(unsigned char), 1, imf);
Chris@634 5273 fread(&dat1, sizeof(unsigned char), 1, imf);
Chris@634 5274 fread(&dat2, sizeof(unsigned char), 1, imf);
Chris@634 5275 fread(&dat3, sizeof(unsigned char), 1, imf);
Chris@634 5276
Chris@634 5277
Chris@634 5278 sample_delta[i] = ((dat<<24) | (dat1<<16) | (dat2<<8) | (dat3));
Chris@634 5279
Chris@634 5280 }
Chris@634 5281
Chris@634 5282 d=0;
Chris@634 5283 while (d==0){
Chris@634 5284
Chris@634 5285 fread(&dat, sizeof(unsigned char), 1, imf);
Chris@634 5286 fread(&dat1, sizeof(unsigned char), 1, imf);
Chris@634 5287 fread(&dat2, sizeof(unsigned char), 1, imf);
Chris@634 5288 fread(&dat3, sizeof(unsigned char), 1, imf);
Chris@634 5289
Chris@634 5290 if (dat == 0x73 && dat1 == 0x74 && dat2 == 0x73 && dat3 == 0x7A) { // 73 74 73 7A = s t s z
Chris@634 5291 d=1;
Chris@634 5292 }
Chris@634 5293
Chris@634 5294 else{
Chris@634 5295 fseek(imf, -3, SEEK_CUR); //if we have not readen ´stts´
Chris@634 5296 }
Chris@634 5297
Chris@634 5298 } //close while
Chris@634 5299
Chris@634 5300 for (int i=1;i<=8;i++){ //avanzamos 8 posiciones
Chris@634 5301
Chris@634 5302 fread(&dat, sizeof(unsigned char), 1, imf);
Chris@634 5303
Chris@634 5304 }
Chris@634 5305
Chris@634 5306 fread(&dat, sizeof(unsigned char), 1, imf); //read sample_count
Chris@634 5307 fread(&dat1, sizeof(unsigned char), 1, imf);
Chris@634 5308 fread(&dat2, sizeof(unsigned char), 1, imf);
Chris@634 5309 fread(&dat3, sizeof(unsigned char), 1, imf);
Chris@634 5310
Chris@634 5311 int samplecount = ((dat<<24) | (dat1<<16) | (dat2<<8) | (dat3));
Chris@634 5312 int sample_size[samplecount];
Chris@634 5313 for (int i=0;i<samplecount;i++){
Chris@634 5314
Chris@634 5315 fread(&dat, sizeof(unsigned char), 1, imf);
Chris@634 5316 fread(&dat1, sizeof(unsigned char), 1, imf);
Chris@634 5317 fread(&dat2, sizeof(unsigned char), 1, imf);
Chris@634 5318 fread(&dat3, sizeof(unsigned char), 1, imf);
Chris@634 5319
Chris@634 5320 sample_size[i] = ((dat<<24) | (dat1<<16) | (dat2<<8) | (dat3));// the size of every string including modifiers
Chris@634 5321
Chris@634 5322 }
Chris@634 5323
Chris@634 5324 d=0;
Chris@634 5325 while (d==0){
Chris@634 5326
Chris@634 5327 fread(&dat, sizeof(unsigned char), 1, imf);
Chris@634 5328 fread(&dat1, sizeof(unsigned char), 1, imf);
Chris@634 5329 fread(&dat2, sizeof(unsigned char), 1, imf);
Chris@634 5330 fread(&dat3, sizeof(unsigned char), 1, imf);
Chris@634 5331
Chris@634 5332 if (dat == 0x63 && dat1 == 0x6F && dat2 == 0x36 && dat3 == 0x34) { // 63 6F 36 34 = c o 6 4
Chris@634 5333 d=1;
Chris@634 5334 }
Chris@634 5335
Chris@634 5336 else{
Chris@634 5337 fseek(imf, -3, SEEK_CUR); //if we have not readen ´stts´
Chris@634 5338 }
Chris@634 5339
Chris@634 5340 } //close while
Chris@634 5341
Chris@634 5342 for (int i=1;i<=12;i++){ //advance 12 memory bytes
Chris@634 5343
Chris@634 5344 fread(&dat, sizeof(unsigned char), 1, imf);
Chris@634 5345
Chris@634 5346 }
Chris@634 5347
Chris@634 5348 fread(&dat, sizeof(unsigned char), 1, imf); //read co64 box
Chris@634 5349 fread(&dat1, sizeof(unsigned char), 1, imf);
Chris@634 5350 fread(&dat2, sizeof(unsigned char), 1, imf);
Chris@634 5351 fread(&dat3, sizeof(unsigned char), 1, imf);
Chris@634 5352
Chris@634 5353 int chunk_offset = ((dat<<24) | (dat1<<16) | (dat2<<8) | (dat3));
Chris@634 5354
Chris@634 5355 fseek (imf,0,SEEK_SET);
Chris@634 5356 fseek (imf,chunk_offset,SEEK_CUR); //jump to the position where starts text strings
Chris@634 5357
Chris@634 5358 int num_modifiers;
Chris@634 5359 float duration1;
Chris@634 5360 for (int j=0;j<samplecount;j++){
Chris@634 5361
Chris@634 5362 fread(&dat, sizeof(unsigned char), 1, imf); // read sizestring
Chris@634 5363 fread(&dat1, sizeof(unsigned char), 1, imf);
Chris@634 5364
Chris@634 5365 int sizestring = ((dat<<8) | (dat1));
Chris@634 5366
Chris@634 5367 char text [sizestring+1];
Chris@634 5368
Chris@634 5369 for (int i=0;i<sizestring;i++){
Chris@634 5370 fread(&dat, sizeof(unsigned char), 1, imf);
Chris@634 5371 text [i] = dat;
Chris@634 5372 }
Chris@634 5373 text[sizestring]= '\0';// indicates the end of the char string.If we don´t add this character, the conversion to QString does not work
Chris@634 5374 num_modifiers = sample_size[j]-sizestring-2;
Chris@634 5375
Chris@634 5376 for (int i=0;i<num_modifiers;i++){
Chris@634 5377 fread(&dat, sizeof(unsigned char), 1, imf);
Chris@634 5378 }
Chris@634 5379 QString result (text);//convert string char to QString
Chris@634 5380 duration1=0;
Chris@634 5381 for (int h=0;h<j;h++){
Chris@634 5382 duration1 = sample_delta[h]+duration1;
Chris@634 5383 }
Chris@634 5384 float duration2 = duration1 / 1000;
Chris@634 5385 int duration3 = duration2 * 44100;
Chris@634 5386 if (sizestring >1){ //sizestring = 1 when there is only a blank space.We do not want to add a blank space alone.
Chris@634 5387
Chris@634 5388 if (samplecount%2==0){//to avoid overlapping
Chris@634 5389 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@634 5390 insertLyrics (duration3, result);
Chris@634 5391 }
Chris@634 5392 else{
Chris@634 5393 m_paneStack->setCurrentLayer(pane, newLayer1);
Chris@634 5394 insertLyrics (duration3, result);
Chris@634 5395 }
Chris@634 5396
Chris@634 5397
Chris@634 5398 } // close if
Chris@634 5399 } //close for
Chris@634 5400 } // close if haslyrics
Chris@634 5401
Chris@634 5402 }
Chris@634 5403 void
Chris@634 5404 MainWindow::openMP3IMAF()
Chris@634 5405 {
Chris@634 5406 FileOpenStatus status;
Chris@634 5407
Chris@634 5408 for (int i=0;i<audiotracks;i++){
Chris@634 5409
Chris@634 5410 char buf[2];
Chris@634 5411 sprintf(buf, "%d", i); //convert int to char
Chris@1150 5412 status = openPath(buf, CreateAdditionalModel);
Chris@634 5413 remove (buf);
Chris@634 5414
Chris@634 5415 }
Chris@634 5416
Chris@634 5417 }
Chris@1150 5418
Chris@634 5419 void CheckBox::set_selruleType(QAbstractButton *button)
Chris@634 5420 {
Chris@634 5421 selrule_type = button->objectName().toInt();
Chris@634 5422
Chris@634 5423 if( (selrule_type == 0) || (selrule_type == 1) || (selrule_type == 3) ){
Chris@634 5424 sel_rule1->setText("Track A");
Chris@634 5425 sel_rule1->setDisabled(false);
Chris@634 5426 sel_rule2->setText("Track B");
Chris@634 5427 sel_rule2->setDisabled(false);
Chris@634 5428 }else{
Chris@634 5429 sel_rule1->setText("Track A");
Chris@634 5430 sel_rule1->setDisabled(false);
Chris@634 5431 sel_rule2->setDisabled(true);
Chris@634 5432 }
Chris@634 5433 }
Chris@634 5434
Chris@634 5435 void CheckBox::set_selrulePAR1(int value)
Chris@634 5436 {
Chris@634 5437 selrule_par1 = value; // TRACK A
Chris@634 5438 }
Chris@634 5439
Chris@634 5440 void CheckBox::set_selrulePAR2(int value)
Chris@634 5441 {
Chris@634 5442 selrule_par2 = value; // TRACK B
Chris@634 5443 }
Chris@634 5444
Chris@634 5445 void CheckBox::set_mixruleType(QAbstractButton *button)
Chris@634 5446 {
Chris@634 5447 mixrule_type = button->objectName().toInt();
Chris@634 5448
Chris@634 5449 if( (mixrule_type == 0) || (mixrule_type == 1) || (mixrule_type == 2) ){
Chris@634 5450 mix_rule1->setText("Track A");
Chris@634 5451 mix_rule1->setDisabled(false);
Chris@634 5452 mix_rule2->setText("Track B");
Chris@634 5453 mix_rule2->setDisabled(false);
Chris@634 5454 mix_rule3->setDisabled(true);
Chris@634 5455 mix_rule4->setDisabled(true);
Chris@634 5456 }else{
Chris@634 5457 mix_rule1->setText("Track A");
Chris@634 5458 mix_rule1->setDisabled(false);
Chris@634 5459 mix_rule2->setDisabled(true);
Chris@634 5460 mix_rule3->setText("Min Volume");
Chris@634 5461 mix_rule3->setDisabled(false);
Chris@634 5462 mix_rule4->setText("Max Volume");
Chris@634 5463 mix_rule4->setDisabled(false);
Chris@634 5464 }
Chris@634 5465 }
Chris@634 5466
Chris@634 5467 void CheckBox::set_mixrulePAR1(int value)
Chris@634 5468 {
Chris@634 5469 mixrule_par1 = value; // TRACK A
Chris@634 5470 }
Chris@634 5471
Chris@634 5472 void CheckBox::set_mixrulePAR2(int value)
Chris@634 5473 {
Chris@634 5474 mixrule_par2 = value; // TRACK B
Chris@634 5475 }
Chris@634 5476
Chris@634 5477 void CheckBox::set_mixrulePAR3(int value)
Chris@634 5478 {
Chris@634 5479 mixrule_par3 = value; // MIN VOL for Limit Rule
Chris@634 5480 }
Chris@634 5481
Chris@634 5482 void CheckBox::set_mixrulePAR4(int value)
Chris@634 5483 {
Chris@634 5484 mixrule_par4 = value; // MAX VOL for Limit Rule
Chris@634 5485 }
Chris@634 5486
Chris@634 5487 void CheckBox::set_TrackInGroup(QAbstractButton *button)
Chris@634 5488 {
Chris@634 5489 int temp = button->objectName().toInt();
Chris@634 5490
Chris@634 5491 if (button->isChecked()){
Chris@634 5492 group_tracks[temp-1] = 1;
Chris@634 5493 }else{
Chris@634 5494 group_tracks[temp-1] = 0;
Chris@634 5495 }
Chris@634 5496 }
Chris@634 5497
Chris@634 5498 void CheckBox::set_GroupName(QString name)
Chris@634 5499 {
Chris@634 5500 group_name = name;
Chris@634 5501 }
Chris@634 5502
Chris@634 5503 void CheckBox::set_GroupVolume(int value)
Chris@634 5504 {
Chris@634 5505 group_volume = value;
Chris@634 5506 }
Chris@634 5507
Chris@634 5508 void CheckBox::set_presetType(QAbstractButton *button)
Chris@634 5509 {
Chris@634 5510 preset_type = button->objectName().toInt();
Chris@634 5511 }
Chris@634 5512
Chris@634 5513 void CheckBox::set_fade(QAbstractButton *button)
Chris@634 5514 {
Chris@634 5515 fade_in = button->objectName().toInt();
Chris@634 5516 }