]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 2602: \unfoldRepeats and \repeat tremolo 7,14,15 produces weird output
authorDavid Kastrup <dak@gnu.org>
Thu, 14 Jun 2012 11:20:40 +0000 (13:20 +0200)
committerDavid Kastrup <dak@gnu.org>
Wed, 20 Jun 2012 05:42:55 +0000 (07:42 +0200)
This just shamelessly copies the logic of make-repeat into unfold-repeats,
on the assumption that we want to have the same rules apply for creating
and unfolding tremoli.

scm/music-functions.scm

index edf7659748c15c72f9abdeb4b8ad2333d0c5bc55..8df16aae2720f0e99e135d1268b5af69231a7729 100644 (file)
@@ -346,32 +346,35 @@ beats to be distinguished."
   (let ((es (ly:music-property music 'elements))
        (e (ly:music-property music 'element)))
 
-    (if (memq 'repeated-music (ly:music-property music 'types))
+    (if (music-is-of-type? music 'repeated-music)
        (let* ((props (ly:music-mutable-properties music))
               (old-name (ly:music-property music 'name))
               (flattened (flatten-alist props)))
          (set! music (apply make-music (cons 'UnfoldedRepeatedMusic
                                              flattened)))
 
-         (if (equal? old-name 'TremoloRepeatedMusic)
-             (let* ((seq-arg? (memq 'sequential-music
-                                    (ly:music-property e 'types)))
-                    (count (ly:music-property music 'repeat-count))
-                    (dot-shift (if (= 0 (remainder count 3))
-                                   -1 0))
-                    (child-count (if seq-arg?
-                                     (length (ly:music-property e 'elements))
-                                     0)))
-
-               (if (= 0 -1)
-                   (set! count (* 2 (quotient count 3))))
-
-               (shift-duration-log music (+ (if (= 2 child-count)
-                                                1 0)
-                                            (ly:intlog2 count)) dot-shift)
-
-               (if seq-arg?
-                   (ly:music-compress e (ly:make-moment child-count 1)))))))
+         (if (and (equal? old-name 'TremoloRepeatedMusic)
+                  (pair? (extract-named-music e '(EventChord NoteEvent))))
+             ;; This works for single-note and multi-note tremolos!
+             (let* ((children (if (music-is-of-type? e 'sequential-music)
+                                  ;; \repeat tremolo n { ... }
+                                  (length (extract-named-music e '(EventChord
+                                                                      NoteEvent)))
+                                  ;; \repeat tremolo n c4
+                                  1))
+                    (times (ly:music-property music 'repeat-count))
+
+                    ;; # of dots is equal to the 1 in bitwise representation (minus 1)!
+                    (dots (1- (logcount (* times children))))
+                    ;; The remaining missing multiplicator to scale the notes by
+                    ;; times * children
+                    (mult (/ (* times children (ash 1 dots)) (1- (ash 2 dots))))
+                    (shift (- (ly:intlog2 (floor mult)))))
+
+               ;; Adjust the time of the notes
+               (ly:music-compress music (ly:make-moment children 1))
+               ;; Adjust the displayed note durations
+               (shift-duration-log music (- shift) (- dots))))))
 
     (if (pair? es)
        (set! (ly:music-property music 'elements)