local ord = require('Module:Ordinal')
local utils = require('Module:Utils')
local p = {}
function p.parse_ed(unparsed)
local unparsed = unparsed or "12edpi"
-- If the unparsed ed is only a numeric value, default to edo
if tonumber(unparsed) ~= nil then
unparsed = unparsed .. "edo"
end
-- Parse
local steps, suffix, equave = unparsed:match('^(%d+)([Ee][Dd](.+))$')
-- If the equave is text, then the equave is:
-- o: octave, 2/1 (2nd harmonic)
-- t: tritave or twelfth, 3/1 (3rd harmonic)
-- f: fifth, 3/2
-- For irrational/transcendental constants:
-- pi or π: 3.141593
-- phi or φ: 1.618034
-- n (typically used for e): 2.718282
if equave == "o" or equave == "O" then
equave = "2"
elseif equave == "t" or equave == "T" then
equave = "3"
elseif equave == "f" or equave == "F" then
equave = "3/2"
elseif equave == "pi" or equave == "π" then
equave = "" .. math.pi
elseif equave == "phi" or equave == "φ" then
equave = "1.6180339887499"
elseif equave == "n" or equave == "N" then
equave = "" .. math.exp(1)
end
return { ['steps'] = steps, ['suffix'] = suffix, ['equave'] = equave }
end
function p.ed_intro(ed)
-- Intro formats for each possible case
-- - Common abbrevs: edo, edt, edf
-- - General harmonic: edh (h-th harmonic)
-- - Arbitrary JI ratio: edp/q
-- - Arbitrary constant: edc
-- - Equal-step tunings: 1edo, 1edt, 1edf, 1edh, 1edp/q, 1edc
local intro_text = ""
if is_est then
if is_edo then
intro_text = "'''1 equal division of the octave''' (abbreviated '''1edo''' or '''1ed2'''), also called '''1-tone equal temperament''' ('''1tet'''), or '''1 equal temperament''' ('''1et''') when viewed under a [[regular temperament]] perspective, is the [[tuning system]] where adjacent pitches are one [[octave]], or exactly/about s [[¢]], from each other.\n"
elseif is_edt then
intro_text = "'''1 equal division of the tritave''' (abbreviated '''1edt''' or '''1ed3''') is the [[non-octave]] [[tuning system]] where adjacent pitches are one tritave ([[3/1]]), or exactly/about s [[¢]], apart from each other.\n"
elseif is_edf then
intro_text = "'''1 equal division of the fifth''' (abbreviated '''1edf''' or '''1ed3/2''') is the [[non-octave]] [[tuning system]] where adjacent pitches are one perfect fifth ([[3/2]]), or exactly/about s [[¢]], apart from each other.\n"
elseif is_harmonic then
intro_text = "'''1 equal division of the ''h''th harmonic''' (abbreviated '''1ed''h''''') is the [[non-octave]] [[tuning system]] where adjacent pitches are one interval of [[''h''/1]], or exactly/about s [[¢]], apart from each other.\n"
elseif is_edpq then
intro_text = "'''1 equal division of ''p''/''q''''' (abbreviated '''1ed''p''/''q''''') is the [[non-octave]] [[tuning system]] where adjacent pitches are one interval of [[''p''/''q'']], or exactly/about s [[¢]], apart from each other.\n"
elseif is_edc then
intro_text = "'''1 equal division of ''c''¢''' (abbreviated '''1ed''c''''') is the [[non-octave]] [[tuning system]] where adjacent pitches are s [[¢]], apart from each other.\n"
end
else
if is_edo then
intro_text = "'''''k'' equal divisions of the octave''' (abbreviated '''''k''edo''' or '''''k''ed2'''), also called '''''k''-tone equal temperament''' ('''''k''tet'''), or '''''k'' equal temperament''' ('''''k''et''') when viewed under a [[regular temperament]] perspective, is the [[tuning system]] that divides the [[octave]] into ''k'' [[equal]] parts of exactly/about s [[¢]] each. Each step of ''k''edo represents a [[frequency ratio]] of 2<sup>1/''k''</sup>, or the ''k''th root of 2.\n"
elseif is_edt then
intro_text = "'''''k'' equal divisions of the tritave''' (abbreviated '''''k''edt''' or '''''k''ed3''') is the [[non-octave]] [[tuning system]] that divides the interval [[3/1]] – also called the [[tritave]] or perfect twelfth – into ''k'' equal parts of exactly/about s [[¢]] each. Each step of ''k''edt represents a [[frequency ratio]] of 3<sup>1/''k''</sup>, or the ''k''th root of 3.\n"
elseif is_edf then
intro_text = "'''''k'' equal divisions of the fifth''' (abbreviated '''''k''edf''' or '''''k''ed3/2''') is the [[non-octave]] [[tuning system]] that divides the interval [[3/2]], or perfect fifth, into ''k'' equal parts of exactly/about s [[¢]] each. Each step of ''k''edf represents a [[frequency ratio]] of (3/2)<sup>1/''k''</sup>, or the ''k''th root of 3/2.\n"
elseif is_harmonic then
intro_text = "'''''k'' equal divisions of the ''h''th harmonic''' (abbreviated '''''k''ed''h''''') is the [[non-octave]] [[tuning system]] that divides the interval [[''h''/1]], or the ''h''th harmonic, into ''k'' equal parts of exactly/about s [[¢]] each. Each step of ''k''ed''h'' represents a [[frequency ratio]] of ''h''<sup>1/''k''</sup>, or the ''k''th root of ''h''.\n"
elseif is_edpq then
intro_text = "'''''k'' equal divisions of ''p''/''q''''' (abbreviated '''''k''ed''p''/''q''''') is the [[non-octave]] [[tuning system]] that divides the interval [[''p''/''q'']] into ''k'' [[equal]] pieces of exactly/about s [[¢]] each. Each step of ''k''ed''p''/''q'' represents the [[frequency ratio]] of (''p''/''q'')<sup>1/''k''</sup>, or the ''k''th root of ''p''/''q''.\n"
elseif is_edc then
intro_text = "'''''k'' equal divisions of ''c''¢''' (abbreviated '''''k''ed''c''c''' or '''''k''ed''c''¢''') is the [[non-octave]] [[tuning system]] that divides interval of r¢ is divided into ''k'' [[equal]] pieces of exactly/about s [[¢]] each. Each step of ''k''ed''c'' represents the [[frequency ratio]] of ''c''<sup>1/''k''</sup>, or the ''k''th root of ''c''.\n"
end
end
end
return p