Module:Mediants: Difference between revisions
m Comments, testing |
Changed code to accept initial ratios in an array |
||
| Line 1: | Line 1: | ||
local mos = require("Module:MOS") | local mos = require("Module:MOS") -- For testing | ||
local utils = require("Module:Utils") -- For testing | |||
local p = {} | local p = {} | ||
-- Module for finding mediants, either by search depth or by search function. | -- Module for finding mediants, either by search depth or by search function. | ||
function p.find_mediants_by_depth( | function p.find_mediants_by_depth(init_ratios, depth) | ||
local | local init_ratios = init_ratios or {{1,1}, {1,0}} | ||
local depth = depth or 5 | local depth = depth or 5 | ||
local ratios = { | local ratios = {} | ||
for i = 1, #init_ratios do | |||
table.insert(ratios, init_ratios[i]) | |||
end | |||
for i = 1, depth do | for i = 1, depth do | ||
| Line 56: | Line 59: | ||
end | end | ||
function p.find_mediants_by_filter( | function p.find_mediants_by_filter(init_ratios, filter, filter_arg) | ||
local | local init_ratios = init_ratios or {{1,1}, {1,0}} | ||
local ratios = { | local ratios = {} | ||
for i = 1, #init_ratios do | |||
table.insert(ratios, init_ratios[i]) | |||
end | |||
local new_ratios_added = true | local new_ratios_added = true | ||
| Line 83: | Line 88: | ||
local func = p.int_limit_filter | local func = p.int_limit_filter | ||
local ratios = p.find_mediants_by_filter({1,1}, {1,0}, func, | local ratios = p.find_mediants_by_filter({{1,1}, {1,0}}, func, 12) | ||
ratios = p.find_mediants_by_depth({{1,1}, {1,0}}, 5) | |||
local generators = {} | local generators = {} | ||
for i = 1, #ratios do | for i = 1, #ratios do | ||
local input_mos = mos.new(5,2) | local input_mos = mos.new(5,2) | ||
local gen = mos.bright_gen_to_cents(input_mos, ratios[i]) | local gen = mos.bright_gen_to_cents(input_mos, ratios[i]) | ||
local edo = ratios[i][1] * 5 + ratios[i][2] * 2 | local gcd = utils._gcd(ratios[i][1], ratios[i][2]) | ||
local new_string = string.format("%s:%s\t%sedo\t%.3f", ratios[i][1], ratios[i][2], edo, gen) | local edo = (ratios[i][1] * 5 + ratios[i][2] * 2)/gcd | ||
local new_string = string.format("%s:%s\t%sedo\t%.3f", ratios[i][1]/gcd, ratios[i][2]/gcd, edo, gen) | |||
table.insert(generators, new_string) | table.insert(generators, new_string) | ||
end | end | ||