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
resettorecording.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 // Reset to recorded pitches
22 //=============================================================================
23 
24 #include "resettorecording.h"
26 #include "core/system/log.h"
27 
28 template<>
30  AlgorithmFactoryDescription("resettorecording"));
31 
32 
34 {
35 
36 //-----------------------------------------------------------------------------
37 // Constructor
38 //-----------------------------------------------------------------------------
39 
45 
47  Algorithm(piano, description)
48 {
49 }
50 
51 
52 //-----------------------------------------------------------------------------
53 // Worker function carrying out the computation
54 //-----------------------------------------------------------------------------
55 
59 
61 {
62  LogI("Algorithm ResetToRecording carried out, copying the recorded pitches to the tuning curve.")
63 
64  const int A4key = mPiano.getKeyboard().getKeyNumberOfA4();
65  double fA4 = mPiano.getKey(A4key).getRecordedFrequency();
66  // if A4 was not recorded then fall back to 440 Hz
67  if (fA4 < 400 or fA4 > 480) fA4=440;
68 
69  // Copy all recorded values, normalizing them to the wanted ConcertPitch
70  for (int i = 0; i < mNumberOfKeys; ++i)
71  {
72  msleep(10);
74  }
75 }
76 
77 
78 } // end of namespace resettorecording
double getRecordedFrequency() const
Get recorded frequency.
Definition: key.cpp:119
The AlgorithmFactory class is a template class to be created with the actual Algorithm.
void msleep(double milliseconds)
Sleep function for staying idle.
Definition: piano.h:40
const Keyboard & getKeyboard() const
Definition: piano.h:83
#define LogI(...)
Definition: log.h:50
static const AlgorithmFactory mSingleton
void updateTuningCurve(int keynumber, double frequency)
Definition: algorithm.cpp:60
The Algorithm class is a basic abstract class for any algorithm.
Definition: algorithm.h:38
int getKeyNumberOfA4() const
Definition: keyboard.h:73
ResetToRecording(const Piano &piano, const AlgorithmFactoryDescription &description)
Constructor of the copy algorithm.
virtual void algorithmWorkerFunction() overridefinal
Worker function in which the computation thread is carried out.
Piano mPiano
Copy of the piano.
Definition: algorithm.h:62
const Key & getKey(int i) const
Definition: piano.h:86
const int mNumberOfKeys
The number of keys.
Definition: algorithm.h:68