Module:JI ratios in ED: Difference between revisions

Ganaram inukshuk (talk | contribs)
No edit summary
ArrowHead294 (talk | contribs)
mNo edit summary
 
(10 intermediate revisions by 2 users not shown)
Line 1: Line 1:
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 et = require('Module:ET')
local p = {}
local p = {}
local et = require("Module:ET")
--local interval = require('Module:Harmonic entropy')
local jiraf = require("Module:JI ratio finder")
local rat = require("Module:Rational")
local tip = require("Module:Template input parse")
local utils = require("Module:Utils")
local yesno = require("Module:Yesno")


-- Helper function
-- Helper function
Line 41: Line 43:
-- Helper function
-- Helper function
-- Creates the non-header cells in the table
-- Creates the non-header cells in the table
function p.ji_ratio_in_ed_content_cells(steps, equave, candidate_ratios, primes, threshold)
function p.ji_ratio_in_ed_content_cells(steps, equave, candidate_ratios, primes, tolerance)
local steps = steps or 12
local steps = steps or 12
local equave = equave or rat.new(2)
local equave = equave or rat.new(2)
local candidate_ratios = candidate_ratios or { rat.new(1), rat.new(2), rat.new(3, 2), rat.new(4, 3), rat.new (5, 4), rat.new (9, 7)}
local candidate_ratios = candidate_ratios or { rat.new(1), rat.new(2), rat.new(3, 2), rat.new(4, 3), rat.new (5, 4), rat.new (9, 7)}
local primes = primes or { 2, 3, 7 }
local primes = primes or { 2, 3, 7 }
local threshold = threshold or 0.3
local tolerance = tolerance or 20
-- Calculate equave and tolerance
-- Calculate equave
-- Tolerance is +/- 30% of one step, by default; configurable
local equave_in_cents = rat.cents(equave)
local equave_in_cents = rat.cents(equave)
local tolerance = equave_in_cents / steps * threshold
-- Build the rows for each step, showing ratios by limit
-- Build the rows for each step, showing ratios by limit
Line 60: Line 60:
-- Table headers
-- Table headers
local step_in_cents = (step / steps) * rat.cents(equave)
local step_in_cents = (step / steps) * rat.cents(equave)
result = result .. string.format('| %d\n', step)
result = result .. string.format("| %d\n", step)
result = result .. string.format('| %.3f\n', step_in_cents)
result = result .. string.format("| %.3f\n", step_in_cents)
-- If this is the first or last step, only use the unison or equave
-- If this is the first or last step, only use the unison or equave
Line 88: Line 88:
end
end


