Module:MOS gamut: Difference between revisions

Ganaram inukshuk (talk | contribs)
Simplified output so it's the gamut by itself
Ganaram inukshuk (talk | contribs)
m Clarified the genchain function's params (genchain_init and genchain_length) is per period
Line 13: Line 13:
-- is a single genchain.
-- is a single genchain.
-- This genchain is agnostic of notation, so in standard notation, instead of
-- This genchain is agnostic of notation, so in standard notation, instead of
-- C, C#/Db, D etc, it's denoted  as N(0), N(0)+c/N(1)-c, N(1)
-- C, C#/Db, D etc, it's denoted  as N(0), N(0)+c/N(1)-c, N(1), etc
-- What is returned is the number in the parentheses (k, accessed as index) and
-- N(k) is the note name by itself (or the note name reached by going up g mossteps, where
-- how many chromas to add (an integer value)
-- g is the gen in mossteps) and nc is how many sharps (flats if n is negative) to add
-- 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
-- - genchain_init - how many named pitches per period are there without accidentals added?
-- - genchain_init_per_period - how many named pitches per period are there without accidentals added?
--  This is either the value u or d for the UDP of up|dp.
--  This is either the value u or d for the UDP of up|dp.
-- - genchain_length - how many generators should the genchain extend after the root?
-- - genchain_length_per_period - how many generators should the genchain extend after the root?
-- - 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_genchain(input_mos, genchain_init, genchain_length, going_up)
function p.mos_genchain(input_mos, genchain_init_per_period, genchain_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 genchain_init = genchain_init or 5
local genchain_init_per_period = genchain_init_per_period or 5
local genchain_length = genchain_length or 10
local genchain_length_per_period = genchain_length_per_period or 10
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 77: Line 77:
-- Create the rest of the genchain
-- Create the rest of the genchain
for j = 1, genchain_length do
for j = 1, genchain_length_per_period do
-- Increment the index by the generator
-- Increment the index by the generator
accumulator = accumulator + gen_in_mossteps
accumulator = accumulator + gen_in_mossteps
Line 87: Line 87:
-- This is negative if the genchain is descending
-- This is negative if the genchain is descending
local accidentals_to_add = 0
local accidentals_to_add = 0
if j > genchain_init then
if j > genchain_init_per_period then
accidentals_to_add = math.ceil((j - genchain_init) / mossteps_per_period)
accidentals_to_add = math.ceil((j - genchain_init_per_period) / mossteps_per_period)
end
end
if not going_up then
if not going_up then
Line 201: Line 201:
end
end
-- How long are the genchains?
-- How long are the genchains? Length is per period
local ascending_genchain_length = gens_up_per_period + genchain_extend
local ascending_genchain_length = gens_up_per_period + genchain_extend
local descending_genchain_length = gens_down_per_period + genchain_extend
local descending_genchain_length = gens_down_per_period + genchain_extend