Module:TAMNAMS: Difference between revisions

Ganaram inukshuk (talk | contribs)
Consolidated helper functions; rewrote preprocess functions; interval_quality() and degree_quality() added
Ganaram inukshuk (talk | contribs)
Bugfixed code for applying APd for root mosses
Line 376: Line 376:
local is_bright_gen = step_count % mos.period_step_count(input_mos) == mos.bright_gen_step_count(input_mos)
local is_bright_gen = step_count % mos.period_step_count(input_mos) == mos.bright_gen_step_count(input_mos)
local is_dark_gen  = step_count % mos.period_step_count(input_mos) == mos.dark_gen_step_count(input_mos)
local is_dark_gen  = step_count % mos.period_step_count(input_mos) == mos.dark_gen_step_count(input_mos)
-- If the interval is a period or generator of a non-root mos, then it's
-- perfectable.
local is_perfectable = (is_period or is_bright_gen or is_dark_gen) and not is_root_mos
-- Special case: APd does not apply to a root mos's (nL ns) generators;
-- Special case: APd does not apply to a root mos's (nL ns) generators;
-- instead, it's Mm.
-- instead, it's Mm.
local is_root_mos = input_mos.nL == input_mos.ns
local is_root_mos = input_mos.nL == input_mos.ns
-- Is perfectable? This is for intervals for which maj/min does not apply.
local is_perfectable = is_period or (is_bright_gen and not is_root_mos) or (is_bright_gen and not is_root_mos)
-- Get chroma count and adjust as needed
-- Get chroma count and adjust as needed
local chroma_count = 0
local chroma_count = 0
if is_perfectable then
if is_period then
if is_equave or is_period then
-- Chroma count 0 is the perfect size. This interval does not appear
-- Chroma count 0 is the perfect size. This interval does not appear
-- as any other size across all mos modes.
-- as any other size across all mos modes.
chroma_count = mos.interval_chroma_count(interval, input_mos)
chroma_count = mos.interval_chroma_count(interval, input_mos)
elseif is_bright_gen and not is_root_mos then
elseif is_bright_gen and not is_root_mos then
-- Chroma count 0 is the large size, and -1 the small size; these
-- Chroma count 0 is the large size, and -1 the small size; these
-- are perfect and diminished respectively.
-- are perfect and diminished respectively.
chroma_count = mos.interval_chroma_count(interval, input_mos)
chroma_count = mos.interval_chroma_count(interval, input_mos)
elseif is_dark_gen and not is_root_mos then
elseif is_dark_gen and not is_root_mos then
-- Chroma count 0 is the large size, and -1 the small size; these
-- Chroma count 0 is the large size, and -1 the small size; these
-- are augmented and perfect respectively. Since the perfect size
-- are augmented and perfect respectively. Since the perfect size
-- corresponds to a chroma count of -1, pass in -1 as the 3rd arg.
-- corresponds to a chroma count of -1, pass in -1 as the 3rd arg.
chroma_count = mos.interval_chroma_count(interval, input_mos, -1)
chroma_count = mos.interval_chroma_count(interval, input_mos, -1)
end
else
else
-- Chroma count 0 is the large size, and -1 the small size; these are
-- Chroma count 0 is the large size, and -1 the small size; these are
Line 510: Line 507:


function p.tester()
function p.tester()
--return p.lookup_step_ratio_range(rat.new(10, 1), rat.new(1, 0), true)
local input_mos = mos.new(4,4)
--return p.lookup_step_ratio_range(rat.new(6,5), rat.new(1,1), true)
local brightest_mode = mos.brightest_mode(input_mos)
local abbrev_code = "abbrev"
local interval_qualities = {}
local input_mos = mos.new(5,2)
--[[
for i = 1, #brightest_mode + 1 do
return
local substring = string.sub(brightest_mode, 0, i - 1)
p.chroma_count_to_nonperfectable_interval_quality( 4, abbrev_code) .. "\n" ..
local interval_vector = mos.interval_from_step_sequence(substring)
p.chroma_count_to_nonperfectable_interval_quality( 3, abbrev_code) .. "\n" ..
local interval_quality = p.interval_quality(interval_vector, input_mos, "abbrev")
p.chroma_count_to_nonperfectable_interval_quality( 2, abbrev_code) .. "\n" ..
table.insert(interval_qualities, interval_quality)
p.chroma_count_to_nonperfectable_interval_quality( 1, abbrev_code) .. "\n" ..
end
p.chroma_count_to_nonperfectable_interval_quality( 0, abbrev_code) .. "\n" ..
return interval_qualities
p.chroma_count_to_nonperfectable_interval_quality(-1, abbrev_code) .. "\n" ..
p.chroma_count_to_nonperfectable_interval_quality(-2, abbrev_code) .. "\n" ..
p.chroma_count_to_nonperfectable_interval_quality(-3, abbrev_code) .. "\n" ..
p.chroma_count_to_nonperfectable_interval_quality(-4, abbrev_code) .. "\n" ..
p.chroma_count_to_nonperfectable_interval_quality(-5, abbrev_code)
]]--
local output_string =
p.interval_quality({['L']= 6,['s']=-4}, input_mos, abbrev_code) .. "\n" ..
p.interval_quality({['L']= 5,['s']=-3}, input_mos, abbrev_code) .. "\n" ..
p.interval_quality({['L']= 4,['s']=-2}, input_mos, abbrev_code) .. "\n" ..
p.interval_quality({['L']= 3,['s']=-1}, input_mos, abbrev_code) .. "\n" ..
p.interval_quality({['L']= 2,['s']= 0}, input_mos, abbrev_code) .. "\n" ..
p.interval_quality({['L']= 1,['s']= 1}, input_mos, abbrev_code) .. "\n" ..
p.interval_quality({['L']= 0,['s']= 2}, input_mos, abbrev_code) .. "\n" ..
p.interval_quality({['L']=-1,['s']= 3}, input_mos, abbrev_code) .. "\n" ..
p.interval_quality({['L']=-2,['s']= 4}, input_mos, abbrev_code) .. "\n" ..
p.interval_quality({['L']=-3,['s']= 5}, input_mos, abbrev_code)
return p.decode_quality({['L']=2,['s']=1}, input_mos, abbrev_code)
end
end


return p
return p