Module:Harmonics infobox: Difference between revisions
use _infobox, no line break |
m Unify the case and plural |
||
| Line 1: | Line 1: | ||
-- Module:Harmonics infobox | -- Module: Harmonics infobox | ||
-- Infobox for "Harmonics n–2n" and "Subharmonics n–2n" pages. | -- Infobox for "Harmonics n–2n" and "Subharmonics n–2n" pages. | ||
-- Called through Template:Infobox | -- Called through Template: Infobox harmonics and Template: Infobox subharmonics. | ||
local p = {} | local p = {} | ||
local getArgs = require("Module:Arguments").getArgs | local getArgs = require("Module:Arguments").getArgs | ||
| Line 11: | Line 11: | ||
-- category names, in one place | -- category names, in one place | ||
local CATEGORY = { harmonics = "Overtone | local CATEGORY = { harmonics = "Overtone scales", subharmonics = "Undertone scales" } | ||
local CATEGORY_PRIME = { harmonics = "Prime overtone | local CATEGORY_PRIME = { harmonics = "Prime overtone scales", subharmonics = "Prime undertone scales" } | ||
local function cents(num, den) | local function cents(num, den) | ||
| Line 26: | Line 26: | ||
local n = tonumber(args[1] or args.n or args.steps) | local n = tonumber(args[1] or args.n or args.steps) | ||
if not n or n < 1 or n ~= math.floor(n) then | if not n or n < 1 or n ~= math.floor(n) then | ||
return '<strong class="error">Template:Infobox | return '<strong class="error">Template:Infobox harmonics requires a positive integer, e.g. <code>{{Infobox harmonics|12}}</code>.</strong>' | ||
end | end | ||
local sub = kind == "subharmonics" | local sub = kind == "subharmonics" | ||
| Line 47: | Line 47: | ||
local sharp, flat, exact | local sharp, flat, exact | ||
if sub then | if sub then | ||
-- degree k has ratio 2n/(2n-k); a fifth needs 2n-k = 4n/3 | -- degree k has ratio 2n/(2n - k); a fifth needs 2n - k = 4n/3 | ||
local m = math.floor(4 * n / 3) | local m = math.floor(4 * n / 3) | ||
if (4 * n) % 3 == 0 then | if (4 * n) % 3 == 0 then | ||
| Line 55: | Line 55: | ||
end | end | ||
else | else | ||
-- degree k has ratio (n+k)/n; a fifth needs n+k = 3n/2 | -- degree k has ratio (n + k)/n; a fifth needs n + k = 3n/2 | ||
local k = n + math.ceil(n / 2) | local k = n + math.ceil(n / 2) | ||
if n % 2 == 0 then | if n % 2 == 0 then | ||