Module:Harmonics intro: Difference between revisions

Sintel (talk | contribs)
Formatting, skip 2
Sintel (talk | contribs)
phrasing
Line 29: Line 29:
return '<strong class="error">Template:Harmonics intro requires a positive integer, e.g. <code>{{Harmonics intro|12}}</code>.</strong>'
return '<strong class="error">Template:Harmonics intro requires a positive integer, e.g. <code>{{Harmonics intro|12}}</code>.</strong>'
end
end
local base = sub and "Subharmonics" or "Harmonics"
local range = n .. EN_DASH .. 2 * n
local twin = sub and "Harmonics" or "Subharmonics"
local twin_title = (sub and "Harmonics " or "Subharmonics ") .. range
local title = string.format("%s %d%s%d", base, n, EN_DASH, 2 * n)
local twin_title = string.format("%s %d%s%d", twin, n, EN_DASH, 2 * n)


-- first sentence
-- "harmonics 12–24" is a noun phrase, not the name of a scale: plural, lower case
local bold = "'''" .. title .. "'''"
local phrase = (sub and "subharmonics " or "harmonics ") .. range
local akas = {}
for name in mw.text.gsplit(args.aka or "", "%s*;%s*") do
if name ~= "" then
akas[#akas + 1] = "'''" .. name .. "'''"
end
end
local aka = ""
if #akas > 0 then
aka = ", also known as " .. table.concat(akas, " and ") .. ","
end


local out = {}
local out = {}
if sub then
if sub then
out[#out + 1] = string.format(
out[#out + 1] = string.format(
"%s%s is the scale formed by the [[subharmonic]]s %d through %d of the [[subharmonic series]], that is, the ratios %d/%d, %d/%d, …, %d/%d above the root. ",
"The '''%s''' are the [[subharmonic]]s %d through %d of the [[subharmonic series]]. Above the root they form the ratios %d/%d, %d/%d, …, %d/%d and span one octave. ",
bold,
phrase,
aka,
n,
n,
2 * n,
2 * n,
Line 62: Line 49:
n
n
)
)
out[#out + 1] = string.format("Used as a scale, this set is also called mode %d of the subharmonic series. ", n)
else
else
out[#out + 1] = string.format(
out[#out + 1] = string.format(
"%s%s is the [[Harmonic series#Segments|harmonic segment]] %d::%d, consisting of harmonics %d through %d (%s) and spanning one octave above the root. ",
"The '''[[Harmonic series#Segments|harmonic segment]] %d::%d''' (also '''%s''') consists of harmonics %d through %d (%s) and spans one octave above the root. ",
bold,
aka,
n,
n,
2 * n,
2 * n,
phrase,
n,
n,
2 * n,
2 * n,
chord(n, 2 * n)
chord(n, 2 * n)
)
)
out[#out + 1] = string.format("Used as a scale, it is also called mode %d of the harmonic series. ", n)
end
-- other names, given as aka="name; name"
local akas = {}
for name in mw.text.gsplit(args.aka or "", "%s*;%s*") do
if name ~= "" then
akas[#akas + 1] = "'''" .. name .. "'''"
end
end
if #akas > 0 then
out[#out + 1] = "It is also known as " .. table.concat(akas, " and ") .. ". "
end
end
-- second sentence: mode name
 
out[#out + 1] =
string.format("It is also called mode %d of the %s series. ", n, sub and "subharmonic" or "harmonic")
-- inverse
-- inverse
if n ~= 2 and page_exists(twin_title) then -- 2–4 is its own inverse
if n ~= 2 and page_exists(twin_title) then -- 2–4 is its own inverse
out[#out + 1] = string.format("Its inverse is [[%s]]. ", twin_title)
out[#out + 1] = string.format(
"The inverse consists of [[%s|%s]]. ",
twin_title,
(sub and "harmonics " or "subharmonics ") .. range
)
end
end
return (table.concat(out):gsub("%s+$", ""))
return (table.concat(out):gsub("%s+$", ""))