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
piano.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 //=============================================================================
21 // Piano class
22 //=============================================================================
23 
24 #include "piano.h"
25 
26 #include <cmath>
27 #include <ctime>
28 
29 #include "../system/eptexception.h"
30 
31 const int Piano::DEFAULT_NUMBER_OF_KEYS = 88;
32 const int Piano::DEFAULT_KEY_NUMBER_OF_A = 48;
34 const double Piano::DEFAULT_CONCERT_PITCH = 440;
35 
36 
37 //-----------------------------------------------------------------------------
38 // Constructor
39 //-----------------------------------------------------------------------------
40 
44 
46  mName(""),
47  mType(piano::PT_GRAND),
48  mSerialNumber(""),
49  mManufactureYear(""),
50  mManufactureLocation(""),
51  mTuningLocation(""),
52  mTuningTime(""),
53  mConcertPitch(DEFAULT_CONCERT_PITCH),
54  mKeyboard(DEFAULT_NUMBER_OF_KEYS)
55 {
56  setTuningTimeToActualTime(); // Set current time as tuning time
57 }
58 
59 
60 
61 //-----------------------------------------------------------------------------
62 // set tuning time to actual time
63 //-----------------------------------------------------------------------------
64 
69 
71 {
72  time_t rawtime = time(0);
73  struct tm nowtime;
74 #ifdef _MSC_VER
75  gmtime_s(&nowtime, &rawtime);
76 #else
77  nowtime = *gmtime(&rawtime);
78 #endif
79  char buffer[50];
80  strftime(buffer, 50, "%Y-%m-%d %H:%M:%S", &nowtime);
81  mTuningTime = buffer;
82 }
83 
84 
85 //-----------------------------------------------------------------------------
86 // Set tuning time to actual time
87 //-----------------------------------------------------------------------------
88 
101 
102 double Piano::getExpectedInharmonicity (double f) const
103 {
104  return (f > 100 ? exp(-15.45 + 1.354*log(f)) : exp(-2.622 - 1.431*log(f)));
105 }
106 
107 
108 //-----------------------------------------------------------------------------
109 // Equal temperament
110 //-----------------------------------------------------------------------------
111 
122 
123 double Piano::getEqualTempFrequency (int keynumber, double cents, double A4) const
124 {
125  EptAssert(keynumber>=0 and keynumber < mKeyboard.getNumberOfKeys(),"range of keynumber");
126  return (A4>0 ? A4 : mConcertPitch) *
127  pow(2.0, (100.0*(keynumber-mKeyboard.getKeyNumberOfA4())+cents)/1200.0);
128 }
129 
130 
131 //-----------------------------------------------------------------------------
132 // define the temperament
133 //-----------------------------------------------------------------------------
134 
147 
148 double Piano::getDefiningTempFrequency (int keynumber, double cents, double A4) const
149 {
150  EptAssert(keynumber>=0 and keynumber < mKeyboard.getNumberOfKeys(),"range of keynumber");
151  return getEqualTempFrequency(keynumber,cents,A4);
152 }
Keyboard mKeyboard
the keyboard
Definition: piano.h:122
static const double DEFAULT_CONCERT_PITCH
default concert pitch of A
Definition: piano.h:46
double mConcertPitch
concert pitch (default 440 Hz)
Definition: piano.h:119
double getDefiningTempFrequency(int keynumber, double cents=0, double A4=0) const
Compute the defining temperatent.
Definition: piano.cpp:148
static const int DEFAULT_KEY_NUMBER_OF_A
Definition: piano.h:44
Piano()
Constructor of the piano, initializing the member variables.
Definition: piano.cpp:45
double getEqualTempFrequency(int keynumber, double cents=0, double A4=0) const
Function returning the equal temperament.
Definition: piano.cpp:123
static const int DEFAULT_KEYS_ON_BASS_BRIDGE
Definition: piano.h:45
void setTuningTimeToActualTime()
This function resets the tuning time to the actual time. This is used as default value.
Definition: piano.cpp:70
static const int DEFAULT_NUMBER_OF_KEYS
Definition: piano.h:43
int getKeyNumberOfA4() const
Definition: keyboard.h:73
std::string mTuningTime
time when the tuning hast been started (format yyyy-mm-dd HH:MM:SS, UTC)
Definition: piano.h:117
#define EptAssert(a, b)
Definition: eptexception.h:47
double getExpectedInharmonicity(double f) const
Compute expected approximative inharmonicity.
Definition: piano.cpp:102
int getNumberOfKeys() const
Definition: keyboard.h:72
The piano is a grand piano.
Definition: pianodefines.h:30