Module:MOS notation: Difference between revisions

Ganaram inukshuk (talk | contribs)
Simplified code for mosstep-to-degree function, un-abbreviated qualities
Ganaram inukshuk (talk | contribs)
Added a helper function to parse notation entered as one param instead of three separate ones; to be later added to mos degrees and mos gamut modules
Line 5: Line 5:
local rat = require('Module:Rational')
local rat = require('Module:Rational')
local p = {}
local p = {}
-- Helper function for parsing notation entered as a string; for example,
-- "CDEFGAB, #, b" becomes an associative array, where:
-- - the key ['Naturals'] has the value "CDEFGAB"; also called "nominals"
-- - the key ['Sharp'] has the value "#"
-- - the key ['Flat'] has the value "b"
-- The string entered is comma-separated
-- TODO (low-priority):
-- - Add specific symbols for double-accidentals, namely "x" for two #'s
function p.parse_notation(notation_unparsed)
local parsed = {}
for entry in string.gmatch(step_ratio_unparsed, '([^,]+)') do
local trimmed = entry:gsub("^%s*(.-)%s*$", "%1")
table.insert(parsed, trimmed) -- Add to array
end
local notation = { ['Naturals'] = parsed[1], ['Sharp'] = parsed[2], ['Flat'] = parsed[3] }
if #parsed == 3 then
return notation
else
return nil
end
end


-- Helper function for parsing a step ratio entered as a string "p/q"
-- Helper function for parsing a step ratio entered as a string "p/q"