Module:MOS in EDO: Difference between revisions

Ganaram inukshuk (talk | contribs)
mNo edit summary
Ganaram inukshuk (talk | contribs)
m rename
 
(34 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local mos = require('Module:MOS')
local utils = require('Module:Utils')
local p = {}
local p = {}
local mos = require("Module:MOS")
local step_vis = require("Module:Step vis")
local tamnams = require("Module:TAMNAMS")
local utils = require("Module:Utils")
local yesno = require("Module:Yesno")


-- Global variables for cell colors
-- Global variables for cell colors
-- Dark blue for large steps, light blue for small steps
-- Dark blue for large steps, light blue for small steps
-- For mosses that are reversed (starts with s and ends with L), use orange instead
-- For mosses that are reversed (starts with s and ends with L), use orange instead
p.cell_color_none = "NONE" -- For cells that don't have a color (default cell color applies)
p.cell_color_none = "" -- For cells that don't have a color (default cell color applies)
p.cell_color_perfect_size = "NONE" -- Only applies for steps of an edo
p.cell_color_perfect_size = "" -- Only applies for steps of an edo
p.cell_color_large = "BDD7EE"
p.cell_color_large = "#BDD7EE"
p.cell_color_small = "DDEBF7"
p.cell_color_small = "#DDEBF7"
p.cell_color_lg_rev = "F8CBAD"
p.cell_color_lg_rev = "#F8CBAD"
p.cell_color_sm_rev = "FCE4D6"
p.cell_color_sm_rev = "#FCE4D6"


-- Helper function
-- Helper function
Line 60: Line 64:
end
end
return string.format("%iL %is", large_step_count, small_step_count)
return string.format("%iL %is", large_step_count, small_step_count)


end
end
Line 150: Line 154:


     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 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 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)
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 222: Line 191:
-- Create table, starting with headers
-- Create table, starting with headers
local result = string.format('{| class="wikitable center-all"\n')
local result = "{| class=\"wikitable center-all\"\n"
result = result .. string.format('|+ Generators %i\\%i and %i\\%i\n', gen_in_edosteps, edo, comp_in_edosteps, edo)
.. "|+ style=\"font-size: 105%; white-space: nowrap;\" | " .. string.format("Generators %i\\%i and %i\\%i\n", gen_in_edosteps, edo, comp_in_edosteps, edo)
result = result .. string.format('|-\n')
.. "|-\n"
result = result .. string.format('! colspan="%i" |Steps\n', edo)
.. string.format("! colspan=\"%i\" | Steps\n", edo)
result = result .. string.format('!MOS (name)\n')
.. "! MOS (name)\n"
result = result .. string.format('!Step ratio\n')
.. "! Step ratio\n"
if show_temperament then
if show_temperament then
result = result .. string.format('!Temperament\n')
result = result .. string.format("! Temperament\n")
end
end


Line 245: Line 214:
-- Add the step sizes
-- Add the step sizes
result = result .. string.format('|-\n')
result = result .. "|-\n"
for i = 1, #current_scale do
for i = 1, #current_scale do
local current_step = current_scale[i]
local current_step = current_scale[i]
Line 269: Line 238:
if current_step == 1 then
if current_step == 1 then
if large_step_size == small_step_size then
if large_step_size == small_step_size then
result = result .. string.format('| 1\n')
result = result .. "| 1\n"
else
else
result = result .. string.format('| bgcolor="%s" | 1\n', cell_color)
result = result .. string.format("| style=\"background-color: %s;\" | 1\n", cell_color)
end
end
else
else
if cell_color == p.cell_color_none then
if cell_color == p.cell_color_none then
result = result .. string.format('| colspan="%i" | %i\n', current_step, current_step)
result = result .. string.format("| colspan=\"%i\" | %i\n", current_step, current_step)
else
else
result = result .. string.format('| bgcolor="%s" colspan="%i" | %i\n', cell_color, current_step, current_step)
result = result .. string.format("| style=\"background-color: %s\" colspan=\"%i\" | %i\n", cell_color, current_step, current_step)
end
end
end
end
Line 287: Line 256:
-- Get the tamnams name, if there is one
-- 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)
-- 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 tamnams_name = tamnams.lookup_name(scale_sig)
local current_step_count = #current_scale
local current_step_count = #current_scale
Line 315: Line 284:
end
end


