annotate src/MainWindow.cpp @ 429:9dad69cbf452

Wire options into CSVFileWriter; omit levels from Tony note export
author Chris Cannam
date Tue, 31 Mar 2015 11:05:02 +0100
parents 46003a5a8736
children 548433164338
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 Tony
Chris@0 5 An intonation analysis and annotation tool
Chris@0 6 Centre for Digital Music, Queen Mary, University of London.
Chris@0 7 This file copyright 2006-2012 Chris Cannam and QMUL.
Chris@0 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@0 16 #include "../version.h"
Chris@0 17
Chris@0 18 #include "MainWindow.h"
Chris@95 19 #include "NetworkPermissionTester.h"
Chris@6 20 #include "Analyser.h"
Chris@6 21
Chris@0 22 #include "framework/Document.h"
Chris@95 23 #include "framework/VersionTester.h"
Chris@0 24
Chris@0 25 #include "view/Pane.h"
Chris@0 26 #include "view/PaneStack.h"
Chris@0 27 #include "data/model/WaveFileModel.h"
matthiasm@26 28 #include "data/model/NoteModel.h"
matthiasm@26 29 #include "data/model/FlexiNoteModel.h"
matthiasm@42 30 #include "layer/FlexiNoteLayer.h"
matthiasm@26 31 #include "data/model/NoteModel.h"
Chris@0 32 #include "view/ViewManager.h"
Chris@0 33 #include "base/Preferences.h"
Chris@404 34 #include "base/AudioLevel.h"
Chris@0 35 #include "layer/WaveformLayer.h"
Chris@0 36 #include "layer/TimeInstantLayer.h"
Chris@0 37 #include "layer/TimeValueLayer.h"
Chris@192 38 #include "layer/SpectrogramLayer.h"
Chris@0 39 #include "widgets/Fader.h"
Chris@0 40 #include "view/Overview.h"
Chris@0 41 #include "widgets/AudioDial.h"
Chris@0 42 #include "widgets/IconLoader.h"
Chris@0 43 #include "widgets/KeyReference.h"
Chris@414 44 #include "widgets/LevelPanToolButton.h"
Chris@0 45 #include "audioio/AudioCallbackPlaySource.h"
Chris@0 46 #include "audioio/AudioCallbackPlayTarget.h"
Chris@0 47 #include "audioio/PlaySpeedRangeMapper.h"
Chris@0 48 #include "base/Profiler.h"
Chris@0 49 #include "base/UnitDatabase.h"
Chris@0 50 #include "layer/ColourDatabase.h"
Chris@139 51 #include "base/Selection.h"
Chris@0 52
Chris@174 53 #include "rdf/RDFImporter.h"
Chris@174 54 #include "data/fileio/DataFileReaderFactory.h"
Chris@174 55 #include "data/fileio/CSVFormat.h"
matthiasm@26 56 #include "data/fileio/CSVFileWriter.h"
matthiasm@26 57 #include "data/fileio/MIDIFileWriter.h"
matthiasm@26 58 #include "rdf/RDFExporter.h"
matthiasm@26 59
Chris@227 60 #include "widgets/RangeInputDialog.h"
Chris@244 61 #include "widgets/ActivityLog.h"
Chris@227 62
Chris@0 63 // For version information
Chris@0 64 #include "vamp/vamp.h"
Chris@0 65 #include "vamp-sdk/PluginBase.h"
Chris@0 66 #include "plugin/api/ladspa.h"
Chris@0 67 #include "plugin/api/dssi.h"
Chris@0 68
Chris@0 69 #include <QApplication>
Chris@0 70 #include <QMessageBox>
Chris@0 71 #include <QGridLayout>
Chris@0 72 #include <QLabel>
Chris@0 73 #include <QMenuBar>
Chris@0 74 #include <QToolBar>
Chris@0 75 #include <QToolButton>
Chris@0 76 #include <QInputDialog>
Chris@0 77 #include <QStatusBar>
Chris@0 78 #include <QFileInfo>
Chris@0 79 #include <QDir>
Chris@0 80 #include <QProcess>
Chris@2 81 #include <QPushButton>
Chris@0 82 #include <QSettings>
Chris@0 83 #include <QScrollArea>
Chris@128 84 #include <QPainter>
Chris@413 85 #include <QWidgetAction>
Chris@0 86
Chris@0 87 #include <iostream>
Chris@0 88 #include <cstdio>
Chris@0 89 #include <errno.h>
Chris@0 90
Chris@0 91 using std::vector;
Chris@0 92
Chris@0 93
matthiasm@364 94 MainWindow::MainWindow(bool withAudioOutput, bool withSonification, bool withSpectrogram) :
Chris@277 95 MainWindowBase(withAudioOutput, false),
Chris@0 96 m_overview(0),
Chris@0 97 m_mainMenusCreated(false),
Chris@0 98 m_playbackMenu(0),
gyorgyf@45 99 m_recentFilesMenu(0),
Chris@0 100 m_rightButtonMenu(0),
Chris@0 101 m_rightButtonPlaybackMenu(0),
Chris@0 102 m_deleteSelectedAction(0),
Chris@0 103 m_ffwdAction(0),
Chris@0 104 m_rwdAction(0),
Chris@168 105 m_intelligentActionOn(true), //GF: !!! temporary
Chris@244 106 m_activityLog(new ActivityLog()),
matthiasm@296 107 m_keyReference(new KeyReference()),
matthiasm@364 108 m_selectionAnchor(0),
matthiasm@364 109 m_withSonification(withSonification),
matthiasm@364 110 m_withSpectrogram(withSpectrogram)
Chris@0 111 {
Chris@0 112 setWindowTitle(QApplication::applicationName());
Chris@0 113
Chris@206 114 #ifdef Q_OS_MAC
Chris@206 115 #if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0))
Chris@206 116 setUnifiedTitleAndToolBarOnMac(true);
Chris@206 117 #endif
Chris@206 118 #endif
Chris@206 119
Chris@0 120 UnitDatabase *udb = UnitDatabase::getInstance();
Chris@0 121 udb->registerUnit("Hz");
Chris@0 122 udb->registerUnit("dB");
Chris@0 123 udb->registerUnit("s");
Chris@0 124
Chris@0 125 ColourDatabase *cdb = ColourDatabase::getInstance();
Chris@0 126 cdb->addColour(Qt::black, tr("Black"));
Chris@0 127 cdb->addColour(Qt::darkRed, tr("Red"));
Chris@0 128 cdb->addColour(Qt::darkBlue, tr("Blue"));
Chris@0 129 cdb->addColour(Qt::darkGreen, tr("Green"));
Chris@0 130 cdb->addColour(QColor(200, 50, 255), tr("Purple"));
Chris@0 131 cdb->addColour(QColor(255, 150, 50), tr("Orange"));
Chris@120 132 cdb->addColour(QColor(180, 180, 180), tr("Grey"));
Chris@0 133 cdb->setUseDarkBackground(cdb->addColour(Qt::white, tr("White")), true);
Chris@0 134 cdb->setUseDarkBackground(cdb->addColour(Qt::red, tr("Bright Red")), true);
Chris@0 135 cdb->setUseDarkBackground(cdb->addColour(QColor(30, 150, 255), tr("Bright Blue")), true);
Chris@0 136 cdb->setUseDarkBackground(cdb->addColour(Qt::green, tr("Bright Green")), true);
Chris@0 137 cdb->setUseDarkBackground(cdb->addColour(QColor(225, 74, 255), tr("Bright Purple")), true);
Chris@0 138 cdb->setUseDarkBackground(cdb->addColour(QColor(255, 188, 80), tr("Bright Orange")), true);
Chris@0 139
Chris@0 140 Preferences::getInstance()->setResampleOnLoad(true);
Chris@315 141 Preferences::getInstance()->setFixedSampleRate(44100);
Chris@0 142 Preferences::getInstance()->setSpectrogramSmoothing
Chris@0 143 (Preferences::SpectrogramInterpolated);
Chris@332 144 Preferences::getInstance()->setNormaliseAudio(true);
Chris@0 145
Chris@0 146 QSettings settings;
Chris@0 147
Chris@0 148 settings.beginGroup("MainWindow");
Chris@0 149 settings.setValue("showstatusbar", false);
Chris@0 150 settings.endGroup();
Chris@0 151
Chris@96 152 settings.beginGroup("Transformer");
Chris@96 153 settings.setValue("use-flexi-note-model", true);
Chris@96 154 settings.endGroup();
Chris@96 155
Chris@73 156 settings.beginGroup("LayerDefaults");
Chris@73 157 settings.setValue("waveform",
Chris@73 158 QString("<layer scale=\"%1\" channelMode=\"%2\"/>")
Chris@73 159 .arg(int(WaveformLayer::LinearScale))
Chris@73 160 .arg(int(WaveformLayer::MixChannels)));
Chris@73 161 settings.endGroup();
Chris@73 162
Chris@6 163 m_viewManager->setAlignMode(false);
Chris@6 164 m_viewManager->setPlaySoloMode(false);
Chris@392 165 m_viewManager->setToolMode(ViewManager::NavigateMode);
Chris@0 166 m_viewManager->setZoomWheelsEnabled(false);
Chris@6 167 m_viewManager->setIlluminateLocalFeatures(true);
matthiasm@368 168 m_viewManager->setShowWorkTitle(false);
Chris@6 169 m_viewManager->setShowCentreLine(false);
matthiasm@368 170 m_viewManager->setShowDuration(false);
Chris@213 171 m_viewManager->setOverlayMode(ViewManager::GlobalOverlays);
Chris@0 172
Chris@192 173 connect(m_viewManager, SIGNAL(selectionChangedByUser()),
Chris@192 174 this, SLOT(selectionChangedByUser()));
Chris@164 175
Chris@0 176 QFrame *frame = new QFrame;
Chris@0 177 setCentralWidget(frame);
Chris@0 178
Chris@0 179 QGridLayout *layout = new QGridLayout;
Chris@0 180
Chris@0 181 QScrollArea *scroll = new QScrollArea(frame);
Chris@0 182 scroll->setWidgetResizable(true);
Chris@0 183 scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
Chris@0 184 scroll->setFrameShape(QFrame::NoFrame);
Chris@0 185
Chris@6 186 // We have a pane stack: it comes with the territory. However, we
Chris@120 187 // have a fixed and known number of panes in it -- it isn't
Chris@120 188 // variable
Chris@0 189 m_paneStack->setLayoutStyle(PaneStack::NoPropertyStacks);
Chris@137 190 m_paneStack->setShowPaneAccessories(false);
Chris@399 191 connect(m_paneStack, SIGNAL(doubleClickSelectInvoked(sv_frame_t)),
Chris@399 192 this, SLOT(doubleClickSelectInvoked(sv_frame_t)));
Chris@0 193 scroll->setWidget(m_paneStack);
Chris@6 194
Chris@0 195 m_overview = new Overview(frame);
Chris@362 196 m_overview->setPlaybackFollow(PlaybackScrollPage);
Chris@0 197 m_overview->setViewManager(m_viewManager);
Chris@393 198 m_overview->setFixedHeight(60);
Chris@0 199 #ifndef _WIN32
Chris@0 200 // For some reason, the contents of the overview never appear if we
Chris@0 201 // make this setting on Windows. I have no inclination at the moment
Chris@0 202 // to track down the reason why.
Chris@0 203 m_overview->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
Chris@0 204 #endif
Chris@0 205 connect(m_overview, SIGNAL(contextHelpChanged(const QString &)),
Chris@0 206 this, SLOT(contextHelpChanged(const QString &)));
Chris@0 207
Chris@0 208 m_panLayer = new WaveformLayer;
Chris@0 209 m_panLayer->setChannelMode(WaveformLayer::MergeChannels);
Chris@0 210 m_panLayer->setAggressiveCacheing(true);
Chris@393 211 m_panLayer->setGain(0.5);
Chris@0 212 m_overview->addLayer(m_panLayer);
Chris@0 213
Chris@0 214 if (m_viewManager->getGlobalDarkBackground()) {
Chris@0 215 m_panLayer->setBaseColour
Chris@0 216 (ColourDatabase::getInstance()->getColourIndex(tr("Bright Green")));
Chris@0 217 } else {
Chris@0 218 m_panLayer->setBaseColour
matthiasm@13 219 (ColourDatabase::getInstance()->getColourIndex(tr("Blue")));
Chris@0 220 }
Chris@0 221
Chris@0 222 m_fader = new Fader(frame, false);
Chris@0 223 connect(m_fader, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
Chris@0 224 connect(m_fader, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
Chris@0 225
Chris@0 226 m_playSpeed = new AudioDial(frame);
Chris@343 227 m_playSpeed->setMeterColor(Qt::darkBlue);
Chris@0 228 m_playSpeed->setMinimum(0);
Chris@0 229 m_playSpeed->setMaximum(200);
Chris@0 230 m_playSpeed->setValue(100);
Chris@0 231 m_playSpeed->setFixedWidth(24);
Chris@0 232 m_playSpeed->setFixedHeight(24);
Chris@0 233 m_playSpeed->setNotchesVisible(true);
Chris@0 234 m_playSpeed->setPageStep(10);
Chris@0 235 m_playSpeed->setObjectName(tr("Playback Speedup"));
Chris@0 236 m_playSpeed->setDefaultValue(100);
Chris@0 237 m_playSpeed->setRangeMapper(new PlaySpeedRangeMapper(0, 200));
Chris@0 238 m_playSpeed->setShowToolTip(true);
Chris@0 239 connect(m_playSpeed, SIGNAL(valueChanged(int)),
gyorgyf@27 240 this, SLOT(playSpeedChanged(int)));
Chris@0 241 connect(m_playSpeed, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
Chris@0 242 connect(m_playSpeed, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
Chris@0 243
Chris@414 244 m_audioLPW = new LevelPanToolButton(frame);
Chris@404 245 m_audioLPW->setObjectName(tr("Audio Track Level and Pan"));
Chris@404 246 connect(m_audioLPW, SIGNAL(levelChanged(float)), this, SLOT(audioGainChanged(float)));
Chris@404 247 connect(m_audioLPW, SIGNAL(panChanged(float)), this, SLOT(audioPanChanged(float)));
Chris@404 248
Chris@404 249 if (m_withSonification) {
Chris@404 250
Chris@414 251 m_pitchLPW = new LevelPanToolButton(frame);
Chris@404 252 m_pitchLPW->setObjectName(tr("Pitch Track Level and Pan"));
Chris@404 253 connect(m_pitchLPW, SIGNAL(levelChanged(float)), this, SLOT(pitchGainChanged(float)));
Chris@404 254 connect(m_pitchLPW, SIGNAL(panChanged(float)), this, SLOT(pitchPanChanged(float)));
Chris@404 255
Chris@414 256 m_notesLPW = new LevelPanToolButton(frame);
Chris@404 257 m_notesLPW->setObjectName(tr("Note Track Level and Pan"));
Chris@404 258 connect(m_notesLPW, SIGNAL(levelChanged(float)), this, SLOT(notesGainChanged(float)));
Chris@404 259 connect(m_notesLPW, SIGNAL(panChanged(float)), this, SLOT(notesPanChanged(float)));
matthiasm@366 260 }
justin@160 261
Chris@0 262 layout->setSpacing(4);
Chris@6 263 layout->addWidget(m_overview, 0, 1);
Chris@6 264 layout->addWidget(scroll, 1, 1);
Chris@0 265
Chris@0 266 layout->setColumnStretch(1, 10);
Chris@0 267
Chris@0 268 frame->setLayout(layout);
Chris@0 269
gyorgyf@21 270 m_analyser = new Analyser();
Chris@128 271 connect(m_analyser, SIGNAL(layersChanged()),
Chris@128 272 this, SLOT(updateLayerStatuses()));
Chris@187 273 connect(m_analyser, SIGNAL(layersChanged()),
Chris@187 274 this, SLOT(updateMenuStates()));
gyorgyf@21 275
Chris@0 276 setupMenus();
Chris@0 277 setupToolbars();
Chris@0 278 setupHelpMenu();
Chris@0 279
Chris@0 280 statusBar();
Chris@0 281
Chris@288 282 finaliseMenus();
Chris@288 283
Chris@244 284 connect(m_viewManager, SIGNAL(activity(QString)),
Chris@244 285 m_activityLog, SLOT(activityHappened(QString)));
Chris@244 286 connect(m_playSource, SIGNAL(activity(QString)),
Chris@244 287 m_activityLog, SLOT(activityHappened(QString)));
Chris@244 288 connect(CommandHistory::getInstance(), SIGNAL(activity(QString)),
Chris@244 289 m_activityLog, SLOT(activityHappened(QString)));
Chris@244 290 connect(this, SIGNAL(activity(QString)),
Chris@244 291 m_activityLog, SLOT(activityHappened(QString)));
Chris@244 292 connect(this, SIGNAL(replacedDocument()), this, SLOT(documentReplaced()));
Chris@260 293 connect(this, SIGNAL(sessionLoaded()), this, SLOT(analyseNewMainModel()));
Chris@260 294 connect(this, SIGNAL(audioFileLoaded()), this, SLOT(analyseNewMainModel()));
Chris@244 295 m_activityLog->hide();
Chris@244 296
Chris@95 297 newSession();
Chris@6 298
Chris@95 299 settings.beginGroup("MainWindow");
Chris@95 300 settings.setValue("zoom-default", 512);
Chris@95 301 settings.endGroup();
Chris@95 302 zoomDefault();
Chris@95 303
Chris@95 304 NetworkPermissionTester tester;
Chris@95 305 bool networkPermission = tester.havePermission();
Chris@95 306 if (networkPermission) {
Chris@95 307 m_versionTester = new VersionTester
Chris@95 308 ("sonicvisualiser.org", "latest-tony-version.txt", TONY_VERSION);
Chris@95 309 connect(m_versionTester, SIGNAL(newerVersionAvailable(QString)),
Chris@95 310 this, SLOT(newerVersionAvailable(QString)));
Chris@95 311 } else {
Chris@95 312 m_versionTester = 0;
Chris@95 313 }
Chris@0 314 }
Chris@0 315
Chris@0 316 MainWindow::~MainWindow()
Chris@0 317 {
Chris@6 318 delete m_analyser;
Chris@0 319 delete m_keyReference;
Chris@0 320 Profiles::getInstance()->dump();
Chris@0 321 }
Chris@0 322
Chris@0 323 void
Chris@0 324 MainWindow::setupMenus()
Chris@0 325 {
Chris@0 326 if (!m_mainMenusCreated) {
Chris@385 327
Chris@385 328 #ifdef Q_OS_LINUX
Chris@385 329 // In Ubuntu 14.04 the window's menu bar goes missing entirely
Chris@385 330 // if the user is running any desktop environment other than Unity
Chris@385 331 // (in which the faux single-menubar appears). The user has a
Chris@385 332 // workaround, to remove the appmenu-qt5 package, but that is
Chris@385 333 // awkward and the problem is so severe that it merits disabling
Chris@385 334 // the system menubar integration altogether. Like this:
Chris@385 335 menuBar()->setNativeMenuBar(false);
Chris@385 336 #endif
Chris@385 337
Chris@0 338 m_rightButtonMenu = new QMenu();
Chris@0 339 }
Chris@0 340
Chris@0 341 if (!m_mainMenusCreated) {
Chris@0 342 CommandHistory::getInstance()->registerMenu(m_rightButtonMenu);
Chris@0 343 m_rightButtonMenu->addSeparator();
Chris@0 344 }
Chris@0 345
Chris@0 346 setupFileMenu();
Chris@0 347 setupEditMenu();
Chris@0 348 setupViewMenu();
matthiasm@317 349 setupAnalysisMenu();
Chris@0 350
Chris@0 351 m_mainMenusCreated = true;
Chris@0 352 }
Chris@0 353
Chris@0 354 void
Chris@0 355 MainWindow::setupFileMenu()
Chris@0 356 {
Chris@0 357 if (m_mainMenusCreated) return;
Chris@0 358
Chris@0 359 QMenu *menu = menuBar()->addMenu(tr("&File"));
Chris@0 360 menu->setTearOffEnabled(true);
Chris@0 361 QToolBar *toolbar = addToolBar(tr("File Toolbar"));
Chris@0 362
Chris@0 363 m_keyReference->setCategory(tr("File and Session Management"));
Chris@0 364
Chris@0 365 IconLoader il;
Chris@1 366 QIcon icon;
Chris@1 367 QAction *action;
Chris@0 368
Chris@0 369 icon = il.load("fileopen");
Chris@0 370 icon.addPixmap(il.loadPixmap("fileopen-22"));
Chris@1 371 action = new QAction(icon, tr("&Open..."), this);
Chris@0 372 action->setShortcut(tr("Ctrl+O"));
Chris@257 373 action->setStatusTip(tr("Open a session or audio file"));
Chris@0 374 connect(action, SIGNAL(triggered()), this, SLOT(openFile()));
Chris@0 375 m_keyReference->registerShortcut(action);
Chris@0 376 menu->addAction(action);
Chris@0 377 toolbar->addAction(action);
Chris@0 378
Chris@1 379 action = new QAction(tr("Open Lo&cation..."), this);
Chris@0 380 action->setShortcut(tr("Ctrl+Shift+O"));
Chris@1 381 action->setStatusTip(tr("Open a file from a remote URL"));
Chris@0 382 connect(action, SIGNAL(triggered()), this, SLOT(openLocation()));
Chris@0 383 m_keyReference->registerShortcut(action);
Chris@0 384 menu->addAction(action);
Chris@0 385
Chris@1 386 m_recentFilesMenu = menu->addMenu(tr("Open &Recent"));
Chris@0 387 m_recentFilesMenu->setTearOffEnabled(true);
Chris@0 388 setupRecentFilesMenu();
Chris@0 389 connect(&m_recentFiles, SIGNAL(recentChanged()),
Chris@0 390 this, SLOT(setupRecentFilesMenu()));
Chris@0 391
Chris@0 392 menu->addSeparator();
Chris@257 393
Chris@257 394 icon = il.load("filesave");
Chris@257 395 icon.addPixmap(il.loadPixmap("filesave-22"));
Chris@257 396 action = new QAction(icon, tr("&Save Session"), this);
Chris@257 397 action->setShortcut(tr("Ctrl+S"));
Chris@257 398 action->setStatusTip(tr("Save the current session into a %1 session file").arg(QApplication::applicationName()));
Chris@257 399 connect(action, SIGNAL(triggered()), this, SLOT(saveSession()));
Chris@257 400 connect(this, SIGNAL(canSave(bool)), action, SLOT(setEnabled(bool)));
Chris@257 401 m_keyReference->registerShortcut(action);
Chris@257 402 menu->addAction(action);
Chris@257 403 toolbar->addAction(action);
Chris@257 404
Chris@257 405 icon = il.load("filesaveas");
Chris@257 406 icon.addPixmap(il.loadPixmap("filesaveas-22"));
Chris@257 407 action = new QAction(icon, tr("Save Session &As..."), this);
Chris@257 408 action->setShortcut(tr("Ctrl+Shift+S"));
Chris@257 409 action->setStatusTip(tr("Save the current session into a new %1 session file").arg(QApplication::applicationName()));
Chris@257 410 connect(action, SIGNAL(triggered()), this, SLOT(saveSessionAs()));
Chris@313 411 connect(this, SIGNAL(canSaveAs(bool)), action, SLOT(setEnabled(bool)));
Chris@257 412 menu->addAction(action);
Chris@257 413 toolbar->addAction(action);
Chris@257 414
matthiasm@319 415 action = new QAction(tr("Save Session to Audio &Path"), this);
matthiasm@310 416 action->setShortcut(tr("Ctrl+Alt+S"));
Chris@313 417 action->setStatusTip(tr("Save the current session into a %1 session file with the same filename as the audio but a .ton extension.").arg(QApplication::applicationName()));
matthiasm@310 418 connect(action, SIGNAL(triggered()), this, SLOT(saveSessionInAudioPath()));
Chris@313 419 connect(this, SIGNAL(canSaveAs(bool)), action, SLOT(setEnabled(bool)));
matthiasm@310 420 menu->addAction(action);
matthiasm@310 421
Chris@257 422 menu->addSeparator();
Chris@257 423
Chris@253 424 action = new QAction(tr("I&mport Pitch Track Data..."), this);
Chris@253 425 action->setStatusTip(tr("Import pitch-track data from a CSV, RDF, or layer XML file"));
Chris@174 426 connect(action, SIGNAL(triggered()), this, SLOT(importPitchLayer()));
Chris@174 427 connect(this, SIGNAL(canImportLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@174 428 menu->addAction(action);
Chris@174 429
Chris@253 430 action = new QAction(tr("E&xport Pitch Track Data..."), this);
Chris@253 431 action->setStatusTip(tr("Export pitch-track data to a CSV, RDF, or layer XML file"));
Chris@85 432 connect(action, SIGNAL(triggered()), this, SLOT(exportPitchLayer()));
Chris@224 433 connect(this, SIGNAL(canExportPitchTrack(bool)), action, SLOT(setEnabled(bool)));
Chris@85 434 menu->addAction(action);
Chris@85 435
Chris@253 436 action = new QAction(tr("&Export Note Data..."), this);
Chris@253 437 action->setStatusTip(tr("Export note data to a CSV, RDF, layer XML, or MIDI file"));
Chris@85 438 connect(action, SIGNAL(triggered()), this, SLOT(exportNoteLayer()));
Chris@224 439 connect(this, SIGNAL(canExportNotes(bool)), action, SLOT(setEnabled(bool)));
matthiasm@26 440 menu->addAction(action);
matthiasm@26 441
matthiasm@26 442 menu->addSeparator();
Chris@0 443 action = new QAction(il.load("exit"), tr("&Quit"), this);
Chris@0 444 action->setShortcut(tr("Ctrl+Q"));
Chris@0 445 action->setStatusTip(tr("Exit %1").arg(QApplication::applicationName()));
Chris@0 446 connect(action, SIGNAL(triggered()), this, SLOT(close()));
Chris@0 447 m_keyReference->registerShortcut(action);
Chris@0 448 menu->addAction(action);
Chris@0 449 }
Chris@0 450
Chris@0 451 void
Chris@0 452 MainWindow::setupEditMenu()
Chris@0 453 {
Chris@0 454 if (m_mainMenusCreated) return;
Chris@0 455
Chris@0 456 QMenu *menu = menuBar()->addMenu(tr("&Edit"));
Chris@0 457 menu->setTearOffEnabled(true);
Chris@0 458 CommandHistory::getInstance()->registerMenu(menu);
Chris@126 459 menu->addSeparator();
Chris@126 460
Chris@254 461 m_keyReference->setCategory
Chris@254 462 (tr("Selection Strip Mouse Actions"));
Chris@254 463 m_keyReference->registerShortcut
Chris@254 464 (tr("Jump"), tr("Left"),
Chris@254 465 tr("Click left button to move the playback position to a time"));
Chris@254 466 m_keyReference->registerShortcut
Chris@254 467 (tr("Select"), tr("Left"),
Chris@254 468 tr("Click left button and drag to select a region of time"));
Chris@254 469 m_keyReference->registerShortcut
Chris@254 470 (tr("Select Note Duration"), tr("Double-Click Left"),
Chris@254 471 tr("Double-click left button to select the region of time corresponding to a note"));
Chris@254 472
Chris@126 473 QToolBar *toolbar = addToolBar(tr("Tools Toolbar"));
Chris@126 474
Chris@126 475 CommandHistory::getInstance()->registerToolbar(toolbar);
Chris@126 476
Chris@250 477 QActionGroup *group = new QActionGroup(this);
Chris@250 478
Chris@250 479 IconLoader il;
Chris@250 480
Chris@126 481 m_keyReference->setCategory(tr("Tool Selection"));
Chris@126 482 QAction *action = toolbar->addAction(il.load("navigate"),
Chris@126 483 tr("Navigate"));
Chris@126 484 action->setCheckable(true);
Chris@126 485 action->setChecked(true);
Chris@126 486 action->setShortcut(tr("1"));
Chris@126 487 action->setStatusTip(tr("Navigate"));
Chris@126 488 connect(action, SIGNAL(triggered()), this, SLOT(toolNavigateSelected()));
Chris@126 489 connect(this, SIGNAL(replacedDocument()), action, SLOT(trigger()));
Chris@126 490 group->addAction(action);
Chris@126 491 menu->addAction(action);
Chris@126 492 m_keyReference->registerShortcut(action);
Chris@126 493
Chris@250 494 m_keyReference->setCategory
Chris@250 495 (tr("Navigate Tool Mouse Actions"));
Chris@250 496 m_keyReference->registerShortcut
Chris@250 497 (tr("Navigate"), tr("Left"),
Chris@250 498 tr("Click left button and drag to move around"));
Chris@250 499 m_keyReference->registerShortcut
Chris@250 500 (tr("Re-Analyse Area"), tr("Shift+Left"),
Chris@250 501 tr("Shift-click left button and drag to define a specific pitch and time range to re-analyse"));
Chris@250 502 m_keyReference->registerShortcut
Chris@250 503 (tr("Edit"), tr("Double-Click Left"),
Chris@250 504 tr("Double-click left button on an item to edit it"));
Chris@392 505
Chris@250 506 m_keyReference->setCategory(tr("Tool Selection"));
Chris@126 507 action = toolbar->addAction(il.load("move"),
Chris@126 508 tr("Edit"));
Chris@126 509 action->setCheckable(true);
Chris@126 510 action->setShortcut(tr("2"));
Chris@126 511 action->setStatusTip(tr("Edit with Note Intelligence"));
Chris@126 512 connect(action, SIGNAL(triggered()), this, SLOT(toolEditSelected()));
Chris@126 513 group->addAction(action);
Chris@126 514 menu->addAction(action);
Chris@126 515 m_keyReference->registerShortcut(action);
Chris@126 516
Chris@250 517 m_keyReference->setCategory
Chris@250 518 (tr("Note Edit Tool Mouse Actions"));
Chris@250 519 m_keyReference->registerShortcut
Chris@250 520 (tr("Adjust Pitch"), tr("Left"),
Chris@250 521 tr("Click left button on the main part of a note and drag to move it up or down"));
Chris@250 522 m_keyReference->registerShortcut
Chris@250 523 (tr("Split"), tr("Left"),
Chris@250 524 tr("Click left button on the bottom edge of a note to split it at the click point"));
Chris@250 525 m_keyReference->registerShortcut
Chris@250 526 (tr("Resize"), tr("Left"),
Chris@250 527 tr("Click left button on the left or right edge of a note and drag to change the time or duration of the note"));
Chris@250 528 m_keyReference->registerShortcut
Chris@250 529 (tr("Erase"), tr("Shift+Left"),
Chris@250 530 tr("Shift-click left button on a note to remove it"));
Chris@250 531
Chris@250 532
Chris@126 533 /* Remove for now...
Chris@126 534
Chris@250 535 m_keyReference->setCategory(tr("Tool Selection"));
Chris@126 536 action = toolbar->addAction(il.load("notes"),
Chris@126 537 tr("Free Edit"));
Chris@126 538 action->setCheckable(true);
Chris@126 539 action->setShortcut(tr("3"));
Chris@126 540 action->setStatusTip(tr("Free Edit"));
Chris@126 541 connect(action, SIGNAL(triggered()), this, SLOT(toolFreeEditSelected()));
Chris@126 542 group->addAction(action);
Chris@126 543 m_keyReference->registerShortcut(action);
Chris@126 544 */
Chris@142 545
Chris@142 546 menu->addSeparator();
Chris@142 547
Chris@143 548 m_keyReference->setCategory(tr("Selection"));
Chris@143 549
Chris@143 550 action = new QAction(tr("Select &All"), this);
Chris@143 551 action->setShortcut(tr("Ctrl+A"));
Chris@143 552 action->setStatusTip(tr("Select the whole duration of the current session"));
Chris@143 553 connect(action, SIGNAL(triggered()), this, SLOT(selectAll()));
Chris@143 554 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
Chris@143 555 m_keyReference->registerShortcut(action);
Chris@143 556 menu->addAction(action);
Chris@143 557 m_rightButtonMenu->addAction(action);
Chris@143 558
Chris@287 559 action = new QAction(tr("C&lear Selection"), this);
Chris@211 560 action->setShortcuts(QList<QKeySequence>()
Chris@211 561 << QKeySequence(tr("Esc"))
Chris@211 562 << QKeySequence(tr("Ctrl+Esc")));
Chris@211 563 action->setStatusTip(tr("Clear the selection and abandon any pending pitch choices in it"));
Chris@194 564 connect(action, SIGNAL(triggered()), this, SLOT(abandonSelection()));
Chris@143 565 connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@143 566 m_keyReference->registerShortcut(action);
Chris@211 567 m_keyReference->registerAlternativeShortcut(action, QKeySequence(tr("Ctrl+Esc")));
Chris@143 568 menu->addAction(action);
Chris@143 569 m_rightButtonMenu->addAction(action);
Chris@143 570
Chris@143 571 menu->addSeparator();
Chris@189 572 m_rightButtonMenu->addSeparator();
Chris@143 573
Chris@189 574 m_keyReference->setCategory(tr("Pitch Track"));
Chris@211 575
Chris@211 576 action = new QAction(tr("Choose Higher Pitch"), this);
Chris@211 577 action->setShortcut(tr("Ctrl+Up"));
Chris@211 578 action->setStatusTip(tr("Move pitches up an octave, or to the next higher pitch candidate"));
Chris@211 579 m_keyReference->registerShortcut(action);
Chris@211 580 connect(action, SIGNAL(triggered()), this, SLOT(switchPitchUp()));
Chris@211 581 connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@211 582 menu->addAction(action);
Chris@211 583 m_rightButtonMenu->addAction(action);
Chris@211 584
Chris@211 585 action = new QAction(tr("Choose Lower Pitch"), this);
Chris@211 586 action->setShortcut(tr("Ctrl+Down"));
Chris@211 587 action->setStatusTip(tr("Move pitches down an octave, or to the next lower pitch candidate"));
Chris@211 588 m_keyReference->registerShortcut(action);
Chris@211 589 connect(action, SIGNAL(triggered()), this, SLOT(switchPitchDown()));
Chris@211 590 connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@211 591 menu->addAction(action);
Chris@211 592 m_rightButtonMenu->addAction(action);
Chris@189 593
Chris@187 594 m_showCandidatesAction = new QAction(tr("Show Pitch Candidates"), this);
Chris@187 595 m_showCandidatesAction->setShortcut(tr("Ctrl+Return"));
Chris@189 596 m_showCandidatesAction->setStatusTip(tr("Toggle the display of alternative pitch candidates for the selected region"));
Chris@189 597 m_keyReference->registerShortcut(m_showCandidatesAction);
Chris@187 598 connect(m_showCandidatesAction, SIGNAL(triggered()), this, SLOT(togglePitchCandidates()));
Chris@187 599 connect(this, SIGNAL(canClearSelection(bool)), m_showCandidatesAction, SLOT(setEnabled(bool)));
Chris@187 600 menu->addAction(m_showCandidatesAction);
Chris@189 601 m_rightButtonMenu->addAction(m_showCandidatesAction);
Chris@187 602
Chris@287 603 action = new QAction(tr("Remove Pitches"), this);
matthiasm@327 604 action->setShortcut(tr("Ctrl+Backspace"));
Chris@211 605 action->setStatusTip(tr("Remove all pitch estimates within the selected region, making it unvoiced"));
Chris@189 606 m_keyReference->registerShortcut(action);
Chris@187 607 connect(action, SIGNAL(triggered()), this, SLOT(clearPitches()));
Chris@167 608 connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@167 609 menu->addAction(action);
Chris@189 610 m_rightButtonMenu->addAction(action);
Chris@237 611
Chris@237 612 menu->addSeparator();
Chris@237 613 m_rightButtonMenu->addSeparator();
Chris@237 614
matthiasm@327 615 m_keyReference->setCategory(tr("Note Track"));
matthiasm@327 616
Chris@287 617 action = new QAction(tr("Split Note"), this);
matthiasm@327 618 action->setShortcut(tr("/"));
Chris@240 619 action->setStatusTip(tr("Split the note at the current playback position into two"));
Chris@237 620 m_keyReference->registerShortcut(action);
Chris@240 621 connect(action, SIGNAL(triggered()), this, SLOT(splitNote()));
Chris@240 622 connect(this, SIGNAL(canExportNotes(bool)), action, SLOT(setEnabled(bool)));
Chris@237 623 menu->addAction(action);
Chris@237 624 m_rightButtonMenu->addAction(action);
Chris@238 625
Chris@287 626 action = new QAction(tr("Merge Notes"), this);
matthiasm@327 627 action->setShortcut(tr("\\"));
Chris@238 628 action->setStatusTip(tr("Merge all notes within the selected region into a single note"));
Chris@238 629 m_keyReference->registerShortcut(action);
Chris@238 630 connect(action, SIGNAL(triggered()), this, SLOT(mergeNotes()));
Chris@238 631 connect(this, SIGNAL(canSnapNotes(bool)), action, SLOT(setEnabled(bool)));
Chris@238 632 menu->addAction(action);
Chris@238 633 m_rightButtonMenu->addAction(action);
matthiasm@292 634
matthiasm@292 635 action = new QAction(tr("Delete Notes"), this);
matthiasm@327 636 action->setShortcut(tr("Backspace"));
matthiasm@327 637 action->setStatusTip(tr("Delete all notes within the selected region"));
matthiasm@292 638 m_keyReference->registerShortcut(action);
matthiasm@292 639 connect(action, SIGNAL(triggered()), this, SLOT(deleteNotes()));
matthiasm@292 640 connect(this, SIGNAL(canSnapNotes(bool)), action, SLOT(setEnabled(bool)));
matthiasm@292 641 menu->addAction(action);
matthiasm@292 642 m_rightButtonMenu->addAction(action);
Chris@238 643
Chris@240 644 action = new QAction(tr("Form Note from Selection"), this);
matthiasm@327 645 action->setShortcut(tr("="));
Chris@240 646 action->setStatusTip(tr("Form a note spanning the selected region, splitting any existing notes at its boundaries"));
Chris@240 647 m_keyReference->registerShortcut(action);
Chris@240 648 connect(action, SIGNAL(triggered()), this, SLOT(formNoteFromSelection()));
Chris@240 649 connect(this, SIGNAL(canSnapNotes(bool)), action, SLOT(setEnabled(bool)));
Chris@240 650 menu->addAction(action);
Chris@240 651 m_rightButtonMenu->addAction(action);
Chris@247 652
Chris@238 653 action = new QAction(tr("Snap Notes to Pitch Track"), this);
Chris@238 654 action->setStatusTip(tr("Set notes within the selected region to the median frequency of their underlying pitches, or remove them if there are no underlying pitches"));
matthiasm@327 655 // m_keyReference->registerShortcut(action);
Chris@238 656 connect(action, SIGNAL(triggered()), this, SLOT(snapNotesToPitches()));
Chris@238 657 connect(this, SIGNAL(canSnapNotes(bool)), action, SLOT(setEnabled(bool)));
Chris@238 658 menu->addAction(action);
Chris@238 659 m_rightButtonMenu->addAction(action);
Chris@0 660 }
Chris@0 661
Chris@0 662 void
Chris@0 663 MainWindow::setupViewMenu()
Chris@0 664 {
Chris@0 665 if (m_mainMenusCreated) return;
Chris@0 666
Chris@0 667 IconLoader il;
Chris@0 668
Chris@0 669 QAction *action = 0;
Chris@0 670
Chris@0 671 m_keyReference->setCategory(tr("Panning and Navigation"));
Chris@0 672
Chris@0 673 QMenu *menu = menuBar()->addMenu(tr("&View"));
Chris@0 674 menu->setTearOffEnabled(true);
Chris@300 675 action = new QAction(tr("Peek &Left"), this);
Chris@300 676 action->setShortcut(tr("Alt+Left"));
Chris@300 677 action->setStatusTip(tr("Scroll the current pane to the left without changing the play position"));
Chris@0 678 connect(action, SIGNAL(triggered()), this, SLOT(scrollLeft()));
Chris@0 679 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@0 680 m_keyReference->registerShortcut(action);
Chris@0 681 menu->addAction(action);
gyorgyf@27 682
Chris@300 683 action = new QAction(tr("Peek &Right"), this);
Chris@300 684 action->setShortcut(tr("Alt+Right"));
Chris@300 685 action->setStatusTip(tr("Scroll the current pane to the right without changing the play position"));
Chris@0 686 connect(action, SIGNAL(triggered()), this, SLOT(scrollRight()));
Chris@0 687 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@0 688 m_keyReference->registerShortcut(action);
Chris@0 689 menu->addAction(action);
matthiasm@283 690
Chris@0 691 menu->addSeparator();
Chris@0 692
Chris@0 693 m_keyReference->setCategory(tr("Zoom"));
Chris@0 694
Chris@0 695 action = new QAction(il.load("zoom-in"),
Chris@0 696 tr("Zoom &In"), this);
Chris@0 697 action->setShortcut(tr("Up"));
Chris@0 698 action->setStatusTip(tr("Increase the zoom level"));
Chris@0 699 connect(action, SIGNAL(triggered()), this, SLOT(zoomIn()));
Chris@0 700 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@0 701 m_keyReference->registerShortcut(action);
Chris@0 702 menu->addAction(action);
gyorgyf@27 703
Chris@0 704 action = new QAction(il.load("zoom-out"),
Chris@0 705 tr("Zoom &Out"), this);
Chris@0 706 action->setShortcut(tr("Down"));
Chris@0 707 action->setStatusTip(tr("Decrease the zoom level"));
Chris@0 708 connect(action, SIGNAL(triggered()), this, SLOT(zoomOut()));
Chris@0 709 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@0 710 m_keyReference->registerShortcut(action);
Chris@0 711 menu->addAction(action);
gyorgyf@27 712
Chris@0 713 action = new QAction(tr("Restore &Default Zoom"), this);
Chris@0 714 action->setStatusTip(tr("Restore the zoom level to the default"));
Chris@0 715 connect(action, SIGNAL(triggered()), this, SLOT(zoomDefault()));
Chris@0 716 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@0 717 menu->addAction(action);
Chris@0 718
Chris@0 719 action = new QAction(il.load("zoom-fit"),
Chris@0 720 tr("Zoom to &Fit"), this);
Chris@0 721 action->setShortcut(tr("F"));
Chris@0 722 action->setStatusTip(tr("Zoom to show the whole file"));
Chris@0 723 connect(action, SIGNAL(triggered()), this, SLOT(zoomToFit()));
Chris@0 724 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@0 725 m_keyReference->registerShortcut(action);
Chris@0 726 menu->addAction(action);
Chris@227 727
Chris@227 728 menu->addSeparator();
Chris@227 729
Chris@227 730 action = new QAction(tr("Set Displayed Fre&quency Range..."), this);
Chris@227 731 action->setStatusTip(tr("Set the minimum and maximum frequencies in the visible display"));
Chris@227 732 connect(action, SIGNAL(triggered()), this, SLOT(editDisplayExtents()));
Chris@227 733 menu->addAction(action);
Chris@0 734 }
Chris@0 735
Chris@0 736 void
matthiasm@317 737 MainWindow::setupAnalysisMenu()
matthiasm@317 738 {
matthiasm@317 739 if (m_mainMenusCreated) return;
matthiasm@317 740
matthiasm@317 741 IconLoader il;
matthiasm@317 742
matthiasm@317 743 QAction *action = 0;
matthiasm@317 744
matthiasm@317 745 QMenu *menu = menuBar()->addMenu(tr("&Analysis"));
matthiasm@317 746 menu->setTearOffEnabled(true);
matthiasm@317 747
Chris@427 748 m_autoAnalyse = new QAction(tr("Auto-Analyse &New Audio"), this);
Chris@427 749 m_autoAnalyse->setStatusTip(tr("Automatically trigger analysis upon opening of a new audio file."));
Chris@427 750 m_autoAnalyse->setCheckable(true);
Chris@427 751 connect(m_autoAnalyse, SIGNAL(triggered()), this, SLOT(autoAnalysisToggled()));
Chris@427 752 menu->addAction(m_autoAnalyse);
Chris@427 753
Chris@427 754 action = new QAction(tr("&Analyse Now!"), this);
Chris@427 755 action->setStatusTip(tr("Trigger analysis of pitches and notes. (This will delete all existing pitches and notes.)"));
Chris@427 756 connect(action, SIGNAL(triggered()), this, SLOT(analyseNow()));
Chris@427 757 menu->addAction(action);
Chris@427 758 m_keyReference->registerShortcut(action);
Chris@427 759
Chris@427 760 menu->addSeparator();
Chris@427 761
Chris@427 762 m_precise = new QAction(tr("&Unbiased Timing (slow)"), this);
Chris@427 763 m_precise->setStatusTip(tr("Use a symmetric window in YIN to remove frequency-dependent timing bias. (This is slow!)"));
Chris@427 764 m_precise->setCheckable(true);
Chris@427 765 connect(m_precise, SIGNAL(triggered()), this, SLOT(precisionAnalysisToggled()));
Chris@427 766 menu->addAction(m_precise);
Chris@427 767
Chris@427 768 m_lowamp = new QAction(tr("&Penalise Soft Pitches"), this);
Chris@427 769 m_lowamp->setStatusTip(tr("Reduce the likelihood of detecting a pitch when the signal has low amplitude."));
Chris@427 770 m_lowamp->setCheckable(true);
Chris@427 771 connect(m_lowamp, SIGNAL(triggered()), this, SLOT(lowampAnalysisToggled()));
Chris@427 772 menu->addAction(m_lowamp);
Chris@427 773
Chris@427 774 m_onset = new QAction(tr("&High Onset Sensitivity"), this);
Chris@427 775 m_onset->setStatusTip(tr("Increase likelihood of separating notes, especially consecutive notes at the same pitch."));
Chris@427 776 m_onset->setCheckable(true);
Chris@427 777 connect(m_onset, SIGNAL(triggered()), this, SLOT(onsetAnalysisToggled()));
Chris@427 778 menu->addAction(m_onset);
Chris@427 779
Chris@427 780 m_prune = new QAction(tr("&Drop Short Notes"), this);
Chris@427 781 m_prune->setStatusTip(tr("Duration-based pruning: automatic note estimator will not output notes of less than 100ms duration."));
Chris@427 782 m_prune->setCheckable(true);
Chris@427 783 connect(m_prune, SIGNAL(triggered()), this, SLOT(pruneAnalysisToggled()));
Chris@427 784 menu->addAction(m_prune);
Chris@427 785
Chris@427 786 menu->addSeparator();
Chris@427 787
Chris@427 788 action = new QAction(tr("Reset Options to Defaults"), this);
Chris@427 789 action->setStatusTip(tr("Reset all of the Analyse menu options to their default settings."));
Chris@427 790 connect(action, SIGNAL(triggered()), this, SLOT(resetAnalyseOptions()));
Chris@427 791 menu->addAction(action);
Chris@427 792
Chris@427 793 updateAnalyseStates();
Chris@427 794 }
Chris@427 795
Chris@427 796 void
Chris@427 797 MainWindow::resetAnalyseOptions()
Chris@427 798 {
Chris@427 799 //!!! oh no, we need to update the menu states as well...
Chris@427 800 QSettings settings;
Chris@427 801 settings.beginGroup("Analyser");
Chris@427 802 settings.setValue("auto-analysis", true);
Chris@427 803 settings.setValue("precision-analysis", false);
Chris@427 804 settings.setValue("lowamp-analysis", true);
Chris@427 805 settings.setValue("onset-analysis", true);
Chris@427 806 settings.setValue("prune-analysis", true);
Chris@427 807 settings.endGroup();
Chris@427 808 updateAnalyseStates();
Chris@427 809 }
Chris@427 810
Chris@427 811 void
Chris@427 812 MainWindow::updateAnalyseStates()
Chris@427 813 {
Chris@323 814 QSettings settings;
Chris@323 815 settings.beginGroup("Analyser");
Chris@323 816 bool autoAnalyse = settings.value("auto-analysis", true).toBool();
Chris@323 817 bool precise = settings.value("precision-analysis", false).toBool();
matthiasm@345 818 bool lowamp = settings.value("lowamp-analysis", true).toBool();
matthiasm@423 819 bool onset = settings.value("onset-analysis", true).toBool();
matthiasm@423 820 bool prune = settings.value("prune-analysis", true).toBool();
Chris@323 821 settings.endGroup();
Chris@323 822
Chris@427 823 m_autoAnalyse->setChecked(autoAnalyse);
Chris@427 824 m_precise->setChecked(precise);
Chris@427 825 m_lowamp->setChecked(lowamp);
Chris@427 826 m_onset->setChecked(onset);
Chris@427 827 m_prune->setChecked(prune);
Chris@323 828 }
Chris@323 829
Chris@323 830 void
Chris@323 831 MainWindow::autoAnalysisToggled()
Chris@323 832 {
Chris@323 833 QAction *a = qobject_cast<QAction *>(sender());
Chris@323 834 if (!a) return;
Chris@323 835
Chris@323 836 bool set = a->isChecked();
Chris@323 837
Chris@323 838 QSettings settings;
Chris@323 839 settings.beginGroup("Analyser");
Chris@323 840 settings.setValue("auto-analysis", set);
Chris@323 841 settings.endGroup();
Chris@323 842 }
Chris@323 843
Chris@323 844 void
Chris@323 845 MainWindow::precisionAnalysisToggled()
Chris@323 846 {
Chris@323 847 QAction *a = qobject_cast<QAction *>(sender());
Chris@323 848 if (!a) return;
Chris@323 849
Chris@323 850 bool set = a->isChecked();
Chris@323 851
Chris@323 852 QSettings settings;
Chris@323 853 settings.beginGroup("Analyser");
Chris@323 854 settings.setValue("precision-analysis", set);
Chris@323 855 settings.endGroup();
Chris@323 856
Chris@326 857 // don't run analyseNow() automatically -- it's a destructive operation
matthiasm@317 858 }
matthiasm@317 859
matthiasm@317 860 void
matthiasm@345 861 MainWindow::lowampAnalysisToggled()
matthiasm@345 862 {
matthiasm@345 863 QAction *a = qobject_cast<QAction *>(sender());
matthiasm@345 864 if (!a) return;
matthiasm@345 865
matthiasm@345 866 bool set = a->isChecked();
matthiasm@345 867
matthiasm@345 868 QSettings settings;
matthiasm@345 869 settings.beginGroup("Analyser");
matthiasm@345 870 settings.setValue("lowamp-analysis", set);
matthiasm@345 871 settings.endGroup();
matthiasm@345 872
matthiasm@345 873 // don't run analyseNow() automatically -- it's a destructive operation
matthiasm@345 874 }
matthiasm@345 875
matthiasm@345 876 void
matthiasm@423 877 MainWindow::onsetAnalysisToggled()
matthiasm@423 878 {
matthiasm@423 879 QAction *a = qobject_cast<QAction *>(sender());
matthiasm@423 880 if (!a) return;
matthiasm@423 881
matthiasm@423 882 bool set = a->isChecked();
matthiasm@423 883
matthiasm@423 884 QSettings settings;
matthiasm@423 885 settings.beginGroup("Analyser");
matthiasm@423 886 settings.setValue("onset-analysis", set);
matthiasm@423 887 settings.endGroup();
matthiasm@423 888
matthiasm@423 889 // don't run analyseNow() automatically -- it's a destructive operation
matthiasm@423 890 }
matthiasm@423 891
matthiasm@423 892 void
matthiasm@423 893 MainWindow::pruneAnalysisToggled()
matthiasm@423 894 {
matthiasm@423 895 QAction *a = qobject_cast<QAction *>(sender());
matthiasm@423 896 if (!a) return;
matthiasm@423 897
matthiasm@423 898 bool set = a->isChecked();
matthiasm@423 899
matthiasm@423 900 QSettings settings;
matthiasm@423 901 settings.beginGroup("Analyser");
matthiasm@423 902 settings.setValue("prune-analysis", set);
matthiasm@423 903 settings.endGroup();
matthiasm@423 904
matthiasm@423 905 // don't run analyseNow() automatically -- it's a destructive operation
matthiasm@423 906 }
matthiasm@423 907
matthiasm@423 908 void
Chris@0 909 MainWindow::setupHelpMenu()
Chris@0 910 {
Chris@0 911 QMenu *menu = menuBar()->addMenu(tr("&Help"));
Chris@0 912 menu->setTearOffEnabled(true);
Chris@0 913
Chris@0 914 m_keyReference->setCategory(tr("Help"));
Chris@0 915
Chris@0 916 IconLoader il;
Chris@0 917
Chris@1 918 QString name = QApplication::applicationName();
matthiasm@367 919 QAction *action;
matthiasm@367 920
Chris@0 921 action = new QAction(tr("&Key and Mouse Reference"), this);
Chris@0 922 action->setShortcut(tr("F2"));
Chris@1 923 action->setStatusTip(tr("Open a window showing the keystrokes you can use in %1").arg(name));
Chris@0 924 connect(action, SIGNAL(triggered()), this, SLOT(keyReference()));
Chris@0 925 m_keyReference->registerShortcut(action);
Chris@0 926 menu->addAction(action);
matthiasm@369 927
matthiasm@369 928 action = new QAction(il.load("help"),
matthiasm@369 929 tr("&Help Reference"), this);
matthiasm@369 930 action->setShortcut(tr("F1"));
matthiasm@369 931 action->setStatusTip(tr("Open the %1 reference manual").arg(name));
matthiasm@369 932 connect(action, SIGNAL(triggered()), this, SLOT(help()));
matthiasm@369 933 m_keyReference->registerShortcut(action);
matthiasm@369 934 menu->addAction(action);
matthiasm@369 935
Chris@0 936
Chris@1 937 action = new QAction(tr("%1 on the &Web").arg(name), this);
Chris@1 938 action->setStatusTip(tr("Open the %1 website").arg(name));
Chris@0 939 connect(action, SIGNAL(triggered()), this, SLOT(website()));
Chris@0 940 menu->addAction(action);
Chris@0 941
Chris@1 942 action = new QAction(tr("&About %1").arg(name), this);
Chris@1 943 action->setStatusTip(tr("Show information about %1").arg(name));
Chris@0 944 connect(action, SIGNAL(triggered()), this, SLOT(about()));
Chris@0 945 menu->addAction(action);
Chris@0 946 }
Chris@0 947
Chris@0 948 void
Chris@0 949 MainWindow::setupRecentFilesMenu()
Chris@0 950 {
Chris@0 951 m_recentFilesMenu->clear();
Chris@0 952 vector<QString> files = m_recentFiles.getRecent();
Chris@0 953 for (size_t i = 0; i < files.size(); ++i) {
Chris@50 954 QAction *action = new QAction(files[i], this);
Chris@50 955 connect(action, SIGNAL(triggered()), this, SLOT(openRecentFile()));
Chris@0 956 if (i == 0) {
Chris@0 957 action->setShortcut(tr("Ctrl+R"));
Chris@0 958 m_keyReference->registerShortcut
Chris@0 959 (tr("Re-open"),
Chris@50 960 action->shortcut().toString(),
Chris@0 961 tr("Re-open the current or most recently opened file"));
Chris@0 962 }
Chris@50 963 m_recentFilesMenu->addAction(action);
Chris@0 964 }
Chris@0 965 }
Chris@0 966
Chris@0 967 void
Chris@0 968 MainWindow::setupToolbars()
Chris@0 969 {
Chris@0 970 m_keyReference->setCategory(tr("Playback and Transport Controls"));
Chris@0 971
Chris@0 972 IconLoader il;
Chris@0 973
Chris@0 974 QMenu *menu = m_playbackMenu = menuBar()->addMenu(tr("Play&back"));
Chris@0 975 menu->setTearOffEnabled(true);
Chris@0 976 m_rightButtonMenu->addSeparator();
Chris@0 977 m_rightButtonPlaybackMenu = m_rightButtonMenu->addMenu(tr("Playback"));
Chris@0 978
Chris@0 979 QToolBar *toolbar = addToolBar(tr("Playback Toolbar"));
Chris@0 980
Chris@0 981 QAction *rwdStartAction = toolbar->addAction(il.load("rewind-start"),
Chris@0 982 tr("Rewind to Start"));
Chris@0 983 rwdStartAction->setShortcut(tr("Home"));
Chris@0 984 rwdStartAction->setStatusTip(tr("Rewind to the start"));
Chris@0 985 connect(rwdStartAction, SIGNAL(triggered()), this, SLOT(rewindStart()));
Chris@0 986 connect(this, SIGNAL(canPlay(bool)), rwdStartAction, SLOT(setEnabled(bool)));
Chris@0 987
Chris@0 988 QAction *m_rwdAction = toolbar->addAction(il.load("rewind"),
Chris@0 989 tr("Rewind"));
Chris@300 990 m_rwdAction->setShortcut(tr("Left"));
Chris@300 991 m_rwdAction->setStatusTip(tr("Rewind to the previous one-second boundary"));
Chris@0 992 connect(m_rwdAction, SIGNAL(triggered()), this, SLOT(rewind()));
Chris@0 993 connect(this, SIGNAL(canRewind(bool)), m_rwdAction, SLOT(setEnabled(bool)));
Chris@0 994
Chris@300 995 setDefaultFfwdRwdStep(RealTime(1, 0));
Chris@300 996
Chris@0 997 QAction *playAction = toolbar->addAction(il.load("playpause"),
Chris@0 998 tr("Play / Pause"));
Chris@0 999 playAction->setCheckable(true);
Chris@0 1000 playAction->setShortcut(tr("Space"));
Chris@0 1001 playAction->setStatusTip(tr("Start or stop playback from the current position"));
Chris@0 1002 connect(playAction, SIGNAL(triggered()), this, SLOT(play()));
Chris@0 1003 connect(m_playSource, SIGNAL(playStatusChanged(bool)),
gyorgyf@27 1004 playAction, SLOT(setChecked(bool)));
Chris@0 1005 connect(this, SIGNAL(canPlay(bool)), playAction, SLOT(setEnabled(bool)));
Chris@0 1006
Chris@0 1007 m_ffwdAction = toolbar->addAction(il.load("ffwd"),
Chris@0 1008 tr("Fast Forward"));
Chris@300 1009 m_ffwdAction->setShortcut(tr("Right"));
Chris@300 1010 m_ffwdAction->setStatusTip(tr("Fast-forward to the next one-second boundary"));
Chris@0 1011 connect(m_ffwdAction, SIGNAL(triggered()), this, SLOT(ffwd()));
Chris@0 1012 connect(this, SIGNAL(canFfwd(bool)), m_ffwdAction, SLOT(setEnabled(bool)));
Chris@0 1013
Chris@0 1014 QAction *ffwdEndAction = toolbar->addAction(il.load("ffwd-end"),
Chris@0 1015 tr("Fast Forward to End"));
Chris@0 1016 ffwdEndAction->setShortcut(tr("End"));
Chris@0 1017 ffwdEndAction->setStatusTip(tr("Fast-forward to the end"));
Chris@0 1018 connect(ffwdEndAction, SIGNAL(triggered()), this, SLOT(ffwdEnd()));
Chris@0 1019 connect(this, SIGNAL(canPlay(bool)), ffwdEndAction, SLOT(setEnabled(bool)));
Chris@6 1020
Chris@0 1021 toolbar = addToolBar(tr("Play Mode Toolbar"));
Chris@0 1022
Chris@0 1023 QAction *psAction = toolbar->addAction(il.load("playselection"),
Chris@0 1024 tr("Constrain Playback to Selection"));
Chris@0 1025 psAction->setCheckable(true);
Chris@0 1026 psAction->setChecked(m_viewManager->getPlaySelectionMode());
Chris@0 1027 psAction->setShortcut(tr("s"));
Chris@0 1028 psAction->setStatusTip(tr("Constrain playback to the selected regions"));
Chris@0 1029 connect(m_viewManager, SIGNAL(playSelectionModeChanged(bool)),
Chris@0 1030 psAction, SLOT(setChecked(bool)));
Chris@0 1031 connect(psAction, SIGNAL(triggered()), this, SLOT(playSelectionToggled()));
Chris@0 1032 connect(this, SIGNAL(canPlaySelection(bool)), psAction, SLOT(setEnabled(bool)));
Chris@0 1033
Chris@0 1034 QAction *plAction = toolbar->addAction(il.load("playloop"),
Chris@0 1035 tr("Loop Playback"));
Chris@0 1036 plAction->setCheckable(true);
Chris@0 1037 plAction->setChecked(m_viewManager->getPlayLoopMode());
Chris@0 1038 plAction->setShortcut(tr("l"));
Chris@0 1039 plAction->setStatusTip(tr("Loop playback"));
Chris@0 1040 connect(m_viewManager, SIGNAL(playLoopModeChanged(bool)),
Chris@0 1041 plAction, SLOT(setChecked(bool)));
Chris@0 1042 connect(plAction, SIGNAL(triggered()), this, SLOT(playLoopToggled()));
Chris@0 1043 connect(this, SIGNAL(canPlay(bool)), plAction, SLOT(setEnabled(bool)));
Chris@0 1044
Chris@300 1045 QAction *oneLeftAction = new QAction(tr("&One Note Left"), this);
Chris@300 1046 oneLeftAction->setShortcut(tr("Ctrl+Left"));
Chris@300 1047 oneLeftAction->setStatusTip(tr("Move cursor to the preceding note (or silence) onset."));
Chris@300 1048 connect(oneLeftAction, SIGNAL(triggered()), this, SLOT(moveOneNoteLeft()));
Chris@300 1049 connect(this, SIGNAL(canScroll(bool)), oneLeftAction, SLOT(setEnabled(bool)));
Chris@300 1050
Chris@300 1051 QAction *oneRightAction = new QAction(tr("O&ne Note Right"), this);
Chris@300 1052 oneRightAction->setShortcut(tr("Ctrl+Right"));
Chris@300 1053 oneRightAction->setStatusTip(tr("Move cursor to the succeeding note (or silence)."));
Chris@300 1054 connect(oneRightAction, SIGNAL(triggered()), this, SLOT(moveOneNoteRight()));
Chris@300 1055 connect(this, SIGNAL(canScroll(bool)), oneRightAction, SLOT(setEnabled(bool)));
Chris@300 1056
Chris@300 1057 QAction *selectOneLeftAction = new QAction(tr("&Select One Note Left"), this);
Chris@300 1058 selectOneLeftAction->setShortcut(tr("Ctrl+Shift+Left"));
Chris@300 1059 selectOneLeftAction->setStatusTip(tr("Select to the preceding note (or silence) onset."));
Chris@300 1060 connect(selectOneLeftAction, SIGNAL(triggered()), this, SLOT(selectOneNoteLeft()));
Chris@300 1061 connect(this, SIGNAL(canScroll(bool)), selectOneLeftAction, SLOT(setEnabled(bool)));
Chris@300 1062
Chris@300 1063 QAction *selectOneRightAction = new QAction(tr("S&elect One Note Right"), this);
Chris@300 1064 selectOneRightAction->setShortcut(tr("Ctrl+Shift+Right"));
Chris@300 1065 selectOneRightAction->setStatusTip(tr("Select to the succeeding note (or silence)."));
Chris@300 1066 connect(selectOneRightAction, SIGNAL(triggered()), this, SLOT(selectOneNoteRight()));
Chris@300 1067 connect(this, SIGNAL(canScroll(bool)), selectOneRightAction, SLOT(setEnabled(bool)));
Chris@300 1068
Chris@0 1069 m_keyReference->registerShortcut(psAction);
Chris@0 1070 m_keyReference->registerShortcut(plAction);
Chris@0 1071 m_keyReference->registerShortcut(playAction);
Chris@0 1072 m_keyReference->registerShortcut(m_rwdAction);
Chris@0 1073 m_keyReference->registerShortcut(m_ffwdAction);
Chris@0 1074 m_keyReference->registerShortcut(rwdStartAction);
Chris@0 1075 m_keyReference->registerShortcut(ffwdEndAction);
Chris@300 1076 m_keyReference->registerShortcut(oneLeftAction);
Chris@300 1077 m_keyReference->registerShortcut(oneRightAction);
Chris@300 1078 m_keyReference->registerShortcut(selectOneLeftAction);
Chris@300 1079 m_keyReference->registerShortcut(selectOneRightAction);
Chris@0 1080
Chris@6 1081 menu->addAction(playAction);
Chris@0 1082 menu->addAction(psAction);
Chris@0 1083 menu->addAction(plAction);
Chris@0 1084 menu->addSeparator();
Chris@0 1085 menu->addAction(m_rwdAction);
Chris@0 1086 menu->addAction(m_ffwdAction);
Chris@0 1087 menu->addSeparator();
Chris@0 1088 menu->addAction(rwdStartAction);
Chris@0 1089 menu->addAction(ffwdEndAction);
Chris@0 1090 menu->addSeparator();
Chris@300 1091 menu->addAction(oneLeftAction);
Chris@300 1092 menu->addAction(oneRightAction);
Chris@300 1093 menu->addAction(selectOneLeftAction);
Chris@300 1094 menu->addAction(selectOneRightAction);
Chris@300 1095 menu->addSeparator();
Chris@0 1096
Chris@0 1097 m_rightButtonPlaybackMenu->addAction(playAction);
Chris@0 1098 m_rightButtonPlaybackMenu->addAction(psAction);
Chris@0 1099 m_rightButtonPlaybackMenu->addAction(plAction);
Chris@0 1100 m_rightButtonPlaybackMenu->addSeparator();
Chris@0 1101 m_rightButtonPlaybackMenu->addAction(m_rwdAction);
Chris@0 1102 m_rightButtonPlaybackMenu->addAction(m_ffwdAction);
Chris@0 1103 m_rightButtonPlaybackMenu->addSeparator();
Chris@0 1104 m_rightButtonPlaybackMenu->addAction(rwdStartAction);
Chris@0 1105 m_rightButtonPlaybackMenu->addAction(ffwdEndAction);
Chris@0 1106 m_rightButtonPlaybackMenu->addSeparator();
Chris@300 1107 m_rightButtonPlaybackMenu->addAction(oneLeftAction);
Chris@300 1108 m_rightButtonPlaybackMenu->addAction(oneRightAction);
Chris@300 1109 m_rightButtonPlaybackMenu->addAction(selectOneLeftAction);
Chris@300 1110 m_rightButtonPlaybackMenu->addAction(selectOneRightAction);
Chris@300 1111 m_rightButtonPlaybackMenu->addSeparator();
Chris@0 1112
Chris@0 1113 QAction *fastAction = menu->addAction(tr("Speed Up"));
Chris@0 1114 fastAction->setShortcut(tr("Ctrl+PgUp"));
Chris@0 1115 fastAction->setStatusTip(tr("Time-stretch playback to speed it up without changing pitch"));
Chris@0 1116 connect(fastAction, SIGNAL(triggered()), this, SLOT(speedUpPlayback()));
Chris@0 1117 connect(this, SIGNAL(canSpeedUpPlayback(bool)), fastAction, SLOT(setEnabled(bool)));
Chris@0 1118
Chris@0 1119 QAction *slowAction = menu->addAction(tr("Slow Down"));
Chris@0 1120 slowAction->setShortcut(tr("Ctrl+PgDown"));
Chris@0 1121 slowAction->setStatusTip(tr("Time-stretch playback to slow it down without changing pitch"));
Chris@0 1122 connect(slowAction, SIGNAL(triggered()), this, SLOT(slowDownPlayback()));
Chris@0 1123 connect(this, SIGNAL(canSlowDownPlayback(bool)), slowAction, SLOT(setEnabled(bool)));
Chris@0 1124
Chris@0 1125 QAction *normalAction = menu->addAction(tr("Restore Normal Speed"));
Chris@0 1126 normalAction->setShortcut(tr("Ctrl+Home"));
Chris@0 1127 normalAction->setStatusTip(tr("Restore non-time-stretched playback"));
Chris@0 1128 connect(normalAction, SIGNAL(triggered()), this, SLOT(restoreNormalPlayback()));
Chris@0 1129 connect(this, SIGNAL(canChangePlaybackSpeed(bool)), normalAction, SLOT(setEnabled(bool)));
Chris@0 1130
Chris@0 1131 m_keyReference->registerShortcut(fastAction);
Chris@0 1132 m_keyReference->registerShortcut(slowAction);
Chris@0 1133 m_keyReference->registerShortcut(normalAction);
Chris@0 1134
Chris@0 1135 m_rightButtonPlaybackMenu->addAction(fastAction);
Chris@0 1136 m_rightButtonPlaybackMenu->addAction(slowAction);
Chris@0 1137 m_rightButtonPlaybackMenu->addAction(normalAction);
Chris@6 1138
Chris@195 1139 toolbar = new QToolBar(tr("Playback Controls"));
Chris@195 1140 addToolBar(Qt::BottomToolBarArea, toolbar);
Chris@195 1141
Chris@6 1142 toolbar->addWidget(m_playSpeed);
Chris@6 1143 toolbar->addWidget(m_fader);
Chris@0 1144
Chris@128 1145 toolbar = addToolBar(tr("Show and Play"));
matthiasm@258 1146 addToolBar(Qt::BottomToolBarArea, toolbar);
Chris@144 1147
Chris@144 1148 m_showAudio = toolbar->addAction(il.load("waveform"), tr("Show Audio"));
Chris@144 1149 m_showAudio->setCheckable(true);
Chris@144 1150 connect(m_showAudio, SIGNAL(triggered()), this, SLOT(showAudioToggled()));
Chris@144 1151 connect(this, SIGNAL(canPlay(bool)), m_showAudio, SLOT(setEnabled(bool)));
Chris@144 1152
Chris@424 1153 m_playAudio = toolbar->addAction(il.load("speaker"), tr("Play Audio"));
Chris@424 1154 m_playAudio->setCheckable(true);
Chris@424 1155 connect(m_playAudio, SIGNAL(triggered()), this, SLOT(playAudioToggled()));
Chris@424 1156 connect(this, SIGNAL(canPlayWaveform(bool)), m_playAudio, SLOT(setEnabled(bool)));
Chris@424 1157
Chris@419 1158 m_audioLPW->setImageSize(m_viewManager->scalePixelSize(26));
Chris@414 1159 toolbar->addWidget(m_audioLPW);
Chris@414 1160
Chris@290 1161 // Pitch (f0)
Chris@290 1162 QLabel *spacer = new QLabel; // blank
Chris@419 1163 spacer->setFixedWidth(m_viewManager->scalePixelSize(30));
Chris@290 1164 toolbar->addWidget(spacer);
Chris@145 1165
Chris@144 1166 m_showPitch = toolbar->addAction(il.load("values"), tr("Show Pitch Track"));
Chris@144 1167 m_showPitch->setCheckable(true);
Chris@144 1168 connect(m_showPitch, SIGNAL(triggered()), this, SLOT(showPitchToggled()));
Chris@144 1169 connect(this, SIGNAL(canPlay(bool)), m_showPitch, SLOT(setEnabled(bool)));
Chris@144 1170
Chris@405 1171 if (m_withSonification) {
Chris@424 1172 m_playPitch = toolbar->addAction(il.load("speaker"), tr("Play Pitch Track"));
Chris@424 1173 m_playPitch->setCheckable(true);
Chris@424 1174 connect(m_playPitch, SIGNAL(triggered()), this, SLOT(playPitchToggled()));
Chris@424 1175 connect(this, SIGNAL(canPlayPitch(bool)), m_playPitch, SLOT(setEnabled(bool)));
Chris@424 1176
Chris@419 1177 m_pitchLPW->setImageSize(m_viewManager->scalePixelSize(26));
Chris@404 1178 toolbar->addWidget(m_pitchLPW);
Chris@424 1179 } else {
Chris@424 1180 m_playPitch = 0;
matthiasm@366 1181 }
Chris@404 1182
Chris@290 1183 // Notes
Chris@290 1184 spacer = new QLabel;
Chris@419 1185 spacer->setFixedWidth(m_viewManager->scalePixelSize(30));
Chris@290 1186 toolbar->addWidget(spacer);
Chris@290 1187
Chris@144 1188 m_showNotes = toolbar->addAction(il.load("notes"), tr("Show Notes"));
Chris@144 1189 m_showNotes->setCheckable(true);
Chris@144 1190 connect(m_showNotes, SIGNAL(triggered()), this, SLOT(showNotesToggled()));
Chris@144 1191 connect(this, SIGNAL(canPlay(bool)), m_showNotes, SLOT(setEnabled(bool)));
justin@156 1192
Chris@405 1193 if (m_withSonification) {
Chris@424 1194 m_playNotes = toolbar->addAction(il.load("speaker"), tr("Play Notes"));
Chris@424 1195 m_playNotes->setCheckable(true);
Chris@424 1196 connect(m_playNotes, SIGNAL(triggered()), this, SLOT(playNotesToggled()));
Chris@424 1197 connect(this, SIGNAL(canPlayNotes(bool)), m_playNotes, SLOT(setEnabled(bool)));
Chris@424 1198
Chris@419 1199 m_notesLPW->setImageSize(m_viewManager->scalePixelSize(26));
Chris@404 1200 toolbar->addWidget(m_notesLPW);
Chris@424 1201 } else {
Chris@424 1202 m_playNotes = 0;
matthiasm@366 1203 }
justin@156 1204
justin@156 1205 // Spectrogram
Chris@290 1206 spacer = new QLabel;
Chris@419 1207 spacer->setFixedWidth(m_viewManager->scalePixelSize(30));
Chris@290 1208 toolbar->addWidget(spacer);
Chris@290 1209
matthiasm@366 1210 if (!m_withSpectrogram)
matthiasm@366 1211 {
matthiasm@366 1212 m_showSpect = new QAction(tr("Show Spectrogram"), this);
matthiasm@366 1213 } else {
matthiasm@366 1214 m_showSpect = toolbar->addAction(il.load("spectrogram"), tr("Show Spectrogram"));
matthiasm@366 1215 }
justin@156 1216 m_showSpect->setCheckable(true);
justin@156 1217 connect(m_showSpect, SIGNAL(triggered()), this, SLOT(showSpectToggled()));
justin@156 1218 connect(this, SIGNAL(canPlay(bool)), m_showSpect, SLOT(setEnabled(bool)));
Chris@128 1219
Chris@0 1220 Pane::registerShortcuts(*m_keyReference);
matthiasm@366 1221
Chris@405 1222 updateLayerStatuses();
Chris@0 1223 }
Chris@0 1224
matthiasm@281 1225
matthiasm@281 1226 void
matthiasm@281 1227 MainWindow::moveOneNoteRight()
matthiasm@281 1228 {
matthiasm@281 1229 // cerr << "MainWindow::moveOneNoteRight" << endl;
matthiasm@296 1230 moveByOneNote(true, false);
matthiasm@281 1231 }
matthiasm@281 1232
matthiasm@281 1233 void
matthiasm@281 1234 MainWindow::moveOneNoteLeft()
matthiasm@281 1235 {
matthiasm@281 1236 // cerr << "MainWindow::moveOneNoteLeft" << endl;
matthiasm@296 1237 moveByOneNote(false, false);
matthiasm@281 1238 }
matthiasm@281 1239
matthiasm@281 1240 void
matthiasm@283 1241 MainWindow::selectOneNoteRight()
matthiasm@283 1242 {
matthiasm@296 1243 moveByOneNote(true, true);
matthiasm@283 1244 }
matthiasm@283 1245
matthiasm@283 1246 void
matthiasm@283 1247 MainWindow::selectOneNoteLeft()
matthiasm@283 1248 {
matthiasm@296 1249 moveByOneNote(false, true);
matthiasm@283 1250 }
matthiasm@283 1251
matthiasm@283 1252
matthiasm@283 1253 void
matthiasm@296 1254 MainWindow::moveByOneNote(bool right, bool doSelect)
matthiasm@281 1255 {
Chris@399 1256 sv_frame_t frame = m_viewManager->getPlaybackFrame();
matthiasm@301 1257 cerr << "MainWindow::moveByOneNote startframe: " << frame << endl;
matthiasm@281 1258
matthiasm@304 1259 bool isAtSelectionBoundary = false;
matthiasm@304 1260 MultiSelection::SelectionList selections = m_viewManager->getSelections();
matthiasm@304 1261 if (!selections.empty()) {
matthiasm@304 1262 Selection sel = *selections.begin();
matthiasm@342 1263 isAtSelectionBoundary = (frame == sel.getStartFrame()) || (frame == sel.getEndFrame());
matthiasm@304 1264 }
matthiasm@304 1265 if (!doSelect || !isAtSelectionBoundary) {
matthiasm@296 1266 m_selectionAnchor = frame;
matthiasm@296 1267 }
matthiasm@296 1268
matthiasm@281 1269 Layer *layer = m_analyser->getLayer(Analyser::Notes);
matthiasm@281 1270 if (!layer) return;
matthiasm@281 1271
matthiasm@281 1272 FlexiNoteModel *model = qobject_cast<FlexiNoteModel *>(layer->getModel());
matthiasm@281 1273 if (!model) return;
matthiasm@281 1274
matthiasm@281 1275 FlexiNoteModel::PointList points = model->getPoints();
matthiasm@281 1276 if (points.empty()) return;
matthiasm@281 1277
matthiasm@281 1278 FlexiNoteModel::PointList::iterator i = points.begin();
Chris@399 1279 std::set<sv_frame_t> snapFrames;
matthiasm@281 1280 snapFrames.insert(0);
matthiasm@281 1281 while (i != points.end()) {
matthiasm@281 1282 snapFrames.insert(i->frame);
matthiasm@281 1283 snapFrames.insert(i->frame + i->duration + 1);
matthiasm@281 1284 ++i;
matthiasm@281 1285 }
Chris@399 1286 std::set<sv_frame_t>::iterator i2;
Chris@399 1287 if (snapFrames.find(frame) == snapFrames.end()) {
matthiasm@281 1288 // we're not on an existing snap point, so go to previous
matthiasm@281 1289 snapFrames.insert(frame);
matthiasm@281 1290 }
matthiasm@281 1291 i2 = snapFrames.find(frame);
Chris@399 1292 if (right) {
matthiasm@281 1293 i2++;
matthiasm@281 1294 if (i2 == snapFrames.end()) i2--;
matthiasm@281 1295 } else {
matthiasm@281 1296 if (i2 != snapFrames.begin()) i2--;
matthiasm@281 1297 }
matthiasm@281 1298 frame = *i2;
matthiasm@281 1299 m_viewManager->setPlaybackFrame(frame);
matthiasm@296 1300 if (doSelect) {
matthiasm@296 1301 Selection sel;
matthiasm@296 1302 if (frame > m_selectionAnchor) {
matthiasm@342 1303 sel = Selection(m_selectionAnchor, frame);
matthiasm@296 1304 } else {
matthiasm@342 1305 sel = Selection(frame, m_selectionAnchor);
matthiasm@296 1306 }
matthiasm@296 1307 m_viewManager->setSelection(sel);
matthiasm@296 1308 }
matthiasm@301 1309 cerr << "MainWindow::moveByOneNote endframe: " << frame << endl;
matthiasm@281 1310 }
matthiasm@281 1311
Chris@0 1312 void
Chris@70 1313 MainWindow::toolNavigateSelected()
Chris@70 1314 {
Chris@70 1315 m_viewManager->setToolMode(ViewManager::NavigateMode);
Chris@70 1316 m_intelligentActionOn = true;
Chris@70 1317 }
Chris@70 1318
Chris@70 1319 void
Chris@70 1320 MainWindow::toolEditSelected()
Chris@70 1321 {
matthiasm@294 1322 cerr << "MainWindow::toolEditSelected" << endl;
Chris@77 1323 m_viewManager->setToolMode(ViewManager::NoteEditMode);
Chris@70 1324 m_intelligentActionOn = true;
Chris@70 1325 m_analyser->setIntelligentActions(m_intelligentActionOn);
Chris@70 1326 }
Chris@70 1327
Chris@70 1328 void
Chris@70 1329 MainWindow::toolFreeEditSelected()
Chris@70 1330 {
Chris@77 1331 m_viewManager->setToolMode(ViewManager::NoteEditMode);
Chris@70 1332 m_intelligentActionOn = false;
Chris@70 1333 m_analyser->setIntelligentActions(m_intelligentActionOn);
Chris@70 1334 }
Chris@70 1335
gyorgyf@21 1336 void
Chris@0 1337 MainWindow::updateMenuStates()
Chris@0 1338 {
Chris@0 1339 MainWindowBase::updateMenuStates();
Chris@0 1340
Chris@0 1341 Pane *currentPane = 0;
Chris@0 1342 Layer *currentLayer = 0;
Chris@0 1343
Chris@0 1344 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
Chris@0 1345 if (currentPane) currentLayer = currentPane->getSelectedLayer();
Chris@0 1346
Chris@291 1347 bool haveMainModel =
Chris@291 1348 (getMainModel() != 0);
Chris@291 1349 bool havePlayTarget =
Chris@291 1350 (m_playTarget != 0);
Chris@0 1351 bool haveCurrentPane =
Chris@0 1352 (currentPane != 0);
Chris@0 1353 bool haveCurrentLayer =
Chris@0 1354 (haveCurrentPane &&
Chris@0 1355 (currentLayer != 0));
Chris@0 1356 bool haveSelection =
Chris@187 1357 (m_viewManager &&
Chris@187 1358 !m_viewManager->getSelections().empty());
Chris@0 1359 bool haveCurrentTimeInstantsLayer =
Chris@187 1360 (haveCurrentLayer &&
Chris@187 1361 qobject_cast<TimeInstantLayer *>(currentLayer));
Chris@0 1362 bool haveCurrentTimeValueLayer =
Chris@187 1363 (haveCurrentLayer &&
Chris@187 1364 qobject_cast<TimeValueLayer *>(currentLayer));
Chris@187 1365 bool pitchCandidatesVisible =
Chris@187 1366 m_analyser->arePitchCandidatesShown();
Chris@0 1367
Chris@0 1368 emit canChangePlaybackSpeed(true);
Chris@0 1369 int v = m_playSpeed->value();
Chris@0 1370 emit canSpeedUpPlayback(v < m_playSpeed->maximum());
Chris@0 1371 emit canSlowDownPlayback(v > m_playSpeed->minimum());
Chris@0 1372
Chris@291 1373 bool haveWaveform =
Chris@291 1374 m_analyser->isVisible(Analyser::Audio) &&
Chris@291 1375 m_analyser->getLayer(Analyser::Audio);
Chris@291 1376
Chris@237 1377 bool havePitchTrack =
Chris@237 1378 m_analyser->isVisible(Analyser::PitchTrack) &&
Chris@237 1379 m_analyser->getLayer(Analyser::PitchTrack);
Chris@237 1380
Chris@237 1381 bool haveNotes =
Chris@237 1382 m_analyser->isVisible(Analyser::Notes) &&
Chris@237 1383 m_analyser->getLayer(Analyser::Notes);
Chris@237 1384
Chris@237 1385 emit canExportPitchTrack(havePitchTrack);
Chris@237 1386 emit canExportNotes(haveNotes);
Chris@237 1387 emit canSnapNotes(haveSelection && haveNotes);
Chris@224 1388
Chris@291 1389 emit canPlayWaveform(haveWaveform && haveMainModel && havePlayTarget);
Chris@291 1390 emit canPlayPitch(havePitchTrack && haveMainModel && havePlayTarget);
Chris@291 1391 emit canPlayNotes(haveNotes && haveMainModel && havePlayTarget);
Chris@291 1392
Chris@187 1393 if (pitchCandidatesVisible) {
Chris@187 1394 m_showCandidatesAction->setText(tr("Hide Pitch Candidates"));
Chris@187 1395 m_showCandidatesAction->setStatusTip(tr("Remove the display of alternate pitch candidates for the selected region"));
Chris@187 1396 } else {
Chris@187 1397 m_showCandidatesAction->setText(tr("Show Pitch Candidates"));
Chris@187 1398 m_showCandidatesAction->setStatusTip(tr("Show alternate pitch candidates for the selected region"));
Chris@187 1399 }
Chris@187 1400
Chris@0 1401 if (m_ffwdAction && m_rwdAction) {
Chris@0 1402 if (haveCurrentTimeInstantsLayer) {
Chris@0 1403 m_ffwdAction->setText(tr("Fast Forward to Next Instant"));
Chris@0 1404 m_ffwdAction->setStatusTip(tr("Fast forward to the next time instant in the current layer"));
Chris@0 1405 m_rwdAction->setText(tr("Rewind to Previous Instant"));
Chris@0 1406 m_rwdAction->setStatusTip(tr("Rewind to the previous time instant in the current layer"));
Chris@0 1407 } else if (haveCurrentTimeValueLayer) {
Chris@0 1408 m_ffwdAction->setText(tr("Fast Forward to Next Point"));
Chris@0 1409 m_ffwdAction->setStatusTip(tr("Fast forward to the next point in the current layer"));
Chris@0 1410 m_rwdAction->setText(tr("Rewind to Previous Point"));
Chris@0 1411 m_rwdAction->setStatusTip(tr("Rewind to the previous point in the current layer"));
Chris@0 1412 } else {
Chris@0 1413 m_ffwdAction->setText(tr("Fast Forward"));
Chris@0 1414 m_ffwdAction->setStatusTip(tr("Fast forward"));
Chris@0 1415 m_rwdAction->setText(tr("Rewind"));
Chris@0 1416 m_rwdAction->setStatusTip(tr("Rewind"));
Chris@0 1417 }
Chris@0 1418 }
Chris@0 1419 }
Chris@0 1420
Chris@0 1421 void
Chris@144 1422 MainWindow::showAudioToggled()
Chris@128 1423 {
Chris@144 1424 m_analyser->toggleVisible(Analyser::Audio);
justin@220 1425
Chris@424 1426 QSettings settings;
Chris@424 1427 settings.beginGroup("MainWindow");
Chris@424 1428
Chris@424 1429 bool playOn = false;
Chris@424 1430 if (m_analyser->isVisible(Analyser::Audio)) {
Chris@424 1431 // just switched layer on; check whether playback was also on previously
Chris@424 1432 playOn = settings.value("playaudiowas", true).toBool();
Chris@424 1433 } else {
Chris@424 1434 settings.setValue("playaudiowas", m_playAudio->isChecked());
Chris@424 1435 }
Chris@291 1436 m_analyser->setAudible(Analyser::Audio, playOn);
Chris@424 1437
Chris@424 1438 settings.endGroup();
Chris@291 1439
Chris@291 1440 updateMenuStates();
Chris@424 1441 updateLayerStatuses();
Chris@128 1442 }
Chris@128 1443
Chris@128 1444 void
Chris@144 1445 MainWindow::showPitchToggled()
Chris@128 1446 {
Chris@144 1447 m_analyser->toggleVisible(Analyser::PitchTrack);
justin@185 1448
Chris@424 1449 QSettings settings;
Chris@424 1450 settings.beginGroup("MainWindow");
Chris@424 1451
Chris@424 1452 bool playOn = false;
Chris@424 1453 if (m_analyser->isVisible(Analyser::PitchTrack)) {
Chris@424 1454 // just switched layer on; check whether playback was also on previously
Chris@424 1455 playOn = settings.value("playpitchwas", true).toBool();
Chris@424 1456 } else {
Chris@424 1457 settings.setValue("playpitchwas", m_playPitch->isChecked());
Chris@424 1458 }
Chris@424 1459 m_analyser->setAudible(Analyser::PitchTrack, playOn);
Chris@424 1460
Chris@424 1461 settings.endGroup();
Chris@291 1462
Chris@291 1463 updateMenuStates();
Chris@424 1464 updateLayerStatuses();
Chris@128 1465 }
Chris@128 1466
Chris@128 1467 void
Chris@145 1468 MainWindow::showSpectToggled()
Chris@145 1469 {
Chris@145 1470 m_analyser->toggleVisible(Analyser::Spectrogram);
Chris@145 1471 }
Chris@145 1472
Chris@145 1473 void
Chris@144 1474 MainWindow::showNotesToggled()
Chris@128 1475 {
Chris@144 1476 m_analyser->toggleVisible(Analyser::Notes);
justin@220 1477
Chris@424 1478 QSettings settings;
Chris@424 1479 settings.beginGroup("MainWindow");
Chris@424 1480
Chris@424 1481 bool playOn = false;
Chris@424 1482 if (m_analyser->isVisible(Analyser::Notes)) {
Chris@424 1483 // just switched layer on; check whether playback was also on previously
Chris@424 1484 playOn = settings.value("playnoteswas", true).toBool();
Chris@424 1485 } else {
Chris@424 1486 settings.setValue("playnoteswas", m_playNotes->isChecked());
Chris@424 1487 }
Chris@424 1488 m_analyser->setAudible(Analyser::Notes, playOn);
Chris@424 1489
Chris@424 1490 settings.endGroup();
Chris@291 1491
Chris@291 1492 updateMenuStates();
Chris@424 1493 updateLayerStatuses();
Chris@144 1494 }
Chris@144 1495
Chris@144 1496 void
Chris@144 1497 MainWindow::playAudioToggled()
Chris@144 1498 {
Chris@144 1499 m_analyser->toggleAudible(Analyser::Audio);
Chris@424 1500 updateLayerStatuses();
Chris@144 1501 }
Chris@144 1502
Chris@144 1503 void
Chris@144 1504 MainWindow::playPitchToggled()
Chris@144 1505 {
Chris@144 1506 m_analyser->toggleAudible(Analyser::PitchTrack);
Chris@424 1507 updateLayerStatuses();
Chris@144 1508 }
Chris@144 1509
Chris@144 1510 void
Chris@144 1511 MainWindow::playNotesToggled()
Chris@144 1512 {
Chris@144 1513 m_analyser->toggleAudible(Analyser::Notes);
Chris@424 1514 updateLayerStatuses();
Chris@144 1515 }
Chris@144 1516
Chris@144 1517 void
Chris@144 1518 MainWindow::updateLayerStatuses()
Chris@144 1519 {
Chris@144 1520 m_showAudio->setChecked(m_analyser->isVisible(Analyser::Audio));
Chris@424 1521 m_playAudio->setChecked(m_analyser->isAudible(Analyser::Audio));
Chris@424 1522 m_audioLPW->setEnabled(m_analyser->isAudible(Analyser::Audio));
Chris@405 1523 m_audioLPW->setLevel(m_analyser->getGain(Analyser::Audio));
Chris@405 1524 m_audioLPW->setPan(m_analyser->getPan(Analyser::Audio));
Chris@424 1525
Chris@405 1526 m_showPitch->setChecked(m_analyser->isVisible(Analyser::PitchTrack));
Chris@424 1527 m_playPitch->setChecked(m_analyser->isAudible(Analyser::PitchTrack));
Chris@424 1528 m_pitchLPW->setEnabled(m_analyser->isAudible(Analyser::PitchTrack));
Chris@405 1529 m_pitchLPW->setLevel(m_analyser->getGain(Analyser::PitchTrack));
Chris@405 1530 m_pitchLPW->setPan(m_analyser->getPan(Analyser::PitchTrack));
Chris@405 1531
Chris@405 1532 m_showNotes->setChecked(m_analyser->isVisible(Analyser::Notes));
Chris@424 1533 m_playNotes->setChecked(m_analyser->isAudible(Analyser::Notes));
Chris@424 1534 m_notesLPW->setEnabled(m_analyser->isAudible(Analyser::Notes));
Chris@405 1535 m_notesLPW->setLevel(m_analyser->getGain(Analyser::Notes));
Chris@405 1536 m_notesLPW->setPan(m_analyser->getPan(Analyser::Notes));
Chris@405 1537
Chris@145 1538 m_showSpect->setChecked(m_analyser->isVisible(Analyser::Spectrogram));
Chris@128 1539 }
Chris@128 1540
Chris@128 1541 void
Chris@227 1542 MainWindow::editDisplayExtents()
Chris@227 1543 {
Chris@399 1544 double min, max;
Chris@399 1545 double vmin = 0;
Chris@399 1546 double vmax = getMainModel()->getSampleRate() /2;
Chris@227 1547
Chris@227 1548 if (!m_analyser->getDisplayFrequencyExtents(min, max)) {
Chris@227 1549 //!!!
Chris@227 1550 return;
Chris@227 1551 }
Chris@227 1552
Chris@227 1553 RangeInputDialog dialog(tr("Set frequency range"),
Chris@227 1554 tr("Enter new frequency range, from %1 to %2 Hz.\nThese values will be rounded to the nearest spectrogram bin.")
Chris@227 1555 .arg(vmin).arg(vmax),
Chris@399 1556 "Hz", float(vmin), float(vmax), this);
Chris@399 1557 dialog.setRange(float(min), float(max));
Chris@227 1558
Chris@227 1559 if (dialog.exec() == QDialog::Accepted) {
Chris@399 1560 float fmin, fmax;
Chris@399 1561 dialog.getRange(fmin, fmax);
Chris@399 1562 min = fmin;
Chris@399 1563 max = fmax;
Chris@227 1564 if (min > max) {
Chris@399 1565 double tmp = max;
Chris@227 1566 max = min;
Chris@227 1567 min = tmp;
Chris@227 1568 }
Chris@227 1569 m_analyser->setDisplayFrequencyExtents(min, max);
Chris@227 1570 }
Chris@227 1571 }
Chris@227 1572
Chris@227 1573 void
Chris@0 1574 MainWindow::updateDescriptionLabel()
Chris@0 1575 {
Chris@6 1576 // Nothing, we don't have one
Chris@0 1577 }
Chris@0 1578
Chris@0 1579 void
Chris@0 1580 MainWindow::documentModified()
Chris@0 1581 {
Chris@0 1582 MainWindowBase::documentModified();
Chris@0 1583 }
Chris@0 1584
Chris@0 1585 void
Chris@0 1586 MainWindow::documentRestored()
Chris@0 1587 {
Chris@0 1588 MainWindowBase::documentRestored();
Chris@0 1589 }
Chris@0 1590
Chris@0 1591 void
Chris@0 1592 MainWindow::newSession()
Chris@0 1593 {
Chris@0 1594 if (!checkSaveModified()) return;
Chris@0 1595
Chris@0 1596 closeSession();
Chris@0 1597 createDocument();
Chris@0 1598 m_document->setAutoAlignment(true);
Chris@0 1599
Chris@0 1600 Pane *pane = m_paneStack->addPane();
Chris@362 1601 pane->setPlaybackFollow(PlaybackScrollPage);
Chris@0 1602
Chris@391 1603 m_viewManager->setGlobalCentreFrame
Chris@391 1604 (pane->getFrameForX(width() / 2));
Chris@391 1605
Chris@0 1606 connect(pane, SIGNAL(contextHelpChanged(const QString &)),
Chris@0 1607 this, SLOT(contextHelpChanged(const QString &)));
Chris@0 1608
Chris@6 1609 // Layer *waveform = m_document->createMainModelLayer(LayerFactory::Waveform);
Chris@6 1610 // m_document->addLayerToView(pane, waveform);
Chris@0 1611
Chris@0 1612 m_overview->registerView(pane);
Chris@0 1613
Chris@0 1614 CommandHistory::getInstance()->clear();
Chris@0 1615 CommandHistory::getInstance()->documentSaved();
Chris@0 1616 documentRestored();
Chris@0 1617 updateMenuStates();
Chris@0 1618 }
Chris@0 1619
Chris@0 1620 void
Chris@244 1621 MainWindow::documentReplaced()
Chris@244 1622 {
Chris@244 1623 if (m_document) {
Chris@244 1624 connect(m_document, SIGNAL(activity(QString)),
Chris@244 1625 m_activityLog, SLOT(activityHappened(QString)));
Chris@244 1626 }
Chris@244 1627 }
Chris@244 1628
Chris@244 1629 void
Chris@0 1630 MainWindow::closeSession()
Chris@0 1631 {
Chris@0 1632 if (!checkSaveModified()) return;
Chris@0 1633
Chris@226 1634 m_analyser->fileClosed();
Chris@226 1635
Chris@0 1636 while (m_paneStack->getPaneCount() > 0) {
Chris@0 1637
Chris@167 1638 Pane *pane = m_paneStack->getPane(m_paneStack->getPaneCount() - 1);
Chris@0 1639
Chris@167 1640 while (pane->getLayerCount() > 0) {
Chris@167 1641 m_document->removeLayerFromView
Chris@167 1642 (pane, pane->getLayer(pane->getLayerCount() - 1));
Chris@167 1643 }
Chris@167 1644
Chris@167 1645 m_overview->unregisterView(pane);
Chris@167 1646 m_paneStack->deletePane(pane);
Chris@0 1647 }
Chris@0 1648
Chris@0 1649 while (m_paneStack->getHiddenPaneCount() > 0) {
Chris@0 1650
Chris@167 1651 Pane *pane = m_paneStack->getHiddenPane
Chris@167 1652 (m_paneStack->getHiddenPaneCount() - 1);
Chris@167 1653
Chris@167 1654 while (pane->getLayerCount() > 0) {
Chris@167 1655 m_document->removeLayerFromView
Chris@167 1656 (pane, pane->getLayer(pane->getLayerCount() - 1));
Chris@167 1657 }
Chris@167 1658
Chris@167 1659 m_overview->unregisterView(pane);
Chris@167 1660 m_paneStack->deletePane(pane);
Chris@0 1661 }
Chris@0 1662
Chris@0 1663 delete m_document;
Chris@0 1664 m_document = 0;
Chris@0 1665 m_viewManager->clearSelections();
Chris@0 1666 m_timeRulerLayer = 0; // document owned this
Chris@0 1667
Chris@0 1668 m_sessionFile = "";
Chris@0 1669
Chris@0 1670 CommandHistory::getInstance()->clear();
Chris@0 1671 CommandHistory::getInstance()->documentSaved();
Chris@0 1672 documentRestored();
Chris@0 1673 }
Chris@0 1674
Chris@0 1675 void
Chris@0 1676 MainWindow::openFile()
Chris@0 1677 {
Chris@0 1678 QString orig = m_audioFile;
Chris@0 1679 if (orig == "") orig = ".";
Chris@0 1680 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 1681
Chris@0 1682 QString path = getOpenFileName(FileFinder::AnyFile);
Chris@0 1683
Chris@0 1684 if (path.isEmpty()) return;
Chris@0 1685
Chris@387 1686 FileOpenStatus status = openPath(path, ReplaceSession);
Chris@0 1687
Chris@0 1688 if (status == FileOpenFailed) {
Chris@0 1689 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 1690 tr("<b>File open failed</b><p>File \"%1\" could not be opened").arg(path));
Chris@0 1691 } else if (status == FileOpenWrongMode) {
Chris@0 1692 QMessageBox::critical(this, tr("Failed to open file"),
Chris@0 1693 tr("<b>Audio required</b><p>Please load at least one audio file before importing annotation data"));
Chris@0 1694 }
Chris@0 1695 }
Chris@0 1696
Chris@0 1697 void
Chris@0 1698 MainWindow::openLocation()
Chris@0 1699 {
Chris@0 1700 QSettings settings;
Chris@0 1701 settings.beginGroup("MainWindow");
Chris@0 1702 QString lastLocation = settings.value("lastremote", "").toString();
Chris@0 1703
Chris@0 1704 bool ok = false;
Chris@0 1705 QString text = QInputDialog::getText
Chris@0 1706 (this, tr("Open Location"),
Chris@0 1707 tr("Please enter the URL of the location to open:"),
Chris@0 1708 QLineEdit::Normal, lastLocation, &ok);
Chris@0 1709
Chris@0 1710 if (!ok) return;
Chris@0 1711
Chris@0 1712 settings.setValue("lastremote", text);
Chris@0 1713
Chris@0 1714 if (text.isEmpty()) return;
Chris@0 1715
Chris@387 1716 FileOpenStatus status = openPath(text, ReplaceSession);
Chris@0 1717
Chris@0 1718 if (status == FileOpenFailed) {
Chris@0 1719 QMessageBox::critical(this, tr("Failed to open location"),
Chris@0 1720 tr("<b>Open failed</b><p>URL \"%1\" could not be opened").arg(text));
Chris@0 1721 } else if (status == FileOpenWrongMode) {
Chris@0 1722 QMessageBox::critical(this, tr("Failed to open location"),
Chris@0 1723 tr("<b>Audio required</b><p>Please load at least one audio file before importing annotation data"));
Chris@0 1724 }
Chris@0 1725 }
Chris@0 1726
Chris@0 1727 void
Chris@0 1728 MainWindow::openRecentFile()
Chris@0 1729 {
Chris@0 1730 QObject *obj = sender();
Chris@3 1731 QAction *action = qobject_cast<QAction *>(obj);
Chris@0 1732
Chris@0 1733 if (!action) {
Chris@188 1734 cerr << "WARNING: MainWindow::openRecentFile: sender is not an action"
Chris@188 1735 << endl;
Chris@188 1736 return;
Chris@0 1737 }
Chris@0 1738
Chris@0 1739 QString path = action->text();
Chris@0 1740 if (path == "") return;
Chris@0 1741
Chris@387 1742 FileOpenStatus status = openPath(path, ReplaceSession);
Chris@0 1743
Chris@0 1744 if (status == FileOpenFailed) {
Chris@0 1745 QMessageBox::critical(this, tr("Failed to open location"),
Chris@0 1746 tr("<b>Open failed</b><p>File or URL \"%1\" could not be opened").arg(path));
Chris@0 1747 } else if (status == FileOpenWrongMode) {
Chris@0 1748 QMessageBox::critical(this, tr("Failed to open location"),
Chris@0 1749 tr("<b>Audio required</b><p>Please load at least one audio file before importing annotation data"));
Chris@0 1750 }
Chris@0 1751 }
Chris@0 1752
Chris@0 1753 void
Chris@0 1754 MainWindow::paneAdded(Pane *pane)
Chris@0 1755 {
Chris@6 1756 pane->setPlaybackFollow(PlaybackScrollPage);
Chris@0 1757 m_paneStack->sizePanesEqually();
Chris@0 1758 if (m_overview) m_overview->registerView(pane);
Chris@0 1759 }
Chris@0 1760
Chris@0 1761 void
Chris@0 1762 MainWindow::paneHidden(Pane *pane)
Chris@0 1763 {
Chris@0 1764 if (m_overview) m_overview->unregisterView(pane);
Chris@0 1765 }
Chris@0 1766
Chris@0 1767 void
Chris@0 1768 MainWindow::paneAboutToBeDeleted(Pane *pane)
Chris@0 1769 {
Chris@0 1770 if (m_overview) m_overview->unregisterView(pane);
Chris@0 1771 }
Chris@0 1772
Chris@0 1773 void
Chris@0 1774 MainWindow::paneDropAccepted(Pane *pane, QStringList uriList)
Chris@0 1775 {
Chris@4 1776 if (pane) m_paneStack->setCurrentPane(pane);
Chris@0 1777
Chris@0 1778 for (QStringList::iterator i = uriList.begin(); i != uriList.end(); ++i) {
Chris@0 1779
Chris@387 1780 FileOpenStatus status = openPath(*i, ReplaceSession);
Chris@0 1781
Chris@0 1782 if (status == FileOpenFailed) {
Chris@0 1783 QMessageBox::critical(this, tr("Failed to open dropped URL"),
Chris@0 1784 tr("<b>Open failed</b><p>Dropped URL \"%1\" could not be opened").arg(*i));
Chris@0 1785 } else if (status == FileOpenWrongMode) {
Chris@0 1786 QMessageBox::critical(this, tr("Failed to open dropped URL"),
Chris@0 1787 tr("<b>Audio required</b><p>Please load at least one audio file before importing annotation data"));
Chris@0 1788 }
Chris@0 1789 }
Chris@0 1790 }
Chris@0 1791
Chris@0 1792 void
Chris@0 1793 MainWindow::paneDropAccepted(Pane *pane, QString text)
Chris@0 1794 {
Chris@0 1795 if (pane) m_paneStack->setCurrentPane(pane);
Chris@0 1796
Chris@0 1797 QUrl testUrl(text);
Chris@0 1798 if (testUrl.scheme() == "file" ||
Chris@0 1799 testUrl.scheme() == "http" ||
Chris@0 1800 testUrl.scheme() == "ftp") {
Chris@0 1801 QStringList list;
Chris@0 1802 list.push_back(text);
Chris@0 1803 paneDropAccepted(pane, list);
Chris@0 1804 return;
Chris@0 1805 }
Chris@0 1806
Chris@0 1807 //!!! open as text -- but by importing as if a CSV, or just adding
Chris@0 1808 //to a text layer?
Chris@0 1809 }
Chris@0 1810
Chris@0 1811 void
Chris@0 1812 MainWindow::closeEvent(QCloseEvent *e)
Chris@0 1813 {
Chris@70 1814 // cerr << "MainWindow::closeEvent" << endl;
Chris@0 1815
Chris@0 1816 if (m_openingAudioFile) {
Chris@70 1817 // cerr << "Busy - ignoring close event" << endl;
Chris@257 1818 e->ignore();
Chris@257 1819 return;
Chris@0 1820 }
Chris@0 1821
Chris@0 1822 if (!m_abandoning && !checkSaveModified()) {
Chris@70 1823 // cerr << "Ignoring close event" << endl;
Chris@257 1824 e->ignore();
Chris@257 1825 return;
Chris@0 1826 }
Chris@0 1827
Chris@0 1828 QSettings settings;
Chris@0 1829 settings.beginGroup("MainWindow");
Chris@0 1830 settings.setValue("size", size());
Chris@0 1831 settings.setValue("position", pos());
Chris@0 1832 settings.endGroup();
Chris@0 1833
Chris@0 1834 delete m_keyReference;
Chris@0 1835 m_keyReference = 0;
Chris@0 1836
Chris@0 1837 closeSession();
Chris@0 1838
Chris@0 1839 e->accept();
Chris@0 1840 return;
Chris@0 1841 }
Chris@0 1842
Chris@0 1843 bool
Chris@0 1844 MainWindow::commitData(bool mayAskUser)
Chris@0 1845 {
Chris@0 1846 if (mayAskUser) {
Chris@0 1847 bool rv = checkSaveModified();
Chris@0 1848 return rv;
Chris@0 1849 } else {
Chris@0 1850 if (!m_documentModified) return true;
Chris@0 1851
Chris@0 1852 // If we can't check with the user first, then we can't save
Chris@0 1853 // to the original session file (even if we have it) -- have
Chris@0 1854 // to use a temporary file
Chris@0 1855
Chris@0 1856 QString svDirBase = ".sv1";
Chris@0 1857 QString svDir = QDir::home().filePath(svDirBase);
Chris@0 1858
Chris@0 1859 if (!QFileInfo(svDir).exists()) {
Chris@0 1860 if (!QDir::home().mkdir(svDirBase)) return false;
Chris@0 1861 } else {
Chris@0 1862 if (!QFileInfo(svDir).isDir()) return false;
Chris@0 1863 }
Chris@0 1864
Chris@0 1865 // This name doesn't have to be unguessable
Chris@0 1866 #ifndef _WIN32
Chris@0 1867 QString fname = QString("tmp-%1-%2.sv")
Chris@0 1868 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"))
Chris@0 1869 .arg(QProcess().pid());
Chris@0 1870 #else
Chris@0 1871 QString fname = QString("tmp-%1.sv")
Chris@0 1872 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"));
Chris@0 1873 #endif
Chris@0 1874 QString fpath = QDir(svDir).filePath(fname);
Chris@0 1875 if (saveSessionFile(fpath)) {
Chris@0 1876 m_recentFiles.addFile(fpath);
Chris@0 1877 return true;
Chris@0 1878 } else {
Chris@0 1879 return false;
Chris@0 1880 }
Chris@0 1881 }
Chris@0 1882 }
Chris@0 1883
Chris@0 1884 bool
Chris@0 1885 MainWindow::checkSaveModified()
Chris@0 1886 {
Chris@0 1887 // Called before some destructive operation (e.g. new session,
Chris@0 1888 // exit program). Return true if we can safely proceed, false to
Chris@0 1889 // cancel.
Chris@0 1890
Chris@0 1891 if (!m_documentModified) return true;
Chris@0 1892
Chris@0 1893 int button =
Chris@257 1894 QMessageBox::warning(this,
Chris@257 1895 tr("Session modified"),
Chris@257 1896 tr("The current session has been modified.\nDo you want to save it?"),
Chris@257 1897 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
Chris@0 1898 QMessageBox::Yes);
Chris@0 1899
Chris@0 1900 if (button == QMessageBox::Yes) {
Chris@257 1901 saveSession();
Chris@257 1902 if (m_documentModified) { // save failed -- don't proceed!
Chris@257 1903 return false;
Chris@257 1904 } else {
Chris@0 1905 return true; // saved, so it's safe to continue now
Chris@0 1906 }
Chris@0 1907 } else if (button == QMessageBox::No) {
Chris@257 1908 m_documentModified = false; // so we know to abandon it
Chris@257 1909 return true;
Chris@0 1910 }
Chris@0 1911
Chris@0 1912 // else cancel
Chris@0 1913 return false;
Chris@0 1914 }
Chris@0 1915
Chris@314 1916 bool
Chris@314 1917 MainWindow::waitForInitialAnalysis()
Chris@314 1918 {
Chris@314 1919 // Called before saving a session. We can't safely save while the
Chris@314 1920 // initial analysis is happening, because then we end up with an
Chris@314 1921 // incomplete session on reload. There are certainly theoretically
Chris@314 1922 // better ways to handle this...
Chris@314 1923
Chris@330 1924 QSettings settings;
Chris@330 1925 settings.beginGroup("Analyser");
Chris@330 1926 bool autoAnalyse = settings.value("auto-analysis", true).toBool();
Chris@330 1927 settings.endGroup();
Chris@330 1928
Chris@330 1929 if (!autoAnalyse) {
Chris@330 1930 return true;
Chris@330 1931 }
Chris@330 1932
Chris@314 1933 if (!m_analyser || m_analyser->getInitialAnalysisCompletion() >= 100) {
Chris@314 1934 return true;
Chris@314 1935 }
Chris@314 1936
Chris@314 1937 QMessageBox mb(QMessageBox::Information,
Chris@314 1938 tr("Waiting for analysis"),
Chris@314 1939 tr("Waiting for initial analysis to complete before saving..."),
Chris@314 1940 QMessageBox::Cancel,
Chris@314 1941 this);
Chris@314 1942
Chris@314 1943 connect(m_analyser, SIGNAL(initialAnalysisCompleted()),
Chris@314 1944 &mb, SLOT(accept()));
Chris@314 1945
Chris@314 1946 if (mb.exec() == QDialog::Accepted) {
Chris@314 1947 return true;
Chris@314 1948 } else {
Chris@314 1949 return false;
Chris@314 1950 }
Chris@314 1951 }
Chris@314 1952
Chris@0 1953 void
Chris@0 1954 MainWindow::saveSession()
Chris@0 1955 {
Chris@269 1956 // We do not want to save mid-analysis regions -- that would cause
Chris@269 1957 // confusion on reloading
Chris@269 1958 m_analyser->clearReAnalysis();
Chris@269 1959 clearSelection();
Chris@269 1960
Chris@0 1961 if (m_sessionFile != "") {
Chris@257 1962 if (!saveSessionFile(m_sessionFile)) {
Chris@257 1963 QMessageBox::critical
Chris@257 1964 (this, tr("Failed to save file"),
Chris@257 1965 tr("Session file \"%1\" could not be saved.").arg(m_sessionFile));
Chris@257 1966 } else {
Chris@257 1967 CommandHistory::getInstance()->documentSaved();
Chris@257 1968 documentRestored();
Chris@257 1969 }
Chris@0 1970 } else {
Chris@257 1971 saveSessionAs();
Chris@0 1972 }
Chris@0 1973 }
Chris@0 1974
Chris@0 1975 void
matthiasm@310 1976 MainWindow::saveSessionInAudioPath()
matthiasm@310 1977 {
matthiasm@311 1978 if (m_audioFile == "") return;
matthiasm@311 1979
Chris@314 1980 if (!waitForInitialAnalysis()) return;
Chris@314 1981
matthiasm@310 1982 // We do not want to save mid-analysis regions -- that would cause
matthiasm@310 1983 // confusion on reloading
matthiasm@310 1984 m_analyser->clearReAnalysis();
matthiasm@310 1985 clearSelection();
matthiasm@310 1986
matthiasm@310 1987 QString filepath = QFileInfo(m_audioFile).absoluteDir().canonicalPath();
matthiasm@310 1988 QString basename = QFileInfo(m_audioFile).completeBaseName();
matthiasm@310 1989
matthiasm@310 1990 QString path = QDir(filepath).filePath(basename + ".ton");
matthiasm@310 1991
matthiasm@310 1992 cerr << path << endl;
matthiasm@310 1993
Chris@313 1994 // We don't want to overwrite an existing .ton file unless we put
Chris@313 1995 // it there in the first place
Chris@313 1996 bool shouldVerify = true;
Chris@313 1997 if (m_sessionFile == path) {
Chris@313 1998 shouldVerify = false;
Chris@313 1999 }
Chris@313 2000
Chris@313 2001 if (shouldVerify && QFileInfo(path).exists()) {
Chris@313 2002 if (QMessageBox::question(0, tr("File exists"),
Chris@313 2003 tr("<b>File exists</b><p>The file \"%1\" already exists.\nDo you want to overwrite it?").arg(path),
Chris@313 2004 QMessageBox::Ok,
Chris@313 2005 QMessageBox::Cancel) != QMessageBox::Ok) {
Chris@313 2006 return;
Chris@313 2007 }
Chris@313 2008 }
Chris@313 2009
Chris@314 2010 if (!waitForInitialAnalysis()) {
Chris@314 2011 QMessageBox::warning(this, tr("File not saved"),
Chris@314 2012 tr("Wait cancelled: the session has not been saved."));
Chris@314 2013 }
Chris@314 2014
matthiasm@310 2015 if (!saveSessionFile(path)) {
matthiasm@310 2016 QMessageBox::critical(this, tr("Failed to save file"),
matthiasm@310 2017 tr("Session file \"%1\" could not be saved.").arg(path));
matthiasm@310 2018 } else {
matthiasm@310 2019 setWindowTitle(tr("%1: %2")
matthiasm@310 2020 .arg(QApplication::applicationName())
matthiasm@310 2021 .arg(QFileInfo(path).fileName()));
matthiasm@310 2022 m_sessionFile = path;
matthiasm@310 2023 CommandHistory::getInstance()->documentSaved();
matthiasm@310 2024 documentRestored();
matthiasm@310 2025 m_recentFiles.addFile(path);
matthiasm@310 2026 }
matthiasm@310 2027 }
matthiasm@310 2028
matthiasm@310 2029 void
Chris@0 2030 MainWindow::saveSessionAs()
Chris@0 2031 {
Chris@270 2032 // We do not want to save mid-analysis regions -- that would cause
Chris@270 2033 // confusion on reloading
Chris@270 2034 m_analyser->clearReAnalysis();
Chris@270 2035 clearSelection();
Chris@270 2036
Chris@0 2037 QString path = getSaveFileName(FileFinder::SessionFile);
Chris@0 2038
Chris@309 2039 if (path == "") {
Chris@309 2040 return;
Chris@309 2041 }
Chris@0 2042
Chris@314 2043 if (!waitForInitialAnalysis()) {
Chris@314 2044 QMessageBox::warning(this, tr("File not saved"),
Chris@314 2045 tr("Wait cancelled: the session has not been saved."));
Chris@314 2046 return;
Chris@314 2047 }
Chris@314 2048
Chris@0 2049 if (!saveSessionFile(path)) {
Chris@85 2050 QMessageBox::critical(this, tr("Failed to save file"),
Chris@85 2051 tr("Session file \"%1\" could not be saved.").arg(path));
Chris@0 2052 } else {
Chris@85 2053 setWindowTitle(tr("%1: %2")
Chris@0 2054 .arg(QApplication::applicationName())
Chris@85 2055 .arg(QFileInfo(path).fileName()));
Chris@85 2056 m_sessionFile = path;
Chris@85 2057 CommandHistory::getInstance()->documentSaved();
Chris@85 2058 documentRestored();
Chris@0 2059 m_recentFiles.addFile(path);
Chris@0 2060 }
Chris@0 2061 }
Chris@0 2062
Chris@85 2063 QString
Chris@85 2064 MainWindow::exportToSVL(QString path, Layer *layer)
Chris@85 2065 {
Chris@85 2066 Model *model = layer->getModel();
Chris@85 2067
Chris@85 2068 QFile file(path);
Chris@85 2069 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
Chris@85 2070 return tr("Failed to open file %1 for writing").arg(path);
Chris@85 2071 } else {
Chris@85 2072 QTextStream out(&file);
Chris@85 2073 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
Chris@85 2074 << "<!DOCTYPE sonic-visualiser>\n"
Chris@85 2075 << "<sv>\n"
Chris@85 2076 << " <data>\n";
Chris@85 2077
Chris@85 2078 model->toXml(out, " ");
Chris@85 2079
Chris@85 2080 out << " </data>\n"
Chris@85 2081 << " <display>\n";
Chris@85 2082
Chris@85 2083 layer->toXml(out, " ");
Chris@85 2084
Chris@85 2085 out << " </display>\n"
Chris@85 2086 << "</sv>\n";
Chris@85 2087
Chris@85 2088 return "";
Chris@85 2089 }
Chris@85 2090 }
Chris@85 2091
Chris@0 2092 void
Chris@174 2093 MainWindow::importPitchLayer()
Chris@174 2094 {
Chris@174 2095 QString path = getOpenFileName(FileFinder::LayerFileNoMidiNonSV);
Chris@174 2096 if (path == "") return;
Chris@174 2097
Chris@174 2098 FileOpenStatus status = importPitchLayer(path);
Chris@174 2099
Chris@174 2100 if (status == FileOpenFailed) {
Chris@174 2101 emit hideSplash();
Chris@174 2102 QMessageBox::critical(this, tr("Failed to open file"),
Chris@174 2103 tr("<b>File open failed</b><p>Layer file %1 could not be opened.").arg(path));
Chris@174 2104 return;
Chris@174 2105 } else if (status == FileOpenWrongMode) {
Chris@174 2106 emit hideSplash();
Chris@174 2107 QMessageBox::critical(this, tr("Failed to open file"),
Chris@174 2108 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@174 2109 }
Chris@174 2110 }
Chris@174 2111
Chris@174 2112 MainWindow::FileOpenStatus
Chris@174 2113 MainWindow::importPitchLayer(FileSource source)
Chris@174 2114 {
Chris@174 2115 if (!source.isAvailable()) return FileOpenFailed;
Chris@174 2116 source.waitForData();
Chris@174 2117
Chris@174 2118 QString path = source.getLocalFilename();
Chris@174 2119
Chris@174 2120 RDFImporter::RDFDocumentType rdfType =
Chris@174 2121 RDFImporter::identifyDocumentType(QUrl::fromLocalFile(path).toString());
Chris@174 2122
Chris@174 2123 if (rdfType != RDFImporter::NotRDF) {
Chris@174 2124
Chris@174 2125 //!!!
Chris@174 2126 return FileOpenFailed;
Chris@174 2127
Chris@174 2128 } else if (source.getExtension().toLower() == "svl" ||
Chris@174 2129 (source.getExtension().toLower() == "xml" &&
Chris@174 2130 (SVFileReader::identifyXmlFile(source.getLocalFilename())
Chris@174 2131 == SVFileReader::SVLayerFile))) {
Chris@174 2132
Chris@174 2133 //!!!
Chris@174 2134 return FileOpenFailed;
Chris@174 2135
Chris@174 2136 } else {
Chris@174 2137
Chris@174 2138 try {
Chris@174 2139
Chris@174 2140 CSVFormat format(path);
Chris@174 2141 format.setSampleRate(getMainModel()->getSampleRate());
Chris@174 2142
Chris@174 2143 if (format.getModelType() != CSVFormat::TwoDimensionalModel) {
Chris@174 2144 //!!! error report
Chris@174 2145 return FileOpenFailed;
Chris@174 2146 }
Chris@174 2147
Chris@174 2148 Model *model = DataFileReaderFactory::loadCSV
Chris@174 2149 (path, format, getMainModel()->getSampleRate());
Chris@174 2150
Chris@174 2151 if (model) {
Chris@174 2152
Chris@174 2153 SVDEBUG << "MainWindow::importPitchLayer: Have model" << endl;
Chris@174 2154
Chris@174 2155 CommandHistory::getInstance()->startCompoundOperation
Chris@174 2156 (tr("Import Pitch Track"), true);
Chris@174 2157
Chris@174 2158 Layer *newLayer = m_document->createImportedLayer(model);
Chris@174 2159
Chris@174 2160 m_analyser->takePitchTrackFrom(newLayer);
Chris@174 2161
Chris@174 2162 m_document->deleteLayer(newLayer);
Chris@174 2163
Chris@174 2164 CommandHistory::getInstance()->endCompoundOperation();
Chris@174 2165
Chris@174 2166 //!!! swap all data in to existing layer instead of this
Chris@174 2167
Chris@174 2168 if (!source.isRemote()) {
Chris@174 2169 registerLastOpenedFilePath
Chris@174 2170 (FileFinder::LayerFile,
Chris@174 2171 path); // for file dialog
Chris@174 2172 }
Chris@174 2173
Chris@174 2174 return FileOpenSucceeded;
Chris@174 2175 }
Chris@174 2176 } catch (DataFileReaderFactory::Exception e) {
Chris@174 2177 if (e == DataFileReaderFactory::ImportCancelled) {
Chris@174 2178 return FileOpenCancelled;
Chris@174 2179 }
Chris@174 2180 }
Chris@174 2181 }
Chris@174 2182
Chris@174 2183 return FileOpenFailed;
Chris@174 2184 }
Chris@174 2185
Chris@174 2186 void
Chris@85 2187 MainWindow::exportPitchLayer()
matthiasm@26 2188 {
Chris@174 2189 Layer *layer = m_analyser->getLayer(Analyser::PitchTrack);
matthiasm@26 2190 if (!layer) return;
matthiasm@26 2191
Chris@85 2192 SparseTimeValueModel *model =
Chris@85 2193 qobject_cast<SparseTimeValueModel *>(layer->getModel());
matthiasm@26 2194 if (!model) return;
matthiasm@26 2195
Chris@96 2196 FileFinder::FileType type = FileFinder::LayerFileNoMidiNonSV;
matthiasm@26 2197
matthiasm@26 2198 QString path = getSaveFileName(type);
matthiasm@26 2199
matthiasm@26 2200 if (path == "") return;
matthiasm@26 2201
matthiasm@26 2202 if (QFileInfo(path).suffix() == "") path += ".svl";
matthiasm@26 2203
matthiasm@26 2204 QString suffix = QFileInfo(path).suffix().toLower();
matthiasm@26 2205
matthiasm@26 2206 QString error;
matthiasm@26 2207
matthiasm@26 2208 if (suffix == "xml" || suffix == "svl") {
matthiasm@26 2209
Chris@85 2210 error = exportToSVL(path, layer);
matthiasm@26 2211
matthiasm@26 2212 } else if (suffix == "ttl" || suffix == "n3") {
matthiasm@26 2213
Chris@85 2214 RDFExporter exporter(path, model);
Chris@85 2215 exporter.write();
Chris@85 2216 if (!exporter.isOK()) {
Chris@85 2217 error = exporter.getError();
Chris@85 2218 }
Chris@85 2219
Chris@85 2220 } else {
Chris@85 2221
Chris@429 2222 DataExportOptions options = DataExportFillGaps;
Chris@429 2223
Chris@85 2224 CSVFileWriter writer(path, model,
Chris@429 2225 ((suffix == "csv") ? "," : "\t"),
Chris@429 2226 options);
Chris@85 2227 writer.write();
Chris@85 2228
Chris@85 2229 if (!writer.isOK()) {
Chris@85 2230 error = writer.getError();
Chris@85 2231 }
Chris@85 2232 }
Chris@85 2233
Chris@85 2234 if (error != "") {
Chris@85 2235 QMessageBox::critical(this, tr("Failed to write file"), error);
Chris@85 2236 } else {
Chris@85 2237 emit activity(tr("Export layer to \"%1\"").arg(path));
Chris@85 2238 }
Chris@85 2239 }
Chris@85 2240
Chris@85 2241 void
Chris@85 2242 MainWindow::exportNoteLayer()
Chris@85 2243 {
Chris@174 2244 Layer *layer = m_analyser->getLayer(Analyser::Notes);
Chris@85 2245 if (!layer) return;
Chris@85 2246
Chris@85 2247 FlexiNoteModel *model = qobject_cast<FlexiNoteModel *>(layer->getModel());
Chris@85 2248 if (!model) return;
Chris@85 2249
Chris@96 2250 FileFinder::FileType type = FileFinder::LayerFileNonSV;
Chris@85 2251
Chris@85 2252 QString path = getSaveFileName(type);
Chris@85 2253
Chris@85 2254 if (path == "") return;
Chris@85 2255
Chris@85 2256 if (QFileInfo(path).suffix() == "") path += ".svl";
Chris@85 2257
Chris@85 2258 QString suffix = QFileInfo(path).suffix().toLower();
Chris@85 2259
Chris@85 2260 QString error;
Chris@85 2261
Chris@85 2262 if (suffix == "xml" || suffix == "svl") {
Chris@85 2263
Chris@85 2264 error = exportToSVL(path, layer);
Chris@85 2265
Chris@85 2266 } else if (suffix == "mid" || suffix == "midi") {
Chris@85 2267
Chris@85 2268 MIDIFileWriter writer(path, model, model->getSampleRate());
Chris@85 2269 writer.write();
Chris@85 2270 if (!writer.isOK()) {
Chris@85 2271 error = writer.getError();
Chris@85 2272 }
Chris@85 2273
Chris@85 2274 } else if (suffix == "ttl" || suffix == "n3") {
Chris@85 2275
Chris@85 2276 RDFExporter exporter(path, model);
Chris@85 2277 exporter.write();
Chris@85 2278 if (!exporter.isOK()) {
Chris@85 2279 error = exporter.getError();
matthiasm@26 2280 }
matthiasm@26 2281
matthiasm@26 2282 } else {
matthiasm@26 2283
Chris@429 2284 DataExportOptions options = DataExportOmitLevels;
Chris@429 2285
matthiasm@26 2286 CSVFileWriter writer(path, model,
Chris@429 2287 ((suffix == "csv") ? "," : "\t"),
Chris@429 2288 options);
matthiasm@26 2289 writer.write();
matthiasm@26 2290
matthiasm@26 2291 if (!writer.isOK()) {
matthiasm@26 2292 error = writer.getError();
matthiasm@26 2293 }
matthiasm@26 2294 }
matthiasm@26 2295
matthiasm@26 2296 if (error != "") {
matthiasm@26 2297 QMessageBox::critical(this, tr("Failed to write file"), error);
matthiasm@26 2298 } else {
matthiasm@26 2299 emit activity(tr("Export layer to \"%1\"").arg(path));
matthiasm@26 2300 }
matthiasm@26 2301 }
matthiasm@26 2302
Chris@139 2303 void
Chris@399 2304 MainWindow::doubleClickSelectInvoked(sv_frame_t frame)
Chris@139 2305 {
Chris@399 2306 sv_frame_t f0, f1;
Chris@139 2307 m_analyser->getEnclosingSelectionScope(frame, f0, f1);
Chris@139 2308
Chris@139 2309 cerr << "MainWindow::doubleClickSelectInvoked(" << frame << "): [" << f0 << "," << f1 << "]" << endl;
Chris@139 2310
Chris@164 2311 Selection sel(f0, f1);
Chris@164 2312 m_viewManager->setSelection(sel);
Chris@164 2313 }
Chris@164 2314
Chris@164 2315 void
Chris@194 2316 MainWindow::abandonSelection()
Chris@167 2317 {
Chris@194 2318 // Named abandonSelection rather than clearSelection to indicate
Chris@194 2319 // that this is an active operation -- it restores the original
Chris@194 2320 // content of the pitch track in the selected region rather than
Chris@194 2321 // simply un-selecting.
Chris@194 2322
Chris@194 2323 cerr << "MainWindow::abandonSelection()" << endl;
Chris@167 2324
Chris@199 2325 CommandHistory::getInstance()->startCompoundOperation(tr("Abandon Selection"), true);
Chris@168 2326
Chris@194 2327 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@194 2328 if (!selections.empty()) {
Chris@194 2329 Selection sel = *selections.begin();
Chris@199 2330 m_analyser->abandonReAnalysis(sel);
Chris@252 2331 auxSnapNotes(sel);
Chris@194 2332 }
Chris@194 2333
Chris@167 2334 MainWindowBase::clearSelection();
Chris@168 2335
Chris@168 2336 CommandHistory::getInstance()->endCompoundOperation();
Chris@167 2337 }
Chris@167 2338
Chris@167 2339 void
Chris@192 2340 MainWindow::selectionChangedByUser()
Chris@164 2341 {
Chris@221 2342 if (!m_document) {
Chris@221 2343 // we're exiting, most likely
Chris@221 2344 return;
Chris@221 2345 }
Chris@221 2346
Chris@164 2347 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@164 2348
Chris@192 2349 cerr << "MainWindow::selectionChangedByUser" << endl;
Chris@192 2350
Chris@192 2351 m_analyser->showPitchCandidates(m_pendingConstraint.isConstrained());
Chris@190 2352
Chris@164 2353 if (!selections.empty()) {
Chris@164 2354 Selection sel = *selections.begin();
Chris@192 2355 cerr << "MainWindow::selectionChangedByUser: have selection" << endl;
Chris@192 2356 QString error = m_analyser->reAnalyseSelection
Chris@192 2357 (sel, m_pendingConstraint);
Chris@164 2358 if (error != "") {
Chris@164 2359 QMessageBox::critical
Chris@164 2360 (this, tr("Failed to analyse selection"),
Chris@164 2361 tr("<b>Analysis failed</b><p>%2</p>").arg(error));
Chris@164 2362 }
Chris@164 2363 }
Chris@192 2364
Chris@192 2365 m_pendingConstraint = Analyser::FrequencyRange();
Chris@192 2366 }
Chris@192 2367
Chris@192 2368 void
Chris@192 2369 MainWindow::regionOutlined(QRect r)
Chris@192 2370 {
Chris@192 2371 cerr << "MainWindow::regionOutlined(" << r.x() << "," << r.y() << "," << r.width() << "," << r.height() << ")" << endl;
Chris@192 2372
Chris@192 2373 Pane *pane = qobject_cast<Pane *>(sender());
Chris@192 2374 if (!pane) {
Chris@192 2375 cerr << "MainWindow::regionOutlined: not sent by pane, ignoring" << endl;
Chris@192 2376 return;
Chris@192 2377 }
Chris@192 2378
Chris@192 2379 if (!m_analyser) {
Chris@192 2380 cerr << "MainWindow::regionOutlined: no analyser, ignoring" << endl;
Chris@192 2381 return;
Chris@192 2382 }
Chris@192 2383
Chris@192 2384 SpectrogramLayer *spectrogram = qobject_cast<SpectrogramLayer *>
Chris@192 2385 (m_analyser->getLayer(Analyser::Spectrogram));
Chris@192 2386 if (!spectrogram) {
Chris@192 2387 cerr << "MainWindow::regionOutlined: no spectrogram layer, ignoring" << endl;
Chris@192 2388 return;
Chris@192 2389 }
Chris@192 2390
Chris@399 2391 sv_frame_t f0 = pane->getFrameForX(r.x());
Chris@399 2392 sv_frame_t f1 = pane->getFrameForX(r.x() + r.width());
Chris@192 2393
Chris@399 2394 double v0 = spectrogram->getFrequencyForY(pane, r.y() + r.height());
Chris@399 2395 double v1 = spectrogram->getFrequencyForY(pane, r.y());
Chris@192 2396
Chris@192 2397 cerr << "MainWindow::regionOutlined: frame " << f0 << " -> " << f1
Chris@192 2398 << ", frequency " << v0 << " -> " << v1 << endl;
Chris@192 2399
Chris@192 2400 m_pendingConstraint = Analyser::FrequencyRange(v0, v1);
Chris@192 2401
Chris@192 2402 Selection sel(f0, f1);
Chris@192 2403 m_viewManager->setSelection(sel);
Chris@0 2404 }
Chris@0 2405
Chris@0 2406 void
Chris@168 2407 MainWindow::clearPitches()
Chris@168 2408 {
Chris@168 2409 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@168 2410
Chris@168 2411 CommandHistory::getInstance()->startCompoundOperation(tr("Clear Pitches"), true);
Chris@168 2412
Chris@168 2413 for (MultiSelection::SelectionList::iterator k = selections.begin();
Chris@168 2414 k != selections.end(); ++k) {
Chris@184 2415 m_analyser->deletePitches(*k);
Chris@252 2416 auxSnapNotes(*k);
Chris@168 2417 }
Chris@168 2418
Chris@168 2419 CommandHistory::getInstance()->endCompoundOperation();
Chris@168 2420 }
Chris@168 2421
Chris@168 2422 void
Chris@142 2423 MainWindow::octaveShift(bool up)
Chris@142 2424 {
Chris@142 2425 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@142 2426
Chris@211 2427 CommandHistory::getInstance()->startCompoundOperation
Chris@211 2428 (up ? tr("Choose Higher Octave") : tr("Choose Lower Octave"), true);
Chris@142 2429
Chris@168 2430 for (MultiSelection::SelectionList::iterator k = selections.begin();
Chris@168 2431 k != selections.end(); ++k) {
Chris@142 2432
Chris@168 2433 m_analyser->shiftOctave(*k, up);
Chris@252 2434 auxSnapNotes(*k);
Chris@142 2435 }
Chris@142 2436
Chris@142 2437 CommandHistory::getInstance()->endCompoundOperation();
Chris@142 2438 }
Chris@142 2439
Chris@142 2440 void
Chris@184 2441 MainWindow::togglePitchCandidates()
Chris@184 2442 {
Chris@199 2443 CommandHistory::getInstance()->startCompoundOperation(tr("Toggle Pitch Candidates"), true);
Chris@199 2444
Chris@184 2445 m_analyser->showPitchCandidates(!m_analyser->arePitchCandidatesShown());
Chris@199 2446
Chris@199 2447 CommandHistory::getInstance()->endCompoundOperation();
Chris@199 2448
Chris@187 2449 updateMenuStates();
Chris@184 2450 }
Chris@184 2451
Chris@184 2452 void
Chris@184 2453 MainWindow::switchPitchUp()
Chris@167 2454 {
Chris@211 2455 if (m_analyser->arePitchCandidatesShown()) {
Chris@211 2456 if (m_analyser->haveHigherPitchCandidate()) {
Chris@211 2457
Chris@211 2458 CommandHistory::getInstance()->startCompoundOperation
Chris@211 2459 (tr("Choose Higher Pitch Candidate"), true);
Chris@211 2460
Chris@211 2461 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@211 2462
Chris@211 2463 for (MultiSelection::SelectionList::iterator k = selections.begin();
Chris@211 2464 k != selections.end(); ++k) {
Chris@211 2465 m_analyser->switchPitchCandidate(*k, true);
Chris@252 2466 auxSnapNotes(*k);
Chris@211 2467 }
Chris@211 2468
Chris@211 2469 CommandHistory::getInstance()->endCompoundOperation();
Chris@211 2470 }
Chris@211 2471 } else {
Chris@211 2472 octaveShift(true);
Chris@167 2473 }
Chris@167 2474 }
Chris@167 2475
Chris@167 2476 void
Chris@184 2477 MainWindow::switchPitchDown()
Chris@184 2478 {
Chris@211 2479 if (m_analyser->arePitchCandidatesShown()) {
Chris@211 2480 if (m_analyser->haveLowerPitchCandidate()) {
Chris@211 2481
Chris@211 2482 CommandHistory::getInstance()->startCompoundOperation
Chris@211 2483 (tr("Choose Lower Pitch Candidate"), true);
Chris@211 2484
Chris@211 2485 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@211 2486
Chris@211 2487 for (MultiSelection::SelectionList::iterator k = selections.begin();
Chris@211 2488 k != selections.end(); ++k) {
Chris@211 2489 m_analyser->switchPitchCandidate(*k, false);
Chris@252 2490 auxSnapNotes(*k);
Chris@211 2491 }
Chris@211 2492
Chris@211 2493 CommandHistory::getInstance()->endCompoundOperation();
Chris@211 2494 }
Chris@211 2495 } else {
Chris@211 2496 octaveShift(false);
Chris@184 2497 }
Chris@184 2498 }
Chris@184 2499
Chris@184 2500 void
Chris@237 2501 MainWindow::snapNotesToPitches()
Chris@237 2502 {
matthiasm@274 2503 cerr << "in snapNotesToPitches" << endl;
Chris@237 2504 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@237 2505
Chris@237 2506 if (!selections.empty()) {
Chris@237 2507
Chris@237 2508 CommandHistory::getInstance()->startCompoundOperation
Chris@237 2509 (tr("Snap Notes to Pitches"), true);
Chris@237 2510
Chris@237 2511 for (MultiSelection::SelectionList::iterator k = selections.begin();
Chris@237 2512 k != selections.end(); ++k) {
Chris@239 2513 auxSnapNotes(*k);
Chris@237 2514 }
Chris@237 2515
Chris@237 2516 CommandHistory::getInstance()->endCompoundOperation();
Chris@237 2517 }
Chris@237 2518 }
Chris@237 2519
Chris@237 2520 void
Chris@239 2521 MainWindow::auxSnapNotes(Selection s)
Chris@239 2522 {
matthiasm@274 2523 cerr << "in auxSnapNotes" << endl;
Chris@239 2524 FlexiNoteLayer *layer =
Chris@239 2525 qobject_cast<FlexiNoteLayer *>(m_analyser->getLayer(Analyser::Notes));
Chris@239 2526 if (!layer) return;
Chris@239 2527
Chris@239 2528 layer->snapSelectedNotesToPitchTrack(m_analyser->getPane(), s);
Chris@239 2529 }
Chris@239 2530
Chris@239 2531 void
Chris@240 2532 MainWindow::splitNote()
Chris@237 2533 {
Chris@237 2534 FlexiNoteLayer *layer =
Chris@237 2535 qobject_cast<FlexiNoteLayer *>(m_analyser->getLayer(Analyser::Notes));
Chris@237 2536 if (!layer) return;
Chris@237 2537
Chris@240 2538 layer->splitNotesAt(m_analyser->getPane(), m_viewManager->getPlaybackFrame());
Chris@237 2539 }
Chris@237 2540
Chris@237 2541 void
Chris@238 2542 MainWindow::mergeNotes()
Chris@238 2543 {
Chris@238 2544 FlexiNoteLayer *layer =
Chris@238 2545 qobject_cast<FlexiNoteLayer *>(m_analyser->getLayer(Analyser::Notes));
Chris@238 2546 if (!layer) return;
Chris@238 2547
Chris@238 2548 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@238 2549
Chris@238 2550 if (!selections.empty()) {
Chris@238 2551
Chris@238 2552 CommandHistory::getInstance()->startCompoundOperation
Chris@238 2553 (tr("Merge Notes"), true);
Chris@238 2554
Chris@238 2555 for (MultiSelection::SelectionList::iterator k = selections.begin();
Chris@238 2556 k != selections.end(); ++k) {
Chris@240 2557 layer->mergeNotes(m_analyser->getPane(), *k, true);
Chris@238 2558 }
Chris@238 2559
Chris@238 2560 CommandHistory::getInstance()->endCompoundOperation();
Chris@238 2561 }
Chris@238 2562 }
Chris@238 2563
Chris@238 2564 void
matthiasm@292 2565 MainWindow::deleteNotes()
matthiasm@292 2566 {
matthiasm@292 2567 FlexiNoteLayer *layer =
matthiasm@292 2568 qobject_cast<FlexiNoteLayer *>(m_analyser->getLayer(Analyser::Notes));
matthiasm@292 2569 if (!layer) return;
matthiasm@292 2570
matthiasm@292 2571 MultiSelection::SelectionList selections = m_viewManager->getSelections();
matthiasm@292 2572
matthiasm@292 2573 if (!selections.empty()) {
matthiasm@292 2574
matthiasm@292 2575 CommandHistory::getInstance()->startCompoundOperation
matthiasm@292 2576 (tr("Delete Notes"), true);
matthiasm@292 2577
matthiasm@292 2578 for (MultiSelection::SelectionList::iterator k = selections.begin();
matthiasm@292 2579 k != selections.end(); ++k) {
matthiasm@294 2580 layer->deleteSelectionInclusive(*k);
matthiasm@292 2581 }
matthiasm@292 2582
matthiasm@292 2583 CommandHistory::getInstance()->endCompoundOperation();
matthiasm@292 2584 }
matthiasm@292 2585 }
matthiasm@292 2586
matthiasm@292 2587
matthiasm@292 2588 void
Chris@240 2589 MainWindow::formNoteFromSelection()
Chris@240 2590 {
matthiasm@293 2591 Layer *layer0 = m_analyser->getLayer(Analyser::Notes);
matthiasm@293 2592 FlexiNoteModel *model = qobject_cast<FlexiNoteModel *>(layer0->getModel());
matthiasm@293 2593
Chris@240 2594 FlexiNoteLayer *layer =
Chris@240 2595 qobject_cast<FlexiNoteLayer *>(m_analyser->getLayer(Analyser::Notes));
Chris@240 2596 if (!layer) return;
Chris@240 2597
Chris@240 2598 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@240 2599
Chris@240 2600 if (!selections.empty()) {
Chris@240 2601
Chris@240 2602 CommandHistory::getInstance()->startCompoundOperation
Chris@240 2603 (tr("Form Note from Selection"), true);
Chris@240 2604 for (MultiSelection::SelectionList::iterator k = selections.begin();
Chris@240 2605 k != selections.end(); ++k) {
Chris@355 2606 if (!model->getNotesWithin(k->getStartFrame(), k->getEndFrame()).empty()) {
matthiasm@293 2607 layer->splitNotesAt(m_analyser->getPane(), k->getStartFrame());
matthiasm@293 2608 layer->splitNotesAt(m_analyser->getPane(), k->getEndFrame());
matthiasm@293 2609 layer->mergeNotes(m_analyser->getPane(), *k, false);
matthiasm@293 2610 } else {
matthiasm@293 2611 layer->addNoteOn(k->getStartFrame(), 100, 100);
matthiasm@293 2612 layer->addNoteOff(k->getEndFrame(), 100);
matthiasm@293 2613 layer->mergeNotes(m_analyser->getPane(), *k, false); // only so the note adapts in case of exisitng pitch track
matthiasm@293 2614 }
Chris@240 2615 }
Chris@240 2616
matthiasm@293 2617 CommandHistory::getInstance()->endCompoundOperation();
Chris@240 2618 }
Chris@240 2619 }
Chris@240 2620
Chris@240 2621 void
Chris@0 2622 MainWindow::playSpeedChanged(int position)
Chris@0 2623 {
Chris@0 2624 PlaySpeedRangeMapper mapper(0, 200);
Chris@0 2625
Chris@399 2626 double percent = m_playSpeed->mappedValue();
Chris@399 2627 double factor = mapper.getFactorForValue(percent);
Chris@0 2628
Chris@70 2629 cerr << "speed = " << position << " percent = " << percent << " factor = " << factor << endl;
Chris@0 2630
Chris@0 2631 bool something = (position != 100);
Chris@0 2632
Chris@399 2633 int pc = int(lrint(percent));
Chris@0 2634
Chris@0 2635 if (!something) {
Chris@0 2636 contextHelpChanged(tr("Playback speed: Normal"));
Chris@0 2637 } else {
Chris@0 2638 contextHelpChanged(tr("Playback speed: %1%2%")
Chris@0 2639 .arg(position > 100 ? "+" : "")
Chris@0 2640 .arg(pc));
Chris@0 2641 }
Chris@0 2642
Chris@0 2643 m_playSource->setTimeStretch(factor);
Chris@0 2644
Chris@0 2645 updateMenuStates();
Chris@0 2646 }
Chris@0 2647
Chris@0 2648 void
Chris@0 2649 MainWindow::playSharpenToggled()
Chris@0 2650 {
Chris@0 2651 QSettings settings;
Chris@0 2652 settings.beginGroup("MainWindow");
Chris@0 2653 settings.setValue("playsharpen", m_playSharpen->isChecked());
Chris@0 2654 settings.endGroup();
Chris@0 2655
Chris@0 2656 playSpeedChanged(m_playSpeed->value());
justin@157 2657 // TODO: pitch gain?
Chris@0 2658 }
Chris@0 2659
Chris@0 2660 void
Chris@0 2661 MainWindow::playMonoToggled()
Chris@0 2662 {
Chris@0 2663 QSettings settings;
Chris@0 2664 settings.beginGroup("MainWindow");
Chris@0 2665 settings.setValue("playmono", m_playMono->isChecked());
Chris@0 2666 settings.endGroup();
Chris@0 2667
Chris@0 2668 playSpeedChanged(m_playSpeed->value());
justin@157 2669 // TODO: pitch gain?
Chris@0 2670 }
Chris@0 2671
Chris@0 2672 void
Chris@0 2673 MainWindow::speedUpPlayback()
Chris@0 2674 {
Chris@0 2675 int value = m_playSpeed->value();
Chris@0 2676 value = value + m_playSpeed->pageStep();
Chris@0 2677 if (value > m_playSpeed->maximum()) value = m_playSpeed->maximum();
Chris@0 2678 m_playSpeed->setValue(value);
Chris@0 2679 }
Chris@0 2680
Chris@0 2681 void
Chris@0 2682 MainWindow::slowDownPlayback()
Chris@0 2683 {
Chris@0 2684 int value = m_playSpeed->value();
Chris@0 2685 value = value - m_playSpeed->pageStep();
Chris@0 2686 if (value < m_playSpeed->minimum()) value = m_playSpeed->minimum();
Chris@0 2687 m_playSpeed->setValue(value);
Chris@0 2688 }
Chris@0 2689
Chris@0 2690 void
Chris@0 2691 MainWindow::restoreNormalPlayback()
Chris@0 2692 {
Chris@0 2693 m_playSpeed->setValue(m_playSpeed->defaultValue());
Chris@0 2694 }
Chris@0 2695
justin@157 2696 void
Chris@404 2697 MainWindow::audioGainChanged(float gain)
justin@159 2698 {
Chris@404 2699 double db = AudioLevel::multiplier_to_dB(gain);
Chris@404 2700 cerr << "gain = " << gain << " (" << db << " dB)" << endl;
Chris@404 2701 contextHelpChanged(tr("Audio Gain: %1 dB").arg(db));
Chris@417 2702 if (gain == 0.f) {
Chris@417 2703 m_analyser->setAudible(Analyser::Audio, false);
Chris@417 2704 } else {
Chris@417 2705 m_analyser->setAudible(Analyser::Audio, true);
Chris@417 2706 m_analyser->setGain(Analyser::Audio, gain);
Chris@417 2707 }
justin@159 2708 updateMenuStates();
justin@159 2709 }
justin@159 2710
justin@159 2711 void
Chris@404 2712 MainWindow::pitchGainChanged(float gain)
justin@159 2713 {
Chris@404 2714 double db = AudioLevel::multiplier_to_dB(gain);
Chris@404 2715 cerr << "gain = " << gain << " (" << db << " dB)" << endl;
Chris@404 2716 contextHelpChanged(tr("Pitch Gain: %1 dB").arg(db));
Chris@417 2717 if (gain == 0.f) {
Chris@417 2718 m_analyser->setAudible(Analyser::PitchTrack, false);
Chris@417 2719 } else {
Chris@417 2720 m_analyser->setAudible(Analyser::PitchTrack, true);
Chris@417 2721 m_analyser->setGain(Analyser::PitchTrack, gain);
Chris@417 2722 }
justin@157 2723 updateMenuStates();
justin@157 2724 }
justin@157 2725
justin@157 2726 void
Chris@404 2727 MainWindow::notesGainChanged(float gain)
justin@157 2728 {
Chris@404 2729 double db = AudioLevel::multiplier_to_dB(gain);
Chris@404 2730 cerr << "gain = " << gain << " (" << db << " dB)" << endl;
Chris@404 2731 contextHelpChanged(tr("Notes Gain: %1 dB").arg(db));
Chris@417 2732 if (gain == 0.f) {
Chris@417 2733 m_analyser->setAudible(Analyser::Notes, false);
Chris@417 2734 } else {
Chris@417 2735 m_analyser->setAudible(Analyser::Notes, true);
Chris@417 2736 m_analyser->setGain(Analyser::Notes, gain);
Chris@417 2737 }
justin@159 2738 updateMenuStates();
justin@159 2739 }
justin@159 2740
justin@159 2741 void
Chris@404 2742 MainWindow::audioPanChanged(float pan)
justin@159 2743 {
Chris@404 2744 contextHelpChanged(tr("Audio Pan: %1").arg(pan));
Chris@404 2745 m_analyser->setPan(Analyser::Audio, pan);
justin@160 2746 updateMenuStates();
justin@160 2747 }
justin@160 2748
justin@160 2749 void
Chris@404 2750 MainWindow::pitchPanChanged(float pan)
justin@160 2751 {
Chris@404 2752 contextHelpChanged(tr("Pitch Pan: %1").arg(pan));
Chris@404 2753 m_analyser->setPan(Analyser::PitchTrack, pan);
justin@160 2754 updateMenuStates();
justin@160 2755 }
justin@160 2756
justin@160 2757 void
Chris@404 2758 MainWindow::notesPanChanged(float pan)
justin@160 2759 {
Chris@404 2760 contextHelpChanged(tr("Notes Pan: %1").arg(pan));
Chris@404 2761 m_analyser->setPan(Analyser::Notes, pan);
justin@160 2762 updateMenuStates();
justin@160 2763 }
justin@160 2764
justin@160 2765 void
Chris@0 2766 MainWindow::updateVisibleRangeDisplay(Pane *p) const
Chris@0 2767 {
Chris@0 2768 if (!getMainModel() || !p) {
Chris@0 2769 return;
Chris@0 2770 }
Chris@0 2771
Chris@0 2772 bool haveSelection = false;
Chris@403 2773 sv_frame_t startFrame = 0, endFrame = 0;
Chris@0 2774
Chris@0 2775 if (m_viewManager && m_viewManager->haveInProgressSelection()) {
Chris@0 2776
Chris@0 2777 bool exclusive = false;
Chris@0 2778 Selection s = m_viewManager->getInProgressSelection(exclusive);
Chris@0 2779
Chris@0 2780 if (!s.isEmpty()) {
Chris@0 2781 haveSelection = true;
Chris@0 2782 startFrame = s.getStartFrame();
Chris@0 2783 endFrame = s.getEndFrame();
Chris@0 2784 }
Chris@0 2785 }
Chris@0 2786
Chris@0 2787 if (!haveSelection) {
Chris@0 2788 startFrame = p->getFirstVisibleFrame();
Chris@0 2789 endFrame = p->getLastVisibleFrame();
Chris@0 2790 }
Chris@0 2791
Chris@0 2792 RealTime start = RealTime::frame2RealTime
Chris@0 2793 (startFrame, getMainModel()->getSampleRate());
Chris@0 2794
Chris@0 2795 RealTime end = RealTime::frame2RealTime
Chris@0 2796 (endFrame, getMainModel()->getSampleRate());
Chris@0 2797
Chris@0 2798 RealTime duration = end - start;
Chris@0 2799
Chris@0 2800 QString startStr, endStr, durationStr;
Chris@0 2801 startStr = start.toText(true).c_str();
Chris@0 2802 endStr = end.toText(true).c_str();
Chris@0 2803 durationStr = duration.toText(true).c_str();
Chris@0 2804
Chris@0 2805 if (haveSelection) {
Chris@0 2806 m_myStatusMessage = tr("Selection: %1 to %2 (duration %3)")
Chris@0 2807 .arg(startStr).arg(endStr).arg(durationStr);
Chris@0 2808 } else {
Chris@0 2809 m_myStatusMessage = tr("Visible: %1 to %2 (duration %3)")
Chris@0 2810 .arg(startStr).arg(endStr).arg(durationStr);
Chris@0 2811 }
matthiasm@42 2812
Chris@362 2813 getStatusLabel()->setText(m_myStatusMessage);
Chris@0 2814 }
Chris@0 2815
Chris@0 2816 void
Chris@0 2817 MainWindow::updatePositionStatusDisplays() const
Chris@0 2818 {
Chris@0 2819 if (!statusBar()->isVisible()) return;
Chris@0 2820
Chris@0 2821 }
Chris@0 2822
Chris@0 2823 void
Chris@0 2824 MainWindow::outputLevelsChanged(float left, float right)
Chris@0 2825 {
Chris@0 2826 m_fader->setPeakLeft(left);
Chris@0 2827 m_fader->setPeakRight(right);
Chris@0 2828 }
Chris@0 2829
Chris@0 2830 void
Chris@399 2831 MainWindow::sampleRateMismatch(sv_samplerate_t ,
Chris@399 2832 sv_samplerate_t ,
Chris@399 2833 bool )
Chris@0 2834 {
Chris@0 2835 updateDescriptionLabel();
Chris@0 2836 }
Chris@0 2837
Chris@0 2838 void
Chris@0 2839 MainWindow::audioOverloadPluginDisabled()
Chris@0 2840 {
Chris@0 2841 QMessageBox::information
Chris@0 2842 (this, tr("Audio processing overload"),
Chris@0 2843 tr("<b>Overloaded</b><p>Audio effects plugin auditioning has been disabled due to a processing overload."));
Chris@0 2844 }
Chris@0 2845
Chris@0 2846 void
Chris@0 2847 MainWindow::audioTimeStretchMultiChannelDisabled()
Chris@0 2848 {
Chris@0 2849 static bool shownOnce = false;
Chris@0 2850 if (shownOnce) return;
Chris@0 2851 QMessageBox::information
Chris@0 2852 (this, tr("Audio processing overload"),
Chris@0 2853 tr("<b>Overloaded</b><p>Audio playback speed processing has been reduced to a single channel, due to a processing overload."));
Chris@0 2854 shownOnce = true;
Chris@0 2855 }
Chris@0 2856
Chris@0 2857 void
Chris@0 2858 MainWindow::layerRemoved(Layer *layer)
Chris@0 2859 {
Chris@0 2860 MainWindowBase::layerRemoved(layer);
Chris@0 2861 }
Chris@0 2862
Chris@0 2863 void
Chris@0 2864 MainWindow::layerInAView(Layer *layer, bool inAView)
Chris@0 2865 {
Chris@0 2866 MainWindowBase::layerInAView(layer, inAView);
Chris@0 2867 }
Chris@0 2868
Chris@0 2869 void
Chris@0 2870 MainWindow::modelAdded(Model *model)
Chris@0 2871 {
Chris@0 2872 MainWindowBase::modelAdded(model);
Chris@3 2873 DenseTimeValueModel *dtvm = qobject_cast<DenseTimeValueModel *>(model);
Chris@0 2874 if (dtvm) {
Chris@70 2875 cerr << "A dense time-value model (such as an audio file) has been loaded" << endl;
Chris@0 2876 }
Chris@0 2877 }
Chris@0 2878
Chris@0 2879 void
Chris@0 2880 MainWindow::modelAboutToBeDeleted(Model *model)
Chris@0 2881 {
Chris@0 2882 MainWindowBase::modelAboutToBeDeleted(model);
Chris@0 2883 }
Chris@0 2884
Chris@0 2885 void
Chris@0 2886 MainWindow::mainModelChanged(WaveFileModel *model)
Chris@0 2887 {
Chris@0 2888 m_panLayer->setModel(model);
Chris@0 2889
Chris@0 2890 MainWindowBase::mainModelChanged(model);
Chris@0 2891
Chris@0 2892 if (m_playTarget) {
Chris@0 2893 connect(m_fader, SIGNAL(valueChanged(float)),
Chris@0 2894 m_playTarget, SLOT(setOutputGain(float)));
Chris@0 2895 }
Chris@259 2896 }
Chris@259 2897
Chris@259 2898 void
Chris@323 2899 MainWindow::analyseNow()
Chris@323 2900 {
Chris@323 2901 cerr << "analyseNow called" << endl;
Chris@325 2902 if (!m_analyser) return;
Chris@325 2903
Chris@325 2904 CommandHistory::getInstance()->startCompoundOperation
Chris@325 2905 (tr("Analyse Audio"), true);
Chris@325 2906
Chris@325 2907 QString error = m_analyser->analyseExistingFile();
Chris@325 2908
Chris@325 2909 CommandHistory::getInstance()->endCompoundOperation();
Chris@325 2910
Chris@325 2911 if (error != "") {
Chris@325 2912 QMessageBox::warning
Chris@325 2913 (this,
Chris@325 2914 tr("Failed to analyse audio"),
Chris@325 2915 tr("<b>Analysis failed</b><p>%1</p>").arg(error),
Chris@325 2916 QMessageBox::Ok);
Chris@325 2917 }
Chris@323 2918 }
Chris@323 2919
Chris@323 2920 void
Chris@259 2921 MainWindow::analyseNewMainModel()
Chris@259 2922 {
Chris@259 2923 WaveFileModel *model = getMainModel();
Chris@260 2924
Chris@260 2925 cerr << "MainWindow::analyseNewMainModel: main model is " << model << endl;
Chris@260 2926
Chris@260 2927 cerr << "(document is " << m_document << ", it says main model is " << m_document->getMainModel() << ")" << endl;
Chris@259 2928
Chris@324 2929 if (!model) {
Chris@324 2930 cerr << "no main model!" << endl;
Chris@324 2931 return;
Chris@324 2932 }
Chris@324 2933
Chris@324 2934 if (!m_paneStack) {
Chris@324 2935 cerr << "no pane stack!" << endl;
Chris@324 2936 return;
Chris@324 2937 }
Chris@324 2938
Chris@324 2939 int pc = m_paneStack->getPaneCount();
Chris@324 2940 Pane *pane = 0;
Chris@324 2941 Pane *selectionStrip = 0;
Chris@324 2942
Chris@324 2943 if (pc < 2) {
Chris@324 2944 pane = m_paneStack->addPane();
Chris@324 2945 selectionStrip = m_paneStack->addPane();
Chris@324 2946 m_document->addLayerToView
Chris@324 2947 (selectionStrip,
Chris@324 2948 m_document->createMainModelLayer(LayerFactory::TimeRuler));
Chris@324 2949 } else {
Chris@324 2950 pane = m_paneStack->getPane(0);
Chris@324 2951 selectionStrip = m_paneStack->getPane(1);
Chris@324 2952 }
Chris@324 2953
Chris@362 2954 pane->setPlaybackFollow(PlaybackScrollPage);
Chris@362 2955
Chris@324 2956 if (selectionStrip) {
Chris@362 2957 selectionStrip->setPlaybackFollow(PlaybackScrollPage);
Chris@324 2958 selectionStrip->setFixedHeight(26);
Chris@324 2959 m_paneStack->sizePanesEqually();
Chris@324 2960 m_viewManager->clearToolModeOverrides();
Chris@324 2961 m_viewManager->setToolModeFor(selectionStrip,
Chris@324 2962 ViewManager::SelectMode);
Chris@324 2963 }
Chris@324 2964
Chris@324 2965 if (pane) {
Chris@324 2966
Chris@324 2967 disconnect(pane, SIGNAL(regionOutlined(QRect)),
Chris@324 2968 pane, SLOT(zoomToRegion(QRect)));
Chris@324 2969 connect(pane, SIGNAL(regionOutlined(QRect)),
Chris@324 2970 this, SLOT(regionOutlined(QRect)));
Chris@324 2971
Chris@324 2972 QString error = m_analyser->newFileLoaded
Chris@324 2973 (m_document, getMainModel(), m_paneStack, pane);
Chris@324 2974 if (error != "") {
Chris@324 2975 QMessageBox::warning
Chris@324 2976 (this,
Chris@324 2977 tr("Failed to analyse audio"),
Chris@324 2978 tr("<b>Analysis failed</b><p>%1</p>").arg(error),
Chris@324 2979 QMessageBox::Ok);
Chris@72 2980 }
Chris@72 2981 }
matthiasm@366 2982
matthiasm@366 2983 if (!m_withSpectrogram)
matthiasm@366 2984 {
matthiasm@366 2985 m_analyser->setVisible(Analyser::Spectrogram, false);
matthiasm@366 2986 }
matthiasm@366 2987
matthiasm@366 2988 if (!m_withSonification)
matthiasm@366 2989 {
matthiasm@366 2990 m_analyser->setAudible(Analyser::PitchTrack, false);
matthiasm@366 2991 m_analyser->setAudible(Analyser::Notes, false);
matthiasm@366 2992 }
Chris@419 2993
Chris@419 2994 updateLayerStatuses();
Chris@0 2995 }
Chris@0 2996
Chris@0 2997 void
Chris@0 2998 MainWindow::modelGenerationFailed(QString transformName, QString message)
Chris@0 2999 {
Chris@0 3000 if (message != "") {
Chris@0 3001
Chris@0 3002 QMessageBox::warning
Chris@0 3003 (this,
Chris@0 3004 tr("Failed to generate layer"),
Chris@0 3005 tr("<b>Layer generation failed</b><p>Failed to generate derived layer.<p>The layer transform \"%1\" failed:<p>%2")
Chris@0 3006 .arg(transformName).arg(message),
Chris@0 3007 QMessageBox::Ok);
Chris@0 3008 } else {
Chris@0 3009 QMessageBox::warning
Chris@0 3010 (this,
Chris@0 3011 tr("Failed to generate layer"),
Chris@0 3012 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@0 3013 .arg(transformName),
Chris@0 3014 QMessageBox::Ok);
Chris@0 3015 }
Chris@0 3016 }
Chris@0 3017
Chris@0 3018 void
Chris@355 3019 MainWindow::modelGenerationWarning(QString /* transformName */, QString message)
Chris@0 3020 {
Chris@0 3021 QMessageBox::warning
Chris@0 3022 (this, tr("Warning"), message, QMessageBox::Ok);
Chris@0 3023 }
Chris@0 3024
Chris@0 3025 void
Chris@0 3026 MainWindow::modelRegenerationFailed(QString layerName,
Chris@399 3027 QString transformName,
Chris@399 3028 QString message)
Chris@0 3029 {
Chris@0 3030 if (message != "") {
Chris@0 3031
Chris@0 3032 QMessageBox::warning
Chris@0 3033 (this,
Chris@0 3034 tr("Failed to regenerate layer"),
Chris@0 3035 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@0 3036 .arg(layerName).arg(transformName).arg(message),
Chris@0 3037 QMessageBox::Ok);
Chris@0 3038 } else {
Chris@0 3039 QMessageBox::warning
Chris@0 3040 (this,
Chris@0 3041 tr("Failed to regenerate layer"),
Chris@0 3042 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@0 3043 .arg(layerName).arg(transformName),
Chris@0 3044 QMessageBox::Ok);
Chris@0 3045 }
Chris@0 3046 }
Chris@0 3047
Chris@0 3048 void
Chris@0 3049 MainWindow::modelRegenerationWarning(QString layerName,
Chris@355 3050 QString /* transformName */,
Chris@355 3051 QString message)
Chris@0 3052 {
Chris@0 3053 QMessageBox::warning
Chris@0 3054 (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@0 3055 }
Chris@0 3056
Chris@0 3057 void
Chris@0 3058 MainWindow::alignmentFailed(QString transformName, QString message)
Chris@0 3059 {
Chris@0 3060 QMessageBox::warning
Chris@0 3061 (this,
Chris@0 3062 tr("Failed to calculate alignment"),
Chris@0 3063 tr("<b>Alignment calculation failed</b><p>Failed to calculate an audio alignment using transform \"%1\":<p>%2")
Chris@0 3064 .arg(transformName).arg(message),
Chris@0 3065 QMessageBox::Ok);
Chris@0 3066 }
Chris@0 3067
Chris@0 3068 void
Chris@0 3069 MainWindow::rightButtonMenuRequested(Pane *pane, QPoint position)
Chris@0 3070 {
Chris@70 3071 // cerr << "MainWindow::rightButtonMenuRequested(" << pane << ", " << position.x() << ", " << position.y() << ")" << endl;
Chris@0 3072 m_paneStack->setCurrentPane(pane);
Chris@0 3073 m_rightButtonMenu->popup(position);
Chris@0 3074 }
Chris@0 3075
Chris@0 3076 void
Chris@355 3077 MainWindow::handleOSCMessage(const OSCMessage &)
Chris@0 3078 {
Chris@70 3079 cerr << "MainWindow::handleOSCMessage: Not implemented" << endl;
Chris@0 3080 }
Chris@0 3081
Chris@0 3082 void
Chris@0 3083 MainWindow::mouseEnteredWidget()
Chris@0 3084 {
Chris@3 3085 QWidget *w = qobject_cast<QWidget *>(sender());
Chris@0 3086 if (!w) return;
Chris@0 3087
Chris@0 3088 if (w == m_fader) {
Chris@0 3089 contextHelpChanged(tr("Adjust the master playback level"));
Chris@0 3090 } else if (w == m_playSpeed) {
Chris@0 3091 contextHelpChanged(tr("Adjust the master playback speed"));
Chris@0 3092 } else if (w == m_playSharpen && w->isEnabled()) {
Chris@0 3093 contextHelpChanged(tr("Toggle transient sharpening for playback time scaling"));
Chris@0 3094 } else if (w == m_playMono && w->isEnabled()) {
Chris@0 3095 contextHelpChanged(tr("Toggle mono mode for playback time scaling"));
Chris@0 3096 }
Chris@0 3097 }
Chris@0 3098
Chris@0 3099 void
Chris@0 3100 MainWindow::mouseLeftWidget()
Chris@0 3101 {
Chris@0 3102 contextHelpChanged("");
Chris@0 3103 }
Chris@0 3104
Chris@0 3105 void
Chris@0 3106 MainWindow::website()
Chris@0 3107 {
Chris@4 3108 //!!! todo: URL!
Chris@4 3109 openHelpUrl(tr("http://code.soundsoftware.ac.uk/projects/tony/"));
Chris@0 3110 }
Chris@0 3111
Chris@0 3112 void
Chris@0 3113 MainWindow::help()
Chris@0 3114 {
Chris@4 3115 //!!! todo: help URL!
matthiasm@369 3116 openHelpUrl(tr("http://code.soundsoftware.ac.uk/projects/tony/wiki/Reference"));
Chris@0 3117 }
Chris@0 3118
Chris@0 3119 void
Chris@0 3120 MainWindow::about()
Chris@0 3121 {
Chris@0 3122 bool debug = false;
Chris@0 3123 QString version = "(unknown version)";
Chris@0 3124
Chris@0 3125 #ifdef BUILD_DEBUG
Chris@0 3126 debug = true;
Chris@0 3127 #endif
Chris@0 3128 version = tr("Release %1").arg(TONY_VERSION);
Chris@0 3129
Chris@0 3130 QString aboutText;
Chris@0 3131
Chris@0 3132 aboutText += tr("<h3>About Tony</h3>");
Chris@0 3133 aboutText += tr("<p>Tony is a program for interactive note and pitch analysis and annotation.</p>");
Chris@0 3134 aboutText += tr("<p>%1 : %2 configuration</p>")
Chris@0 3135 .arg(version)
Chris@0 3136 .arg(debug ? tr("Debug") : tr("Release"));
Chris@212 3137 aboutText += tr("<p>Using Qt framework version %1.</p>")
Chris@206 3138 .arg(QT_VERSION_STR);
Chris@0 3139
Chris@0 3140 aboutText +=
Chris@266 3141 "<p>Copyright &copy; 2005&ndash;2014 Chris Cannam, Queen Mary University of London, and the Tony project authors: Matthias Mauch, George Fazekas, Justin Salamon, and Rachel Bittner.</p>"
Chris@212 3142 "<p>pYIN analysis plugin written by Matthias Mauch.</p>"
Chris@90 3143 "<p>This program is free software; you can redistribute it and/or "
Chris@90 3144 "modify it under the terms of the GNU General Public License as "
Chris@90 3145 "published by the Free Software Foundation; either version 2 of the "
Chris@0 3146 "License, or (at your option) any later version.<br>See the file "
Chris@0 3147 "COPYING included with this distribution for more information.</p>";
Chris@0 3148
Chris@0 3149 QMessageBox::about(this, tr("About %1").arg(QApplication::applicationName()), aboutText);
Chris@0 3150 }
Chris@0 3151
Chris@0 3152 void
Chris@0 3153 MainWindow::keyReference()
Chris@0 3154 {
Chris@0 3155 m_keyReference->show();
Chris@0 3156 }
Chris@0 3157
Chris@231 3158 void
Chris@231 3159 MainWindow::newerVersionAvailable(QString version)
Chris@231 3160 {
Chris@231 3161 //!!! nicer URL would be nicer
Chris@231 3162 QSettings settings;
Chris@231 3163 settings.beginGroup("NewerVersionWarning");
Chris@231 3164 QString tag = QString("version-%1-available-show").arg(version);
Chris@231 3165 if (settings.value(tag, true).toBool()) {
Chris@231 3166 QString title(tr("Newer version available"));
Chris@231 3167 QString text(tr("<h3>Newer version available</h3><p>You are using version %1 of Tony, but version %2 is now available.</p><p>Please see the <a href=\"http://code.soundsoftware.ac.uk/projects/tony/\">Tony website</a> for more information.</p>").arg(TONY_VERSION).arg(version));
Chris@231 3168 QMessageBox::information(this, title, text);
Chris@231 3169 settings.setValue(tag, false);
Chris@231 3170 }
Chris@231 3171 settings.endGroup();
Chris@231 3172 }
Chris@231 3173
matthiasm@356 3174 void
matthiasm@356 3175 MainWindow::ffwd()
matthiasm@356 3176 {
matthiasm@356 3177 if (!getMainModel()) return;
matthiasm@356 3178
Chris@403 3179 sv_frame_t frame = m_viewManager->getPlaybackFrame();
matthiasm@356 3180 ++frame;
matthiasm@356 3181
Chris@403 3182 sv_samplerate_t sr = getMainModel()->getSampleRate();
matthiasm@356 3183
matthiasm@356 3184 // The step is supposed to scale and be as wide as a step of
matthiasm@357 3185 // m_defaultFfwdRwdStep seconds at zoom level 720 and sr = 44100
Chris@403 3186 int framesPerPixel = m_viewManager->getGlobalZoom();
Chris@403 3187
Chris@403 3188 double defaultZoom = (720 * 44100) / sr;
Chris@403 3189 double scaler = framesPerPixel / defaultZoom;
Chris@403 3190 RealTime step = m_defaultFfwdRwdStep * scaler;
Chris@403 3191
matthiasm@356 3192 frame = RealTime::realTime2Frame
Chris@403 3193 (RealTime::frame2RealTime(frame, sr) + step, sr);
Chris@403 3194
Chris@403 3195 if (frame > getMainModel()->getEndFrame()) {
matthiasm@356 3196 frame = getMainModel()->getEndFrame();
matthiasm@356 3197 }
Chris@403 3198
matthiasm@356 3199 if (frame < 0) frame = 0;
matthiasm@356 3200
matthiasm@356 3201 if (m_viewManager->getPlaySelectionMode()) {
Chris@403 3202 frame = m_viewManager->constrainFrameToSelection(frame);
matthiasm@356 3203 }
matthiasm@356 3204
matthiasm@356 3205 m_viewManager->setPlaybackFrame(frame);
matthiasm@356 3206
Chris@403 3207 if (frame == getMainModel()->getEndFrame() &&
matthiasm@356 3208 m_playSource &&
matthiasm@356 3209 m_playSource->isPlaying() &&
matthiasm@356 3210 !m_viewManager->getPlayLoopMode()) {
matthiasm@356 3211 stop();
matthiasm@356 3212 }
matthiasm@356 3213 }
matthiasm@356 3214
matthiasm@356 3215 void
matthiasm@356 3216 MainWindow::rewind()
matthiasm@356 3217 {
matthiasm@356 3218 if (!getMainModel()) return;
matthiasm@356 3219
Chris@403 3220 sv_frame_t frame = m_viewManager->getPlaybackFrame();
matthiasm@356 3221 if (frame > 0) --frame;
matthiasm@356 3222
Chris@403 3223 sv_samplerate_t sr = getMainModel()->getSampleRate();
matthiasm@356 3224
matthiasm@356 3225 // The step is supposed to scale and be as wide as a step of
matthiasm@357 3226 // m_defaultFfwdRwdStep seconds at zoom level 720 and sr = 44100
Chris@403 3227 int framesPerPixel = m_viewManager->getGlobalZoom();
Chris@403 3228
Chris@403 3229 double defaultZoom = (720 * 44100) / sr;
Chris@403 3230 double scaler = framesPerPixel / defaultZoom;
Chris@403 3231 RealTime step = m_defaultFfwdRwdStep * scaler;
Chris@403 3232
matthiasm@356 3233 frame = RealTime::realTime2Frame
Chris@403 3234 (RealTime::frame2RealTime(frame, sr) - step, sr);
Chris@403 3235
Chris@403 3236 if (frame < getMainModel()->getStartFrame()) {
matthiasm@356 3237 frame = getMainModel()->getStartFrame();
matthiasm@356 3238 }
matthiasm@356 3239
matthiasm@356 3240 if (frame < 0) frame = 0;
matthiasm@356 3241
matthiasm@356 3242 if (m_viewManager->getPlaySelectionMode()) {
Chris@403 3243 frame = m_viewManager->constrainFrameToSelection(frame);
matthiasm@356 3244 }
matthiasm@356 3245
matthiasm@356 3246 m_viewManager->setPlaybackFrame(frame);
matthiasm@356 3247 }