annotate src/MainWindow.cpp @ 421:abf3af4fc20b

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