Module:JI ratios: Difference between revisions
No edit summary |
comments; todo |
||
| Line 1: | Line 1: | ||
local rat = require("Module:Rational") | local rat = require("Module:Rational") | ||
local utils = require("Module:Utils") | local utils = require("Module:Utils") | ||
local tip = require("Module:Template input parse") | local tip = require("Module:Template input parse") | ||
local m = require("Module:Mediants") | |||
p = {} | p = {} | ||
-- TODO: | |||
-- Adopt mediants module for all filtering needs | |||
-- Template for handling multiple entry of JI ratios into a template, and for | |||
-- searching for JI ratios if automatic entry is desired. | |||
-- This is a successor/replacement for JI ratio finder. | |||
-- JI ratios are searched by the following params in a hierarchy: | |||
-- - The absolute minimum for ratio search int limit, which limits the maximum | |||
-- size of the numerator and denominator. | |||
-- - If subgroup is present, ratios are searched by subgroup within an int | |||
-- limit. Subgroup takes precedence over prime limit, as subgroup is | |||
-- (typically) a subset of prime limit, so prime limit is ignored. (Nonprime | |||
-- subgroups take precedence over prime subgroups.) | |||
-- - If prime limit is present, ratios are searched by prime limit within an int | |||
-- limit. | |||
-- NOTES: | |||
-- - Prime limits are infinite sets, so int limit is used to restrain the set | |||
-- to a finite size. The same is true for subgroup. | |||
-- - Tenney height is used for further filtering of ratios, and is considered | |||
-- optional. | |||
-- INT_LIMIT_MAX is hardcoded to limit the size of output. | -- INT_LIMIT_MAX is hardcoded to limit the size of output. | ||
| Line 17: | Line 37: | ||
local INT_LIMIT_MAX = 200 | local INT_LIMIT_MAX = 200 | ||
local DEFAULT_INT_LIMIT = 50 | local DEFAULT_INT_LIMIT = 50 | ||
-------------------------------------------------------------------------------- | |||
----------------------- MEDIANT SEARCH FILTER FUNCTIONS ------------------------ | |||
-------------------------------------------------------------------------------- | |||
-- Mediants module is used to find JI ratios, so this section is for filter | |||
-- functions. | |||
-- A filter function has three params: mediant, depth, and a set of args, which | |||
-- can be a single value or a table of values. | |||
-- Int limit filter determines whether a ratio is within an int limit. Does not | |||
-- use depth. | |||
function p.int_limit_filter(mediant, depth, int_limit) | |||
return math.max(mediant[1], mediant[2]) <= int_limit | |||
end | |||
-- Tenney height filter determines whether a ratio is within a target Tenney | |||
-- height. Does not use depth. | |||
function p.tenney_height_filter(mediant, depth, tenney_height) | |||
return math.log(mediant[1] * mediant[2]) / math.log(2) <= tenney_height | |||
end | |||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
| Line 31: | Line 73: | ||
integer_limit = math.max(0, math.min(INT_LIMIT_MAX, integer_limit)) | integer_limit = math.max(0, math.min(INT_LIMIT_MAX, integer_limit)) | ||
local | local init_ratios = {{1,1}, {2,1}} | ||
local filter_func = p.int_limit_filter | |||
local filter_args = integer_limit | |||
local ratios = m.find_mediants_by_filter(init_ratios, filter_func, filter_args) | |||
local | |||
-- If the max cents is greater than the octave, duplicate all existing | -- If the max cents is greater than the octave, duplicate all existing | ||
| Line 133: | Line 156: | ||
end | end | ||
function p.search_param_footnotes(search_params) | function p.search_param_footnotes(search_params) | ||
local result = "Not all notable ratios may be shown, and other interpretations are possible." | local result = "Not all notable ratios may be shown, and other interpretations are possible." | ||