Just Intonation  Version 1.3.1 (19)
Explore key-independent dynamically adapting tuning in just intonation
Tuner Class Reference

This is the main class of the tuner module. More...

#include <tuner.h>

Inheritance diagram for Tuner:
Inheritance graph
Collaboration diagram for Tuner:
Collaboration graph

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< KeyDatamKeyDataVector
 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
 

Detailed Description

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).

Definition at line 49 of file tuner.h.

Constructor & Destructor Documentation

Tuner::Tuner ( )

Constructor of the Tuner.

Constructor of the Tuner, resetting its member variables

Definition at line 35 of file tuner.cpp.

Here is the call graph for this function:

Member Function Documentation

void Tuner::emitPitchCorrections ( )
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.

Here is the call graph for this function:

void Tuner::enableTuning ( bool  enable)
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.

Parameters
enable: True for active tuning, false otherwise

Definition at line 175 of file tuner.cpp.

virtual bool ThreadBase::exit ( )
inlinevirtualinherited

Virtual exit function (no functionality here)

Reimplemented in AudioOutput.

Definition at line 71 of file threadbase.h.

Here is the call graph for this function:

void Tuner::finallyCalledWorker ( )
finaloverrideprivatevirtual

Cleanup of the terminating thread.

Reimplemented from ThreadBase.

Definition at line 530 of file tuner.cpp.

qint64 Tuner::getNow ( )
private

Private function: Get current elapsed tuner runtime in milliseconds.

Returns
Time elapsed since thread intitialization in milliseconds

Definition at line 441 of file tuner.cpp.

QString ThreadBase::getThreadName ( ) const
inherited

Get thread name.

Definition at line 132 of file threadbase.cpp.

Here is the call graph for this function:

int ThreadBase::getVerbosity ( )
inlineinherited

Get verbosity level.

Definition at line 80 of file threadbase.h.

Here is the call graph for this function:

void Tuner::handlePitchDrift ( )
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

Definition at line 620 of file tuner.cpp.

bool Tuner::init ( )
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.

Here is the call graph for this function:

void Tuner::initiallyCalledWorker ( )
finaloverrideprivatevirtual

Initialization of the starting thread.

Reimplemented from ThreadBase.

Definition at line 516 of file tuner.cpp.

Here is the call graph for this function:

bool ThreadBase::isActive ( ) const
inherited

Return true if thread is running and not suspended.

Definition at line 136 of file threadbase.cpp.

bool ThreadBase::isInterruptionRequested ( ) const
protectedinherited

Return true if the thread was requested to interrupt or terminate.

Definition at line 128 of file threadbase.cpp.

void Tuner::periodicallyCalledWorker ( )
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.

Here is the call graph for this function:

void Tuner::receiveMidiEvent ( QMidiMessage  event)
slot

Public slot: Receive Midi event (Main input of the tuner)

This slot receives and interprets Midi keyboard data in real time.

Note
Call this function exclusively via signal-slot. Otherwise the tuning process would be executed in the calling thread.
Parameters
event: Midi event of the type QMidiMessage (see library QMidi)

Definition at line 271 of file tuner.cpp.

Here is the call graph for this function:

void Tuner::resetPitchProgression ( )
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.

Here is the call graph for this function:

void ThreadBase::resume ( )
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.

void Tuner::setDelayParameter ( double  delay)
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.

Definition at line 226 of file tuner.cpp.

void Tuner::setEnvelopeParameters ( double  secondsBass,
double  secondsTreble,
double  secondsRelease 
)
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.

Parameters
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.

Definition at line 490 of file tuner.cpp.

void Tuner::setFrequencyOfA4 ( double  f = 440)
slot

Public slot: Set the desired target frequency of A4 (concert pitch)

Parameters
f: Frequency in Hz (standard value is 440 Hz)

Definition at line 110 of file tuner.cpp.

void Tuner::setIntervalSize ( int  semitones,
double  cents 
)
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.

Parameters
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).

Definition at line 339 of file tuner.cpp.

void Tuner::setIntervalWeight ( int  semitones,
double  weight 
)
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.

Parameters
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

Definition at line 369 of file tuner.cpp.

void Tuner::setMemoryLength ( double  seconds)
slot

Public slot: Set memory parameter.

Parameters
seconds: Memory duration in seconds

Definition at line 247 of file tuner.cpp.

void Tuner::setPitchProgressionCompensationParameter ( double  lambda)
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).

Parameters
lambda: parameter in the range from 0 (no correction) to 1 (instant correction)

Definition at line 201 of file tuner.cpp.

void ThreadBase::setPriority ( const QThread::Priority  p)
protectedinherited

Set thread priority.

Definition at line 109 of file threadbase.cpp.

Here is the call graph for this function:

void Tuner::setStaticTuningMode ( bool  enable,
int  reference = 0 
)
slot

Slot: Enable or disable static tuning mode.

Parameters
enable: True if static tuning mode is enabled, false otherwise
reference: Integer index (Midi) of the reference key (C=0)

Definition at line 457 of file tuner.cpp.

void ThreadBase::setThreadName ( const QString  name)
protectedinherited

Set thread name (Linux only)

