lilypond-user
[Top][All Lists]
Advanced

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

Re: vertical spacing of rests


From: Ralph Palmer
Subject: Re: vertical spacing of rests
Date: Mon, 24 Aug 2015 17:17:13 -0400

On Mon, Aug 24, 2015 at 2:56 PM, David Kastrup <address@hidden> wrote:
address@hidden (Peter Selinger) writes:

>
> this is a true newbie question. I am trying to engrave two polyphonic
> voices on a single staff. Since the two voices have all their rests in
> common, I only want to typeset each rest once, so I use spacer rests
> in the second voice. Still the vertical spacing is such that all the
> rests are put near the top of the staff. I would like them to appear
> in their "normal" positions.
>
> From the manual, I know two ways to do this. Solution 1 is to enclose
> each rest between \oneVoice and \voiceOne, forcing standard vertical
> spacing:
>
> Solution 2 is to specify an explicit vertical position for each rest.

> Neither solution is particularly elegant, as they both require every
> rest to be marked up individually. Is there a global way to turn off
> vertical spacing for rests in a context, i.e., some command whose
> effect would be to make notes behave as with \voiceOne and rests
> behave as with \oneVoice?

I apologize if I'm just making noise, since I have not followed this thread closely. As I understand it, the difficulty is with two voices, one staff, and the position of rests, especially dotted rests. I also understand that the merge rests definition I have been using (I confess I no longer know who gave it to me) in LilyPond 2.18.2 apparently doesn't work. I'll add that definition at the end of this message.

Spacer rests in one voice and positioned rests (e.g. b4\rest ) in the other voice don't work?

Hope this helps,

Ralph

Anyway, here's the merge rests definition I've been using - much thanks to the author!

%%%%%%%%%%%%%%% Start merge rests definition %%%%%%%%%%%%%%

#(define (rest-score r)
   (let ((score 0)
         (yoff (ly:grob-property-data r 'Y-offset))
         (sp (ly:grob-property-data r 'staff-position)))
     (if (number? yoff)
         (set! score (+ score 2))
         (if (eq? yoff 'calculation-in-progress)
             (set! score (- score 3))))
     (and (number? sp)
          (<= 0 2 sp)
          (set! score (+ score 2))
          (set! score (- score (abs (- 1 sp)))))
     score))

#(define (merge-rests-on-positioning grob)
   (let* ((can-merge #f)
          (elts (ly:grob-object grob 'elements))
          (num-elts (and (ly:grob-array? elts)
                         (ly:grob-array-length elts)))
          (two-voice? (= num-elts 2)))
     (if two-voice?
         (let* ((v1-grob (ly:grob-array-ref elts 0))
                (v2-grob (ly:grob-array-ref elts 1))
                (v1-rest (ly:grob-object v1-grob 'rest))
                (v2-rest (ly:grob-object v2-grob 'rest)))
           (and
            (ly:grob? v1-rest)
            (ly:grob? v2-rest)       
            (let* ((v1-duration-log (ly:grob-property v1-rest 'duration-log))
                   (v2-duration-log (ly:grob-property v2-rest 'duration-log))
                   (v1-dot (ly:grob-object v1-rest 'dot))
                   (v2-dot (ly:grob-object v2-rest 'dot))
                   (v1-dot-count (and (ly:grob? v1-dot)
                                      (ly:grob-property v1-dot 'dot-count -1)))
                   (v2-dot-count (and (ly:grob? v2-dot)
                                      (ly:grob-property v2-dot 'dot-count -1))))
              (set! can-merge
                    (and 
                     (number? v1-duration-log)
                     (number? v2-duration-log)
                     (= v1-duration-log v2-duration-log)
                     (eq? v1-dot-count v2-dot-count)))
              (if can-merge
                  ;; keep the rest that looks best:
                  (let* ((keep-v1? (>= (rest-score v1-rest)
                                       (rest-score v2-rest)))
                         (rest-to-keep (if keep-v1? v1-rest v2-rest))
                         (dot-to-kill (if keep-v1? v2-dot v1-dot)))
                    ;; uncomment if you're curious of which rest was chosen:
                    ;;(ly:grob-set-property! v1-rest 'color green)
                    ;;(ly:grob-set-property! v2-rest 'color blue)
                    (ly:grob-suicide! (if keep-v1? v2-rest v1-rest))
                    (if (ly:grob? dot-to-kill)
                        (ly:grob-suicide! dot-to-kill))
                    (ly:grob-set-property! rest-to-keep 'direction 0)
                    (ly:rest::y-offset-callback rest-to-keep)))))))
     (if can-merge
         #t
         (ly:rest-collision::calc-positioning-done grob))))

%%%%%%%%%%% End merge rests definition %%%%%%%%%% 



--
Ralph Palmer
Brattleboro, VT
USA
address@hidden

reply via email to

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