Module:MOS
- This module primarily serves as a library for other modules and has no corresponding template.
This module provides functions for working with MOS scales in Lua code.
| Introspection summary for Module:MOS | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
| ||||||||||||||||||||||||
No function descriptions were provided. The Lua code may have further information.
local rat = require('Module:Rational')
local seq = require('Module:Sequence')
local et = require('Module:ET')
local p = {}
local common_name = {
['3/2'] = 'fifth'
}
local common_ratio = {
['fifth'] = rat.new(3, 2)
}
-- create a MOS structure (nL)L (ns)s <equave>
function p.new(nL, ns, equave)
local nL = nL or 5
local ns = ns or 2
local equave = equave or 2
return { nL = nL, ns = ns, equave = equave }
end
-- parse a MOS structure
function p.parse(unparsed)
local nL, ns, equave = unparsed:match('^(%d+[Ll])(%s*)(%d+[Ss])(%s*.-equivalent)?$')
if equave == nil then
equave = 2
end
equave = common_ratio[equave] or rat.parse(equave)
if nL == nil or ns == nil or equave == nil then
return nil
end
return p.new(nL, ns, equave)
end
-- construct a string representation for a MOS structure
function p.as_string(mos)
local suffix = nil
if mos.equave ~= 2 then
suffix = "<" .. rat.as_ratio(mos.equave):lower() .. ">"
end
return mos.nL .. "L " .. mos.ns .. "s " .. suffix
end
return p