Module:MOS modes: Difference between revisions

Ganaram inukshuk (talk | contribs)
m parentheses
Ganaram inukshuk (talk | contribs)
Changed code to how I currently write template modules (underscore-prefixed primary function called by no-underscore-prefix wrapper function)
Line 58: Line 58:
end
end


-- Test function that produces the modes of a mos as a table
-- "Main" function
function p.modes_table(frame)
-- To be called by wrapper
function p._mos_modes(input_mos, mode_names, headers, entries)
-- Mos is entered as a scale signature "xL ys" or "xL ys<p/q>" since the mos module can parse that format
-- Mos is entered as a scale signature "xL ys" or "xL ys<p/q>" since the mos module can parse that format
local scale_sig = frame.args['Scale Signature'] or "5L 2s"
local input_mos = input_mos or 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
-- Mode names are entered as a semicolon-delimited list
-- Mode names are entered as a semicolon-delimited list
local mode_names = nil
local mode_names = mode_names or {}
if scale_sig == "5L 2s" then
mode_names_unparsed = "Lydian; Ionian (major); Mixolydian; Dorian; Aeolian (minor); Phrygian; Locrian"
mode_names = p.parse_entries(mode_names_unparsed)
else
mode_names_unparsed = frame.args['Mode Names']
mode_names = p.parse_entries(mode_names_unparsed)
end
-- Get the mos's modes and the mode count
-- Get the mos's modes and the mode count
Line 82: Line 75:
-- For n headers, the number of entries must match the number of modes times the number of headers
-- For n headers, the number of entries must match the number of modes times the number of headers
-- or else column data won't be added
-- or else column data won't be added
local headers_unparsed = frame.args['Table Headers']
local headers = headers or {}
local headers = p.parse_entries(headers_unparsed)
local entries = entries or {}
local entries_unparsed = frame.args['Table Entries']
local entries = p.parse_entries(entries_unparsed)


-- To determine whether to add additional columns, determine whether the number of entries
-- To determine whether to add additional columns, determine whether the number of entries
Line 155: Line 145:
result = result .. "|}"
result = result .. "|}"
return result
end
-- Wrapper function; to be called by template
function p.modes_table(frame)
-- Mos is entered as a scale signature "xL ys" or "xL ys<p/q>" since the mos module can parse that format
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_unparsed = "Lydian; Ionian (major); Mixolydian; Dorian; Aeolian (minor); Phrygian; Locrian"
mode_names = p.parse_entries(mode_names_unparsed)
else
mode_names_unparsed = frame.args['Mode Names']
mode_names = p.parse_entries(mode_names_unparsed)
end
-- This is for entering multiple columns of info, if a single column of mode names isn't enough
-- For n headers, the number of entries must match the number of modes times the number of headers
-- or else column data won't be added
local headers_unparsed = frame.args['Table Headers']
local headers = p.parse_entries(headers_unparsed)
local entries_unparsed = frame.args['Table Entries']
local entries = p.parse_entries(entries_unparsed)
local result = p._mos_modes(input_mos, mode_names, headers, entries)
return result
return result