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
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  *****************************************************************************/
20 //=============================================================================
21 // Class describing a single piano key
22 //=============================================================================
24 #ifndef KEY_H
25 #define KEY_H
27 #include <vector>
28 #include <map>
45 class Key
46 {
47 public:
48  // Charactereistics of the logarithmically binned spectrum
50  static const int NumberOfBins;
51  static const int BinsPerOctave;
52  static const double fmin;
54  using SpectrumType = std::vector<double>;
55  using PeakListType = std::map<double,double>;
57  // Conversion function in the context of the logarithmically binned spectrum
59  static int FrequencyToIndex(double f);
60  static double FrequencyToRealIndex (double f);
61  static double IndexToFrequency (double m);
63 public:
65  Key() { clear(); }
66  ~Key() {}
67  void clear();
69  void setSpectrum (const SpectrumType &s);
70  const SpectrumType &getSpectrum() const;
73  void setPeaks (const PeakListType &s);
74  const PeakListType &getPeaks() const;
77  void setRecordedFrequency (const double f);
78  double getRecordedFrequency () const;
79  double &getRecordedFrequency ();
81  void setMeasuredInharmonicity(double f);
82  double getMeasuredInharmonicity () const;
83  double &getMeasuredInharmonicity ();
85  void setRecognitionQuality(double f);
86  double getRecognitionQuality () const;
87  double &getRecognitionQuality ();
89  void setComputedFrequency (double f);
90  double getComputedFrequency () const;
91  double &getComputedFrequency ();
93  void setTunedFrequency (double f);
94  double getTunedFrequency () const;
95  double &getTunedFrequency ();
97  void setOverpull (double cents);
98  double getOverpull () const;
99  double &getOverpull ();
101  void setRecorded(bool r) {mRecorded = r;}
102  bool isRecorded() const {return mRecorded;}
103  bool &isRecorded() {return mRecorded;}
105 private:
113  double mOverpull;
114  bool mRecorded;
115 };
117 #endif // KEY_H
bool isRecorded() const
Get recorded flag.
Definition: key.h:102
double getRecordedFrequency() const
Get recorded frequency.
Definition: key.cpp:119
void setTunedFrequency(double f)
Set tuned frequency.
Definition: key.cpp:187
void setPeaks(const PeakListType &s)
Copy map of peaks.
Definition: key.cpp:245
PeakListType mPeaks
List of identified peaks.
Definition: key.h:107
double mOverpull
Overpull in cents.
Definition: key.h:113
const PeakListType & getPeaks() const
Get a read-only reference to mPeaks.
Definition: key.cpp:259
void setMeasuredInharmonicity(double f)
Set estimated inharmonicity.
Definition: key.cpp:130
void setComputedFrequency(double f)
Set computed frequency.
Definition: key.cpp:168
Class describing a single piano key.
Definition: key.h:45
void setRecordedFrequency(const double f)
Set recorded frequency.
Definition: key.cpp:113
static const int NumberOfBins
Total number of slots: 9 octaves.
Definition: key.h:50
static const int BinsPerOctave
Number of slots per ocatave (here 1 cent)
Definition: key.h:51
double mRecognitionQuality
Accuracy of higher partials (in cents)
Definition: key.h:110
void setOverpull(double cents)
Set overpull in cents.
Definition: key.cpp:204
Definition: key.h:66
bool mRecorded
Is the key already recorded?
Definition: key.h:114
static double IndexToFrequency(double m)
Convert continuous slot index to frequency in Hz.
Definition: key.cpp:102
void setSpectrum(const SpectrumType &s)
Copy spectrum to mSpectrum.
Definition: key.cpp:222
double mRecordedFrequency
Recorded frequency of 1st partial in Hz.
Definition: key.h:108
double getComputedFrequency() const
Get computed frequency.
Definition: key.cpp:174
double getMeasuredInharmonicity() const
Get estimated inharmonicity.
Definition: key.cpp:141
static double FrequencyToRealIndex(double f)
Convert frequency to real-valued logbin index.
Definition: key.cpp:70
void setRecognitionQuality(double f)
Set quality of recognition.
Definition: key.cpp:152
void clear()
Clear all data elements of the Key.
Definition: key.cpp:42
double getRecognitionQuality() const
Get quality of recognition.
Definition: key.cpp:155
std::vector< double > SpectrumType
Type of a log-binned spectrum.
Definition: key.h:54
double mMeasuredInharmonicity
Measured inharmonicity of recorded signal.
Definition: key.h:109
SpectrumType mSpectrum
Logarithmically organized spectrum.
Definition: key.h:106
const SpectrumType & getSpectrum() const
Get a read-only reference to mSpectrum.
Definition: key.cpp:237
void setRecorded(bool r)
Set recorded flag.
Definition: key.h:101
Definition: key.h:65
double mComputedFrequency
Computed frequency in Hz (tuning curve)
Definition: key.h:111
static int FrequencyToIndex(double f)
Convert frequency to logbin index.
Definition: key.cpp:88
double getTunedFrequency() const
Get tuned frequency.
Definition: key.cpp:193
std::map< double, double > PeakListType
Type for a peak map.
Definition: key.h:55
double getOverpull() const
Get overpull in cents.
Definition: key.cpp:211
static const double fmin
Mimimal frequency of logbinned spectrum in Hz.
Definition: key.h:52
double mTunedFrequency
Tuned frequency in Hz.
Definition: key.h:112
bool & isRecorded()
Get recorded flag.
Definition: key.h:103