lilypond-devel
[Top][All Lists]
Advanced

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

Re: sponsorship option gone?


From: Arvid Grøtting
Subject: Re: sponsorship option gone?
Date: Fri, 30 Mar 2007 07:40:20 +0200

2007/3/22, Han-Wen Nienhuys <address@hidden>:
2007/3/22, Arvid Grøtting <address@hidden>:
> But I just might come up with a scheme function that takes two (or
> more) voices and merges (or centers) the rests that are common.  Do
> you think that's feasible?

Good point there:  you'll probably be able to write a callback for
positioning-done which checks whether the rests (ly:grob-object
'rests) have equal 'duration-log and 'dot-count properties, and if yes
force them to overlap, and if no, call the original
calc-positioning-done function.

Hmm.   I've managed to merge some rests that way, but:

- where do I get at the dot-count?  I've tried several ways, but so
far with no luck...

- how do I make sure the merged rest stays in the middle?  Do I need
to kill both rest grobs and create a new one, or something?

- this callback doesn't seem to be called by multi-measure rests.  Any
ideas on how to merge those?

My code so far is below.  Never mind my setting the colors and calling
display-scheme-music a lot; that's just me trying to figure out what
happens...

Cheers,

-- Arvid

\version "2.11.20"


va = \relative c'' {
 c4 r e r |
 d8. e16 r f16~f8 r2 |
 r1 |
 r2. r4 |
 r4. e8 r8. e16 r16. e32 r32. d64 r16 |
 \bar "||"
 c4 r r-1 g     |
  r2.    r4   |
  r4.   r8-2 r8. r16 r4 |
  R1 |
  R1*4 }
vb = \relative c'' {
 c4 r e r |
 d8. e16 r f16~f8 r2 |
 r1 |
 r2. r4 |
 r4. e8 r8. e16 r16. e32 r32. d64 r16 |
 \bar "||"
 c4 e r r8. e16 |
  r4 c r4. b8 |
  r4 r8 r8   r8    r4.  |
  R1*3 |
  R1*2}




#(define merge-rests-on-positioning
 (lambda (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)))   
     (display-scheme-music (list 'rest-grobs v1-rest v2-rest))
     (set! can-merge
      (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-dots (ly:grob-object v1-rest 'dots))
               (v2-dots (ly:grob-object v2-rest 'dots))
               (v1-dot-count (and (ly:grob? v1-dots)
                              (ly:grob-property v1-dots 'dot-count -1)))
               (v2-dot-count (and (ly:grob? v2-dots)
                              (ly:grob-property v2-dots 'dot-count -1))))
         (display-scheme-music
          (list 'rests
           (list 'duration-logs v1-duration-log v2-duration-log)
           (list 'dots v1-dots v2-dots)
           (list 'dot-counts v1-dot-count v2-dot-count)
           ;(list 'music-duration-lengths
             ; (ly:music-duration-length v1-rest)
             ; (ly:music-duration-length v2-rest))
           ;(list 'properties (ly:grob-properties v1-rest)
             ; (ly:grob-properties v2-rest))
         ))
         (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
      (begin
        (display-scheme-music "; mergable rest! here!")
        (display-scheme-music (list 'Y-offsets
                               (ly:grob-property v1-rest 'Y-offset)
                               (ly:grob-property v1-rest 'Y-offset)))
        ;(ly:grob-set-property! v1-rest 'Y-offset 0)
        ;(ly:grob-set-property! v1-rest 'Y-extent '(-1 . 1))
        ;(ly:grob-set-property! v1-rest 'staff-position -3)
        (ly:grob-set-property! v1-rest 'direction 0)
        (ly:grob-set-property! v1-rest 'color red)
        ;(ly:grob-set-property! v2-rest 'Y-offset 0)
        ;(ly:grob-set-property! v2-rest 'Y-extent '(-1 . 1))
        ;(ly:grob-set-property! v2-rest 'staff-position 0)
        (ly:grob-set-property! v2-rest 'direction 0)
        (ly:grob-set-property! v2-rest 'color blue)
        (ly:grob-suicide! v1-rest)
        #t)
      (ly:rest-collision::calc-positioning-done grob))) ; when two
voices, but not two equal rests
    (ly:rest-collision::calc-positioning-done grob))))) % when not two voices

\score {
 \context Score <<
   \new Staff \with {
     \override RestCollision #'positioning-done = #merge-rests-on-positioning
   }
   % \displayMusic
   <<
     \va \\
     \vb
   >>
 >>
 \layout {}
}




reply via email to

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