[JW Lua] Changing independent key signatures crashes Finale
Jan Angermüller
jan at angermueller.com
Thu Jan 29 18:27:58 CET 2015
Jari,
I have two issues with changing the key signature on an FCCell object
with Finale 2014d/Windows7/JW Lua 0.29.
1.) If "Independent Element -> Key Signature" is NOT selected in the
staff settings,
the following code *may crash *Finale. It "may crash", as sometimes I
have to run the script several times until it crashes, so there must be
some undefined behaviour.
Maybe this is by design and the developer has to make sure that it is a
staff with an independent key signature before calling
FCCell:GetKeySignature(). But it would be more safe if you inserted a
quick check into the FCCell:GetKeySignature()-implementation.
I would expect cell:GetKeySignature() to return nil on a non-independent
key signature staff.
That's better than crashing ;-)
BTW, you have FCCell.HasIndependentTimeSig(). Maybe you could also add
HasIndependentKeySig().
This is the test code:
--change key signature on first selected measure of first selected staff
if not finenv.Region():IsEmpty() then
local
cell=finale.FCCell(finenv.Region().StartMeasure,finenv.Region().StartStaff)
key=cell:GetKeySignature()
if key ~= nil then
print("Old alteration:", key.Alteration)
key:SetMajorKey(5)
print("New alteration:", key.Alteration)
key:Save() --I don't know if this is necessary: same behaviour
if I keep it in or take it out
cell:Save() --this function call crashes Finale
end
end
2.) Now if "Independent Element -> Key Signature" IS selected in the
staff settings and I also add a condition to check that key signatures
are independent, the code above has the same behaviour: it still doesn't
change any key signatures, but crashes Finale (if not after the first
run, then after running it several times).
This is the test code:
--change key signature on first selected measure of first selected staff
--with independent key signature check
if not finenv.Region():IsEmpty() then
local staff=finale.FCStaff()
staff:Load(finenv.Region().StartStaff)
if staff.IndependentKeySig then
local
cell=finale.FCCell(finenv.Region().StartMeasure,finenv.Region().StartStaff)
key=cell:GetKeySignature()
if key ~= nil then
print("Old alteration:", key.Alteration)
key:SetMajorKey(5)
print("New alteration:", key.Alteration)
key:Save() --I don't know if this is necessary: same
behaviour if I keep it in or take it out
cell:Save() --this function call crashes Finale
end
end
end
What works fine is changing the global key sig using
FCMeasure:GetKeySignature(), i.e something like:
local measure=finale.FCMeasure()
measure:Load(1)
local key=measure:GetKeySignature()
key:SetMajorKey(5) --change key sig in measure 1
measure:Save()
Any ideas what the independent key sig thingy comes from ?
Best regards,
Jan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://jwmusic.nu/pipermail/jwlua_jwmusic.nu/attachments/20150129/2f837a9a/attachment-0002.html>
More information about the JWLua
mailing list