Module:MOS mode degrees: Difference between revisions

Ganaram inukshuk (talk | contribs)
m Update todo
Ganaram inukshuk (talk | contribs)
Adopt functions provided by other templates; begin work on rewriting modmos function
Line 4: Line 4:
local mosnot = require('Module:MOS notation')
local mosnot = require('Module:MOS notation')
local et = require('Module:ET')
local et = require('Module:ET')
local tip = require('Module:Template input parse')
local tamnams = require('Module:TAMNAMS')
local tamnams = require('Module:TAMNAMS')
local p = {}
local p = {}
Line 19: Line 20:
p.cell_color_small_size      = "FCE4D6"
p.cell_color_small_size      = "FCE4D6"
p.cell_color_sm_altered_size = "F8CBAD"
p.cell_color_sm_altered_size = "F8CBAD"
-- Helper function
-- Parses entries from a semicolon-delimited string and returns them in an array
-- TODO: Separate this and related functions (parse_pair and parse_kv_pairs) into its own module, as they're included
-- in various modules at this point, such as: scale tree, mos mdoes
function p.parse_entries(unparsed)
local parsed = {}
for entry in string.gmatch(unparsed, '([^;]+)') do
local trimmed = entry:gsub("^%s*(.-)%s*$", "%1")
table.insert(parsed, trimmed) -- Add to array
end
return parsed
end


-- Helper function
-- Helper function
Line 590: Line 578:
local use_default_mode_names = use_default_mode_names == 1
local use_default_mode_names = use_default_mode_names == 1
-- Get the modes as strings
-- Get the modes as strings and step vectors
local step_patterns = mos.modes_by_brightness(input_mos)
local step_patterns = mos.modes_by_brightness(input_mos)
local step_matrices = mos.modes_to_step_matrices(input_mos)
-- Get the scale sig
-- Get the scale sig
Line 599: Line 588:
local brightness_order = p.calculate_mos_mode_brightness_order(input_mos)
local brightness_order = p.calculate_mos_mode_brightness_order(input_mos)
local rotational_order = p.calculate_mos_mode_rotational_order(input_mos)
local rotational_order = p.calculate_mos_mode_rotational_order(input_mos)
-- Get step matrices for every mode
local step_matrices = mos.modes_to_step_matrices(input_mos)


-- Equave step count
-- Equave step count; needed for degree column count
local equave_step_count = mos.equave_step_count(input_mos)
local equave_step_count = mos.equave_step_count(input_mos)
Line 655: Line 641:
result = result .. string.format('| %s%s\n', style_code, degree_quality)
result = result .. string.format('| %s%s\n', style_code, degree_quality)
--[[
if row_colors[i][j] == p.cell_color_none then
result = result .. string.format('| %s\n', degree_quality)
elseif row_colors[i][j] == p.cell_color_lg_altered_size or row_colors[i][j] == p.cell_color_sm_altered_size then
result = result .. string.format('| style="background: #%s" | \'\'%s\'\'\n', row_colors[i][j], degree_quality)
else
result = result .. string.format('| style="background: #%s" | %s\n', row_colors[i][j], degree_quality)
end
]]--
end
end
end
end
Line 683: Line 658:
local use_default_mode_names = use_default_mode_names == 1
local use_default_mode_names = use_default_mode_names == 1
-- Get the modes
-- Get the modes and step matrices for the modmos
local modes = p.calculate_step_pattern_rotations(input_mos, step_pattern, false)
local step_patterns = mos.mode_rotations(step_pattern)
local step_matrices = mos.mode_rotations_to_step_matrices(step_pattern)
-- Get the number of mossteps per period and equave, and periods per equave
-- Get the step matrices for the true modes
local mossteps_per_equave = (input_mos.nL + input_mos.ns)
local true_step_matrices = mos.modes_to_step_matrices(input_mos)
local periods_per_equave = utils._gcd(input_mos.nL, input_mos.ns)
local mossteps_per_period = mossteps_per_equave / periods_per_equave
-- Get the number of mossteps per equave
local equave_step_count = mos.equave_step_count(input_mos)
-- Get the scale sig
-- Get the scale sig
Line 701: Line 678:
-- Get mosstep vectors for all modes
-- Get mosstep vectors for all modes
local mosstep_vectors = p.calculate_mos_mode_degrees(input_mos, modes)
local step_matrices = p.calculate_mos_mode_degrees(input_mos, step_patterns)
-- Get row colors
-- Get row colors
local row_colors = p.calculate_row_colors(input_mos, mosstep_vectors)
local row_colors = p.calculate_row_colors(input_mos, step_matrices)
-- Create table
-- Create table
Line 716: Line 693:
-- Add mode names if present
-- Add mode names if present
local mode_names_given = (mode_names ~= nil and #mode_names == #modes) 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\n'
Line 722: Line 699:
-- Add header for scale degrees
-- Add header for scale degrees
result = result .. string.format('! colspan="%d" class="unsortable" | Scale degree (%sdegree)\n', mossteps_per_equave + 1, mos_prefix)
result = result .. string.format('! colspan="%d" class="unsortable" | Scale degree (%sdegree)\n', equave_step_count + 1, mos_prefix)
-- Add second row of headers
-- Add second row of headers; these are for the scale degrees
result = result .. "|-\n"
result = result .. "|-\n"
for i = 1, mossteps_per_equave + 1 do
for i = 1, equave_step_count + 1 do
result = result .. string.format('! class="unsortable" |%d\n', i-1)
result = result .. string.format('! class="unsortable" |%d\n', i-1)
end
end
-- Add table contents
-- Add table contents
for i = 1, #modes do
for i = 1, #step_patterns do
result = result .. "|-\n"
result = result .. "|-\n"
-- 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', alterations[i], i, modes[i])
result = result .. string.format('| %s\n| %s\n| %s\n', alterations[i], i, step_patterns[i])
-- Add mode name if given
-- Add mode name if given
Line 748: Line 725:
-- Add scale degrees with cell coloring
-- Add scale degrees with cell coloring
-- This includes period intervals bold and alterations italicized
-- This includes period intervals bold and alterations italicized
for j = 1, #mosstep_vectors[i] do
for j = 1, #step_matrices[i] do
if row_colors[i][j] == p.cell_color_none then
if row_colors[i][j] == p.cell_color_none then
result = result .. string.format('| %s\n', p.decode_quality(mosstep_vectors[i][j]))
result = result .. string.format('| %s\n', p.decode_quality(step_matrices[i][j]))
elseif row_colors[i][j] == p.cell_color_lg_altered_size or row_colors[i][j] == p.cell_color_sm_altered_size then
elseif row_colors[i][j] == p.cell_color_lg_altered_size or row_colors[i][j] == p.cell_color_sm_altered_size then
result = result .. string.format('| style="background: #%s" | \'\'%s\'\'\n', row_colors[i][j], p.decode_quality(mosstep_vectors[i][j]))
result = result .. string.format('| style="background: #%s" | \'\'%s\'\'\n', row_colors[i][j], p.decode_quality(step_matrices[i][j]))
else
else
result = result .. string.format('| style="background: #%s" | %s\n', row_colors[i][j], p.decode_quality(mosstep_vectors[i][j]))
result = result .. string.format('| style="background: #%s" | %s\n', row_colors[i][j], p.decode_quality(step_matrices[i][j]))
end
end
end
end
Line 811: Line 788:
use_default_names = 1
use_default_names = 1
else
else
mode_names = p.parse_entries(frame.args['Mode Names'])
mode_names = tip.parse_entries(frame.args['Mode Names'])
end
end
end
end