[JW Lua] Create lyrics
Chris
marcel.denio at gmail.com
Mon Apr 7 07:43:30 CEST 2014
Hello All
Here's my new script for those interested here. (sorry it's in french)
But I have a problem with some transposing instruments.
For example, with a transposition "(Bb) UP M2 - Add 2 sharps" and a key
signature "Bb major" (in C),
the CalcPitchRaiseLower method (with true) does not return the correct
values.
Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://jwmusic.nu/pipermail/jwlua_jwmusic.nu/attachments/20140407/b8b35528/attachment.htm>
-------------- next part --------------
function plugindef()
-- This function and the 'finaleplugin' namespace
-- are both reserved for the plug-in definition.
finaleplugin.RequireSelection = true
finaleplugin.Author = "Chris"
finaleplugin.CategoryTags = "Lyric, Note"
return "Ajouter nom des notes", "Ajouter nom des notes", ""
end
local dialog = finenv.UserValueInput()
dialog.Title = "Ajouter nom des notes - Couche 1"
dialog:SetTypes("NumberedList","String","Number","NumberedList")
dialog:SetDescriptions("Langue :","Ajouter dans :","Numero :","Accords :")
dialog:SetLists({"Francais - Majuscules","Francais - minuscules","Francais - 1ere lettre Majuscule","Anglais - Majuscules","Anglais - minuscules"},
{"Couplet", "Refrain", "Partie"},nil,
{"Aucun nom","Note grave","Note aigue"})
dialog:SetInitValues(1,"Couplet", 1,1)
local returnvalues = dialog:Execute()
if returnvalues == nil then return end
function init()
if returnvalues[3] < 1 or returnvalues[3] > 500 then
finenv.UI():AlertInfo("Erreur sur le numero","Ajouter nom des notes")
return false
else
return true
end
end
function createStringLyrics()
local notes = {"DO RE MI FA SOL LA SI ",
"do re mi fa sol la si ",
"Do Re Mi Fa Sol La Si ",
"C D E F G A B ",
"c d e f g a b "}
local str = notes[returnvalues[1]]
return string.gsub(str, " ", "bb ") ..
string.gsub(str, " ", "b ") ..
str ..
string.gsub(str, " ", "# ") ..
string.gsub(str, " ", "## ")
end
function initLyrics(nextvs)
local lyric
local vs
if returnvalues[2] == "Couplet" then
lyric = finale.FCVerseLyricsText()
vs = finale.FCVerseSyllable()
elseif returnvalues[2] == "Refrain" then
lyric = finale.FCChorusLyricsText()
vs = finale.FCChorusSyllable()
else
lyric = finale.FCSectionLyricsText()
vs = finale.FCSectionSyllable()
end
vs.RawTextNumber=returnvalues[3]
-- next syllable
vs.SyllableNumber = 1
while vs:IsValidSyllableNumber() do
vs.SyllableNumber= vs.SyllableNumber + 1
end
lyric:Load(returnvalues[3])
local text = lyric:CreateString()
if vs.SyllableNumber > 1 then text:AppendLuaString(" ") end
text:AppendLuaString(createStringLyrics())
lyric:SetText(text)
lyric:Save()
return vs, vs.SyllableNumber
end
function indNote(noteentry)
if not noteentry:IsNote() then return nil end
if noteentry.Count == 0 then return nil end
local note
if noteentry.Count == 1 then -- note seule
note = noteentry:CalcLowestNote(nil)
else -- accord
if returnvalues[4] == 1 then -- Aucun nom
return nil
elseif returnvalues[4] == 2 then -- Note grave
note = noteentry:CalcLowestNote(nil)
else -- Note aigue
note = noteentry:CalcHighestNote(nil)
end
end
local pos = string.find("CDEFGAB", note:CalcWrittenPitchChar())
if pos == nil then return nil end
local alter = note:CalcPitchRaiseLower(true)
return pos + ((alter + 2) * 7)
end
function main()
local vs, nextSyllable= initLyrics(nextvs)
for noteentry in eachentrysaved(finenv.Region(),1) do
local ind = indNote(noteentry)
if ind ~= nil then
vs:SetNoteEntry(noteentry)
vs.SyllableNumber= nextSyllable + ind - 1
if vs:IsValidSyllableNumber() then
vs:SaveNew()
else
print("Erreur","RawTextNumber :",vs.RawTextNumber,"SyllableNumber :",vs.SyllableNumber)
end
end
end
end
-- DEBUT DU PROGRAMME
if init() then main() end
More information about the JWLua
mailing list