Module:MOS notation: Difference between revisions
m Fixed bug with generating degree name for multi-diminished mosdegrees (rep took in a negative value) |
m Clarified comments, renamed params; genchain_length_per_period -> chain_length_per_period, refers to the number of elements in the resulting chain rather than generators stacked from the root |
||
| Line 96: | Line 96: | ||
-- Parameters: | -- Parameters: | ||
-- - input_mos - the mos itself represented as a data structure from Module:MOS | -- - input_mos - the mos itself represented as a data structure from Module:MOS | ||
-- - | -- - upd_gens_per_period - This is either the value u or d for the UDP of up|dp, and is | ||
-- used to calculate the number of initial notes that don't have accidentals. | |||
-- - | -- Note that this is per period, so it's necessary to "simplify" the UDP like a fraction. | ||
-- - chain_length_per_period - the number of notes in the resulting chain. NOTE: if working | |||
-- in terms of "generators stacked after the root", add 1 to that value. | |||
-- - going_up - bool; whether the genchain is going up or down; true for up, false for down | -- - going_up - bool; whether the genchain is going up or down; true for up, false for down | ||
function p.mos_nomacc_chain(input_mos, | function p.mos_nomacc_chain(input_mos, upd_gens_per_period, chain_length_per_period, going_up) | ||
-- Default parameters for testing | -- Default parameters for testing | ||
--[[ | --[[ | ||
local input_mos = input_mos or mos.new(5, 2, 2) | local input_mos = input_mos or mos.new(5, 2, 2) | ||
local | local upd_gens_per_period = upd_gens_per_period or 5 | ||
local | local chain_length_per_period = chain_length_per_period or 14 | ||
local note_symbols = note_symbols or "CDEFGAB" | local note_symbols = note_symbols or "CDEFGAB" | ||
local chroma_symbol = chroma_symbol or "#" | local chroma_symbol = chroma_symbol or "#" | ||
| Line 155: | Line 157: | ||
-- Create the genchain | -- Create the genchain | ||
local genchain = { } | local genchain = { } | ||
for j = 1, | for j = 1, chain_length_per_period do | ||
-- Convert the accumulator into an index | -- Convert the accumulator into an index | ||
| Line 162: | Line 164: | ||
-- Add accidentals | -- Add accidentals | ||
-- This is negative if the genchain is descending | -- This is negative if the genchain is descending | ||
-- The | -- The upd_gens_per_period refers to the value u (or d for descending chains) in | ||
-- the UDP of up|dp. The first u notes reached by stacking up that many generators from the | -- the UDP of up|dp. The first u notes reached by stacking up that many generators from the | ||
-- root don't have accidentals, but the number of notes that don't have accidentals | -- root don't have accidentals, but the number of notes that don't have accidentals | ||
-- is actually u+1, since the root doesn't have accidentals either. | -- is actually u+1, since the root doesn't have accidentals either. | ||
local accidentals_to_add = 0 | local accidentals_to_add = 0 | ||
if j > | if j > upd_gens_per_period + 1 then | ||
accidentals_to_add = math.ceil((j - | accidentals_to_add = math.ceil((j - upd_gens_per_period - 1) / mossteps_per_period) | ||
end | end | ||
if not going_up then | if not going_up then | ||
| Line 193: | Line 195: | ||
end | end | ||
-- Helper function that | -- Helper function that decodes a scale degree given as a quantity of mossteps | ||
-- and a numeric quality (0=perf, 1=maj, -1=min, 2=aug, -2=dim, etc) into a | -- and a numeric quality (0=perf, 1=maj, -1=min, 2=aug, -2=dim, etc) into a | ||
-- scale degree | -- scale degree | ||
| Line 290: | Line 292: | ||
-- The following name rules are followed, and numeric values described above are used: | -- The following name rules are followed, and numeric values described above are used: | ||
-- - If an interval is the period (including the unison and equave), then the quality is perfect. | -- - If an interval is the period (including the unison and equave), then the quality is perfect. | ||
-- - | -- - For all other intervals, there are two sizes of major (large size) and minor (small size). | ||
-- - | -- - For bright generators of non-nL-ns mosses, the sizes are perfect and diminished instead. | ||
-- - | -- - For dark generators of non-nL-ns mosses, the sizes are augmented and perfect instead. | ||
-- - Alterations | -- - Generators of nL ns mosses use the terms major and minor instead. | ||
-- - | -- - Alterations denote raising a large interval by a chroma, or lowering a small interval by a chroma. | ||
-- | -- Since non-nL-ns mosses have augmented dark gen and diminished bright gen already, alterations | ||
function p.mos_degree_chain(input_mos, | -- for those are 2x-augmented and 2x-diminished intervals; these are encoded accoringly. | ||
-- Params are as follows: | |||
-- - input_mos: the input mos itself | |||
-- - chain_length_per_period: the number of degrees in the resulting chain. | |||
-- NOTE: if working in terms of "generators stacked after the root", add 1 to that value. | |||
-- - going_up - whether the chain is built on stacking up or down; true for up, false for down | |||
function p.mos_degree_chain(input_mos, chain_length_per_period, going_up) | |||
-- Default parameters for testing | -- Default parameters for testing | ||
--[[ | --[[ | ||
local input_mos = input_mos or mos.new(5, 2, 2) | local input_mos = input_mos or mos.new(5, 2, 2) | ||
local | local chain_length_per_period = chain_length_per_period or 10 | ||
local going_up = false | local going_up = false | ||
]]-- | ]]-- | ||
| Line 318: | Line 326: | ||
local chain_for_period = {} | local chain_for_period = {} | ||
for i = 1, | for i = 1, chain_length_per_period do | ||
-- Calculate mossteps | -- Calculate mossteps | ||