]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 5003 unfoldRepeats can be restricted to certain repeat-types
authorThomas Morley <thomasmorley65@gmail.com>
Thu, 1 Dec 2016 21:38:54 +0000 (22:38 +0100)
committerThomas Morley <thomasmorley65@gmail.com>
Mon, 12 Dec 2016 23:13:31 +0000 (00:13 +0100)
It now takes an additional, optional argument.
It's a list of symbols representing the repeat-types which should
be unfolded.
Possible settings are percent, tremolo and volta.
The default is an empty list, for which repeated-music is taken,
unfolding all.
A new regtest is added to cover the new feature.
Changes is extended accordingly.

Also correcting two small typos in Documentation/notation/staff.itely

Documentation/changes.tely
Documentation/notation/staff.itely
input/regression/repeat-unfold-partial.ly [new file with mode: 0644]
ly/articulate.ly
ly/music-functions-init.ly
scm/music-functions.scm

index 2407b3d018f3c664b9e6c387b04647684db2cea4..958ecb109e095c7fa9605da34647ca2ac0fbfb6c 100644 (file)
@@ -61,6 +61,14 @@ which scares away people.
 
 @end ignore
 
+@item
+The music function @code{\\unfoldRepeats} can now take an
+optional argument-list specifying which type(s) of repeated music
+should be unfolded.  Possible entries are @code{percent}, @code{tremolo},
+@code{volta}.
+If the optional argument-list is unspecified, @code{repeated-music} will be
+used, unfolding all.
+
 @item
 A new @code{output-attributes} grob property is now used for svg output
 instead of the @code{id} grob property.  It allows multiple attributes
index a1144346644864b8298f30a4fe6e9df2423c9078..d097535643b0bb9a4f6e6841755b11c07b65fa5c 100644 (file)
@@ -1078,9 +1078,9 @@ oboeNotes = \relative {
 }
 @end lilypond
 
-If an @code{\unfoldRepeat} command in a music expression is required to
+If an @code{\unfoldRepeats} command in a music expression is required to
 be printed when using @code{\quoteDuring}, then it too must also contain
-its own @code{\unfoldRepeat} command;
+its own @code{\unfoldRepeats} command;
 
 @lilypond[verbatim,quote]
 fluteNotes = \relative {
diff --git a/input/regression/repeat-unfold-partial.ly b/input/regression/repeat-unfold-partial.ly
new file mode 100644 (file)
index 0000000..8023932
--- /dev/null
@@ -0,0 +1,37 @@
+\header {
+  texidoc = "The music function @code{\\unfoldRepeats} can take an
+optional argument-list specifying which type(s) of repeated music has
+to be unfolded."
+}
+
+m =
+  \repeat volta 2 {
+      \repeat percent 2 { c'1 }
+      \repeat tremolo 4 { c'16 d' }
+      f'2
+  }
+  \alternative {
+      { d'1 }
+      { e'1 }
+  }
+
+\markup "not expanding"
+\m
+
+\markup "expanding all"
+\unfoldRepeats \m
+
+\markup "expanding percent-repeated-music"
+\unfoldRepeats percent \m
+
+\markup "expanding tremolo-repeated-music"
+\unfoldRepeats tremolo \m
+
+\markup "expanding volta-repeated-music"
+\unfoldRepeats volta \m
+
+\markup \column {
+  "combinations are possible:"
+  "expanding percent-repeated-music and tremolo-repeated-music"
+}
+\unfoldRepeats percent,tremolo \m
index 0f198ffbedcbdb3b6e1c7c51240f5cc718f7f787..1dc0e5566b1868a8153501e4be362487e40641fe 100644 (file)
 %    how to do lookahead in scheme.
 %  * Also ignore explicit line breaks.
 %  * Add Mordents (reported by Patrick Karl)
-%
+%  * Thomas Morley: extend unfold-repeats to reflect the possibility to
+%    customize its effect to user-settable repeat-types. Here the most general
+%    setting is hard-coded, resulting in unchanged behaviour.
 
 \version "2.19.22"
 
         (make-music 'BarCheck))))
      (else
       m)))
-   (unfold-repeats music)))
+   (unfold-repeats '() music)))
 
 % If there's an articulation, use it.
 % If in a slur, use (1 . 1) instead (unless the note is marked staccato,
index d96e655370612f6e107ac3259df3a4c066071fd1..1f94319bce743ca1e6994eebdff7daa672db0e12 100644 (file)
@@ -1976,11 +1976,16 @@ unsets already in @var{music} cause a warning.  Non-property-related music is ig
         (else (make-sequential-music lst))))))
 
 unfoldRepeats =
