Module:Infobox ET: Difference between revisions

Move highly composite edos notice to the prime factorization line. Suppress it for 1ed's since it can be confusing otherwise.
ArrowHead294 (talk | contribs)
mNo edit summary
 
(3 intermediate revisions by 2 users not shown)
Line 2: Line 2:


local ET = require("Module:ET")
local ET = require("Module:ET")
local getArgs = require("Module:Arguments").getArgs
local infobox = require("Module:Infobox")
local infobox = require("Module:Infobox")
local limits = require("Module:Limits")
local limits = require("Module:Limits")
local rat = require("Module:Rational")
local rat = require("Module:Rational")
local utils = require("Module:Utils")
local utils = require("Module:Utils")
local yesno = require("Module:Yesno")


-- check whether the input is a non-empty string
-- check whether the input is a non-empty string
Line 36: Line 38:
local link = rat.as_table(ratio)[2] .. et.suffix
local link = rat.as_table(ratio)[2] .. et.suffix
ratio = string.format(" (→ [[%s|%s%s]])",
ratio = string.format(" (→ [[%s|%s%s]])",
link,
link, rat.as_ratio(ratio, "\\"), (rat.eq(et.equave, 2) == false and et.suffix or ""))
rat.as_ratio(ratio, "\\"),
(rat.eq(et.equave, 2) == false and et.suffix or ""))
else
else
ratio = ""
ratio = ""
Line 45: Line 45:
local cents = utils._round(ET.cents(et, approx), 6)
local cents = utils._round(ET.cents(et, approx), 6)


return approx .. "\\" .. tuning .. " (" .. cents .. "{{c}})" .. ratio .. convergement_notice
return string.format("%s\\%s (%s{{c}})%s%s",
approx, tuning, utils._round(ET.cents(et, approx), 6), ratio, convergement_notice)
end
end


function p.infobox_ET(frame)
function p.infobox_ET(frame)
local args = getArgs(frame)
-- debug mode will disable the categories
-- debug mode will disable the categories
local debug_mode = frame.args["debug"]
local debug_mode = yesno(frame.args["debug"] or args["debug"], false)
local categories = ""
local wtext = yesno(frame.args["wtext"] or args["wtext"])


local tuning = frame.args["tuning"]
local tuning = frame.args["tuning"]
Line 57: Line 60:


-- category of the main article
-- category of the main article
categories = categories .. "{{#ifexist: Category:" .. tuning .. "|[[Category:" .. tuning .. "| ]]|}}"
local categories = string.format(" {{#ifexist: Category:%s|[[Category:%s| ]]|}}", tuning, tuning)
-- category of the equal division
-- category of the equal division
if rat.eq(et.equave, 2) then
if rat.eq(et.equave, 2) then
categories = categories
categories = categories
.. "[[Category:Equal divisions of the octave|"
.. string.format(" [[Category:Equal divisions of the octave|%s]]",
.. string.rep("#", string.len(et.size))
string.rep("#", string.len(et.size)))
.. "]]"
elseif rat.eq(et.equave, 3) then
elseif rat.eq(et.equave, 3) then
categories = categories .. "[[Category:Edts|" .. string.rep("#", string.len(et.size)) .. "]]"
categories = categories .. string.format(" [[Category:Edts|%s]]",
string.rep("#", string.len(et.size)))
elseif rat.eq(et.equave, rat.new (3, 2)) then
elseif rat.eq(et.equave, rat.new (3, 2)) then
categories = categories .. "[[Category:Edfs|" .. string.rep("#", string.len(et.size)) .. "]]"
categories = categories .. string.format(" [[Category:Edfs|%s]]",
string.rep("#", string.len(et.size)))
else
else
categories = categories .. "[[Category:" .. et.suffix .. "'s|" .. string.rep("#", string.len(et.size)) .. "]]"
categories = categories .. string.format(" [[Category:%s's|%s]]",
et.suffix, string.rep("#", string.len(et.size)))
end
end


