Module:Step vis: Difference between revisions

From Xenharmonic Wiki
Jump to navigation Jump to search
Ganaram inukshuk (talk | contribs)
Changed to parse numeric values; this should allow for showing size-0 steps
Ganaram inukshuk (talk | contribs)
Made step vis independent from mosinedo
Line 1: Line 1:
local mosinedo = require("Module:MOS in EDO")
--local mosinedo = require("Module:MOS in EDO")
local tip = require("Module:Template input parse")
local tip = require("Module:Template input parse")
local p = {}
local p = {}
-- Helper function
-- Create a step visualization that's based on the table on the diasem page
function p.step_pattern_to_visualization(step_pattern)
local step_pattern = step_pattern or { 5, 2, 5, 0, 5, 2, 0 }
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


-- Wrapper function for step visualization
-- Wrapper function for step visualization
-- Calls the step visualization function from the mosinedo template
function p.step_vis_frame(frame)
function p.step_vis_frame(frame)
local step_pattern = tip.parse_numeric_entries(frame.args["Step Pattern"], " ")
local step_pattern = tip.parse_numeric_entries(frame.args["Step Pattern"], " ")
return mosinedo.step_pattern_to_simple_visualization(step_pattern)
return p.step_pattern_to_visualization(step_pattern)
end
end


return p
return p

Revision as of 00:11, 15 December 2023

Module documentation[view] [edit] [history] [purge]
This module may be invoked by templates using its corresponding template Template:Step vis, or used directly from other modules.

Generates a visual representation of a scale based on predefined step sizes.

Introspection summary for Module:Step vis 
Functions provided (2)
Line Function Params
7 step_pattern_to_visualization (step_pattern)
58 step_vis_frame (invokable) (frame)
Lua modules required (1)
Variable Module Functions used
tip Module:Template input parse parse_numeric_entries

No function descriptions were provided. The Lua code may have further information.


--local mosinedo = require("Module:MOS in EDO")
local tip = require("Module:Template input parse")
local p = {}

-- Helper function
-- Create a step visualization that's based on the table on the diasem page
function p.step_pattern_to_visualization(step_pattern)
	local step_pattern = step_pattern or { 5, 2, 5, 0, 5, 2, 0 }
	
	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

-- Wrapper function for step visualization
function p.step_vis_frame(frame)
	local step_pattern = tip.parse_numeric_entries(frame.args["Step Pattern"], " ")
	return p.step_pattern_to_visualization(step_pattern)
end

return p