Module:MOS: Difference between revisions
m Minor rewrites to comments |
Comments/todo; added several more helper functions (based on how many times these were needed in other modules): darkest_mode(), dark_gen(), period(), bright_gen_step_count(), dark_gen_step_count(), period_step_count() |
||
| Line 4: | Line 4: | ||
local et = require('Module:ET') | local et = require('Module:ET') | ||
local p = {} | local p = {} | ||
-- TODO: transfer tamnams-related info to tamnams module | |||
-- Table of official tamnams names (2/1-equave only) | -- Table of official tamnams names (2/1-equave only) | ||
| Line 210: | Line 212: | ||
end | end | ||
-- Compute the | -- Find the darkest mode of a mos | ||
-- It's the reverse of the brightest mode | |||
function p.darkest_mode(mos) | |||
local nL = mos.nL | |||
local ns = mos.ns | |||
local d = utils._gcd(nL, ns) | |||
if d > 1 then -- use single period mos, with period as new equave | |||
nL = round(nL/d) | |||
ns = round(ns/d) | |||
end | |||
local current_L, current_s = 0, 0 | |||
local result = '' | |||
while current_L < nL or current_s < ns do | |||
if (current_s + 1) * nL <= ns * (current_L) then | |||
current_s = current_s + 1 | |||
result = 's' .. result -- !esreveR | |||
else | |||
current_L = current_L + 1 | |||
result = 'L' .. result -- !esreveR | |||
end | |||
end | |||
return string.rep(result, d) | |||
end | |||
-- Compute the period as a vector of L's and s's. | |||
function p.period(mos) | |||
local gcd = utils._gcd(mos.nL, mos.ns) | |||
local result = { | |||
['L'] = mos.nL / gcd, | |||
['s'] = mos.ns / gcd | |||
} | |||
return result | |||
end | |||
-- Compute the bright gen as a vector of L's and s's. | |||
function p.bright_gen(mos) | function p.bright_gen(mos) | ||
local nL = mos.nL | local nL = mos.nL | ||
| Line 238: | Line 274: | ||
end | end | ||
return result | return result | ||
end | |||
-- Compute the dark gen as a vector of L's and s's. | |||
function p.dark_gen(mos) | |||
local bright_gen = p.bright_gen(mos) | |||
local period = p.period(mos) | |||
local dark_gen = { | |||
['L'] = period['L'] - bright_gen['L'], | |||
['s'] = period['s'] - bright_gen['s'] | |||
} | |||
return dark_gen | |||
end | |||
-- Compute the size of the period in mossteps (L's plus s's) | |||
function p.period_step_count(mos) | |||
local period = p.period(mos) | |||
return period['L'] + period['s'] | |||
end | |||
-- Compute the size of the bright gen in mossteps (L's plus s's) | |||
function p.bright_gen_step_count(mos) | |||
local bright_gen = p.bright_gen(mos) | |||
return bright_gen['L'] + bright_gen['s'] | |||
end | |||
-- Compute the size of the dark gen in mossteps (L's plus s's) | |||
function p.dark_gen_step_count(mos) | |||
local dark_gen = p.dark_gen(mos) | |||
return dark_gen['L'] + dark_gen['s'] | |||
end | end | ||
| Line 257: | Line 322: | ||
-- Given a mos, find the ancestor mos with a target note count (default 10) | -- Given a mos, find the ancestor mos with a target note count (default 10) | ||
-- or less | -- or less; to be moved to tamnams module | ||
function p.find_ancestor(mos, target_note_count) | function p.find_ancestor(mos, target_note_count) | ||
local mos = mos or p.new(5, 2) | local mos = mos or p.new(5, 2) | ||
| Line 278: | Line 343: | ||
return p.new(z, w, mos.equave) | return p.new(z, w, mos.equave) | ||
end | |||
-- Tester function | |||
function p.tester() | |||
return p.period_length(p.new(21, 8)) | |||
end | end | ||
return p | return p | ||