Module:Sharpness documentation: Difference between revisions

From Xenharmonic Wiki
Jump to navigation Jump to search
ArrowHead294 (talk | contribs)
mNo edit summary
Dave Keenan (talk | contribs)
Added line break <br> before "This symbol set ...".
 
(30 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local yesno = require("Module:yesno")
local p = {}
local module = {}


function module.main(frame)
local yesno = require("Module:Yesno")
 
function p.main(frame)
local in_str = frame.args["input"]
local in_str = frame.args["input"]
local note = frame.args["note"] or ""
local note = frame.args["note"] or ""
local aux_note = frame.args["auxnote"] or ""
local notation = frame.args["notation"] or ""
local notation = frame.args["notation"] or ""
local debugg = yesno(frame.args["debug"])


-- typ: "sharp" or "flat"
-- typ: "sharp" or "flat"
-- value: absolute value of sharpness (the "n" as in sharp-n and flat-n)
-- value: Absolute value of sharpness (the "n" as in sharp-n and flat-n)
-- extension: used for identifying alternative symbol set
-- extension: Used for identifying alternative symbol set
local typ, value, extension, suffix = in_str:match("%-(%a*)(%d+)(%a*)-(%a*)")
local typ, value, extension, suffix = string.lower(in_str):match("%-(%a*)(%d+)(%a*)-?(%a*)")


-- signed sharpness
-- Signed sharpness
local s = tonumber(value)
local s = tonumber(value)
if typ == "flat" then
if typ == "flat" then
Line 22: Line 25:
end
end


local out_str = "This template is used "
local result = "This template is used "


if s == 0 then
if s == 0 then
out_str = out_str
-- Sharp-0 EDOs (lower 5 multiples of 7) are redundant, take care of that right away
result = result
.. "for {{EDOs| 7, 14, 21, 28, and 35 }} [[equal divisions of the octave]]. "
.. "for {{EDOs| 7, 14, 21, 28, and 35 }} [[equal divisions of the octave]]. "
.. "Since these tunings temper out the 3-limit augmented unison ([[2187/2048]], known as the Pythagorean apotome), "
.. "Since these tunings temper out the 3-limit augmented unison ([[2187/2048]], known as the Pythagorean apotome), "
.. "going up seven fifths brings one back to the root note, and as such, "
.. "going up seven fifths brings one back to the root note, and as such "
.. "the traditional sharps and flats are redundant and cannot raise or lower the pitch."
.. "the traditional sharps and flats are redundant and cannot raise or lower the pitch."
else
else
out_str = out_str
-- Otherwise
result = result
.. "for [[edo]]s where a sharp "
.. "for [[edo]]s where a sharp "
.. ((s < 0) and "lowers" or "raises")
.. ((s < 0) and "lowers" or "raises")
Line 39: Line 44:


if math.abs(s) ~= 1 then
if math.abs(s) ~= 1 then
out_str = out_str .. "s"
result = result .. "s"
end
end


out_str = out_str .. "."
result = result .. "."
end


if notation == "" then
if notation == "" then
out_str = out_str .. " This symbol set "
result = result .. "<br>This symbol set "


if math.abs(s) == 1 then
if math.abs(s) == 1 then
out_str = out_str .. "is identical to standard notation."
result = result .. "is identical to standard notation."
else
else
if extension == "" then
if extension == "" then
if math.abs(s) == 2 then
if math.abs(s) == 2 then
out_str = out_str
-- If a sharp raises by two steps
.. "comprises sharps, flats, and Stein&ndash;Zimmerman [[24edo #Notation|quartertone]] accidentals."
result = result
.. "comprises sharps, flats, and Stein&ndash;Zimmermann [[24edo #Notation|quartertone]] accidentals."
else
if s == 0 then
result = result
.. "is based on [[ups and downs notation]] and comprises naturals "
.. "with arrows from [[Helmholtz&ndash;Ellis notation]]."
else
else
out_str = out_str
-- Otherwise (if a sharp raises by three or more steps)
result = result
.. "is based on [[ups and downs notation]] and comprises sharps, flats, "
.. "is based on [[ups and downs notation]] and comprises sharps, flats, "
.. (s % 2 == 0 and "naturals, and Stein&ndash;Zimmerman [[24edo #Notation|quartertone]] accidentals " or "and naturals ")
.. (s % 2 == 0 and "naturals, and Stein&ndash;Zimmermann [[24edo #Notation|quartertone]] accidentals " or "and naturals ")
.. "with arrows from [[Helmholtz&ndash;Ellis notation]]."
.. "with arrows from [[Helmholtz&ndash;Ellis notation]]."
end
end
elseif extension == "a" or extension == "A" then -- extension for modern-style ups and downs
out_str = out_str .. "is based on [[ups and downs notation]] using separate arrows."
end
end
elseif extension == "a" or extension == "A" then
-- Extension for modern-style ups and downs
result = result .. "is based on [[ups and downs notation]] using separate up and down chevrons."
end
end
else
out_str = out_str .. " It is based on " .. notation .. "."
end
end
else
result = result .. string.format(" It is based on %s.", notation)
end


-- display custom note
-- display custom notes
if note then
if note or aux_note then
out_str = out_str .. " " .. note
result = result .. " " .. note ..(aux_note ~= "" and "\n\n" .. aux_note or "")
end
end


-- display the note about supersets of 12edo for sharpness-1 and above
-- Display the note about supersets of 12edo for sharpness-1 and above and set the edo number for supersets of 12edo
if s >= 1 then
if s >= 1 then
local n_edo = s * 12 -- edo number for supersets of 12edo
local n_edo = s * 12


out_str = out_str
result = result
.. "\n\n<h3>Parameters</h3>\n"
.. "\n\n<h3>Parameters</h3>\n"
.. "Passing <code>{{pipe}}"
.. string.format("Passing in <code>%d</code> as a single unnamed parameter will change "
.. n_edo
.. "'''Step offset''' to '''Semitones''' in the case of [[%dedo]]", n_edo, n_edo)
.. "</code> will change '''Step offset''' to '''Semitones''' in the case of [["
if s >= 2 then
.. n_edo
result = result .. string.format(", since %dedo is a superset of [[12edo]]", n_edo)
.. "edo]]"
if s >= 2 then
out_str = out_str .. ", since " .. n_edo .. "edo is a superset of [[12edo]]"
end
out_str = out_str .. "."
end
end
result = result .. "."
end


-- display the "see also" section for sharpness-3 and above
-- Display a "see also" section for sharpness-2 and above, and sharpness-0
if extension == "a" or extension == "A" or s >= 2 then
if s >= 2 or s <= -2 or s == 0 then
out_str = out_str .. "\n\n<h3>See also</h3>\n"
local basic = "Template:Sharpness-" .. typ .. value
if s >= 2 then
local basic_suf = basic .. "-" .. suffix
out_str = out_str .. "* [[Alternative symbols for ups and downs notation]]"
result = result .. "\n\n<h3>See also</h3>\n"
end
.. "* [[Alternative symbols for ups and downs notation]]\n"
if s >= 3 then
out_str = out_str .. "\n* [[Template:Sharpness-" .. typ .. value .. "-" .. suffix .. "]] "
if (extension == "a" or extension == "A") then
.. "&ndash; the classic version of this template that attaches arrows to accidentals."
-- If the template shows separate up and down chevrons
result = result
.. string.format("* [[{{#ifexist: %s|%s|%s}}]] &ndash; ", basic_suf, basic_suf, basic)
.. (s == 2
and "uses Stein&ndash;Zimmermann quarter tone accidentals."
or "the classic version of this template that shows arrows attached to standard accidentals.")
else
-- If the template shows integrated (HEJI-like) arrows
result = result .. string.format("{{#ifexist: %sa|* [[%sa]] &ndash; ", basic, basic)
.. "an alternate version of this template that shows separate up and down chevrons.\n|}}"
if string.lower(suffix) ~= "" then
-- If we are on a different version of a template (e.g. "extended" ones that show more arrows than the minimum)
result = result .. string.format("{{#ifexist: %s|* [[%s]] &ndash; ", basic, basic)
.. "the basic version of this template.|}}"
else
-- Otherwise, add an additional note for possible extended versions, if they exist
if s % 2 == 1 and s >= 3 then
result = result .. string.format("{{#ifexist: %s-extended|* [[%s-extended]] &ndash; ", basic, basic)
.. "an alternate version of this template that includes "
if s == 3 then
-- Sharp-3 EDOs normally only need single arrows, but note that
-- sometimes double arrows may be needed
result = result .. "double"
elseif s == 5 then
-- Sharp-5 EDOs normally need double arrows, and note that sometimes
-- triple arrows may be needed
result = result .. "triple"
end
result = result .. " arrows.|}}"
end
end
end
end
end
end
end


local is_debug = yesno(frame.args["debug"])
-- Debugger option
return frame:preprocess(is_debug == true and "<pre>" .. out_str .. "</pre>" or out_str)
if debugg == true then
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
end
return frame:preprocess(result)
end
end


return module
return p

Latest revision as of 04:40, 3 May 2026

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

This module is used for Template:Sharpness documentation to automate information for sharpness templates (templates that show how many steps sharps or flats raise or lower by).

By default, it handles standard sharps and flats, quarter-tone accidentals, and ups and downs notation.

Introspection summary for Module:Sharpness documentation 
Functions provided (1)
Line Function Params
5 main (invokable) (frame)
Lua modules required (1)
Variable Module Functions used
yesno Module:Yesno yesno

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

See also


local p = {}

local yesno = require("Module:Yesno")

function p.main(frame)
	local in_str = frame.args["input"]
	local note = frame.args["note"] or ""
	local aux_note = frame.args["auxnote"] or ""
	local notation = frame.args["notation"] or ""
	local debugg = yesno(frame.args["debug"])

	-- typ: "sharp" or "flat"
	-- value: Absolute value of sharpness (the "n" as in sharp-n and flat-n)
	-- extension: Used for identifying alternative symbol set
	local typ, value, extension, suffix = string.lower(in_str):match("%-(%a*)(%d+)(%a*)-?(%a*)")

	-- Signed sharpness
	local s = tonumber(value)
	if typ == "flat" then
		s = -s
	end

	if extension == nil then
		extension = ""
	end

	local result = "This template is used "

	if s == 0 then
		-- Sharp-0 EDOs (lower 5 multiples of 7) are redundant, take care of that right away
		result = result
			.. "for {{EDOs| 7, 14, 21, 28, and 35 }} [[equal divisions of the octave]]. "
			.. "Since these tunings temper out the 3-limit augmented unison ([[2187/2048]], known as the Pythagorean apotome), "
			.. "going up seven fifths brings one back to the root note, and as such "
			.. "the traditional sharps and flats are redundant and cannot raise or lower the pitch."
	else
		-- Otherwise
		result = result
			.. "for [[edo]]s where a sharp "
			.. ((s < 0) and "lowers" or "raises")
			.. " by "
			.. math.abs(s)
			.. " step"

		if math.abs(s) ~= 1 then
			result = result .. "s"
		end

		result = result .. "."
	end

	if notation == "" then
		result = result .. "<br>This symbol set "

		if math.abs(s) == 1 then
			result = result .. "is identical to standard notation."
		else
			if extension == "" then
				if math.abs(s) == 2 then
					-- If a sharp raises by two steps
					result = result
						.. "comprises sharps, flats, and Stein&ndash;Zimmermann [[24edo #Notation|quartertone]] accidentals."
				else
					if s == 0 then
						result = result
							.. "is based on [[ups and downs notation]] and comprises naturals "
							.. "with arrows from [[Helmholtz&ndash;Ellis notation]]."
					else
						-- Otherwise (if a sharp raises by three or more steps)
						result = result
							.. "is based on [[ups and downs notation]] and comprises sharps, flats, "
							.. (s % 2 == 0 and "naturals, and Stein&ndash;Zimmermann [[24edo #Notation|quartertone]] accidentals " or "and naturals ")
							.. "with arrows from [[Helmholtz&ndash;Ellis notation]]."
					end
				end
			elseif extension == "a" or extension == "A" then
				-- Extension for modern-style ups and downs
				result = result .. "is based on [[ups and downs notation]] using separate up and down chevrons."
			end
		end
	else
		result = result .. string.format(" It is based on %s.", notation)
	end

	-- display custom notes
	if note or aux_note then
		result = result .. " " .. note ..(aux_note ~= "" and "\n\n" .. aux_note or "")
	end

	-- Display the note about supersets of 12edo for sharpness-1 and above and set the edo number for supersets of 12edo
	if s >= 1 then
		local n_edo = s * 12

		result = result
			.. "\n\n<h3>Parameters</h3>\n"
			.. string.format("Passing in <code>%d</code> as a single unnamed parameter will change "
			.. "'''Step offset''' to '''Semitones''' in the case of [[%dedo]]", n_edo, n_edo)
		if s >= 2 then
			result = result .. string.format(", since %dedo is a superset of [[12edo]]", n_edo)
		end
		result = result .. "."
	end

	-- Display a "see also" section for sharpness-2 and above, and sharpness-0
	if s >= 2 or s <= -2 or s == 0 then
		local basic = "Template:Sharpness-" .. typ .. value
		local basic_suf = basic .. "-" .. suffix
		result = result .. "\n\n<h3>See also</h3>\n"
			.. "* [[Alternative symbols for ups and downs notation]]\n"
		
		if (extension == "a" or extension == "A") then
			-- If the template shows separate up and down chevrons
			result = result
				.. string.format("* [[{{#ifexist: %s|%s|%s}}]] &ndash; ", basic_suf, basic_suf, basic)
				.. (s == 2
					and "uses Stein&ndash;Zimmermann quarter tone accidentals."
					or "the classic version of this template that shows arrows attached to standard accidentals.")
		else
			-- If the template shows integrated (HEJI-like) arrows
			result = result .. string.format("{{#ifexist: %sa|* [[%sa]] &ndash; ", basic, basic)
				.. "an alternate version of this template that shows separate up and down chevrons.\n|}}"
			
			if string.lower(suffix) ~= "" then
				-- If we are on a different version of a template (e.g. "extended" ones that show more arrows than the minimum)
				result = result .. string.format("{{#ifexist: %s|* [[%s]] &ndash; ", basic, basic)
					.. "the basic version of this template.|}}"
			else
				-- Otherwise, add an additional note for possible extended versions, if they exist
				if s % 2 == 1 and s >= 3 then
					result = result .. string.format("{{#ifexist: %s-extended|* [[%s-extended]] &ndash; ", basic, basic)
					.. "an alternate version of this template that includes "
				
					if s == 3 then
						-- Sharp-3 EDOs normally only need single arrows, but note that 
						-- sometimes double arrows may be needed
						result = result .. "double"
					elseif s == 5 then
						-- Sharp-5 EDOs normally need double arrows, and note that sometimes
						-- triple arrows may be needed
						result = result .. "triple"
					end
					
					result = result .. " arrows.|}}"
				end
			end
		end
	end

	-- Debugger option
	if debugg == true then
		result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
	end
	
	return frame:preprocess(result)
end

return p