Module:Ups and downs sharpness: Difference between revisions

From Xenharmonic Wiki
Jump to navigation Jump to search
Tristanbay (talk | contribs)
forgot a </tr> before
Tristanbay (talk | contribs)
changed back to wiki pipe because XHTML screwed the template up
Tag: Manual revert
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 spanf = "<td style=\"margin-bottom:-45px; transform:translate(0, %spx); white-space:nowrap;\">%s</td>\n"
local spanf = "| <span style=\"margin-bottom:-45px; transform:translate(0, %spx); white-space:nowrap;\">%s</span>\n"
local arrow_marg = -2.5
local arrow_marg = -2.5
local sharp_marg = -15
local sharp_marg = -15
Line 21: Line 21:
tab = "{{sharpness-flat1}}"
tab = "{{sharpness-flat1}}"
elseif sharp == 0 then
elseif sharp == 0 then
tab = "<table center-all>\n"
tab = "{| class=\"wikitable center-all\"\n"
.. "<tr>\n"
.. "|-\n"
.. "<th>Step offset</th>\n"
.. "! Step offset\n"
.. "<td>−3</td><td>−2</td><td>−1</td><td>0</td><td>+1</td><td>+2</td><td>+3</td>\n"
.. "| −3 || −2 || −1 || 0 || +1 || +2 || +3\n"
.. "</tr>\n<tr>\n"
.. "|-\n"
.. "<th>Symbol</th>\n"
.. "! Symbol\n"
.. string.format(spanf, arrow_marg, string.rep("&#x202F;[[File:Down arrow petaluma script.svg|10px]]", 3))
.. string.format(spanf, arrow_marg, string.rep("&#x202F;[[File:Down arrow petaluma script.svg|10px]]", 3))
.. string.format(spanf, arrow_marg, string.rep("&#x202F;[[File:Down arrow petaluma script.svg|10px]]", 2))
.. string.format(spanf, arrow_marg, string.rep("&#x202F;[[File:Down arrow petaluma script.svg|10px]]", 2))
Line 34: Line 34:
.. string.format(spanf, arrow_marg, string.rep("&#x202F;[[File:Up arrow petaluma script.svg|10px]]", 2))
.. string.format(spanf, arrow_marg, string.rep("&#x202F;[[File:Up arrow petaluma script.svg|10px]]", 2))
.. string.format(spanf, arrow_marg, string.rep("&#x202F;[[File:Up arrow petaluma script.svg|10px]]", 3))
.. string.format(spanf, arrow_marg, string.rep("&#x202F;[[File:Up arrow petaluma script.svg|10px]]", 3))
.. "\n</tr>\n</table>"
.. "|}"
elseif sharp == 1 then
elseif sharp == 1 then
tab = "{{sharpness-sharp1}}"
tab = "{{sharpness-sharp1}}"
else
else
tab = "<table center-all>\n"
tab = "{| class=\"wikitable center-all\"\n"
.. "<tr>\n"
.. "|-\n"
.. "<th>Step offset<th>\n"
.. "! Step offset\n"
.. "<td>'''0'''</td>"
.. "| '''0'''"
for i = 1, sharp * 2 + 1 do
for i = 1, sharp * 2 + 1 do
tab = tab .. string.format((i % sharp == 0 and "<td>'''%s'''</td>" or "<td>%s</td>"), i)
tab = tab .. string.format((i % sharp == 0 and " || '''%s'''" or " || %s"), i)
end
end
tab = tab .. "\n</tr>\n<tr>\n<th>Sharp symbol<th>\n"
tab = tab .. "\n|-\n! Sharp symbol\n"
.. "<td rowspan=\"2\" style=\"white-space:nowrap;\">&#x202F;[[File:Heji18.svg|15px]]</td>\n"
.. "| rowspan=\"2\" | <span style=\"white-space:nowrap;\">&#x202F;[[File:Heji18.svg|15px]]</span>\n"
for i = 1, sharp * 2 + 1 do
for i = 1, sharp * 2 + 1 do
local cs = math.ceil((i / sharp) - 0.5) -- sharpness of note
local cs = math.ceil((i / sharp) - 0.5) -- sharpness of note
Line 93: Line 93:
end
end
tab = tab .. "\n<tr>\n<th>Flat symbol</th>\n"
tab = tab .. "|-\n! Flat symbol\n"
for i = 1, sharp * 2 + 1 do
for i = 1, sharp * 2 + 1 do
Line 137: Line 137:
end
end
tab = tab .. "\n</tr>\n</table>"
tab = tab .. "|}"
end
end

