annotate main/MainWindow.cpp @ 656:51bf4d43a1c0 imaf_enc

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