Module:TAMNAMS: Difference between revisions

Ganaram inukshuk (talk | contribs)
mNo edit summary
Ganaram inukshuk (talk | contribs)
Removed encode function as it's part of module:mos now; removed hyphen from prefixes since the more common case is prepending it, not having it standalone
Line 119: Line 119:
-- And prefixes
-- And prefixes
p.tamnams_prefix = {
p.tamnams_prefix = {
['1L 1s'] = 'monwd-',
['1L 1s'] = 'monwd',
['2L 2s'] = 'biwd-',
['2L 2s'] = 'biwd',
['1L 5s'] = 'amech-',
['1L 5s'] = 'amech',
['2L 4s'] = 'mal-',
['2L 4s'] = 'mal',
['3L 3s'] = 'triwd-',
['3L 3s'] = 'triwd',
['4L 2s'] = 'citro-',
['4L 2s'] = 'citro',
['5L 1s'] = 'mech-',
['5L 1s'] = 'mech',
['1L 6s'] = 'on-',
['1L 6s'] = 'on',
['2L 5s'] = 'pel-',
['2L 5s'] = 'pel',
['3L 4s'] = 'mosh-',
['3L 4s'] = 'mosh',
['4L 3s'] = 'smi-',
['4L 3s'] = 'smi',
['5L 2s'] = 'dia-',
['5L 2s'] = 'dia',
['6L 1s'] = 'arch-',
['6L 1s'] = 'arch',
['1L 7s'] = 'apine-',
['1L 7s'] = 'apine',
['2L 6s'] = 'subar-',
['2L 6s'] = 'subar',
['3L 5s'] = 'check-',
['3L 5s'] = 'check',
['4L 4s'] = 'tetrawd-',
['4L 4s'] = 'tetrawd',
['5L 3s'] = 'oneiro-',
['5L 3s'] = 'oneiro',
['6L 2s'] = 'ek-',
['6L 2s'] = 'ek',
['7L 1s'] = 'pine-',
['7L 1s'] = 'pine',
['1L 8s'] = 'ablu-',
['1L 8s'] = 'ablu',
['2L 7s'] = 'bal-',
['2L 7s'] = 'bal',
['3L 6s'] = 'cher-',
['3L 6s'] = 'cher',
['4L 5s'] = 'gram-',
['4L 5s'] = 'gram',
['5L 4s'] = 'cthon-',
['5L 4s'] = 'cthon',
['6L 3s'] = 'hyru-',
['6L 3s'] = 'hyru',
['7L 2s'] = 'arm-',
['7L 2s'] = 'arm',
['8L 1s'] = 'blu-',
['8L 1s'] = 'blu',
['1L 9s'] = 'asina-',
['1L 9s'] = 'asina',
['2L 8s'] = 'jara-',
['2L 8s'] = 'jara',
['3L 7s'] = 'seph-',
['3L 7s'] = 'seph',
['4L 6s'] = 'lime-',
['4L 6s'] = 'lime',
['5L 5s'] = 'pentawd-',
['5L 5s'] = 'pentawd',
['6L 4s'] = 'lem-',
['6L 4s'] = 'lem',
['7L 3s'] = 'dico-',
['7L 3s'] = 'dico',
['8L 2s'] = 'tara-',
['8L 2s'] = 'tara',
['9L 1s'] = 'sina-'
['9L 1s'] = 'sina'
}
}


Line 268: Line 268:
------------------------------ HELPER FUNCTIONS --------------------------------
------------------------------ HELPER FUNCTIONS --------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Line 273: Line 276:
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


-- Function that encodes a sequence of mossteps into a vector.
-- Step sequences of L's and s's are encoded into a vector containing how many
-- L's and s's there are. Steps that denote alterations by a chroma are allowed
-- since they can be expressed as the sum (or difference) between multiple large
-- and small steps:
-- - c: a single chroma; the difference between a large and small step, or L - s
-- - A: an augmented step; a large step plus a chroma, or 2L + s
-- - d: a diminished step, a small step minus a chroma, or -L + 2s
-- Proposed encoding (work-in-progress):
--  2 = Large size +1 chroma OR perfect size +2 chromas
--  1 = Large size OR perfect size +1 chroma
--  0 = Perfect size; reserved for period intervals
-- -1 = Small size OR perfect size -1 chroma
-- -2 = Small size -1 chroma OR perfect size -2 chromas
-- Large/small is translated to major/minor for nonperfectable intervals,
-- perfect/diminished for bright gens, and augmented/perfect for dark gens. The
-- value denotes the number of chromas from the perfect size (for perfectables)
-- or either the large or small size.
-- Encoding can continue for any number of chromas; only [-2, 2] is shown for
-- demonstration.
-- Encoding can be adapted for use with mos notation (EG, diamond-mos), where
-- the values denote how many chromas are added/subtracted.
function p.encode_mosstep_sequence_to_vector(input_mos, mosstep_sequence)
local input_mos = input_mos or mos.new(5, 2)
local mosstep_sequence = mosstep_sequence or "LLAALLAA"


local encoding = {
 
--['Is period'] = #mosstep_sequence % utils._gcd(5, 2) == 0,
['L'] = 0,
['s'] = 0
}
local large_step_count = 0
local small_step_count = 0
for i = 1, #mosstep_sequence do
local step = string.sub(mosstep_sequence, i, i)
if step == "L" then
large_step_count = large_step_count + 1
elseif step == "s" or step == "S" then
small_step_count = small_step_count + 1
elseif step == "c" then
large_step_count = large_step_count + 1
small_step_count = small_step_count - 1
elseif step == "A" then
large_step_count = large_step_count + 2
small_step_count = small_step_count - 1
elseif step == "d" then
large_step_count = large_step_count - 1
small_step_count = small_step_count + 2
end
end
encoding['L'] = large_step_count
encoding['s'] = small_step_count
return encoding
end


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------