Module:MOS gamut: Difference between revisions
m Clarified the genchain function's params (genchain_init and genchain_length) is per period |
Changed variable names for readability; fixed bug where multi-period mosses repeated the notes of the first period |
||
| Line 35: | Line 35: | ||
-- Get the number of mossteps per period and equave | -- Get the number of mossteps per period and equave | ||
local mossteps_per_equave = input_mos.nL + input_mos.ns | local mossteps_per_equave = input_mos.nL + input_mos.ns | ||
local | local periods_per_equave = rat.gcd(input_mos.nL, input_mos.ns) | ||
local mossteps_per_period = mossteps_per_equave / | local mossteps_per_period = mossteps_per_equave / periods_per_equave | ||
--[[ | --[[ | ||
| Line 42: | Line 42: | ||
-- This is only necessary if the mos is multi-period | -- This is only necessary if the mos is multi-period | ||
local note_subsets = {} | local note_subsets = {} | ||
for i = 1, | for i = 1, periods_per_equave do | ||
local start_index = (i - 1) * mossteps_per_period + 1 | local start_index = (i - 1) * mossteps_per_period + 1 | ||
local stop_index = i * mossteps_per_period | local stop_index = i * mossteps_per_period | ||
| Line 52: | Line 52: | ||
-- Create the genchain for each period | -- Create the genchain for each period | ||
local genchains = {} | local genchains = {} | ||
for i = 1, | for i = 1, periods_per_equave do | ||
--local note_names = note_subsets[i] | --local note_names = note_subsets[i] | ||
| Line 73: | Line 73: | ||
--local root = string.sub(note_names, 1, 1) | --local root = string.sub(note_names, 1, 1) | ||
--local genchain = { root } | --local genchain = { root } | ||
local root = { ['Nk'] = | local root_offest = (i - 1) * mossteps_per_period -- To make sure that, across all periods, every note has a unique index | ||
local root = { ['Nk'] = root_offest, ['nc'] = 0 } | |||
local genchain = { root } | local genchain = { root } | ||
| Line 96: | Line 97: | ||
-- Get the final note name N(k)+nc | -- Get the final note name N(k)+nc | ||
local note_name = {} | local note_name = {} | ||
note_name['Nk'] = index | note_name['Nk'] = index + root_offest -- The N(k) in N(k) notation | ||
note_name['nc'] = accidentals_to_add -- How many chromas to add or subtract | note_name['nc'] = accidentals_to_add -- How many chromas to add or subtract | ||
| Line 118: | Line 119: | ||
-- Get the number of mossteps per period and equave | -- Get the number of mossteps per period and equave | ||
local mossteps_per_equave = input_mos.nL + input_mos.ns | local mossteps_per_equave = input_mos.nL + input_mos.ns | ||
local | local periods_per_equave = rat.gcd(input_mos.nL, input_mos.ns) | ||
local mossteps_per_period = mossteps_per_equave / | local mossteps_per_period = mossteps_per_equave / periods_per_equave | ||
-- Some default params will be different if the scalesig is 5L 2s | -- Some default params will be different if the scalesig is 5L 2s | ||
| Line 126: | Line 127: | ||
-- 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_default = mossteps_per_equave - | local generators_up_default = mossteps_per_equave - periods_per_equave | ||
if scale_sig == "5L 2s" then | if scale_sig == "5L 2s" then | ||
generators_up_default = 5 | generators_up_default = 5 | ||
| Line 158: | Line 159: | ||
-- by the number of periods will give the number of generators per period (u and d by | -- by the number of periods will give the number of generators per period (u and d by | ||
-- themselves) | -- themselves) | ||
local generators_down = mossteps_per_equave - generators_up - | local generators_down = mossteps_per_equave - generators_up - periods_per_equave | ||
-- How long is the inital genchain for notes without accidentals? | -- How long is the inital genchain for notes without accidentals? | ||
local gens_up_per_period = generators_up / | local gens_up_per_period = generators_up / periods_per_equave | ||
local gens_down_per_period = generators_down / | local gens_down_per_period = generators_down / periods_per_equave | ||
-- Get and simplify the step ratio | -- Get and simplify the step ratio | ||
| Line 172: | Line 173: | ||
-- How many large and small steps per period? | -- How many large and small steps per period? | ||
local x = input_mos.nL / | local x = input_mos.nL / periods_per_equave -- Large step count | ||
local y = input_mos.ns / | local y = input_mos.ns / periods_per_equave -- Small step count | ||
-- How many esteps are in the equave? Gamut does not include any notes reached by | -- How many esteps are in the equave? Gamut does not include any notes reached by | ||
-- increments smaller than a chroma, so if the step ratio is not simplified, the | -- increments smaller than a chroma, so if the step ratio is not simplified, the | ||
-- gamut returned will be for a simplified step ratio | -- gamut returned will be for a simplified step ratio | ||
local | local esteps_per_equave = input_mos.nL * num + input_mos.ns * den | ||
-- Similarly, how many esteps per period? | -- Similarly, how many esteps per period? | ||
local | local esteps_per_period = x * num + y * den | ||
-- How long should the genchain extend after the initial genchain? | -- How long should the genchain extend after the initial genchain? | ||
| Line 212: | Line 213: | ||
-- Create an empty gamut | -- Create an empty gamut | ||
local gamut = {} | local gamut = {} | ||
for i = 1, | for i = 1, esteps_per_equave + 1 do | ||
table.insert(gamut, "") | table.insert(gamut, "") | ||
end | end | ||
| Line 219: | Line 220: | ||
local bright_gen = mos.bright_gen(input_mos) | local bright_gen = mos.bright_gen(input_mos) | ||
local esteps_per_bright_gen = bright_gen['L'] * num + bright_gen['s'] * den | local esteps_per_bright_gen = bright_gen['L'] * num + bright_gen['s'] * den | ||
local esteps_per_dark_gen = | local esteps_per_dark_gen = esteps_per_period - esteps_per_bright_gen | ||
-- Add the notes to the gamut | -- Add the notes to the gamut | ||
for j = 1, | for j = 1, periods_per_equave do | ||
local bright_accumulator = 0 | local bright_accumulator = 0 | ||
for i = 1, #ascending_genchain[j] do | for i = 1, #ascending_genchain[j] do | ||
local index = (bright_accumulator % | local index = (bright_accumulator % esteps_per_period) + (j - 1) * esteps_per_period + 1 | ||
-- Convert the notationally agnostic form into a form that uses given notation | -- Convert the notationally agnostic form into a form that uses given notation | ||
| Line 238: | Line 239: | ||
local dark_accumulator = esteps_per_dark_gen | local dark_accumulator = esteps_per_dark_gen | ||
for i = 2, #descending_genchain[j] do | for i = 2, #descending_genchain[j] do | ||
local index = (dark_accumulator % | local index = (dark_accumulator % esteps_per_period) + (j - 1) * esteps_per_period + 1 | ||
-- Convert the notationally agnostic form into a form that uses given notation | -- Convert the notationally agnostic form into a form that uses given notation | ||
| Line 289: | Line 290: | ||
-- Get the number of mossteps per period and equave | -- Get the number of mossteps per period and equave | ||
local mossteps_per_equave = input_mos.nL + input_mos.ns | local mossteps_per_equave = input_mos.nL + input_mos.ns | ||
local | local periods_per_equave = rat.gcd(input_mos.nL, input_mos.ns) | ||
local mossteps_per_period = mossteps_per_equave / | local mossteps_per_period = mossteps_per_equave / periods_per_equave | ||
-- If certain params were left blank and the scalesig is 5L 2s, the default | -- If certain params were left blank and the scalesig is 5L 2s, the default | ||
| Line 298: | Line 299: | ||
-- 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 = mossteps_per_equave - | local generators_up = mossteps_per_equave - periods_per_equave | ||
if scale_sig == "5L 2s" then | if scale_sig == "5L 2s" then | ||
generators_up = 5 | generators_up = 5 | ||