Coloration Syntaxique

Télécharger le script ! - mod phpBB

---- Ajustement des hauteurs des portees en fonction des elements qu'elle contient
---- Les portˇes multi-voix (layered) sont gˇrˇes
-----------------------------------------------------------------------------
------------------------------------------------------------------------------
-- AdjustStaffHeight
--=> portee, position par rapport a la baseline haute et basse de l'aire
--- la portee est eventuellement ajustee pour que cette position soit dans son aire
-------------------------------------------------------------------------------
function AdjustStaffHeight(staff,staffLyric,posTop,posBottom)
    local delta
    
    --print("top "..posTop.." posBottom "..posBottom)
    -- hauteur minimale
    if posBottom<20 then posBottom=20 end
    posTop=-posTop
    --- Depassement par le haut
    delta=posTop-staff.BaseLine
    staff.BaseLine=posTop
    if staffLyric~=nil  then
        staffLyric.BaseLine=posTop
        staff.Height=staff.BaseLine+posBottom+staffLyric.LyricsVerticalSize
        staffLyric.LyricsYPosition=staffLyric.Height-staffLyric.LyricsVerticalSize
    else
        staff.Height=staff.BaseLine+posBottom
    end
    if staff.BarNumberingType~=BAR_NUMBERING_NONE then
        --staff.BarNumberingYPosition=staff.BarNumberingYPosition+delta
        staff.BarNumberingYPosition=staff.BaseLine-4*12
    end
end
------------------------------------------------------------------------------
-- GetMax
-------------------------------------------------------------------------------
function GetMax(pos,posTop,posBottom)

    if pos<posTop then posTop=pos end
    if pos>posBottom then posBottom=pos  end
    return posTop,posBottom
end
------------------------------------------------------------------------------
-- ComputeSymbolPosition
-- Calcule nouveau minimum et maximum en fonction des symboles
--- presents dans la portˇe
--- => portee, haut, bas maximum
---<= haut, bas maximum
-------------------------------------------------------------------------------
function ComputeSymbolPosition(staff,posTop,posBottom)
    local note
    local stemHeight
    local kind,delay,x1,y1,xm,ym,x2,y2,width
    local pos
    
    note=staff.FirstSymbol
    while note~=nil do
        if note.IsGhostRest==false then
            --note.Color=IDX_COLOR_RED
            stemHeight=GetStemHeight(note)
            --note.Color=IDX_COLOR_BLUE
            --print(note.VerticalPixelPosition)
            -- Tige basse
            if note.IsStemDown==true then
                -- haut de la note
                posTop,posBottom=GetMax(note.VerticalPixelPosition,posTop,posBottom)
                -- bas de la note
                --print(note.VerticalPixelPosition.. " "..stemHeight)
                pos=note.VerticalPixelPosition+stemHeight+1*staff.LineSpacing
                --note.Color=IDX_COLOR_RED
                if note.TupletDiv~=1 then
                    pos=pos+2*staff.LineSpacing
                end
                posTop,posBottom=GetMax(pos,posTop,posBottom)
            else
                -- Tige haute
                pos=note.VerticalPixelPosition-stemHeight
                if note.TupletDiv~=1 then
                    pos=pos-2*staff.LineSpacing
                end
                posTop,posBottom=GetMax(pos,posTop,posBottom)
                posTop,posBottom=GetMax(note.VerticalPixelPosition+staff.LineSpacing,posTop,posBottom)
            end
            --- Slur associˇ ?
            if note.SlurTarget~=nil then
                pp=posBottom
                kind,delay,x1,y1,xm,ym,x2,y2,width=note.GetSlurSettings()
                posTop,posBottom=GetMax(note.VerticalPixelPosition+y1,posTop,posBottom)
                posTop,posBottom=GetMax(note.VerticalPixelPosition+y2,posTop,posBottom)
                if posBottom>pp then
                --    note.Color=IDX_COLOR_RED
                end
            end
            if note.SlurSource~=nil then
                pp=posBottom
                kind,delay,x1,y1,xm,ym,x2,y2,width=note.SlurSource.GetSlurSettings()
                posTop,posBottom=GetMax(note.VerticalPixelPosition+y1,posTop,posBottom)
                posTop,posBottom=GetMax(note.VerticalPixelPosition+y2,posTop,posBottom)
                if posBottom>pp then
                --    note.Color=IDX_COLOR_RED
                end
            end
        end
        note=note.Next
    end
    return posTop,posBottom
