Thank you Valentin, this is very helpful! The situation is that I always create a custom context, named "Tactus", that creates bars for proportional notation (it's a Dynamics alias, that accepts Voice and some overrides, transparent noteheads, offset, etc.). During the insertion of notes, if I want a passage with Tactus bars onto the current staff, I always write something like
\new Staff = "main_staff_context" { %... << { %music } \new Tactus \with { alignAboveContext = "main_staff_context"} { c4 c c c %... } >> %... } Now, I find this very redundant, because it's glaring that the Tactus is to be aligned above the current Staff context. I just have to figure out how to avoid having to write it, so I imagined I could track down the name of the current context. The fact of having to access it during the translation process I think is the greatest difficulty. What do you think? Rip_mus Il giorno dom 23 lug 2023 alle ore 09:34 Valentin Petzel <valen...@petzel.at> ha scritto: > 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 > >