lilypond-user
[Top][All Lists]
Advanced

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

Music function interfere with variable name


From: foxfanfare
Subject: Music function interfere with variable name
Date: Fri, 11 Oct 2019 05:02:55 -0700 (MST)

Hi all,

In my piano scores, I use a lot a music function which can draw little hook
to indicate the hand separation. We discussed this in this post :
http://lilypond.1069038.n5.nabble.com/Layout-of-a-piano-hand-indicator-tp184061p212748.html

I currently use the code that Harm wrote last year. The problem I just
encounter is when I use specific variable in my score, it could interfere
with the function. I cannot use the X anymore, like X.title if I want a
variable for the name of the 10th movement in my work. I guess it's related
to the absciss in the function but I don't have the skill to understand it
properly.

My question is the following, can this function be corrected to avoid that
bug or does that mean that I definitely cannot write anymore roman numbers
in my variables? (note that the function works when I write "x" but crashes
with "X").

Here is an example for clarification:

\version "2.19.82"

%% From
%%
https://archiv.lilypondforum.de/index.php/topic,2507.msg14157.html#msg14157
%% slightly changed
#(define (get-parent-in-hierarchie grob searchword)
  ;; goes up in hierarchie until it finds
  ;; a grob named searchword
  (define result #f)

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

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

      (cond ((not(equal? result #f))
              result )
            ((compare parx)
              (set! result parx)
              result)
            ((compare pary)
              (set! result pary)
              result)
            (else
              (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)
            result
            #f)))

#(define (get-grob-most-left-relative-coordinate ref-point)
  ;; most suitable for container-grobs
  (lambda (grob)
    (if (ly:grob? grob)
        (cond
          ((eq? (grob::name grob) 'NoteColumn)
             (let* ((note-heads-array (ly:grob-object grob 'note-heads))
                    (note-heads-grobs
                      (if (ly:grob-array? note-heads-array)
                          (ly:grob-array->list note-heads-array)
                          '()))
                    (note-heads-refpoints
                      (map
                        (lambda (nh)
                          (ly:grob-relative-coordinate nh ref-point X))
                        note-heads-grobs))
                    (sorted-note-heads-refpoints (sort note-heads-refpoints
<)))
              (if (not (null? sorted-note-heads-refpoints))
                  (car sorted-note-heads-refpoints))))
           ((eq? (grob::name grob) 'AccidentalPlacement)
              (let* ((acc-list (ly:grob-object grob 'accidental-grobs))
                     (acc-refpoints
                       (map
                         (lambda (acc)
                           (ly:grob-relative-coordinate (cadr acc) ref-point
X))
                         acc-list))
                     (sorted-acc-refpoints (sort acc-refpoints <)))
               (if (not (null? sorted-acc-refpoints))
                   (car sorted-acc-refpoints))))
           (else
             (if (ly:grob? grob)
                 (ly:grob-relative-coordinate grob ref-point X))))
        '()))) 
hook =
#(define-event-function (details direction)
  ((number-list? '(0 0 -0.85 3)) ly:dir?)
  (let* ((hook-markup
         #{
             \markup
               \path
                 #0.175
                 #`((moveto 0 0)
                   (rlineto ,(caddr details) 0)
                   (rlineto 0 ,(* direction (cadddr details))))
         #}))
    #{
       \tweak before-line-breaking
         #(lambda (grob)
            (let* (;; grob-parent may be FingeringColumn
                   (grob-parent (ly:grob-parent grob X))
                   (note-head (get-parent-in-hierarchie grob 'NoteHead))
                   (staff-pos (ly:grob-property note-head 'staff-position))
                   (staff-space (ly:staff-symbol-staff-space grob))
                   (fingering-column
                     (grob::has-interface
                       grob-parent
                       'fingering-column-interface)))
        ;; If `fingeringOrientations = #'(left)' and more than one fingering
        ;; is present, we need to go via FingeringColumn.positioning-done
        (if fingering-column
            (let* ((fingers-array (ly:grob-object grob-parent 'fingerings))
                   (fingers-list
                     (if (ly:grob-array? fingers-array)
                         (ly:grob-array->list fingers-array)
                         '())))
              (ly:grob-set-property! grob-parent 'positioning-done
                (lambda (x)
                  (for-each
                    (lambda (f)
                      (if (equal? grob f)
                          (ly:grob-set-property! f 'stencil
                            (ly:stencil-translate
                              (ly:grob-property f 'stencil)
                              (cons
                                (car details)
                                (* direction
                                   (+
                                      (/ (cadddr details) 2)
                                      (cadr details)
                                      (* staff-space
                                         (if (even? staff-pos) -0.5
-1)))))))
                          (ly:grob-set-property! f 'stencil
                            (ly:stencil-aligned-to
                              (ly:grob-property f 'stencil)
                              Y
                              DOWN))))
                    fingers-list))))


            (let* ((side-axis (ly:grob-property grob 'side-axis))
                   (padding (ly:grob-property grob 'padding))
                   (sys (get-parent-in-hierarchie grob 'System))
                   (note-column (ly:grob-parent note-head X))
                   (note-head-ext
                     (ly:grob-extent note-head note-column X))
                   (nc-left
                     ((get-grob-most-left-relative-coordinate sys)
                      note-column))
                   (acc-placement (ly:note-column-accidentals note-column))
                   (acc-left
                     ((get-grob-most-left-relative-coordinate sys)
                      acc-placement))
                   (val
                     (cond ((and (null? acc-left) (not (negative? nc-left)))
                            (+ (- nc-left)
                               (if (not (zero? (car note-head-ext)))
                                   (car note-head-ext)
                                   0)))
                           ((and (not (null? acc-left)) (negative? nc-left))
                            (+
                               (- acc-left)
                               (if (negative? (car note-head-ext))
                                   (car note-head-ext)
                                   0)))
                           ((not (null? acc-left))
                            (+ (- nc-left acc-left)
                               (if (not (zero? (car note-head-ext)))
                                   (car note-head-ext)
                                   0)))
                           (else
                             (if (negative? (car note-head-ext))
                                 0
                                 (- nc-left))))))

         (if (not (zero? side-axis))
             (ly:grob-translate-axis!
               grob
               (- (+ val (car details) padding))
               X))
              (ly:grob-set-property! grob 'Y-offset
                (+ (* direction staff-space (if (even? staff-pos) -0.5 -1))
                   (if (zero? side-axis)
                       0
                       (/ staff-pos 2))
                   (cadr details)))))))
       \finger #hook-markup
    #})) 

%---

IX = "title 9"
X = "title 10"

\score {
  \relative c' { c1\hook #UP }
  \header {
    piece = \X
  }
}



--
Sent from: http://lilypond.1069038.n5.nabble.com/User-f3.html



reply via email to

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