-#(define-music-function (music) (ly:music?)
-   (_i "Force any @code{\\repeat volta}, @code{\\repeat tremolo} or
+#(define-music-function (types music)
+   ((symbol-list-or-symbol? '()) ly:music?)
+   (_i "Force @code{\\repeat volta}, @code{\\repeat tremolo} or
 @code{\\repeat percent} commands in @var{music} to be interpreted
-as @code{\\repeat unfold}.")
-   (unfold-repeats music))
+as @code{\\repeat unfold}, if specified in the optional symbol-list @var{types}.
+The default for @var{types} is an empty list, which will force any of those
+commands in @var{music} to be interpreted as @code{\\repeat unfold}.  Possible
+entries are @code{volta}, @code{tremolo} or @code{percent}.  Multiple entries
+are possible.")
+   (unfold-repeats types music))
 
 void =
 #(define-void-function (arg) (scheme?)
index 3e9818d0093b48c1d0072dbfe3d7fa2d97efcf18..b1dc2f9c61391f32931e66b039561220af3e493c 100644 (file)
@@ -390,19 +390,36 @@ beats to be distinguished."
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; repeats.
 
-(define-public (unfold-repeats music)
-  "Replace all repeats with unfolded repeats."
-  (let ((es (ly:music-property music 'elements))
-        (e (ly:music-property music 'element)))
-    (if (music-is-of-type? music 'repeated-music)
-        (set! music (make-music 'UnfoldedRepeatedMusic music)))
-    (if (pair? es)
-        (set! (ly:music-property music 'elements)
-              (map unfold-repeats es)))
-    (if (ly:music? e)
-        (set! (ly:music-property music 'element)
-              (unfold-repeats e)))
-    music))
+(define-public (unfold-repeats types music)
+  "Replace repeats of the types given by @var{types} with unfolded repeats.
+If @var{types} is an empty list, @code{repeated-music} is taken, unfolding all."
+  (let* ((types-list
+           (if (or (null? types) (not (list? types)))
+               (list types)
+               types))
+         (repeat-types-alist
+           '((volta . volta-repeated-music)
+             (percent . percent-repeated-music)
+             (tremolo . tremolo-repeated-music)
+             (() . repeated-music)))
+         (repeat-types-hash (alist->hash-table repeat-types-alist)))
+  (for-each
+    (lambda (type)
+      (let ((repeat-type (hashq-ref repeat-types-hash type)))
+        (if repeat-type
+            (let ((es (ly:music-property music 'elements))
+                  (e (ly:music-property music 'element)))
+              (if (music-is-of-type? music repeat-type)
+                  (set! music (make-music 'UnfoldedRepeatedMusic music)))
+              (if (pair? es)
+                  (set! (ly:music-property music 'elements)
+                        (map (lambda (x) (unfold-repeats types x)) es)))
+              (if (ly:music? e)
+                  (set! (ly:music-property music 'element)
+                        (unfold-repeats types e))))
+            (ly:warning "unknown repeat-type ~a, ignoring." type))))
+    types-list)
+  music))
 
 (define-public (unfold-repeats-fully music)
   "Unfolds repeats and expands the resulting @code{unfolded-repeated-music}."
@@ -411,7 +428,7 @@ beats to be distinguished."
      (and (music-is-of-type? m 'unfolded-repeated-music)
           (make-sequential-music
            (ly:music-deep-copy (make-unfolded-set m)))))
-   (unfold-repeats music)))
+   (unfold-repeats '() music)))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; property setting music objs.