Module:MOS gamut: Difference between revisions

Ganaram inukshuk (talk | contribs)
Changed variable names for readability; fixed bug where multi-period mosses repeated the notes of the first period
Ganaram inukshuk (talk | contribs)
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, so in standard notation, instead of
-- This genchain is agnostic of notation, and only denotes the mossteps needed to reach
-- C, C#/Db, D etc, it's denoted  as N(0), N(0)+c/N(1)-c, N(1), etc
-- a note, followed by the number of chromas. For example, F# is reached going up 3
-- N(k) is the note name by itself (or the note name reached by going up g mossteps, where
-- mossteps and adding one chroma; Fb is the same except subtracting one chroma.
-- 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
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 = { ['Nk'] = root_offest, ['nc'] = 0 }
local root = { ['mossteps'] = root_offest, ['chromas'] = 0 }
local genchain = { root }
local genchain = { root }
Line 95: Line 94:
end
end
-- Get the final note name N(k)+nc
-- Get the final note name
local note_name = {}
local note_name = {}
note_name['Nk'] = index + root_offest -- The N(k) in N(k) notation
note_name['mossteps'] = index + root_offest -- Mossteps needed to reach a note
note_name['nc'] = accidentals_to_add -- How many chromas to add or subtract
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['Nk'] + 1, note['Nk'] + 1)
local note_symbol = string.sub(note_symbols, note['mossteps'] + 1, note['mossteps'] + 1)
local chroma_count = note['nc']
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['Nk'] + 1, note['Nk'] + 1)
local note_symbol = string.sub(note_symbols, note['mossteps'] + 1, note['mossteps'] + 1)
local chroma_count = note['nc'] * -1
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)