Module:MOS modes: Difference between revisions

Ganaram inukshuk (talk | contribs)
Preparing to make the modes table into a template
Ganaram inukshuk (talk | contribs)
Adding support for mode names
Line 45: Line 45:
return modes
return modes
end
-- Helper function that parses mode names from a semicolon-delimited string and returns the names in an array
-- If it's nil, then return nil
function p.parse_mode_names(mode_names_unparsed)
if mode_names_unparsed == nil then
return nil
else
local mode_names = {}
for mode_name in string.gmatch(mode_names_unparsed, ";") do
table.insert(mode_names, mode_name)
end
return mode_names
end
end
end


Line 56: Line 70:
local input_mos = mos.parse(mosstring)
local input_mos = mos.parse(mosstring)
-- Get the mos's mode names, if given; otherwise, the default will be those for 5L 2s
-- Mode names are entered as a semicolon-delimited list
local mode_names = {}
if mosstring == "5L 2s" then
mode_names = { "lydian", "ionian", "mixolydian", "dorian", "aeolian", "phrygian", "locrian" }
else
mode_names = p.parse_mode_names(frame.args['ModeNames'])
end
-- Get the mos's modes
local mos_modes = p.modes_by_brightness(input_mos)
local mos_modes = p.modes_by_brightness(input_mos)
local periods = rat.gcd(input_mos.nL, input_mos.ns) -- Needed for UDP
local periods = rat.gcd(input_mos.nL, input_mos.ns) -- Needed for UDP
Line 65: Line 89:
result = result .. "! [[UDP]]\n"
result = result .. "! [[UDP]]\n"
result = result .. "! Step pattern\n"
result = result .. "! Step pattern\n"
-- If there are mode names (if the mode names array is not nil), then add a column for mode names
if mode_names ~= nil then
result = result .. "! Mode names\n"
end
-- Enter each row
-- Enter each row
Line 82: Line 111:
-- Add the mode's step pattern
-- Add the mode's step pattern
result = result .. "|" .. mos_modes[i] .. "\n"
result = result .. "|" .. mos_modes[i] .. "\n"
-- Add the mode's name, if given
if mode_names ~= nil then
result = result .. "|" .. mode_names[i]
end
end
end