Module:MOS gamut: Difference between revisions
Changed variable names for readability; fixed bug where multi-period mosses repeated the notes of the first period |
Made the genchain function's output easier to read (mossteps and chromas) |
||
| Line 12: | Line 12: | ||
-- denote the named pitch. For the single-period case, it's a size-1 array whose element | -- denote the named pitch. For the single-period case, it's a size-1 array whose element | ||
-- is a single genchain. | -- is a single genchain. | ||
-- This genchain is agnostic of notation, | -- This genchain is agnostic of notation, and only denotes the mossteps needed to reach | ||
-- | -- a note, followed by the number of chromas. For example, F# is reached going up 3 | ||
-- mossteps and adding one chroma; Fb is the same except subtracting one chroma. | |||
-- | |||
-- 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 | ||
| Line 74: | Line 73: | ||
--local genchain = { root } | --local genchain = { root } | ||
local root_offest = (i - 1) * mossteps_per_period -- To make sure that, across all periods, every note has a unique index | local root_offest = (i - 1) * mossteps_per_period -- To make sure that, across all periods, every note has a unique index | ||
local root = { [' | local root = { ['mossteps'] = root_offest, ['chromas'] = 0 } | ||
local genchain = { root } | local genchain = { root } | ||
| Line 95: | Line 94: | ||
end | end | ||
-- Get the final note name | -- Get the final note name | ||
local note_name = {} | local note_name = {} | ||
note_name[' | note_name['mossteps'] = index + root_offest -- Mossteps needed to reach a note | ||
note_name[' | note_name['chromas'] = accidentals_to_add -- How many chromas | ||
-- Add the note name | -- Add the note name | ||
| Line 230: | Line 229: | ||
-- Convert the notationally agnostic form into a form that uses given notation | -- Convert the notationally agnostic form into a form that uses given notation | ||
local note = ascending_genchain[j][i] | local note = ascending_genchain[j][i] | ||
local note_symbol = string.sub(note_symbols, note[' | local note_symbol = string.sub(note_symbols, note['mossteps'] + 1, note['mossteps'] + 1) | ||
local chroma_count = note[' | local chroma_count = note['chromas'] | ||
local note_name = note_symbol .. string.rep(chroma_plus_symbol, chroma_count) | local note_name = note_symbol .. string.rep(chroma_plus_symbol, chroma_count) | ||
| Line 243: | Line 242: | ||
-- Convert the notationally agnostic form into a form that uses given notation | -- Convert the notationally agnostic form into a form that uses given notation | ||
local note = descending_genchain[j][i] | local note = descending_genchain[j][i] | ||
local note_symbol = string.sub(note_symbols, note[' | local note_symbol = string.sub(note_symbols, note['mossteps'] + 1, note['mossteps'] + 1) | ||
local chroma_count = note[' | local chroma_count = note['chromas'] * -1 | ||
local note_name = note_symbol .. string.rep(chroma_minus_symbol, chroma_count) | local note_name = note_symbol .. string.rep(chroma_minus_symbol, chroma_count) | ||