Module:MOS: Difference between revisions
comment review |
mNo edit summary |
||
| (5 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
-- This module follows User:Ganaram inukshuk/Provisional style guide for Lua | -- This module follows [[User:Ganaram inukshuk/Provisional style guide for Lua]] | ||
local et = require("Module:ET") | |||
local rat = require("Module:Rational") | |||
local utils = require("Module:Utils") | |||
local p = {} | local p = {} | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
| Line 40: | Line 23: | ||
-- If no equave "p/q" is provided, it's assumed to be 2/1-equivalent. | -- If no equave "p/q" is provided, it's assumed to be 2/1-equivalent. | ||
function p.parse(unparsed) | function p.parse(unparsed) | ||
local nL, ns, equave = unparsed:match("^(%d+)[Ll] | local nL, ns, equave = unparsed:match("^(%d+)[Ll].-(%d+)[Ss]%s*(.*)$") | ||
nL = tonumber(nL) | nL = tonumber(nL) | ||
ns = tonumber(ns) | ns = tonumber(ns) | ||
| Line 88: | Line 71: | ||
suffix = "⟨" .. rat.as_ratio(mos.equave):lower() .. "⟩" | suffix = "⟨" .. rat.as_ratio(mos.equave):lower() .. "⟩" | ||
end | end | ||
return | return mos.nL .. "L" .. (use_nbsp and " " or " ") .. mos.ns .. "s" .. suffix | ||
else | else | ||
return | return math.max(mos.nL, mos.ns) .. p.et_suffix(mos) | ||
end | end | ||
end | end | ||
| Line 106: | Line 89: | ||
suffix = (use_nbsp and " " or " ") .. string.format("(%s-equivalent)", rat.as_ratio(mos.equave):lower()) | suffix = (use_nbsp and " " or " ") .. string.format("(%s-equivalent)", rat.as_ratio(mos.equave):lower()) | ||
end | end | ||
return | return mos.nL .. "L" .. (use_nbsp and " " or " ") .. mos.ns .. "s" .. suffix | ||
else | else | ||
return | return math.max(mos.nL, mos.ns) .. p.et_suffix(mos) | ||
end | end | ||
end | end | ||
| Line 121: | Line 104: | ||
return string.format("[[%s]]", link) | return string.format("[[%s]]", link) | ||
else | else | ||
return string.format("[[%s | %s]]", link, text) | return string.format("[[%s|%s]]", link, text) | ||
end | end | ||
end | end | ||
| Line 307: | Line 290: | ||
local current_mode = mode_string | local current_mode = mode_string | ||
for i = 1, #mode_string do | for i = 1, #mode_string do | ||
if not | if not utils.table_contains(rotations, current_mode) then | ||
table.insert(rotations, current_mode) | table.insert(rotations, current_mode) | ||
end | end | ||
| Line 560: | Line 543: | ||
------------------------------- COUNT FUNCTIONS -------------------------------- | ------------------------------- COUNT FUNCTIONS -------------------------------- | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
-- Given a mos, return the number of steps. | |||
function p.step_count(mos) | |||
return mos.nL + mos.ns | |||
end | |||
-- Given a mos, compute the number of steps in its bright gen (L's plus s's). | -- Given a mos, compute the number of steps in its bright gen (L's plus s's). | ||
| Line 577: | Line 565: | ||
end | end | ||
-- | -- TODO: deprecate this since "equave_step_count" is redundant and longer than | ||
-- "step count". | |||
function p.equave_step_count(mos) | function p.equave_step_count(mos) | ||
return mos.nL + mos.ns | return mos.nL + mos.ns | ||