lilypond-user
[Top][All Lists]
Advanced

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

Re: \makeOctaves broken?


From: Gilles
Subject: Re: \makeOctaves broken?
Date: Thu, 19 Apr 2012 10:13:27 +0200
User-agent: Opera Mail/11.62 (Win32)


David Kastrup did a quick fix a few months
back:http://lists.gnu.org/archive/html/lilypond-user/2012-03/msg00114.html

I just tried it and it had a few problems:
- it didn't work within a relative section. It only worked within
relative sections before.
- Slurs and dynamics attached to single notes are lost during the
conversion to chords.

Below fixes the relative problem, but I haven't spent enough time on
it to figure out the second problem.

Slurs and dynamics for single note are now wrapped in the 'articulations
property.
So we have to extract those events to copy them to the 'elements property
of the event-chord.
I think that the receive scheme function is the simpler way to do that.
( http://www.gnu.org/software/guile/manual/guile.html#Multiple-Values )

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\version "2.15.35"
#(use-modules (ice-9 receive)) %% for the use of receive
#(define (with-octave-up m octave)
    (let* ((old-pitch (ly:music-property m 'pitch))
           (new-note (ly:music-deep-copy m))
           (new-pitch (ly:make-pitch
                        (- octave 1)
                        (ly:pitch-notename old-pitch)
                        (ly:pitch-alteration old-pitch))))
      (set! (ly:music-property new-note 'pitch) new-pitch)
      (list m new-note)))

#(define (octavize music t)
    (map-some-music
      (lambda (m)
        (cond ((music-is-of-type? m 'event-chord)
               (set!
                 (ly:music-property m 'elements)
                 (append-map!
                   (lambda (n)
                     (if (music-is-of-type? n 'note-event)
                       (with-octave-up n t)
                       (list n)))
                   (ly:music-property m 'elements)))
               m)
              ((music-is-of-type? m 'note-event)
                (receive (note-arti chord-arti)
                  (partition
                    ; separates arti for NoteEvent from arti for EventChord
                   (lambda (evt)(memq (ly:music-property evt 'name)
                    (list 'StringNumberEvent 'StrokeFingerEvent
'FingeringEvent)))
                   (ly:music-property m 'articulations))
                  (ly:music-set-property! m 'articulations note-arti)
               (make-event-chord (append
                (with-octave-up m t) chord-arti))))
              (else #f)))
      music))

makeOctaves = #(define-music-function (parser location arg mus)
(integer? ly:music?)
   (octavize mus arg))

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



reply via email to

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