Module:TAMNAMS: Difference between revisions

Ganaram inukshuk (talk | contribs)
m Fixed bug where if the closest mode is the brightest mode, the closest_mode_as_step_matrix would have an empty table
Ganaram inukshuk (talk | contribs)
Added experimental code for handling step patterns that exceed the equave
Line 679: Line 679:
-- multi-period and single-period respectively.
-- multi-period and single-period respectively.
-- If only u is known, then d = p - u - 1.
-- If only u is known, then d = p - u - 1.
-- If only d is known, then u = p - d - 1. (Basically, p = u + d + 1.)
-- If only d is known, then u = p - d - 1. (Basically, u + d + 1 = steps/p.)
function p.udp(gens_up_per_period, gens_down_per_period, periods)
function p.udp(gens_up_per_period, gens_down_per_period, periods)
if periods == 1 then
if periods == 1 then
Line 744: Line 744:
--  period of repetition is needed, as other modes reached by rotation after
--  period of repetition is needed, as other modes reached by rotation after
--  that are literally redendant.
--  that are literally redendant.
function p.mode_rotation_udps(input_mode, input_mos, mos_abbrev)
-- - If the step pattern is for a modmos, then the closest brightest mode will
--  be returned by default. The darkest can be returned instead.
function p.mode_rotation_udps(input_mode, input_mos, mos_abbrev, use_brightest_mode_search)
local use_brightest_mode_search = use_brightest_mode_search == nil or use_brightest_mode_search
local modes = mos.mode_rotations(input_mode)
local modes = mos.mode_rotations(input_mode)
local udps = {}
local udps = {}
for i = 1, #modes do
for i = 1, #modes do
table.insert(udps, p.mode_udp(modes[i], input_mos, mos_abbrev))
table.insert(udps, p.mode_udp(modes[i], input_mos, mos_abbrev, use_brightest_mode_search))
end
end
return udps
return udps
Line 759: Line 762:
-- by its altered scale degrees. Alterations require a mos abbrev, which is
-- by its altered scale degrees. Alterations require a mos abbrev, which is
-- automatically looked up, defaulting to "m" if no abbrev can be found.
-- automatically looked up, defaulting to "m" if no abbrev can be found.
function p.mode_udp(input_mode, input_mos, mos_abbrev)
function p.mode_udp(input_mode, input_mos, mos_abbrev, use_brightest_mode_search)
local use_brightest_mode_search = use_brightest_mode_search == nil or use_brightest_mode_search
local mos_abbrev = mos_abbrev or p.lookup_abbrev(input_mos) or "m"
local mos_abbrev = mos_abbrev or p.lookup_abbrev(input_mos) or "m"
local true_modes = mos.modes_to_step_matrices(input_mos)
local true_modes = mos.modes_to_step_matrices(input_mos)
Line 768: Line 772:
-- If the number of diffs is ever zero, then the entered mode was a true-mos
-- If the number of diffs is ever zero, then the entered mode was a true-mos
-- mode and has zero alterations.
-- mode and has zero alterations.
local lowest_differences = mos.equave_step_count(input_mos)
local lowest_differences = #input_mode_as_step_matrix
local bright_gens_down_per_period = 0
local bright_gens_down_per_period = 0
local closest_mode_as_step_matrix = true_modes[1]
local closest_mode_as_step_matrix = true_modes[1]
Line 777: Line 781:
for j = 1, #input_mode_as_step_matrix do
for j = 1, #input_mode_as_step_matrix do
local mode_interval = input_mode_as_step_matrix[j]
local mode_interval = input_mode_as_step_matrix[j]
local true_interval = current_true_mode[j]  
local true_interval = current_true_mode[j]
-- If a true interval is an extra-equave interval, get the
-- corresponding equave-reduced interval and add back an equave
if true_interval == nil then
true_interval = current_true_mode[(j-1) % mos.equave_step_count(input_mos) + 1]
true_interval = mos.interval_add(true_interval, mos.interval_mul(mos.equave(input_mos), math.floor((j-1)/mos.equave_step_count(input_mos))))
end
if not mos.interval_eq(mode_interval, true_interval) then
if not mos.interval_eq(mode_interval, true_interval) then
Line 784: Line 795:
end
end
if differences < lowest_differences then
if use_brightest_mode_search then
bright_gens_down_per_period = i - 1
if differences < lowest_differences then
lowest_differences = differences
bright_gens_down_per_period = i - 1
closest_mode_as_step_matrix = current_true_mode
lowest_differences = differences
closest_mode_as_step_matrix = current_true_mode
end
else
if differences <= lowest_differences then
bright_gens_down_per_period = i - 1
lowest_differences = differences
closest_mode_as_step_matrix = current_true_mode
end
end
end
end
end
Line 804: Line 823:
mode_interval = input_mode_as_step_matrix[i]
mode_interval = input_mode_as_step_matrix[i]
true_interval = closest_mode_as_step_matrix[i]
true_interval = closest_mode_as_step_matrix[i]
-- If a true interval is an extra-equave interval, get the
-- corresponding equave-reduced interval and add back an equave
if true_interval == nil then
true_interval = closest_mode_as_step_matrix[(i-1) % mos.equave_step_count(input_mos) + 1]
true_interval = mos.interval_add(true_interval, mos.interval_mul(mos.equave(input_mos), math.floor((i-1)/mos.equave_step_count(input_mos))))
end
if not mos.interval_eq(mode_interval, true_interval) then
if not mos.interval_eq(mode_interval, true_interval) then
Line 828: Line 854:
output_ = output_ .. "LLsLsAs" .. " " .. p.mode_udp("LLsLsAs", mos.new(5,2))
output_ = output_ .. "LLsLsAs" .. " " .. p.mode_udp("LLsLsAs", mos.new(5,2))
return p.mode_rotation_udps("LLLsLLs", mos.new(5,2), "m")
return p.mode_rotation_udps("LLsLLsLLsLL", mos.new(5, 2), "m")
--return p.degree_quality({4, -1}, mos.new(5,2), "ABBREV", 'm')
--return p.degree_quality({4, -1}, mos.new(5,2), "ABBREV", 'm')