Safe Haskell | Safe-Inferred |
---|
Tuning theory
- fromLeft :: Either a b -> Maybe a
- fromRight :: Either a b -> Maybe b
- type Approximate_Ratio = Double
- type Cents = Double
- data Tuning = Tuning {
- ratios_or_cents :: Either [Rational] [Cents]
- octave_ratio :: Rational
- divisions :: Tuning -> Int
- ratios :: Tuning -> Maybe [Rational]
- cents :: Tuning -> [Cents]
- cents_i :: Integral i => Tuning -> [i]
- cents_to_ratio :: Floating a => a -> a
- ratio_to_cents :: Floating a => a -> a
- approximate_ratios :: Tuning -> [Approximate_Ratio]
- reconstructed_ratios :: Double -> Tuning -> Maybe [Rational]
- to_cents :: Approximate_Ratio -> Cents
- approximate_ratio :: Rational -> Approximate_Ratio
- to_cents_r :: Rational -> Cents
- reconstructed_ratio :: Double -> Cents -> Rational
- cps_shift_cents :: Floating a => a -> a -> a
- cps_difference_cents :: Floating a => a -> a -> a
- syntonic_comma :: Rational
- pythagorean_comma :: Rational
- mercators_comma :: Rational
- nth_root :: (Floating a, Eq a) => a -> a -> a
- twelve_tone_equal_temperament_comma :: (Floating a, Eq a) => a
- ditone_r :: [Rational]
- ditone :: Tuning
- pythagorean_r :: [Rational]
- pythagorean :: Tuning
- werckmeister_iii_ar :: [Approximate_Ratio]
- werckmeister_iii_c :: [Cents]
- werckmeister_iii :: Tuning
- werckmeister_iv_ar :: [Approximate_Ratio]
- werckmeister_iv_c :: [Cents]
- werckmeister_iv :: Tuning
- werckmeister_v_ar :: [Approximate_Ratio]
- werckmeister_v_c :: [Cents]
- werckmeister_v :: Tuning
- werckmeister_vi_r :: [Rational]
- werckmeister_vi :: Tuning
- pietro_aaron_1523_c :: [Cents]
- pietro_aaron_1523 :: Tuning
- thomas_young_1799_c :: [Cents]
- thomas_young_1799 :: Tuning
- five_limit_tuning_r :: [Rational]
- five_limit_tuning :: Tuning
- equal_temperament_c :: [Cents]
- equal_temperament :: Tuning
- septimal_tritone_just_intonation_r :: [Rational]
- septimal_tritone_just_intonation :: Tuning
- seven_limit_just_intonation_r :: [Rational]
- seven_limit_just_intonation :: Tuning
- kirnberger_iii_ar :: [Approximate_Ratio]
- kirnberger_iii :: Tuning
- vallotti_c :: [Cents]
- vallotti :: Tuning
- mayumi_reinhard_r :: [Rational]
- mayumi_reinhard :: Tuning
- la_monte_young_r :: [Rational]
- la_monte_young :: Tuning
- ben_johnston_r :: [Rational]
- ben_johnston :: Tuning
- lou_harrison_16_r :: [Rational]
- lou_harrison_16 :: Tuning
- partch_43_r :: [Rational]
- partch_43 :: Tuning
- mk_isomorphic_layout :: Integral a => a -> a -> (a, a) -> [[(a, a)]]
- minimal_isomorphic_note_layout :: [[(Int, Int)]]
- rank_two_regular_temperament :: Integral a => a -> a -> [(a, a)] -> [a]
- mk_syntonic_tuning :: Int -> [Cents]
- syntonic_697 :: Tuning
- syntonic_702 :: Tuning
- fold_cps_to_octave_of :: (Ord a, Fractional a) => a -> a -> a
- harmonic_series_cps :: (Num t, Enum t) => t -> [t]
- harmonic_series_cps_n :: (Num a, Enum a) => Int -> a -> [a]
- partial :: (Num a, Enum a) => a -> Int -> a
- fold_ratio_to_octave :: Integral i => Ratio i -> Ratio i
- harmonic_series_cps_derived :: (Ord a, Fractional a, Enum a) => Int -> a -> [a]
- harmonic_series_folded :: Integer -> [Rational]
- harmonic_series_folded_c :: Integer -> [Cents]
- harmonic_series_folded_21 :: Tuning
Either/Maybe
Types
type Approximate_Ratio = DoubleSource
An approximation of a ratio.
A tuning specified Either
as a sequence of exact ratios, or as
a sequence of possibly inexact Cents
.
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]
approximate_ratios :: Tuning -> [Approximate_Ratio]Source
Possibly inexact Approximate_Ratio
s of tuning.
to_cents :: Approximate_Ratio -> CentsSource
Convert from an Approximate_Ratio
to Cents
.
round (to_cents (3/2)) == 702
approximate_ratio :: Rational -> Approximate_RatioSource
Convert from Rational
to Approximate_Ratio
, ie. fromRational
.
reconstructed_ratio :: Double -> Cents -> RationalSource
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/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 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]
vallotti_c :: [Cents]Source
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'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]
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.
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]
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
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]