Module:ED intro: Difference between revisions

Ganaram inukshuk (talk | contribs)
m Updated todo
Address Template talk: ED intro #Square/cube root of 2. Now square/cube root are displayed instead of 2nd/3rd root
 
(21 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local ord = require('Module:Ordinal')
local ord = require("Module:Ordinal")
local utils = require('Module:Utils')
local rat = require("Module:Rational")
local rat = require('Module:Rational')
local utils = require("Module:Utils")
local yesno = require("Module:Yesno")
local p = {}
local p = {}


Line 37: Line 38:
local edstep_size_rounded = utils._round(edstep_size, 3)
local edstep_size_rounded = utils._round(edstep_size, 3)
local is_exact = edstep_size - edstep_size_rounded == 0
local is_exact = edstep_size - edstep_size_rounded == 0
local ordinal = ord._ordinal(ed)
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]] that uses [[equal]] steps of 2/1 (one [[octave]]), or exactly/about ''s'' [[¢]]."
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''{{cent}}."
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''{{cent}} each. Each step represents a [[frequency ratio]] of 2<sup>1/''k''</sup>, or the ''kth'' root of 2."
end
end


Line 51: Line 50:
intro_text = string.gsub(intro_text, "exactly/about", (is_exact and "exactly" or "about"))
intro_text = string.gsub(intro_text, "exactly/about", (is_exact and "exactly" or "about"))
intro_text = string.gsub(intro_text, "''s''", utils._round (edstep_size, 3))
intro_text = string.gsub(intro_text, "''s''", utils._round (edstep_size, 3))
intro_text = string.gsub(intro_text, "''kth''", ord._ordinal(ed))
intro_text = string.gsub(intro_text, "''kth''", p.root_ordinal(ed))
return intro_text
return intro_text
Line 65: Line 64:
local edstep_size_rounded = utils._round(edstep_size, 3)
local edstep_size_rounded = utils._round(edstep_size, 3)
local is_exact = edstep_size - edstep_size_rounded == 0
local is_exact = edstep_size - edstep_size_rounded == 0
local ordinal = ord._ordinal(ed)
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 a [[nonoctave]] [[tuning system]] that uses [[equal]] steps of [[3/1]] (one tritave), or exactly/about ''s'' [[¢]]."
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''{{cent}}."
else
else
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."
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''{{cent}} each. Each step represents a [[frequency ratio]] of 3<sup>1/''k''</sup>, or the ''kth'' root of 3."
end
end


Line 79: Line 76:
intro_text = string.gsub(intro_text, "exactly/about", (is_exact and "exactly" or "about"))
intro_text = string.gsub(intro_text, "exactly/about", (is_exact and "exactly" or "about"))
intro_text = string.gsub(intro_text, "''s''", utils._round (edstep_size, 3))
intro_text = string.gsub(intro_text, "''s''", utils._round (edstep_size, 3))
intro_text = string.gsub(intro_text, "''kth''", ord._ordinal(ed))
intro_text = string.gsub(intro_text, "''kth''", p.root_ordinal(ed))
return intro_text
return intro_text
Line 93: Line 90:
local edstep_size_rounded = utils._round(edstep_size, 3)
local edstep_size_rounded = utils._round(edstep_size, 3)
local is_exact = edstep_size - edstep_size_rounded == 0
local is_exact = edstep_size - edstep_size_rounded == 0
local ordinal = ord._ordinal(ed)
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 a [[nonoctave]] [[tuning system]] that uses [[equal]] steps of [[3/2]] (one perfect fifth), or exactly/about ''s'' [[¢]]."
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''{{cent}}."
else
else
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."
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''{{cent}} each. Each step represents a [[frequency ratio]] of (3/2)<sup>1/''k''</sup>, or the ''kth'' root of 3/2."
end
end


