annotate src/MainWindow.cpp @ 476:bc48192e8307 recording

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