[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: metronome-mark-alignment

From: Thomas Morley
Subject: Re: metronome-mark-alignment
Date: Sat, 11 Jan 2020 23:36:53 +0100

Am Sa., 11. Jan. 2020 um 18:04 Uhr schrieb David Nalesnik
> On Saturday, January 11, 2020, Daniel Rosen <address@hidden> wrote:
>> On Jan 9, 2020, at 4:21 PM, Daniel Rosen <address@hidden> wrote:
>> >> I have a new problem. If I take away the first instance of \music in each 
>> >> staff of my original example,
>> > Whoops, meant to say *your* example with the revised function.
>> >> the file fails to compile, and I get this error message:
>> >>
>> >>> ~/ Wrong type argument in position 1 (expecting 
>> >>> Grob_array): ()
>> >>
>> >> Can you help me with this one?
>> Seems like this might have fallen through the cracks, so... bump.
>> DR
> Sorry, no time at the moment.  Perhaps someone else can help...


\version "2.19.83"

%%%% Code by xr:
#(define (get-parent-in-hierarchie grob searchword)
     ;; goes up in hierarchie until it finds
     ;; a grob named searchword
     (define result #f)

     (define (get-par grob)

       (define compare
         (lambda (x) (and (ly:grob? x) (equal? searchword (grob::name x)))))

       (let* ((parx (ly:grob-parent grob X))
              (pary (ly:grob-parent grob Y)))

         (cond ((not (equal? result #f))
               ((compare parx)
                   (set! result parx)
               ((compare pary)
                   (set! result pary)
                   (if (ly:grob? parx)
                       (get-par parx))
                   (if(ly:grob? pary)
                       (get-par pary))))))
    ;; the inner function gets called from here
    (let* ((result (get-par grob)))
        ;; check if we found something
        (if (ly:grob? result)

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

#(define align-tempo-with-accidental
  (lambda (grob)
    (let* (;; returns PaperColumn- or NonMusicalPaperColumn-grob
           (col (ly:item-get-column grob))
           ;; returns System-grob
           ;; maybe taking a sledgehammer to crack a nut...
           (sys (get-parent-in-hierarchie grob 'System))
           (all-array (ly:grob-object sys 'all-elements))
           ;; better be paranoid and check for ly:grob-array?
             (if (ly:grob-array? all-array)
                 (ly:grob-array->list all-array)
           ;; get all AccidentalPlacement-grobs
               (lambda (x)
                 (and (eq? col (ly:grob-parent x X))
                      (eq? 'AccidentalPlacement (grob::name x))))
      ;; print a stencil for PaperColumn or NonMusicalPaperColumn
      ;; (for debugging)
      ;(ly:grob-set-property! col 'stencil ly:paper-column::print)

      ;; if accidentals are present return the most left coodinate of most
      ;; left accidental to use for X-offset otherwise return the default.
      (if (pair? acc-pl-grobs)
          (let* (;; get all Accidental-grobs from AccidentalPlacement
                   ;; TODO is it really safe to go for cadr only?
                     (ly:grob-object (car acc-pl-grobs) 'accidental-grobs)))
                 ;; get all X-extents of accs
                   (map (lambda (x) (ly:grob-extent x sys X)) accs))
                 ;; returns a pair containing most left, most right coordinate
                 ;; of the accidentals
                 (un (reduce interval-union '() accs-x-exts)))
            ;; return most left coordinate
            (car un))
          ;; Return the default.
          (let* ((basic-props (ly:grob-basic-properties grob))
                 (default-x-off-proc (assoc-get 'X-offset basic-props)))

%%%% Tiny example:

\layout {
  \context {
    \override MetronomeMark.X-offset = #align-tempo-with-accidental

music = { cis'1 }

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

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

  R1 |
  \tempo "Tempo"
  <aes' bes'>
  \tempo "Tempo II"
  <as' bes' ges' fes' es' des' ces'>
  \tempo "Tempo III"
  <ais' bis' gis' fis' eis' dis' cis'>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]