]> git.donarmstrong.com Git - lilypond.git/blob - ly/chord-repetition-init.ly
Issue #768: Chord repetition shortcut
[lilypond.git] / ly / chord-repetition-init.ly
1 \version "2.13.8"
2 %{
3 Two functions define the chord repetition behavior, and may
4 be invoked by the user to customize it.
5
6 ly:parser-set-repetition-symbol
7   set the chord repetition shortcut.
8   `q' is the default value set in this file.
9
10 ly:parser-set-repetition-function
11   set the function that is invoked when a chord repetition symbol
12   is encountered by the parser: a three argument function
13   (previous-chord, duration, list of articulations) which is supposed
14   to return a new chord.
15   `default-repeat-chord' is the default function set in this file.
16 %}
17
18 #(define-public (default-repeat-chord previous-chord duration articulations)
19    "Copy the previous chord, filter out events which are not notes, set the
20 chord duration, add articulations."
21    (let ((new-chord (ly:music-deep-copy previous-chord)))
22      (set! (ly:music-property new-chord 'elements)
23            (append! articulations
24                     (filter (lambda (event)
25                               (eqv? (ly:music-property event 'name) 'NoteEvent))
26                             (ly:music-property new-chord 'elements))))
27      (for-each (lambda (event)
28                  (if (ly:duration? (ly:music-property event 'duration))
29                      (set! (ly:music-property event 'duration) duration)))
30                (ly:music-property new-chord 'elements))
31     new-chord))
32
33 #(ly:parser-set-repetition-symbol parser 'q)
34 #(ly:parser-set-repetition-function parser default-repeat-chord)