Module:Sharpness documentation: 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 8: Line 8:


-- 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 25: Line 25:


if s == 0 then
if s == 0 then
-- Sharp-0 EDOs (lower 5 multiples of 7) are redundant, take care of that right away
out_str = out_str
out_str = out_str
.. "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
-- Otherwise
out_str = out_str
out_str = out_str
.. "for [[edo]]s where a sharp "
.. "for [[edo]]s where a sharp "
Line 52: Line 54:
if extension == "" then
if extension == "" then
if math.abs(s) == 2 then
if math.abs(s) == 2 then
-- If a sharp raises by two steps
out_str = out_str
out_str = out_str
.. "comprises sharps, flats, and Stein–Zimmerman [[24edo #Notation|quartertone]] accidentals."
.. "comprises sharps, flats, and Stein–Zimmerman [[24edo #Notation|quartertone]] accidentals."
else
else
-- Otherwise (if a sharp raises by three or more steps)
out_str = out_str
out_str = out_str
.. "is based on [[ups and downs notation]] and comprises sharps, flats, "
.. "is based on [[ups and downs notation]] and comprises sharps, flats, "
Line 60: Line 64:
.. "with arrows from [[Helmholtz–Ellis notation]]."
.. "with arrows from [[Helmholtz–Ellis notation]]."
end
end
elseif extension == "a" or extension == "A" then -- extension for modern-style ups and downs
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."
out_str = out_str .. "is based on [[ups and downs notation]] using separate arrows."
end
end
Line 73: Line 78:
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
out_str = out_str
Line 90: Line 96:
end
end


-- display the "see also" section for sharpness-2 and above
-- Display the "see also" section for sharpness-2 and above
if s >= 2 then
if s >= 2 then
local basic = "Template:Sharpness-" .. typ .. value
local basic = "Template:Sharpness-" .. typ .. value
Line 97: Line 103:
if (extension == "a" or extension == "A") then
if (extension == "a" or extension == "A") then
-- If the template shows separate arrows
out_str = out_str
out_str = out_str
.. "* [[Alternative symbols for ups and downs notation]]\n"
.. "* [[Alternative symbols for ups and downs notation]]\n"
Line 104: Line 111:
or "the classic version of this template that shows arrows attached to standard accidentals.")
or "the classic version of this template that shows arrows attached to standard accidentals.")
else
else
-- If the template shows integrated (HEJI-like) arrows
out_str = out_str .. "{{#ifexist: " .. basic .. "a|* [[" .. basic .. "a]] – "
out_str = out_str .. "{{#ifexist: " .. basic .. "a|* [[" .. basic .. "a]] – "
.. "an alternate version of this template that shows separate arrows.\n|}}"
.. "an alternate version of this template that shows separate arrows.\n|}}"
if string.lower(suffix) ~= "extended" then
if string.lower(suffix) == "extended" then
out_str = out_str .. "{{#ifexist: " .. basic .. "-extended|* [[" .. basic .. "-extended]] – "
-- If we are on an extended version of a template (showing more arrows than the minimum)
.. "an alternate version of this template that includes "
if s == 3 then
out_str = out_str .. "double"
elseif s == 5 then
out_str = out_str .. "triple"
end
out_str = out_str .. " arrows.|}}"
else
out_str = out_str .. "{{#ifexist: ".. basic .. "|* [[" .. basic .. "]] – "
out_str = out_str .. "{{#ifexist: ".. basic .. "|* [[" .. basic .. "]] – "
.. "the basic version of this template.|}}"
.. "the basic version of this template.|}}"
else
-- Otherwise, add an additional note for possible extended versions, if they exist
if s == 3 or s == 5 then
out_str = out_str .. "{{#ifexist: " .. basic .. "-extended|* [[" .. basic .. "-extended]] – "
.. "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
out_str = out_str .. "double"
elseif s == 5 then
-- Sharp-5 EDOs normally need double arrows, and note that sometimes
-- triple arrows may be needed
out_str = out_str .. "triple"
end
out_str = out_str .. " arrows.|}}"
end
end
end
end
end

Revision as of 16:30, 14 February 2025

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
4 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 yesno = require("Module:yesno")
local module = {}

function module.main(frame)
	local in_str = frame.args["input"]
	local note = frame.args["note"] or ""
	local notation = frame.args["notation"] or ""

	-- 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 out_str = "This template is used "

	if s == 0 then
		-- Sharp-0 EDOs (lower 5 multiples of 7) are redundant, take care of that right away
		out_str = out_str
			.. "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
		out_str = out_str
			.. "for [[edo]]s where a sharp "
			.. ((s < 0) and "lowers" or "raises")
			.. " by "
			.. math.abs(s)
			.. " step"

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

		out_str = out_str .. "."

		if notation == "" then
			out_str = out_str .. " This symbol set "

			if math.abs(s) == 1 then
				out_str = out_str .. "is identical to standard notation."
			else
				if extension == "" then
					if math.abs(s) == 2 then
						-- If a sharp raises by two steps
						out_str = out_str
							.. "comprises sharps, flats, and Stein&ndash;Zimmerman [[24edo #Notation|quartertone]] accidentals."
					else
						-- Otherwise (if a sharp raises by three or more steps)
						out_str = out_str
							.. "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 ")
							.. "with arrows from [[Helmholtz&ndash;Ellis notation]]."
					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
		else
			out_str = out_str .. " It is based on " .. notation .. "."
		end

		-- display custom note
		if note then
			out_str = out_str .. " " .. note
		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

			out_str = out_str
				.. "\n\n<h3>Parameters</h3>\n"
				.. "Passing <code>{{pipe}}"
				.. n_edo
				.. "</code> will change '''Step offset''' to '''Semitones''' in the case of [["
				.. 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

		-- Display the "see also" section for sharpness-2 and above
		if s >= 2 then
			local basic = "Template:Sharpness-" .. typ .. value
			local basic_suf = basic .. "-" .. suffix
			out_str = out_str .. "\n\n<h3>See also</h3>\n"
			
			if (extension == "a" or extension == "A") then
				-- If the template shows separate arrows
				out_str = out_str
					.. "* [[Alternative symbols for ups and downs notation]]\n"
					.. "* [[{{#ifexist: " .. basic_suf .. "|" .. basic_suf .. "|" .. basic .. "}}]] &ndash; "
					.. (s == 2
						and "uses Stein&ndash;Zimmerman 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
				out_str = out_str .. "{{#ifexist: " .. basic .. "a|* [[" .. basic .. "a]] &ndash; "
					.. "an alternate version of this template that shows separate arrows.\n|}}"
				
				if string.lower(suffix) == "extended" then
					-- If we are on an extended version of a template (showing more arrows than the minimum)
					out_str = out_str .. "{{#ifexist: ".. basic .. "|* [[" .. basic .. "]] &ndash; "
						.. "the basic version of this template.|}}"
				else
					-- Otherwise, add an additional note for possible extended versions, if they exist
					if s == 3 or s == 5 then
						out_str = out_str .. "{{#ifexist: " .. basic .. "-extended|* [[" .. basic .. "-extended]] &ndash; "
						.. "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
							out_str = out_str .. "double"
						elseif s == 5 then
							-- Sharp-5 EDOs normally need double arrows, and note that sometimes
							-- triple arrows may be needed
							out_str = out_str .. "triple"
						end
						
						out_str = out_str .. " arrows.|}}"
					end
				end
			end
		end
	end

	local is_debug = yesno(frame.args["debug"])
	return frame:preprocess(is_debug == true and "<pre>" .. out_str .. "</pre>" or out_str)
end

return module