Module:JI ratios in ED: Difference between revisions

Ganaram inukshuk (talk | contribs)
m Corrected title
Ganaram inukshuk (talk | contribs)
ed2/1, ed3/1, and ed3/2 -> edo, edt, and edf; added newlines to cells, added tenney height
Line 6: Line 6:
local p = {}
local p = {}


function p.find_ratios_in_ed_by_primes(ed, primes, int_limit, equave)
function p.find_ratios_in_ed_by_primes(ed, primes, int_limit, equave, tenney_height)
local ed = ed or 12
local ed = ed or 12
local primes = primes or { 3, 5, 7, 11, 13, 17, 19 }
local primes = primes or { 3, 5, 7, 11, 13, 17, 19 }
local equave = equave or rat.new(2, 1)
local equave = equave or rat.new(2, 1)
local tenney_height = tenney_height or 10
local equave_in_cents = rat.cents(equave)
local equave_in_cents = rat.cents(equave)
local tolerance = equave_in_cents / ed / 4
local tolerance = equave_in_cents / ed / 3
-- Find candidate ratios; filter later
local candidate_ratios = jiraf.find_candidate_ratios(equave_in_cents, 99)
local candidate_ratios = jiraf.find_candidate_ratios(equave_in_cents, 99)
-- Equave as text
local equave_as_text = rat.as_ratio(equave)
if equave_as_text == "2/1" then
equave_as_text = "edo"
elseif equave_as_text == "3/1" then
equave_as_text = "edt"
elseif equave_as_text == "3/2" then
equave_as_text = "edf"
end
-- Build table headers
-- Build table headers
local result = string.format('{| class="wikitable center-all"\n')
local result = string.format('{| class="wikitable center-all"\n')
result = result .. string.format('|+ Approximated intervals of %ded%s\n', ed, rat.as_ratio(equave))
result = result .. string.format('|+ Approximated intervals of %d%s\n', ed, equave_as_text)
result = result .. string.format('|-\n')
result = result .. string.format('|-\n')
result = result .. string.format('! Degree\n')
result = result .. string.format('! Degree\n')
Line 42: Line 54:
local current_prime = primes[j]
local current_prime = primes[j]
-- Filter ratios by harmonic class
local prime_filtered_ratios = jiraf.filter_ratios_by_harmonic_class(filtered_ratios, current_prime)
local prime_filtered_ratios = jiraf.filter_ratios_by_harmonic_class(filtered_ratios, current_prime)
local ratios_as_text = jiraf.ratios_to_text(prime_filtered_ratios, ", ")
-- Filter ratios by tenney height
prime_filtered_ratios = jiraf.filter_ratios_by_tenney_height(prime_filtered_ratios, tenney_height)
-- Add ratios to cells
local ratios_as_text = jiraf.ratios_to_text(prime_filtered_ratios, "\n")
result = result .. string.format('| %s\n', ratios_as_text)
result = result .. string.format('| %s\n', ratios_as_text)
end
end
Line 63: Line 81:


function p.parse_equave(unparsed)
function p.parse_equave(unparsed)
local unparsed = unparsed or "7"
local unparsed = unparsed or "10ed4"
local equave_unparsed = ""
local equave_unparsed = ""
Line 73: Line 91:
equave_unparsed = "3/2"
equave_unparsed = "3/2"
else
else
equave_unparsed = unparsed:match('[%d]+ed([%d]+/[%d]+)')
equave_unparsed = unparsed:match('[%d]+ed([%d]+/[%d]+)') or unparsed:match('[%d]+ed([%d]+)')
end
end
Line 88: Line 106:
primes = tip.parse_numeric_entries(frame.args["Primes"], ',')
primes = tip.parse_numeric_entries(frame.args["Primes"], ',')
end
end
local tenney_height = tonumber(frame.args["Tenney Height"]) or 10
local result = p.find_ratios_in_ed_by_primes(ed, primes, 99, equave)
local result = p.find_ratios_in_ed_by_primes(ed, primes, 99, equave, tenney_height)
return result
return result