1 %%% -*- Mode: Scheme -*-
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 (let* ((new-chord (ly:music-deep-copy previous-chord))
33 (notes (filter (lambda (event)
34 (eqv? (ly:music-property event 'name) 'NoteEvent))
35 (ly:music-property new-chord 'elements))))
36 ;; remove possible cautionary/forced accidentals from notes
37 (for-each (lambda (note)
38 (if (eqv? (ly:music-property note 'cautionary) #t)
39 (set! (ly:music-property note 'cautionary) #f))
40 (if (eqv? (ly:music-property note 'force-accidental) #t)
41 (set! (ly:music-property note 'force-accidental) #f)))
43 ;; Add articulations and notes to the new event chord
44 (set! (ly:music-property new-chord 'elements)
45 (append! notes articulations))
46 ;; Set the duration of each event
47 (for-each (lambda (event)
48 (if (ly:duration? (ly:music-property event 'duration))
49 (set! (ly:music-property event 'duration) duration)))
50 (ly:music-property new-chord 'elements))
51 ;; Set the new chord origin
52 (set! (ly:music-property new-chord 'origin) location)
53 ;; return the new chord
56 #(ly:parser-set-repetition-symbol parser 'q)
57 #(ly:parser-set-repetition-function parser default-repeat-chord)