Audacity 3.2.0
TimeAndPitchExperimentalSettings.cpp
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 TimeAndPitchExperimentalSettings.cpp
7
8 Matthieu Hodgkinson
9
10**********************************************************************/
12#include "FileNames.h"
13#include "Prefs.h"
14#include <cstdlib>
15#include <fstream>
16
17namespace
18{
19template <typename T> std::optional<T> GetFromFile(const char* filenameStem)
20{
21 bool tuningOn = false;
22 gPrefs->Read(wxT("/TimeAndPitch/TuningOn"), &tuningOn, false);
23 if (!tuningOn)
24 return {};
25 T value;
26 std::ifstream file { TimeAndPitchExperimentalSettings::GetLogDir() + "/" +
27 filenameStem + ".txt" };
28 if (!file.is_open())
29 return {};
30 // Check if file is empty or first character is newline.
31 if (file.peek() == std::ifstream::traits_type::eof() || file.peek() == '\n')
32 return {};
33 file >> value;
34 return value;
35}
36} // namespace
37
39{
40 return FileNames::ConfigDir().ToStdString() + "/TimeAndPitchTuning/";
41}
42
43std::optional<int>
45{
46 if (const auto logTime = GetFromFile<double>("overrideLogTime"))
47 return static_cast<int>(*logTime * sampleRate);
48 return {};
49}
50
51std::optional<double>
53{
54 return GetFromFile<double>("overrideCutoffQuefrency");
55}
56
58{
59 if (const auto fftSizeExponent = GetFromFile<int>("overrideFftSizeExponent"))
60 return 1 << *fftSizeExponent;
61 return {};
62}
63
65{
66 if (const auto reduceImaging = GetFromFile<int>("overrideReduceImaging"))
67 return static_cast<bool>(*reduceImaging);
68 return {};
69}
wxT("CloseDown"))
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
virtual bool Read(const wxString &key, bool *value) const =0
FILES_API FilePath ConfigDir()
Audacity user config directory.
std::optional< int > GetLogSample(int sampleRate)