Module:Infobox chord: Difference between revisions

ArrowHead294 (talk | contribs)
mNo edit summary
There's no whitespaces in use
 
(8 intermediate revisions by 3 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 consistency = require("Module:Chord consistency")
local infobox = require("Module:Infobox")
local yesno = require("Module:Yesno")
local yesno = require("Module:Yesno")


function p.infobox_chord(frame)
function p.infobox_chord(frame)
local debug_mode = yesno(frame.args["debug"])
local debug_mode = yesno(frame.args["debug"])
local page_name = frame:preprocess("{{PAGENAME}}")
local page_name = frame:preprocess("{{PAGENAME}}")
Line 94: 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 200: 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, " – ")})
table.insert(infobox_data, {"Intervals from root", table.concat(root_interval_links,  
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, {"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, ", ")})
Line 223: 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 254: Line 254:
end
end


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


return p
return p