Module:JI ratios: Difference between revisions

Ganaram inukshuk (talk | contribs)
Bugfix to reflect changes to mediants module
Ganaram inukshuk (talk | contribs)
Bugfix based on recent changes to mediants module
Line 37: Line 37:
local INT_LIMIT_MAX = 200
local INT_LIMIT_MAX = 200
local DEFAULT_INT_LIMIT = 50
local DEFAULT_INT_LIMIT = 50
--------------------------------------------------------------------------------
----------------------- MEDIANT SEARCH FILTER FUNCTIONS ------------------------
--------------------------------------------------------------------------------
-- Mediants module is used to find JI ratios, so this section is for filter
-- functions.
-- A filter function has three params: mediant, depth, and a set of args, which
-- can be a single value or a table of values.
-- Int limit filter determines whether a ratio is within an int limit. Does not
-- use depth.
function p.int_limit_filter(mediant_data, int_limit)
local mediant = mediant_data["mediant"]
return math.max(mediant[1], mediant[2]) <= int_limit
end
-- Tenney height filter determines whether a ratio is within a target Tenney
-- height. Does not use depth.
function p.tenney_height_filter(mediant, depth, tenney_height)
local mediant = mediant_data["mediant"]
return math.log(mediant[1] * mediant[2]) / math.log(2) <= tenney_height
end


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Line 76: Line 52:
local init_ratios = {{1,1}, {2,1}}
local init_ratios = {{1,1}, {2,1}}
local filter_func = p.int_limit_filter
local func = m.int_limit_search
local filter_args = integer_limit
local args = integer_limit
local ratios = m.find_mediants_by_filter(init_ratios, filter_func, filter_args)
local ratios = m.find_mediants_by_search_func(init_ratios, func, args)
-- If the max cents is greater than the octave, duplicate all existing
-- If the max cents is greater than the octave, duplicate all existing