hmt-0.14: Haskell Music Theory

Safe HaskellSafe-Inferred

Music.Theory.Tuning

Contents

Description

Tuning theory

Synopsis

Either/Maybe

fromLeft :: Either a b -> Maybe aSource

Maybe Left of Either.

fromRight :: Either a b -> Maybe bSource

Maybe Right of Either.

Types

type Approximate_Ratio = DoubleSource

An approximation of a ratio.

type Cents = DoubleSource

A real valued division of a tone into one hundred parts.

data Tuning Source

A tuning specified Either as a sequence of exact ratios, or as a sequence of possibly inexact Cents.

Instances

divisions :: Tuning -> IntSource

Divisions of octave.

 divisions ditone == 12

ratios :: Tuning -> Maybe [Rational]Source

Maybe exact ratios of Tuning.

cents :: Tuning -> [Cents]Source

Possibly inexact Cents of tuning.

cents_to_ratio :: Floating a => a -> aSource

Convert from cents invterval to frequency ratio.

 map cents_to_ratio [0,701.9550008653874,1200] == [1,3/2,2]

ratio_to_cents :: Floating a => a -> aSource

Convert from frequency ratio to cents interval.

 map ratio_to_cents [1,4/3,2] == [0.0,498.04499913461245,1200.0]

reconstructed_ratios :: Double -> Tuning -> Maybe [Rational]Source

Maybe exact ratios reconstructued from possibly inexact Cents of Tuning.

 let r = [1,17/16,9/8,13/11,5/4,4/3,7/5,3/2,11/7,5/3,16/9,15/8]
 in reconstructed_ratios 1e-2 werckmeister_iii == Just r

to_cents :: Approximate_Ratio -> CentsSource

Convert from an Approximate_Ratio to Cents.

 round (to_cents (3/2)) == 702

reconstructed_ratio :: Double -> Cents -> RationalSource

Construct an exact Rational that approximates Cents to within epsilon.

 map (reconstructed_ratio 1e-5) [0,700,1200] == [1,442/295,2]
 to_cents_r (442/295) == 699.9976981706735

cps_shift_cents :: Floating a => a -> a -> aSource

Frequency n cents from f.

 map (cps_shift_cents 440) [-100,100] == map octpc_to_cps [(4,8),(4,10)]

cps_difference_cents :: Floating a => a -> a -> aSource

Interval in cents from p to q, ie. ratio_to_cents of p / q.

 cps_difference_cents 440 (octpc_to_cps (5,2)) == 500
 let abs_dif i j = abs (i - j)
 in cps_difference_cents 440 (fmidi_to_cps 69.1) `abs_dif` 10 < 1e9

Commas

syntonic_comma :: RationalSource

The Syntonic comma.

 syntonic_comma == 81/80

pythagorean_comma :: RationalSource

The Pythagorean comma.

 pythagorean_comma == 3^12 / 2^19

mercators_comma :: RationalSource

Mercators comma.

 mercators_comma == 3^53 / 2^84

nth_root :: (Floating a, Eq a) => a -> a -> aSource

Calculate nth root of x.

 12 `nth_root` 2  == twelve_tone_equal_temperament_comma

twelve_tone_equal_temperament_comma :: (Floating a, Eq a) => aSource

12-tone equal temperament comma (ie. 12th root of 2).

 twelve_tone_equal_temperament_comma == 1.0594630943592953

12-tone tunings

ditone :: TuningSource

Ditone/pythagorean tuning, see http://www.billalves.com/porgitaro/ditonesettuning.html

 cents_i ditone == [0,114,204,294,408,498,612,702,816,906,996,1110]

pythagorean :: TuningSource

Pythagorean tuning.

 cents_i pythagorean == [0,90,204,294,408,498,612,702,792,906,996,1110]

werckmeister_iii :: TuningSource

Werckmeister III, Andreas Werckmeister (1645-1706)

 cents_i werckmeister_iii == [0,90,192,294,390,498,588,696,792,888,996,1092]

werckmeister_iv :: TuningSource

Werckmeister IV, Andreas Werckmeister (1645-1706)

 cents_i werckmeister_iv == [0,82,196,294,392,498,588,694,784,890,1004,1086]

werckmeister_v :: TuningSource

Werckmeister V, Andreas Werckmeister (1645-1706)

 cents_i werckmeister_v == [0,96,204,300,396,504,600,702,792,900,1002,1098]

werckmeister_vi :: TuningSource

Werckmeister VI, Andreas Werckmeister (1645-1706)

 cents_i werckmeister_vi == [0,91,196,298,395,498,595,698,793,893,1000,1097]

pietro_aaron_1523 :: TuningSource

Pietro Aaron (1523) meantone temperament, see http://www.kylegann.com/histune.html

 cents_i pietro_aaron_1523 == [0,76,193,310,386,503,580,697,773,890,1007,1083]

thomas_young_1799 :: TuningSource

