Re: Custom ambitus ?

Tina Petzel <[email protected]>
Newsgroups gmane.comp.gnu.lilypond.general
Message-ID <[email protected]>
Hi Pierre,

Am Freitag, 7. August 2026, 22:51:14 Mitteleuropäische Sommerzeit schrieb 
Pierre-Luc Gauthier:
> Hi everyone,
> 
> Is there a way to inject specific notes in the "Ambitus_engraver" ? I
> guess then it would be trivial to gather all the different notes in a
> music expression.

It would be quite simple to write an engraver that listens for all unique 
pitches. The problem is then what to do with it. The ambitus system inplace 
does is not really designed to handle multi-note setting, such as collisions and 
stuff. Instead I suppose it would be much easier to inject a score-markup with 
a chord of all occurring pitches.

The appended file does exactly that. What it does not do yet is to match all 
possibly relevant settings between the markup-score and the original staff (staff 
line positions and such).

Cheers,
Tina
custom-ambitus.ly (text/x-lilypond, 2.8 KB)
#(define (custom-ambitus-engraver context)
   (let ((ambitus #f) (ambitus-head #f) (pitches (make-hash-table)) (is-typeset? #f) (start-c0 #f) (start_key_sig_ #f))
     (make-engraver
      ((process-music engraver)
       (if (not ambitus)
           (begin
            (set! ambitus (ly:engraver-make-grob engraver 'Ambitus '()))
            (set! ambitus-head (ly:engraver-make-grob engraver 'AmbitusNoteHead '()))
            (ly:grob-set-object! ambitus 'elements (ly:grob-list->grob-array (list ambitus-head)))
            (ly:grob-set-property! ambitus-head 'stencil ly:text-interface::print)
            (ly:grob-set-parent! ambitus-head X ambitus)
            (set! is-typeset? #f))))
      ((stop-translation-timestep engraver)
       (if (and ambitus (not is-typeset?))
           (let*
            ((c_pos (ly:context-property context 'middleCPosition))
             (cue_pos (ly:context-property context 'middleCCuePosition)))
            (set!
             start-c0
             (cond ((ly:context-property context 'ottavaStartNow #f)
                    (ly:context-property context 'middleCClefPosition 0))
                   ((and (integer? c_pos) (not (integer? cue_pos)))
                    c_pos)
                   (else
                    (+ (ly:context-property context 'middleCClefPosition 0)
                       (ly:context-property context 'middleCOffset 0)))))
            (set! start_key_sig_
                  (ly:context-property context 'keyAlterations))
            (set! is-typeset? #t))))
      (acknowledgers
       ((note-head-interface engraver grob source)
        (let* ((cause (ly:grob-property grob 'cause))
               (pitch (and (ly:stream-event? cause) (ly:event-property cause 'pitch))))
          (if (and pitch (not (hash-ref pitches pitch #f)))
              (hash-set! pitches pitch cause)))))
      ((finalize engraver)
       (ly:grob-set-property!
        ambitus-head
        'text
        (make-score-markup
         #{
           \score {
             \layout {
               indent = 0
             }
             \new Staff \with {
               \remove #custom-ambitus-engraver
               middleCPosition = #start-c0
               \remove Clef_engraver
               \remove Time_signature_engraver
               \omit Stem
               \omit StaffSymbol
             } {
               #(make-music
                 'EventChord
                 'elements
                 (hash-map->list
                  (lambda (key value)
                    (make-music
                     'NoteEvent
                     'duration
                     (ly:make-duration 2)
                     'pitch
                     key))
                  pitches))
             }
           }
         #}))))))

\layout {
  \context {
    \Staff
    \consists #custom-ambitus-engraver
  }
}

{ c' e' gis' e' a' }
signature.asc (application/pgp-signature, 228 B)
-----BEGIN PGP SIGNATURE-----

iHUEABYKAB0WIQS0sdUK2Lu8of48K2+FHhaCPe7BywUCanc3LgAKCRCFHhaCPe7B
y0hKAQCLjNcTihPYmFR9Spa4y2tcUgxUxYn/+AC8ns4vxdgH5wEA5YjVVVgKy0AA
5gRelOYKZJNGHivVEFLkW7LhINcrBgA=
=Xm/3
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.