X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=ly%2Fchord-repetition-init.ly;h=0c986a34ba4b1962c96f812df57bcb41c4931703;hb=ff7a9e47e778dd4f8b9e50e246b9866a0b0f8bdb;hp=bea929f4c658a5a8ce6f2682c8abfb4261b4da26;hpb=37a1acdcb64020041d724e42e3e41b921e655709;p=lilypond.git diff --git a/ly/chord-repetition-init.ly b/ly/chord-repetition-init.ly index bea929f4c6..0c986a34ba 100644 --- a/ly/chord-repetition-init.ly +++ b/ly/chord-repetition-init.ly @@ -1,5 +1,5 @@ %%% -*- Mode: Scheme -*- -\version "2.13.9" +\version "2.13.17" %{ The following functions define the chord repetition behavior, and may @@ -16,42 +16,64 @@ ly:parser-set-repetition-function (previous-chord, location, duration, list of articulations) which is supposed to return a new chord. `default-repeat-chord' is the default function set in this file. + `tab-repeat-chord' may be used in tablatures to preserve the string information. %} -#(define-public (default-repeat-chord previous-chord location duration articulations) - "Copy the previous chord, filter out events which are not notes, set -the chord duration, add articulations." +#(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 in an other music block, which is certainly not - ;; what the user has intended. In that case, raise a warning. + ;; 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)))) + (null? (ly:music-property previous-chord 'length)))) (ly:input-message location - (_ "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)))) +#(define-public default-repeat-chord + (make-repeat-chord-function '() '())) + +#(define-public tab-repeat-chord + (make-repeat-chord-function '(StringNumberEvent) '(StringNumberEvent))) + +% default settings #(ly:parser-set-repetition-symbol parser 'q) #(ly:parser-set-repetition-function parser default-repeat-chord)