Module:Infobox MOS: Difference between revisions
Changed ancestor function to the one in the tamnams module |
Partially revert changes due to bugs |
||
| Line 238: | Line 238: | ||
return section_entries | return section_entries | ||
end | |||
-- Helper function for a helper function | |||
-- Determines what mos the given mos descends from | |||
-- as well as what step ratio that produces this scale | |||
-- Mosses within the "named range" passed here will return itself | |||
function p.find_mos_ancestor(input_mos) | |||
local input_mos = input_mos or mos.new(5, 2) | |||
local z = input_mos.nL | |||
local w = input_mos.ns | |||
local generations = 0 | |||
-- For an ancestral 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 lg_chunk = { nL = 1, ns = 0 } | |||
local sm_chunk = { nL = 0, ns = 1 } | |||
while (z ~= w) and (z + w > 10) 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 | |||
return mos.new(z, w, input_mos.equave), lg_chunk, sm_chunk, generations | |||
end | end | ||
| Line 280: | Line 324: | ||
elseif not is_within_named_range and notecount > 10 and not is_root_mos then | elseif not is_within_named_range and notecount > 10 and not is_root_mos then | ||
-- Mos is a non-root mos and has a tamnams-named ancestor | -- Mos is a non-root mos and has a tamnams-named ancestor | ||
local ancestor_mos, | local ancestor_mos, lg_chunk, sm_chunk, generations = p.find_mos_ancestor(input_mos) | ||
local ancestor_scalesig = mos.as_string(ancestor_mos) | local ancestor_scalesig = mos.as_string(ancestor_mos) | ||
local ancestor_long_scalesig = mos.as_long_string(ancestor_mos) | local ancestor_long_scalesig = mos.as_long_string(ancestor_mos) | ||
local ancestor_name = tamnams.lookup_name(ancestor_mos) | local ancestor_name = tamnams.lookup_name(ancestor_mos) | ||
local | -- Helper code for finding mos ancestor and relation to it | ||
local num1 = lg_chunk.nL + lg_chunk.ns | |||
local | local den1 = sm_chunk.nL + sm_chunk.ns | ||
local num2 = lg_chunk.nL | |||
local den2 = sm_chunk.nL | |||
local first_ancestor_step_ratio = "" | |||
local second_ancestor_step_ratio = "" | |||
if num1/den1 < num2/den2 then | |||
first_ancestor_step_ratio = string.format("%d:%d", num1, den1) | |||
second_ancestor_step_ratio = string.format("%d:%d", num2, den2) | |||
else | |||
first_ancestor_step_ratio = string.format("%d:%d", num2, den2) | |||
second_ancestor_step_ratio = string.format("%d:%d", num1, den1) | |||
end | |||
-- Step ratio range as text | |||
local step_ratio_range = string.format("%s to %s", first_ancestor_step_ratio, second_ancestor_step_ratio) | |||
-- Step ratio range as a named range | |||
local named_range = step_ratio_range | |||
if step_ratio_range == "1:1 to 2:1" then | |||
named_range = named_range .. " (soft-of-basic)" | |||
elseif step_ratio_range == "2:1 to 1:0" then | |||
named_range = named_range .. " (hard-of-basic)" | |||
elseif step_ratio_range == "1:1 to 3:2" then | |||
named_range = named_range .. " (soft)" | |||
elseif step_ratio_range == "3:2 to 2:1" then | |||
named_range = named_range .. " (hyposoft)" | |||
elseif step_ratio_range == "2:1 to 3:1" then | |||
named_range = named_range .. " (hypohard)" | |||
elseif step_ratio_range == "3:1 to 1:0" then | |||
named_range = named_range .. " (hard)" | |||
elseif step_ratio_range == "1:1 to 4:3" then | |||
named_range= named_range .. " (ultrasoft)" | |||
elseif step_ratio_range == "4:3 to 3:2" then | |||
named_range = named_range .. " (parasoft)" | |||
elseif step_ratio_range == "3:2 to 5:3" then | |||
named_range = named_range .. " (quasisoft)" | |||
elseif step_ratio_range == "5:3 to 2:1" then | |||
named_range = named_range .. " (minisoft)" | |||
elseif step_ratio_range == "2:1 to 5:2" then | |||
named_range = named_range .. " (minihard)" | |||
elseif step_ratio_range == "5:2 to 3:1" then | |||
named_range = named_range .. " (quasihard)" | |||
elseif step_ratio_range == "3:1 to 4:1" then | |||
named_range = named_range .. " (parahard)" | |||
elseif step_ratio_range == "4:1 to 1:0" then | |||
named_range = named_range .. " (ultrahard)" | |||
end | |||
local ancestor_entry = string.format("[[%s | %s]]", ancestor_long_scalesig, ancestor_scalesig) | local ancestor_entry = string.format("[[%s | %s]]", ancestor_long_scalesig, ancestor_scalesig) | ||
| Line 297: | Line 387: | ||
{string.format("<b>%s</b>", section_header)}, | {string.format("<b>%s</b>", section_header)}, | ||
{"Descends from", ancestor_entry}; | {"Descends from", ancestor_entry}; | ||
{"Ancestor's step ratio range", string.format("%s", | {"Ancestor's step ratio range", string.format("%s", named_range)} | ||
} | } | ||
end | end | ||
| Line 547: | Line 637: | ||
--return infobox.build_multilink("5L 2s (2/1-equivalent)", entries) | --return infobox.build_multilink("5L 2s (2/1-equivalent)", entries) | ||
return p._infobox_mos("7L | return p._infobox_mos("7L 16s") | ||
end | end | ||
return p | return p | ||