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
examplealgorithm.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 "examplealgorithm.h"
21 
22 // include the factory we will create later
24 
25 // this line adds a factory for this algorithm and automatically registers it with the given name
26 // to the calculation manager
27 template<>
29  AlgorithmFactoryDescription("examplealgorithm"));
30 
31 // namespace of the algorithm to prevent naming conflicts
33 {
34 
35 // constructor that expects the originam piano. This piano will be copied into mPiano which is why
36 // you may do any changes to mPiano because it doesnt change the actual one.
38  Algorithm(piano, description),
39  // load the parameter from the description
40  mConcertPitchParam(description.getDoubleParameter("concertPitch"))
41 {
42 }
43 
44 // This is the actual worker function in which you have to define your algorithm.
45 // It will be started in a separate std::thread.
46 // It might happen that the user wants to cancel the algorithm even though it is not
47 // finished yet. Therefore you have to set exit marks using CHECK_CANCEL_THREAD, at
48 // whom the algorithm can exit and the thread will be stopped.
50 {
51  // use check cancel thread flags to mark exit points (if the user wants to cancel)
53 
54  // do the calculation here
55 
56  // for example we just to a equidistant tuning
57  for (int i = 0; i < mNumberOfKeys; ++i)
58  {
59  // usually the exit mark should be set at each time before you make some kind of longer calculation,
60  // that can't be interrupted.
62 
63  // show the calculation progress to the user
64  showCalculationProgress(static_cast<double>(i) / mNumberOfKeys);
65 
66  // sleep for 0.2 sec so that you can see the changes in the tuning curve and test to cancel the algorithm
67  msleep(200);
68 
69  // set the tuning curve
71  }
72 }
73 
74 } // namespace examplealgorithm
The AlgorithmFactory class is a template class to be created with the actual Algorithm.
#define CHECK_CANCEL_THREAD
void msleep(double milliseconds)
Sleep function for staying idle.
Definition: piano.h:40
virtual void algorithmWorkerFunction() overridefinal
double getEqualTempFrequency(int keynumber, double cents=0, double A4=0) const
Function returning the equal temperament.
Definition: piano.cpp:123
static const AlgorithmFactory mSingleton
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
The Algorithm class is a basic abstract class for any algorithm.
Definition: algorithm.h:38
ExampleAlgorithm(const Piano &piano, const AlgorithmFactoryDescription &description)
Piano mPiano
Copy of the piano.
Definition: algorithm.h:62
const int mNumberOfKeys
The number of keys.
Definition: algorithm.h:68