Thomas Young (1799) - Well Temperament

 cents_i thomas_young_1799 == [0,94,196,298,392,500,592,698,796,894,1000,1092]

five_limit_tuning :: TuningSource

Five-limit tuning (five limit just intonation).

 cents_i five_limit_tuning == [0,112,204,316,386,498,590,702,814,884,996,1088]

equal_temperament :: TuningSource

Equal temperament.

 cents equal_temperament == [0,100..1100]

la_monte_young :: TuningSource

La Monte Young's "The Well-Tuned Piano", see http://www.kylegann.com/tuning.html.

 cents_i la_monte_young == [0,177,204,240,471,444,675,702,738,969,942,1173]

ben_johnston :: TuningSource

Ben Johnston's "Suite for Microtonal Piano" (1977), see http://www.kylegann.com/tuning.html

 cents_i ben_johnston == [0,105,204,298,386,471,551,702,841,906,969,1088]

lou_harrison_16 :: TuningSource

Lou Harrison 16 tone Just Intonation scale, see http://www.microtonal-synthesis.com/scale_harrison_16.html

 cents_i lou_harrison_16 == [0,112,182,231,267,316,386,498,603,702,814,884,933,969,1018,1088]

partch_43 :: TuningSource

Harry Partch 43 tone scale, see http://www.microtonal-synthesis.com/scale_partch.html

 cents_i partch_43 == [0,22,53,84,112,151,165
                      ,182,204,231,267,294,316
                      ,347,386,418,435
                      ,471,498,520,551,583,617,649
                      ,680,702,729,765,782,814,853,884,906,933
                      ,969,996,1018,1035,1049,1088,1116,1147,1178]

Syntonic tuning

mk_isomorphic_layout :: Integral a => a -> a -> (a, a) -> [[(a, a)]]Source

Construct an isomorphic layout of r rows and c columns with an upper left value of (i,j).

minimal_isomorphic_note_layout :: [[(Int, Int)]]Source

A minimal isomorphic note layout.

 let [i,j,k] = mk_isomorphic_layout 3 5 (3,-4)
 in [i,take 4 j,(2,-4):take 4 k] == minimal_isomorphic_note_layout

rank_two_regular_temperament :: Integral a => a -> a -> [(a, a)] -> [a]Source

Make a rank two regular temperament from a list of (i,j) positions by applying the scalars a and b.

mk_syntonic_tuning :: Int -> [Cents]Source

Syntonic tuning system based on mk_isomorphic_layout of 5 rows and 7 columns starting at (3,-4) and a rank_two_regular_temperament with a of 1200 and indicated b.

syntonic_697 :: TuningSource

mk_syntonic_tuning of 697.

 divisions syntonic_697 == 17
 cents_i syntonic_697 == [0,79,194,273,309,388,467,503,582,697,776,812,891,970,1006,1085,1164]

syntonic_702 :: TuningSource

mk_syntonic_tuning of 702.

 divisions syntonic_702 == 17
 cents_i syntonic_702 == [0,24,114,204,294,318,408,498,522,612,702,792,816,906,996,1020,1110]

Harmonic series

fold_cps_to_octave_of :: (Ord a, Fractional a) => a -> a -> aSource

Raise or lower the frequency q by octaves until it is in the octave starting at p.

 fold_to_octave_of 55 392 == 98

harmonic_series_cps :: (Num t, Enum t) => t -> [t]Source

Harmonic series on n.

harmonic_series_cps_n :: (Num a, Enum a) => Int -> a -> [a]Source

n elements of harmonic_series_cps.

 harmonic_series_cps_n 14 55 == [55,110,165,220,275,330,385,440,495,550,605,660,715,770]

partial :: (Num a, Enum a) => a -> Int -> aSource

nth partial of f1, ie. one indexed.

 map (partial 55) [1,5,3] == [55,275,165]

fold_ratio_to_octave :: Integral i => Ratio i -> Ratio iSource

Fold ratio until within an octave, ie. 1 < n <= 2.

harmonic_series_cps_derived :: (Ord a, Fractional a, Enum a) => Int -> a -> [a]Source

Derivative harmonic series, based on kth partial of f1.

 let {r = [52,103,155,206,258,309,361,412,464,515,567,618,670,721,773]
     ;d = harmonic_series_cps_derived 5 (octpc_to_cps (1,4))}
 in map round (take 15 d) == r

harmonic_series_folded :: Integer -> [Rational]Source

Harmonic series to nth harmonic (folded).

 harmonic_series_folded 17 == [1,17/16,9/8,5/4,11/8,3/2,13/8,7/4,15/8]

harmonic_series_folded_c :: Integer -> [Cents]Source

to_cents_r variant of harmonic_series_folded.

 map round (harmonic_series_folded_c 21) == [0,105,204,298,386,471,551,702,841,969,1088]

harmonic_series_folded_21 :: TuningSource

12-tone tuning of first 21 elements of the harmonic series.

 cents_i harmonic_series_folded_21 == [0,105,204,298,386,471,551,702,841,969,1088]