Module:JI ratios in ED: Difference between revisions
Jump to navigation
Jump to search
Created page with "local utils = require('Module:Utils') local interval = require('Module:Interval') local rat = require('Module:Rational') local jiraf = require('Module:JI ratio finder') local..." |
Separated parse function into two functions (one for the ed, one for the equave) |
||
| Line 55: | Line 55: | ||
function p.parse_ed(unparsed) | function p.parse_ed(unparsed) | ||
local unparsed = unparsed or " | local unparsed = unparsed or "12ed2/1" | ||
local ed = unparsed:match('(%d+)ed') | local ed = tonumber(unparsed) or unparsed:match('(%d+)ed') | ||
return ed | |||
end | |||
function p.parse_equave(unparsed) | |||
local unparsed = unparsed or "12" | |||
local equave_unparsed = "" | local equave_unparsed = "" | ||
if string.match(unparsed, "edo") then | if string.match(unparsed, "edo") or tonumber(unparsed) ~= nil then | ||
equave_unparsed = "2/1" | equave_unparsed = "2/1" | ||
elseif string.match(unparsed, "edt") then | elseif string.match(unparsed, "edt") then | ||
| Line 69: | Line 75: | ||
equave_unparsed = unparsed:match('[%d]+ed([%d]+/[%d]+)') | equave_unparsed = unparsed:match('[%d]+ed([%d]+/[%d]+)') | ||
end | end | ||
return | return rat.parse(equave_unparsed) | ||
end | end | ||
function p.ji_ratios_in_ed_frame(frame) | function p.ji_ratios_in_ed_frame(frame) | ||
local ed | local ed = tonumber(p.parse_ed(frame.args["EDO"])) or p.parse_ed(frame.args["EDO"]) | ||
local | local equave = p.parse_equave(frame.args["EDO"]) or p.parse_ed(frame.args["EDO"]) | ||
local primes = tip.parse_entries(frame.args["Primes"], ",") or { 3, 5, 7, 11, 13, 17, 19 } | local primes = tip.parse_entries(frame.args["Primes"], ",") or { 3, 5, 7, 11, 13, 17, 19 } | ||
Revision as of 11:45, 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 single_edstep_in_cents = equave_in_cents / ed
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 12edo\n')
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 + single_edstep_in_cents * 0.75, edstep_in_cents + single_edstep_in_cents * 1.25)
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 "12ed2/1"
local ed = tonumber(unparsed) or unparsed:match('(%d+)ed')
return ed
end
function p.parse_equave(unparsed)
local unparsed = unparsed or "12"
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 = tonumber(p.parse_ed(frame.args["EDO"])) or p.parse_ed(frame.args["EDO"])
local equave = p.parse_equave(frame.args["EDO"]) or p.parse_ed(frame.args["EDO"])
local primes = tip.parse_entries(frame.args["Primes"], ",") or { 3, 5, 7, 11, 13, 17, 19 }
local result = p.find_ratios_in_ed_by_primes(ed, primes, 99, equave)
return result
end
return p