annotate main/MainWindow.cpp @ 677:bfd68cc71a25 imaf_enc

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