Module:MOS mode degrees: Difference between revisions

Ganaram inukshuk (talk | contribs)
Adopt functions provided by other templates; begin work on rewriting modmos function
ArrowHead294 (talk | contribs)
mNo edit summary
Line 24: Line 24:
-- Determines whether an item is in an array
-- Determines whether an item is in an array
function p.find_item_in_table(table, item)
function p.find_item_in_table(table, item)
local item_found = false
local item_found = false
for i = 1, #table do
for i = 1, #table do
Line 81: Line 80:
end
end
local mosstep_vector = { ['L'] = large_step_count, ['s'] = small_step_count }
local mosstep_vector = { ["L"] = large_step_count, ["s"] = small_step_count }
return mosstep_vector
return mosstep_vector
end
end
Line 110: Line 109:
function p.calculate_mosstep_quality(input_mos, mosstep_vector)
function p.calculate_mosstep_quality(input_mos, mosstep_vector)
local input_mos = input_mos or mos.new(5, 2)
local input_mos = input_mos or mos.new(5, 2)
local mosstep_vector = mosstep_vector or { ['L'] = 5, ['s'] = 2 }
local mosstep_vector = mosstep_vector or { ["L"] = 5, ["s"] = 2 }
-- Get the number of mossteps per period and equave, and periods per equave
-- Get the number of mossteps per period and equave, and periods per equave
Line 119: Line 118:
-- Get the number of mossteps in the bright gen and dark gen
-- Get the number of mossteps in the bright gen and dark gen
local bright_gen = mos.bright_gen(input_mos)
local bright_gen = mos.bright_gen(input_mos)
local mossteps_per_bright_gen = bright_gen['L'] + bright_gen['s']
local mossteps_per_bright_gen = bright_gen["L"] + bright_gen["s"]
local mossteps_per_dark_gen = mossteps_per_period - mossteps_per_bright_gen
local mossteps_per_dark_gen = mossteps_per_period - mossteps_per_bright_gen
-- Get the number of mossteps as the sum of the number of L's and s's
-- Get the number of mossteps as the sum of the number of L's and s's
local mossteps = mosstep_vector['L'] + mosstep_vector['s']
local mossteps = mosstep_vector["L"] + mosstep_vector["s"]
-- Get the brightest and darkest modes for the input mos
-- Get the brightest and darkest modes for the input mos
Line 135: Line 134:
-- which is L-s, simply count the large step difference between the given mosstep vector
-- which is L-s, simply count the large step difference between the given mosstep vector
-- and the expected large and small ones.
-- and the expected large and small ones.
local large_step_count = mosstep_vector['L']
local large_step_count = mosstep_vector["L"]
local number_of_chromas = large_step_count - expected_large_mosstep_vector['L']
local number_of_chromas = large_step_count - expected_large_mosstep_vector["L"]
-- Determine what mosstep was passed in; is it a generator or period?
-- Determine what mosstep was passed in; is it a generator or period?
Line 283: Line 282:
-- Get the number of mossteps in the bright gen and dark gen
-- Get the number of mossteps in the bright gen and dark gen
local bright_gen = mos.bright_gen(input_mos)
local bright_gen = mos.bright_gen(input_mos)
local mossteps_per_bright_gen = bright_gen['L'] + bright_gen['s']
local mossteps_per_bright_gen = bright_gen["L"] + bright_gen["s"]


-- For each scale degree within a single period of a step pattern,
-- For each scale degree within a single period of a step pattern,
Line 296: Line 295:
local brightness_order = {}
local brightness_order = {}
for i = 1, mossteps_per_period do
for i = 1, mossteps_per_period do
local current_udp = number_of_gens_up .. '|' .. number_of_gens_down
local current_udp = number_of_gens_up .. "|" .. number_of_gens_down
if periods_per_equave ~= 1 then
if periods_per_equave ~= 1 then
current_udp = current_udp .. string.format("(%d)", periods_per_equave)
current_udp = current_udp .. string.format("(%d)", periods_per_equave)
Line 322: Line 321:
-- Get the number of mossteps in the bright gen and dark gen
-- Get the number of mossteps in the bright gen and dark gen
local bright_gen = mos.bright_gen(input_mos)
local bright_gen = mos.bright_gen(input_mos)
local mossteps_per_bright_gen = bright_gen['L'] + bright_gen['s']
local mossteps_per_bright_gen = bright_gen["L"] + bright_gen["s"]


