annotate main/MainWindow.cpp @ 634:ba338234c001 imaf_enc

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