- (_ "No memorized chord in music block before chord repetition")))
- (let* ((new-chord (ly:music-deep-copy previous-chord))
- (notes (filter (lambda (event)
- (eqv? (ly:music-property event 'name) 'NoteEvent))
- (ly:music-property new-chord 'elements))))
- ;; remove possible cautionary/forced accidentals from notes
- (for-each (lambda (note)
- (if (eqv? (ly:music-property note 'cautionary) #t)
- (set! (ly:music-property note 'cautionary) #f))
- (if (eqv? (ly:music-property note 'force-accidental) #t)
- (set! (ly:music-property note 'force-accidental) #f)))
- notes)
- ;; Add articulations and notes to the new event chord
- (set! (ly:music-property new-chord 'elements)
- (append! notes articulations))
- ;; Set the duration of each event
- (for-each (lambda (event)
- (if (ly:duration? (ly:music-property event 'duration))
- (set! (ly:music-property event 'duration) duration)))
- (ly:music-property new-chord 'elements))
- ;; Set the new chord origin
- (set! (ly:music-property new-chord 'origin) location)
- ;; return the new chord
- new-chord))
+ (_ "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
+ 'origin location
+ '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))))