[JW Lua] Measure width in score changes when measure width in a part is changed after Undo/Redo - Workaround

Jan Angermüller jan at angermueller.com
Thu Apr 4 08:40:22 CEST 2024


I can now confirm that the workaround seems to solve the measure width 
undo/redo problem in Perfect Layout. I have also added the code to 
another plug-in and it fixed the problem too.

Probably it makes sense to add this code to all plug-ins that change the 
measure width in parts.
Maybe it makes sense to even support this directly through RGP Lua?

Below is the full code that I used.

Robert, I was wondering about one thing:
according to my notes changing the FCMeasure object works best when the 
part has the focus with part:ViewInDocument().
In a first attempt I had also added p:ViewInDocument() to my code below 
when the plug-in was applied to the part only and the measure width had 
to be corrected in the invisible score (see commented line below).
However, the workaround also worked fine when I removed ViewInDocument.
Is FCMeasure safe without ViewInDocument?
Or is it because of the Finale bug that this weird workaround even works 
without ViewInDocument?

Jan


-- add to the beginning of the code
local parts=finale.FCParts()
parts:LoadAll()
local NumParts=parts.Count
local part=finale.FCPart(finale.PARTID_CURRENT)
local CurrentPartIsScore=part:IsScore()

function FixMeasureWidthInScore(region)
     if NumParts>1 then
         local p
         if not CurrentPartIsScore then
             p=finale.FCPart(0)
             p:SwitchTo()
             --p:ViewInDocument()  --seems to be not necessary
         end
         if region==nil then
             region=finale.FCMusicRegion()
             region:SetFullDocument()
         end
         local i
         for i=region.StartMeasure, region.EndMeasure do
             local meas=finale.FCMeasure()
             meas:Load(i)
             meas.Width=meas.Width+1
             meas:Save()
             meas.Width=meas.Width-1
             meas:Save()
         end
         if not CurrentPartIsScore then
             p:SwitchBack()
             --add code for ViewInDocument of original part  -> but 
seems to be not necessary
         end
     end
end

...

FixMeasureWidthInScore(region)  --add this line at the very end of the 
script






Am 03.04.2024 um 16:34 schrieb Robert Patterson:
> I saw an additional issue, which is that the Undo does not undo the 
> part width setting. I found some notes about this in my Patterson 
> Plugins code, so the problem has been around a while.
>
> Glad you found a workaround.
>
> On Wed, Apr 3, 2024 at 9:29 AM Jan Angermüller <jan at angermueller.com> 
> wrote:
>
>     Thank you for the quick response, Robert!
>     I found a workaround which at least works in the test case below:
>     When I (re-)save the measure width in the score afterwards, it is
>     still the same bug.
>     BUT:
>     When I slightly change the measure width in the score, save it,
>     then restore the original value and save it again, both the
>     measure width in the score and in the parts seem to have the
>     correct value.
>     It seems to set a flag in Finale that the measure width in the
>     score has indeed changed.
>
>     I will have to check if this also solves the problem in Perfect
>     Layout.
>
>     Here is the new test code with the additional lines in bold:
>
>     --Show measure 1 width from score
>     local meas=finale.FCMeasure(1)
>     meas:Load(1)
>     print("Measure Width in Score",meas.Width)
>
>     --Load Part 3 and change
>     local p=finale.FCPart(3)
>     p:SwitchTo();
>         p:ViewInDocument()
>         meas=finale.FCMeasure(1)
>         meas:Load(1)
>         print("Measure Width in Part ",p.ID,meas.Width)
>         meas.Width=360
>         meas:Save()
>         print("Measure Width after change",meas.Width)
>     p:SwitchBack();
>
>     --Go back to score and show measure 1 width
>     p=finale.FCPart(0)
>     p:ViewInDocument()
>     meas=finale.FCMeasure(1)
>     meas:Load(1)
>     *meas.Width=meas.Width+1
>     meas:Save()
>     meas.Width=meas.Width-1
>     meas:Save()*
>     print("Measure Width in Score",meas.Width)
>
>     Jan
>
>
>
>     Am 03.04.2024 um 15:34 schrieb Robert Patterson:
>>     This is a bug in Finale. I doubt it will be fixed. But you could
>>     send it to them if you wish.
>>
>>     On Wed, Apr 3, 2024 at 7:53 AM Jan Angermüller
>>     <jan at angermueller.com> wrote:
>>
>>         Robert,
>>
>>         I have noticed several times that undo-ing and re-doing a JW
>>         Lua plug-in can change the measure width.
>>         Finally, I have created a short reproduceable demo that I
>>         can't explain.
>>
>>         The script is below.
>>         When applied to the score of the attached Finale file, it
>>         switches to linked part 3, loads measure 1 and changes its
>>         measure width to 360 and then returns to the score.
>>         The measure width in the score remains unchanged. So far,
>>         everything ok.
>>         Then I undo the plug-in in Finale and click on Edit->Redo ...
>>         Now the width in measure 1 also changes in the score!
>>
>>         Here is a video that shows the effect (with a slightly
>>         different version of the score):
>>         https://www.youtube.com/watch?v=lPJd3sq9zQg
>>
>>         In Perfect Layout it makes Finale's Undo-/Redo feature
>>         unusuable, because it (nearly) always changes the measure
>>         widths in the score for an unknown  reason.
>>         Do you have an idea how I can prevent this?
>>
>>         Jan
>>
>>         --Show measure 1 width from score
>>         local meas=finale.FCMeasure(1)
>>         meas:Load(1)
>>         print("Measure Width in Score",meas.Width)
>>
>>         --Load Part 3 and change
>>         local p=finale.FCPart(3)
>>         p:SwitchTo();
>>             p:ViewInDocument()
>>             meas=finale.FCMeasure(1)
>>             meas:Load(1)
>>             print("Measure Width in Part ",p.ID,meas.Width)
>>             meas.Width=360
>>             meas:Save()
>>             print("Measure Width after change",meas.Width)
>>         p:SwitchBack();
>>
>>         --Go back to score and show measure 1 width
>>         p=finale.FCPart(0)
>>         p:ViewInDocument()
>>         meas=finale.FCMeasure(1)
>>         meas:Load(1)
>>         print("Measure Width in Score",meas.Width)
>>         _______________________________________________
>>         JWLua mailing list
>>         JWLua at jwmusic.nu
>>         http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu
>>
>>
>>     _______________________________________________
>>     JWLua mailing list
>>     JWLua at jwmusic.nu
>>     http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu
>
>     -- 
>     Jan Angermüller
>     Orchideenstieg 13
>     22297 Hamburg
>     Tel. 040 - 28 94 84 82
>     Mobil 0173 - 99 33 904
>     www.elbsound.studio  <http://www.elbsound.studio>
>
>     _______________________________________________
>     JWLua mailing list
>     JWLua at jwmusic.nu
>     http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu
>
>
> _______________________________________________
> JWLua mailing list
> JWLua at jwmusic.nu
> http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu

-- 
Jan Angermüller
Orchideenstieg 13
22297 Hamburg
Tel. 040 - 28 94 84 82
Mobil 0173 - 99 33 904
www.elbsound.studio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://jwmusic.nu/pipermail/jwlua_jwmusic.nu/attachments/20240404/ed55261a/attachment-0001.html>


More information about the JWLua mailing list