Module:Infobox ET: Difference between revisions

Categorize macrotonal tunings to Category: Macrotonal
Fredg999 (talk | contribs)
Make zeta properties display opt-in, but always include zeta categories nonetheless
 
(18 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local p = {}
local p = {}
local utils = require("Module:Utils")
 
local rat = require("Module:Rational")
local limits = require("Module:Limits")
local ET = require("Module:ET")
local ET = require("Module:ET")
local infobox = require("Module:Infobox")
local infobox = require("Module:Infobox")
local limits = require("Module:Limits")
local rat = require("Module:Rational")
local utils = require("Module:Utils")


-- check whether the input is a non-empty string
-- check whether the input is a non-empty string
Line 34: Line 35:
convergement_notice = ""
convergement_notice = ""
local link = rat.as_table(ratio)[2] .. et.suffix
local link = rat.as_table(ratio)[2] .. et.suffix
ratio = " (→[[" .. link .. "|" .. rat.as_ratio(ratio, "\\")
ratio = string.format(" (→ [[%s|%s%s]])",
if not rat.eq(et.equave, 2) then
link,
ratio = ratio .. et.suffix
rat.as_ratio(ratio, "\\"),
end
(rat.eq(et.equave, 2) == false and et.suffix or ""))
ratio = ratio .. "]])"
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 .. "¢)" .. ratio .. convergement_notice
return approx .. "\\" .. tuning .. " (" .. cents .. "{{c}})" .. ratio .. convergement_notice
end
end


Line 54: Line 54:


local tuning = frame.args["tuning"]
local tuning = frame.args["tuning"]
local et = ET.parse(tuning) or ET.parse("12edo")
local et = ET.parse(tuning) or ET.parse(tuning .. "edo") or ET.parse("12edo")


-- category of the main article
-- category of the main article
categories = categories .. "[[Category:" .. tuning .. "| ]]"
categories = categories .. "{{#ifexist: Category:" .. tuning .. "|[[Category:" .. 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
Line 64: Line 64:
.. string.rep("#", string.len(et.size))
.. string.rep("#", string.len(et.size))
.. "]]"
.. "]]"
elseif rat.eq(et.equave, 3) then
categories = categories .. "[[Category:Edts|" .. string.rep("#", string.len(et.size)) .. "]]"
elseif rat.eq(et.equave, rat.new (3, 2)) then
categories = categories .. "[[Category:Edfs|" .. string.rep("#", string.len(et.size)) .. "]]"
else
else
categories = categories .. "[[Category:" .. et.suffix .. "|" .. string.rep("#", string.len(et.size)) .. "]]"
categories = categories .. "[[Category:" .. et.suffix .. "'s|" .. string.rep("#", string.len(et.size)) .. "]]"
end
end


Line 87: Line 91:
local zeta_switch
local zeta_switch
if value_provided(zeta_override) then
if value_provided(zeta_override) then
zeta_switch = not zeta_override:match("^[Nn][Oo]$")
zeta_switch = zeta_override:match("^[Yy][Ee][Ss]$") and ET.is_zeta(et)
else
else
zeta_switch = rat.eq(et.equave, 2) and ET.is_zeta(et)
zeta_switch = false
end
end


Line 136: Line 140:
table.insert(infobox_data, {
table.insert(infobox_data, {
"Step size",
"Step size",
utils._round(step_size, 6) .. "¢" .. note_12edo .. " ",
utils._round(step_size, 6) .. "{{c}}" .. note_12edo .. " ",
})
})


Line 157: Line 161:
table.insert(infobox_data, {
table.insert(infobox_data, {
"Semitones (A1:m2)",
"Semitones (A1:m2)",
A1 .. ":" .. m2 .. " (" .. A1_cents .. "¢ : " .. m2_cents .. "¢)",
A1 .. ":" .. m2 .. " (" .. A1_cents .. "{{c}} : " .. m2_cents .. "{{c}})",
})
})
if is_dual_fifth and et.size > 0 then
if is_dual_fifth and et.size > 0 then
Line 181: Line 185:
end
end


-- consistency and distinct consistency
-- max_limit is used to prevent timeout
local consistency = tonumber(frame.args["Consistency"])
local consistency = tonumber(frame.args["Consistency"])
local max_limit = rat.eq(et.equave, 2) and 43 or 32
if consistency == nil then
if consistency == nil then
consistency = limits.consistency_limit(et, false, 43)
consistency = limits.consistency_limit(et, false, max_limit)
end
end
if consistency == nil then
if consistency == nil then
consistency = "at least 43"
consistency = "at least " .. max_limit
end
end
if consistency ~= nil then
if consistency ~= nil then
Line 196: Line 203:
local distinct_consistency = tonumber(frame.args["Distinct consistency"])
local distinct_consistency = tonumber(frame.args["Distinct consistency"])
if distinct_consistency == nil then
if distinct_consistency == nil then
distinct_consistency = limits.consistency_limit(et, consistency or true, 43)
distinct_consistency = limits.consistency_limit(et, consistency or true, max_limit)
end
end
if distinct_consistency == nil then
if distinct_consistency == nil then
distinct_consistency = "at least 43"
distinct_consistency = "at least " .. max_limit
end
end
if distinct_consistency ~= nil then
if distinct_consistency ~= nil then
Line 209: Line 216:


-- special properties
-- special properties
if ET.is_highly_composite(et) or zeta_switch then
if ET.is_highly_composite(et) or ET.is_zeta(et) then
local text = ""
local text = ""
if ET.is_highly_composite(et) then
if ET.is_highly_composite(et) then
Line 220: Line 227:
end
end
end
end
if zeta_switch then
if ET.is_zeta(et) and rat.eq(et.equave, 2) then
if #text > 0 then
categories = categories
text = text .. "<br>"
.. "[[Category:Zeta record EDOs|"
end
.. string.rep("#", string.len(et.size))
if not value_provided(zeta_override) then
.. "]]"
if zeta_switch then
if #text > 0 then
text = text .. "<br>"
end
text = text .. ET.why_zeta(et)
text = text .. ET.why_zeta(et)
else
text = text .. zeta_override
end
if rat.eq(et.equave, 2) then
categories = categories
.. "[[Category:Zeta record EDOs|"
.. string.rep("#", string.len(et.size))
.. "]]"
end
end
end
if #text >0 then
table.insert(infobox_data, {
"Special properties",
"<div style=\"max-width: 300px;\">" .. text .. "</div>",
})
end
end
table.insert(infobox_data, {
"Special properties",
"<div style=\"max-width: 300px;\">" .. text .. "</div>",
})
end
end


local result = infobox.build("[[" .. et.suffix .. "|" .. tuning .. "]]", infobox_data, prev_one, next_one)
local result = infobox.build("[[" .. et.suffix .. "|" .. tuning .. "]]", infobox_data, prev_one, next_one)
if not value_provided(debug_mode) then
if not value_provided(debug_mode) then
result = result .. categories
result = result .. categories
end
end
return result
return frame:preprocess(result)
end
end


return p
return p