[JW Lua] FCCellFrameHold:CalcClefChange problem with hidden layers

Jari Williamsson jari.williamsson at mailbox.swipnet.se
Sun Sep 14 00:28:20 CEST 2014


Jan,

Here's a Lua test replacement for CalcClefChange. Send the 
FCCellFrameHold object as an argument to the function. Can you check if 
this fixes your issues (and don't introduces new issues)?


Best regards,

Jari Williamsson


On 2014-09-13 21:53, Jan Angermüller wrote:
> Jari,
>
> thanks for your responses to the many clef issues.
> They really help !
>
> Attached you find an example excerpt from a score where
> I get weird CalcClefChange results.
>
> Just select all and run the following script:
>
>      local region=finenv.Region()
>      for i,j in eachcell(region) do
>          local cell=finale.FCCell(i,j)
>          local CellFrameHold=finale.FCCellFrameHold()
>          CellFrameHold:ConnectCell(cell)
>          if CellFrameHold:Load() then
>              print("Clef Change",i,CellFrameHold:CalcClefChange())
>          else
>              print("No Clef Change",i)
>          end
>      end
>
> These are the results that I get:
> Clef Change 1 false             (I don't know if the very first measure
> should return true, probably it should. Up to you.)
> No Clef Change 2
> No Clef Change 3
> Clef Change 4 false               (should be true !)
> Clef Change 5 false
> Clef Change 6 true
> No Clef Change 7
> No Clef Change 8
> No Clef Change 9
>
> - it only returns true for CalcClefChange in the measure after the cue
> notes,
>    and false for the cue notes measures that have a clef change
> - the first clef change is only detected through loading the object,
>    CalcClefChange still returns false
>
> Jan
>
>
> _______________________________________________
> JWLua mailing list
> JWLua at jwmusic.nu
> http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu
>

-------------- next part --------------
function CalcClefChange(frame)
    local _pConnectedCell = finale.FCCell(frame.Measure, frame.Staff) -- Extra Lua

    if (_pConnectedCell:GetMeasure() < 2) then return false end

    local currentmeasure = _pConnectedCell:GetMeasure()

    local existingchange = -1;
    
    -- Scan backwards through the frames to find a different clef:
    while (currentmeasure > 1) do        
       currentmeasure = currentmeasure - 1;
       local prevcell = finale.FCCell(currentmeasure, _pConnectedCell:GetStaff())
       local prevframe = finale.FCCellFrameHold()
       prevframe:ConnectCell(prevcell)
       if (prevframe:Load()) then       
           -- Load the entries and see if there's a mid-clef change:
           local noteentrycell = finale.FCNoteEntryCell(prevcell:GetMeasure(), prevcell:GetStaff())
           noteentrycell:SetLoadLayerMode(-1)
           noteentrycell:Load()
           if (noteentrycell:GetCount() > 0) then           
               local lastclefchangepos = -1
               local lastclefchangeindex = frame:GetClefIndex()
               for i = 0, noteentrycell:GetCount() - 1 do               
                   local pEntry = noteentrycell:GetItemAt(i)
                   if (pEntry:GetClefIndex() ~= lastclefchangeindex) then                   
                       if (pEntry:GetMeasurePos() > lastclefchangepos) then                       
                           lastclefchangepos = pEntry:GetMeasurePos()
                           lastclefchangeindex = pEntry:GetClefIndex()
                       end
                   end
               end
               if (lastclefchangeindex ~= frame:GetClefIndex()) then               
                   --/* Note entry clef change. Check that it occurs
                   -- * in the measure just prior to the frame. */                    
                   return (currentmeasure + 1 == _pConnectedCell:GetMeasure())
               end
               existingchange = lastclefchangeindex
           end -- if ... then
           
           if (prevframe:GetClefIndex() ~= frame:GetClefIndex() and (existingchange == -1)) then    -- CHANGE!!!
               -- /* Frame clef change. Check that it occurs just prior to the frame. */                
               --return (currentmeasure + 1 == _pConnectedCell:GetMeasure())           
                return true   -- CHANGE!!!
            end
            existingchange = prevframe:GetClefIndex()            
        end -- if ... then
    end    

    if (existingchange == -1) then             
        --/* No previous clef change was found. Check how the clef matches the
        -- * start clef. */
        local staff = finale.FCStaff()
        staff:Load(_pConnectedCell:GetStaff())
        if (frame:GetClefIndex() ~= staff:GetFirstClef()) then return true end
    end
    
    return false
end   -- End of function


local region=finenv.Region()
    for i,j in eachcell(region) do
        local cell=finale.FCCell(i,j)
        local CellFrameHold=finale.FCCellFrameHold()
        CellFrameHold:ConnectCell(cell)
        if CellFrameHold:Load() then
            print("Clef Change",i, CalcClefChange(CellFrameHold))
        else
            print("No Clef Change",i)
        end
    end 


More information about the JWLua mailing list