Module:Infobox chord: Difference between revisions
m Make “intervallic odd limit” label consistent between high- and low-limit chords |
ArrowHead294 (talk | contribs) m Alphabetise dependencies |
||
(20 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 | local yesno = require("Module:Yesno") | ||
function p.infobox_chord(frame) | function p.infobox_chord(frame) | ||
local debug_mode = | 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 | local color_names = {} | ||
if utils.value_provided(frame.args["ColorName"]) then | |||
color_name = frame.args["ColorName"] | |||
-- search for ", " not "," because many chord names contain commas, e.g. Cz,y6 | |||
for name in (color_name .. ", "):gmatch("(.-), ") do | |||
table.insert(color_names, name) | |||
end | end | ||
else | |||
cats = cats .. "[[Category:Todo:add color name]]" | |||
end | end | ||
Line 178: | Line 168: | ||
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 200: | 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 224: | Line 237: | ||
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'' ≥ " .. 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 ≤ ''d'' < 4; ** 4 ≤ ''d'' < 8; *** 8 ≤ ''d'' < 16; …]]</div>"}) | |||
else | |||
table.insert(infobox_data, {"[[Consistency|Consistent edos]] (''d'' ≥ " .. distance .. ")", "<small>not exist in the range up to 72</small>"}) | |||
end | |||
end | end | ||
Line 233: | Line 253: | ||
end | end | ||
local | local result = infobox.build("<u>Chord information</u>", infobox_data) | ||
if not debug_mode then | if not debug_mode then | ||
result = result .. cats | |||
end | end | ||
return | |||
return frame:preprocess(result) | |||
end | end | ||
return p | return p |