Module:Chord consistency: Difference between revisions
Dummy index (talk | contribs) mark by consistency distance |
Dummy index (talk | contribs) +distance parameter |
||
Line 96: | Line 96: | ||
end | end | ||
return maxe | return maxe | ||
end | |||
function p.consistent_edos(harmonics, distance) | |||
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, 72 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 = 0.5/maxe | |||
local up = (dist >= distance) | |||
local llevel = 0 | |||
while (dist >= 2) do | |||
llevel = llevel + 1 | |||
dist = dist / 2 | |||
end | |||
if up then | |||
table.insert(vals, "[[" .. i .. "edo]]" .. string.rep("*", llevel)) | |||
end | |||
end | |||
end | |||
return table.concat(vals, ", ") | |||
end | end | ||
function p.noinfobox_chord(frame) | function p.noinfobox_chord(frame) | ||
local | local distance = tonumber(frame.args["Distance"]) | ||
local debug_data = "" | local debug_data = "" | ||
local infobox_data = {} | local infobox_data = {} | ||
Line 111: | Line 145: | ||
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 173: | ||
local root_interval_links = {} | local root_interval_links = {} | ||
local step_interval_links = {} | local step_interval_links = {} | ||
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 187: | ||
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 | end | ||
end | end | ||
cat = "(d >= " .. distance .. ") " .. p.consistent_edos(harmonics, distance) | |||
--end | --end | ||
return cat | return cat |