Module:Infobox chord: Difference between revisions

Bcmills (talk | contribs)
omit explicit powers of 1 from the genus
ArrowHead294 (talk | contribs)
m Alphabetise dependencies
 
(31 intermediate revisions by 5 users not shown)
Line 1: Line 1:
local p = {}
local p = {}


local consistency = require("Module:Chord consistency")
local infobox = require("Module:Infobox")
local rat = require("Module:Rational")
local rat = require("Module:Rational")
local utils = require("Module:Utils")
local utils = require("Module:Utils")
local infobox = require("Module:Infobox")
local yesno = require("Module:Yesno")


function p.infobox_chord(frame)
function p.infobox_chord(frame)
local debug_mode = utils.value_provided(frame.args["debug"])
local debug_mode = yesno(frame.args["debug"])
 
local page_name = frame:preprocess("{{PAGENAME}}")
local page_name = frame:preprocess("{{PAGENAME}}")
Line 14: Line 15:
local cats = ""
local cats = ""


local name = frame.args["Name"]
local color_names = {}
if utils.value_provided(name) then
if utils.value_provided(frame.args["ColorName"]) then
local caption = "Name"
color_name = frame.args["ColorName"]
if name:match(",") then
-- search for ", " not "," because many chord names contain commas, e.g. Cz,y6
caption = "Names"
for name in (color_name .. ", "):gmatch("(.-), ") do
-- removing manual line breaks
table.insert(color_names, name)
local matches
name, matches = name:gsub("<br/?>", "")
if matches > 0 then
cats = cats .. "[[Category:Todo:remove manual line breaks]]"
end
-- removing whitespaces after commas
name = name:gsub(",%s+", ",")
-- placing line breaks after commas
name = name:gsub(",", ",<br/>")
end
end
table.insert(infobox_data, {
else
caption,
cats = cats .. "[[Category:Todo:add color name]]"
name,
})
end
end


Line 43: Line 33:
table.insert(harmonics, h)
table.insert(harmonics, h)
end
end
-- reduce harmonics to simplest terms, in case the user accidentally failed to reduce them
local gcd = harmonics[1]
for i, h in ipairs(harmonics) do
gcd = utils._gcd(gcd, h)
if gcd == 1 then break end
end
if gcd > 1 then
for i, h in ipairs(harmonics) do
harmonics[i] = harmonics[i] / gcd
end
end
local root = harmonics[1]
local root = harmonics[1]
if utils.value_provided(frame.args["Root"]) then
if utils.value_provided(frame.args["Root"]) then
Line 150: Line 153:
-- genus
-- genus
local genus_terms = {}
local genus_terms = {}
local genus_product = 1
local primes = {}
local primes = {}
for prime, _ in pairs(genus) do
for prime, _ in pairs(genus) do
Line 162: Line 166:
table.insert(genus_terms, prime .. "<sup>" .. exponent .. "</sup>")
table.insert(genus_terms, prime .. "<sup>" .. exponent .. "</sup>")
end
end
genus_product = genus_product * (prime ^ exponent)
end
end
-- consistent edos
local distance = tonumber(frame.args["Distance"])
if distance == nil then
if #harmonics >= 5 then
distance = 1.5
elseif #harmonics >= 3 then
distance = 2.0
else
distance = 3.0
end
end
local consistent_edos = consistency.consistent_edos(harmonics, distance, 'edo', 4)
-- compute tag to add for category sort order: as many "#" as the number of digits in the first harmonic
-- compute tag to add for category sort order: as many "#" as the number of digits in the first harmonic
Line 177: Line 195:
end
end


table.insert(infobox_data, {"Harmonics", frame.args["Harmonics"]})
table.insert(infobox_data, {"Harmonics", table.concat(harmonics, ":")})
if (not utils.value_provided(frame.args["Root"])) and (utonal_odd_limit <= otonal_odd_limit or utonal_odd_limit < 1000) then
if (not utils.value_provided(frame.args["Root"])) and (utonal_odd_limit <= otonal_odd_limit or utonal_odd_limit < 1000) then
table.insert(infobox_data, {"Subharmonics", "1/(" .. table.concat(subharmonics, ":") .. ")"})
table.insert(infobox_data, {"Subharmonics", "1/(" .. table.concat(subharmonics, ":") .. ")"})
Line 185: Line 203:
table.insert(infobox_data, {"Step intervals", table.concat(step_interval_links, ", ")})
table.insert(infobox_data, {"Step intervals", table.concat(step_interval_links, ", ")})
table.insert(infobox_data, {"Step cents", table.concat(step_cents, ", ")})
table.insert(infobox_data, {"Step cents", table.concat(step_cents, ", ")})
-- TODO: category goes here.
if table.getn(color_names) > 0 then
local label = "Color name"
if table.getn(color_names) > 1 then
label = "Color names"
end
table.insert(infobox_data, {"[[Color notation|" .. label .. "]]", table.concat(color_names, "<br />")})
end


if prime_limit < 96 then
if prime_limit < 96 then
Line 193: Line 221:
cats = cats .. "[[Category:Just intonation chords" .. sort_tag .. "]]"
cats = cats .. "[[Category:Just intonation chords" .. sort_tag .. "]]"
end
end
table.insert(infobox_data, {"[[Genus]]", table.concat(genus_terms, "&#x200A;&sdot;&#x200A;")})
 
local genus_data = table.concat(genus_terms, "&#x200A;&sdot;&#x200A;")
-- append the actual product if it's (arbitrarily) 9 digits or fewer
if genus_product < 1000000000 then
genus_data = genus_data .. " (" .. genus_product .. ")"
end
table.insert(infobox_data, {"[[Euler-Fokker genus|Genus]]", genus_data})


if odd_limit < 32 then
if odd_limit < 32 then
Line 199: Line 233:
cats = cats .. "[[Category:" .. odd_limit .. "-odd-limit chords" .. sort_tag .. "]]"
cats = cats .. "[[Category:" .. odd_limit .. "-odd-limit chords" .. sort_tag .. "]]"
else  
else  
table.insert(infobox_data, {"[[Odd limit]]", odd_limit})
table.insert(infobox_data, {"[[Intervallic odd limit]]", odd_limit})
end
end
table.insert(infobox_data, {"[[Otonal odd limit]]", otonal_odd_limit})
table.insert(infobox_data, {"[[Otonal odd limit]]", otonal_odd_limit})
table.insert(infobox_data, {"[[Utonal odd limit]]", utonal_odd_limit})
table.insert(infobox_data, {"[[Utonal odd limit]]", utonal_odd_limit})
if consistent_edos ~= "" then
table.insert(infobox_data, {"[[Consistency|Consistent edos]] (''d'' &ge; " .. distance .. ")", "<span style=\"font-size: 75%;\">" .. consistent_edos .. "</span>"})
table.insert(infobox_data, {"<div style=\"font-size: 75%; text-align: right; white-space: nowrap;\">[[Module:Chord consistency/doc|* 2 &le; ''d'' &lt; 4; ** 4 &le; ''d'' &lt; 8; *** 8 &le; ''d'' &lt; 16; &hellip;]]</div>"})
else
table.insert(infobox_data, {"[[Consistency|Consistent edos]] (''d'' &ge; " .. distance .. ")", "<small>not exist in the range up to 72</small>"})
end
end
end
Line 212: Line 253:
end
end


local s = infobox.build("<u>Chord information</u>", infobox_data)
local result = infobox.build("<u>Chord information</u>", infobox_data)
if not debug_mode then
if not debug_mode then
s = s .. cats
result = result .. cats
end
end
return s
return frame:preprocess(result)
end
end


return p
return p