Hello Rip_Mus,

you can obtain the name of a context using ly::context-id, and the type of a 
context using ly:context-name.

The problem is that you can only really use these only during the translation 
step. So I thing the easiest way would be to create an engraver that adds this 
information:

#(define ((annotate-ctx-engraver which) context)
   (define (extract-context-hierarchy ctx)
     (if ctx
         (cons (cons (ly:context-name ctx) (ly:context-id ctx)) (extract-
context-hierarchy (ly:context-parent ctx)))
         '()))
   (let* ((hierarchy (extract-context-hierarchy context))
          (hierarchy (filter (lambda (x) (member (car x) which)) hierarchy))
          (hierarchy-markups (map (lambda (x) (format #f "~a: ~a" (car x) (cdr 
x))) hierarchy))
          (hierarchy-markup (primitive-eval (list 'markup #:column hierarchy-
markups))))
     (make-engraver
     (acknowledgers
       ((grob-interface engraver grob source-engraver)
        (let* ((det (ly:grob-property grob 'details))
               (annotate (assoc-get 'annotate-context det)))
          (if annotate
              (let ((text-grob (ly:engraver-make-grob engraver 'TextScript 
'())))
                (ly:grob-set-property! text-grob 'text hierarchy-
markup)))))))))

\layout {
  \context {
    \Voice
    \consists #(annotate-ctx-engraver '(Staff Voice))
  }
}

\new Staff = "the-staff" \new Voice = "the-one-and-only-voice" {
  c' d' \override NoteHead.details.annotate-context = ##t e
}

Cheers,
Valentin

Am Sonntag, 23. Juli 2023, 08:37:52 CEST schrieb Rip _Mus:
> Good morning,
> is it possible to retrieve the name of the Voice and Staff contexts during
> the insertion of the music (as if I wanted to use it to automatically print
> the name of these contexts on a markup of a note)?
> 
> Thank you
> 
> Rip_mus

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to