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

Main Tuning Algorithm. More...

#include <tuneralgorithm.h>

Inheritance diagram for TunerAlgorithm:
Inheritance graph
Collaboration diagram for TunerAlgorithm:
Collaboration graph

Public Member Functions

 TunerAlgorithm ()
 Constructor of the TunerAlgorithm. More...
void setIntervalSize (int halftones, double cents)
void setIntervalWeight (int halftones, double weight)
void tuneStatically (KeyDataVector &keys, const QVector< double > pitches, const int referenceKey, const int wolfsIntervalShift)
 Tune statically in a given unequal temperament (UT) More...
double tuneDynamically (KeyDataVector &keyData, const QVector< double > intervals, const QVector< double > weights, bool optimizedJI)
 Main Tuninig Procedure: Tune dynamically. More...

Private Attributes

Eigen::MatrixXi mSelectedVariant
 Previously used pitch variant. More...
double mProgression
 Actual pitch progression. More...
const double octaveWeightFactor = 0.5
const double memoryWeight = 0.00005
const double epsilon = 1E-10
const QVector< QVector< double > > cJustIntonation
 major seventh 15/8 More...

Detailed Description

Main Tuning Algorithm.

This class contains the main tuning algorithm.

The static tuning function is trivial: It simply copies the given pitches in the argument to the corresponding keys.

The dynamical tuning function can operate in two different modes. If the flag 'optimizedJI' is false, then the algorithm tunes dynamically according to the given list of pitches and weigths in the arguments. If the flag is true, then the list of pitches is ignored and the chord is tuned according to the best possible choice of interval sizes from the list defined at the end of this file (cJustIntonation).

Definition at line 54 of file tuneralgorithm.h.

Constructor & Destructor Documentation

TunerAlgorithm::TunerAlgorithm ( )

Constructor of the TunerAlgorithm.

Definition at line 37 of file tuneralgorithm.cpp.

Member Function Documentation

void TunerAlgorithm::setIntervalSize ( int  halftones,
double  cents 
void TunerAlgorithm::setIntervalWeight ( int  halftones,
double  weight 
double TunerAlgorithm::tuneDynamically ( KeyDataVector keyDataVector,
const QVector< double >  intervals,
const QVector< double >  weights,
bool  optimizedJI 

Main Tuninig Procedure: Tune dynamically.

This function is the essential part of the JustIntonation project. Based on the actual pattern of pressed keys, the current volume of each key and an empircal memory parameter for each key, it calculates the pitches for all pressed keys by solving a linear system of equations. For the solution we use the open-source library 'eigen'. Most of the function deals with setting up the system of linear equations A.C=B. There are three contributions: (i) equations reflecting the targeted interval pitch differences between the pressed keys, (ii) equations expressing the tendency of an already pressed to to keep its own pitch, and (iii) a single equation reflecting the constraint of maintaining a predefined average pitch. The computation results are forwarded to the corresponding signals in the TunerThread.

keyDataVector: Array containing all information about the keyboard keys
intervals: Intervals according to which the tuner tunes
weights: Weights of the intervals in the least-square fit
optimizedJI: true if non-unique interval sizes shall be optimized
: Least square deviation from optimal tune

Definition at line 109 of file tuneralgorithm.cpp.

void TunerAlgorithm::tuneStatically ( KeyDataVector keys,
const QVector< double >  pitches,
const int  referenceKey,
const int  wolfsIntervalShift 

Tune statically in a given unequal temperament (UT)

The tuning module sends deviations to the sampler or MIDI device which are given in cents relative to the ET. Static UT's are defined by a set of time-independent cent deviations which refer to a certain reference keynote. Usually a UT sounds good only in this keynote and its complementary keys. For example, static just intonation based on the keynote C sounds nice in C-Major but unacceptably out of tune in D-Major.

This function copies the given pitch deviations from the table to the actual pitches of the active keys. The pitch deviations are assumed ro repeat on each octave. As static temperaments do not exhibit harmonic progression, the average pitch progression is zero. The location of the wolfs interval can be shifted according to the conventions.

keys: Array of all keys
pitches: 12 pitches defining the static temperament
referenceKey: Root key to which the temperament refers
wolfsIntervalShift: Index from which the circle of fifths starts

Definition at line 70 of file tuneralgorithm.cpp.

Member Data Documentation

const QVector<QVector<double> > TunerAlgorithm::cJustIntonation
Initial value:
{3.9100, -17.5963},
{-3.9100, 17.5963, -31.1741},

major seventh 15/8

Definition at line 84 of file tuneralgorithm.h.

const double TunerAlgorithm::epsilon = 1E-10

Definition at line 79 of file tuneralgorithm.h.

const double TunerAlgorithm::memoryWeight = 0.00005

Definition at line 78 of file tuneralgorithm.h.

double TunerAlgorithm::mProgression

Actual pitch progression.

Definition at line 75 of file tuneralgorithm.h.

Eigen::MatrixXi TunerAlgorithm::mSelectedVariant

Previously used pitch variant.

Definition at line 74 of file tuneralgorithm.h.

const double TunerAlgorithm::octaveWeightFactor = 0.5

Definition at line 77 of file tuneralgorithm.h.

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