Module:Ups and downs sharpness: Difference between revisions

From Xenharmonic Wiki
Jump to navigation Jump to search
ArrowHead294 (talk | contribs)
mNo edit summary
ArrowHead294 (talk | contribs)
mNo edit summary
Line 9: Line 9:
function p.ud_sharpness(frame) -- generate table
function p.ud_sharpness(frame) -- generate table
local sharp = sharp_n(frame.args["edo"])
local sharp = sharp_n(frame.args["edo"])
local tab = "{| class=\"wikitable center-all\"\n"
local tab
.. "|-\n"
.. "! Step offset\n"
if sharp == -2 then
.. "| '''0'''"
tab = "{{sharpness-flat2}}"
for i = 1, sharp * 2 + 1 do
elseif sharp == -1 then
tab = tab .. string.format((i % sharp == 0 and " || '''%s'''" or " || %s"), i)
tab = "{{sharpness-flat1}}"
end
elseif sharp == 0 then
tab = tab .. "\n|-\n! Sharp symbol\n"
tab = "{{sharpness-0}}"
.. "| rowspan=\"2\" | <span style=\"white-space: nowrap;\">&#x202F;[[File:Heji18.svg|15px]]</span>\n"
elseif sharp == 1 then
for i = 1, sharp * 2 + 1 do
tab = "{{sharpness-sharp1}}"
local cs = math.ceil((i / sharp) - 0.5)
else
tab = tab .. "| <span style=\"display: inline-block; margin-bottom: -45px; transform: translate(0, "
tab = "{| class=\"wikitable center-all\"\n"
if cs == 0 then
.. "|-\n"
tab = tab .. "-2.5px"
.. "! Step offset\n"
elseif cs == 1 then
.. "| '''0'''"
tab = tab .. "-15px"
for i = 1, sharp * 2 + 1 do
elseif cs == 2 then
tab = tab .. string.format((i % sharp == 0 and " || '''%s'''" or " || %s"), i)
tab = tab .. "-20px"
end
end
tab = tab .. "); white-space: nowrap;\">"
tab = tab .. "\n|-\n! Sharp symbol\n"
if ((i - (sharp * math.floor(i / sharp))) / sharp) > math.ceil(((i - (sharp * math.floor(i / sharp))) / sharp) - 0.5) then
.. "| rowspan=\"2\" | <span style=\"white-space: nowrap;\">&#x202F;[[File:Heji18.svg|15px]]</span>\n"
if (i - (sharp * math.floor(i / sharp))) % 5 == 4 then
for i = 1, sharp * 2 + 1 do
tab = tab .. "&#x202F;[[File:Down narrow.svg|9px]]&#x202F;[[File:Quip narrow.svg|9px]]"
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 .. "&#x202F;[[File:Down narrow.svg|9px]]&#x202F;[[File:Quip narrow.svg|9px]]"
else
for j = 1, (i - (sharp * math.floor(i / sharp))) % 5 do
tab = tab .. "&#x202F;[[File:Up narrow.svg|9px]]"
end
end
for j = 1, math.floor((i - (sharp * math.floor(i / sharp))) / 5) do
tab = tab .. "&#x202F;[[File:Quip narrow.svg|9px]]"
end
else
else
for j = 1, (i - (sharp * math.floor(i / sharp))) % 5 do
if ((sharp * math.ceil(i / sharp)) - i) % 5 == 4 then
tab = tab .. "&#x202F;[[File:Up narrow.svg|9px]]"
tab = tab .. "&#x202F;[[File:Up narrow.svg|9px]]&#x202F;[[File:Quid narrow.svg|9px]]"
else
for j = 1, ((sharp * math.ceil(i / sharp)) - i) % 5 do
tab = tab .. "&#x202F;[[File:Down narrow.svg|9px]]"
end
end
end
end
for j = 1, math.floor(((sharp * math.ceil(i / sharp)) - i) / 5) do
for j = 1, math.floor((i - (sharp * math.floor(i / sharp))) / 5) do
tab = tab .. "&#x202F;[[File:Quid narrow.svg|9px]]"
tab = tab .. "&#x202F;[[File:Quip narrow.svg|9px]]"
end
else
if ((sharp * math.ceil(i / sharp)) - i) % 5 == 4 then
tab = tab .. "&#x202F;[[File:Up narrow.svg|9px]]&#x202F;[[File:Quid narrow.svg|9px]]"
else
for j = 1, ((sharp * math.ceil(i / sharp)) - i) % 5 do
tab = tab .. "&#x202F;[[File:Down narrow.svg|9px]]"
end
end
end
end
for j = 1, math.floor(((sharp * math.ceil(i / sharp)) - i) / 5) do
if cs == 1 then
tab = tab .. "&#x202F;[[File:Quid narrow.svg|9px]]"
tab = tab .. "&#x202F;[[File:Heji25.svg|16px]]"
elseif cs == 2 then
tab = tab .. "&#x202F;[[File:Heji32.svg|21px]]"
end
end
tab = tab .. "</span>\n"
end
end
if cs == 1 then
tab = tab .. "|-\n! Flat symbol\n"
tab = tab .. "&#x202F;[[File:Heji25.svg|16px]]"
for i = 1, sharp * 2 + 1 do
elseif cs == 2 then
local cs = math.ceil((i / sharp) - 0.5)
tab = tab .. "&#x202F;[[File:Heji32.svg|21px]]"
tab = tab .. "| <span style=\"display: inline-block; margin-bottom: -45px; transform: translate(0, "
end
if cs == 1 or cs == 2 then
tab = tab .. "</span>\n"
tab = tab .. "-12.5px"
end
end
tab = tab .. "|-\n! Flat symbol\n"
tab = tab .. "); white-space: nowrap;\">"
for i = 1, sharp * 2 + 1 do
if ((i - (sharp * math.floor(i / sharp))) / sharp) > math.ceil(((i - (sharp * math.floor(i / sharp))) / sharp) - 0.5) then
local cs = math.ceil((i / sharp) - 0.5)
if (i - (sharp * math.floor(i / sharp))) % 5 == 4 then
tab = tab .. "| <span style=\"display: inline-block; margin-bottom: -45px; transform: translate(0, "
tab = tab .. "&#x202F;[[File:Up narrow.svg|9px]]&#x202F;[[File:Quid narrow.svg|9px]]"
if cs == 1 or cs == 2 then
else
tab = tab .. "-12.5px"
for j = 1, (i - (sharp * math.floor(i / sharp))) % 5 do
end
tab = tab .. "&#x202F;[[File:Down narrow.svg|9px]]"
tab = tab .. "); white-space: nowrap;\">"
end
if ((i - (sharp * math.floor(i / sharp))) / sharp) > math.ceil(((i - (sharp * math.floor(i / sharp))) / sharp) - 0.5) then
end
if (i - (sharp * math.floor(i / sharp))) % 5 == 4 then
for j = 1, math.floor((i - (sharp * math.floor(i / sharp))) / 5) do
tab = tab .. "&#x202F;[[File:Up narrow.svg|9px]]&#x202F;[[File:Quid narrow.svg|9px]]"
tab = tab .. "&#x202F;[[File:Quid narrow.svg|9px]]"
end
else
else
for j = 1, (i - (sharp * math.floor(i / sharp))) % 5 do
if ((sharp * math.ceil(i / sharp)) - i) % 5 == 4 then
tab = tab .. "&#x202F;[[File:Down narrow.svg|9px]]"
tab = tab .. "&#x202F;[[File:Down narrow.svg|9px]]&#x202F;[[File:Quip narrow.svg|9px]]"
else
for j = 1, ((sharp * math.ceil(i / sharp)) - i) % 5 do
tab = tab .. "&#x202F;[[File:Up narrow.svg|9px]]"
end
end
end
end
for j = 1, math.floor(((sharp * math.ceil(i / sharp)) - i) / 5) do
for j = 1, math.floor((i - (sharp * math.floor(i / sharp))) / 5) do
tab = tab .. "&#x202F;[[File:Quip narrow.svg|9px]]"
tab = tab .. "&#x202F;[[File:Quid narrow.svg|9px]]"
end
else
if ((sharp * math.ceil(i / sharp)) - i) % 5 == 4 then
tab = tab .. "&#x202F;[[File:Down narrow.svg|9px]]&#x202F;[[File:Quip narrow.svg|9px]]"
else
for j = 1, ((sharp * math.ceil(i / sharp)) - i) % 5 do
tab = tab .. "&#x202F;[[File:Up narrow.svg|9px]]"
end
end
end
end
for j = 1, math.floor(((sharp * math.ceil(i / sharp)) - i) / 5) do
if cs == 1 then
tab = tab .. "&#x202F;[[File:Quip narrow.svg|9px]]"
tab = tab .. "&#x202F;[[File:Heji11.svg|16px]]"
elseif cs == 2 then
tab = tab .. "&#x202F;[[File:Heji4.svg|27px]]"
end
end
tab = tab .. "</span>\n"
end
end
if cs == 1 then
tab = tab .. "|}"
tab = tab .. "&#x202F;[[File:Heji11.svg|16px]]"
elseif cs == 2 then
tab = tab .. "&#x202F;[[File:Heji4.svg|27px]]"
end
tab = tab .. "</span>\n"
end
end
tab = tab .. "|}"
if yesno(frame.args["debug"]) == true then
if yesno(frame.args["debug"]) == true then

