Module:Infobox chord: Difference between revisions

Bcmills (talk | contribs)
mNo edit summary
Bcmills (talk | contribs)
No edit summary
Line 52: Line 52:
local prime_limit = 1
local prime_limit = 1
local lcm = 1
local lcm = 1
local otonal_odd_limit = 1
local root_interval_links = {}
local root_interval_links = {}
for i, h in ipairs(harmonics) do
for i, h in ipairs(harmonics) do
-- compute LCM of all harmonics to use as the denominator in utonal form, if needed
lcm = lcm * h / (utils._gcd(lcm, h))
-- increase otonal odd limit for this harmonic, if needed
local odd = h
while odd > 0 and odd % 2 == 0 do
odd = odd / 2
end
if odd > otonal_odd_limit then
otonal_odd_limit = odd
end
-- increase prime limit for this harmonic, if needed
for prime, n in pairs(utils.prime_factorization_raw(h)) do
for prime, n in pairs(utils.prime_factorization_raw(h)) do
if prime > prime_limit then
if prime > prime_limit then
Line 60: Line 74:
end
end
lcm = lcm * h / (utils._gcd(lcm, h))
-- compute ratio of this harmonic relative to the root
 
local gcd = utils._gcd(h, root)
local gcd = utils._gcd(h, root)
local numer = h / gcd
local numer = h / gcd
Line 68: Line 81:
end
end
local utonal_intervals = nil
local utonal_odd_limit = 1
if not utils.value_provided(frame.args["Root"]) then
local utonal_intervals = {}
utonal_intervals = {}
for i, h in ipairs(harmonics) do
for i, h in ipairs(harmonics) do
local gcd = utils._gcd(lcm, h)
local gcd = utils._gcd(lcm, h)
local numer = h / gcd
local numer = h / gcd
local denom = lcm / gcd
local denom = lcm / gcd
table.insert(utonal_intervals, numer .. "/" .. denom)
table.insert(utonal_intervals, numer .. "/" .. denom)
 
local denom_odd = denom
while denom_odd > 0 and denom_odd % 2 == 0 do
denom_odd = denom_odd / 2
end
if denom_odd > utonal_odd_limit then
utonal_odd_limit = denom_odd
end
end
end
end
Line 93: Line 112:
end
end


while denom % 2 == 0 do
while denom > 0 and denom % 2 == 0 do
denom = denom / 2
denom = denom / 2
end
end
Line 104: Line 123:
table.insert(infobox_data, {"Harmonics", frame.args["Harmonics"]})
table.insert(infobox_data, {"Harmonics", frame.args["Harmonics"]})
table.insert(infobox_data, {"Intervals from root", table.concat(root_interval_links, " ‒ ")})
table.insert(infobox_data, {"Intervals from root", table.concat(root_interval_links, " ‒ ")})
if utonal_intervals ~= nil then
if (not utils.value_provided(frame.args["Root"])) and (utonal_limit < otonal_limit or utonal_limit < 1000) then
table.insert(infobox_data, {"[[Utonal]] Ratios", table.concat(utonal_intervals, " ‒ ")})
table.insert(infobox_data, {"[[Utonal]] Ratios", table.concat(utonal_intervals, " ‒ ")})
end
end
if prime_limit < 96 then
if prime_limit < 96 then
table.insert(infobox_data, {"[[Prime limit]]", "[[" .. prime_limit .. "-limit|" .. prime_limit .. "]]"})
table.insert(infobox_data, {"[[Prime limit]]", "[[" .. prime_limit .. "-limit|" .. prime_limit .. "]]"})
Line 121: Line 141:
table.insert(infobox_data, {"[[Odd limit]]", odd_limit})
table.insert(infobox_data, {"[[Odd limit]]", odd_limit})
end
end
table.insert(infobox_data, "[[Otonal]] odd limit", otonal_limit)
table.insert(infobox_data, "[[Utonal]] odd limit", utonal_limit)
end
end