annotate src/MainWindow.cpp @ 479:1a7bffbd971b recording

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