end
-----------------------------------------------------------------------------
-- ComputeDynamicPosition
-- Calcule nouveau minimum et maximum en fonction des nuances
--- presents dans la portˇe
--- => portee, haut, bas maximum
---<= haut, bas maximum
-------------------------------------------------------------------------------
function ComputeDynamicPosition(staff,posTop,posBottom)
    local dynamic
    
    dynamic=staff.FirstDynamic
    while dynamic~=nil do
        posTop,posBottom=GetMax(dynamic.AreaTop,posTop,posBottom)
        posTop,posBottom=GetMax(dynamic.AreaBottom,posTop,posBottom)
        dynamic=dynamic.Next
    end
    return posTop,posBottom
end
-----------------------------------------------------------------------------
-- ComputeTextPosition
-- Calcule nouveau minimum et maximum en fonction des textes
--- presents dans la portˇe
--- => portee, haut, bas maximum
---<= haut, bas maximum
-------------------------------------------------------------------------------
function ComputeTextPosition(staff,posTop,posBottom)
    local text
    
    text=staff.FirstText
    while text~=nil do
        posTop,posBottom=GetMax(text.AreaTop,posTop,posBottom)
        posTop,posBottom=GetMax(text.AreaBottom,posTop,posBottom)
        text=text.Next
    end
    return posTop,posBottom
end
-----------------------------------------------------------------------------
-- ComputeStavesHeight
-- Calcule toutes les tailles des portees
-------------------------------------------------------------------------------
function ComputeStavesHeight(score)
    local masterStaff
    local staff
    local posTop
    local posBottom
    local staffLyric
    
    if Application.MyrScriptVersion<"1.1.4" then
        print("Sorry, but MyrScript version needed is 1.1.4 or more to compte staff height.")
        return
    end
    staff=score.FirstStaff
    masterStaff=staff
    posTop=9999
    posBottom=-9999
    --- Si la portee est fusionnˇe, on travaille sur la premiere de la fusion
    --- Si une des portˇes contient des paroles, c'est cette position de paroles qui sera ajustee
    while staff~=nil do
        if staff.Type==STAFF_TYPE_DRUM_GRID then
            staff.BaseLine=16
            staff.Height=16
        else
            --- Calcul du min et max en fonction des symboles presents sur la portee
            posTop,posBottom=ComputeSymbolPosition(staff,posTop,posBottom)
            --print("Symbols "..posTop..","..posBottom)
            posTop,posBottom=ComputeDynamicPosition(staff,posTop,posBottom)
            --print("Dynamics "..posTop..","..posBottom)
            posTop,posBottom=ComputeTextPosition(staff,posTop,posBottom)
            --print("Texts "..posTop..","..posBottom)
            --- Memorisation de la position de la ligne de lyrics
            if staff.IsLyrics==true then staffLyric=staff end
            --- Fin de merge, on applique
            if staff.IsMergedWithNext==false then
                AdjustStaffHeight(masterStaff,staffLyric,posTop,posBottom)
                masterStaff=staff.Next
                posTop=9999
                posBottom=-9999
                staffLyric=nil
            end
        end
        --- Portee suivante
        staff=staff.Next
    
    end
end

--ComputeStavesHeight(FrontScore())

    
--EOF--EXTRA_DATA
--WRECT 459 184 1435 1028
--SYNTAX_COLOR_ON 1
--FONT "Geneva" 0 12
43100 octets
198 lignes générées en 0.02928 secondes,
soit une vitesse de 6728 lignes par seconde

Apache/2.4.38 (Debian)

Texte à analyser:

Langage :