]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/define-markup-commands.scm
define-markup-commands.scm: Fix bad parameter type for \on-the-fly
[lilypond.git] / scm / define-markup-commands.scm
index d60191decf0465e3615dc09ed66ad9ba1fc7fb94..aa022974e38adaa9637d5d1c512d12bb3e54b6f7 100644 (file)
@@ -937,25 +937,45 @@ the use of @code{\\simple} is unnecessary.
 Like simple-markup, but use tie characters for @q{~} tilde symbols.
 
 @lilypond[verbatim,quote]
-\\markup {
-  \\tied-lyric #\"Lasciate~i monti\"
-}
-@end lilypond"
-  (if (string-contains str "~")
-      (let*
-         ((half-space (/ word-space 2))
-          (parts (string-split str #\~))
-          (tie-str (markup #:hspace half-space
-                           #:musicglyph "ties.lyric"
-                           #:hspace half-space))
-          (joined  (list-join parts tie-str))
-          (join-stencil (interpret-markup layout props tie-str))
-          )
+\\markup \\column {
+  \\tied-lyric #\"Siam navi~all'onde~algenti Lasciate~in abbandono\"
+  \\tied-lyric #\"Impetuosi venti I nostri~affetti sono\"
+  \\tied-lyric #\"Ogni diletto~e scoglio Tutta la vita~e~un mar.\"
+}
+@end lilypond"
+  (define (replace-ties tie str)
+    (if (string-contains str "~")
+        (let*
+          ((half-space (/ word-space 2))
+           (parts (string-split str #\~))
+           (tie-str (markup #:hspace half-space
+                            #:musicglyph tie
+                            #:hspace half-space))
+           (joined  (list-join parts tie-str)))
+          (make-concat-markup joined))
+        str))
+
+  (define short-tie-regexp (make-regexp "~[^.]~"))
+  (define (match-short str) (regexp-exec short-tie-regexp str))
+
+  (define (replace-short str mkp)
+    (let ((match (match-short str)))
+      (if (not match)
+          (make-concat-markup (list
+            mkp
+            (replace-ties "ties.lyric.default" str)))
+          (let ((new-str (match:suffix match))
+                (new-mkp (make-concat-markup (list
+                          mkp
+                          (replace-ties "ties.lyric.default"
+                                        (match:prefix match))
+                          (replace-ties "ties.lyric.short"
+                                        (match:substring match))))))
+              (replace-short new-str new-mkp)))))
 
-       (interpret-markup layout
-                         props
-                         (make-concat-markup joined)))
-      (interpret-markup layout props str)))
+  (interpret-markup layout
+                    props
+                    (replace-short str (markup))))
 
 (define-public empty-markup
   (make-simple-markup ""))
@@ -1863,6 +1883,14 @@ Add padding @var{amount} around @var{arg} in the X@tie{}direction.
 ;; property
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
+(define-markup-command (property-recursive layout props symbol)
+  (symbol?)
+  #:category other
+  "Print out a warning when a header field markup contains some recursive
+markup definition."
+  (ly:warning "Recursive definition of property ~a detected!" symbol)
+  empty-stencil)
+
 (define-markup-command (fromproperty layout props symbol)
   (symbol?)
   #:category other
@@ -1885,11 +1913,12 @@ returns an empty markup.
 @end lilypond"
   (let ((m (chain-assoc-get symbol props)))
     (if (markup? m)
-        (interpret-markup layout props m)
+        ;; prevent infinite loops by clearing the interpreted property:
+        (interpret-markup layout (cons (list (cons symbol `(,property-recursive-markup ,symbol))) props) m)
         empty-stencil)))
 
 (define-markup-command (on-the-fly layout props procedure arg)
-  (symbol? markup?)
+  (procedure? markup?)
   #:category other
   "Apply the @var{procedure} markup command to @var{arg}.
 @var{procedure} should take a single argument."
@@ -1900,6 +1929,29 @@ returns an empty markup.
     (interpret-markup layout props (list anonymous-with-signature arg))))
 
 (define-markup-command (footnote layout props mkup note)
+  (markup? markup?)
+  #:category other
+  "Have footnote @var{note} act as an annotation to the markup @var{mkup}.
+
+@lilypond[verbatim,quote]
+\\markup {
+  \\auto-footnote a b
+  \\override #'(padding . 0.2)
+  \\auto-footnote c d
+}
+@end lilypond
+The footnote will not be annotated automatically."
+  (ly:stencil-combine-at-edge
+    (interpret-markup layout props mkup)
+    X
+    RIGHT
+    (ly:make-stencil
+      `(footnote (gensym "footnote") #f ,(interpret-markup layout props note))
+      '(0 . 0)
+      '(0 . 0))
+    0.0))
+
+(define-markup-command (auto-footnote layout props mkup note)
   (markup? markup?)
   #:category other
   #:properties ((raise 0.5)
@@ -1908,11 +1960,12 @@ returns an empty markup.
 
 @lilypond[verbatim,quote]
 \\markup {
-  \\footnote a b
+  \\auto-footnote a b
   \\override #'(padding . 0.2)
-  \\footnote c d
+  \\auto-footnote c d
 }
-@end lilypond"
+@end lilypond
+The footnote will be annotated automatically."
   (let* ((markup-stencil (interpret-markup layout props mkup))
          (auto-numbering (ly:output-def-lookup layout
                                                'footnote-auto-numbering))
@@ -1970,7 +2023,7 @@ returns an empty markup.
   (ly:stencil-add
     main-stencil
     (ly:make-stencil
-      `(footnote ,footnote-hash ,(interpret-markup layout props note))
+      `(footnote ,footnote-hash #t ,(interpret-markup layout props note))
       '(0 . 0)
       '(0 . 0)))))
 
@@ -2100,18 +2153,16 @@ Adjusts @code{baseline-skip} and @code{word-space} accordingly.
 }
 @end lilypond"
   (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
-         (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
-         (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
-         (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
-         (magnification (/ size ref-size)))
-     (interpret-markup
-       layout
-       (cons
-         `((baseline-skip . ,(* magnification ref-baseline))
-           (word-space . ,(* magnification ref-word-space))
-           (font-size . ,(magnification->font-size magnification)))
-         props)
-       arg)))
+        (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
+        (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
+        (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
+        (magnification (/ size ref-size)))
+    (interpret-markup layout
+                     (cons `((baseline-skip . ,(* magnification ref-baseline))
+                             (word-space . ,(* magnification ref-word-space))
+                             (font-size . ,(magnification->font-size magnification)))
+                           props)
+                     arg)))
 
 (define-markup-command (fontsize layout props increment arg)
   (number? markup?)
@@ -2130,14 +2181,11 @@ accordingly.
   smaller
 }
 @end lilypond"
-  (interpret-markup
-    layout
-    (cons
-      `((baseline-skip . ,(* baseline-skip (magstep increment)))
-        (word-space . ,(* word-space (magstep increment)))
-        (font-size . ,(+ font-size increment)))
-      props)
-    arg))
+  (let ((entries (list
+                  (cons 'baseline-skip (* baseline-skip (magstep increment)))
+                  (cons 'word-space (* word-space (magstep increment)))
+                  (cons 'font-size (+ font-size increment)))))
+    (interpret-markup layout (cons entries props) arg)))
 
 (define-markup-command (magnify layout props sz arg)
   (number? markup?)
@@ -3642,28 +3690,6 @@ Patterns are aligned to the @var{dir} markup.
                               #:pattern (1+ count) X space pattern
                               right))))
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Replacements
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-(define-markup-command (replace layout props replacements arg)
-  (list? markup?)
-  #:category font
-  "
-Used to automatically replace a string by another in the markup @var{arg}.
-Each pair of the alist @var{replacements} specifies what should be replaced.
-The @code{key} is the string to be replaced by the @code{value} string.
-
-@lilypond[verbatim, quote]
-\\markup \\replace #'((\"thx\" . \"Thanks!\")) thx
-@end lilypond"
-  (interpret-markup
-    layout
-    (internal-add-text-replacements
-      props
-      replacements)
-    (markup arg)))
-
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Markup list commands
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;