Am So., 23. Juli 2023 um 10:03 Uhr schrieb Rip _Mus <ripetizioni.mus...@gmail.com>: > > 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 >>
Hi, I still don't understand what you want to achieve with the "Tactus"-context. Nevertheless here another possibility to get context-name/id in a markup. \version "2.24.0" printCtx = { \applyOutput Bottom.TextScript #(lambda (grob current-ctx target-context) ;; `current-ctx' is the context where this command is applied ;; `target-conetxt' is the context which is specified above, here: Bottom ;; (uncomment below and change Bottom to Staff above to see the difference) ;; (pretty-print target-context) (ly:grob-set-property! grob 'text (format #f "In ~a named ~a" (ly:context-name current-ctx) (ly:context-id current-ctx)))) <>-"" } \new Staff = "my-staff" \new Voice = "my-voice" { \printCtx b } Cheers, Harm