Module:MOS modes: Difference between revisions
No edit summary |
force-collapse, following nick vucis recommendation on not sponsoring mode names |
||
| (5 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
local | local p = {} | ||
local mos | |||
local rat | local mos = require("Module:MOS") | ||
local rat = require("Module:Rational") | |||
local tamnams = require("Module:TAMNAMS") | local tamnams = require("Module:TAMNAMS") | ||
local tip | local tip = require("Module:Template input parse") | ||
local utils | local utils = require("Module:Utils") | ||
local yesno | local yesno = require("Module:Yesno") | ||
-- TODO: | -- TODO: | ||
-- - Add ability to autocollapse on large mos pages (say, more than 12 modes) | -- - Add ability to autocollapse on large mos pages (say, more than 12 modes) | ||
-- "Main" function | -- "Main" function | ||
-- To be called by wrapper | -- To be called by wrapper | ||
function p._mos_modes( | function p._mos_modes(input_mos, mode_names, headers, entries, is_collapsed) | ||
local is_collapsed | local is_collapsed = true | ||
local input_mos | local input_mos = input_mos or mos.new(5,2) | ||
local mode_names | local mode_names = mode_names or {} | ||
local headers | local headers = headers or {} | ||
local entries | local entries = entries or {} | ||
-- Get UDPs and CPOs | -- Get UDPs and CPOs | ||
| Line 66: | Line 28: | ||
-- Check whether to add mode names | -- Check whether to add mode names | ||
local add_mode_names = | local add_mode_names = #mode_names == #mos_modes | ||
-- Check whether the number of headers times the number of modes equals the | -- Check whether the number of headers times the number of modes equals the | ||
| Line 113: | Line 75: | ||
-- Add the mode's name, if given | -- Add the mode's name, if given | ||
if add_mode_names then | if add_mode_names then | ||
result = result .. string.format(" || %s", mode_names[i]) | result = result .. string.format(" || %s", mode_names[i]) | ||
end | end | ||
| Line 134: | Line 96: | ||
-- Wrapper function; to be called by template | -- Wrapper function; to be called by template | ||
function p.modes_table(frame) | function p.modes_table(frame) | ||
local | local scale_sig = frame.args["Scale Signature"] or "5L 2s" | ||
local input_mos = mos.parse(scale_sig) | local input_mos = mos.parse(scale_sig) | ||
-- Get the mos's mode names, if given | -- Get the mos's mode names, if given | ||
| Line 156: | Line 104: | ||
local mode_names = nil | local mode_names = nil | ||
if scale_sig == "5L 2s" then | if scale_sig == "5L 2s" then | ||
mode_names = { | |||
"Lydian", | "Lydian", | ||
"Ionian (major)", | "Ionian (major)", | ||
| Line 165: | Line 113: | ||
"Locrian" | "Locrian" | ||
} | } | ||
end | end | ||
-- | -- Get mode names entered | ||
if #frame.args["Mode Names"] ~= 0 then | if #frame.args["Mode Names"] ~= 0 then | ||
mode_names = tip.parse_entries(frame.args["Mode Names"], "$") | |||
end | end | ||
local result = p._mos_modes( | -- Get supplementary info | ||
local headers_unparsed = frame.args["Table Headers"] | |||
local headers = tip.parse_entries(headers_unparsed, "$") | |||
local entries_unparsed = frame.args["Table Entries"] | |||
local entries = tip.parse_entries(entries_unparsed, "$") | |||
local is_collapsed = yesno(frame.args["Collapsed"], false) | |||
local debugg = yesno(frame.args["debug"]) | |||
local result = p._mos_modes(input_mos, mode_names, headers, entries, is_collapsed) | |||
-- Current means of adding entries is unmaintainable; to be deprecated. | -- Current means of adding entries is unmaintainable; to be deprecated. | ||
| Line 183: | Line 135: | ||
-- Debugger option | -- Debugger option | ||
if debugg == true then | if debugg == true then | ||
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>" | result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>" | ||
| Line 189: | Line 140: | ||
return frame:preprocess(result) | return frame:preprocess(result) | ||
end | end | ||
return p | return p | ||