Hi Daniel,

On Tue, Jan 7, 2020 at 5:18 PM Daniel Rosen <drose...@gmail.com> wrote:
>
> I just rediscovered David Nalesnik's metronome-mark-alignment function in 
> this thread that I originally started years ago: https://bit.ly/2QUmi6H

I just rediscovered it too!  Completely forgot I had done this.
>
> The function works fine as long as Metronome_mark_engraver only exists in the 
> Score context. However, if it's added to, say, a Staff context or a Voice 
> context, it prevents the file from compiling and yields the following error 
> messages:
>
> > ~/example.ly:23:14: In expression (ly:make-simple-closure (quasiquote #)):
> > ~/example.ly:23:14: Unbound variable: ly:make-simple-closure
>
> See the attached example.

>
> Can anyone tweak this function so that it will work under these conditions?
>

The problem is that ly:make-simple-closure has been removed.  I
replaced the old default with the new definition (found in the
Internals Reference), and the function works again.  See attached.

Best.
David
\version "2.19.83"

%%%% David Nalesnik's metronome-mark-alignment function:

#(define align-tempo-with-accidental
   (lambda (grob)
     (let* ((p-col (ly:grob-parent grob X))
            (sys (ly:grob-parent p-col X))
            (all (ly:grob-object sys 'all-elements))
            (grob-name (lambda (x) (assq-ref (ly:grob-property x 'meta) 'name)))
            (pl (filter
                 (lambda (x) (eq? 'AccidentalPlacement (grob-name x)))
                 (ly:grob-array->list all)))
            (pl-p-col (filter
                       (lambda (x) (eq? p-col (ly:grob-parent x X)))
                       pl)))
       (if (pair? pl-p-col)
           (let* ((accs (map cadr (ly:grob-object (car pl-p-col) 'accidental-grobs)))
                  (X-exts (map (lambda (x) (ly:grob-extent x sys X)) accs))
                  (un (reduce interval-union '() X-exts)))
             (car un))
           ; Return the default.
           self-alignment-interface::self-aligned-on-breakable))))

%%%% Tiny example:

music = { cis'1 }

<<
  \new Staff { \music \music }
  \new Staff { \music \tempo "Tempo" \music }
>>

\layout {
  \context {
    \Staff
    \consists "Metronome_mark_engraver"
    \override MetronomeMark.X-offset = #align-tempo-with-accidental
  }
}

Reply via email to