Revision as of 07:37, 5 October 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 spanf = "| <span style=\"margin-bottom:-45px; transform:translate(0, %spx); white-space:nowrap;\">%s</span>\n"
	local arrow_marg = -2.5
	local sharp_marg = -15
	local double_sharp_marg = -20
	local flat_marg = -12.5
	local tab
	
	if sharp == -2 then
		tab = "{{sharpness-flat2}}"
	elseif sharp == -1 then
		tab = "{{sharpness-flat1}}"
	elseif sharp == 0 then
		tab = "{| class=\"wikitable center-all\"\n"
			.. "|-\n"
			.. "! Step offset\n"
			.. "| −3 || −2 || −1 || 0 || +1 || +2 || +3\n"
			.. "|-\n"
			.. "! Symbol\n"
			.. string.format(spanf, arrow_marg, string.rep("&#x202F;[[File:Down arrow petaluma script.svg|10px]]", 3))
			.. string.format(spanf, arrow_marg, string.rep("&#x202F;[[File:Down arrow petaluma script.svg|10px]]", 2))
			.. string.format(spanf, arrow_marg, "&#x202F;[[File:Down arrow petaluma script.svg|10px]]")
			.. string.format(spanf, arrow_marg - 15, "&#x202F;[[File:Heji18.svg|15px]]")
			.. string.format(spanf, arrow_marg, "&#x202F;[[File:Up arrow petaluma script.svg|10px]]")
			.. string.format(spanf, arrow_marg, string.rep("&#x202F;[[File:Up arrow petaluma script.svg|10px]]", 2))
			.. string.format(spanf, arrow_marg, string.rep("&#x202F;[[File:Up arrow petaluma script.svg|10px]]", 3))
			.. "|}"
	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) -- sharpness of note
			local marg -- margin value for formatting
			local s = ""
			
			if cs == 0 then
				marg = arrow_marg
			elseif cs == 1 then
				marg = sharp_marg
			elseif cs == 2 then
				marg = double_sharp_marg
			else
				marg = 0 -- Failsafe
			end
			
			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
					s = s .. "&#x202F;[[File:Down arrow petaluma script.svg|10px]]&#x202F;[[File:Quip narrow.svg|9px]]"
				else
					for j = 1, (i - (sharp * math.floor(i / sharp))) % 5 do
						s = s .. "&#x202F;[[File:Up arrow petaluma script.svg|10px]]"
					end
				end
				for j = 1, math.floor((i - (sharp * math.floor(i / sharp))) / 5) do
					s = s .. "&#x202F;[[File:Quip narrow.svg|9px]]"
				end
			else
				if ((sharp * math.ceil(i / sharp)) - i) % 5 == 4 then
					s = s .. "&#x202F;[[File:Up arrow petaluma script.svg|10px]]&#x202F;[[File:Quid narrow.svg|9px]]"
				else
					for j = 1, ((sharp * math.ceil(i / sharp)) - i) % 5 do
						s = s .. "&#x202F;[[File:Down arrow petaluma script.svg|10px]]"
					end
				end
				for j = 1, math.floor(((sharp * math.ceil(i / sharp)) - i) / 5) do
					s = s .. "&#x202F;[[File:Quid narrow.svg|9px]]"
				end
			end
			if cs == 1 then
				s = s .. "&#x202F;&#x202F;[[File:Heji25.svg|16px]]"
			elseif cs == 2 then
				s = s .. "&#x202F;&#x202F;[[File:Heji32.svg|21px]]"
			end
			tab = tab .. string.format(spanf, marg, s)
		end
		
		tab = tab .. "|-\n! Flat symbol\n"
		
		for i = 1, sharp * 2 + 1 do
			local cs = math.ceil((i / sharp) - 0.5) -- flatness of note
			local marg -- margin value for formatting
			local s = ""
			
			if cs == 0 then
				marg = arrow_marg
			elseif cs == 1 or cs == 2 then
				marg = flat_marg
			end
			
			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
					s = s .. "&#x202F;[[File:Up arrow petaluma script.svg|10px]]&#x202F;[[File:Quid narrow.svg|9px]]"
				else
					for j = 1, (i - (sharp * math.floor(i / sharp))) % 5 do
						s = s .. "&#x202F;[[File:Down arrow petaluma script.svg|10px]]"
					end
				end
				for j = 1, math.floor((i - (sharp * math.floor(i / sharp))) / 5) do
					s = s .. "&#x202F;[[File:Quid narrow.svg|9px]]"
				end
			else
				if ((sharp * math.ceil(i / sharp)) - i) % 5 == 4 then
					s = s .. "&#x202F;[[File:Down arrow petaluma script.svg|10px]]&#x202F;[[File:Quip narrow.svg|9px]]"
				else
					for j = 1, ((sharp * math.ceil(i / sharp)) - i) % 5 do
						s = s .. "&#x202F;[[File:Up arrow petaluma script.svg|10px]]"
					end
				end
				for j = 1, math.floor(((sharp * math.ceil(i / sharp)) - i) / 5) do
					s = s .. "&#x202F;[[File:Quip narrow.svg|9px]]"
				end
			end
			if cs == 1 then
				s = s .. "&#x202F;&#x202F;[[File:Heji11.svg|16px]]"
			elseif cs == 2 then
				s = s .. "&#x202F;&#x202F;[[File:Heji4.svg|27px]]"
			end
			tab = tab .. string.format(spanf, marg, s)
		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