Module:MOS degrees: Difference between revisions
m Commented out test values |
Added naming rules for nL ns mosses to newly added function; "unison" is now used instead of "0-mosstep" |
||
| Line 56: | Line 56: | ||
-- Default parameters for testing | -- Default parameters for testing | ||
--[[ | --[[ | ||
local input_mos = input_mos or mos.new( | local input_mos = input_mos or mos.new(5, 5, 2) | ||
local genchain_length_per_period = genchain_length_per_period or 10 | local genchain_length_per_period = genchain_length_per_period or 10 | ||
local going_up = | local going_up = false | ||
]]-- | ]]-- | ||
| Line 65: | Line 65: | ||
local periods_per_equave = rat.gcd(input_mos.nL, input_mos.ns) | local periods_per_equave = rat.gcd(input_mos.nL, input_mos.ns) | ||
local mossteps_per_period = mossteps_per_equave / periods_per_equave | local mossteps_per_period = mossteps_per_equave / periods_per_equave | ||
-- Get the number of mossteps for the generators | |||
local bright_gen = mos.bright_gen(input_mos) | |||
local mossteps_per_bright_gen = bright_gen['L'] + bright_gen['s'] | |||
-- The easiest way to get scale degrees is through the following method: | -- The easiest way to get scale degrees is through the following method: | ||
| Line 76: | Line 80: | ||
-- For each period, the first two elements represent the root (perfect) | -- For each period, the first two elements represent the root (perfect) | ||
-- and dark generator (small size is perfect). | -- and dark generator (small size is perfect). | ||
-- - Since the root and generators start as perfect, | -- - Since the root and generators start as perfect, any chromas added to | ||
-- | -- that represent augmented/diminished degrees. | ||
-- Note that this is agnostic of notation, so only the genchain length is | -- Note that this is agnostic of notation, so only the genchain length is | ||
-- needed. The UDP for the second-brightest mode is auto-calculated and is | -- needed. The UDP for the second-brightest mode is auto-calculated and is | ||
| Line 83: | Line 87: | ||
local genchain = mosg.mos_genchain(input_mos, mossteps_per_period - 2, genchain_length_per_period, true) | local genchain = mosg.mos_genchain(input_mos, mossteps_per_period - 2, genchain_length_per_period, true) | ||
-- Interpret as scale degrees | -- Interpret as scale degrees. | ||
-- The first two elements are always perfect. | -- The first two elements are always perfect. | ||
-- 0 chromas | -- 0 chromas is major (or minor if descending). | ||
-- 1 chroma is augmented | -- 1 chroma is augmented (diminished if descending). | ||
-- n chromas is n-times augmented, | -- n chromas is n-times augmented (n-times diminished if descending). | ||
-- Notes and caveats: | |||
-- - The 0-mosdegree is also called the unison. | |||
-- - Generators for nL ns mosses aren't called perf/aug/dim, but instead | |||
-- called major and minor. This requires offsetting the note's chroma | |||
-- value by -1, or else the singly-aug/dim generator will be skipped. | |||
local degreechain = {} | local degreechain = {} | ||
for j = 1, periods_per_equave do | for j = 1, periods_per_equave do | ||
| Line 96: | Line 105: | ||
local mossteps = note['mossteps'] | local mossteps = note['mossteps'] | ||
local chromas = note['chromas'] | local chromas = note['chromas'] | ||
-- Mosses of the form nL ns have slightly different rules. Is the | |||
-- input mos of that form? | |||
local is_nL_ns = input_mos.nL == input_mos.ns | |||
if is_nL_ns and mossteps == mossteps_per_bright_gen + (j-1) * mossteps_per_period then | |||
chromas = chromas - 1 | |||
end | |||
-- If not going up, use the period complements instead | -- If not going up, use the period complements instead | ||
| Line 109: | Line 125: | ||
end | end | ||
-- What is the quality of the note? (major, minor, etc) | |||
local quality = "" | local quality = "" | ||
if i == 1 then | if i == 1 then | ||
quality = "perfect" | quality = "perfect" | ||
elseif i == 2 then | elseif i == 2 then | ||
quality = "perfect" | if is_nL_ns then | ||
quality = maj_or_min | |||
else | |||
quality = "perfect" | |||
end | |||
else | else | ||
if chromas == 0 then | if chromas == 0 then | ||
| Line 124: | Line 145: | ||
end | end | ||
local degree = quality .. " " .. mossteps .. "-mosstep" | -- Put together the name | ||
-- TODO?: Prefix lookup | |||
-- If it's the 0-mosstep, simply say it's the unison instead. | |||
local degree = "" | |||
if mossteps == 0 then | |||
degree = quality .. " unison" | |||
else | |||
degree = quality .. " " .. mossteps .. "-mosstep" | |||
end | |||
table.insert(chain_for_period, degree) | table.insert(chain_for_period, degree) | ||