Module:JI ratios in ED: Difference between revisions

Ganaram inukshuk (talk | contribs)
Fixed default params for prime-limit function
Ganaram inukshuk (talk | contribs)
Added threshold; ratios within the threshold (percentage) are included on the table
Line 41: Line 41:
-- 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)
function p.ji_ratio_in_ed_content_cells(steps, equave, candidate_ratios, primes, threshold)
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
-- Calculate equave and tolerance
-- Calculate equave and tolerance
-- Tolerance is +/- 40 cents or 40% of a step, whichever is smaller.
-- 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 = math.min(equave_in_cents / steps * 0.4, 40)
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 97: Line 98:


-- Main function variant for prime limit
-- Main function variant for prime limit
function p.ji_ratios_in_ed_by_prime_limit(input_et, int_limit, prime_limit, tenney_height)
function p.ji_ratios_in_ed_by_prime_limit(input_et, int_limit, prime_limit, tenney_height, threshold)
local input_et = input_et or et.parse("12edo")
local input_et = input_et or et.parse("12edo")
local prime_limit = prime_limit or 7
local prime_limit = prime_limit or 7
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)
Line 114: Line 116:
-- Tolerance is +/- 40 cents or 40% of a step, whichever is smaller.
-- Tolerance is +/- 40 cents or 40% of a step, whichever is smaller.
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 212: Line 214:
local tenney_height = tonumber(frame.args["Tenney Height"]) or 10
local tenney_height = tonumber(frame.args["Tenney Height"]) or 10
local int_limit = tonumber(frame.args["Integer Limit"]) or 99
local int_limit = tonumber(frame.args["Integer Limit"]) or 99
local threshold = tonumber(frame.args["Threshold"]) or 0.3


local primes = tonumber(frame.args["Prime Limit"]) or 5
local primes = tonumber(frame.args["Prime Limit"]) or 5