Module:Mediants: Difference between revisions

Ganaram inukshuk (talk | contribs)
m todo
Ganaram inukshuk (talk | contribs)
Changed filter functions to be two-param, where the first param is a table that has both the mediant and depth; may momentarily break dependent modules
Line 4: Line 4:


-- Module for finding mediants, either by search depth or by search function.
-- Module for finding mediants, either by search depth or by search function.
-- TODO
-- Make two classes of filter functions: one that returns both mediants AND
-- depths, and one that returns only mediants. Filter functions therefore come
-- in two forms: two params (mediant, args) and three params (mediant, depth,
-- args).


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Line 24: Line 18:
-- Int limit filter determines whether a ratio is within an int limit. Does not
-- Int limit filter determines whether a ratio is within an int limit. Does not
-- use depth.
-- use depth.
function p.int_limit_filter(mediant, depth, int_limit)
function p.int_limit_filter(mediant_data, int_limit)
local mediant = mediant_data["mediant"]
return math.max(mediant[1], mediant[2]) <= int_limit
return math.max(mediant[1], mediant[2]) <= int_limit
end
end
Line 30: Line 25:
-- Depth filter determines whether a ratio is within a target depth. Does not
-- Depth filter determines whether a ratio is within a target depth. Does not
-- use the mediant itself.
-- use the mediant itself.
function p.search_depth_filter(mediant, depth, search_depth)
function p.search_depth_filter(mediant_data, search_depth)
local depth = mediant_data["depth"]
return depth <= search_depth
return depth <= search_depth
end
end
Line 36: Line 32:
-- Tenney height filter determines whether a ratio is within a target Tenney
-- Tenney height filter determines whether a ratio is within a target Tenney
-- height. Does not use depth.
-- height. Does not use depth.
function p.tenney_height_filter(mediant, depth, tenney_height)
function p.tenney_height_filter(mediant_data, tenney_height)
local mediant = mediant_data["mediant"]
return math.log(mediant[1] * mediant[2]) / math.log(2) <= tenney_height
return math.log(mediant[1] * mediant[2]) / math.log(2) <= tenney_height
end
end
Line 78: Line 75:
table.insert(new_depths, depth_1)
table.insert(new_depths, depth_1)
if filter_func(mediant, new_depth, filter_args) then
local mediant_data = { ["mediant"] = mediant, ["depth"] = new_depth }
if filter_func(mediant_data, filter_args) then
table.insert(new_ratios, mediant)
table.insert(new_ratios, mediant)
table.insert(new_depths, new_depth)
table.insert(new_depths, new_depth)