Module:MOS intervals: Difference between revisions
mNo edit summary |
Fixed bug with mosstep range calculation for nL ns mosses |
||
| Line 44: | Line 44: | ||
end | end | ||
return return_string | return return_string | ||
end | |||
-- Helper function | |||
-- Produces the cent range of a mosstep | |||
function p.mos_interval_to_cent_range(step_pattern, mossteps, input_mos) | |||
local step_pattern = step_pattern or "LLsLLLs" | |||
local mossteps = mossteps or 1 | |||
local input_mos = input_mos or mos.new(5, 5, 2) | |||
local L_count = 0 | |||
local s_count = 0 | |||
for i = 1, mossteps do | |||
local step = string.sub(step_pattern, i, i) | |||
if step == "L" then | |||
L_count = L_count + 1 | |||
elseif step == "s" then | |||
s_count = s_count + 1 | |||
end | |||
end | |||
-- The range of a small step is from 0 to 1 step of the equalized mos | |||
-- The range of a large step is from 1 step of equalized to 1 step of collapsed | |||
-- These ranges do not apply if the mosstep interval is for a period; instead | |||
-- it's a fixed value. | |||
local equave_in_cents = rat.cents(input_mos.equave) | |||
local s_size_min = 0 | |||
local s_size_max = equave_in_cents / (input_mos.nL + input_mos.ns) | |||
local L_size_min = s_size_max | |||
local L_size_max = equave_in_cents / input_mos.nL | |||
local mossteps_per_period = (input_mos.nL + input_mos.ns) / utils._gcd(input_mos.nL, input_mos.ns) | |||
local is_period = mossteps % mossteps_per_period == 0 | |||
local result = "" | |||
if not is_period then | |||
local min_cents = L_count * L_size_min + s_count * s_size_max | |||
local max_cents = L_count * L_size_max + s_count * s_size_min | |||
result = string.format("%.1f¢ to %.1f¢", min_cents, max_cents) | |||
else | |||
local period_in_cents = equave_in_cents / utils._gcd(input_mos.nL, input_mos.ns) | |||
local number_of_periods = mossteps / mossteps_per_period | |||
result = string.format("%.1f¢", period_in_cents * number_of_periods) | |||
end | |||
return result | |||
end | end | ||
-- Helper function | -- Helper function | ||
-- Produces the cent range for a mosstep | -- Produces the cent range for a mosstep | ||
--[[ | |||
function p.mos_interval_to_cent_range(step_pattern, mossteps, input_mos) | function p.mos_interval_to_cent_range(step_pattern, mossteps, input_mos) | ||
| Line 75: | Line 119: | ||
return result | return result | ||
end | end | ||
]]-- | |||
-- Helper function | -- Helper function | ||