annotate src/MainWindow.cpp @ 405:7d97da3c744e

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