Module:JI ratios: Difference between revisions

Ganaram inukshuk (talk | contribs)
add todo to write filter-by-cent-range function
Ganaram inukshuk (talk | contribs)
rewrite int-limit search to (hopefully) produce fewer out-of-range ratios
Line 92: Line 92:
local init_ratios = {{1,1}, {1,0}}
local init_ratios = {{1,1}, {1,0}}
local ratios = med.find_mediants_by_int_limit(init_ratios, int_limit)
local ratios = med.find_only_mediants(init_ratios, 2)
for i = 3, int_limit do
-- Remove last ratio to prevent divide-by-zero
ratios = med.find_mediants_by_int_limit(ratios, i)
table.remove(ratios, #ratios)
-- Purge ratios from the beginning.
-- If the first and second ratio are smaller than min_cents, and smaller
-- than max_cents, then remove the first ratio. Keeping the first ratio
-- would add mediants outside the cent range.
local cents_1 = utils.log2(ratios[1][1] / ratios[1][2]) * 1200
local cents_2 = utils.log2(ratios[2][1] / ratios[2][2]) * 1200
if cents_1 < min_cents and cents_2 <= min_cents and cents_1 < max_cents and cents_2 < max_cents then
table.remove(ratios, 1)
end
-- Purge ratios from the end.
-- If the 2nd-last ratio and last ratio are greater than max_cents, and
-- larger than min_cents, then remove the last ratio. Keeping the last
-- ratio would add mediants outside the cent range.
local cents_3 = utils.log2(ratios[#ratios-1][1] / ratios[#ratios-1][2]) * 1200
local cents_4 = utils.log2(ratios[#ratios  ][1] / ratios[#ratios  ][2]) * 1200
if cents_3 > max_cents and cents_4 >= max_cents and cents_3 > min_cents and cents_4 > min_cents then
table.remove(ratios, #ratios)
end
end
-- Convert to ratios that Module:Rational can work with
-- Convert to ratios that Module:Rational can work with
Line 102: Line 122:
end
end
-- Remove ratios that fall outside the cent range.
-- Remove any remaining ratios that fall outside the cent range.
while rat.cents(ratios[1]) < min_cents do
while rat.cents(ratios[1]) < min_cents do
table.remove(ratios, 1)
table.remove(ratios, 1)
Line 410: Line 430:
--return p.ratios_as_string(p._ji_ratios(p.parse_args("Int Limit: 16; Equave: 3/1; Complements Only: 0")))
--return p.ratios_as_string(p._ji_ratios(p.parse_args("Int Limit: 16; Equave: 3/1; Complements Only: 0")))
--return p.ratios_as_string(p.search_by_prime_limit_within_cents(372, 440, 17, 30))
--return p.ratios_as_string(p.search_by_prime_limit_within_cents(372, 440, 17, 30))
return p.ratios_as_string(p.search_by_subgroup_within_cents(300,500, 30, {2,3,7}))
return p.ratios_as_string(p.search_by_int_limit_within_cents(380, 420, 50))
end
end