lilypond-user
[Top][All Lists]
Advanced

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

Re: String Number collision


From: Marc Hohl
Subject: Re: String Number collision
Date: Thu, 6 Jul 2017 08:53:38 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1

Hi Harm,

Am 05.07.2017 um 23:21 schrieb Thomas Morley:
Hi Marc,

2017-07-05 8:13 GMT+02:00 Marc Hohl <address@hidden>:
Hi list,

I have the following MWE:
[...]
It causes the string number "5" to appear twice, strangely overlapping.
I tried to move the New_fingering_engraver to Staff, but then I got

side-axis not set for grob StringNumber.

Not sure what you expected, I didn't explore the programming error, though.

Well, I hoped that lilypond discardes one of two identical string-number events automatically.

I assume that I have to create an engraver similar to the
Merge_rests_engraver that does this job? Or is there another way apart from

\once\hide StringNumber

all the way across the file?



You could do:

#(define (suicide-duplicate-text-grobs grob-lst)
"Walks through the sorted @var{grob-lst}, suiciding grobs with duplicate text"
   (if (null? (cdr grob-lst))
       #f
       (suicide-duplicate-text-grobs
         (if (string=? (ly:grob-property (car grob-lst) 'text)
                       (ly:grob-property (cadr grob-lst) 'text))
             (begin
               (ly:grob-suicide! (car grob-lst))
               (cdr grob-lst))
             (cdr grob-lst)))))

#(define reduce-string-numbers
   (lambda (grob)
"Gets the PaperColumn-grob, filters for StringNumber-grobs, sorts this grobs
with @code{string<?} looking at their 'text-property.
Finally suicides grobs with already present text."
     (let* ((paper-column (ly:item-get-column grob))
            (strgs
              (filter
                (lambda (g)
                  (grob::has-interface g 'string-number-interface))
                (ly:grob-array->list (ly:grob-object paper-column 'elements))))
            (sorted-strgs
              (sort
                strgs
                (lambda (p q)
                  (string<? (ly:grob-property p 'text)
                            (ly:grob-property q 'text))))))
       (suicide-duplicate-text-grobs sorted-strgs))))

deleteDuplicateStrings =
\override StringNumber.after-line-breaking = #reduce-string-numbers


up = { <c'\5 g'\4 e''>8 ~ e''2. }

down = { <c'\5  g'\4> ~ c'2. }

\score {
   <<
   \new Staff
   <<
      \new Voice \with { \deleteDuplicateStrings } { \voiceOne \up }
      \new Voice  { \voiceTwo \down }
   >>
   \new TabStaff
   <<
      \new TabVoice { \voiceOne \up }
      \new TabVoice  { \voiceTwo \down }
   >>
   >>
}


Though, I think an engraver would probably do the job cheaper. (Not tested)

Okay, thanks a lot for your solution! I'll check how it fits in my project.

Regards,

Marc



HTH,
   Harm





reply via email to

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