Module:TAMNAMS: Difference between revisions

Ganaram inukshuk (talk | contribs)
No edit summary
Ganaram inukshuk (talk | contribs)
Added encoder function for mossteps
Line 4: Line 4:
local mos = require('Module:MOS')
local mos = require('Module:MOS')
local rat = require('Module:Rational')
local rat = require('Module:Rational')
local utils = require('Module:Utils')
local p = {}
local p = {}
--------------------------------------------------------------------------------
------------------------------- LOOKUP TABLES ----------------------------------
--------------------------------------------------------------------------------


-- Lookup table for tamnams step ratios
-- Lookup table for tamnams step ratios
Line 193: Line 198:
['9L 1s'] = 'si'
['9L 1s'] = 'si'
}
}
--------------------------------------------------------------------------------
----------------------------- LOOKUP FUNCTIONS ---------------------------------
--------------------------------------------------------------------------------


-- Function for looking up a mos's name (octave-equivalent mosses only)
-- Function for looking up a mos's name (octave-equivalent mosses only)
Line 255: Line 264:
function p.lookup_named_ancestor(input_mos)
function p.lookup_named_ancestor(input_mos)
end
end
--------------------------------------------------------------------------------
------------------------------ HELPER FUNCTIONS --------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-------------------------- ENCODE/DECODE FUNCTIONS -----------------------------
--------------------------------------------------------------------------------
-- 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
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
--------------------------------------------------------------------------------
----------------------------- TESTER FUNCTION ----------------------------------
--------------------------------------------------------------------------------


function p.tester()
function p.tester()