Module:TAMNAMS: Difference between revisions
Bugfixed code for applying APd for root mosses |
Added mos-ancestor functions |
||
| Line 79: | Line 79: | ||
} | } | ||
-- Lookup table for | -- Lookup table for tamnams names within the range of 6-10 steps | ||
p.tamnams_name = { | p.tamnams_name = { | ||
['1L 1s'] = 'monowood', | ['1L 1s'] = 'monowood', | ||
| Line 296: | Line 296: | ||
end | end | ||
function p. | -- Given a mos, find the ancestor mos within the target note count. | ||
function p.find_ancestor(input_mos, target_note_count) | |||
local target_note_count = target_note_count or 10 | |||
local z = input_mos.nL | |||
local w = input_mos.ns | |||
while (z ~= w) and (z + w > target_note_count) do | |||
local m1 = math.max(z, w) | |||
local m2 = math.min(z, w) | |||
-- For use with updating ancestor mos chunks | |||
local z_prev = z | |||
-- Update step ratios | |||
z = m2 | |||
w = m1 - m2 | |||
end | |||
return p.new(z, w, mos.equave) | |||
end | |||
-- Given a mos, find the ancestor mos within the target note count, while also | |||
-- returning the step ancestor's step ratio range (as two ratios) and the number | |||
-- of generations between the two mosses. (A more in-depth version of the prev.) | |||
function p.find_ancestor_info(input_mos, target_step_count) | |||
local target_step_count = target_step_count or 10 | |||
-- For an ancestor mos zU wv and descendant xL ys, how many steps of size | |||
-- L and s can fit inside U and v? (basically the chunking operation) | |||
local z = input_mos.nL | |||
local w = input_mos.ns | |||
local lg_chunk = { nL = 1, ns = 0 } | |||
local sm_chunk = { nL = 0, ns = 1 } | |||
local generations = 0 | |||
while (z ~= w) and (z + w > target_step_count) do | |||
local m1 = math.max(z, w) | |||
local m2 = math.min(z, w) | |||
-- For use with updating ancestor mos chunks | |||
local z_prev = z | |||
-- Count how many generations | |||
generations = generations + 1 | |||
-- Update step ratios | |||
z = m2 | |||
w = m1 - m2 | |||
-- Update large chunk | |||
local prev_lg_chunk = { nL = lg_chunk.nL, ns = lg_chunk.ns } | |||
lg_chunk.nL = lg_chunk.nL + sm_chunk.nL | |||
lg_chunk.ns = lg_chunk.ns + sm_chunk.ns | |||
-- Update small chunk | |||
if z ~= z_prev then | |||
sm_chunk = prev_lg_chunk | |||
end | |||
end | |||
-- Translate chunks into step ratios | |||
local ratio_1, ratio_2 | |||
if num1/den1 < num2/den2 then | |||
ratio_1 = { lg_chunk.nL + lg_chunk.ns, sm_chunk.nL + sm_chunk.ns } | |||
ratio_2 = { lg_chunk.nL, sm_chunk.nL } | |||
else | |||
ratio_2 = { lg_chunk.nL + lg_chunk.ns, sm_chunk.nL + sm_chunk.ns } | |||
ratio_1 = { lg_chunk.nL, sm_chunk.nL } | |||
end | |||
return mos.new(z, w), ratio_1, ratio_2, generations | |||
end | end | ||