X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scm%2Fpart-combiner.scm;h=21cfa99326ac9f1083da409d166333bc27ce5058;hb=ab8dfc6e8f3de3cefc8fab09a4993acaec460720;hp=2a95e2083bbe5331734a30382ba4abbbbffd945e;hpb=144cd434d02e6d90b2fb738eeee99119a7c5e1d2;p=lilypond.git diff --git a/scm/part-combiner.scm b/scm/part-combiner.scm index 2a95e2083b..21cfa99326 100644 --- a/scm/part-combiner.scm +++ b/scm/part-combiner.scm @@ -1,6 +1,6 @@ ;;;; This file is part of LilyPond, the GNU music typesetter. ;;;; -;;;; Copyright (C) 2004--2010 Han-Wen Nienhuys +;;;; Copyright (C) 2004--2012 Han-Wen Nienhuys ;;;; ;;;; LilyPond is free software: you can redistribute it and/or modify ;;;; it under the terms of the GNU General Public License as published by @@ -200,8 +200,9 @@ Voice-state objects ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define-public (recording-group-emulate music odef) - "Interprets music according to odef, but stores all events in a chronological -list, similar to the Recording_group_engraver in 2.8 and earlier" + "Interpret @var{music} according to @var{odef}, but store all events +in a chronological list, similar to the @code{Recording_group_engraver} in +LilyPond version 2.8 and earlier." (let* ((context-list '()) (now-mom (ly:make-moment 0 0)) @@ -242,7 +243,7 @@ list, similar to the Recording_group_engraver in 2.8 and earlier" (ly:interpret-music-expression (make-non-relative-music music) global) context-list)) -(define-public (make-part-combine-music parser music-list) +(define-public (make-part-combine-music parser music-list direction) (let* ((m (make-music 'PartCombineMusic)) (m1 (make-non-relative-music (context-spec-music (first music-list) 'Voice "one"))) (m2 (make-non-relative-music (context-spec-music (second music-list) 'Voice "two"))) @@ -251,6 +252,7 @@ list, similar to the Recording_group_engraver in 2.8 and earlier" (evs1 (recording-group-emulate m1 listener))) (set! (ly:music-property m 'elements) (list m1 m2)) + (set! (ly:music-property m 'direction) direction) (set! (ly:music-property m 'split-list) (if (and (assoc "one" evs1) (assoc "two" evs2)) (determine-split-list (reverse! (assoc-get "one" evs1) '()) @@ -259,7 +261,7 @@ list, similar to the Recording_group_engraver in 2.8 and earlier" m)) (define-public (determine-split-list evl1 evl2) - "EVL1 and EVL2 should be ascending" + "@var{evl1} and @var{evl2} should be ascending." (let* ((pc-debug #f) (chord-threshold 8) (voice-state-vec1 (make-voice-states evl1)) @@ -462,7 +464,7 @@ Only set if not set previously. (previous-voice-state vs))) (define (try-solo type start-idx current-idx) - "Find a maximum stretch that can be marked as solo. Only set + "Find a maximum stretch that can be marked as solo. Only set the mark when there are no spanners active. return next idx to analyse. @@ -497,7 +499,7 @@ the mark when there are no spanners active. start-idx)) (define (analyse-moment result-idx) - "Analyse 'apart starting at RESULT-IDX. Return next index. " + "Analyse 'apart starting at RESULT-IDX. Return next index." (let* ((now-state (vector-ref result result-idx)) (vs1 (current-voice-state now-state 1)) (vs2 (current-voice-state now-state 2)) @@ -570,10 +572,27 @@ the mark when there are no spanners active. (define-public (add-quotable parser name mus) (let* ((tab (eval 'musicQuotes (current-module))) - (context-list (recording-group-emulate (context-spec-music mus 'Voice) - (ly:parser-lookup parser 'partCombineListener)))) - (if (pair? context-list) - (hash-set! tab name - ;; cdr : skip name string - (list->vector (reverse! (cdar context-list) - '())))))) + (voicename (get-next-unique-voice-name)) + ;; recording-group-emulate returns an assoc list (reversed!), so + ;; hand it a proper unique context name and extract that key: + (ctx-spec (context-spec-music mus 'Voice voicename)) + (listener (ly:parser-lookup parser 'partCombineListener)) + (context-list (reverse (recording-group-emulate ctx-spec listener))) + (raw-voice (assoc voicename context-list)) + (quote-contents (if (pair? raw-voice) (cdr raw-voice) '()))) + + ;; If the context-specced quoted music does not contain anything, try to + ;; use the first child, i.e. the next in context-list after voicename + ;; That's the case e.g. for \addQuote "x" \relative c \new Voice {...} + (if (null? quote-contents) + (let find-non-empty ((current-tail (member raw-voice context-list))) + ;; if voice has contents, use them, otherwise check next ctx + (cond ((null? current-tail) #f) + ((and (pair? (car current-tail)) + (pair? (cdar current-tail))) + (set! quote-contents (cdar current-tail))) + (else (find-non-empty (cdr current-tail)))))) + + (if (not (null? quote-contents)) + (hash-set! tab name (list->vector (reverse! quote-contents '()))) + (ly:music-warning mus (ly:format (_ "quoted music `~a' is empty") name)))))