Module:MOS: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
needs to parse "tritave" |
||
| Line 5: | Line 5: | ||
local common_name = { | local common_name = { | ||
['3/2'] = 'fifth' | ['3/2'] = 'fifth', | ||
['3/1'] = 'tritave' | |||
} | } | ||
local common_ratio = { | local common_ratio = { | ||
['fifth'] = rat.new(3, 2) | ['fifth'] = rat.new(3, 2), | ||
['tritave'] = rat.new(3, 1) | |||
} | } | ||
Revision as of 00:43, 1 April 2023
- 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',
['3/1'] = 'tritave'
}
local common_ratio = {
['fifth'] = rat.new(3, 2),
['tritave'] = rat.new(3, 1)
}
-- 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*(.*)$')
nL = tonumber(nL)
ns = tonumber(ns)
equave = equave:match('^%((.*)-equivalent%)$') or rat.new(2, 1)
equave = common_ratio[equave] or 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 = ''
if not rat.eq(mos.equave, 2) then
suffix = '<' .. rat.as_ratio(mos.equave):lower() .. '>'
end
return '' .. mos.nL .. 'L ' .. mos.ns .. 's' .. suffix
end
return p