local p = {}
local utils = require("Module:Utils")
local yesno = require("Module:Yesno")
local function sharp_n(edo) -- calculate amount of steps for sharp/flat
return (7 * math.floor((edo * math.log(3) / math.log(2)) + 0.5)) - (11 * edo) -- mapping of augmented unison
end
function p.ud_sharpness(frame) -- generate table
local sharp = sharp_n(frame.args["edo"])
local tab = "{| class=\"wikitable center-all\"\n"
.. "|-\n"
.. "! Step offset\n"
.. "| '''0'''"
for i = 1, sharp * 2 + 1 do
tab = tab .. string.format((i % sharp == 0 and " || '''%s'''" or " || %s"), i)
end
tab = tab .. "\n|-\n! Sharp symbol\n"
.. "| rowspan=\"2\" | <span style=\"white-space: nowrap;\"> [[File:Heji18.svg|15px]]</span>\n"
for i = 1, sharp * 2 + 1 do
local cs = math.ceil((i / sharp) - 0.5)
tab = tab .. "| <span style=\"display: inline-block; margin-bottom: -45px; transform: translate(0, "
if cs == 0 then
tab = tab .. "-2.5px"
elseif cs == 1 then
tab = tab .. "-15px"
elseif cs == 2 then
tab = tab .. "-20px"
end
tab = tab .. "); white-space: nowrap;\">"
if ((i - (sharp * math.floor(i / sharp))) / sharp) > math.ceil(((i - (sharp * math.floor(i / sharp))) / sharp) - 0.5) then
if (i - (sharp * math.floor(i / sharp))) % 5 == 4 then
tab = tab .. " [[File:Down narrow.svg|9px]] [[File:Quip narrow.svg|9px]]"
else
for j = 1, (i - (sharp * math.floor(i / sharp))) % 5 do
tab = tab .. " [[File:Up narrow.svg|9px]]"
end
end
for j = 1, math.floor((i - (sharp * math.floor(i / sharp))) / 5) do
tab = tab .. " [[File:Quip narrow.svg|9px]]"
end
else
if ((sharp * math.ceil(i / sharp)) - i) % 5 == 4 then
tab = tab .. " [[File:Up narrow.svg|9px]] [[File:Quid narrow.svg|9px]]"
else
for j = 1, ((sharp * math.ceil(i / sharp)) - i) % 5 do
tab = tab .. " [[File:Down narrow.svg|9px]]"
end
end
for j = 1, math.floor(((sharp * math.ceil(i / sharp)) - i) / 5) do
tab = tab .. " [[File:Quid narrow.svg|9px]]"
end
end
if cs == 1 then
tab = tab .. " [[File:Heji25.svg|16px]]"
elseif cs == 2 then
tab = tab .. " [[File:Heji32.svg|21px]]"
end
tab = tab .. "</span>\n"
end
tab = tab .. "|-\n! Flat symbol\n"
for i = 1, sharp * 2 + 1 do
local cs = math.ceil((i / sharp) - 0.5)
tab = tab .. "| <span style=\"display: inline-block; margin-bottom: -45px; transform: translate(0, "
if cs == 1 or cs == 2 then
tab = tab .. "-12.5px"
end
tab = tab .. "); white-space: nowrap;\">"
if ((i - (sharp * math.floor(i / sharp))) / sharp) > math.ceil(((i - (sharp * math.floor(i / sharp))) / sharp) - 0.5) then
if (i - (sharp * math.floor(i / sharp))) % 5 == 4 then
tab = tab .. " [[File:Up narrow.svg|9px]] [[File:Quid narrow.svg|9px]]"
else
for j = 1, (i - (sharp * math.floor(i / sharp))) % 5 do
tab = tab .. " [[File:Down narrow.svg|9px]]"
end
end
for j = 1, math.floor((i - (sharp * math.floor(i / sharp))) / 5) do
tab = tab .. " [[File:Quid narrow.svg|9px]]"
end
else
if ((sharp * math.ceil(i / sharp)) - i) % 5 == 4 then
tab = tab .. " [[File:Down narrow.svg|9px]] [[File:Quip narrow.svg|9px]]"
else
for j = 1, ((sharp * math.ceil(i / sharp)) - i) % 5 do
tab = tab .. " [[File:Up narrow.svg|9px]]"
end
end
for j = 1, math.floor(((sharp * math.ceil(i / sharp)) - i) / 5) do
tab = tab .. " [[File:Quip narrow.svg|9px]]"
end
end
if cs == 1 then
tab = tab .. " [[File:Heji11.svg|16px]]"
elseif cs == 2 then
tab = tab .. " [[File:Heji4.svg|27px]]"
end
tab = tab .. "</span>\n"
end
tab = tab .. "|}"
if yesno(frame.args["debug"]) == true then
tab = "<syntaxhighlight lang=\"wikitext\">" .. tab .. "</syntaxhighlight>"
end
return frame:preprocess(tab)
end
return p