Module:Ups and downs sharpness: Difference between revisions

Tristanbay (talk | contribs)
Added files for Stein-Zimmerman accidentals
Tristanbay (talk | contribs)
Added Stein-Zimmerman accidental functionality
Line 10: Line 10:
local edo = math.floor(frame.args["edo"])
local edo = math.floor(frame.args["edo"])
local sharp = sharp_n(edo)
local sharp = sharp_n(edo)
local use_sz -- whether to use Stein-Zimmerman accidentals or not
local spanf = "| <div style=\"width: %sem; margin-bottom: -45px; transform:translate(0, %spx); white-space: nowrap;\">%s</div>\n"
local spanf = "| <div style=\"width: %sem; margin-bottom: -45px; transform:translate(0, %spx); white-space: nowrap;\">%s</div>\n"
local cell_width -- forced cell width in ems
local cell_width -- forced cell width in ems
local arrow_marg = -10
local arrow_marg = -10
local sharp_marg = -22.5
local sharp_marg = -22.5
local double_sharp_marg = -22.5
local double_sharp_marg = -22.5
local flat_marg = -20
local flat_marg = -20
local double_flat_marg = -20
local half_sharp_marg = -22.5
local sesqui_sharp_marg = -22.5
local half_flat_marg = -20
local sesqui_flat_marg = -20
local tab
local tab
Line 36: Line 44:
local ssharp_t = "&#x202F;&#x202F;[[File:HeQu3.svg|16px]]"
local ssharp_t = "&#x202F;&#x202F;[[File:HeQu3.svg|16px]]"
local sflat_t = "&#x202F;&#x202F;[[File:HeQd3.svg|16px]]"
local sflat_t = "&#x202F;&#x202F;[[File:HeQd3.svg|16px]]"
if frame.args["sz"] == "true" and sharp % 2 == 0 then -- use SZ accidentals?
use_sz = true
sharp = sharp * 2
else
use_sz = false
end
if sharp == -2 then
if sharp == -2 then
Line 64: Line 79:
.. "! Semitones\n"
.. "! Semitones\n"
.. "| '''0'''"
.. "| '''0'''"
for i = 1, sharp * 2 do
for i = 1, use_sz and (use_sz and sharp * 4 or sharp * 2) + 1 do
tab = tab .. (i % sharp == 0 and string.format(" || '''%s'''", math.floor(i / sharp)) or string.format(" || {{Simplified fraction|%s|%s|true}}", i, sharp))
tab = tab .. (i % sharp == 0 and string.format(" || '''%s'''", math.floor(i / sharp)) or string.format(" || {{Simplified fraction|%s|%s|true}}", i, sharp))
end
end
Line 72: Line 87:
.. "! Step offset\n"
.. "! Step offset\n"
.. "| '''0'''"
.. "| '''0'''"
for i = 1, sharp * 2 do
for i = 1, use_sz and (use_sz and sharp * 4 or sharp * 2) + 1 do
tab = tab .. string.format((i % sharp == 0 and " || '''%s'''" or " || %s"), i)
tab = tab .. string.format((i % sharp == 0 and " || '''%s'''" or " || %s"), i)
end
end
end
end
tab = tab .. "\n|-\n! Sharp symbol\n"
tab = tab .. "\n|-\n! Sharp symbol\n" -- sharp row
.. "| rowspan=\"2\" style=\"white-space: nowrap; width: 3em;\" | " .. natural_t .. "\n"
.. "| rowspan=\"2\" style=\"white-space: nowrap; width: 3em;\" | " .. natural_t .. "\n"
for i = 1, sharp * 2 do
for i = 1, (use_sz and sharp * 4 or 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 (treated differently depending on SZ or no SZ)
local marg -- margin value for formatting
local marg -- margin value for formatting
local s = ""
local s = ""
if cs == 0 then
if cs == 0 then -- set vertical accidental margins
marg = arrow_marg
marg = arrow_marg
cell_width = 0
cell_width = 0
elseif cs == 1 then
elseif (cs == 1 and not use_sz) or (cs == 2 and use_sz) then
marg = sharp_marg
marg = sharp_marg
cell_width = 1.5
cell_width = 1.5
elseif cs == 2 then
elseif (cs == 2 and not use_sz) or (cs == 4 and use_sz) then
marg = double_sharp_marg
marg = double_sharp_marg
cell_width = 2.5
elseif cs == 1 and use_sz then
marg = half_sharp_marg
cell_width = 1
elseif cs == 3 and use_sz then
marg = sesqui_sharp_marg
cell_width = 2.5
cell_width = 2.5
else
else
marg = 0 -- Failsafe
marg = 0 -- failsafe
cell_width = 1
end
end
Line 125: Line 147:
end
end
end
end
if cs == 1 then
if (cs == 1 and not use_sz) or (cs == 2 and use_sz) then
s = s .. sharp_t
s = s .. sharp_t
elseif cs == 2 then
elseif (cs == 2 and not use_sz) or (cs == 4 and use_sz) then
s = s .. dsharp_t
s = s .. dsharp_t
elseif use_sz then
if cs == 1 then
s = s .. hsharp_t
elseif cs == 3 then
s = s .. ssharp_t
end
end
end
tab = tab .. string.format(spanf, cell_width, marg, s)
tab = tab .. string.format(spanf, cell_width, marg, s)
end
end
tab = tab .. "|-\n! Flat symbol\n"
tab = tab .. "|-\n! Flat symbol\n" -- flat row
for i = 1, sharp * 2 do
for i = 1, (use_sz and sharp * 4 or sharp * 2) + 1 do
local cs = math.ceil((i / sharp) - 0.5) -- flatness of note
local cs = math.ceil((i / sharp) - 0.5) -- flatness of note (treated differently depending on SZ or no SZ)
local marg -- margin value for formatting
local marg -- margin value for formatting
local s = ""
local s = ""
if cs == 0 then
if cs == 0 then -- set vertical accidental margins
marg = arrow_marg
marg = arrow_marg
cell_width = 0
cell_width = 0
elseif cs == 1 then
elseif (cs == 1 and not use_sz) or (cs == 2 and use_sz) then
marg = flat_marg
marg = flat_marg
cell_width = 1.5
cell_width = 1.5
elseif cs == 2 then
elseif (cs == 2 and not use_sz) or (cs == 4 and use_sz) then
marg = flat_marg
marg = double_flat_marg
cell_width = 3
elseif cs == 1 and use_sz then
marg = half_flat_marg
cell_width = 1.5
elseif cs == 3 and use_sz then
marg = sesqui_flat_marg
cell_width = 3
cell_width = 3
else
marg = 0 -- failsafe
cell_width = 1
end
end
Line 180: Line 217:
end
end
end
end
if cs == 1 then
if (cs == 1 and not use_sz) or (cs == 2 and use_sz) then
s = s .. flat_t
s = s .. flat_t
elseif cs == 2 then
elseif (cs == 2 and not use_sz) or (cs == 4 and use_sz) then
s = s .. dflat_t
s = s .. dflat_t
elseif use_sz then
if cs == 1 then
s = s .. hflat_t
elseif cs == 3 then
s = s .. sflat_t
end
end
end
tab = tab .. string.format(spanf, cell_width, marg, s)
tab = tab .. string.format(spanf, cell_width, marg, s)