Module:JI ratios: Difference between revisions
ArrowHead294 (talk | contribs) mNo edit summary |
todo; add odd-limit search |
||
| Line 7: | Line 7: | ||
local utils = require("Module:Utils") | local utils = require("Module:Utils") | ||
local yesno = require("Module:Yesno") | local yesno = require("Module:Yesno") | ||
-- TODO: Refactor code such that: | |||
-- - For int-limit search, int limit is the first arg, and equave and min/max | |||
-- cents default to 2/1, 0c, and 1200c respectively. | |||
-- (int_limit, equave) | |||
-- (int_limit, min_cents, max_cents) | |||
-- - For odd-limit search, odd limit is the first arg, int limit defaults to | |||
-- twice the odd limit, and equave and min/max cents default to 2/1, 0c, and | |||
-- 1200c respectively. | |||
-- (odd_limit, int_limit, equave) | |||
-- (odd_limit, int_limit, min_cents, max_cents) | |||
-- - For prime-limit search, prime-limit is the first arg, int limit defaults to | |||
-- twice the largest prime, and equave and min/max cents default to 2/1, 0c, | |||
-- and 1200c respectively. | |||
-- (prime_limit, int_limit, equave) | |||
-- (prime_limit, int_limit, min_cents, max_cents) | |||
-- - For subgroup search, subgroup is the first arg, there's no default value | |||
-- for int limit (due to complexity of subgroups), and equave and min/max | |||
-- cents default to 2/1, 0c, and 1200c respectively. | |||
-- (subgroup, int_limit, equave) | |||
-- (subgroup, int_limit, min_cents, max_cents) | |||
-- - Filter ratios function is split into two: | |||
-- - Filter ratios by complement removes ratios from a table if its complement | |||
-- is missing. Complements are octave-complements by default. | |||
-- - Filter ratios by tenney height removes ratios from a table if its tenney | |||
-- height exceeds a passed-in value. | |||
-- TODO: write filter function for cent range | -- TODO: write filter function for cent range | ||
| Line 16: | Line 42: | ||
-- Module searches for ratios that are, at the minimum, up to an equave and are | -- Module searches for ratios that are, at the minimum, up to an equave and are | ||
-- up to some integer limit. Search hierarchy is as follows: | -- up to some integer limit. Search hierarchy is as follows: | ||
-- - Search by subgroup ( | -- - Search by subgroup (subgroup elements may be nonprime or rational) | ||
-- - Then search by prime limit | -- - Then search by prime limit | ||
-- - Then search by odd limit | -- - Then search by odd limit | ||
-- - Then search by int limit | -- - Then search by int limit | ||
| Line 138: | Line 164: | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
-- | -- Convert odd limit into equivalent subgroup. | ||
-- EG, 11-odd-limit becomes 2.3.5.7.9.11 | |||
-- 2 is part of the subgroup by definition. | |||
function p.odd_limit_to_subgroup(odd_limit) | |||
local subgroup = { rat.new(2) } | |||
for i = 3, odd_limit, 2 do | |||
table.insert(subgroup, rat.new(i)) | |||
end | |||
return subgroup | |||
end | |||
function p.search_by_odd_limit(equave, int_limit, odd_limit) | |||
local subgroup = p.odd_limit_to_subgroup(odd_limit) | |||
return p.search_by_subgroup_within_cents(0, rat.cents(equave), int_limit, subgroup) | |||
end | |||
function p.search_by_odd_limit_within_cents(min_cents, max_cents, odd_limit) | |||
local subgroup = p.odd_limit_to_subgroup(odd_limit) | |||
return p.search_by_subgroup_within_cents(min_cents, max_cents, int_limit, subgroup) | |||
end | |||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
| Line 144: | Line 189: | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
-- Convert prime limit into equivalent subgroup. | |||
-- EG, 11-prime-limit becomes 2.3.5.7.11 | |||
function p.prime_limit_to_subgroup(prime_limit) | function p.prime_limit_to_subgroup(prime_limit) | ||
local subgroup = {} | local subgroup = {} | ||
for i = | for i = 3, prime_limit do | ||
local is_prime = true | local is_prime = true | ||
for j = 2, math.floor(math.sqrt(i)) do | for j = 2, math.floor(math.sqrt(i)) do | ||
| Line 255: | Line 302: | ||
return ratios | return ratios | ||
end | end | ||
-------------------------------------------------------------------------------- | |||
------------------------------- HELPER FUNCTIONS ------------------------------- | |||
-------------------------------------------------------------------------------- | |||
-- Heleper function; merges elements from source table with destination table | -- Heleper function; merges elements from source table with destination table | ||
| Line 357: | Line 408: | ||
function p._ji_ratios(args) | function p._ji_ratios(args) | ||
-- Args for ease of access | -- Args for ease of access | ||
equave = args["Equave"] | equave = args["Equave" ] or DEFAULT_EQUAVE | ||
int_limit = args["Int Limit"] | int_limit = args["Int Limit" ] or DEFAULT_INT_LIMIT | ||
odd_limit = args["Odd Limit"] | odd_limit = args["Odd Limit" ] | ||
prime_limit = args["Prime Limit"] | prime_limit = args["Prime Limit"] | ||
subgroup = args["Subgroup"] | subgroup = args["Subgroup" ] | ||
-- Filtering args | -- Filtering args | ||
tenney_height = args["Tenney Height"] | 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 | ||
| Line 383: | Line 434: | ||
-- Invokable function; for templates | -- Invokable function; for templates | ||
-- Ratios are returned as a comma-delimited list, | -- Ratios are returned as a comma-delimited list. For finer control, it's | ||
-- | -- necessary to call the "main" function, then further process the results. | ||
function p.ji_ratios(frame) | function p.ji_ratios(frame) | ||
args = getArgs(frame) | args = getArgs(frame) | ||
| Line 436: | Line 487: | ||
--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. | return p.ratios_as_string(p.search_by_odd_limit(rat.new(2), 15, 15*2)) | ||
end | end | ||