Module:MOS modes: Difference between revisions
Jump to navigation
Jump to search
ArrowHead294 (talk | contribs) m Wait Tag: Undo |
ArrowHead294 (talk | contribs) mNo edit summary |
||
(36 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local mos = require("Module:MOS") | |||
local rat = require("Module:Rational") | |||
local tamnams = require("Module:TAMNAMS") | |||
local tip = require("Module:Template input parse") | |||
local utils = require("Module:Utils") | |||
local yesno = require("Module:Yesno") | |||
-- TODO: | -- TODO: | ||
-- - | -- - 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(input_mos, mode_names, headers, entries) | function p._mos_modes(input_mos, mode_names, headers, entries, is_collapsed) | ||
local is_collapsed = is_collapsed == true | |||
local input_mos = input_mos or mos. | local input_mos = input_mos or mos.new(5,2) | ||
local mode_names = mode_names or {} | |||
local headers = headers or {} | |||
local entries = entries or {} | |||
-- Get | -- Get UDPs and CPOs | ||
local udps = tamnams.mos_mode_udps(input_mos) | |||
local | local cpos = tamnams.mos_mode_cpos(input_mos) | ||
-- Get the mos's modes | -- Get the mos's modes | ||
local mos_modes = mos.modes_by_brightness(input_mos) | local mos_modes = mos.modes_by_brightness(input_mos) | ||
-- | -- Check whether to add mode names | ||
local add_mode_names = #mode_names == #mos_modes | |||
local | |||
-- | -- Check whether the number of headers times the number of modes equals the | ||
-- | -- number of entries. Supplementary info can only be added if this condition | ||
-- is | -- is met. Limited to 3 columns of supplementary info. | ||
local add_columns = #headers > 0 and #entries > 0 | local add_columns = #headers > 0 and #entries > 0 | ||
if add_columns then | if add_columns then | ||
add_columns = add_columns and #mos_modes * #headers == #entries | add_columns = add_columns and #mos_modes * #headers == #entries and #headers <= 3 | ||
end | end | ||
-- | -- Table caption | ||
local scale_sig = mos.as_string(input_mos) | |||
local | |||
-- | -- Start of table | ||
local result = | local result = "{| class=\"wikitable sortable center-2 center-3 mw-collapsible" .. (is_collapsed and " mw-collapsed\"\n" or "\"\n") | ||
.. "|+ style=\"font-size: 105%; white-space: nowrap;\" | " .. string.format("Modes of %s\n", scale_sig) | |||
.. "|-\n" | |||
result = result .. "! [[UDP]] | |||
-- Table headers | |||
result = result | |||
.. "! [[UDP]]" | |||
.. " !! Cyclic<br />order" | |||
.. " !! Step<br />pattern" | |||
-- | -- Add header for mode names, if provided. | ||
if | if add_mode_names then | ||
result = result .. | result = result .. " !! class=\"unsortable\" | Mode names" | ||
end | end | ||
-- Add | -- Add column headers for supplementary info, if provided. | ||
if add_columns then | if add_columns then | ||
for i = 1, #headers do | for i = 1, #headers do | ||
result = result .. | result = result .. string.format(" !! class=\"unsortable\" | %s", headers[i]) | ||
end | end | ||
end | end | ||
result = result .. "\n" | |||
-- Enter each row | -- Enter each row | ||
for i = 1, #mos_modes do | for i = 1, #mos_modes do | ||
result = result .. "|-\n" | result = result .. "|-\n" | ||
-- Add the UDP, | -- Add the UDP, brightness order, and the mode's step pattern | ||
result = result .. string.format("| %s || %s || %s", | |||
udps[i], cpos[i], mos_modes[i]) | |||
-- Add the mode's name, if given | -- Add the mode's name, if given | ||
if | if add_mode_names then | ||
result = result .. "|" | result = result .. string.format(" || %s", mode_names[i]) | ||
end | end | ||
Line 101: | Line 83: | ||
for j = 1, #headers do | for j = 1, #headers do | ||
local index = (i - 1) * #headers + j | local index = (i - 1) * #headers + j | ||
result = result .. "|" | result = result .. string.format(" || %s", entries[index]) | ||
end | end | ||
end | end | ||
result = result .. "\n" | |||
end | end | ||
result = result .. "|}" | result = result .. "|}" | ||
return result | return result | ||
end | end | ||
-- 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 scale_sig = frame.args["Scale Signature"] or "5L 2s" | |||
local scale_sig = frame.args[ | |||
local input_mos = mos.parse(scale_sig) | local input_mos = mos.parse(scale_sig) | ||
Line 123: | 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", | |||
"Ionian (major)", | |||
"Mixolydian", | |||
mode_names = tip.parse_entries( | "Dorian", | ||
"Aeolian (minor)", | |||
"Phrygian", | |||
"Locrian" | |||
} | |||
end | |||
-- Get mode names entered | |||
if #frame.args["Mode Names"] ~= 0 then | |||
mode_names = tip.parse_entries(frame.args["Mode Names"], "$") | |||
end | end | ||
-- | -- Get supplementary info | ||
local headers_unparsed = frame.args["Table Headers"] | |||
local headers = tip.parse_entries(headers_unparsed, "$") | |||
local | local entries_unparsed = frame.args["Table Entries"] | ||
local | 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. | |||
if headers_unparsed ~= "" and entries_unparsed ~= "" then | |||
result = result .. "[[Category:Pages with deprecated template parameters]]" | |||
end | |||
-- Debugger option | |||
if debugg == true then | |||
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>" | |||
end | |||
return result | return frame:preprocess(result) | ||
end | end | ||
return p | return p |
Latest revision as of 12:45, 1 June 2025
Note: Do not invoke this module directly; use the corresponding template instead: Template:MOS modes.
This template is used for mos pages to automatically generate and list that mos's modes, along with the modes' UDP (up-down-period) notation.
local p = {}
local mos = require("Module:MOS")
local rat = require("Module:Rational")
local tamnams = require("Module:TAMNAMS")
local tip = require("Module:Template input parse")
local utils = require("Module:Utils")
local yesno = require("Module:Yesno")
-- TODO:
-- - Add ability to autocollapse on large mos pages (say, more than 12 modes)
-- "Main" function
-- To be called by wrapper
function p._mos_modes(input_mos, mode_names, headers, entries, is_collapsed)
local is_collapsed = is_collapsed == true
local input_mos = input_mos or mos.new(5,2)
local mode_names = mode_names or {}
local headers = headers or {}
local entries = entries or {}
-- Get UDPs and CPOs
local udps = tamnams.mos_mode_udps(input_mos)
local cpos = tamnams.mos_mode_cpos(input_mos)
-- Get the mos's modes
local mos_modes = mos.modes_by_brightness(input_mos)
-- Check whether to add mode names
local add_mode_names = #mode_names == #mos_modes
-- Check whether the number of headers times the number of modes equals the
-- number of entries. Supplementary info can only be added if this condition
-- is met. Limited to 3 columns of supplementary info.
local add_columns = #headers > 0 and #entries > 0
if add_columns then
add_columns = add_columns and #mos_modes * #headers == #entries and #headers <= 3
end
-- Table caption
local scale_sig = mos.as_string(input_mos)
-- Start of table
local result = "{| class=\"wikitable sortable center-2 center-3 mw-collapsible" .. (is_collapsed and " mw-collapsed\"\n" or "\"\n")
.. "|+ style=\"font-size: 105%; white-space: nowrap;\" | " .. string.format("Modes of %s\n", scale_sig)
.. "|-\n"
-- Table headers
result = result
.. "! [[UDP]]"
.. " !! Cyclic<br />order"
.. " !! Step<br />pattern"
-- Add header for mode names, if provided.
if add_mode_names then
result = result .. " !! class=\"unsortable\" | Mode names"
end
-- Add column headers for supplementary info, if provided.
if add_columns then
for i = 1, #headers do
result = result .. string.format(" !! class=\"unsortable\" | %s", headers[i])
end
end
result = result .. "\n"
-- Enter each row
for i = 1, #mos_modes do
result = result .. "|-\n"
-- Add the UDP, brightness order, and the mode's step pattern
result = result .. string.format("| %s || %s || %s",
udps[i], cpos[i], mos_modes[i])
-- Add the mode's name, if given
if add_mode_names then
result = result .. string.format(" || %s", mode_names[i])
end
-- Add columns if given
if add_columns then
for j = 1, #headers do
local index = (i - 1) * #headers + j
result = result .. string.format(" || %s", entries[index])
end
end
result = result .. "\n"
end
result = result .. "|}"
return result
end
-- Wrapper function; to be called by template
function p.modes_table(frame)
local scale_sig = frame.args["Scale Signature"] or "5L 2s"
local input_mos = mos.parse(scale_sig)
-- Get the mos's mode names, if given
-- Mode names are entered as a semicolon-delimited list
-- 5L 2s gets default names
local mode_names = nil
if scale_sig == "5L 2s" then
mode_names = {
"Lydian",
"Ionian (major)",
"Mixolydian",
"Dorian",
"Aeolian (minor)",
"Phrygian",
"Locrian"
}
end
-- Get mode names entered
if #frame.args["Mode Names"] ~= 0 then
mode_names = tip.parse_entries(frame.args["Mode Names"], "$")
end
-- 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.
if headers_unparsed ~= "" and entries_unparsed ~= "" then
result = result .. "[[Category:Pages with deprecated template parameters]]"
end
-- Debugger option
if debugg == true then
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
end
return frame:preprocess(result)
end
return p