Module:MOS mode degrees: Difference between revisions

Ganaram inukshuk (talk | contribs)
Removed unused functions
Ganaram inukshuk (talk | contribs)
Updated comments; condensed modmos and mos functions back into one since code is near-identical
Line 14: Line 14:
p.cell_color_sm_altered_size = "#F8CBAD"
p.cell_color_sm_altered_size = "#F8CBAD"


-- A simplified version of calculate_row_colors
-- Finds the row color for a single cell
-- Finds the row color for a single cell
function p.cell_color(interval, input_mos)
function p.cell_color(interval, input_mos)
Line 51: Line 49:


-- Create a table of a mos's degrees
-- Create a table of a mos's degrees
function p._mos_mode_degrees(input_mos, mos_prefix, mode_names, use_default_mode_names)
-- If a step pattern is provided, it's assumed to be that of a modmos
function p._mos_mode_degrees(input_mos, mos_prefix, mode_names, use_default_mode_names, step_pattern)
local is_true_mos = step_pattern == nil
local input_mos = input_mos or mos.new(5, 2)
local input_mos = input_mos or mos.new(5, 2)
local mos_prefix = mos_prefix or "mos"
local mos_prefix = mos_prefix or "mos"
Line 58: Line 59:
-- Get the modes as strings and step vectors
-- Get the modes as strings and step vectors
local step_patterns = mos.modes_by_brightness(input_mos)
local step_patterns = {}
local step_matrices = mos.modes_to_step_matrices(input_mos)
local step_matrices = {}
if is_true_mos then
step_patterns = mos.modes_by_brightness(input_mos)
step_matrices = mos.modes_to_step_matrices(input_mos)
else
step_patterns = mos.mode_rotations(step_pattern)
step_matrices = mos.mode_rotations_to_step_matrices(step_pattern)
end
-- Get the brightness (UDP) and rotational orderings
local udps = {}
local cpos = {}
if is_true_mos then
udps = tamnams.mos_mode_udps(input_mos)
cpos = tamnams.mos_mode_cpos(input_mos)
else
udps = tamnams.mode_rotation_udps(step_pattern, input_mos)
for i = 1, #udps do
table.insert(cpos, i)
end
end
-- Get the scale sig
-- Get the scale sig
local scale_sig = mos.as_string(input_mos)
local scale_sig = mos.as_string(input_mos)
-- Get the brightness (UDP) and rotational orderings
local brightness_order = tamnams.mos_mode_udps(input_mos)
local rotational_order = tamnams.mos_mode_cpos(input_mos)