Line 81: Line 86:
if rat.eq(et.equave, 2) then
if rat.eq(et.equave, 2) then
categories = categories  
categories = categories  
.. "[[Category:Prime EDOs|" .. string.rep("#", string.len(et.size)) .. "]]"
.. string.format(" [[Category:Prime EDOs|%s]]",
string.rep("#", string.len(et.size)))
end
end
end
end
Line 88: Line 94:
if rat.eq(et.equave, 2) then
if rat.eq(et.equave, 2) then
categories = categories  
categories = categories  
.. "[[Category:Highly composite EDOs|" .. string.rep("#", string.len(et.size)) .. "]]"
.. string.format(" [[Category:Highly composite EDOs|%s]]",
string.rep("#", string.len(et.size)))
end
end
end
end
Line 111: Line 118:
local prev_one = ""
local prev_one = ""
if et.size >= increment then
if et.size >= increment then
prev_one = "[[" .. (et.size - increment) .. et.suffix .. "|← " .. (et.size - increment) .. et.suffix .. "]]"
prev_one = string.format("[[%s|← %s]]",
(et.size - increment) .. et.suffix, (et.size - increment) .. et.suffix)
end
end
local next_one = "[[" .. (et.size + increment) .. et.suffix .. "|" .. (et.size + increment) .. et.suffix .. " →]]"
local next_one = string.format("[[%s|%s →]]",
(et.size + increment) .. et.suffix, (et.size + increment) .. et.suffix)


-- step size in cents
-- step size in cents
local step_size = ET.cents(et, 1)
local step_size = ET.cents(et, 1)
if step_size > 100 then
if step_size > 100 then
categories = categories .. "[[Category:Macrotonal|" .. string.rep("#", string.len(et.size)) .. "]]"
categories = categories .. string.format(" [[Category:Macrotonal|%s]]",
string.rep("#", string.len(et.size)))
end
end
local note_12edo = ""
local note_12edo = ""
Line 148: Line 158:
table.insert(infobox_data, {
table.insert(infobox_data, {
"Step size",
"Step size",
utils._round(step_size, 6) .. "{{c}}" .. note_12edo .. " ",
string.format("%s{{c}}%s ",
utils._round(step_size, 6), note_12edo)
})
})


Line 169: Line 180:
table.insert(infobox_data, {
table.insert(infobox_data, {
"Semitones (A1:m2)",
"Semitones (A1:m2)",
A1 .. ":" .. m2 .. " (" .. A1_cents .. "{{c}} : " .. m2_cents .. "{{c}})",
string.format("%s:%s (%s{{c}} : %s{{c}})",
A1, m2, A1_cents, m2_cents)
})
})
if is_dual_fifth and et.size > 0 then
if is_dual_fifth and et.size > 0 then
Line 187: Line 199:
})
})
categories = categories
categories = categories
.. "[[Category:Dual-fifth temperaments|"
.. string.format(" [[Category:Dual-fifth temperaments|%s]]",
.. string.rep("#", string.len(et.size))
string.rep("#", string.len(et.size)))
.. "]]"
end
end
end
end
Line 228: Line 239:
if rat.eq(et.equave, 2) then
if rat.eq(et.equave, 2) then
categories = categories
categories = categories
.. "[[Category:Zeta record EDOs|"  
.. string.format(" [[Category:Zeta record EDOs|%s]]",
.. string.rep("#", string.len(et.size))  
string.rep("#", string.len(et.size)))
.. "]]"
if zeta_switch then
if zeta_switch then
text = text .. ET.why_zeta(et)
text = text .. ET.why_zeta(et)
Line 243: Line 253:
end
end


local result = infobox.build("[[" .. et.suffix .. "|" .. tuning .. "]]", infobox_data, prev_one, next_one)
local result = infobox.build(string.format("[[%s|%s]]", et.suffix, tuning), infobox_data, prev_one, next_one)
if not value_provided(debug_mode) then
if not debug_mode then
result = result .. categories
result = result .. categories
end
if wtext then
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
end
end