Module:MOS degrees: Difference between revisions
Added decoupled preprocess function for scale degrees; for future rewrite that allows omission of note names |
Added decoupled note names preprocess function; new functions to be added later |
||
| Line 156: | Line 156: | ||
return rows | return rows | ||
end | |||
-- Helper function; FOR FUTURE REWRITE | |||
-- Creates the column for the note name | |||
-- Decoupled degree and note name functions allow note names being omitted. | |||
function p.preprocess_note_names(input_mos, udp, note_symbols, sharp_symbol, flat_symbol, asc_chain_length, des_chain_length) | |||
-- Test parameters | |||
--[[ | |||
local input_mos = input_mos or mos.new(5, 2, 2) | |||
local udp = udp or { 5, 1 } | |||
local note_symbols = note_symbols or "CDEFGAB" | |||
local sharp_symbol = sharp_symbol or "#" | |||
local flat_symbol = flat_symbol or "b" | |||
local asc_chain_length = input_mos.nL * 2 + input_mos.ns | |||
local des_chain_length = input_mos.nL * 2 + input_mos.ns | |||
]]-- | |||
-- Get the number of mossteps per period and equave | |||
local mossteps_per_equave = 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 | |||
-- How long are the initial genchain lengths? (These correspond to the UDP) | |||
local gens_up_per_period = udp[1] / periods_per_equave | |||
local gens_dn_per_period = udp[2] / periods_per_equave | |||
-- Get the genchains | |||
local asc_genchain = mosnot.mos_nomacc_chain(input_mos, gens_up_per_period, asc_chain_length, true) | |||
local des_genchain = mosnot.mos_nomacc_chain(input_mos, gens_dn_per_period, des_chain_length, false) | |||
-- Calculate the entries for each cell | |||
local column = {} | |||
for i = 1, periods_per_equave do | |||
-- Add degrees from ascending chain | |||
for j = 1, asc_chain_length do | |||
local mossteps = asc_genchain[i][j]['mossteps'] | |||
local chromas = asc_genchain[i][j]['chromas'] | |||
-- Find the note name | |||
local note_symbol = string.sub(note_symbols, mossteps + 1, mossteps + 1) | |||
local note_name = mosnot.mosstep_and_chroma_to_note_name(mossteps, chromas, note_symbol, sharp_symbol) | |||
table.insert(column, note_name) | |||
end | |||
-- Calculate the stop value for the for loop as being 1 or 2, depending | |||
-- on whether this is the last period or not | |||
local stop_value = 1 | |||
if i ~= periods_per_equave then | |||
stop_value = stop_value + 1 | |||
end | |||
-- Add degrees from descending chain | |||
-- The descending chain differs from the ascending chain: | |||
-- - The descending chain should follow after the ascending chain. | |||
-- - The descending chain's entries should be added backwards and skip | |||
-- the root. | |||
-- - This way, if the mos is multi-period, the root of the next period's | |||
-- ascending chain (which is the same as the current period's descend- | |||
-- ing chain) won't be added twice. | |||
-- - If the period is the last period, add the root as the equave. | |||
for j = des_chain_length, stop_value, -1 do | |||
local mossteps = des_genchain[i][j]['mossteps'] | |||
local chromas = des_genchain[i][j]['chromas'] | |||
-- Find the note name | |||
-- If the mosstep is the root of the period, add a period to it | |||
local note_symbol = string.sub(note_symbols, mossteps + 1, mossteps + 1) | |||
if mossteps % mossteps_per_period == 0 then | |||
mossteps = mossteps + mossteps_per_period | |||
end | |||
local note_name = mosnot.mosstep_and_chroma_to_note_name(mossteps, chromas, note_symbol, flat_symbol) | |||
table.insert(column, note_name) | |||
end | |||
end | |||
return column | |||
end | end | ||
-- Helper function; FOR FUTURE REWRITE | -- Helper function; FOR FUTURE REWRITE | ||
-- Creates the column for the degree name | -- Creates the column for the degree name | ||
-- Decoupled degree | -- Decoupled degree and note name functions allow note names being omitted. | ||
function p.preprocess_degrees(input_mos, asc_chain_length, des_chain_length, prefix, notation) | function p.preprocess_degrees(input_mos, asc_chain_length, des_chain_length, prefix, notation) | ||
-- Test parameters | -- Test parameters | ||
| Line 193: | Line 271: | ||
end | end | ||
table.insert(column, degree_name) | |||
table.insert(column, | |||
end | end | ||
| Line 232: | Line 309: | ||
end | end | ||
table.insert(column, degree_name) | |||
table.insert(column, | |||
end | end | ||
end | end | ||