local ratios_as_text = jiraf.ratios_to_text_with_error(prime_filtered_ratios, step_in_cents, "<br>", true)
local ratios_as_text = jiraf.ratios_to_text(prime_filtered_ratios, "<br>", true)
result = result .. string.format('| %s\n', ratios_as_text)
result = result .. string.format("| %s\n", ratios_as_text)
end
end
result = result .. string.format('|-\n')
result = result .. string.format("|-\n")
end
end
return result
return result
Line 106: Line 106:
-- Get the number of divisions, equave, and et as text (eg edo, edt, etc)
-- Get the number of divisions, equave, and et as text (eg edo, edt, etc)
local steps = input_et['size']
local steps = input_et["size"]
local equave = input_et['equave']
local equave = input_et["equave"]
if tonumber(equave) ~= nil then
if tonumber(equave) ~= nil then
equave = rat.new(equave)
equave = rat.new(equave)
Line 114: Line 114:
-- Calculate equave and tolerance
-- Calculate equave and tolerance
-- Tolerance is +/- 40 cents or 40% of a step, whichever is smaller.
-- Tolerance is a percentage (threshold) of the step size
local equave_in_cents = rat.cents(equave)
local equave_in_cents = rat.cents(equave)
local tolerance = equave_in_cents / steps * threshold
local tolerance = equave_in_cents / steps * threshold
Line 129: Line 129:
-- Build table headers
-- Build table headers
local result = string.format('{| class="wikitable center-all"\n')
local result = "{| class=\"wikitable center-all\"\n"
result = result .. string.format('|+ Intervals of %s (as a %d-limit temperament)\n', et_as_string, prime_limit)
.. "|+ style=\"font-size: 105%;\" | "
result = result .. string.format('|-\n')
.. string.format("Intervals of %s (as a %d-limit temperament)\n", et_as_string, prime_limit)
result = result .. string.format('! rowspan="2" | [[Degree]]\n')
.. "|-\n"
result = result .. string.format('! rowspan="2" | [[Cent]]s\n')
.. "! rowspan=\"2\" | [[Degree]]\n"
result = result .. string.format('! colspan="%d" | Approximated [[JI]] intervals ([[error]] in cents)\n', #primes)
.. "! rowspan=\"2\" | [[Cent]]s\n"
result = result .. string.format('|-\n')
.. string.format("! colspan=\"%d\" | Approximated [[JI]] intervals\n", #primes)
.. "|-\n"
-- Build header cells for each prime limit
-- Build header cells for each prime limit
for i = 1, #primes do
for i = 1, #primes do
result = result .. string.format('! [[%d-limit]]\n', primes[i])
result = result .. string.format("! [[%d-limit]]\n", primes[i])
end
end
result = result .. string.format('|-\n')
result = result .. string.format("|-\n")
-- Add rest of table
-- Add rest of table
result = result .. p.ji_ratio_in_ed_content_cells(steps, equave, candidate_ratios, primes)
result = result .. p.ji_ratio_in_ed_content_cells(steps, equave, candidate_ratios, primes, tolerance)
result = result .. string.format('|}\n')
result = result .. string.format("|}\n")
return result
return result
end
end


-- Main function variant for prime subgroup
-- Main function variant for prime subgroup
function p.ji_ratios_in_ed_by_prime_subgroup(input_et, int_limit, primes, tenney_height)
function p.ji_ratios_in_ed_by_prime_subgroup(input_et, int_limit, primes, tenney_height, threshold)
local input_et = input_et or et.parse("12edo")
local input_et = input_et or et.parse("12edo")
local primes = primes or { 2, 3, 5, 11 }
local primes = primes or { 2, 3, 5, 11 }
local tenney_height = tenney_height or 10
local tenney_height = tenney_height or 10
local int_limit = int_limit or 99
local int_limit = int_limit or 99
local threshold = threshold or 0.3
-- Get the number of divisions, equave, and et as text (eg edo, edt, etc)
-- Get the number of divisions, equave, and et as text (eg edo, edt, etc)
local steps = input_et['size']
local steps = input_et["size"]
local equave = input_et['equave']
local equave = input_et["equave"]
if tonumber(equave) ~= nil then
if tonumber(equave) ~= nil then
equave = rat.new(equave)
equave = rat.new(equave)
Line 166: Line 168:
-- Calculate equave and tolerance
-- Calculate equave and tolerance
-- Tolerance is +/- 40 cents or 40% of a step, whichever is smaller.
-- Tolerance is a percentage (threshold) of the step size
local equave_in_cents = rat.cents(equave)
local equave_in_cents = rat.cents(equave)
local tolerance = math.min(equave_in_cents / steps * 0.4, 40)
local tolerance = equave_in_cents / steps * threshold
-- Calculate candidate ratios
-- Calculate candidate ratios
Line 181: Line 183:
-- Build table headers
-- Build table headers
local result = string.format('{| class="wikitable center-all"\n')
local result = "{| class=\"wikitable center-all\"\n"
result = result .. string.format('|+ Intervals of %s (as a %s subgroup temperament)\n', et_as_string, subgroup_as_text)
.. "|+ style=\"font-size: 105%;\" | "
result = result .. string.format('|-\n')
.. string.format("Intervals of %s (as a %s subgroup temperament)\n", et_as_string, subgroup_as_text)
result = result .. string.format('! rowspan="2" | [[Degree]]\n')
.. "|-\n"
result = result .. string.format('! rowspan="2" | [[Cent]]s\n')
.. "! rowspan=\"2\" | [[Degree]]\n"
result = result .. string.format('! colspan="%d" | Approximated [[JI]] intervals ([[error]] in cents)\n', #primes)
.. "! rowspan=\"2\" | [[Cent]]s\n"
result = result .. string.format('|-\n')
.. string.format("! colspan=\"%d\" | Approximated [[JI]] intervals\n", #primes)
.. "|-\n"
-- Build header cells for each prime limit
-- Build header cells for each prime limit
for i = 1, #primes do
for i = 1, #primes do
result = result .. string.format('! [[%d-limit]]\n', primes[i])
result = result .. string.format("! [[%d-limit]]\n", primes[i])
end
end
result = result .. string.format('|-\n')
result = result .. "|-\n"
-- Add rest of table
-- Add rest of table
result = result .. p.ji_ratio_in_ed_content_cells(steps, equave, candidate_ratios, primes)
result = result .. p.ji_ratio_in_ed_content_cells(steps, equave, candidate_ratios, primes, tolerance)
result = result .. string.format('|}\n')
result = result .. string.format("|}\n")
return result
return result
end
end
Line 204: Line 207:
-- Wrapper function for primary function; to be called by template
-- Wrapper function for primary function; to be called by template
function p.ji_ratios_in_ed_frame(frame)
function p.ji_ratios_in_ed_frame(frame)
-- Parse the ed; if it's just a number, interpret it as an edo
-- Parse the ed; if it's just a number, interpret it as an edo
local input_et_unparsed = frame.args["ED"] or 12
local input_et_unparsed = frame.args["ED"] or 12
Line 219: Line 221:
local temperament_type = "Prime Limit"
local temperament_type = "Prime Limit"
if string.len(frame.args["Subgroup"]) > 0 then  
if string.len(frame.args["Subgroup"]) > 0 then  
primes = tip.parse_numeric_entries(frame.args["Subgroup"], '.') or tip.parse_numeric_entries(frame.args["Subgroup"], ',')
primes = tip.parse_numeric_entries(frame.args["Subgroup"], ".") or tip.parse_numeric_entries(frame.args["Subgroup"], ",")
temperament_type = "Subgroup"
temperament_type = "Subgroup"
end
end
Line 230: Line 232:
end
end
return result
local debugg = yesno(frame.args["debug"])
if debugg == true then
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
end
return frame:preprocess(result)
end
end


return p
return p