]> git.donarmstrong.com Git - lilypond.git/blobdiff - ly/music-functions-init.ly
Release: bump Welcome versions.
[lilypond.git] / ly / music-functions-init.ly
index 9af5c885395fffaf5a4b57215d4ba9ad462479ea..a23d154fd814d7e1ebdfe4c2de03afb0ab0659d3 100644 (file)
@@ -29,8 +29,6 @@
 #(use-modules (srfi srfi-1)
               (ice-9 optargs))
 
-%% TODO: using define-music-function in a .scm causes crash.
-
 absolute =
 #(define-music-function (music)
    (ly:music?)
@@ -95,7 +93,7 @@ markups), or inside a score.")
 
 alterBroken =
 #(define-music-function (property arg item)
-  (symbol-list-or-symbol? list? symbol-list-or-music?)
+  (key-list-or-symbol? list? key-list-or-music?)
   (_i "Override @var{property} for pieces of broken spanner @var{item}
 with values @var{arg}.  @var{item} may either be music in the form of
 a starting spanner event, or a symbol list in the form
@@ -189,19 +187,17 @@ pitch where to switch staves may be specified.  The clefs for the staves are
 optional as well.  Setting clefs  works only for implicitly instantiated
 staves.")
   (let ;; keep the contexts alive for the full duration
-       ((skip (make-skip-music (make-duration-of-length
-                                     (ly:music-length music)))))
-    #{
-      <<
-        \context Staff = "up" $(or clef-1 #{ \with { \clef "treble" } #})
-          <<
-          #(make-autochange-music pitch music)
-          \new Voice { #skip }
-          >>
-        \context Staff = "down" $(or clef-2 #{ \with { \clef "bass" } #})
-          \new Voice { #skip }
-      >>
-    #}))
+       ((skip (make-duration-of-length (ly:music-length music)))
+        (clef-1 (or clef-1 #{ \with { \clef "treble" } #}))
+        (clef-2 (or clef-2 #{ \with { \clef "bass" } #})))
+    (make-simultaneous-music
+     (list
+      (descend-to-context (make-autochange-music pitch music) 'Staff
+                          "up" clef-1)
+      (context-spec-music (make-skip-music skip) 'Staff
+                          "up" clef-1)
+      (context-spec-music (make-skip-music skip) 'Staff
+                          "down" clef-2)))))
 
 balloonGrobText =
 #(define-music-function (grob-name offset text)
@@ -844,6 +840,37 @@ mark =
           (if label (set! (ly:music-property ev 'label) label))
           ev))))
 
+markupMap =
+#(define-music-function (path markupfun music)
+   (symbol-list-or-symbol? markup-function? ly:music?)
+   (_i "This applies the given markup function @var{markupfun} to all markup
+music properties matching @var{path} in @var{music}.
+
+For example,
+@example
+\\new Voice @{ g'2 c'' @}
+\\addlyrics @{
+  \\markupMap LyricEvent.text
+             \\markup \\with-color #red \\etc
+             @{ Oh yes! @}
+@}
+@end example
+")
+   (let* ((p (check-music-path path (*location*)))
+          (name (and p (car p)))
+          (prop (and p (cadr p))))
+     (if p
+         (for-some-music
+          (lambda (m)
+            (if (or (not name) (eq? (ly:music-property m 'name) name))
+                (let ((text (ly:music-property m prop)))
+                  (if (markup? text)
+                      (set! (ly:music-property m prop)
+                            (list markupfun text)))))
+            #f)
+          music)))
+   music)
+
 musicMap =
 #(define-music-function (proc mus) (procedure? ly:music?)
    (_i "Apply @var{proc} to @var{mus} and all of the music it contains.")
@@ -881,7 +908,7 @@ octaveCheck =
 
 offset =
 #(define-music-function (property offsets item)
-  (symbol-list-or-symbol? scheme? symbol-list-or-music?)
+  (symbol-list-or-symbol? scheme? key-list-or-music?)
    (_i "Offset the default value of @var{property} of @var{item} by
 @var{offsets}.  If @var{item} is a string, the result is
 @code{\\override} for the specified grob type.  If @var{item} is
@@ -969,7 +996,7 @@ of @var{base-moment}, @var{beat-structure}, and @var{beam-exceptions}.")
 
 overrideProperty =
 #(define-music-function (grob-property-path value)
-   (symbol-list? scheme?)
+   (key-list? scheme?)
 
    (_i "Set the grob property specified by @var{grob-property-path} to
 @var{value}.  @var{grob-property-path} is a symbol list of the form
@@ -1048,9 +1075,9 @@ Example:
     d d | e e | f f |
   }
 <==>
-  A = { c c | d d }
-  B = { d d | e e }
-  C = { e e | f f }
+  A = { c c | d d }
+  B = { d d | e e }
+  C = { e e | f f }
 @end verbatim
 
 The last bar checks in a sequence are not copied to the result in
@@ -1267,25 +1294,7 @@ that they share a staff with stems directed downward.")
     #{ \with { \voiceTwo \override DynamicLineSpanner.direction = #DOWN } #}
     #{ \with { \voiceTwo \override DynamicLineSpanner.direction = #DOWN } #} ))
 
-partcombineForce =
-#(define-music-function (type once) (boolean-or-symbol? boolean?)
-   (_i "Override the part-combiner.")
-   (make-music 'EventChord
-               'elements (list (make-music 'PartCombineForceEvent
-                                           'forced-type type
-                                           'once once))))
-partcombineApart = \partcombineForce #'apart ##f
-partcombineApartOnce = \partcombineForce #'apart ##t
-partcombineChords = \partcombineForce #'chords ##f
-partcombineChordsOnce = \partcombineForce #'chords ##t
-partcombineUnisono = \partcombineForce #'unisono ##f
-partcombineUnisonoOnce = \partcombineForce #'unisono ##t
-partcombineSoloI = \partcombineForce #'solo1 ##f
-partcombineSoloIOnce = \partcombineForce #'solo1 ##t
-partcombineSoloII = \partcombineForce #'solo2 ##f
-partcombineSoloIIOnce = \partcombineForce #'solo2 ##t
-partcombineAutomatic = \partcombineForce ##f ##f
-partcombineAutomaticOnce = \partcombineForce ##f ##t
+%% Part combine forcing to be found in ly/property-init.ly
 
 partial =
 #(define-music-function (dur) (ly:duration?)
@@ -1330,7 +1339,7 @@ print @var{secondary-note} as a stemless note head in parentheses.")
 
 propertyOverride =
 #(define-music-function (grob-property-path value)
-   (symbol-list? scheme?)
+   (key-list? scheme?)
    (_i "Set the grob property specified by @var{grob-property-path} to
 @var{value}.  @var{grob-property-path} is a symbol list of the form
 @code{Context.GrobName.property} or @code{GrobName.property}, possibly
@@ -1353,7 +1362,7 @@ command.")
 
 propertyRevert =
 #(define-music-function (grob-property-path)
-   (symbol-list?)
+   (key-list?)
    (_i "Revert the grob property specified by @var{grob-property-path} to
 its previous value.  @var{grob-property-path} is a symbol list of the form
 @code{Context.GrobName.property} or @code{GrobName.property}, possibly
@@ -1390,7 +1399,7 @@ Scheme as a substitute for the built-in @code{\\set} command.")
 
 propertyTweak =
 #(define-music-function (prop value item)
-   (symbol-list-or-symbol? scheme? symbol-list-or-music?)
+   (key-list-or-symbol? scheme? key-list-or-music?)
    (_i "Add a tweak to the following @var{item}, usually music.
 This generally behaves like @code{\\tweak} but will turn into an
 @code{\\override} when @var{item} is a symbol list.
@@ -1416,7 +1425,47 @@ property (inside of an alist) is tweaked.")
    ;; should only be attempted when the simple uses don't match the
    ;; given predicate.
    (if (ly:music? item)
-       (tweak prop value item)
+       (if (music-is-of-type? item 'context-specification)
+           ;; This is essentially dealing with the case
+           ;; \propertyTweak color #red \propertyTweak font-size #3 NoteHead
+           ;; namely when stacked tweaks end in a symbol list
+           ;; rather than a music expression.
+           ;;
+           ;; We have a tweak here to convert into an override,
+           ;; so we need to know the grob to apply it to.  That's
+           ;; easy if we have a directed tweak, and otherwise we
+           ;; need to find the symbol in the expression itself.
+           (let* ((p (check-grob-path prop (*location*)
+                                      #:start 1
+                                      #:default #t
+                                      #:min 2))
+                  (elt (ly:music-property item 'element))
+                  (seq (if (music-is-of-type? elt 'sequential-music)
+                           elt
+                           (make-sequential-music (list elt))))
+                  (elts (ly:music-property seq 'elements))
+                  (symbol (if (symbol? (car p))
+                              (car p)
+                              (and (pair? elts)
+                                   (ly:music-property (car elts)
+                                                      'symbol)))))
+             (if (symbol? symbol)
+                 (begin
+                   (set! (ly:music-property seq 'elements)
+                         (cons (make-music 'OverrideProperty
+                                           'symbol symbol
+                                           'grob-property-path (cdr p)
+                                           'pop-first #t
+                                           'grob-value value
+                                           'origin (*location*))
+                               elts))
+                   (set! (ly:music-property item 'element) seq))
+                 (begin
+                   (ly:parser-error (_ "Cannot \\propertyTweak")
+                                    (*location*))
+                   (ly:music-message item (_ "untweakable"))))
+             item)
+           (tweak prop value item))
        (propertyOverride (append item (if (symbol? prop) (list prop) prop))
                          value)))
 
@@ -1581,7 +1630,7 @@ a context modification duplicating their effect.")
 
 shape =
 #(define-music-function (offsets item)
-   (list? symbol-list-or-music?)
+   (list? key-list-or-music?)
    (_i "Offset control-points of @var{item} by @var{offsets}.  The
 argument is a list of number pairs or list of such lists.  Each
 element of a pair represents an offset to one of the coordinates of a
@@ -1589,15 +1638,11 @@ control-point.  If @var{item} is a string, the result is
 @code{\\once\\override} for the specified grob type.  If @var{item} is
 a music expression, the result is the same music expression with an
 appropriate tweak applied.")
-   (define (shape-curve grob)
+   (define (shape-curve grob coords)
      (let* ((orig (ly:grob-original grob))
             (siblings (if (ly:spanner? grob)
                           (ly:spanner-broken-into orig) '()))
-            (total-found (length siblings))
-            (function (assoc-get 'control-points
-                                 (reverse (ly:grob-basic-properties grob))))
-            (coords (function grob)))
-
+            (total-found (length siblings)))
        (define (offset-control-points offsets)
          (if (null? offsets)
              coords
@@ -1620,7 +1665,9 @@ appropriate tweak applied.")
        (if (>= total-found 2)
            (helper siblings offsets)
            (offset-control-points (car offsets)))))
-   (once (propertyTweak 'control-points shape-curve item)))
+   (once (propertyTweak 'control-points
+                        (grob-transformer 'control-points shape-curve)
+                        item)))
 
 shiftDurations =
 #(define-music-function (dur dots arg)
@@ -1840,7 +1887,7 @@ command without explicit @samp{tuplet-span}, use
 
 tweak =
 #(define-music-function (prop value music)
-   (symbol-list-or-symbol? scheme? ly:music?)
+   (key-list-or-symbol? scheme? ly:music?)
    (_i "Add a tweak to the following @var{music}.
 Layout objects created by @var{music} get their property @var{prop}
 set to @var{value}.  If @var{prop} has the form @samp{Grob.property}, like with
@@ -1861,41 +1908,6 @@ property (inside of an alist) is tweaked.")
            ;; p now contains at least two elements.  The first
            ;; element is #t when no grob has been explicitly
            ;; specified, otherwise it is a grob name.
-           ((music-is-of-type? music 'context-specification)
-            ;; This is essentially dealing with the case
-            ;; \tweak color #red \propertyTweak font-size #3 NoteHead
-            ;; namely when stacked tweaks end in a symbol list
-            ;; rather than a music expression.
-            ;;
-            ;; We have a tweak here to convert into an override,
-            ;; so we need to know the grob to apply it to.  That's
-            ;; easy if we have a directed tweak, and otherwise we
-            ;; need to find the symbol in the expression itself.
-            (let* ((elt (ly:music-property music 'element))
-                   (seq (if (music-is-of-type? elt 'sequential-music)
-                            elt
-                            (make-sequential-music (list elt))))
-                   (elts (ly:music-property seq 'elements))
-                   (symbol (if (symbol? (car p))
-                               (car p)
-                               (and (pair? elts)
-                                    (ly:music-property (car elts)
-                                                       'symbol)))))
-              (if (symbol? symbol)
-                  (begin
-                    (set! (ly:music-property seq 'elements)
-                          (cons (make-music 'OverrideProperty
-                                            'symbol symbol
-                                            'grob-property-path (cdr p)
-                                            'pop-first #t
-                                            'grob-value value
-                                            'origin (*location*))
-                                elts))
-                    (set! (ly:music-property music 'element) seq))
-                  (begin
-                    (ly:parser-error (_ "Cannot \\tweak")
-                                     (*location*))
-                    (ly:music-message music (_ "untweakable"))))))
            (else
             (set! (ly:music-property music 'tweaks)
                   (acons (cond ((pair? (cddr p)) p)