Module:MOS gamut: Difference between revisions
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" |
No edit summary |
||
| Line 105: | Line 105: | ||
function p.mos_gamut(input_mos, generators_up, step_ratio, note_symbols, chroma_plus_symbol, chroma_minus_symbol) | function p.mos_gamut(input_mos, generators_up, step_ratio, note_symbols, chroma_plus_symbol, chroma_minus_symbol) | ||
-- Default parameters for input mos and step ratio (5L 2s and 2:1 step ratio) | -- Default parameters for input mos and step ratio (5L 2s and 2:1 step ratio) | ||
local input_mos = input_mos or mos.new(2 | local input_mos = input_mos or mos.new(5, 2, 2) | ||
local step_ratio = step_ratio or { 2, 1 } | local step_ratio = step_ratio or { 2, 1 } | ||
| Line 112: | Line 112: | ||
local periods = rat.gcd(input_mos.nL, input_mos.ns) | local periods = rat.gcd(input_mos.nL, input_mos.ns) | ||
local mossteps_per_period = mossteps_per_equave / periods | local mossteps_per_period = mossteps_per_equave / periods | ||
-- Some default params will be different if the scalesig is 5L 2s | |||
local scale_sig = mos.as_string(input_mos) | |||
-- The default generators_up value corresponds to the brightest mode, | -- The default generators_up value corresponds to the brightest mode, | ||
-- unless the mos is 5L 2s, then it's the 2nd-brightest mode | -- unless the mos is 5L 2s, then it's the 2nd-brightest mode | ||
local | local generators_up_default = mossteps_per_equave - periods | ||
if scale_sig == "5L 2s" then | if scale_sig == "5L 2s" then | ||
generators_up_default = 5 | |||
end | end | ||
local generators_up = generators_up or generators_up_default | |||
-- The natural note symbols are those that correspond to diamond-mos | -- The natural note symbols are those that correspond to diamond-mos | ||
-- (JKLMN...) unless the mos is 5L 2s, then it's CDEFGAB | -- (JKLMN...) unless the mos is 5L 2s, then it's CDEFGAB | ||
-- If it's diamond-mos, gamut is limited to 17 note names | -- If it's diamond-mos, gamut is limited to 17 note names | ||
local note_symbols_main = "JKLMNOPQRSTUVWXYZ" | local note_symbols_main = "JKLMNOPQRSTUVWXYZ" | ||
local | local note_symbols_default = string.sub(note_symbols_main, 1, mossteps_per_equave) | ||
if scale_sig == "5L 2s" then | if scale_sig == "5L 2s" then | ||
note_symbols_default = "CDEFGAB" | |||
end | end | ||
local note_symbols = note_symbols or note_symbols_default | |||
-- The default accidentals are the amp and at (& and @) | -- The default accidentals are the amp and at (& and @) | ||
-- unless the mos is 5L 2s, then it's sharp and flat (# and b) | -- unless the mos is 5L 2s, then it's sharp and flat (# and b) | ||
local | local chroma_plus_default = "&" | ||
local | local chroma_minus_default = "@" | ||
if scale_sig == "5L 2s" then | if scale_sig == "5L 2s" then | ||
chroma_plus_default = "#" | |||
chroma_minus_default = "b" | |||
end | end | ||
local chroma_plus_symbol = chroma_plus_symbol or chroma_plus_default | |||
local chroma_minus_symbol = chroma_minus_symbol or chroma_minus_default | |||
-- Reconstruct the UDP up|dp (u times p pipe d times p) | -- Reconstruct the UDP up|dp (u times p pipe d times p) | ||
| Line 246: | Line 252: | ||
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 | |||
-- Step ratio | |||
local step_ratio_unparsed = frame.args['Step Ratio'] | |||
local step_ratio = { 2, 1 } | |||
if string.len(step_ratio_unparsed) > 0 then | |||
step_ratio = p.parse_step_ratio(step_ratio_unparsed) | |||
end | |||
-- Get the number of mossteps per period and equave | -- Get the number of mossteps per period and equave | ||
| Line 252: | Line 264: | ||
local periods = rat.gcd(input_mos.nL, input_mos.ns) | local periods = rat.gcd(input_mos.nL, input_mos.ns) | ||
local mossteps_per_period = mossteps_per_equave / periods | local mossteps_per_period = mossteps_per_equave / periods | ||
-- If certain params were left blank and the scalesig is 5L 2s, the default | |||
-- params will be for standard notation | |||
local scale_sig = mos.as_string(input_mos) | |||
-- The default generators_up value corresponds to the brightest mode, | -- The default generators_up value corresponds to the brightest mode, | ||
-- unless the mos is 5L 2s, then it's the 2nd-brightest mode | -- unless the mos is 5L 2s, then it's the 2nd-brightest mode | ||
local generators_up = | local generators_up = mossteps_per_equave - periods | ||
if scale_sig == "5L 2s" then | if scale_sig == "5L 2s" then | ||
generators_up = 5 | generators_up = 5 | ||
end | |||
-- If a value was entered, override the default value | |||
if string.len(frame.args['Bright Gens Up']) > 0 then | |||
generators_up = tonumber(frame.args['Bright Gens Up']) | |||
end | end | ||
| Line 266: | Line 285: | ||
-- This order of operations allows for overriding standard notation for 5L 2s | -- 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 = | local note_symbols = string.sub(note_symbols_main, 1, mossteps_per_equave) | ||
if scale_sig == "5L 2s" then | |||
note_symbols = "CDEFGAB" | |||
end | |||
-- If a value was entered, override the default value | |||
if string.len(frame.args['Note Symbols']) > 0 then | |||
note_symbols = frame.args['Note Symbols'] | |||
end | end | ||
| Line 279: | Line 298: | ||
-- unless the mos is 5L 2s, then it's sharp and flat # and b | -- 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 | -- This order of operations allows for overriding standard notation for 5L 2s | ||
local chroma_plus_symbol = | local chroma_plus_symbol = "&" | ||
local chroma_minus_symbol = | local chroma_minus_symbol = "@" | ||
if scale_sig == "5L 2s" then | |||
chroma_plus_symbol = "#" | |||
chroma_minus_symbol = "b" | |||
end | |||
-- If value(s) were entered, override the default values | |||
if string.len(frame.args['Sharp Symbol']) > 0 then | |||
chroma_plus_symbol = frame.args['Sharp Symbol'] | |||
end | end | ||
if string.len( | if string.len(frame.args['Flat Symbol']) > 0 then | ||
chroma_minus_symbol = frame.args['Flat Symbol'] | |||
end | end | ||