Line 107: Line 102:
intro_text = string.gsub(intro_text, "exactly/about", (is_exact and "exactly" or "about"))
intro_text = string.gsub(intro_text, "exactly/about", (is_exact and "exactly" or "about"))
intro_text = string.gsub(intro_text, "''s''", utils._round (edstep_size, 3))
intro_text = string.gsub(intro_text, "''s''", utils._round (edstep_size, 3))
intro_text = string.gsub(intro_text, "''kth''", ord._ordinal(ed))
intro_text = string.gsub(intro_text, "''kth''", p.root_ordinal(ed))
return intro_text
return intro_text
Line 122: Line 117:
local edstep_size_rounded = utils._round(edstep_size, 3)
local edstep_size_rounded = utils._round(edstep_size, 3)
local is_exact = edstep_size - edstep_size_rounded == 0
local is_exact = edstep_size - edstep_size_rounded == 0
local ordinal = ord._ordinal(ed)
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 a [[nonoctave]] [[tuning system]] that uses [[equal]] steps of [[''h''/1]], or exactly/about ''s'' [[¢]]."
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''{{cent}}."
else
else
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''."
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''{{cent}} each. Each step represents a [[frequency ratio]] of ''h''<sup>1/''k''</sup>, or the ''kth'' root of ''h''."
end
end


Line 136: Line 129:
intro_text = string.gsub(intro_text, "exactly/about", (is_exact and "exactly" or "about"))
intro_text = string.gsub(intro_text, "exactly/about", (is_exact and "exactly" or "about"))
intro_text = string.gsub(intro_text, "''s''", utils._round (edstep_size, 3))
intro_text = string.gsub(intro_text, "''s''", utils._round (edstep_size, 3))
intro_text = string.gsub(intro_text, "''kth''", ord._ordinal(ed))
intro_text = string.gsub(intro_text, "''kth''", p.root_ordinal(ed))
intro_text = string.gsub(intro_text, "hth", ord._ordinal(harmonic))
intro_text = string.gsub(intro_text, "hth", ord._ordinal(harmonic))
intro_text = string.gsub(intro_text, "''h''", harmonic)
intro_text = string.gsub(intro_text, "''h''", harmonic)
Line 153: Line 146:
local edstep_size_rounded = utils._round(edstep_size, 3)
local edstep_size_rounded = utils._round(edstep_size, 3)
local is_exact = edstep_size - edstep_size_rounded == 0
local is_exact = edstep_size - edstep_size_rounded == 0
local ordinal = ord._ordinal(ed)
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 a [[nonoctave]] [[tuning system]] that uses [[equal]] steps of [[''p/q'']], or exactly/about ''s'' [[¢]]."
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''{{cent}}."
else
else
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''."
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''{{cent}} each. Each step represents a [[frequency ratio]] of (''p/q'')<sup>1/''k''</sup>, or the ''kth'' root of ''p/q''."
end
end


Line 167: Line 158:
intro_text = string.gsub(intro_text, "exactly/about", (is_exact and "exactly" or "about"))
intro_text = string.gsub(intro_text, "exactly/about", (is_exact and "exactly" or "about"))
intro_text = string.gsub(intro_text, "''s''", utils._round (edstep_size, 3))
intro_text = string.gsub(intro_text, "''s''", utils._round (edstep_size, 3))
intro_text = string.gsub(intro_text, "''kth''", ord._ordinal(ed))
intro_text = string.gsub(intro_text, "''kth''", p.root_ordinal(ed))
intro_text = string.gsub(intro_text, "''p/q''", rat.as_ratio(ratio))
intro_text = string.gsub(intro_text, "''p/q''", rat.as_ratio(ratio))
Line 182: Line 173:
local edstep_size_rounded = utils._round(edstep_size, 3)
local edstep_size_rounded = utils._round(edstep_size, 3)
local is_exact = edstep_size - edstep_size_rounded == 0
local is_exact = edstep_size - edstep_size_rounded == 0
local ordinal = ord._ordinal(ed)
local intro_text = ""
local intro_text = ""
if ed == 1 then
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'' [[¢]]."
intro_text = "'''1 equal division of ''c''{{c}}''' (abbreviated '''1ed''c''{{c}}''') is a [[nonoctave]] [[tuning system]] that uses [[equal]] steps of ''c''{{cent}}."
else
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."
intro_text = "'''''k'' equal divisions of ''c''{{c}}''' (abbreviated '''''k''ed''c''{{c}}''') is a [[nonoctave]] [[tuning system]] that divides the interval of ''c''{{c}} into ''k'' [[equal]] parts of exactly/about ''s''{{cent}} each."
end
end