Revision as of 15:50, 25 September 2025

Module documentation[view] [edit] [history] [purge]
This module should not be invoked directly; use its corresponding template instead: Template:Ups and downs sharpness.

This module automatically creates a table with the combinations of symbols to notate a given edo using Kite's ups and downs notation.

Introspection summary for Module:Ups and downs sharpness 
Functions provided (1)
Line Function Params
9 ud_sharpness (invokable) (frame)
Lua modules required (2)
Variable Module Functions used
utils Module:Utils dependency not used
yesno Module:Yesno yesno

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


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
	
	if sharp == -2 then
		tab = "{{sharpness-flat2}}"
	elseif sharp == -1 then
		tab = "{{sharpness-flat1}}"
	elseif sharp == 0 then
		tab = "{{sharpness-0}}"
	elseif sharp == 1 then
		tab = "{{sharpness-sharp1}}"
	else
		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;\">&#x202F;[[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 .. "&#x202F;[[File:Down narrow.svg|9px]]&#x202F;[[File:Quip narrow.svg|9px]]"
				else
					for j = 1, (i - (sharp * math.floor(i / sharp))) % 5 do
						tab = tab .. "&#x202F;[[File:Up narrow.svg|9px]]"
					end
				end
				for j = 1, math.floor((i - (sharp * math.floor(i / sharp))) / 5) do
					tab = tab .. "&#x202F;[[File:Quip narrow.svg|9px]]"
				end
			else
				if ((sharp * math.ceil(i / sharp)) - i) % 5 == 4 then
					tab = tab .. "&#x202F;[[File:Up narrow.svg|9px]]&#x202F;[[File:Quid narrow.svg|9px]]"
				else
					for j = 1, ((sharp * math.ceil(i / sharp)) - i) % 5 do
						tab = tab .. "&#x202F;[[File:Down narrow.svg|9px]]"
					end
				end
				for j = 1, math.floor(((sharp * math.ceil(i / sharp)) - i) / 5) do
					tab = tab .. "&#x202F;[[File:Quid narrow.svg|9px]]"
				end
			end
			if cs == 1 then
				tab = tab .. "&#x202F;[[File:Heji25.svg|16px]]"
			elseif cs == 2 then
				tab = tab .. "&#x202F;[[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 .. "&#x202F;[[File:Up narrow.svg|9px]]&#x202F;[[File:Quid narrow.svg|9px]]"
				else
					for j = 1, (i - (sharp * math.floor(i / sharp))) % 5 do
						tab = tab .. "&#x202F;[[File:Down narrow.svg|9px]]"
					end
				end
				for j = 1, math.floor((i - (sharp * math.floor(i / sharp))) / 5) do
					tab = tab .. "&#x202F;[[File:Quid narrow.svg|9px]]"
				end
			else
				if ((sharp * math.ceil(i / sharp)) - i) % 5 == 4 then
					tab = tab .. "&#x202F;[[File:Down narrow.svg|9px]]&#x202F;[[File:Quip narrow.svg|9px]]"
				else
					for j = 1, ((sharp * math.ceil(i / sharp)) - i) % 5 do
						tab = tab .. "&#x202F;[[File:Up narrow.svg|9px]]"
					end
				end
				for j = 1, math.floor(((sharp * math.ceil(i / sharp)) - i) / 5) do
					tab = tab .. "&#x202F;[[File:Quip narrow.svg|9px]]"
				end
			end
			if cs == 1 then
				tab = tab .. "&#x202F;[[File:Heji11.svg|16px]]"
			elseif cs == 2 then
				tab = tab .. "&#x202F;[[File:Heji4.svg|27px]]"
			end
			tab = tab .. "</span>\n"
		end
		tab = tab .. "|}"
	end
	
	if yesno(frame.args["debug"]) == true then
		tab = "<syntaxhighlight lang=\"wikitext\">" .. tab .. "</syntaxhighlight>"
	end
	
	return frame:preprocess(tab)
end

return p