Utilitzar ly:grob-object per accedir als grobs amb \tweak

Es pot accedir "lateralment" a alguns grobs des de dins de la funció de callbak d’un altre grob. Aquests es troben relacionats normalment com "layout objects" (objectes de presentació) en la secció "Internal properties" (propietats internes) d’una interfície de grob. S’usa la funció ly:grob-object per a accedir a aquests grobs.

Es presenten més avall com a exemple algunes formes d’accedir a grobs des de dins d’una funció de callblack de NoteHead, però la tècnica no es limita als caps de nota. No obstant, la funció de callblack de NoteHead és especialment important, perquè és la funció de callback implícita que utilitza l’ordre \tweak.

La funció d’exemple que es defineix sota ("display-grobs") no és probablement tan útil, però mostra que s’està accedint efectivament als grobs.

Sortida d’exemple de la consola:

--------------------
#-Grob Accidental -
#-Grob Arpeggio -
#-Grob Stem -
#(define (notehead-get-accidental notehead)
   ;; notehead is grob
   (ly:grob-object notehead 'accidental-grob))

#(define (notehead-get-arpeggio notehead)
   ;; notehead is grob
   (let ((notecolumn (notehead-get-notecolumn notehead)))
     (ly:grob-object notecolumn 'arpeggio)))

#(define (notehead-get-notecolumn notehead)
   ;; notehead is grob
   (ly:grob-parent notehead X))

#(define (notehead-get-stem notehead)
   ;; notehead is grob
   (let ((notecolumn (notehead-get-notecolumn notehead)))
     (ly:grob-object notecolumn 'stem)))

#(define (display-grobs notehead)
   ;; notehead is grob
   (let ((accidental (notehead-get-accidental notehead))
         (arpeggio (notehead-get-arpeggio notehead))
         (stem (notehead-get-stem notehead)))
     (format (current-error-port) "~2&~a\n" (make-string 20 #\-))
     (for-each
      (lambda (x) (format (current-error-port) "~a\n" x))
      (list accidental arpeggio stem))))

\relative c' {
  %% display grobs for each note head:
  %\override NoteHead.before-line-breaking = #display-grobs
  <c
  %% or just for one:
  \tweak before-line-breaking #display-grobs
  es
  g>1\arpeggio
}

[image of music]


Fragments del LilyPond v2.25.15 (branca de desenvolupament).