Module:ED intro: Difference between revisions
m parentheses |
Added back edc (equal divisions of cent value) |
||
| Line 30: | Line 30: | ||
local intro_text = "" | local intro_text = "" | ||
if ed == 1 then | if ed == 1 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]] | 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]] that uses equal steps of 2/1 (one [[octave]]), or exactly/about ''s'' [[¢]]." | ||
else | else | ||
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 represents a [[frequency ratio]] of 2<sup>1/''k''</sup>, or the ''kth'' root of 2." | 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 represents a [[frequency ratio]] of 2<sup>1/''k''</sup>, or the ''kth'' root of 2." | ||
| Line 57: | Line 57: | ||
local intro_text = "" | local intro_text = "" | ||
if ed == 1 then | if ed == 1 then | ||
intro_text = "'''1 equal division of the tritave''', '''perfect twelfth''', or '''3rd harmonic''' (abbreviated '''1edt''' or '''1ed3'''), is | intro_text = "'''1 equal division of the tritave''', '''perfect twelfth''', or '''3rd harmonic''' (abbreviated '''1edt''' or '''1ed3'''), is a [[nonoctave]] [[tuning system]] that uses equal steps of 3/1 (one [[tritave]]), or exactly/about ''s'' [[¢]]." | ||
else | else | ||
intro_text = "'''''k'' equal divisions of the tritave''', '''perfect twelfth''', or '''3rd harmonic''' (abbreviated '''''k''edt''' or '''''k''ed3'''), is | intro_text = "'''''k'' equal divisions of the tritave''', '''perfect twelfth''', or '''3rd harmonic''' (abbreviated '''''k''edt''' or '''''k''ed3'''), is a [[nonoctave]] [[tuning system]] that divides the interval of [[3/1]] into ''k'' [[equal]] parts of exactly/about ''s'' [[¢]] each. Each step represents a [[frequency ratio]] of 3<sup>1/''k''</sup>, or the ''kth'' root of 3." | ||
end | end | ||
| Line 84: | Line 84: | ||
local intro_text = "" | local intro_text = "" | ||
if ed == 1 then | if ed == 1 then | ||
intro_text = "'''1 equal division of the perfect fifth''' (abbreviated '''1edf''' or '''1ed3/2''') is | intro_text = "'''1 equal division of the perfect fifth''' (abbreviated '''1edf''' or '''1ed3/2''') is a [[nonoctave]] [[tuning system]] that uses equal steps of 3/2 (one perfect fifth), or exactly/about ''s'' [[¢]]." | ||
else | else | ||
intro_text = "'''''k'' equal divisions of the perfect fifth''' (abbreviated '''''k''edf''' or '''''k''ed3/2''') is | intro_text = "'''''k'' equal divisions of the perfect fifth''' (abbreviated '''''k''edf''' or '''''k''ed3/2''') is a [[nonoctave]] [[tuning system]] that divides the interval of [[3/2]] into ''k'' [[equal]] parts of exactly/about ''s'' [[¢]] each. Each step represents a [[frequency ratio]] of (3/2)<sup>1/''k''</sup>, or the ''kth'' root of 3/2." | ||
end | end | ||
| Line 112: | Line 112: | ||
local intro_text = "" | local intro_text = "" | ||
if ed == 1 then | if ed == 1 then | ||
intro_text = "'''1 equal division of the hth harmonic''' (abbreviated '''1ed''h''''') is | intro_text = "'''1 equal division of the hth harmonic''' (abbreviated '''1ed''h''''') is a [[nonoctave]] [[tuning system]] that uses equal steps of [[''h''/1]], or exactly/about ''s'' [[¢]]." | ||
else | else | ||
intro_text = "'''''k'' equal divisions of the hth harmonic''' (abbreviated '''''k''ed''h''''') is | intro_text = "'''''k'' equal divisions of the hth harmonic''' (abbreviated '''''k''ed''h''''') is a [[nonoctave]] [[tuning system]] that divides the interval of [[''h''/1]] into ''k'' [[equal]] parts of exactly/about ''s'' [[¢]] each. Each step represents a [[frequency ratio]] of ''h''<sup>1/''k''</sup>, or the ''kth'' root of ''h''." | ||
end | end | ||
| Line 142: | Line 142: | ||
local intro_text = "" | local intro_text = "" | ||
if ed == 1 then | if ed == 1 then | ||
intro_text = "'''1 equal division of ''p/q''''' (abbreviated '''1ed''p/q''''') is | intro_text = "'''1 equal division of ''p/q''''' (abbreviated '''1ed''p/q''''') is a [[nonoctave]] [[tuning system]] that uses equal steps of [[''p/q'']], or exactly/about ''s'' [[¢]]." | ||
else | else | ||
intro_text = "'''''k'' equal divisions of ''p/q''''' (abbreviated '''''k''ed''p/q''''') is | intro_text = "'''''k'' equal divisions of ''p/q''''' (abbreviated '''''k''ed''p/q''''') is a [[nonoctave]] [[tuning system]] that divides the interval of [[''p/q'']] into ''k'' [[equal]] parts of exactly/about ''s'' [[¢]] each. Each step represents a [[frequency ratio]] of (''p/q'')<sup>1/''k''</sup>, or the ''kth'' root of ''p/q''." | ||
end | end | ||
| Line 157: | Line 157: | ||
end | end | ||
function p. | -- Separate function for edc (arbitrary cent value) | ||
function p.edcent_intro(ed, cents) | |||
local ed = ed or 1 | |||
local cents = cents or 97.5 | |||
-- Exactly or about? Round to 3 DPs | |||
local edstep_size = cents / ed | |||
local edstep_size_rounded = utils._round(edstep_size, 3) | |||
local is_exact = edstep_size - edstep_size_rounded == 0 | |||
local ordinal = ord._ordinal(ed) | |||
local intro_text = "" | |||
if ed == 1 then | |||
intro_text = "'''1 equal division of ''c''¢''' (abbreviated '''1ed''c''¢''') is a [[nonoctave]] [[tuning system]] that uses equal steps of ''c'' [[¢]]." | |||
else | |||
intro_text = "'''''k'' equal divisions of ''c''¢''' (abbreviated '''''k''ed''c''¢''') is a [[nonoctave]] [[tuning system]] that divides the interval of ''c''¢ into ''k'' [[equal]] parts of exactly/about ''s'' [[¢]] each." | |||
end | |||
-- Replace certain strings with the intended final versions | |||
intro_text = string.gsub(intro_text, "''k''", ed) | |||
intro_text = string.gsub(intro_text, "exactly/about", (is_exact and "exactly" or "about")) | |||
intro_text = string.gsub(intro_text, "''s''", string.format("%.3f", edstep_size)) | |||
intro_text = string.gsub(intro_text, "''c''", cents) | |||
return intro_text | |||
end | end | ||
| Line 173: | Line 197: | ||
local steps, equave = unparsed:match('^(%d+)[Ee][Dd](.+)$') | local steps, equave = unparsed:match('^(%d+)[Ee][Dd](.+)$') | ||
-- Determine if the ed is for a cent value | |||
local is_cents = string.match(equave, '%d*%.?%d+[Cc¢]$') ~= nil | |||
-- Parse equave | |||
local parsed_equave | local parsed_equave | ||
if equave == "o" or equave == "O" or equave == "2" or equave == "2/1" then | if equave == "o" or equave == "O" or equave == "2" or equave == "2/1" then | ||
| Line 190: | Line 218: | ||
local num, den = equave:match('^(%d+)/(%d+)$') | local num, den = equave:match('^(%d+)/(%d+)$') | ||
parsed_equave = rat.new(tonumber(num), tonumber(den)) | parsed_equave = rat.new(tonumber(num), tonumber(den)) | ||
elseif is_cents then | |||
-- Equave is arbitrary cent value | |||
parsed_equave = tonumber(equave:match('^(%d*%.?%d+)[Cc¢]$')) | |||
else | else | ||
-- Equave is unsupported | -- Equave is unsupported | ||
| Line 195: | Line 226: | ||
end | end | ||
return tonumber(steps), parsed_equave | return tonumber(steps), parsed_equave, is_cents | ||
end | end | ||
-- Primary function | -- Primary function | ||
function p._ed_intro(ed) | function p._ed_intro(ed) | ||
local ed = ed or " | local ed = ed or "12" | ||
local parsed_ed, parsed_equave = p.parse(ed) | local parsed_ed, parsed_equave, is_cent_value = p.parse(ed) | ||
if rat.eq(0, parsed_equave) then | if rat.eq(0, parsed_equave) then | ||
| Line 212: | Line 243: | ||
elseif rat.eq(rat.new(3,2), parsed_equave) then | elseif rat.eq(rat.new(3,2), parsed_equave) then | ||
return p.edf_intro(parsed_ed) | return p.edf_intro(parsed_ed) | ||
elseif rat.is_harmonic(parsed_equave) then | elseif rat.is_harmonic(parsed_equave) and not is_cent_value then | ||
return p.edh_intro(parsed_ed, parsed_equave) | return p.edh_intro(parsed_ed, parsed_equave) | ||
elseif not rat.is_harmonic(parsed_equave) then | elseif not rat.is_harmonic(parsed_equave) then | ||
return p.edr_intro(parsed_ed, parsed_equave) | return p.edr_intro(parsed_ed, parsed_equave) | ||
elseif is_cent_value then | |||
return p.edcent_intro(parsed_ed, parsed_equave) | |||
else | else | ||
return "Invalid input." | return "Invalid input." | ||