Ero sivun ”Moduuli:Kitarakirja” versioiden välillä

Poistettu sisältö Lisätty sisältö
Hunsvotti (keskustelu | muokkaukset)
Ei muokkausyhteenvetoa
Hunsvotti (keskustelu | muokkaukset)
Ei muokkausyhteenvetoa
Rivi 1:
local NUOTIT = {
C = 0,
CIS = 1,
D = 2,
DIS = 3,
E = 4,
F = 5,
FIS = 6,
G = 7,
GIS = 8,
A = 9,
AIS = 10,
B = 11,
}
 
Rivi 24:
}
 
-- Tiedot korvataan mahdollisilla annetuilla nimillä.
local nuotinnimet = {
"c",
Rivi 38 ⟶ 39:
"b<br/>(h)"
}
 
 
-- Indeksit nuottinnimet-taulukkoon
local indeces = {
["c"] = 0,
["c♯"] = 1,
["c𝄪"] = 2,
["d𝄫"] = 0,
["d♭"] = 1,
["d"] = 2,
["d♯"] = 3,
["d𝄪"] = 4,
["e𝄫"] = 2,
["e♭"] = 3,
["e"] = 4,
["e♯"] = 5,
["e𝄪"] = 6,
["f𝄫"] = 3,
["f♭"] = 4,
["f"] = 5,
["f♯"] = 6,
["f𝄪"] = 7,
["g𝄫"] = 5,
["g♭"] = 6,
["g"] = 7,
["g♯"] = 8,
["g𝄪"] = 9,
["a𝄫"] = 7,
["a♭"] = 8,
["a"] = 9,
["a♯"] = 10,
["a𝄪"] = 11,
["b𝄫"] = 9,
["b♭"] = 10,
["b"] = 11,
["b♯"] = 0,
["b𝄪"] = 1,
["c𝄫"] = 10,
["c♭"] = 11 }
 
 
function lilyoctave(index)
if index < 0 then
return string.rep(",", -index)
elseif index > 0 then
return string.rep("'", index)
end
return ""
end
 
-- Muuttaa nuotinnimen lilypond-muotoon, esim. "e♭" -> "ees"
function lilyfy(notename)
local out = notename
if notename:find("/") then
error("Enharmoniaa ei ole ratkaistu: " .. notename)
end
 
out = string.gsub(out, "♯", "is")
out = string.gsub(out, "𝄪", "isis")
out = string.gsub(out, "♭", "es")
out = string.gsub(out, "𝄫", "eses")
 
return out
end
 
-- Palauttaa nuotin nimen Lilypond-notaatiolla, esim. "dis''"
function lilynote(index)
local octave = math.floor((index - (NUOTIT.C + 3*12)) / 12)
return lilyfy(nuotinnimet[index % 12 + 1]) .. lilyoctave(octave)
end
 
function notename(index)
local name = nuotinnimet[index % 12 + 1]
if name == "b" then
return "b<br/>(h)"
elseif name == "b♭" then
return "b♭<br/>(b)"
elseif name == "b♭" then
return "b𝄫<br/>(b♭)"
elseif name == "b♭" then
return "b♯<br/>(h♯)"
elseif name == "b♭" then
return "b𝄪<br/>(h𝄪)"
end
return name
end
 
function string:split(sep)
local sep, fields = sep or ":", {}
local pattern = string.format("([^%s]+)", sep)
self:gsub(pattern, function(c) fields[#fields+1] = c end)
return fields
end
 
function table.clone(orig)
local orig_type = type(orig)
local copy = {}
for orig_key, orig_value in pairs(orig) do
copy[orig_key] = orig_value
end
return copy
end
 
local p = {}
 
 
function p.Sointuote(frame)
local s_idx = 0
local f_idx = -1
local frets = { -1, -1, -1, -1, -1, -1 }
local fingering = { -1, -1, -1, -1, -1, -1 }
local nauha = (tonumber(frame.args.nauhanumero) or 1) - 1
local output = table.clone(frame.args)
local notenames = {}
local noteindeces = { -1, -1, -1, -1, -1, -1 }
 
if frame.args.nuotit then
notenames = frame.args.nuotit:split(",")
end
-- Annetaan uudet nimet oletusnuotinnimien tilalle
for i, v in ipairs(notenames) do
local index = indeces[v]
print("indeksi: " .. (index + 1) .. " = " .. v)
if index > -1 then
nuotinnimet[index + 1] = v
end
end
 
for i, param in ipairs(frame.args) do
s_idx = (i - 1) % 6 + 1
if s_idx == 1 then
f_idx = f_idx + 1
end
if param == "o" and i >= 0 and i < 7 then -- Vapaat kielet
frets[s_idx] = f_idx
elseif param == "o" or param == "C" or param == "D" or param == "-" then
frets[s_idx] = f_idx + nauha
end
 
if i > 36 and i <= 42 then
fingering[s_idx] = param
end
end
 
local lilyoutput = {
"",
"",
"",
"",
"",
"" }
 
 
output[43] = ""
output[44] = ""
output[45] = ""
output[46] = ""
output[47] = ""
output[48] = ""
 
if frets[1] ~= -1 then
outputnoteindeces[431] = nuotinnimet[(viritys[1] + frets[1]) % 12 + 1]
output[43] = notename(noteindeces[1])
lilyoutput[1] = lilynote(noteindeces[1])
end
if frets[2] ~= -1 then
outputnoteindeces[442] = nuotinnimet[(viritys[2] + frets[2]) % 12 + 1]
output[44] = notename(noteindeces[2])
lilyoutput[2] = lilynote(noteindeces[2])
end
if frets[3] ~= -1 then
outputnoteindeces[453] = nuotinnimet[(viritys[3] + frets[3]) % 12 + 1]
output[45] = notename(noteindeces[3])
lilyoutput[3] = lilynote(noteindeces[3])
end
if frets[4] ~= -1 then
outputnoteindeces[464] = nuotinnimet[(viritys[4] + frets[4]) % 12 + 1]
output[46] = notename(noteindeces[4])
lilyoutput[4] = lilynote(noteindeces[4])
end
if frets[5] ~= -1 then
outputnoteindeces[475] = nuotinnimet[(viritys[5] + frets[5]) % 12 + 1]
output[47] = notename(noteindeces[5])
lilyoutput[5] = lilynote(noteindeces[5])
end
if frets[6] ~= -1 then
outputnoteindeces[486] = nuotinnimet[(viritys[6] + frets[6]) % 12 + 1]
output[48] = notename(noteindeces[6])
lilyoutput[6] = lilynote(noteindeces[6])
end
 
 
return frame:expandTemplate{title='Kitaran sointuote', args = output}
local lilyoutputtab = table.clone(lilyoutput)
-- Lisätään kielen numero nuotteihin, joista luodaan tabulatuuri.
for i, v in ipairs(lilyoutputtab) do
lilyoutputtab[i] = lilyoutputtab[i] .. "\\" .. (6 - i + 1)
end
 
lilyout = [=[
<<
\override Score.BarLine.break-visibility = ##(#f #t #t)
\new Staff {
\clef "treble_8"
\once \override Staff.TimeSignature #'stencil = ##f
<]=] .. table.concat(lilyoutput, " ") .. [=[>1
}
\new TabStaff {
\override Stem #'transparent = ##t
\override Beam #'transparent = ##t
<]=] .. table.concat(lilyoutputtab, " ") .. [=[>
}
>>
]=]
--return frame:expandTemplate{title='Kitaran sointuote', args = output}
return "{{Kitaran sointuote|\n" .. table.concat(output, "|") .. "}} <score>\n" .. lilyout .. "</score>"
 
end