lilypond-devel
[Top][All Lists]
Advanced

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

Re: Enhancement: tabalture chord repetition (issue224082)


From: nicolas . sceaux
Subject: Re: Enhancement: tabalture chord repetition (issue224082)
Date: Sun, 28 Feb 2010 17:29:57 +0000

On 2010/02/28 16:27:07, nicolas.sceaux wrote:
http://codereview.appspot.com/224082/diff/1/3
File ly/chord-repetition-init.ly (right):

http://codereview.appspot.com/224082/diff/1/3#newcode51
ly/chord-repetition-init.ly:51: #(define-public (tab-repeat-chord
previous-chord
location duration articulations)
It would be  better to define a generic repetition function, taking
the event
types that should be kept for NoteEvents. default-repeat-chord and
tab-repeat-chord would then use this function.  I'm writing it on
other post.


#(define-public ((make-repeat-chord-function chord-element-types
note-articulation-types)
                 previous-chord location duration articulations)
   "Make a chord repetition function.
The returned functions copies the notes from @var{previous-chord} into
a new chord.
Chord elements, which type is found in @var{chord-element-types}, are
copied into the new chord.
Note articulations, which type is found in @var
{note-articulation-types},
are also copied.
All other events are not copied into the new chord.
"
   (define (filter-events events event-types)
     (filter (lambda (event)
               (and (memq (ly:music-property event 'name) event-types)
event))
             events))
   ;; If previous-chord has an length property, then it means that it
   ;; has been processed by a music iterator.  In other words, the chord
   ;; has been memorized from an other music block, which is certainly
not
   ;; what the user has intended, as anywy the result will be buggy.
   ;; In that case, raise a warning.
   (if (not (and (ly:music? previous-chord)
                 (null? (ly:music-property previous-chord 'length))))
       (ly:input-message location
                         (_ "No memorized chord in music block before
chord repetition")))
   ;; Instead of copying the previous chord, then removing the
   ;; undesired elements (like articulations), a new empty chord is
built.
   ;; Then, the pitch found in the previous chord are added to the new
   ;; chord, without any "decoration" (e.g. cautionary accidentals,
   ;; fingerings, text scripts, articulations).  Only the events of
types
   ;; given in `chord-elements-types' and `note-articulation-types' are
   ;; copied from the original chord elements and note articulations,
   ;; respectively.
   (let ((elements (ly:music-property (ly:music-deep-copy
previous-chord) 'elements)))
     (make-music
      'EventChord
      'origin location
      'elements (append!
                 (map (lambda (note)
                        (let ((new-note (make-music 'NoteEvent
                                                    'pitch
(ly:music-property note 'pitch)
                                                    'duration duration))
                              (articulations
                               (filter-events (ly:music-property note
'articulations)
                                              note-articulation-types)))
                          (if (not (null? articulations))
                              (set! (ly:music-property new-note
'articulations)
                                    articulations))
                          new-note))
                      (filter-events elements '(NoteEvent)))
                 (filter-events elements chord-element-types)
                 articulations))))

#(define-public default-repeat-chord
   (make-repeat-chord-function '() '()))

#(define-public tab-repeat-chord
   (make-repeat-chord-function '(StringNumberEvent)
'(StringNumberEvent)))


http://codereview.appspot.com/224082/show




reply via email to

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