Module:MOS in EDO: Difference between revisions

Ganaram inukshuk (talk | contribs)
Centering all cells
Ganaram inukshuk (talk | contribs)
Added simplified step visualization
Line 150: Line 150:


     return next_step_array
     return next_step_array
end
-- Helper function
-- Create a step visualization that's based on the table on the diasem page
function p.step_pattern_to_simple_visualization(step_pattern, edosteps_per_period)
local step_pattern = step_pattern or { 2, 2, 2, 1, 2, 2, 1 }
local edosteps_per_period = edosteps_per_period or #step_pattern
local left_border = "├"
local right_border = "┤"
local no_border = "─"
local single_border = "┼"
local double_border = "╫"
local step_visualization = ""
-- For each step size of k, print a single border, followed by k-1 no-border symbols
-- If this is the first step, print the left border instead
-- If this step is for a non-root non-equave period, print a double border instead
-- If this is the last step, add a right border after the entire sequence
for i = 1, #step_pattern do
local current_step_vis = ""
local current_step_size = step_pattern[i]
if i == 1 then
current_step_vis = left_border .. string.rep(no_border, current_step_size - 1)
elseif (i - 1) % edosteps_per_period == 0 and i ~= 1  and i ~= #step_pattern then
current_step_vis = double_border .. string.rep(no_border, current_step_size - 1)
else
current_step_vis = single_border .. string.rep(no_border, current_step_size - 1)
end
step_visualization = step_visualization .. current_step_vis
end
step_visualization = step_visualization .. right_border
return step_visualization
end
end


Line 246: Line 285:
end
end
end
end
-- Add the scale sig
local scale_sig = p.mos_step_pattern_to_scale_sig(current_scale)
-- Get the tamnams name, if there is one
-- Don't show tamnams names for mosses with 5 notes or fewer (to keep the table from being cluttered)
local tamnams_name = mos.tamnams_name[scale_sig]
local current_step_count = #current_scale
-- Use step sizes to determine whether the mos is an edo
local reduced_large_step_size = current_step_sizes["L"] / step_ratio_gcd
local reduced_small_step_size = current_step_sizes["s"] / step_ratio_gcd
if reduced_large_step_size == reduced_small_step_size then
result = result .. string.format("| [[%iedo]]\n", edo / step_ratio_gcd)
elseif tamnams_name ~= nil and current_step_count > 5 then
result = result .. string.format("| [[%s]] (%s)\n", scale_sig, tamnams_name)
else
result = result .. string.format("| [[%s]]\n", scale_sig)
end
-- Add the step ratio
result = result .. string.format("| %s:%s\n", current_step_sizes["L"] / step_ratio_gcd, current_step_sizes["s"] / step_ratio_gcd)
-- Add the temperament name, if there is one
if show_temperament then
local current_step_count = #current_scale
result = result .. string.format("| %s[%i]\n", temperament, current_step_count)
end
-- Produce the next scale in the sequence
current_scale = p.calculate_next_mos_step_pattern(current_scale)
end
result = result .. string.format('|}\n')
return result
end
-- Alternate primary function
-- Instead of a "rectangular horogram", use the same type of visualization shown
-- on the diasem page
function p.mos_in_edo_simplified(edo, gen_in_edosteps, number_of_periods, temperament)
local edo = edo or 24
local gen_in_edosteps = gen_in_edosteps or 14
local number_of_periods = number_of_periods or 1
local temperament = temperament --or "meantone"
-- Check whether the number of periods divides the edo
-- If so, the starting scale will be a multiperiod mos
local period_in_edosteps = edo
local verified_number_of_periods = 1
if edo % number_of_periods == 0 then
period_in_edosteps = edo / number_of_periods
verified_number_of_periods = number_of_periods
end
-- Calculate whether to include temperament names
local show_temperament = temperament ~= "" and temperament ~= nil
-- Calculate the generator complement
local comp_in_edosteps = period_in_edosteps - gen_in_edosteps
-- Are the args for the starting mos valid?
-- The number of steps in the generator must be between 1 (inclusive) and the number of steps in the period (exclusive)
local starting_mos_valid = gen_in_edosteps >= 1 and gen_in_edosteps <= period_in_edosteps
-- Calculate the starting mos
local current_scale = {}
for i = 1, number_of_periods do
table.insert(current_scale, gen_in_edosteps)
table.insert(current_scale, comp_in_edosteps)
end
-- Create table, starting with headers
local result = string.format('{| class="wikitable center-all"\n')
result = result .. string.format('|+ Generators %i\\%i and %i\\%i\n', gen_in_edosteps, edo, comp_in_edosteps, edo)
result = result .. string.format('|-\n')
result = result .. string.format('! Steps\n')
result = result .. string.format('!MOS (name)\n')
result = result .. string.format('!Step ratio\n')
if show_temperament then
result = result .. string.format('!Temperament\n')
end
-- Add the step pattern for successive mosses until the pattern becomes that for an edo
while current_scale ~= nil and starting_mos_valid do
-- Calculate current step ratio
-- Use this to determine which cell colors to use
local current_step_sizes = p.calculate_step_sizes(current_scale)
local step_ratio_gcd = utils._gcd(current_step_sizes["L"], current_step_sizes["s"])
local large_step_size = current_step_sizes["L"]
local small_step_size = current_step_sizes["s"]
-- Is the first step a large step?
local first_step_is_large_step = current_scale[1] == large_step_size
-- Add the step visualization
local step_vis = p.step_pattern_to_simple_visualization(current_scale, period_in_edosteps)
result = result .. string.format('|-\n')
result = result .. string.format('| %s\n', step_vis)
-- Add the scale sig
-- Add the scale sig
Line 293: Line 433:
local number_of_periods = tonumber(frame.args["Number of Periods"])
local number_of_periods = tonumber(frame.args["Number of Periods"])
local result = p.mos_in_edo(edo, gen_in_edosteps, number_of_periods, temperament)
local result = ""
if frame.args["Step Visualization"] == "Simplifed" then
result = p.mos_in_edo_simplified(edo, gen_in_edosteps, number_of_periods, temperament)
else
result = p.mos_in_edo(edo, gen_in_edosteps, number_of_periods, temperament)
end
return result
return result