[JW Lua] Create lyrics

Chris marcel.denio at gmail.com
Tue Apr 1 12:53:16 CEST 2014


Thank you Jaribut my problem was to create new syllables (which do not 
exist).

Here's an example I created to add the names of the notes in lyrics.

-------------------------------------------------------------------------------------

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 nextVerseSyllable(RawTextNumber)
     local vs = finale.FCVerseSyllable()
     local SyllableNumber = 0

     vs.RawTextNumber=RawTextNumber

     repeat
         SyllableNumber = SyllableNumber + 1
         vs.SyllableNumber= SyllableNumber
     until not vs:IsValidSyllableNumber()

     return SyllableNumber
end

function noteTexte(noteEn)
     if returnvalues[1] == 4 then return noteEn end      -- Anglais 
Majuscules
     if returnvalues[1] == 5 then return string.lower(noteEn) end      
-- Anglais minuscules

     local notesFr ={{"DO","RE","MI","FA","SOL","LA","SI"},
                             {"do","re","mi","fa","sol","la","si"},
                             {"Do","Re","Mi","Fa","Sol","La","Si"}}

     return notesFr[returnvalues[1]][string.find("CDEFGAB",noteEn)]
end

function texteNoteEX(noteentry)
     local note = noteentry:CalcLowestNote(nil)
     local text = note:CalcWrittenPitchChar()
     if text == 0 then return "" end
     text= noteTexte(text)

     local alter = note:CalcPitchRaiseLower()

     return text .. textAlter(alter)
end

function textAlter(alterValue)
     if alterValue == 0 then return "" end
     local text

     if alterValue > 0 then   -- diese
         text = string.rep("#", alterValue)
     else    -- bemol
         text = string.rep("b", -alterValue)
     end

     if not returnvalues[4] then return text end

     local font = finale.FCFontInfo()
     font.Name ="Maestro"
     font.Size = 12

     return font:CreateEnigmaString(nil).LuaString .. text
end

function initLyrics()
     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

     lyric:Load(returnvalues[3])
     return lyric,vs
end

function texteNote(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 text = note:CalcWrittenPitchChar()
     if text == 0 then return nil end
     text= noteTexte(text)
     local alter = note:CalcPitchRaiseLower()

     return text .. textAlter(alter)
end

function main()
     local lyric,vs= initLyrics()
     local nextvs = nextVerseSyllable(returnvalues[3])

     for noteentry in eachentrysaved(finenv.Region()) do
         local note = texteNote(noteentry)

         if  note ~= nil then
             local syllabe=finale.FCString()
             syllabe.LuaString = " " .. note

             local text = lyric:CreateString()
             text:AppendString(syllabe)
             lyric:SetText(text)
             lyric:Save()

             vs:SetNoteEntry(noteentry)
             vs.RawTextNumber=returnvalues[3]
             vs.SyllableNumber=nextvs
             vs:SaveNew()

             nextvs = nextvs + 1
         end
     end
end

-- DEBUT DU PROGRAMME
if init() then main() end

-------------------------------------------------------------------------------------


Chris




More information about the JWLua mailing list