-- Equave step count; needed for degree column count
-- Equave step count; needed for degree column count
Line 73: Line 90:
-- Create table
-- Create table
local result = "{| class=\"wikitable sortable\"\n"
local result = "{| class=\"wikitable sortable\"\n"
.. string.format("|+ style=\"font-size: 105%%;\" | Scale degree qualities of %s modes\n", scale_sig)
-- Add table headers for first row
if is_true_mos then
.. "! rowspan=\"2\" | UDP "
result = result .. string.format("|+ style=\"font-size: 105%%;\" | Scale degree qualities of %s modes\n", scale_sig)
.. "!! rowspan=\"2\" | Rotational Order "
else
.. "!! rowspan=\"2\" | Step pattern"
result = result .. string.format("|+ style=\"font-size: 105%%;\" | Scale degree qualities of %s modes (%s)\n", scale_sig, step_pattern)
-- Add mode names if present
local mode_names_given = (mode_names ~= nil and #mode_names == #step_patterns) or use_default_mode_names
if mode_names_given then
result = result .. " !! rowspan=\"2\" class=\"unsortable\" | Mode names"
end
-- Add header for scale degrees
result = result .. string.format(" !! colspan=\"%d\" class=\"unsortable\" | Scale degree (%sdegree)\n", equave_step_count + 1, mos_prefix)
-- Add second row of headers
result = result .. "|- class=\"unsortable\"\n"
.. "! 0"
for i = 1, equave_step_count do
result = result .. string.format(" !! %d", i)
end
result = result .. "\n"
-- Add table contents
for i = 1, #step_patterns do
result = result .. "|-\n"
-- Add brightness order (as UDP), rotational order, and step pattern
.. string.format("| %s || %s || %s", brightness_order[i], rotational_order[i], step_patterns[i])
-- Add mode name if given
if mode_names_given then
if use_default_mode_names then
result = result .. string.format(" || %s %s", scale_sig, brightness_order[i])
else
result = result .. string.format(" || %s", mode_names[i])
end
end
-- Add scale degrees with cell coloring
for j = 1, #step_matrices[i] do
local current_interval = step_matrices[i][j]
local degree_quality = tamnams.decode_quality(current_interval, input_mos, "shortened")
local cell_color = p.cell_color(current_interval, input_mos)
local style_code = cell_color == p.cell_color_none and "" or string.format("style=\"background: %s;\" | ", cell_color)
result = result .. string.format(" || %s%s", style_code, degree_quality)
end
result = result .. "\n"
end
end
-- End of table
result = result .. "|}"
return result
end
-- Create a table of a modmos's degrees
function p._modmos_mode_degrees(input_mos, mos_prefix, step_pattern, mode_names, use_default_mode_names)
local input_mos = input_mos or mos.new(5, 2)
local mos_prefix = mos_prefix or "mos"
local step_pattern = step_pattern or "LsLLsAs"
local mode_names = mode_names or nil
local use_default_mode_names = use_default_mode_names == 1
-- Get the modes and step matrices for the modmos
local step_patterns = mos.mode_rotations(step_pattern)
local step_matrices = mos.mode_rotations_to_step_matrices(step_pattern)
-- Get the scale sig
local scale_sig = mos.as_string(input_mos)
-- Get the UDPs (with alterations)
local udps = tamnams.mode_rotation_udps(step_pattern, input_mos)
-- Equave step count; needed for degree column count
local equave_step_count = mos.equave_step_count(input_mos)
-- Create table
local result = '{| class="wikitable sortable"\n'
local result = result .. string.format("|+ style=\"font-size: 105%%;\" | Scale degree qualities of %s modes (step pattern of %s)\n", scale_sig, step_pattern)
-- Add table headers for first row
-- Add table headers for first row
-- Headers should be on their own line for ease of reading code
result = result
.. "! rowspan=\"2\" | UDP and alterations "
.. "! rowspan=\"2\" | UDP " .. (is_true_mos and "" or " and alterations ")
.. "!! rowspan=\"2\" | Rotational Order "
.. "!! rowspan=\"2\" | Rotational Order "
.. "!! rowspan=\"2\" | Step pattern"
.. "!! rowspan=\"2\" | Step pattern"
Line 187: Line 126:
-- Add brightness order (as UDP), rotational order, and step pattern
-- Add brightness order (as UDP), rotational order, and step pattern
.. string.format("| %s || %s || %s", udps[i], i, step_patterns[i])
.. string.format("| %s || %s || %s", udps[i], cpos[i], step_patterns[i])
-- Add mode name if given
-- Add mode name if given
Line 218: Line 157:


-- Function to be called as part of a template
-- Function to be called as part of a template
-- Note that there are two "main" functions: one for mosses, one for modmosses
-- Whichever is called is based on the step pattern entered
function p.mos_mode_degrees(frame)
function p.mos_mode_degrees(frame)
-- Default param for input mos is 5L 2s
-- Default param for input mos is 5L 2s
Line 272: Line 209:
result = p._mos_mode_degrees(input_mos, mos_prefix, mode_names, use_default_names)
result = p._mos_mode_degrees(input_mos, mos_prefix, mode_names, use_default_names)
elseif #step_pattern == input_mos.nL + input_mos.ns then
elseif #step_pattern == input_mos.nL + input_mos.ns then
result = p._modmos_mode_degrees(input_mos, mos_prefix, step_pattern, mode_names, use_default_names)
result = p._mos_mode_degrees(input_mos, mos_prefix, mode_names, use_default_names, step_pattern)
end
end