Module:TAMNAMS: Difference between revisions

Ganaram inukshuk (talk | contribs)
Added udp function (wip)
Ganaram inukshuk (talk | contribs)
Added/fleshed out UDP function
Line 432: Line 432:
if abbrev_format == "abbrev" or abbrev_format == "ABBREV" then
if abbrev_format == "abbrev" or abbrev_format == "ABBREV" then
return string.format("%s%d%ss", quality, step_count, mos_prefix)
return string.format("%s%d%sd", quality, step_count, mos_prefix)
elseif abbrev_format == "shortened" or abbrev_format == "SHORTENED" then
elseif abbrev_format == "shortened" or abbrev_format == "SHORTENED" then
return string.format("%s %d-%sd.", quality, step_count, mos_prefix)
return string.format("%s %d-%sd.", quality, step_count, mos_prefix)
Line 635: Line 635:
-- TODO: add altered scale degrees
-- TODO: add altered scale degrees
function p.mode_udp(input_mode, input_mos)
function p.mode_udp(input_mode, input_mos)
true_modes = mos.modes_by_brightness(input_mos)
true_modes = mos.modes_to_step_matrices(input_mos)
input_mode_as_step_matrix = mos.mode_to_step_matrix(input_mode)
-- For each mode, count the number of differences between each true mode
-- For each mode, count the number of differences between each true mode
Line 641: Line 642:
-- 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.
lowest_differences = #true_modes[1]
lowest_differences = mos.equave_step_count(input_mos)
bright_gens_down_per_period = 0
bright_gens_down_per_period = 0
closest_mode_as_step_matrix = {}
for i = 1, #true_modes do
for i = 1, #true_modes do
differences = 0
differences = 0
for j = 1, #input_mode do
current_true_mode = true_modes[i]
current_true_mos_step = string.sub(true_modes[i], j, j)
current_mode_step = string.sub(input_mode, j, j)
for j = 1, #input_mode_as_step_matrix do
mode_interval = input_mode_as_step_matrix[j]
true_interval = current_true_mode[j]
if current_true_mos_step ~= current_mode_step then
if not mos.interval_eq(mode_interval, true_interval) then
differences = differences + 1
differences = differences + 1
end
end
Line 657: Line 661:
bright_gens_down_per_period = i - 1
bright_gens_down_per_period = i - 1
lowest_differences = differences
lowest_differences = differences
closest_mode_as_step_matrix = current_true_mode
end
end
end
end
Line 674: Line 679:
alterations = ""
alterations = ""
closest_true_mos_mode = true_modes[bright_gens_down_per_period + 1]
closest_true_mos_mode = true_modes[bright_gens_down_per_period + 1]
if differences ~= 0 then
if differences > 0 then
for i = 1, #input_mode do
for i = 1, #input_mode_as_step_matrix do
mode_interval = mos.interval_from_step_sequence(string.sub(input_mode, 1, i))
mode_interval = input_mode_as_step_matrix[i]
true_interval = mos.interval_from_step_sequence(string.sub(closest_true_mos_mode, 1, i))
true_interval = closest_mode_as_step_matrix[i]
if not mos.interval_eq(mode_interval, true_interval) then
if not mos.interval_eq(mode_interval, true_interval) then
altered_degree = p.degree_quality(mode_interval, input_mos, "ABBREV")
alterations = alterations .. " " .. altered_degree
end
end
end
end
Line 693: Line 699:


function p.tester()
function p.tester()
local input_mos = mos.new(4,3)
mos_modes = mos.modes_by_brightness(mos.new(5,2))
local brightest_mode = mos.brightest_mode(input_mos)
output_ = ""
local interval_qualities = {}
for i = 1, #mos_modes do
 
output_ = output_ .. mos_modes[i] .. " " .. p.mode_udp(mos_modes[i], mos.new(5,2)) .. "\n"
local step_matrices = mos.modes_to_step_matrices(input_mos)
for i = 1, mos.equave_step_count(input_mos) do
local qualities = ""
for j = 1, #step_matrices[i] do
qualities = qualities .. p.decode_quality(step_matrices[i][j], input_mos, "shortened") .. " "
--qualities = qualities .. (step_matrices[i][j] ~= nil and "Y" or "N") .. " "
end
table.insert(interval_qualities, qualities)
end
end
output_ = output_ .. "LLsLsAs" .. " " .. p.mode_udp("LLsLsAs", mos.new(5,2))
return output_
return p.mode_udp(mos.new(), "LLsLsAs")
end
end


return p
return p