annotate main/MainWindow.cpp @ 636:767789a78984 imaf_enc

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