Module:MOS in EDO: Difference between revisions

Ganaram inukshuk (talk | contribs)
Created template; work-in-progress, as some functions are still missing
 
Ganaram inukshuk (talk | contribs)
Added "main" function; bugs still need to be worked out
Line 73: Line 73:
     local next_step_array = {}
     local next_step_array = {}


-- If the small and large step sizes are the same, return nil
     if small_step_size == large_step_size then
     if small_step_size == large_step_size then
         return next_step_array
         return nil
     end
     end


Line 144: Line 145:
-- Primary function
-- Primary function
-- Create a rectangular horogram depicting a mos for a given pair of generators
-- Create a rectangular horogram depicting a mos for a given pair of generators
function p.edo_mos_step_patterns(edo, gen_in_edosteps, number_of_periods, temperaments)
function p.edo_mos_step_patterns(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 ~= ""
-- 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 and the number of steps in the period
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
local result = string.format('{| class="wikitable"\n')
result = result .. string.format('|-\n')
result = result .. string.format('! colspan="%i" |Steps for generators %i\\%i and %i\\%i\n', edo, gen_in_edosteps, edo, comp_in_edosteps, edo)
result = result .. string.format('!Mos\n')
result = result .. string.format('!Step ratio\n')
result = result .. string.format('!TAMNAMS name\n')
if show_temperament then
result = result .. string.format('!Temperament\n')
end
while current_scale ~= nil and starting_mos_valid do
result = result .. string.format('|-\n')
for i = 1, #current_scale do
local current_step = current_scale[i]
if current_step == 1 then
result = result .. string.format('| 1\n')
else
result = result .. string.format('| colspan="%i" | %i\n', current_step, current_step)
end
end
local scale_sig = p.mos_step_pattern_to_scale_sig(current_scale)
if #current_scale == (edo / verified_number_of_periods) then
result = result .. string.format("| %iedo\n", edo / verified_number_of_periods)
else
result = result .. string.format("| [[%s]]\n", scale_sig)
end
local current_step_sizes = p.calculate_step_sizes(current_scale)
local step_ratio_gcd = utils._gcd(current_step_sizes["L"], current_step_sizes["s"])
result = result .. string.format("| %s:%s\n", current_step_sizes["L"] / step_ratio_gcd, current_step_sizes["s"] / step_ratio_gcd)
local tamnams_name = mos.tamnams_name[scale_sig]
if tamnams_name ~= nil then
result = result .. string.format("| %s\n", tamnams_name)
else
result = result .. string.format("|\n")
end
if show_temperament then
local current_step_count = #current_scale
result = result .. string.format("| %s[%i]\n", temperament, current_step_count)
end
current_scale = p.calculate_next_mos_step_pattern(current_scale)
end
result = result .. string.format('|}\n')
return result
end
end




return p
return p