Module:MOS: Difference between revisions
mNo edit summary |
add period to reduced et-steps function |
||
| Line 147: | Line 147: | ||
function p.parent_mos(mos) | function p.parent_mos(mos) | ||
return p.new(math.min(mos.nL, mos.ns), math.abs(mos.nL-mos.ns), mos.equave) | return p.new(math.min(mos.nL, mos.ns), math.abs(mos.nL-mos.ns), mos.equave) | ||
end | |||
-- Find the root of a mos | |||
function p.root_mos(mos) | |||
local num_periods = p.period_count(mos) | |||
return p.new(num_periods, num_periods, mos.equave) | |||
end | end | ||
| Line 723: | Line 729: | ||
function p.period_to_et_steps_as_string(mos, step_ratio, suffix) | function p.period_to_et_steps_as_string(mos, step_ratio, suffix) | ||
return p.interval_to_et_steps_as_string(p.period(mos), mos, step_ratio, suffix) | return p.interval_to_et_steps_as_string(p.period(mos), mos, step_ratio, suffix) | ||
end | |||
-- Given a mos, compute the number of et-steps for its period, reduced, | |||
-- as a string "{steps}\{division}{suffix}". | |||
function p.reduced_period_to_et_steps_as_string(mos, suffix) | |||
return p.interval_to_et_steps_as_string({["L"] = 1, ["s"] = 1}, p.root_mos(mos), {1,0}, suffix) | |||
end | end | ||
| Line 758: | Line 770: | ||
end | end | ||
-- | -- Given a mos and a step ratio, return the number of cents for its period. | ||
-- The period is the interval at which the step pattern repeats, so no step | |||
-- ratio is needed. | |||
function p.period_to_cents(mos) | function p.period_to_cents(mos) | ||
return rat.cents(mos.equave) / p.period_count(mos) | return rat.cents(mos.equave) / p.period_count(mos) | ||
| Line 789: | Line 798: | ||
-- Tester function | -- Tester function | ||
function p.tester() | function p.tester() | ||
local input_mos = p.new( | local input_mos = p.new(6,3,3) | ||
local step_ratio = {2,1} | local step_ratio = {2,1} | ||
local interval_vector = {["L"] = 3, ["s"] = 1} | local interval_vector = {["L"] = 3, ["s"] = 1} | ||
return p.as_string(input_mos, false) | --return p.as_string(input_mos, false) | ||
--return p.mos_to_et(p.new(5,2), {2,1}) | --return p.mos_to_et(p.new(5,2), {2,1}) | ||
return p.reduced_period_to_et_steps_as_string(input_mos) | |||
end | end | ||
return p | return p | ||