Module:JI ratios: Difference between revisions

Ganaram inukshuk (talk | contribs)
re-add ratio filtering
Ganaram inukshuk (talk | contribs)
m complement filtering now accounts for int limit
Line 39: Line 39:
-- Filters currently include:
-- Filters currently include:
-- - Removing ratios that exceed a max Tenney height.
-- - Removing ratios that exceed a max Tenney height.
-- - Removing ratios whose complement would exceed a max Tenney height.
-- - Removing ratios whose complement would exceed a max Tenney height or int limit
function p.filter_ratios(ratios, equave, tenney_height, complements_only)
function p.filter_ratios(ratios, equave, int_limit, tenney_height, complements_only)
--local tenney_height    = tenney_height or 1/0 -- Default Tenney height is +infinity
--local tenney_height    = tenney_height or 1/0 -- Default Tenney height is +infinity
--local complements_only = complements_only or false -- Default is to allow ratios, regardless of whether their complement would be excluded
--local complements_only = complements_only or false -- Default is to allow ratios, regardless of whether their complement would be excluded
Line 53: Line 53:
local ratio_within_th = ratio_th <= tenney_height
local ratio_within_th = ratio_th <= tenney_height
local compl_within_th = compl_th <= tenney_height
local compl_within_th = compl_th <= tenney_height
-- Is the ratio's complement within the int limit?
local compl_within_int_limit = rat.is_within_int_limit(complement, int_limit)
if complements_only then
if complements_only then
-- Only include ratios if its complement is also included.
-- Only include ratios if its complement is also included.
if ratio_within_th and compl_within_th then
if ratio_within_th and compl_within_th and compl_within_int_limit then
table.insert(filtered_ratios, ratios[i])
table.insert(filtered_ratios, ratios[i])
end
end
Line 317: Line 320:
-- Filtering args
-- Filtering args
tenney_height    = args["Tenney Height"]    or 1/0 -- Default Tenney height is infinity
complements_only = args["Complements Only"] or false -- Default is to include all ratios
complements_only = args["Complements Only"] or false -- Default is to include all ratios
tenney_height    = args["Tenney Height"]    or 1/0 -- Default Tenney height is infinity
local ratios = {}
local ratios = {}
Line 330: Line 333:
-- Filter ratios
-- Filter ratios
ratios = p.filter_ratios(ratios, equave, tenney_height, complements_only)
ratios = p.filter_ratios(ratios, equave, int_limit, tenney_height, complements_only)
return ratios
return ratios