![]() |
Just Intonation
Version 1.3.1 (19)
Explore key-independent dynamically adapting tuning in just intonation
|
This is the main class of the tuner module. More...
#include <tuner.h>
Public Slots | |
void | setFrequencyOfA4 (double f=440) |
Public slot: Set the desired target frequency of A4 (concert pitch) More... | |
void | setTuningMode (int mode, int wolfsShift) |
Public slot: Set tuning mode. More... | |
void | enableTuning (bool enable) |
Public Slot: Enable or disable adaptive tuning. More... | |
void | setStaticTuningMode (bool enable, int reference=0) |
Slot: Enable or disable static tuning mode. More... | |
void | setEnvelopeParameters (double secondsSustainBass, double secondsSustainTreble, double secondsRelease) |
Set the essential parameters of the envelope. More... | |
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. More... | |
void | setIntervalWeight (int semitones, double weight) |
Public Slot: Set interval weight The human perception of various intervals depends on their size. For example, the human sense of hearing is very sensitive if a perfect fifth is out of tune while deviations of a halftone, tritone, or a sept are less are more likely to be tolerated. This depends on the number of matching partials in the harmonic series. For key patterns that cannot be tuned in just intonation the algorithm establishes a compromise based on a linear set of equations. In this set each interval is weighet differently, allowing the user to make a difference between "more important" and "less important" intervals. More... | |
void | setPitchProgressionCompensationParameter (double lambda) |
Public slot: Set the parameter for pitch progression compensation. More... | |
void | setDelayParameter (double delay) |
Public Slot: Set delay parameter. More... | |
void | setMemoryLength (double seconds) |
Public slot: Set memory parameter. More... | |
void | receiveMidiEvent (QMidiMessage event) |
Public slot: Receive Midi event (Main input of the tuner) More... | |
void | resetPitchProgression () |
Reset average pitch progression to a given value. More... | |
Signals | |
void | signalReadyForReceivingParameters () |
Signal telling the GUI that the tuner is ready and that the GUI may send the user-defined parameters to the tuner. More... | |
void | signalTuningCorrections (QMap< int, double > corrections) |
Signal sending the tuning results to the microtonal sound device in the form of a map keyindex -> cents for all active keys. More... | |
void | signalAveragePitchDrift (double progression) |
Signal that periodically transmits the average pitch progression. In the GUI this progression is indicated by a circular gauge. More... | |
void | signalIntervalString (QVariant str) |
Signal emitting the tuned interval sizes in a human-readable form. More... | |
void | signalTension (QVariant mu) |
Signal emitting the network tension in the tuned chord, indicating the deviation from just intonation. More... | |
Public Member Functions | |
Tuner () | |
Constructor of the Tuner. More... | |
bool | init () override final |
Initialize the Tuner. More... | |
bool | start () override final |
Public slot: Start the tuner, starting the tuner thread. More... | |
virtual bool | exit () |
Virtual exit function (no functionality here) More... | |
virtual bool | stop () |
Stop the thread. More... | |
virtual void | suspend () |
Mark the thread as suspended. More... | |
virtual void | resume () |
Resume from the suspend mode. More... | |
bool | isActive () const |
Return true if thread is running and not suspended. More... | |
void | setVerbosity (int verbosity) |
Set verbosity level of messages. More... | |
int | getVerbosity () |
Get verbosity level. More... | |
QString | getThreadName () const |
Get thread name. More... | |
Protected Member Functions | |
void | setPriority (const QThread::Priority p) |
Set thread priority. More... | |
void | setTimerInterval (const int msec, const int firstMsec=0) |
Set timer interval for the periodically called worker. More... | |
void | setThreadName (const QString name) |
Set thread name (Linux only) More... | |
bool | isInterruptionRequested () const |
Return true if the thread was requested to interrupt or terminate. More... | |
Private Slots | |
void | tune () |
Tune the pitches of the pressed keys (call TunerAlgorithm) More... | |
Private Member Functions | |
qint64 | getNow () |
Private function: Get current elapsed tuner runtime in milliseconds. More... | |
void | handlePitchDrift () |
Handle pitch drift. More... | |
void | emitPitchCorrections () |
Emit the pitch corrections This functions checks to what extent the calculated pitches differ from the previous ones. If the difference is larger than the centQuantization the changes are sent to the sampler or to the external Midi device. More... | |
virtual void | initiallyCalledWorker () override final |
Initialization of the starting thread. More... | |
virtual void | periodicallyCalledWorker () override final |
Periodically called worker function: Update key data. More... | |
virtual void | finallyCalledWorker () override final |
Cleanup of the terminating thread. More... | |
Private Attributes | |
const uint | tuningIntervalMsec = 20 |
Update interval tuning. More... | |
const uint | updateIntervalMsec = 20 |
Update interval envelope. More... | |
const uint | noteTimeoutSeconds = 60 |
const double | cutoffIntensity = 0.001 |
const double | cutoffMemory = 0.0001 |
const double | memoryOnSeconds = 0.3 |
const double | memoryOnFactor = exp(-0.005*updateIntervalMsec/memoryOnSeconds) |
TunerAlgorithm | mTunerAlgorithm |
The tuning algorithm. More... | |
double | mGlobalTargetPitchInCents |
Global pitch against 440Hz. More... | |
int | mTuningMode |
Actual tuning mode. More... | |
int | mStaticReferenceKey |
Index of static UT reference key. More... | |
int | mWolfsIntervalShift |
Placement of the wolfs interval. More... | |
bool | mTuningEnabled |
Flag for temporary on/off. More... | |
QString | mLastMessage |
remember last message sent More... | |
QVector< double > | mIntervalSizes |
List of 12 interval sizes. More... | |
QVector< double > | mIntervalWeights |
List of 12 interval weights. More... | |
QVector< KeyData > | mKeyDataVector |
Vector containing all key data. More... | |
QElapsedTimer * | pElapsedTimer |
Time elapsed since construction. More... | |
bool | mStaticTuningModeEnabled |
Flag: Tune statically. More... | |
double | mPitchAutoCorrectionParameter |
Pitch correction parameters. More... | |
double | mDelayParameter |
Delay time. More... | |
double | mMemoryOffFactor |
Update factor for memory decay. More... | |
qint8 | mWaitingTimeMsec |
Waiting time before tuning event. More... | |
Friends | |
class | TunerAlgorithm |
This is the main class of the tuner module.
This class is basically a wrapper class which supports the TunerAlgorithm and communicates with the outside world via Qt signals and slots. It keeps track of the pressed keys and generates the memory function M(t).
Tuner::Tuner | ( | ) |
|
private |
Emit the pitch corrections This functions checks to what extent the calculated pitches differ from the previous ones. If the difference is larger than the centQuantization the changes are sent to the sampler or to the external Midi device.
Definition at line 389 of file tuner.cpp.
|
slot |
Public Slot: Enable or disable adaptive tuning.
With this function it is possible to temporarily disable the active tuning process. When disabled, the tuner is not stopped, rather it remains active, sending zero pitches when necessary. This means that the synthesizer plays in equal temperament. In the application this function may be connected e.g. with the left pedal of the keyboard in order to easily demonstrate the difference between just and equal temperament.
enable | : True for active tuning, false otherwise |
|
inlinevirtualinherited |
Virtual exit function (no functionality here)
Reimplemented in AudioOutput.
Definition at line 71 of file threadbase.h.
|
finaloverrideprivatevirtual |
Cleanup of the terminating thread.
Reimplemented from ThreadBase.
|
private |
|
inherited |
Get thread name.
Definition at line 132 of file threadbase.cpp.
|
inlineinherited |
Get verbosity level.
Definition at line 80 of file threadbase.h.
|
private |
Handle pitch drift.
This function compensates the migration of the pitch. To this end it first determines the average pitch of the keys with volume > 0. Then it adiabatically corrects the pitch controlled by the mPitchCorrectionParameter and finally sends the pitch deviation to the circular gauge in the expert mode
|
finaloverridevirtual |
Initialize the Tuner.
Initialize the thread and clear all keys and pitch corrections.
Reimplemented from ThreadBase.
Definition at line 68 of file tuner.cpp.
|
finaloverrideprivatevirtual |
Initialization of the starting thread.
Reimplemented from ThreadBase.
Definition at line 516 of file tuner.cpp.
|
inherited |
Return true if thread is running and not suspended.
Definition at line 136 of file threadbase.cpp.
|
protectedinherited |
Return true if the thread was requested to interrupt or terminate.
Definition at line 128 of file threadbase.cpp.
|
finaloverrideprivatevirtual |
Periodically called worker function: Update key data.
This function is frequently called to emulate the envelope (ADSR) of the intensity I(t) and the psychoacoustic memory M(t).
Reimplemented from ThreadBase.
Definition at line 545 of file tuner.cpp.
|
slot |
Public slot: Receive Midi event (Main input of the tuner)
This slot receives and interprets Midi keyboard data in real time.
event | : Midi event of the type QMidiMessage (see library QMidi) |
Definition at line 271 of file tuner.cpp.
|
slot |
Reset average pitch progression to a given value.
In a dynamical tuning scheme the average pitch may begin to drift away from zero. This function allows you to set the average pitch progression to a given value by force.
Definition at line 656 of file tuner.cpp.
|
virtualinherited |
Resume from the suspend mode.
Restart the timer and clear the mSuspended flag
Reimplemented in MidiPlayer.
Definition at line 99 of file threadbase.cpp.
|
slot |
Public Slot: Set delay parameter.
This experimental option allows the user to specify a timespan after which the tuning sets it. This means that a tone is first played in ordinary equal temperament and then switches to the computed tune. This may be used to demonstrate the difference between ET and UT.
|
slot |
Set the essential parameters of the envelope.
The tuner is controlled by Midi commands. This means that the tuner has no information about the type of the instrument. Since the weight of a tone in the tuning process depends on its volume (a tone that is not audible does not need to be tuned) one can use this function to provide the tuner with a rough information about the envelope as a function of time. When the key is pressed (sustain) the volume is assumed to decay exponentially on a time scale varying linearly from the first argument to the second argument along the keyboard. After releasing the key, the volume is assumed to decay exponentially on a time scale according to the third parameter. For an organ use very large sustain time. For an imstrument with instant decay after release use secondsRelease=0. For a piano typical parameters are 5 secs in the bass and 1 sec in the treble with a decay time of 0.2 secs. These parameters are empirical and it is advised to test various values.
secondsBass | : Sustain exponential decay time scale of the lowest tone |
secondsTreble | : Sustain exponential decay time scale of the highest tone |
secondsRelease | : Release exponential decay time scale. |
|
slot |
|
slot |
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.
halftones | : Number of halftones, specifying the interval. For example, a perfect fourth consists of 5 halftones, a perfect fifth of seven halftones. |
cents | : Deviation of the interval size relative to the equal temperament in the range (-100..100). |
|
slot |
Public Slot: Set interval weight The human perception of various intervals depends on their size. For example, the human sense of hearing is very sensitive if a perfect fifth is out of tune while deviations of a halftone, tritone, or a sept are less are more likely to be tolerated. This depends on the number of matching partials in the harmonic series. For key patterns that cannot be tuned in just intonation the algorithm establishes a compromise based on a linear set of equations. In this set each interval is weighet differently, allowing the user to make a difference between "more important" and "less important" intervals.
halftones | : Number of halftones, specifying the interval. For example, a perfect fourth consists of 5 halftones, a perfect fifth of seven halftones. |
weight | : Weight parameter in the range 0..1 |
|
slot |
|
slot |
Public slot: Set the parameter for pitch progression compensation.
One of the problems of non-ETs is that the global average pitch begins to slide if certain sequences of intervals are being played (this is also the reason why even good choirs tend to get out of pitch after some time). The algorithm tries to compensate this progression by a continuous adiabatic correction of the global average pitch. The parameter $lambda$ which you can set here allows you to control the time scale of this correction, varying from $lambda=0$ (none) to $lambda=1$ (instant).
lambda | : parameter in the range from 0 (no correction) to 1 (instant correction) |
|
protectedinherited |
Set thread priority.
Definition at line 109 of file threadbase.cpp.
|
slot |
|
protectedinherited |
Set thread name (Linux only)
Definition at line 121 of file threadbase.cpp.
|
protectedinherited |
Set timer interval for the periodically called worker.
Definition at line 117 of file threadbase.cpp.
|
slot |
|
inherited |
Set verbosity level of messages.
Definition at line 113 of file threadbase.cpp.
|
signal |
Signal that periodically transmits the average pitch progression. In the GUI this progression is indicated by a circular gauge.
|
signal |
Signal emitting the tuned interval sizes in a human-readable form.
|
signal |
Signal telling the GUI that the tuner is ready and that the GUI may send the user-defined parameters to the tuner.
|
signal |
Signal emitting the network tension in the tuned chord, indicating the deviation from just intonation.
|
signal |
Signal sending the tuning results to the microtonal sound device in the form of a map keyindex -> cents for all active keys.
|
finaloverridevirtual |
Public slot: Start the tuner, starting the tuner thread.
Start the thread of the tuner and tell the GUI that the tuner is ready for setting parameters such as the temperament and the weights
Reimplemented from ThreadBase.
Definition at line 94 of file tuner.cpp.
|
virtualinherited |
Stop the thread.
Send a termination request to the execution loop. Wait for the thread to terminate. The active components of the thread should call isInterruptionRequested() and quit immediately if this function is true.
Reimplemented in MidiPlayer, AudioOutput, and Instrument.
Definition at line 152 of file threadbase.cpp.
|
virtualinherited |
Mark the thread as suspended.
Calling this function tells the thread that it has to wait in some sort of standby. Note that the thread itself is not terminated and that the event loop is still active. Calling this function stops the timer so that the periodicallyCalledWorker() is not active any more. In addition the mSuspended flag is set.
Reimplemented in MidiPlayer, and SoundGenerator.
Definition at line 84 of file threadbase.cpp.
|
privateslot |
Tune the pitches of the pressed keys (call TunerAlgorithm)
This function tunes the pitches of the active keys. It chooses the corresponding function in the TunerAlgorithm class depending on the paremeters (ET, static tuning, and dynamical tuning)
Definition at line 584 of file tuner.cpp.
|
friend |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |