]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/new-markup.scm
(context-doc): add aliases to
[lilypond.git] / scm / new-markup.scm
index f9587aa8a2adeabf74479484d708893216ef6fd6..e59c4bcc709a8a2f7f96a9afd80f4ef1a35a73a4 100644 (file)
@@ -45,10 +45,15 @@ for the reader.
 
 " ; " 
 
-(define-public (simple-markup grob props . rest)
-  (Text_item::text_to_molecule grob props (car rest))
-  )
 
+;;;;;;;;;;;;;;;;;
+;; TODO:
+;; each markup function should have a doc string with
+;; syntax, description and example. 
+;;
+
+(define-public (simple-markup grob props . rest)
+  (Text_item::interpret_markup grob props (car rest)))
 
 (define-public (stack-molecule-line space molecules)
   (if (pair? molecules)
@@ -68,6 +73,10 @@ for the reader.
   )
 
 (define-public (line-markup grob props . rest)
+  "A horizontal line of markups. Syntax:
+\\line << MARKUPS >>
+"
+  
   (stack-molecule-line
    (cdr (chain-assoc 'word-space props))
    (map (lambda (x) (interpret-markup grob props x)) (car rest)))
@@ -94,7 +103,6 @@ for the reader.
                      (cadr rest))
     ))
 
-
 (define-public (finger-markup grob props . rest)
   (interpret-markup grob
                    (cons (list '(font-relative-size . -3)
@@ -102,7 +110,6 @@ for the reader.
                                props)
                    (car rest)))
 
-
 (define-public fontsize-markup (set-property-markup 'font-relative-size))
 (define-public magnify-markup (set-property-markup 'font-magnification))
 
@@ -128,6 +135,8 @@ for the reader.
   (font-markup 'font-family 'dynamic))
 (define-public italic-markup
   (font-markup 'font-shape 'italic))
+(define-public typewriter-markup
+  (font-markup 'font-family 'typewriter))
 
 
 ;; TODO: baseline-skip should come from the font.
@@ -161,6 +170,23 @@ for the reader.
      mols)
     ))
 
+(define-public (right-align-markup grob props . rest)
+  (let* ((m (interpret-markup grob props (car rest))))
+    (ly:molecule-align-to! m X RIGHT)
+    m))
+
+(define-public (halign-markup grob props . rest)
+  "Set horizontal alignment. Syntax: haling A MARKUP. A=-1 is LEFT,
+A=1 is right, values in between vary alignment accordingly."
+  (let* ((m (interpret-markup grob props (cadr rest))))
+    (ly:molecule-align-to! m X (car rest))
+    m))
+
+(define-public (left-align-markup grob props . rest)
+  (let* ((m (interpret-markup grob props (car rest))))
+    (ly:molecule-align-to! m X RIGHT)
+    m))
+
 (define-public (musicglyph-markup grob props . rest)
   (ly:find-glyph-by-name
    (ly:get-font grob (cons '((font-family . music)) props))
@@ -186,8 +212,34 @@ for the reader.
                               grob
                               props
                               (cadr rest))
-                             (car rest) Y)
-  )
+                             (car rest) Y))
+
+(define-public (fraction-markup grob props . rest)
+  "Make a fraction of two markups.
+
+Syntax: \\fraction MARKUP1 MARKUP2."
+
+  (let*
+      ((m1 (interpret-markup grob props (car rest)))
+       (m2 (interpret-markup grob props (cadr rest))))
+
+    (ly:molecule-align-to! m1 X CENTER)
+    (ly:molecule-align-to! m2 X CENTER)
+    
+    (let*
+       ((x1 (ly:molecule-get-extent m1 X))
+        (x2 (ly:molecule-get-extent m2 X))
+        (line (ly:round-filled-box (interval-union x1 x2) '(-0.05 . 0.05) 0.0))
+
+        ;; should stack mols separately, to maintain LINE on baseline
+        (stack (stack-lines -1 0.2 0.6 (list m1 line m2))))
+
+      (ly:molecule-align-to! stack Y CENTER)
+      (ly:molecule-align-to! stack X LEFT)
+      ;; should have EX dimension
+      ;; empirical anyway
+      (ly:molecule-translate-axis stack 0.75 Y) 
+      )))
 
 
 (define-public (note-markup grob props . rest)
@@ -208,10 +260,10 @@ for the reader.
                    0))
        (attachy (* dir 0.28))
        (stemgl (if (> log 0)
-                  (ly:round-filled-box (cons
+                  (ly:round-filled-box
                                     (cons attachx (+ attachx  stemth))
                                     (cons (min stemy attachy)
-                                          (max stemy attachy)))
+                                          (max stemy attachy))
                                    (/ stemth 3)
                                    ) #f))
        (dot (ly:find-glyph-by-name font "dots-dot"))
@@ -307,6 +359,8 @@ for the reader.
   )
 
 (define-public (hbracket-markup grob props . rest)
+  "Horizontal brackets around its single argument. Syntax \\hbracket MARKUP."  
+  
   (let*
       (
        (th 0.1) ;; todo: take from GROB.
@@ -317,6 +371,7 @@ for the reader.
 ))
 
 (define-public (bracket-markup grob props . rest)
+  "Vertical brackets around its single argument. Syntax \\bracket MARKUP."  
   (let*
       (
        (th 0.1) ;; todo: take from GROB.
@@ -381,6 +436,23 @@ for the reader.
     (box-molecule m th pad)
   ))
 
+
+(define-public (strut-markup grob props . rest)
+  "Syntax: \strut
+
+ A box of the same height as the space.
+"
+
+  (let*
+      ((m (Text_item::interpret_markup grob props " ")))
+
+    (ly:molecule-set-extent! m 0 '(1000 . -1000))
+    m))
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+
 (define (markup-signature-to-keyword sig)
   " (A B C) -> a0-b1-c2 "
   
@@ -516,17 +588,23 @@ for the reader.
    (cons finger-markup (list markup?))
    (cons bold-markup (list markup?))
    (cons italic-markup (list markup?))
+   (cons typewriter-markup (list markup?))
    (cons roman-markup (list markup?))
    (cons number-markup (list markup?))
    (cons hbracket-markup  (list markup?))
    (cons bracket-markup  (list markup?))
    (cons note-markup (list integer? integer? ly:dir?))
+   (cons fraction-markup (list markup? markup?))
    
    (cons column-markup (list markup-list?))
    (cons dir-column-markup (list markup-list?))
    (cons center-markup (list markup-list?))
    (cons line-markup  (list markup-list?))
 
+   (cons right-align-markup (list markup?))
+   (cons left-align-markup (list markup?))   
+   (cons halign-markup (list number? markup?))
+   
    (cons combine-markup (list markup? markup?))
    (cons simple-markup (list string?))
    (cons musicglyph-markup (list scheme?))
@@ -542,8 +620,8 @@ for the reader.
    (cons fontsize-markup (list number? markup?))
 
    (cons box-markup  (list markup?))
-   )
-  )
+   (cons strut-markup '())
+   ))
 
 
 (define markup-module (current-module))
@@ -609,13 +687,12 @@ against SIGNATURE, reporting MAKE-NAME as the user-invoked function.
 "
 
   (let*
-      (
-       (arglen (length args))
+      ((arglen (length args))
        (siglen (length signature))
        (error-msg
        (if (and (> siglen 0) (> arglen 0))
-           (markup-argument-list-error signature args 1)))
-       )
+           (markup-argument-list-error signature args 1)
+           #f)))
 
 
     (if (or (not (= arglen siglen)) (< siglen 0) (< arglen 0))
@@ -648,11 +725,15 @@ against SIGNATURE, reporting MAKE-NAME as the user-invoked function.
  markup-module
  )
 
+;;
+;; TODO: add module argument so user-defined markups can also be 
+;; processed.
+;;
 (define-public (lookup-markup-command code)
   (let*
-      ( (sym (string->symbol (string-append code "-markup")))
-       (var (module-local-variable markup-module sym))
-       )
+      ((sym (string->symbol (string-append code "-markup")))
+       (var (module-local-variable markup-module sym))
+       )
     (if (eq? var #f)
        #f   
        (cons (variable-ref var) (object-property  (variable-ref var) 'markup-keyword))
@@ -660,28 +741,11 @@ against SIGNATURE, reporting MAKE-NAME as the user-invoked function.
   ))
 
 
-(define-public (brew-new-markup-molecule grob)
-  (let*
-      ((t (ly:get-grob-property grob 'text))
-       (chain (Font_interface::get_property_alist_chain grob)))
-    (if (markup? t)
-       (interpret-markup grob  chain t)
-       (Text_item::text_to_molecule grob t chain)
-       )))
+(define-public brew-new-markup-molecule Text_item::brew_molecule)
 
 (define-public empty-markup (make-simple-markup ""))
 
-(define-public (interpret-markup grob props markup)
-  (if (string? markup)
-      (simple-markup grob props markup)
-      (let*
-         (
-          (func (car markup))
-          (args (cdr markup))
-          )
-       
-       (apply func (cons grob (cons props args)) )
-       )))
+(define-public interpret-markup Text_item::interpret_markup)
 
 
 ;;;;;;;;;;;;;;;;