result = result .. string.format('|}\n')
result = result .. "|}"
return result
return result
Line 323: Line 292:
-- Instead of a "rectangular horogram", use the same type of visualization shown
-- Instead of a "rectangular horogram", use the same type of visualization shown
-- on the diasem page
-- on the diasem page
function p.mos_in_edo_simplified(edo, gen_in_edosteps, number_of_periods, temperament)
function p.mos_in_edo_simplified(edo, gen_in_edosteps, number_of_periods, generation_limit, temperament)
local edo = edo or 24
local edo = edo or 24
local gen_in_edosteps = gen_in_edosteps or 14
local gen_in_edosteps = gen_in_edosteps or 14
local number_of_periods = number_of_periods or 1
local number_of_periods = number_of_periods or 1
local generation_limit = generation_limit or edo - 1
local temperament = temperament --or "meantone"
local temperament = temperament --or "meantone"
Line 336: Line 306:
period_in_edosteps = edo / number_of_periods
period_in_edosteps = edo / number_of_periods
verified_number_of_periods = number_of_periods
verified_number_of_periods = number_of_periods
end
-- Check whether the generation limit is valid
-- If it's -1, then show all generations (period_in_edosteps-1)
if generation_limit == -1 then
generation_limit = period_in_edosteps - 1
end
end
Line 356: Line 332:
-- Create table, starting with headers
-- Create table, starting with headers
local result = string.format('{| class="wikitable center-all"\n')
local result = "{| class=\"wikitable center-all\"\n"
result = result .. string.format('|+ Generators %i\\%i and %i\\%i\n', gen_in_edosteps, edo, comp_in_edosteps, edo)
.. "|+ style=\"font-size: 105%; white-space: nowrap;\" | " .. string.format("Generators %i\\%i and %i\\%i\n", gen_in_edosteps, edo, comp_in_edosteps, edo)
result = result .. string.format('|-\n')
.. "|-\n"
result = result .. string.format('! Step visualization\n')
.. "! Step visualization\n"
result = result .. string.format('!MOS (name)\n') -- Scale sig (and name)
.. "! MOS (name)\n" -- Scale sig (and name)
result = result .. string.format('!Step sizes (L, s)\n') -- Step sizes
.. "! Step sizes\n" -- Step sizes
result = result .. string.format('!Step ratio\n') -- Step ratio
.. "! Step ratio\n" -- Step ratio
if show_temperament then
if show_temperament then
result = result .. string.format('!Temperament\n') -- Temperament, if given
result = result .. "! Temperament\n" -- Temperament, if given
end
end


-- Add the step pattern for successive mosses until the pattern becomes that for an edo
-- Add the step pattern for successive mosses until the pattern becomes that for an edo
while current_scale ~= nil and starting_mos_valid do
local generation_count = 1
while current_scale ~= nil and starting_mos_valid and generation_count <= generation_limit do
-- Calculate current step ratio
-- Calculate current step ratio
-- Use this to determine which cell colors to use
-- Use this to determine which cell colors to use
Line 377: Line 354:
-- New row
-- New row
result = result .. string.format('|-\n')
result = result .. "|-\n"
-- Add the step visualization
-- Add the step visualization
local step_vis = p.step_pattern_to_simple_visualization(current_scale, period_in_edosteps)
local sv = step_vis._step_vis(current_scale)
result = result .. string.format('| %s\n', step_vis)
result = result .. string.format("| %s\n", sv)
-- Add the scale sig
-- Add the scale sig
-- Also add tamnams name if there is one
-- Also add tamnams name if there is one
local scale_sig = p.mos_step_pattern_to_scale_sig(current_scale)
local scale_sig = p.mos_step_pattern_to_scale_sig(current_scale)
local tamnams_name = mos.tamnams_name[scale_sig]
local tamnams_name = tamnams.lookup_name(scale_sig)
local current_step_count = #current_scale
local current_step_count = #current_scale
if large_step_size == small_step_size then
if large_step_size == small_step_size then
Line 397: Line 374:
-- Add the step sizes
-- Add the step sizes
result = result .. string.format("| %i\\%i, %i\\%i\n", current_step_sizes["L"], edo, current_step_sizes["s"], edo)
result = result .. string.format("| %i,&nbsp;%i\n", current_step_sizes["L"], current_step_sizes["s"])
-- Add step ratio
-- Add step ratio
Line 412: Line 389:
-- Produce the next scale in the sequence
-- Produce the next scale in the sequence
current_scale = p.calculate_next_mos_step_pattern(current_scale)
current_scale = p.calculate_next_mos_step_pattern(current_scale)
-- Increment the generation (row) count
generation_count = generation_count + 1
end
end


result = result .. string.format('|}\n')
result = result .. "|}"
return result
return result
Line 421: Line 401:
-- Function to be called by a template
-- Function to be called by a template
function p.mos_in_edo_frame(frame)
function p.mos_in_edo_frame(frame)
local edo = tonumber(frame.args["EDO"])
local edo = tonumber(frame.args["EDO"])
local gen_in_edosteps = tonumber(frame.args["Generator"])
local gen_in_edosteps = tonumber(frame.args["Generator"])
local temperament = frame.args["Temperament"]
local temperament = frame.args["Temperament"]
local number_of_periods = tonumber(frame.args["Number of Periods"])
local number_of_periods = tonumber(frame.args["Periods"])
local generation_limit = tonumber(frame.args["Generation Limit"])
local debugg = yesno(frame.args["debug"])
local result = p.mos_in_edo_simplified(edo, gen_in_edosteps, number_of_periods, generation_limit, temperament)
-- Debugger option
local result = ""
if debugg == true then
if frame.args["Step Visualization"] == "Simplified" then
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
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
end
return result
return frame:preprocess(result)
end
end


return p
return p