]> git.donarmstrong.com Git - lilypond.git/blobdiff - ly/music-functions-init.ly
Release: bump version.
[lilypond.git] / ly / music-functions-init.ly
index 3b3a5b4c3aff88f6c8fb40eb50b3f60e8c76b7aa..02e6b8647e7b55324dbc7faf4dadd07f7df13912 100644 (file)
@@ -402,6 +402,15 @@ grace =
 #(def-grace-function startGraceMusic stopGraceMusic
    (_i "Insert @var{music} as grace notes."))
 
+grobdescriptions =
+#(define-scheme-function (parser location descriptions) (list?)
+   (_i "Create a context modification from @var{descriptions}, a list
+in the format of @code{all-grob-descriptions}.")
+   (ly:make-context-mod
+    (map (lambda (p)
+          (list 'assign (car p) (list (cdr p))))
+        descriptions)))
+
 harmonicByFret = #(define-music-function (parser location fret music) (number? ly:music?)
   (_i "Convert @var{music} into harmonics; the resulting notes resemble
 harmonics played on a fretted instrument by touching the strings above @var{fret}.")
@@ -754,10 +763,16 @@ Example:
                         (and (not (null? origins)) (car origins)))))))
      ;;
      ;; first, split the music and fill in voices
-     (for-each (lambda (m)
-                    (push-music m)
-                    (if (bar-check? m) (change-voice)))
-                  (ly:music-property music 'elements))
+     ;; We flatten direct layers of SequentialMusic since they are
+     ;; pretty much impossible to avoid when writing music functions.
+     (let rec ((music music))
+       (for-each (lambda (m)
+                  (if (eq? (ly:music-property m 'name) 'SequentialMusic)
+                      (rec m)
+                      (begin
+                        (push-music m)
+                        (if (bar-check? m) (change-voice)))))
+                (ly:music-property music 'elements)))
      (if (not (null? current-sequence)) (change-voice))
      ;; un-circularize `voices' and reorder the voices
      (set! voices (map-in-order (lambda (dummy seqs)
@@ -974,10 +989,49 @@ scaleDurations =
    (ly:music-compress music
                      (ly:make-moment (car fraction) (cdr fraction))))
 
+settingsFrom =
+#(define-scheme-function (parser location ctx music)
+   ((symbol?) ly:music?)
+   (_i "Take the layout instruction events from @var{music}, optionally
+restricted to those applying to context type @var{ctx}, and return
+a context modification duplicating their effect.")
+   (let ((mods (ly:make-context-mod)))
+     (define (musicop m)
+       (if (music-is-of-type? m 'layout-instruction-event)
+          (ly:add-context-mod
+           mods
+           (case (ly:music-property m 'name)
+             ((PropertySet)
+              (list 'assign
+                    (ly:music-property m 'symbol)
+                    (ly:music-property m 'value)))
+             ((PropertyUnset)
+              (list 'unset
+                    (ly:music-property m 'symbol)))
+             ((OverrideProperty)
+              (list 'push
+                    (ly:music-property m 'symbol)
+                    (ly:music-property m 'grob-property-path)
+                    (ly:music-property m 'grob-value)))
+             ((RevertProperty)
+              (list 'pop
+                    (ly:music-property m 'symbol)
+                    (ly:music-property m 'grob-property-path)))))
+          (case (ly:music-property m 'name)
+            ((SequentialMusic SimultaneousMusic)
+             (for-each musicop (ly:music-property m 'elements)))
+            ((ContextSpeccedMusic)
+             (if (or (not ctx)
+                     (eq? ctx (ly:music-property m 'context-type)))
+                 (musicop (ly:music-property m 'element)))))))
+     (musicop music)
+     mods))
+
 shiftDurations =
 #(define-music-function (parser location dur dots arg)
    (integer? integer? ly:music?)
-   (_i "Scale @var{arg} up by a factor of 2^@var{dur}*(2-(1/2)^@var{dots}).")
+   (_i "Change the duration of @var{arg} by adding @var{dur} to the
+@code{durlog} of @var{arg} and @var{dots} to the @code{dots} of @var{arg}.")
 
    (music-map
     (lambda (x)
@@ -1117,7 +1171,6 @@ void =
 Use this if you want to have a scheme expression evaluated
 because of its side-effects, but its value ignored."))
 
-
 withMusicProperty =
 #(define-music-function (parser location sym val music)
    (symbol? scheme? ly:music?)