[JW Lua] JWLua scripts

Charles O. Lawrence charlesolawrence at bellsouth.net
Tue Sep 17 01:07:51 CEST 2013


Jari,

Thank you for taking the time to review my script code.

Of course tables should be used whenever possible.  I should have seen that
in the SetInitValues.

I know you said using the region directly was error prone, but I did not
realize in what way.  Thanks for pointing it out.  I did consider the
possibility that staff numbers may not start at one and be consecutive, but
in all the tests I did, it never happened otherwise.  It just dawned on me
as I was writing this that perhaps if I had repositioned a staff with the
ScoreManager it might have shown up.  I did see the mention of a "slot" when
examining the PDK docs, but it wasn't clear to me what a "slot" really was.
It makes more sense now.

Even though RequireSelection is true, I checked for empty regions because
the AlertError box does not provide for a Cancel (cannot be dismissed), and
is not modal, so the user could unselect any selected region while the alert
box is open waiting for a user response (click OK).  Maybe some other alert
would be more appropriate.

I had in the past briefly examined the Finale PDK supplied by MM, and
quickly dismissed any thought of trying to dig into it.  I had recently
retired and was not interested in coding any more at that time.  JWLua has
rekindled an old smoldering ember.  I used to thrive on this kind of stuff.
I am amazed at what you have done with your PDK in your "spare time."

Charles Lawrence



-----Original Message-----
From: JWLua [mailto:jwlua-bounces at jwmusic.nu] On Behalf Of Jari Williamsson
Sent: Monday, September 16, 2013 4:19 PM
To: The JW Lua script plug-in.
Subject: Re: [JW Lua] JWLua scripts

Charles (and everyone else),

Here are some comments on the source code.

Replace:
dialog:SetInitValues(useLayer[1],useLayer[2],useLayer[3],useLayer[4])
with:
dialog:SetInitValues(useLayer)

(The dialog setters can use a single table as parameters - and tables SHOULD
be used in really large dialog boxes with loads of options. In the 0.05 Wiki
docs, I recommend using a single table from around 6 options.)

The SwapLayersRegion.lua has an error (for the reason why I said it is easy
to make errors by using the region directly).

This line is the problem:
for staff = startStaff,endStaff do

A staff number in Finale can be ANY 1-based number and the staves can appear
in ANY order. It's an error to assume that the staves at the top of the
score always have a lower staff ID number.

Instead you should use the SLOT number for the region, which is linear
within the region - and then convert the slot to a staff number through the
region object.

This would be the replacement code:
local region = finenv.Region()
for slot = region.StartSlot, region.EndSlot do
     local staff = region:CalcStaffNumber(slot)


Also, that same script manually checks for empty regions. However, that code
will never run, since you've also defined the plug-in with:
finaleplugin.RequireSelection = true

So if the user haven't selected a region in this case, JW Lua will display a
message to the user before the plug-in even starts.


On 2013-09-16 21:22, Charles O. Lawrence wrote:
> Believe me, it is not as easy to get started as it
> may first appear.  The learning curve is steep, and JWLua is nothing
> like FinaleScript.

And believe me, if you have ever tried to use the Finale PDK directly, 
the JW Lua learning curve is nothing. ;-)

I guess more developers will have an increased interest when we get 
closer to a "version 1.0". I really appreciate that you're trying JW Lua 
at such an early stage. Your feedback is very valuable - thanks!


Best regards,

Jari Williamsson


_______________________________________________
JWLua mailing list
JWLua at jwmusic.nu
http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu





More information about the JWLua mailing list