Module:JI ratios: Difference between revisions
m testing with smaller default int limit |
re-add ratio filtering |
||
| Line 40: | Line 40: | ||
-- - 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. | ||
function p.filter_ratios(ratios, equave, tenney_height, complements_only) | |||
--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 filtered_ratios = {} | |||
-- | for i = 1, #ratios do | ||
-- | local complement = rat.mul(rat.inv(ratios[i]), equave) | ||
-- to | local ratio_th = rat.tenney_height(ratios[i]) | ||
local compl_th = rat.tenney_height(complement) | |||
-- Are the ratios within the Tenney height? | |||
local ratio_within_th = ratio_th <= tenney_height | |||
local compl_within_th = compl_th <= tenney_height | |||
if complements_only then | |||
-- Only include ratios if its complement is also included. | |||
if ratio_within_th and compl_within_th then | |||
table.insert(filtered_ratios, ratios[i]) | |||
end | |||
else | |||
-- Include ratios regardless of whether its complement is included. | |||
if ratio_within_th then | |||
table.insert(filtered_ratios, ratios[i]) | table.insert(filtered_ratios, ratios[i]) | ||
end | end | ||
end | end | ||
end | end | ||
return filtered_ratios | return filtered_ratios | ||
end | end | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
| Line 322: | Line 315: | ||
prime_limit = args["Prime Limit"] | prime_limit = args["Prime Limit"] | ||
subgroup = args["Subgroup"] | subgroup = args["Subgroup"] | ||
-- Filtering args | |||
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 331: | Line 328: | ||
ratios = p.search_by_int_limit(equave, int_limit) | ratios = p.search_by_int_limit(equave, int_limit) | ||
end | end | ||
-- Filter ratios | |||
ratios = p.filter_ratios(ratios, equave, tenney_height, complements_only) | |||
return ratios | return ratios | ||
| Line 380: | Line 380: | ||
function p.tester() | function p.tester() | ||
return p.ratios_as_string(p._ji_ratios(p.parse_args("Int Limit: | return p.ratios_as_string(p._ji_ratios(p.parse_args("Int Limit: 16; Equave: 3/1; Complements Only: 0"))) | ||
end | end | ||