LSR: Update.
[lilypond/mpolesky.git] / ly / chord-repetition-init.ly
blobf19e3a10b50d5433168ed4c92bafedf90526599d
1 %%% -*- Mode: Scheme -*-
2 \version "2.13.9"
3 %{
5 The following functions define the chord repetition behavior, and may
6 be invoked by the user to customize it.
8 ly:parser-set-repetition-symbol
9 set the chord repetition shortcut.
10 `q' is the default value set in this file.
12 ly:parser-set-repetition-function
14 set the function that is invoked when a chord repetition symbol
15 is encountered by the parser: a four argument function
16 (previous-chord, location, duration, list of articulations) which is
17 supposed to return a new chord.
18 `default-repeat-chord' is the default function set in this file.
21 #(define-public (default-repeat-chord previous-chord location duration articulations)
22 "Copy the previous chord, filter out events which are not notes, set
23 the chord duration, add articulations."
24 ;; If previous-chord has an length property, then it means that it
25 ;; has been processed by a music iterator. In other words, the chord
26 ;; has been memorized in an other music block, which is certainly not
27 ;; what the user has intended. In that case, raise a warning.
28 (if (not (and (ly:music? previous-chord)
29 (null? (ly:music-property previous-chord 'length))))
30 (ly:input-message location
31 (_ "No memorized chord in music block before chord repetition")))
32 ;; Instead of copying the previous chord, then removing the
33 ;; undesired elements (like articulations), a new empty chord is
34 ;; built. Then, the pitch found in the previous chord are added to
35 ;; the new chord, without any "decoration" (e.g. cautionary
36 ;; accidentals, fingerings, text scripts, articulations).
37 (make-music
38 'EventChord
39 'origin location
40 'elements (append! (filter identity
41 (map (lambda (event)
42 (and (eqv? (ly:music-property event 'name) 'NoteEvent)
43 (make-music
44 'NoteEvent
45 'pitch (ly:music-property event 'pitch)
46 'duration duration)))
47 (ly:music-property previous-chord 'elements)))
48 articulations)))
50 #(ly:parser-set-repetition-symbol parser 'q)
51 #(ly:parser-set-repetition-function parser default-repeat-chord)