Module:MOS in EDO: Difference between revisions

ArrowHead294 (talk | contribs)
m Function «tamnams_name» is undefined, commenting out for now
Ganaram inukshuk (talk | contribs)
m rename
 
(16 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local p = {}
local mos = require("Module:MOS")
local mos = require("Module:MOS")
local step_vis = require("Module:Step vis")
local tamnams = require("Module:TAMNAMS")
local utils = require("Module:Utils")
local utils = require("Module:Utils")
local tamnams = require("Module:TAMNAMS")
local yesno = require("Module:Yesno")
local p = {}


-- Global variables for cell colors
-- Global variables for cell colors
Line 61: 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 151: 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)
local step_pattern = step_pattern or { 2, 2, 2, 1, 2, 2, 1 }
local left_border = "├"
local right_border = "┤"
local no_border = "─"
local double_border = "╫"
local double_border_left = "╟"
local double_border_right = "╢"
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 the step size is 0, print a double border only; if this happens, the next step should start with a border character
-- 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
if current_step_size == 0 then
current_step_vis = double_border_left
else
current_step_vis = left_border .. string.rep(no_border, current_step_size - 1)
end
elseif i == #step_pattern then
if current_step_size == 0 then
current_step_vis = double_border_right
else
current_step_vis = single_border .. string.rep(no_border, current_step_size - 1) .. right_border
end
else
if current_step_size == 0 then
current_step_vis = double_border
elseif step_pattern[i-1] == 0 then
current_step_vis = string.rep(no_border, current_step_size - 1)
else
current_step_vis = single_border .. string.rep(no_border, current_step_size - 1)
end
end
step_visualization = step_visualization .. current_step_vis
end
return step_visualization
end
end


Line 241: Line 192:
-- Create table, starting with headers
-- Create table, starting with headers
local result = "{| class=\"wikitable center-all\"\n"
local result = "{| class=\"wikitable center-all\"\n"
.. string.format("|+ style=\"font-size: 105%%;\" | 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)
.. "|-\n"
.. "|-\n"
.. string.format("! colspan=\"%i\" | Steps\n", edo)
.. string.format("! colspan=\"%i\" | Steps\n", edo)
Line 305: 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 333: Line 284:
end
end


result = result .. "|}\n"
result = result .. "|}"
return result
return result
Line 382: Line 333:
-- Create table, starting with headers
-- Create table, starting with headers
local result = "{| class=\"wikitable center-all\"\n"
local result = "{| class=\"wikitable center-all\"\n"
.. string.format("|+ style=\"font-size: 105%%;\" | 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)
.. "|-\n"
.. "|-\n"
.. "! Step visualization\n"
.. "! Step visualization\n"
Line 406: Line 357:
-- Add the step visualization
-- Add the step visualization
local step_vis = p.step_pattern_to_simple_visualization(current_scale)
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 = tamnams.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
result = result .. string.format("| [[%iedo]]\n", edo / step_ratio_gcd)
result = result .. string.format("| [[%iedo]]\n", edo / step_ratio_gcd)
-- elseif tamnams_name ~= nil and current_step_count > 5 then
elseif tamnams_name ~= nil and current_step_count > 5 then
-- result = result .. string.format("| [[%s]] (%s)\n", scale_sig, tamnams_name)
result = result .. string.format("| [[%s]] (%s)\n", scale_sig, tamnams_name)
else
else
result = result .. string.format("| [[%s]]\n", scale_sig)
result = result .. string.format("| [[%s]]\n", scale_sig)
Line 423: Line 374:
-- Add the step sizes
-- Add the step sizes
result = result .. string.format("| %i, %i\n", current_step_sizes["L"], current_step_sizes["s"])
result = result .. string.format("| %i, %i\n", current_step_sizes["L"], current_step_sizes["s"])
-- Add step ratio
-- Add step ratio
Line 443: Line 394:
end
end


result = result .. "|}\n"
result = result .. "|}"
return result
return result
Line 450: 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"])
Line 456: Line 406:
local number_of_periods = tonumber(frame.args["Periods"])
local number_of_periods = tonumber(frame.args["Periods"])
local generation_limit = tonumber(frame.args["Generation Limit"])
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)
local result = ""
-- Debugger option
result = p.mos_in_edo_simplified(edo, gen_in_edosteps, number_of_periods, generation_limit, temperament)
if debugg == true then
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
return result
end
return frame:preprocess(result)
end
end


return p
return p