\tweak で Grob にアクセスするために ly:grob-object を用いる

いくつかの Grob は、他の Grob のコールバックからアクセスすることができます。これらは通常、grob-interface の "Internal properties" セクションにある "layout objects" にリストアップされています。ly:grob-object は、これらの Grob にアクセスするために使用します。

以下に示したのは、NoteHead コールバック内で Grob にアクセスするいくつかの方法ですが、このテクニックは NoteHead に限ったものではありません。しかし、NoteHead は \tweak コマンドで暗黙的に指定されるために、このコールバックは特に重要です。

以下で定義された例の関数 ("display-grobs") はそこまで有用ではないかもしれませんが、Grob が実際にアクセスできることを示しています。

例のコンソール出力:

#Grob Accidental () #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]


LilyPond snippets v2.25.15 (開発版).