Module:MOS gamut: Difference between revisions
m Simplified comments |
Added support for collapsed/equalized step ratios (hopefully); added ability to override 5L 2s standard notation; added parsing of step ratios entered as "p/q" |
||
| Line 171: | Line 171: | ||
-- How long should the genchain extend after the initial genchain? | -- How long should the genchain extend after the initial genchain? | ||
-- For a basic step ratio 2:1, extend by x | -- For a basic step ratio 2:1, extend by x | ||
-- For a collapsed or equalized step ratio, don't extend at all | |||
-- For any other ratio p:q (simplified), do this calculation: | -- For any other ratio p:q (simplified), do this calculation: | ||
-- x*floor(p/2) + y*floor(q/2) | -- x*floor(p/2) + y*floor(q/2) | ||
| Line 176: | Line 177: | ||
if num / den == 2 then | if num / den == 2 then | ||
genchain_extend = x | genchain_extend = x | ||
elseif num == den or den == 0 then | |||
genchain_extend = 0 | |||
else | else | ||
genchain_extend = x * math.floor(num/2) + y * math.floor(den/2) | genchain_extend = x * math.floor(num/2) + y * math.floor(den/2) | ||
| Line 224: | Line 227: | ||
return gamut | return gamut | ||
end | |||
-- Helper function for parsing a step ratio entered as a string "p/q" | |||
function p.parse_step_ratio(step_ratio_unparsed) | |||
local parsed = {} | |||
for entry in string.gmatch(unparsed, '([^/]+)') do | |||
local trimmed = entry:gsub("^%s*(.-)%s*$", "%1") | |||
table.insert(parsed, trimmed) -- Add to array | |||
end | |||
local ratio = { tonumber(parsed[1]), tonumber(parsed[2]) } | |||
return ratio | |||
end | end | ||
| Line 230: | Line 246: | ||
local input_mos_unparsed = frame.args['Scale Signature'] | local input_mos_unparsed = frame.args['Scale Signature'] | ||
local input_mos = mos.parse(input_mos_unparsed) or mos.new(2, 5, 2) | local input_mos = mos.parse(input_mos_unparsed) or mos.new(2, 5, 2) | ||
local | local step_ratio = p.parse_step_ratio(frame.args['Step Ratio']) or { 2, 1 } | ||
-- Get the number of mossteps per period and equave | -- Get the number of mossteps per period and equave | ||
| Line 247: | Line 261: | ||
end | end | ||
-- | -- Get note symbols | ||
-- If this param was blank, default to diamond-mos; limited to 17 note names | |||
-- But if it's blank and the scalesig is 5L 2s, default to standard notation | |||
-- This order of operations allows for overriding standard notation for 5L 2s | |||
local note_symbols_main = "JKLMNOPQRSTUVWXYZ" | local note_symbols_main = "JKLMNOPQRSTUVWXYZ" | ||
local note_symbols = frame.args['Note Symbols'] | local note_symbols = frame.args['Note Symbols'] | ||
if string.len(note_symbols) == 0 then | if string.len(note_symbols) == 0 then | ||
if scale_sig == "5L 2s" then | |||
note_symbols = "CDEFGAB" | |||
else | |||
note_symbols = string.sub(note_symbols_main, 1, mossteps_per_equave) | |||
end | |||
end | end | ||
-- | -- Get accidental symbols | ||
-- unless the mos is 5L 2s, then it's sharp and flat | -- If this param was blank, default to diamond-mos symbols & and @ | ||
-- unless the mos is 5L 2s, then it's sharp and flat # and b | |||
-- This order of operations allows for overriding standard notation for 5L 2s | |||
local chroma_plus_symbol = frame.args['Sharp Symbol'] | local chroma_plus_symbol = frame.args['Sharp Symbol'] | ||
local chroma_minus_symbol = frame.args['Flat Symbol'] | local chroma_minus_symbol = frame.args['Flat Symbol'] | ||
if string.len(chroma_plus_symbol) == 0 then | if string.len(chroma_plus_symbol) == 0 then | ||
chroma_plus_symbol = "&" | if scale_sig == "5L 2s" then | ||
chroma_plus_symbol = "#" | |||
else | |||
chroma_plus_symbol = "&" | |||
end | |||
end | end | ||
if string.len(chroma_minus_symbol) == 0 then | if string.len(chroma_minus_symbol) == 0 then | ||
if scale_sig == "5L 2s" then | |||
chroma_minus_symbol = "@" | |||
else | |||
chroma_minus_symbol = "b" | |||
chroma_minus_symbol = "b" | end | ||
end | end | ||