Module:JI ratios in ED: Difference between revisions

Ganaram inukshuk (talk | contribs)
No edit summary
Ganaram inukshuk (talk | contribs)
Corrected logic
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, 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 114: Line 112:
-- 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 144: Line 142:
-- 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')
Line 151: Line 149:


-- 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)
Line 166: Line 165:
-- 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 196: Line 195:
-- 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')