Allgemein > Fragen zu Funktionen

Abstände von Ankerpunkten in vertikaler Richtung finden

<< < (3/3)

harm6:

--- Zitat ---Der Code geht mal wieder auf eine Anregung harms zurück
--- Ende Zitat ---
Zuviel der Ehre.

Tatsächlich wurde ich auf das Verfahren durch David Kastrup aufmersam gemacht, der es auf eine Anfrage meinerseits im Usage-Manual gefunden hatte. (Nicht diesen code, aber 'page-post-process')
Implementiert wurde es von Rainhold Kainhofer Jahre zuvor und war lange Zeit schlichtweg in Vergessenheit geraten.

Gruß,
  Harm

xr:
Um die Abstände der Ankerpunkte zu finden, habe jetzt folgenden Code:


--- Code: ---#(define counter-va-lines 1)
#(define ht-va-distances (make-hash-table))

#(define (get-slur-extents layout pages)
;; This method has to be the first to be executed. It starts at the end
;; of the first compilation pass. Another pass is neccessary to use the calculated values.
;; It iterates over pages/system-lines/VerticalAlignment/VerticalAxisGroup.
;; Writes the distance between each VerticalAxisGroup
;; and the system baseline to the hash table ht-va-distances.
;; Key is the number of the system line, counted by
;; counter-va-lines
    (for-each (lambda (page)
        (for-each (lambda (line)
            (let* (
                (sys-grob (ly:prob-property line 'system-grob))
                )
                (if (not (equal? sys-grob '()))
                    (begin
                        (let* (
                            (vertAlign (ly:system::get-vertical-alignment sys-grob))
                            (va-groups (ly:grob-array->list (ly:grob-object  vertAlign 'elements)))
                            (tmp '())
                            )
                            (for-each
                             (lambda (group)
                                 ;; a VAGroup with no elements (e.g. no lyrics) will turn
                                 ;; to a spanner grob. As it has no properties, grob::name
                                 ;; returns false.
                                (if (grob::name group)
                                    ;; calculate relative position between
                                    ;; system baseline and VAGroup
                                    (set! tmp (append tmp (list
                                           (ly:grob-relative-coordinate group sys-grob Y))))
                                    (set! tmp (append tmp '(0 0)))
                                )
                             )
                             va-groups
                            )
                            (hash-set! ht-va-distances
                                         (number->string counter-va-lines)
                                         tmp)
                            (set! counter-va-lines (1+ counter-va-lines))
                        )
                    )
                )
            ))
            (ly:prob-property page 'lines)
        ))
        pages
    )
)
--- Ende Code ---

Eingebunden wird der Code mit:


--- Code: ---\paper {   
    #(define (page-post-process layout pages)
        (get-slur-extents layout pages))
}

--- Ende Code ---

Dies ist jetzt ein Auszug aus dem kompletten Beispiel in dem anderen Thread, den ich schon angesprochen hatte.
Das komplette Beispiel findet sich hier:
https://github.com/XRoemer/Lilypond/tree/master/Custom_Slurs
Und hier können alle Dateien als zip. heruntergeladen werden:
https://github.com/XRoemer/Lilypond

Gruß,
Xaver

Navigation

[0] Themen-Index

[*] Vorherige Sete

Zur normalen Ansicht wechseln