http://lsr.dsi.unimi.it/LSR/Snippet?id=445
I think it is impossible to have it working [ both in relative and absolute mode]
i presume all possible tricks have been tried to achieve this!?

Well, here is a version of \makeOctaves, that seems to work in both relative and absolute mode. It fixes also a bug when you entered several notes to the chords to octavize.
Please, test.

Gilles
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
#(define (name-of music)
 (ly:music-property music 'name)) 
    
#(define (octavize-chord elements t)
(let*  ((notes (filter (lambda (x)(eq? (name-of x) 'NoteEvent)) elements))
        (not-notes
              (filter (lambda (x)(not (eq? (name-of x) 'NoteEvent))) elements))
        (transposed-notes (map 
              (lambda (x)
                  (ly:music-transpose
                          (ly:music-deep-copy x)                         
                          (ly:make-pitch t 0 0))) ;; octave (up or down)
              notes)))
 (append notes transposed-notes not-notes)))             
       
makeOctaves =  #(define-music-function (parser location arg mus) (integer? ly:music?)
(music-map
  (lambda (x)
    (let* ((elts (ly:music-property x 'elements))
           (chord-with-notes? (and (eq? 'EventChord (name-of x))
                                   (pair? elts)
                                   (eq? 'NoteEvent (name-of (car elts))))))                              
      (if chord-with-notes? (begin
        (ly:music-set-property! x 'elements (octavize-chord elts arg)) 
        (ly:music-set-property! x 'to-relative-callback  
          (lambda (prob prev-pitch) ;; destroy first the work done before !
            (let* ((es (ly:prob-property prob 'elements))
                   (notes (filter (lambda (x)(eq? (name-of x) 'NoteEvent)) es))
                   (not-notes (filter 
                        (lambda (x)(not (eq? (name-of x) 'NoteEvent))) es))
                   (origin-notes (list-head notes (quotient (length notes) 2))))
              (ly:music-set-property! prob 'elements origin-notes)
                        ;; call now the default callback with the original notes
              (let*((new-pitch (ly:music-sequence::event-chord-relative-callback 
                                                           prob prev-pitch))
                    (new-notes  (ly:prob-property prob 'elements))                                      
                    (transposed-notes (map 
                        (lambda (x)
                            (ly:music-transpose
                                    (ly:music-deep-copy x)                         
                                    (ly:make-pitch arg 0 0)))
                        new-notes)))                                      
                 (ly:music-set-property! prob 'elements (append
                           new-notes transposed-notes not-notes))
                 new-pitch))))))      
      x))     
    mus))    
    
  
%%%%%%%%%%%%%%%%%%%%%%%% tests %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
music =   {
   \clef bass
    a,4 f gis,2  
}

%% an octave up
\score{<< 
  \new StaffGroup << %% absolute mode
    \new Staff  \music
    \new Staff \makeOctaves #1 \music
    >>
  \new StaffGroup <<  %% relative mode case 1
    \new Staff \relative c' \music
    \new Staff \relative c' \makeOctaves #1 \music
    >>
  \new StaffGroup <<  %% relative mode case 2
    \new Staff \relative c' \music
    \new Staff  \makeOctaves #1 \relative c' \music
    >>
>> 
\header { piece = "an octave up"}
}

%% an octave down
music = { g'4 g' d'2}

\score{<< 
  \new StaffGroup << %% absolute mode
    \new Staff  \music
    \new Staff \makeOctaves #-1 \music
    >>
  \new StaffGroup <<  %% relative mode case 1
    \new Staff \relative c' \music
    \new Staff \relative c' \makeOctaves #-1 \music
    >>
  \new StaffGroup <<  %% relative mode case 2
    \new Staff \relative c' \music
    \new Staff  \makeOctaves #-1 \relative c' \music
    >>
>> 
\header { piece = "an octave down"}
}

%% both 
\score {
\relative c' {
   \time 3/8
   \key gis \minor
   \makeOctaves #1  
   { dis8( e dis')~ dis8.( cis16 b8} 
   \makeOctaves #-1 
   { ais' gis dis) cis( dis <dis gis>) }
 }

\header { piece = "both"}
}
_______________________________________________
lilypond-devel mailing list
lilypond-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-devel

Reply via email to