Entropy Piano Tuner  1.1.3 (documentation not yet complete)
An open-source experimental software for piano tuning by entropy minimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
settingsforqt.cpp
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright 2015 Haye Hinrichsen, Christoph Wick
3  *
4  * This file is part of Entropy Piano Tuner.
5  *
6  * Entropy Piano Tuner is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * Entropy Piano Tuner is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * Entropy Piano Tuner. If not, see http://www.gnu.org/licenses/.
18  *****************************************************************************/
19 
20 #include "settingsforqt.h"
21 #include <assert.h>
22 #include "../core/audio/recorder/audiorecorderadapter.h"
24 #include "options/optionsdialog.h"
25 
26 
27 const QString SettingsForQt::KEY_CURRENT_FILE_DIALOG_PATH = "app/currentFileDialogPath";
28 
30  : mApplicationRuns(0),
31  mLastVisitedOptionsPage(options::OptionsDialog::PAGE_ENVIRONMENT) {
32 }
33 
35 {
36 
37 }
38 
39 
41  return static_cast<SettingsForQt&>(Settings::getSingleton());
42 }
43 
44 
46  mApplicationRuns = mSettings.value("app/runs", 0).toLongLong();
47  mLanguageId = mSettings.value("app/languageId", QString()).toString().toStdString();
48 
49  for (int i = 0; i < DoNotShowAgainMessageBox::COUNT; ++i) {
50  if (mSettings.value(QString("doNotShowAgain/id%1").arg(i), false).toBool()) {
51  mDoNotShowAgainMessageBoxes.push_back(i);
52  }
53  }
54 
55  mLastVisitedOptionsPage = mSettings.value("app/lastOptionsPage", options::OptionsDialog::PAGE_ENVIRONMENT).toInt();
56 
57  mInputDeviceName = mSettings.value("audio/inputDeviceName", QString()).toString();
58  mInputDeviceSamplingRate = mSettings.value("audio/inputDeviceSamplingRate", 44100).toInt();
59 
60  mOutputDeviceName = mSettings.value("audio/outputDeviceName", QString()).toString();
61  mOutputDeviceSamplingRate = mSettings.value("audio/outputDeviceSamplingRate", 22050).toInt();
62 
63 
64  mLastUsedAlgorithm = mSettings.value("core/lastUsedAlgorithm", QString()).toString().toStdString();
66  mSettings.value("core/soundGeneratorMode", static_cast<int>(SoundGenerator::SGM_SYNTHESIZE_KEY)).toInt());
67  mSoundGeneratorVolumeDynamic = mSettings.value("core/soundGeneratorVolumeDynamic", true).toBool();
68  mStroboscopeActive = mSettings.value("core/stroboscopeMode", true).toBool();
69  mDisableAutomaticKeySelection = mSettings.value("core/disableAutomaticKeySelection", false).toBool();
70 }
71 
73  return mApplicationRuns;
74 }
75 
78  mSettings.setValue("app/runs", mApplicationRuns);
79 }
80 
81 void SettingsForQt::setLanguageId(const std::string &s) {
83  mSettings.setValue("app/languageId", QString::fromStdString(mLanguageId));
84 }
85 
86 std::string SettingsForQt::getUserLanguageId() const {
87  if (mLanguageId.size() > 0) {
88  return mLanguageId;
89  } else {
90  return QLocale::system().name().left(2).toStdString();
91  }
92 }
93 
95  return std::find(mDoNotShowAgainMessageBoxes.begin(), mDoNotShowAgainMessageBoxes.end(), id) != mDoNotShowAgainMessageBoxes.end();
96 }
97 
98 void SettingsForQt::setDoNotShowAgainMessageBox(int id, bool doNotShowAgain) {
99  auto entry(std::find(mDoNotShowAgainMessageBoxes.begin(), mDoNotShowAgainMessageBoxes.end(), id));
100  if (doNotShowAgain && entry == mDoNotShowAgainMessageBoxes.end()) {
101  mDoNotShowAgainMessageBoxes.push_back(id);
102  mSettings.setValue(QString("doNotShowAgain/id%1").arg(id), true);
103  } else if (entry != mDoNotShowAgainMessageBoxes.end()) {
104  mDoNotShowAgainMessageBoxes.erase(entry);
105  mSettings.remove(QString("doNotShowAgain/id%1").arg(id));
106  }
107 }
108 
111  mSettings.setValue("app/lastOptionsPage", mLastVisitedOptionsPage);
112 }
113 
114 void SettingsForQt::setInputDeviceName(const QString &s) {
115  mInputDeviceName = s;
116  mSettings.setValue("audio/inputDeviceName", mInputDeviceName);
117 }
118 
121  mSettings.setValue("audio/inputDeviceSamplingRate", mInputDeviceSamplingRate);
122 }
123 
124 void SettingsForQt::setOutputDeviceName(const QString &s) {
125  mOutputDeviceName = s;
126  mSettings.setValue("audio/outputDeviceName", mOutputDeviceName);
127 }
128 
131  mSettings.setValue("audio/outputDeviceSamplingRate", mOutputDeviceSamplingRate);
132 }
133 
134 void SettingsForQt::setLastUsedAlgorithm(const std::string &name) {
136  mSettings.setValue("core/lastUsedAlgorithm", QString::fromStdString(name));
137 }
138 
141  mSettings.setValue("core/soundGeneratorMode", static_cast<int>(mode));
142 }
143 
146  mSettings.setValue("core/soundGeneratorVolumeDynamic", dynamic);
147 }
148 
151  mSettings.setValue("core/stroboscopeMode", enable);
152 }
153 
156  mSettings.setValue("core/disableAutomaticKeySelection", disable);
157 }
virtual void setStroboscopeMode(bool enable)
Set flag indicating the stroboscopic mode of the tuning indicator.
Definition: settings.h:79
int mOutputDeviceSamplingRate
output device sampling rate
QString mInputDeviceName
input device name
static Settings & getSingleton()
Get a pointer to the singleton instance.
Definition: settings.cpp:46
static const QString KEY_CURRENT_FILE_DIALOG_PATH
Definition: settingsforqt.h:36
std::string mLanguageId
Language Id.
Definition: settings.h:88
std::vector< int > mDoNotShowAgainMessageBoxes
store the ids of the message boxes that wont show again
void setDoNotShowAgainMessageBox(int id, bool doNotShowAgain)
Sets a AutoClosingMessageBox state whether to show again.
SoundGeneratorMode
Mode for sound generation.
std::string mLastUsedAlgorithm
The algorithm that has been used last time.
Definition: settings.h:90
bool mDisableAutomaticKeySelection
Flag suppressing automatic key selection.
Definition: settings.h:93
bool mSoundGeneratorVolumeDynamic
Flag for automatic volume adjustment.
Definition: settings.h:92
QString mOutputDeviceName
output device name
virtual void setLanguageId(const std::string &s) overridefinal
Set the language id (en, de, fr,-...)
qlonglong mApplicationRuns
Counter for the application runs.
virtual void setSoundGeneratorVolumeDynamic(bool dynamic) overridefinal
Set flag for dynamic volume adaption in the tuning mode.
virtual void setLanguageId(const std::string &id)
Set the language id (en, de, fr,-...)
Definition: settings.h:52
bool doNotShowAgainMessageBox(int id) const
Getter function to check if the given AutoClosingMessageBox shall not be shown again.
SettingsForQt()
Empty default constructor.
virtual void setStroboscopeMode(bool enable) overridefinal
Set flag indicating the stroboscopic mode of the tuning indicator.
void setOutputDeviceName(const QString &s)
Setter function for mOutputDeviceName.
Qt specific settings.
Definition: settingsforqt.h:32
void setLastVisitedOptionsPage(int id)
Setter function for mLastVisitedOptionsPage.
virtual void setSoundGeneratorMode(SoundGenerator::SoundGeneratorMode mode)
Set the last operation mode of the sound generator.
Definition: settings.h:64
virtual void setSoundGeneratorVolumeDynamic(bool dynamic)
Set flag for dynamic volume adaption in the tuning mode.
Definition: settings.h:69
virtual void setDisableAutomaticKeySelection(bool disable) overridefinal
Set flag disabling automatic selection of the key during tuning.
void increaseApplicationRuns()
Increments mApplicationRuns.
virtual void setLastUsedAlgorithm(const std::string &name)
Set the name of the last used algorithm.
Definition: settings.h:59
virtual void setSoundGeneratorMode(SoundGenerator::SoundGeneratorMode mode) overridefinal
Set the last operation mode of the sound generator.
virtual void setDisableAutomaticKeySelection(bool disable)
Set flag disabling automatic selection of the key during tuning.
Definition: settings.h:74
Produce a sound which imitates the string.
void setInputDeviceName(const QString &s)
Setter function for mInputDeviceName.
int mInputDeviceSamplingRate
input device sampling rate
SoundGenerator::SoundGeneratorMode mSoundGeneratorMode
The sound generator mode (sine or synthesizer)
Definition: settings.h:91
QSettings mSettings
The QSettings that will store all values to the storage.
void setInputDeviceSamplingRate(int rate)
Setter function for mInputDeviceSamplingRate.
bool mStroboscopeActive
Flag indicating stroboscopic tuning indicator mode.
Definition: settings.h:94
qlonglong getApplicationRuns() const
Getter function for mApplicationRuns.
void setOutputDeviceSamplingRate(int rate)
Setter function for mOutputDeviceSamplingRate.
static SettingsForQt & getSingleton()
Getter function for the singleton.
void load()
Function to load the settings from the storage.
virtual std::string getUserLanguageId() const overridefinal
Settings::getUserLanguageId.
~SettingsForQt()
Empty defaul destructor.
virtual void setLastUsedAlgorithm(const std::string &name) overridefinal
Set the name of the last used algorithm.
int mLastVisitedOptionsPage
last activated options page