Module:Sharpness documentation: Difference between revisions
ArrowHead294 (talk | contribs) mNo edit summary |
Address missing sharpness-(+/-1) cases. Try to improve this insanely poorly documented code using more descriptive variable names |
||
| Line 4: | Line 4: | ||
function p.main(frame) | function p.main(frame) | ||
local in_str = frame.args["input"] | local in_str = frame.args["input"] | ||
local note = frame.args["note"] or "" | local note = frame.args["note"] or "" | ||
local notation = frame.args["notation"] or "" | local notation = frame.args["notation"] or "" | ||
if | -- type: "sharp" or "flat" | ||
-- value: absolute value of sharpness (the "n" as in sharp-n and flat-n) | |||
-- extension: used for identifying alternative symbol set | |||
local type, value, extension = in_str:match("%-(%a*)(%d+)(%a*)") | |||
-- signed sharpness | |||
local s = tonumber(value) | |||
if type == "flat" then | |||
s = -s | |||
end | end | ||
local | local sc = s * 12 -- edo number for supersets of 12edo | ||
if | if extension == nil then | ||
extension = "" | |||
end | end | ||
local out_str = "This template is used " | |||
if s == 0 then | if s == 0 then | ||
| Line 28: | Line 34: | ||
else | else | ||
out_str = out_str | out_str = out_str | ||
.. "for [[ | .. "for [[edo]]s where a sharp " | ||
.. ((s < 0) and {"lowers"} or {"raises"})[1] .. " by " .. math.abs(s) .. " step" | .. ((s < 0) and {"lowers"} or {"raises"})[1] .. " by " .. math.abs(s) .. " step" | ||
| Line 40: | Line 46: | ||
out_str = out_str .. " This symbol set " | out_str = out_str .. " This symbol set " | ||
if s == 2 then | if s == 1 then | ||
out_str = out_str .. "is identical to standard notation." | |||
elseif s == 2 then | |||
out_str = out_str .. "comprises sharps, flats, and Stein–Zimmerman [[24edo#Notation|quarter tone]] accidentals." | out_str = out_str .. "comprises sharps, flats, and Stein–Zimmerman [[24edo#Notation|quarter tone]] accidentals." | ||
else | |||
if | if extension == "" then | ||
out_str = out_str .. "[[ups and downs notation]] and comprises sharps, flats, " | out_str = out_str .. "[[ups and downs notation]] and comprises sharps, flats, " | ||
.. (s % 2 == 0 | .. (s % 2 == 0 | ||
and "naturals, and Stein–Zimmerman [[24edo#Notation|quarter tone]] accidentals " | and "naturals, and Stein–Zimmerman [[24edo #Notation|quarter tone]] accidentals " | ||
or "and naturals ") | or "and naturals ") | ||
out_str = out_str .. "with arrows from [[Helmholtz–Ellis notation]]." | out_str = out_str .. "with arrows from [[Helmholtz–Ellis notation]]." | ||
elseif | elseif extension == "a" or extension == "A" then -- extension for modern-style ups and downs | ||
out_str = out_str .. "is based on [[ups and downs notation]] using separate arrows." | out_str = out_str .. "is based on [[ups and downs notation]] using separate arrows." | ||
end | end | ||
| Line 58: | Line 66: | ||
end | end | ||
-- display custom note | |||
if note then | if note then | ||
out_str = out_str .. " " .. note | out_str = out_str .. " " .. note | ||
end | end | ||
-- display the note about supersets of 12edo for sharpness-1 and above | |||
if s >= 1 then | if s >= 1 then | ||
out_str = out_str | out_str = out_str | ||
| Line 72: | Line 82: | ||
end | end | ||
-- display the see also section for sharpness-3 and above | |||
if s >= 3 then | if s >= 3 then | ||
out_str = out_str | out_str = out_str | ||