Just Intonation  Version 1.3.1 (19)
Explore key-independent dynamically adapting tuning in just intonation
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright 2016-2017 Karolin Stange, Christoph Wick, and Haye Hinrichsen
3  *
4  * This file is part of JustIntonation.
5  *
6  * JustIntonation 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  * JustIntonation 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
14  * for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with JustIntonation. If not, see http://www.gnu.org/licenses/.
18  *****************************************************************************/
20 //=============================================================================
21 // Tuner: Module for adaptive tuning
22 //=============================================================================
24 #ifndef TUNER_H
25 #define TUNER_H
27 #include <QObject>
28 #include <QVector>
29 #include <QMap>
30 #include <QVariant>
31 #include <QTimer>
32 #include <QElapsedTimer>
33 #include <QMidiMessage>
35 #include "tunerreadme.h"
36 #include "system/threadbase.h"
37 #include "tunerkeydata.h"
38 #include "tuneralgorithm.h"
49 class Tuner : public ThreadBase
50 {
52 public:
53  Tuner(); // Constructor
54  bool init() override final; // Initialization after construction
55  bool start() override final; // Start tuner thread
57  //-------------------------------------------------------------------------
59 public slots:
61  void setFrequencyOfA4 (double f=440);
62  void setTuningMode (int mode, int wolfsShift); // 0:ET 1:UT 2:JI
63  void enableTuning (bool enable);
64  void setStaticTuningMode (bool enable, int reference = 0);
66  double secondsSustainBass,
67  double secondsSustainTreble,
68  double secondsRelease);
70  void setIntervalSize (int semitones, double cents);
71  void setIntervalWeight (int semitones, double weight);
72  void setPitchProgressionCompensationParameter (double lambda);
73  void setDelayParameter (double delay);
74  void setMemoryLength (double seconds);
76  void receiveMidiEvent (QMidiMessage event);
77  void resetPitchProgression();
79  //-------------------------------------------------------------------------
81 signals:
88  void signalTuningCorrections (QMap<int,double> corrections);
92  void signalAveragePitchDrift (double progression);
95  void signalIntervalString (QVariant str);
99  void signalTension (QVariant mu);
101  //-------------------------------------------------------------------------
103 private:
104  // Constants:
105  const uint tuningIntervalMsec = 20;
107  // Constants for envelope simulation:
108  const uint updateIntervalMsec = 20;
109  const uint noteTimeoutSeconds = 60;
110  const double cutoffIntensity = 0.001;
111  const double cutoffMemory = 0.0001;
112  const double memoryOnSeconds = 0.3;
113  const double memoryOnFactor = exp(-0.005*updateIntervalMsec/memoryOnSeconds);
115 private:
116  // Member variables
123  QString mLastMessage;
124  QVector<double> mIntervalSizes;
125  QVector<double> mIntervalWeights;
126  QVector<KeyData> mKeyDataVector;
127  QElapsedTimer *pElapsedTimer;
134 private:
135  friend class TunerAlgorithm;
137  qint64 getNow();
138  void handlePitchDrift();
139  void emitPitchCorrections();
141  virtual void initiallyCalledWorker() override final;
142  virtual void periodicallyCalledWorker() override final;
143  virtual void finallyCalledWorker() override final;
145 private slots:
146  void tune();
147 };
149 #endif // TUNER_H
void signalIntervalString(QVariant str)
Signal emitting the tuned interval sizes in a human-readable form.
bool start() override final
Public slot: Start the tuner, starting the tuner thread.
Definition: tuner.cpp:94
Universal base class for threaded modules.
Definition: threadbase.h:60
void setIntervalSize(int semitones, double cents)
Public Slot: Set interval size This function allows the user to specify the temperament. To this end one specifies the interval sizes relative to the equal temperament in cents. The complete definition of the temperament requires to set all interval sizes, meaning that this slot has to be called 11 times.
Definition: tuner.cpp:339
const double cutoffMemory
Definition: tuner.h:111
double mPitchAutoCorrectionParameter
Pitch correction parameters.
Definition: tuner.h:129
const double memoryOnSeconds
Definition: tuner.h:112
const uint tuningIntervalMsec
Update interval tuning.
Definition: tuner.h:105
QVector< double > mIntervalWeights
List of 12 interval weights.
Definition: tuner.h:125
TunerAlgorithm mTunerAlgorithm
The tuning algorithm.
Definition: tuner.h:117
void enableTuning(bool enable)
Public Slot: Enable or disable adaptive tuning.
Definition: tuner.cpp:175
double mMemoryOffFactor
Update factor for memory decay.
Definition: tuner.h:131
void setStaticTuningMode(bool enable, int reference=0)
Slot: Enable or disable static tuning mode.
Definition: tuner.cpp:457
void signalAveragePitchDrift(double progression)
Signal that periodically transmits the average pitch progression. In the GUI this progression is indi...
bool init() override final
Initialize the Tuner.
Definition: tuner.cpp:68
void setMemoryLength(double seconds)
Public slot: Set memory parameter.
Definition: tuner.cpp:247
void resetPitchProgression()
Reset average pitch progression to a given value.
Definition: tuner.cpp:656
QString mLastMessage
remember last message sent
Definition: tuner.h:123
const uint noteTimeoutSeconds
Definition: tuner.h:109
void setTuningMode(int mode, int wolfsShift)
Public slot: Set tuning mode.
Definition: tuner.cpp:134
Constructor of the Tuner.
Definition: tuner.cpp:35
virtual void periodicallyCalledWorker() override final
Periodically called worker function: Update key data.
Definition: tuner.cpp:545
bool mTuningEnabled
Flag for temporary on/off.
Definition: tuner.h:122
double mDelayParameter
Delay time.
Definition: tuner.h:130
QString f(Eigen::MatrixXd mat)
Definition: tunerdebug.h:27
qint8 mWaitingTimeMsec
Waiting time before tuning event.
Definition: tuner.h:132
void setDelayParameter(double delay)
Public Slot: Set delay parameter.
Definition: tuner.cpp:226
void signalTension(QVariant mu)
Signal emitting the network tension in the tuned chord, indicating the deviation from just intonation...
int mStaticReferenceKey
Index of static UT reference key.
Definition: tuner.h:120
void handlePitchDrift()
Handle pitch drift.
Definition: tuner.cpp:620
void setIntervalWeight(int semitones, double weight)
Public Slot: Set interval weight The human perception of various intervals depends on their size...
Definition: tuner.cpp:369
QVector< double > mIntervalSizes
List of 12 interval sizes.
Definition: tuner.h:124
double mGlobalTargetPitchInCents
Global pitch against 440Hz.
Definition: tuner.h:118
This is the main class of the tuner module.
Definition: tuner.h:49
qint64 getNow()
Private function: Get current elapsed tuner runtime in milliseconds.
Definition: tuner.cpp:441
void signalTuningCorrections(QMap< int, double > corrections)
Signal sending the tuning results to the microtonal sound device in the form of a map keyindex -> cen...
const uint updateIntervalMsec
Update interval envelope.
Definition: tuner.h:108
void receiveMidiEvent(QMidiMessage event)
Public slot: Receive Midi event (Main input of the tuner)
Definition: tuner.cpp:271
Main Tuning Algorithm.
void setFrequencyOfA4(double f=440)
Public slot: Set the desired target frequency of A4 (concert pitch)
Definition: tuner.cpp:110
QVector< KeyData > mKeyDataVector
Vector containing all key data.
Definition: tuner.h:126
const double memoryOnFactor
Definition: tuner.h:113
int mWolfsIntervalShift
Placement of the wolfs interval.
Definition: tuner.h:121
void setPitchProgressionCompensationParameter(double lambda)
Public slot: Set the parameter for pitch progression compensation.
Definition: tuner.cpp:201
void emitPitchCorrections()
Emit the pitch corrections This functions checks to what extent the calculated pitches differ from th...
Definition: tuner.cpp:389
void signalReadyForReceivingParameters()
Signal telling the GUI that the tuner is ready and that the GUI may send the user-defined parameters ...
QElapsedTimer * pElapsedTimer
Time elapsed since construction.
Definition: tuner.h:127
bool mStaticTuningModeEnabled
Flag: Tune statically.
Definition: tuner.h:128
virtual void finallyCalledWorker() override final
Cleanup of the terminating thread.
Definition: tuner.cpp:530
const double cutoffIntensity
Definition: tuner.h:110
int mTuningMode
Actual tuning mode.
Definition: tuner.h:119
void setEnvelopeParameters(double secondsSustainBass, double secondsSustainTreble, double secondsRelease)
Set the essential parameters of the envelope.
Definition: tuner.cpp:490
virtual void initiallyCalledWorker() override final
Initialization of the starting thread.
Definition: tuner.cpp:516
void tune()
Tune the pitches of the pressed keys (call TunerAlgorithm)
Definition: tuner.cpp:584