]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/output-lib.scm
Merge branch 'master' into translation
[lilypond.git] / scm / output-lib.scm
index 8a5cae2b23f0fbcc79ab61c6334dd0222b115380..dcec6ae939b162c26c7c0734de5b5095b852d81a 100644 (file)
@@ -880,8 +880,9 @@ and duration-log @var{log}."
               (ly:stencil-aligned-to
                (make-parenthesis-stencil y-extent
                                          half-thickness
-                                         (- width)
-                                         angularity)
+                                         width
+                                         angularity
+                                         -1)
                Y CENTER)
               X RIGHT))
          (lp-x-extent
@@ -891,7 +892,8 @@ and duration-log @var{log}."
                (make-parenthesis-stencil y-extent
                                          half-thickness
                                          width
-                                         angularity)
+                                         angularity
+                                         1)
                Y CENTER)
               X LEFT))
          (rp-x-extent
@@ -967,14 +969,53 @@ and duration-log @var{log}."
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;
 
-(define-public (chain-grob-member-functions grob value . funcs)
-  (for-each
-   (lambda (func)
-     (set! value (func grob value)))
-   funcs)
-
-  value)
-
+(define-public (grob::compose-function func data)
+  "This creates a callback entity to be stored in a grob property,
+based on the grob property data @var{data} (which can be plain data, a
+callback itself, or an unpure-pure-container).
+
+Function or unpure-pure-container @var{func} accepts a grob and a
+value and returns another value.  Depending on the type of @var{data},
+@var{func} is used for building a grob callback or an
+unpure-pure-container."
+  (if (or (ly:unpure-pure-container? func)
+          (ly:unpure-pure-container? data))
+      (ly:make-unpure-pure-container
+       (lambda (grob) (ly:unpure-call func grob (ly:unpure-call data grob)))
+       (lambda (grob start end)
+         (ly:pure-call func grob start end
+                       (ly:pure-call data grob start end))))
+      (lambda (grob) (ly:unpure-call func grob (ly:unpure-call data grob)))))
+
+(define*-public (grob::offset-function func data
+                                       #:optional (plus +))
+  "This creates a callback entity to be stored in a grob property,
+based on the grob property data @var{data} (which can be plain data, a
+callback itself, or an unpure-pure-container).
+
+Function @var{func} accepts a grob and returns a value that is added
+to the value resulting from @var{data}.  Optional argument @var{plus}
+defaults to @code{+} but may be changed to allow for using a different
+underlying accumulation.
+
+If @var{data} is @code{#f} or @code{'()}, it is not included in the sum."
+  (cond ((or (not data) (null? data))
+         func)
+        ((or (ly:unpure-pure-container? func)
+             (ly:unpure-pure-container? data))
+         (ly:make-unpure-pure-container
+          (lambda rest
+            (plus (apply ly:unpure-call func rest)
+                  (apply ly:unpure-call data rest)))
+          (lambda rest
+            (plus (apply ly:pure-call func rest)
+                  (apply ly:pure-call data rest)))))
+        ((or (procedure? func)
+             (procedure? data))
+         (lambda rest
+           (plus (apply ly:unpure-call func rest)
+                 (apply ly:unpure-call data rest))))
+        (else (plus func data))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; falls/doits
@@ -1080,9 +1121,11 @@ and duration-log @var{log}."
 (define-public (stroke-finger::calc-text grob)
   (let ((event (event-cause grob)))
     (or (ly:event-property event 'text #f)
-        (vector-ref (ly:grob-property grob 'digit-names)
-                    (1- (max 1
-                             (min 5 (ly:event-property event 'digit))))))))
+        (let ((digit-names (ly:grob-property grob 'digit-names)))
+          (vector-ref digit-names
+                      (1- (max 1
+                               (min (vector-length digit-names)
+                                    (ly:event-property event 'digit)))))))))
 
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;