annotate src/MainWindow.cpp @ 522:8f016d8c021a saveall

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