Module:ED intro: Difference between revisions
m Added todo |
Changes to function names; added new functions |
||
| Line 4: | Line 4: | ||
local p = {} | local p = {} | ||
-- TODO: | -- TODO: Add support for the following | ||
-- - edc - equal divisions of a non-integer constant or cent value | -- - edc - equal divisions of a non-integer constant or cent value | ||
-- Notes: | -- Notes: | ||
| Line 20: | Line 15: | ||
-- were formerly called equal-step tunings but were reclassified as 1ed. | -- were formerly called equal-step tunings but were reclassified as 1ed. | ||
-- - Equal divisions of irrational constants (such as pi and e) are not very | -- - Equal divisions of irrational constants (such as pi and e) are not very | ||
-- common, but | -- common, but count as equal divisions of arbitrary cent values. | ||
-- Parse ed function | -- Parse ed function | ||
| Line 93: | Line 87: | ||
return { ['cents'] = cents, ['equave'] = equave, ['ratio'] = ratio, ['steps'] = steps, ['suffix'] = suffix, ['type'] = ed_type } | return { ['cents'] = cents, ['equave'] = equave, ['ratio'] = ratio, ['steps'] = steps, ['suffix'] = suffix, ['type'] = ed_type } | ||
end | |||
-- Separate function for edo intro | |||
function p.edo_intro(ed) | |||
local ed = ed or 12 | |||
-- Exactly or about? Round to 3 DPs | |||
local edstep_size = 1200 / 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 = "'''''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]] where adjacent pitches are one interval of 2/1 (one [[octave]]) apart, or exactly/about ''s'' [[¢]]." | |||
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." | |||
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, "''kth''", ord._ordinal(ed)) | |||
return intro_text | |||
end | |||
-- Separate function for edt intro | |||
function p.edt_intro(ed) | |||
local ed = ed or 13 | |||
-- Exactly or about? Round to 3 DPs | |||
local edstep_size = math.log(3) * 1200 / math.log(2) / 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 = "'''''k'' equal divisions of the tritave''', '''perfect twelfth''', or '''3rd harmonic''' (abbreviated '''''k''edt''' or '''''k''ed3'''), is the [[nonoctave]] [[tuning system]] where adjacent pitches are one interval of 3/1 (one [[tritave]]) apart, or exactly/about ''s'' [[¢]]." | |||
else | |||
intro_text = "'''''k'' equal divisions of the tritave''', '''perfect twelfth''', or '''3rd harmonic''' (abbreviated '''''k''edt''' or '''''k''ed3'''), is the [[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 | |||
-- 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, "''kth''", ord._ordinal(ed)) | |||
return intro_text | |||
end | |||
-- Separate function for edf intro | |||
function p.edf_intro(ed) | |||
local ed = ed or 7 | |||
-- Exactly or about? Round to 3 DPs | |||
local edstep_size = math.log(3/2) * 1200 / math.log(2) / 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 = "'''''k'' equal divisions of the perfect fifth''' (abbreviated '''''k''edf''' or '''''k''ed3/2'''), is the [[nonoctave]] [[tuning system]] where adjacent pitches are one interval of 3/2 (one [[tritave]]) apart, or exactly/about ''s'' [[¢]]." | |||
else | |||
intro_text = "'''''k'' equal divisions of the perfect fifth''' (abbreviated '''''k''edf''' or '''''k''ed3/2'''), is the [[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 | |||
-- 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, "''kth''", ord._ordinal(ed)) | |||
return intro_text | |||
end | |||
-- Separate function for edh intro (arbitrary harmonic) | |||
function p.edh_intro(ed, harmonic) | |||
local ed = ed or 12 | |||
local harmonic = harmonic or 4 | |||
-- Exactly or about? Round to 3 DPs | |||
local edstep_size = math.log(harmonic) * 1200 / math.log(2) / 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 = "'''''k'' equal divisions of the hth harmonic''' (abbreviated '''''k''ed''h'''''), is the [[nonoctave]] [[tuning system]] where adjacent pitches are one interval of [[''h''/1]] apart, or exactly/about ''s'' [[¢]]." | |||
else | |||
intro_text = "'''''k'' equal divisions of the hth harmonic''' (abbreviated '''''k''ed''h'''''), is the [[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 | |||
-- 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, "''kth''", ord._ordinal(ed)) | |||
intro_text = string.gsub(intro_text, "hth", ord._ordinal(harmonic)) | |||
intro_text = string.gsub(intro_text, "''h''", harmonic) | |||
return intro_text | |||
end | |||
-- Separate function for edr intro (arbitrary ratio) | |||
function p.edr_intro(ed, ratio) | |||
local ed = ed or 12 | |||
local ratio = ratio or rat.new(9,4) | |||
-- Exactly or about? Round to 3 DPs | |||
local edstep_size = rat.cents(ratio) / 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 = "'''''k'' equal divisions of ''p/q''''' (abbreviated '''''k''ed''p/q''''') is the [[nonoctave]] [[tuning system]] where adjacent pitches are one interval of [[p/q]] apart, or exactly/about ''s'' [[¢]]." | |||
else | |||
intro_text = "'''''k'' equal divisions of ''p/q''''' (abbreviated '''''k''ed''p/q''''') is the [[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 | |||
-- 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, "''kth''", ord._ordinal(ed)) | |||
intro_text = string.gsub(intro_text, "''p/q''", rat.as_ratio(ratio)) | |||
return intro_text | |||
end | |||
function p.edc_intro(ed, cents, constant_symbol) | |||
return "Equal divisions of an arbitrary cent value currently not supported." | |||
end | end | ||
-- Primary function | -- Primary function | ||
function p. | function p._ed_intro(ed) | ||
local ed = ed or "12edo" | local ed = ed or "12edo" | ||
| Line 167: | Line 305: | ||
-- Wrapper function; for use with a template | -- Wrapper function; for use with a template | ||
function p. | function p.ed_intro(frame) | ||
local ed = frame.args['ED'] | local ed = frame.args['ED'] | ||
return p. | return p._ed_intro(ed) | ||
end | end | ||
return p | return p | ||