Line 199: Line 188:
return intro_text
return intro_text
end
-- ord._ordinal but for roots
function p.root_ordinal(n)
local result = ord._ordinal(n)
if n == 2 then
result = "square"
elseif n == 3 then
result = "cube"
end
return result
end
end


Line 211: Line 211:
-- Parse the step count, the suffix, and the equave
-- Parse the step count, the suffix, and the equave
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
-- Determine if the ed is for a cent value
local is_cents = string.match(equave, '%d*%.?%d+[Cc¢]$') ~= nil
local is_cents = string.match(equave, "%d*%.?%d+[Cc¢]$") ~= nil
-- Parse equave
-- Parse equave
Line 231: Line 231:
parsed_equave = rat.new(3,2)
parsed_equave = rat.new(3,2)
ed_type = ED_TYPE_EDF
ed_type = ED_TYPE_EDF
elseif string.match(equave, '^%d+$') ~= nil then
elseif string.match(equave, "^%d+$") ~= nil then
-- Equave is arbitrary harmonic (not 2/1 or 3/1)
-- Equave is arbitrary harmonic (not 2/1 or 3/1)
parsed_equave = tonumber(equave)
parsed_equave = tonumber(equave)
ed_type = ED_TYPE_EDH
ed_type = ED_TYPE_EDH
elseif string.match(equave, '^%d+/%d+$') ~= nil then
elseif string.match(equave, "^%d+/%d+$") ~= nil then
-- Equave is arbitrary ratio (not 3/2)
-- Equave is arbitrary ratio (not 3/2)
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))
ed_type = ED_TYPE_EDR
ed_type = ED_TYPE_EDR
elseif is_cents then
elseif is_cents then
-- Equave is arbitrary cent value
-- Equave is arbitrary cent value
parsed_equave = tonumber(equave:match('^(%d*%.?%d+)[Cc¢]$'))
parsed_equave = tonumber(equave:match("^(%d*%.?%d+)[Cc¢]$"))
ed_type = ED_TYPE_EDC
ed_type = ED_TYPE_EDC
else
else
Line 298: Line 298:
if ed_type == ED_TYPE_DEFAULT then
if ed_type == ED_TYPE_DEFAULT then
return "Equave type not supported or entered incorrectly."
return "{{error|Error: Equave type not supported or entered incorrectly.}}"
elseif ed_type == ED_TYPE_EDO then
elseif ed_type == ED_TYPE_EDO then
return p.edo_intro(parsed_ed)
return p.edo_intro(parsed_ed)
Line 333: Line 333:
-- Wrapper function; for use with a template
-- Wrapper function; for use with a template
function p.ed_intro(frame)
function p.ed_intro(frame)
local ed = frame.args['ED']
local ed = frame.args["ED"]
local edo = frame.args['EDO'] -- For backwards compatibility with edo intro
local edo = frame.args["EDO"] -- For backwards compatibility with edo intro
 
local debugg = yesno(frame.args["debug"])
if edo ~= nil then
local result = p._ed_intro((edo == nil) and ed or edo)
return p._ed_intro(edo)
else
if debugg == true then
return p._ed_intro(ed)
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
end
end
return frame:preprocess(result)
end
end


return p
return p