===== FinaleScript vs. JW Lua comparison ===== (Please note that this article is mainly intended for //JW Lua// script writers.) ==== The MakeMusic blog ==== Today (Sep. 18, 2013), Kelby Stine at MakeMusic made a post on the MakeMusic blog about replacing Wizard-created staff names through FinaleScript. I thought it would be interesting to do a //FinaleScript// vs. //JW Lua// comparison on this (testing on the //JW Lua beta 0.05// functionality, which is soon available). Kelby's blog post is here: [[http://www.finalemusic.com/blog/using-finalescript-to-rename-staves-in-your-finale-score/|http://www.finalemusic.com/blog/using-finalescript-to-rename-staves-in-your-finale-score/]] ==== The FinaleScript source ==== The FinaleScript source which the blog post is based on is here: [[http://www.finalemusic.com/wp-content/uploads/2013/09/Name_Change_Script.txt|http://www.finalemusic.com/wp-content/uploads/2013/09/Name_Change_Script.txt]] ==== The JW Lua source ==== Here's the //JW Lua// script (what Kelby would probably call "code-based gobbledygook") for approximately the same functionality: function ChangeStaffInstruments(thestring) -- Clarinets thestring:Replace("Clarinet in E^flat()", "E^flat() Clarinet") thestring:Replace("Clarinet in B^flat()", "B^flat() Clarinet") if not thestring:ContainsLuaString("^flat()", nil) then thestring:Replace("Alto Clarinet", "E^flat() Alto Clarinet") thestring:Replace("Bass Clarinet", "B^flat() Bass Clarinet") thestring:Replace("Contralto Clarinet", "E^flat() Contrabass Clarinet") thestring:Replace("Contrabass Clarinet", "B^flat() Contrabass Clarinet") end -- Saxes if not thestring:ContainsLuaString("^flat()", nil) then thestring:Replace("Sopranino Sax", "E^flat() Sopranino Saxophone") thestring:Replace("Soprano Sax", "B^flat() Soprano Saxophone") thestring:Replace("Alto Sax", "E^flat() Alto Saxophone") thestring:Replace("Tenor Sax", "B^flat() Tenor Saxophone") thestring:Replace("Baritone Sax", "E^flat() Baritone Saxophone") thestring:Replace("Bass Sax", "B^flat() Bass Saxophone") thestring:Replace("Contrabass Sax", "E^flat() Contrabass\rSaxophone") thestring:Replace("SubContrabass Sax", "B^flat() Subcontrabass\rSaxophone") end -- Brass if not thestring:ContainsLuaString("^flat()", nil) then thestring:Replace("Trumpet in B^flat()", "B^flat() Trumpet") thestring:Replace("Horn in E^flat()", "E^flat() Horn") end thestring:Replace("Horn in F", "F Horn") thestring:Replace("Baritone (B.C.)", "Baritone BC") thestring:Replace("Baritone (T.C.)", "Baritone TC") end -- Load all staves local staves = finale.FCStaves() staves:LoadAll() -- Parse through the staves for staff in each(staves) do local oldstring = staff:CreateFullNameString() local staffstring = staff:CreateFullNameString() -- Change the instrument texts ChangeStaffInstruments(staffstring) -- If the text has changed, save the string if oldstring.LuaString ~= staffstring.LuaString then staff:SaveFullNameString(staffstring) end end ==== Comparison Result ==== I did the comparisons on the same Finale document (a "Concert Band (Full)" created by the 2012c Document Wizard) on my Windows machine. ^ Comparison Area ^ FinaleScript ^ JW Lua ^ | Total Execution Time | 9.25 seconds (manually timed) | 0.02486 seconds | | Lines of Code (not counting comment lines) | 19 | 37 | | User Restrictions | Make sure to run only once, base document on Wizard's output | Base document on Wizard's output (see remark in "Conclusion" below) | ==== Conclusion ==== //JW Lua// is a programming language, and the comparison clearly shows that difference. You'll need to code a bit more, but you have full coding flexibility, can control the brevity of the language - and you get execution speed. However, in Finale 2012 string replacement in staff names is generally a bad approach since it put user restrictions on the script. Instead, the //JW Lua// script should make changes primarily based on the ''InstrumentUUID'' property. In the specific example above, the //JW Lua// execution is about **372 times faster** than //FinaleScript//, which would probably be an even larger difference if a ''InstrumentUUID'' solution would be used. But that's way beyond this comparison. :-)