Module:TAMNAMS: Difference between revisions

Ganaram inukshuk (talk | contribs)
Adjusted prefix lookup to use abbrevs as needed
Ganaram inukshuk (talk | contribs)
Added udp function (wip)
Line 624: Line 624:
return quality
return quality
end
--------------------------------------------------------------------------------
------------------------- MODE NOTATION FUNCTIONS ------------------------------
--------------------------------------------------------------------------------
-- Given a string that represents a mode, return its udp.
-- If a mode is for a modmos, it will return the closest brightest mode followed
-- by its altered scale degrees.
-- TODO: add altered scale degrees
function p.mode_udp(input_mode, input_mos)
true_modes = mos.modes_by_brightness(input_mos)
-- For each mode, count the number of differences between each true mode
-- and the entered mode and keep track of which mode has the fewest diffs.
-- If the number of diffs is ever zero, then the entered mode was a true-mos
-- mode and has zero alterations.
lowest_differences = #true_modes[1]
bright_gens_down_per_period = 0
for i = 1, #true_modes do
differences = 0
for j = 1, #input_mode do
current_true_mos_step = string.sub(true_modes[i], j, j)
current_mode_step = string.sub(input_mode, j, j)
if current_true_mos_step ~= current_mode_step then
differences = differences + 1
end
end
if differences < lowest_differences then
bright_gens_down_per_period = i - 1
lowest_differences = differences
end
end
-- Produce the UDP (as text) for the mode, formatted as up|dp(p) for multi-
-- period mosses, or u|d for single-period mosses.
period_count = mos.period_count(input_mos)
dark_gens_down_per_period = mos.period_step_count(input_mos) - 1 - bright_gens_down_per_period
udp = ""
if period_count == 1 then
udp = string.format("%s%%&124;%s", dark_gens_down_per_period, bright_gens_down_per_period)
else
udp = string.format("%s%%&124;%s(%s)", dark_gens_down_per_period * period_count, bright_gens_down_per_period * period_count, period_count)
end
-- Produce the list of alterations, if the mode is for a modmos.
alterations = ""
closest_true_mos_mode = true_modes[bright_gens_down_per_period + 1]
if differences ~= 0 then
for i = 1, #input_mode do
mode_interval = mos.interval_from_step_sequence(string.sub(input_mode, 1, i))
true_interval = mos.interval_from_step_sequence(string.sub(closest_true_mos_mode, 1, i))
if not mos.interval_eq(mode_interval, true_interval) then
end
end
end
return udp .. alterations
end
end


Line 644: Line 706:
table.insert(interval_qualities, qualities)
table.insert(interval_qualities, qualities)
end
end
return interval_qualities
return p.mode_udp(mos.new(), "LLsLsAs")
end
end


return p
return p