-- For each scale degree within a single period of a step pattern,
-- For each scale degree within a single period of a step pattern,
Line 363: Line 362:
if rotate_by_generator then
if rotate_by_generator then
local bright_gen = mos.bright_gen(input_mos)
local bright_gen = mos.bright_gen(input_mos)
local mossteps_per_bright_gen = bright_gen['L'] + bright_gen['s']
local mossteps_per_bright_gen = bright_gen["L"] + bright_gen["s"]
shift_amount = mossteps_per_bright_gen
shift_amount = mossteps_per_bright_gen
end
end
Line 397: Line 396:
-- Get the number of mossteps per bright gen
-- Get the number of mossteps per bright gen
local bright_gen = mos.bright_gen(input_mos)
local bright_gen = mos.bright_gen(input_mos)
local mossteps_per_bright_gen = bright_gen['L'] + bright_gen['s']
local mossteps_per_bright_gen = bright_gen["L"] + bright_gen["s"]
local mode_degrees = {}
local mode_degrees = {}
Line 460: Line 459:
local gens_down = (index_of_closest_mode - 1) * periods_per_equave
local gens_down = (index_of_closest_mode - 1) * periods_per_equave
local gens_up = (mossteps_per_period - index_of_closest_mode) * periods_per_equave
local gens_up = (mossteps_per_period - index_of_closest_mode) * periods_per_equave
local udp_of_closest_mode = gens_up .. '|' .. gens_down
local udp_of_closest_mode = gens_up .. "|" .. gens_down
if periods_per_equave ~= 1 then
if periods_per_equave ~= 1 then
udp_of_closest_mode = udp_of_closest_mode .. string.format("(%d)", periods_per_equave)
udp_of_closest_mode = udp_of_closest_mode .. string.format("(%d)", periods_per_equave)
Line 470: Line 469:
for i = 1, #mode_vector do
for i = 1, #mode_vector do
if mode_vector[i] ~= modmos_vector[i] then
if mode_vector[i] ~= modmos_vector[i] then
local encoded_degree = { ['Mossteps'] = i - 1, ['Quality'] = modmos_vector[i] }
local encoded_degree = { ["Mossteps"] = i - 1, ["Quality"] = modmos_vector[i] }
local decoded_degree = mosnot.decode_mosstep_quality(encoded_degree, "m", "mosdegree", "abbreviated")
local decoded_degree = mosnot.decode_mosstep_quality(encoded_degree, "m", "mosdegree", "abbreviated")
alterations = string.format("%s %s", alterations, decoded_degree)
alterations = string.format("%s %s", alterations, decoded_degree)
Line 539: Line 538:
-- 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)
local interval = interval or {['L']=3, ['s']=1}
local interval = interval or {["L"] = 3, ["s"] = 1}
local input_mos = input_mos or mos.new(5,2)
local input_mos = input_mos or mos.new(5, 2)
local period_step_count = mos.period_step_count(input_mos)
local period_step_count = mos.period_step_count(input_mos)
Line 593: Line 592:
-- Create table
-- Create table
local result = '{| class="wikitable sortable"\n'
local result = "{| class=\"wikitable sortable\"\n"
local result = result .. string.format("|+ Scale degree qualities of %s modes\n", scale_sig)
.. string.format("|+ style=\"font-size: 105%%;\" | Scale degree qualities of %s modes\n", scale_sig)
-- Add table headers for first row
-- Add table headers for first row
result = result .. '! rowspan="2" | UDP\n'
.. "! rowspan=\"2\" | UDP !! rowspan=\"2\" | Rotational Order !! rowspan=\"2\" | Step pattern"
result = result .. '! rowspan="2" | Rotational Order\n'
result = result .. '! rowspan="2" | Step pattern\n'
-- Add mode names if present
-- Add mode names if present
local mode_names_given = (mode_names ~= nil and #mode_names == #step_patterns) or use_default_mode_names
local mode_names_given = (mode_names ~= nil and #mode_names == #step_patterns) or use_default_mode_names
if mode_names_given then
if mode_names_given then
result = result .. '! rowspan="2" class="unsortable" | Mode names\n'
result = result .. " !! rowspan=\"2\" class=\"unsortable\" | Mode names"
end
end
-- Add header for scale degrees
-- Add header for scale degrees
result = result .. string.format('! colspan="%d" class="unsortable" | Scale degree (%sdegree)\n', equave_step_count + 1, mos_prefix)
result = result .. string.format(" !! colspan=\"%d\" class=\"unsortable\" | Scale degree (%sdegree)", equave_step_count + 1, mos_prefix)
-- Add second row of headers
-- Add second row of headers
result = result .. "|-\n"
result = result .. "|- class=\"unsortable\"\n"
for i = 1, equave_step_count + 1 do
.. "! 0"
result = result .. string.format('! class="unsortable" |%d\n', i-1)
for i = 1, equave_step_count do
result = result .. string.format(" !! %d", i)
end
end
result = result .. "\n"
-- Add table contents
-- Add table contents
Line 621: Line 621:
-- Add brightness order (as UDP), rotational order, and step pattern
-- Add brightness order (as UDP), rotational order, and step pattern
result = result .. string.format('| %s\n| %s\n| %s\n', brightness_order[i], rotational_order[i], step_patterns[i])
.. string.format("| %s || %s || %s", brightness_order[i], rotational_order[i], step_patterns[i])
-- Add mode name if given
-- Add mode name if given
if mode_names_given then
if mode_names_given then
if use_default_mode_names then
if use_default_mode_names then
result = result .. string.format('| %s %s\n', scale_sig, brightness_order[i])
result = result .. string.format(" || %s %s", scale_sig, brightness_order[i])
else
else
result = result .. string.format('| %s\n', mode_names[i])
result = result .. string.format(" || %s", mode_names[i])
end
end
end
end
Line 638: Line 638:
local cell_color = p.cell_color(current_interval, input_mos)
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)
local style_code = cell_color == p.cell_color_none and "" or string.format("style=\"background: #%s;\" | ", cell_color)
result = result .. string.format('| %s%s\n', style_code, degree_quality)
result = result .. string.format(" || %s%s", style_code, degree_quality)
end
end
result = result .. "\n"
end
end