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
algorithm.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 "algorithm.h"
21 #include <cmath>
22 #include "../messages/messagehandler.h"
23 #include "../messages/messagekeyselectionchanged.h"
24 #include "../messages/messagechangetuningcurve.h"
25 #include "../messages/messagecaluclationprogress.h"
26 
28  mPiano(piano),
29  mFactoryDescription(desciption),
30  mKeyboard(mPiano.getKeyboard()),
31  mKeys(mKeyboard.getKeys()),
32  mNumberOfKeys(mKeyboard.getNumberOfKeys()),
33  mKeyNumberOfA4(mKeyboard.getKeyNumberOfA4())
34 {
35 
36 }
37 
39 {
40 
41 }
42 
44 {
45  setThreadName("Algorithm");
46  LogI("Start calculation.");
47  MessageHandler::send<MessageCaluclationProgress>
49 
51 
52  // After completion of the algorithm, deselect all keys.
53  MessageHandler::send<MessageKeySelectionChanged>(-1,nullptr);
54 
55  MessageHandler::send<MessageCaluclationProgress>
57  LogI("End of calculation");
58 }
59 
60 void Algorithm::updateTuningCurve(int keynumber, double frequency)
61 {
62  EptAssert (keynumber>=0 and keynumber<mNumberOfKeys,"Range of keynumber");
63  mKeyboard[keynumber].setComputedFrequency(frequency);
64  MessageHandler::send<MessageChangeTuningCurve>(keynumber,frequency);
65 
66 }
67 
68 
69 //-----------------------------------------------------------------------------
70 // Show calculation progress
71 //-----------------------------------------------------------------------------
72 
78 
79 void Algorithm::showCalculationProgress (double fraction)
80 {
81  MessageHandler::send<MessageCaluclationProgress>
83 }
84 
85 
86 //-----------------------------------------------------------------------------
87 // Show calculation progress
88 //-----------------------------------------------------------------------------
89 
99 
101  double start, double range)
102 {
103  double k = mKeyNumberOfA4 + 12 * std::log(key.getRecordedFrequency()/440.0)/log(2);
104  showCalculationProgress(start+range*k/mNumberOfKeys);
105 }
double getRecordedFrequency() const
Get recorded frequency.
Definition: key.cpp:119
virtual ~Algorithm()
Definition: algorithm.cpp:38
virtual void algorithmWorkerFunction()=0
virtual void workerFunction() overridefinal
Virtual worker function, executed within the new thread.
Definition: algorithm.cpp:43
Class describing a single piano key.
Definition: key.h:45
Definition: piano.h:40
Keyboard & mKeyboard
Reference to the keyboard.
Definition: algorithm.h:66
static void setThreadName(std::string s)
Specify the name of the thread.
const int mKeyNumberOfA4
Number of A4.
Definition: algorithm.h:69
#define LogI(...)
Definition: log.h:50
void showCalculationProgress(double fraction)
Transmit the current percentage of progress to the messaging system.
Definition: algorithm.cpp:79
void updateTuningCurve(int keynumber, double frequency)
Definition: algorithm.cpp:60
#define EptAssert(a, b)
Definition: eptexception.h:47
Algorithm(const Piano &piano, const AlgorithmFactoryDescription &desciption)
Definition: algorithm.cpp:27
const int mNumberOfKeys
The number of keys.
Definition: algorithm.h:68