Module:Chord consistency: Difference between revisions

Dummy index (talk | contribs)
mark by consistency distance
ArrowHead294 (talk | contribs)
mNo edit summary
 
(6 intermediate revisions by one other user not shown)
Line 1: Line 1:
local ET = require('Module:ET')
local rat = require('Module:Rational')
local rat = require('Module:Rational')
local utils = require("Module:Utils")
local utils = require("Module:Utils")
local ET = require('Module:ET')
local p = {}
local p = {}


Line 96: Line 96:
end
end
return maxe
return maxe
end
function p.consistent_edos(harmonics, distance, ed, maxlen)
distance = distance or 1.0
ed = ed or 'edo'
local max_n = 72
maxlen = maxlen or max_n
if max_n < maxlen then max_n = maxlen end
local all_interval = {}
for i, h in ipairs(harmonics) do
-- compute all ratio
for j, g in ipairs(harmonics) do
if j > i then
local a = rat.new(g, h)
all_interval[rat.as_ratio(a)] = a
end
end
end
local vals = {}
for i = 1, max_n do
local et = ET.parse('' .. i .. ed)
local consistent = p.additively_consistent_int(et, all_interval, false, nil)
if consistent then
local maxe = p.max_error(et, all_interval)
if maxe <= 5.0e-11 then
table.insert(vals, "[[" .. i .. ed .. "]]" .. "(just)")
break
end
local dist = 0.5/maxe
local up = (dist >= distance)
local llevel = 0
while (dist >= 2) do
llevel = llevel + 1
dist = dist / 2
end
if up then
if #vals >= maxlen then
table.insert(vals, "&hellip;")
break
end
table.insert(vals, "[[" .. i .. ed .. "]]" .. string.rep("*", llevel))
end
end
end
return table.concat(vals, ", ")
end
end


function p.noinfobox_chord(frame)
function p.noinfobox_chord(frame)
local page_name = frame:preprocess("{{PAGENAME}}")
local distance = tonumber(frame.args["Distance"])
local debug_data = ""
local debug_data = ""
local infobox_data = {}
local infobox_data = {}
Line 111: Line 158:
assert(h > 0, "invalid harmonic")
assert(h > 0, "invalid harmonic")
table.insert(harmonics, h)
table.insert(harmonics, h)
end
if distance == nil then
if #harmonics >= 5 then
distance = 1.5
elseif #harmonics >= 3 then
distance = 2.0
else
distance = 3.0
end
end
end


Line 129: Line 186:
local root_interval_links = {}
local root_interval_links = {}
local step_interval_links = {}
local step_interval_links = {}
local all_interval = {}
for i, h in ipairs(harmonics) do
for i, h in ipairs(harmonics) do
-- compute ratio of this harmonic relative to the root
-- compute ratio of this harmonic relative to the root
Line 144: Line 200:
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 .. "]]")
end
-- compute all ratio
for j, g in ipairs(harmonics) do
if j > i then
local step_gcd = utils._gcd(g, h)
local step_numer = g / step_gcd
local step_denom = h / step_gcd
local a = rat.new(g, h)
all_interval[rat.as_ratio(a)] = a
end
end
end
local vals = {}
for i = 1, 50 do
local et = ET.parse('' .. i .. 'edo')
local consistent = p.additively_consistent_int(et, all_interval, false, previous)
if consistent then
local maxe = p.max_error(et, all_interval)
local dist = math.ceil(0.5/maxe)-1.0
local llevel = 0
while (dist >= 2) do
llevel = llevel + 1
dist = dist / 2
end
table.insert(vals, "[[" .. i .. "edo]]" .. string.rep("*", llevel))
end
end
end
end
cat = "(d >= " .. distance .. ") " .. p.consistent_edos(harmonics, distance, 'edo', 4)
--end
--end
cat = table.concat(vals, ", ")


return cat
return cat