Module:Infobox chord: Difference between revisions

TallKite (talk | contribs)
mNo edit summary
There's no whitespaces in use
 
(23 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
caption = "Names"
-- removing manual line breaks
local matches
name, matches = name:gsub("<br%s?/?>", "")
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
table.insert(infobox_data, {
caption,
name,
})
end
local colour_name = frame.args["ColorName"]
if utils.value_provided(colour_name) then
local caption = "[[Color notation|Color name]]"
-- search for ", " not "," because many chord names contain commas, e.g. Cz,y6
-- search for ", " not "," because many chord names contain commas, e.g. Cz,y6
if name:match(", ") then
for name in (color_name .. ", "):gmatch("(.-), ") do
caption = "[[Color notation|Color names]]"
table.insert(color_names, name)
-- removing manual line breaks
local matches
name, matches = name:gsub("<br%s?/?>", "")
if matches > 0 then
cats = cats .. "[[Category:Todo:remove manual line breaks]]"
end
-- replacing commas+whitespaces with line breaks
name = name:gsub(",%s+", "<br />")
end
end
table.insert(infobox_data, {
caption,
colour_name,
})
else
else
cats = cats .. "[[Category:Todo:add color name]]"
cats = cats .. "[[Category:Todo:add color name]]"
Line 126: Line 93:
local denom = root / gcd
local denom = root / gcd
table.insert(root_interval_links, "[[" .. numer .. "/" .. denom .. "]]")
table.insert(root_interval_links, "[[" .. numer .. "/" .. denom .. "]]")
local cents_ln2 = 1731.234


-- compute ratio of this harmonic relative to the previous
-- compute ratio of this harmonic relative to the previous
if i > 1 then
if i > 1 then
local prev = harmonics[i-1]
local prev = harmonics[i - 1]
local step_gcd = utils._gcd(h, prev)
local step_gcd = utils._gcd(h, prev)
local step_numer = h / step_gcd
local step_numer = h / step_gcd
local step_denom = prev / step_gcd
local step_denom = prev / step_gcd
table.insert(step_interval_links, "[[" .. step_numer .. "/" .. step_denom .. "]]")
table.insert(step_interval_links, "[[" .. step_numer .. "/" .. step_denom .. "]]")
table.insert(step_cents, utils._round_dec(cents_ln2 * math.log(step_numer / step_denom)) .. "¢")
table.insert(step_cents, utils._round_dec(1200*utils.log2(step_numer/step_denom)) .. "¢")
end
end
table.insert(root_cents_steps, utils._round_dec(cents_ln2 * math.log(numer / denom)) .. "¢")
table.insert(root_cents_steps, utils._round_dec(1200*utils.log2(numer/denom)) .. "¢")
end
end
Line 201: Line 166:
genus_product = genus_product * (prime ^ exponent)
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 219: Line 197:
table.insert(infobox_data, {"Subharmonics", "1/(" .. table.concat(subharmonics, ":") .. ")"})
table.insert(infobox_data, {"Subharmonics", "1/(" .. table.concat(subharmonics, ":") .. ")"})
end
end
table.insert(infobox_data, {"Intervals from root", table.concat(root_interval_links, "&thinsp;&ndash;&thinsp;")})
table.insert(infobox_data, {"Intervals from root", table.concat(root_interval_links,  
table.insert(infobox_data, {"Cents from root", table.concat(root_cents_steps, "&#x2007;")})
"<span style=\"padding-left: 0.1em; padding-right: 0.1em;\">&ndash;</span>")})
table.insert(infobox_data, {"Cents from root", table.concat(root_cents_steps,  
"<span style=\"padding-left: 0.1em; padding-right: 0.1em;\">&ndash;</span>")})
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 232: Line 222:
end
end


local genus_data = table.concat(genus_terms, "&#x200A;&sdot;&#x200A;")
local genus_data = table.concat(genus_terms,  
"<span style=\"padding-left: 0.1em; padding-right: 0.1em;\">&sdot;</span>")
-- append the actual product if it's (arbitrarily) 9 digits or fewer
-- append the actual product if it's (arbitrarily) 9 digits or fewer
if genus_product < 1000000000 then
if genus_product < 1000000000 then
Line 247: Line 238:
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 256: Line 254:
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