Definition at line 121 of file threadbase.cpp.

Here is the call graph for this function:

void ThreadBase::setTimerInterval ( const int  msec,
const int  firstMsec = 0 
)
protectedinherited

Set timer interval for the periodically called worker.

Definition at line 117 of file threadbase.cpp.

Here is the call graph for this function:

void Tuner::setTuningMode ( int  mode,
int  wolfsShift 
)
slot

Public slot: Set tuning mode.

Parameters
mode: Tuning mode (see TuningMode enum)
wolfsShiftIndex shift determining the location of wolfs interval

Definition at line 134 of file tuner.cpp.

void ThreadBase::setVerbosity ( int  verbosity)
inherited

Set verbosity level of messages.

Definition at line 113 of file threadbase.cpp.

Here is the call graph for this function:

void Tuner::signalAveragePitchDrift ( double  progression)
signal

Signal that periodically transmits the average pitch progression. In the GUI this progression is indicated by a circular gauge.

void Tuner::signalIntervalString ( QVariant  str)
signal

Signal emitting the tuned interval sizes in a human-readable form.

void Tuner::signalReadyForReceivingParameters ( )
signal

Signal telling the GUI that the tuner is ready and that the GUI may send the user-defined parameters to the tuner.

void Tuner::signalTension ( QVariant  mu)
signal

Signal emitting the network tension in the tuned chord, indicating the deviation from just intonation.

void Tuner::signalTuningCorrections ( QMap< int, double >  corrections)
signal

Signal sending the tuning results to the microtonal sound device in the form of a map keyindex -> cents for all active keys.

bool Tuner::start ( )
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

Returns
True on success

Reimplemented from ThreadBase.

Definition at line 94 of file tuner.cpp.

Here is the call graph for this function:

bool ThreadBase::stop ( )
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.

Returns
If the thread terminates regularly return true. If the thread does not terminate after a timeout of 2 secs return false.

Reimplemented in MidiPlayer, AudioOutput, and Instrument.

Definition at line 152 of file threadbase.cpp.

Here is the call graph for this function:

void ThreadBase::suspend ( )
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.

void Tuner::tune ( )
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.

Here is the call graph for this function:

Friends And Related Function Documentation

friend class TunerAlgorithm
friend

Definition at line 135 of file tuner.h.

Member Data Documentation

const double Tuner::cutoffIntensity = 0.001
private

Definition at line 110 of file tuner.h.

const double Tuner::cutoffMemory = 0.0001
private

Definition at line 111 of file tuner.h.

double Tuner::mDelayParameter
private

Delay time.

Definition at line 130 of file tuner.h.

const double Tuner::memoryOnFactor = exp(-0.005*updateIntervalMsec/memoryOnSeconds)
private

Definition at line 113 of file tuner.h.

const double Tuner::memoryOnSeconds = 0.3
private

Definition at line 112 of file tuner.h.

double Tuner::mGlobalTargetPitchInCents
private

Global pitch against 440Hz.

Definition at line 118 of file tuner.h.

QVector<double> Tuner::mIntervalSizes
private

List of 12 interval sizes.

Definition at line 124 of file tuner.h.

QVector<double> Tuner::mIntervalWeights
private

List of 12 interval weights.

Definition at line 125 of file tuner.h.

QVector<KeyData> Tuner::mKeyDataVector
private

Vector containing all key data.

Definition at line 126 of file tuner.h.

QString Tuner::mLastMessage
private

remember last message sent

Definition at line 123 of file tuner.h.

double Tuner::mMemoryOffFactor
private

Update factor for memory decay.

Definition at line 131 of file tuner.h.

double Tuner::mPitchAutoCorrectionParameter
private

Pitch correction parameters.

Definition at line 129 of file tuner.h.

int Tuner::mStaticReferenceKey
private

Index of static UT reference key.

Definition at line 120 of file tuner.h.

bool Tuner::mStaticTuningModeEnabled
private

Flag: Tune statically.

Definition at line 128 of file tuner.h.

TunerAlgorithm Tuner::mTunerAlgorithm
private

The tuning algorithm.

Definition at line 117 of file tuner.h.

bool Tuner::mTuningEnabled
private

Flag for temporary on/off.

Definition at line 122 of file tuner.h.

int Tuner::mTuningMode
private

Actual tuning mode.

Definition at line 119 of file tuner.h.

qint8 Tuner::mWaitingTimeMsec
private

Waiting time before tuning event.

Definition at line 132 of file tuner.h.

int Tuner::mWolfsIntervalShift
private

Placement of the wolfs interval.

Definition at line 121 of file tuner.h.

const uint Tuner::noteTimeoutSeconds = 60
private

Definition at line 109 of file tuner.h.

QElapsedTimer* Tuner::pElapsedTimer
private

Time elapsed since construction.

Definition at line 127 of file tuner.h.

const uint Tuner::tuningIntervalMsec = 20
private

Update interval tuning.

Definition at line 105 of file tuner.h.

const uint Tuner::updateIntervalMsec = 20
private

Update interval envelope.

Definition at line 108 of file tuner.h.


The documentation for this class was generated from the following files: