Module:Interval ruler: Difference between revisions

From Xenharmonic Reference
Created page with "local p = {} function p.e(resolution,intervals,length) length = length or 1200 intervals = intervals or {} i = math.floor(length/1200 * resolution + 0.5) z = {} for k = 0, i do z[k] = "─" end for n = 1, #intervals do z[math.floor(intervals[n]/1200 * resolution + 0.5)] = "┴" end for m = 0, math.floor(i/resolution) do if (z[m*resolution] == "┴") then z[m*resolution] = "┼" else z[m*resolution] = "┬" end end if(z[0]=="┼") then z[0]="├" end if(z[0]=="..."
 
No edit summary
Line 2: Line 2:


function p.e(resolution,intervals,length)
function p.e(resolution,intervals,length)
length = length or 1200
length = tonumber(length) or 1200
resolution = tonumber(resolution)
intervals = intervals or {}
intervals = intervals or {}
if(type(intervals) == "string") then
local t = {}
for item in (intervals):gmatch("%s*([^,]+)%s*") do t[#t+1] = item end
intervals = t
end
if(type(intervals) == "number") then
intervals = {intervals}
end


i = math.floor(length/1200 * resolution + 0.5)
i = math.floor(length/1200 * resolution + 0.5)

Revision as of 08:05, 29 December 2025

Documentation for this module may be created at Module:Interval ruler/doc

local p = {}

function p.e(resolution,intervals,length)
length = tonumber(length) or 1200
resolution = tonumber(resolution)
intervals = intervals or {}
if(type(intervals) == "string") then
local t = {}
for item in (intervals):gmatch("%s*([^,]+)%s*") do t[#t+1] = item end 
intervals = t
end
if(type(intervals) == "number") then
intervals = {intervals}
end




i = math.floor(length/1200 * resolution + 0.5)
z = {}


for k = 0, i do
z[k] = "─"
end



for n = 1, #intervals do
z[math.floor(intervals[n]/1200 * resolution + 0.5)] = "┴"
end

for m = 0, math.floor(i/resolution) do 
if (z[m*resolution] == "┴") then
z[m*resolution] = "┼"
else
z[m*resolution] = "┬"
end end
if(z[0]=="┼") then
z[0]="├"
end
if(z[0]=="┬") then
z[0]="┌"
end
if(z[#z]=="┼") then
z[#z]="┤"
end
if(z[#z]=="┬") then
z[#z]="┐"
end
if(z[#z]=="┴") then
z[#z]="┘"
end
if(z[#z]=="─") then
z[#z]="╮"
end


return table.concat(z,"",0)
end

return p