Module:JI ratios in ED: Difference between revisions
Jump to navigation
Jump to search
m Added 2-limit column as part of default columns |
m Corrected title |
||
| Line 18: | Line 18: | ||
-- 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 | result = result .. string.format('|+ Approximated intervals of %ded%s\n', ed, rat.as_ratio(equave)) | ||
result = result .. string.format('|-\n') | result = result .. string.format('|-\n') | ||
result = result .. string.format('! Degree\n') | result = result .. string.format('! Degree\n') | ||
Revision as of 12:37, 21 January 2024
- This module should not be invoked directly; use its corresponding template instead: Template:JI ratios in ED.
| Module:JI ratios in ED is deprecated and has no replacement. Further use of this module is not advised. This module is kept for historical purposes and should not be deleted. |
| Introspection summary for Module:JI ratios in ED | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||||||||||||||||||||||||||
No function descriptions were provided. The Lua code may have further information.
local utils = require('Module:Utils')
local interval = require('Module:Interval')
local rat = require('Module:Rational')
local jiraf = require('Module:JI ratio finder')
local tip = require('Module:Template input parse')
local p = {}
function p.find_ratios_in_ed_by_primes(ed, primes, int_limit, equave)
local ed = ed or 12
local primes = primes or { 3, 5, 7, 11, 13, 17, 19 }
local equave = equave or rat.new(2, 1)
local equave_in_cents = rat.cents(equave)
local tolerance = equave_in_cents / ed / 4
local candidate_ratios = jiraf.find_candidate_ratios(equave_in_cents, 99)
-- Build table headers
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('|-\n')
result = result .. string.format('! Degree\n')
result = result .. string.format('! Cents\n')
-- Add table headers for prime limits (technically harmonic classes)
for i = 1, #primes do
local current_prime = primes[i]
result = result .. string.format('! %d-limit ratios\n', current_prime)
end
result = result .. string.format('|-\n')
-- Build the rows for each edstep, showing ratios by limit
for i = 1, ed + 1 do
local edstep = i - 1
local edstep_in_cents = edstep * equave_in_cents / ed
local filtered_ratios = jiraf.filter_ratios_by_range(candidate_ratios, edstep_in_cents - tolerance, edstep_in_cents + tolerance)
result = result .. string.format('| %d\n', edstep)
result = result .. string.format('| %.3f\n', edstep_in_cents)
for j = 1, #primes do
local current_prime = primes[j]
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, ", ")
result = result .. string.format('| %s\n', ratios_as_text)
end
result = result .. string.format('|-\n')
end
result = result .. string.format('|}\n')
return result
end
function p.parse_ed(unparsed)
local unparsed = unparsed or "12edo"
local ed = tonumber(unparsed) or unparsed:match('(%d+)ed')
return ed
end
function p.parse_equave(unparsed)
local unparsed = unparsed or "7"
local equave_unparsed = ""
if string.match(unparsed, "edo") or tonumber(unparsed) ~= nil then
equave_unparsed = "2/1"
elseif string.match(unparsed, "edt") then
equave_unparsed = "3/1"
elseif string.match(unparsed, "edf") then
equave_unparsed = "3/2"
else
equave_unparsed = unparsed:match('[%d]+ed([%d]+/[%d]+)')
end
return rat.parse(equave_unparsed)
end
function p.ji_ratios_in_ed_frame(frame)
local ed = p.parse_ed(frame.args["ED"])
local equave = p.parse_equave(frame.args["ED"])
local primes = { 2, 3, 5, 7, 11, 13 }
if string.len(frame.args["Primes"]) > 0 then
primes = tip.parse_numeric_entries(frame.args["Primes"], ',')
end
local result = p.find_ratios_in_ed_by_primes(ed, primes, 99, equave)
return result
end
return p