1 ;;;; define-markup-commands.scm -- markup commands
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2000--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
6 ;;;; Jan Nieuwenhuizen <janneke@gnu.org>
10 ;;; * each markup function should have a doc string with
11 ;; syntax, description and example.
13 (use-modules (ice-9 regex))
15 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19 (define-public empty-stencil (ly:make-stencil '() '(1 . -1) '(1 . -1)))
20 (define-public point-stencil (ly:make-stencil "" '(0 . 0) '(0 . 0)))
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 (def-markup-command (draw-circle layout props radius thickness fill)
28 (number? number? boolean?)
29 "A circle of radius @var{radius}, thickness @var{thickness} and
31 (make-circle-stencil radius thickness fill))
33 (def-markup-command (triangle layout props filled) (boolean?)
34 "A triangle, filled or not"
36 ((th (chain-assoc-get 'thickness props 0.1))
37 (size (chain-assoc-get 'font-size props 0))
40 (chain-assoc-get 'baseline-skip props 2))))
54 (def-markup-command (circle layout props arg) (markup?)
55 "Draw a circle around @var{arg}. Use @code{thickness},
56 @code{circle-padding} and @code{font-size} properties to determine line
57 thickness and padding around the markup."
58 (let* ((th (chain-assoc-get 'thickness props 0.1))
59 (size (chain-assoc-get 'font-size props 0))
62 (chain-assoc-get 'circle-padding props 0.2)))
63 (m (interpret-markup layout props arg)))
64 (circle-stencil m th pad)))
66 (def-markup-command (with-url layout props url arg) (string? markup?)
67 "Add a link to URL @var{url} around @var{arg}. This only works in
69 (let* ((stil (interpret-markup layout props arg))
70 (xextent (ly:stencil-extent stil X))
71 (yextent (ly:stencil-extent stil Y))
72 (old-expr (ly:stencil-expr stil))
73 (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
74 (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
77 (def-markup-command (beam layout props width slope thickness)
78 (number? number? number?)
79 "Create a beam with the specified parameters."
80 (let* ((y (* slope width))
81 (yext (cons (min 0 y) (max 0 y)))
82 (half (/ thickness 2)))
88 (ly:output-def-lookup layout 'blotdiameter))
90 (cons (+ (- half) (car yext))
91 (+ half (cdr yext))))))
94 (def-markup-command (box layout props arg) (markup?)
95 "Draw a box round @var{arg}. Looks at @code{thickness},
96 @code{box-padding} and @code{font-size} properties to determine line
97 thickness and padding around the markup."
98 (let* ((th (chain-assoc-get 'thickness props 0.1))
99 (size (chain-assoc-get 'font-size props 0))
100 (pad (* (magstep size)
101 (chain-assoc-get 'box-padding props 0.2)))
102 (m (interpret-markup layout props arg)))
103 (box-stencil m th pad)))
107 (def-markup-command (filled-box layout props xext yext blot)
108 (number-pair? number-pair? number?)
109 "Draw a box with rounded corners of dimensions @var{xext} and @var{yext}."
113 (def-markup-command (whiteout layout props arg) (markup?)
114 "Provide a white underground for @var{arg}"
115 (let* ((stil (interpret-markup layout props
116 (make-with-color-markup black arg)))
118 (interpret-markup layout props
119 (make-with-color-markup
121 (make-filled-box-markup
122 (ly:stencil-extent stil X)
123 (ly:stencil-extent stil Y)
126 (ly:stencil-add white stil)))
128 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
130 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
132 ;;FIXME: is this working?
133 (def-markup-command (strut layout props) ()
134 "Create a box of the same height as the space in the current font."
135 (let ((m (Text_interface::interpret_markup layout props " ")))
136 (ly:make-stencil (ly:stencil-expr m)
137 (ly:stencil-extent m X)
141 ;; todo: fix negative space
142 (def-markup-command (hspace layout props amount) (number?)
143 "This produces a invisible object taking horizontal space.
145 \\markup @{ A \\hspace #2.0 B @}
147 will put extra space between A and B, on top of the space that is
148 normally inserted before elements on a line.
151 (ly:make-stencil "" (cons 0 amount) '(-1 . 1))
152 (ly:make-stencil "" (cons amount amount) '(-1 . 1))))
155 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
156 ;; importing graphics.
157 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
159 (def-markup-command (stencil layout props stil) (ly:stencil?)
165 (make-regexp "%%BoundingBox: ([0-9-]+) ([0-9-]+) ([0-9-]+) ([0-9-]+)"))
167 (define (get-postscript-bbox string)
168 "Extract the bbox from STRING, or return #f if not present."
170 ((match (regexp-exec bbox-regexp string)))
174 (string->number (match:substring match x)))
179 (def-markup-command (epsfile layout props file-name) (string?)
180 "Inline an EPS image. The image is scaled such that 10 PS units is
183 (if (ly:get-option 'safe)
184 (interpret-markup layout props "not allowed in safe")
186 ((contents (ly:gulp-file file-name))
187 (bbox (get-postscript-bbox contents))
190 (map (lambda (x) (/ x 10)) bbox)
192 (ly:warn (_ "can't find bounding box of `~a'")
207 (format "\n%%BeginDocument: ~a\n" file-name)
212 (cons (list-ref scaled-bbox 0) (list-ref scaled-bbox 2))
213 (cons (list-ref scaled-bbox 1) (list-ref scaled-bbox 3)))
215 (ly:make-stencil "" '(0 . 0) '(0 . 0))))))
218 (def-markup-command (postscript layout props str) (string?)
219 "This inserts @var{str} directly into the output as a PostScript
220 command string. Due to technicalities of the output backends,
221 different scales should be used for the @TeX{} and PostScript backend,
222 selected with @code{-f}.
225 For the TeX backend, the following string prints a rotated text
230 0 0 moveto /ecrm10 findfont
231 1.75 scalefont setfont 90 rotate (hello) show
235 The magical constant 1.75 scales from LilyPond units (staff spaces) to
238 For the postscript backend, use the following
241 gsave /ecrm10 findfont
242 10.0 output-scale div
243 scalefont setfont 90 rotate (hello) show grestore
248 (list 'embedded-ps str)
252 (def-markup-command (score layout props score) (ly:score?)
253 "Inline an image of music."
254 (let* ((output (ly:score-embedded-format score layout)))
256 (if (ly:music-output? output)
257 (ly:paper-system-stencil
258 (vector-ref (ly:paper-score-paper-systems output) 0))
260 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
263 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
265 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
267 (def-markup-command (simple layout props str) (string?)
268 "A simple text string; @code{\\markup @{ foo @}} is equivalent with
269 @code{\\markup @{ \\simple #\"foo\" @}}."
270 (interpret-markup layout props str))
273 ;; TODO: use font recoding.
275 ;; (map make-word-markup (string-tokenize str)))))
277 (define-public empty-markup
278 (make-simple-markup ""))
280 ;; helper for justifying lines.
281 (define (get-fill-space word-count line-width text-widths)
282 "Calculate the necessary paddings between each two adjacent texts.
283 The lengths of all texts are stored in @var{text-widths}.
284 The normal formula for the padding between texts a and b is:
285 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
286 The first and last padding have to be calculated specially using the
287 whole length of the first or last text.
288 Return a list of paddings.
291 ((null? text-widths) '())
293 ;; special case first padding
294 ((= (length text-widths) word-count)
296 (- (- (/ line-width (1- word-count)) (car text-widths))
297 (/ (car (cdr text-widths)) 2))
298 (get-fill-space word-count line-width (cdr text-widths))))
299 ;; special case last padding
300 ((= (length text-widths) 2)
301 (list (- (/ line-width (1- word-count))
302 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
305 (- (/ line-width (1- word-count))
306 (/ (+ (car text-widths) (car (cdr text-widths))) 2))
307 (get-fill-space word-count line-width (cdr text-widths))))))
309 (def-markup-command (fill-line layout props markups)
311 "Put @var{markups} in a horizontal line of width @var{line-width}.
312 The markups are spaced/flushed to fill the entire line.
313 If there are no arguments, return an empty stencil."
315 (let* ((orig-stencils
316 (map (lambda (x) (interpret-markup layout props x))
320 (if (ly:stencil-empty? stc)
322 stc)) orig-stencils))
325 (if (ly:stencil-empty? stc)
327 (interval-length (ly:stencil-extent stc X))))
329 (text-width (apply + text-widths))
330 (word-count (length stencils))
331 (word-space (chain-assoc-get 'word-space props))
332 (line-width (chain-assoc-get 'linewidth props))
337 (/ (- line-width text-width) 2)
338 (/ (- line-width text-width) 2)))
341 (- line-width text-width)))
343 (get-fill-space word-count line-width text-widths))))
351 (line-stencils (if (= word-count 1)
358 (if (null? (remove ly:stencil-empty? orig-stencils))
360 (stack-stencils-padding-list X RIGHT fill-space-normal line-stencils))))
362 (def-markup-command (line layout props args) (markup-list?)
363 "Put @var{args} in a horizontal line. The property @code{word-space}
364 determines the space between each markup in @var{args}."
366 ((stencils (map (lambda (m) (interpret-markup layout props m)) args))
367 (space (chain-assoc-get 'word-space props)))
371 (remove ly:stencil-empty? stencils))))
374 (define (wordwrap-stencils stencils
375 justify base-space line-width
378 "Perform simple wordwrap, return stencil of each line."
379 (define space (if justify
381 ;; justify only stretches lines.
385 (define (take-list width space stencils
386 accumulator accumulated-width)
387 "Return (head-list . tail) pair, with head-list fitting into width"
389 (cons accumulator stencils)
391 ((first (car stencils))
392 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
393 (newwid (+ space first-wid accumulated-width))
397 (or (null? accumulator)
400 (take-list width space
402 (cons first accumulator)
404 (cons accumulator stencils))
412 ((line-break (take-list line-width space todo
414 (line-stencils (car line-break))
415 (space-left (- line-width (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
418 (line-word-space (cond
419 ((not justify) space)
421 ;; don't stretch last line of paragraph.
422 ;; hmmm . bug - will overstretch the last line in some case.
423 ((null? (cdr line-break))
425 ((null? line-stencils) 0.0)
426 ((null? (cdr line-stencils)) 0.0)
427 (else (/ space-left (1- (length line-stencils))))))
429 (line (stack-stencil-line
431 (reverse line-stencils))))
433 (if (pair? (cdr line-break))
434 (loop (cons line lines)
437 (reverse (cons line lines))
443 (define (wordwrap-markups layout props args justify)
445 ((baseline-skip (chain-assoc-get 'baseline-skip props))
446 (line-width (chain-assoc-get 'linewidth props))
447 (word-space (chain-assoc-get 'word-space props))
448 (lines (wordwrap-stencils
449 (remove ly:stencil-empty?
450 (map (lambda (m) (interpret-markup layout props m)) args))
451 justify word-space line-width)
454 (stack-lines DOWN 0.0 baseline-skip lines)))
456 (def-markup-command (justify layout props args) (markup-list?)
459 (wordwrap-markups layout props args #t))
461 (def-markup-command (wordwrap layout props args) (markup-list?)
462 "Like wordwrap, but with lines stretched to justify the margins."
464 (wordwrap-markups layout props args #f))
466 (define (wordwrap-string layout props justify arg)
468 ((baseline-skip (chain-assoc-get 'baseline-skip props))
469 (line-width (chain-assoc-get 'linewidth props))
470 (word-space (chain-assoc-get 'word-space props))
471 (para-strings (regexp-split arg "\n[ \t\n]*\n[ \t\n]*"))
473 (list-para-words (map (lambda (str)
474 (regexp-split str "[ \t\n]+"))
476 (para-lines (map (lambda (words)
480 ly:stencil-empty? (map
482 (interpret-markup layout props x))
484 (lines (wordwrap-stencils stencils
485 justify word-space line-width)))
491 (stack-lines DOWN 0.0 baseline-skip (apply append para-lines))))
494 (def-markup-command (wordwrap-string layout props arg) (string?)
495 "Wordwrap a string. Paragraphs may be separated with double newlines"
496 (wordwrap-string layout props #f arg))
498 (def-markup-command (justify-string layout props arg) (string?)
499 "Justify a string. Paragraphs may be separated with double newlines"
500 (wordwrap-string layout props #t arg))
502 (def-markup-command (combine layout props m1 m2) (markup? markup?)
503 "Print two markups on top of each other."
504 (let* ((s1 (interpret-markup layout props m1))
505 (s2 (interpret-markup layout props m2)))
506 (ly:stencil-add s1 s2)))
509 ;; TODO: should extract baseline-skip from each argument somehow..
511 (def-markup-command (column layout props args) (markup-list?)
512 "Stack the markups in @var{args} vertically. The property
513 @code{baseline-skip} determines the space between each markup in @var{args}."
515 -1 0.0 (chain-assoc-get 'baseline-skip props)
516 (remove ly:stencil-empty?
517 (map (lambda (m) (interpret-markup layout props m)) args))))
519 (def-markup-command (dir-column layout props args) (markup-list?)
520 "Make a column of args, going up or down, depending on the setting
521 of the @code{#'direction} layout property."
522 (let* ((dir (chain-assoc-get 'direction props)))
524 (if (number? dir) dir -1)
526 (chain-assoc-get 'baseline-skip props)
527 (map (lambda (x) (interpret-markup layout props x)) args))))
529 (def-markup-command (center-align layout props args) (markup-list?)
530 "Put @code{args} in a centered column. "
531 (let* ((mols (map (lambda (x) (interpret-markup layout props x)) args))
532 (cmols (map (lambda (x) (ly:stencil-aligned-to x X CENTER)) mols)))
533 (stack-lines -1 0.0 (chain-assoc-get 'baseline-skip props) cmols)))
535 (def-markup-command (vcenter layout props arg) (markup?)
536 "Align @code{arg} to its Y center. "
537 (let* ((mol (interpret-markup layout props arg)))
538 (ly:stencil-aligned-to mol Y CENTER)))
540 (def-markup-command (hcenter layout props arg) (markup?)
541 "Align @code{arg} to its X center. "
542 (let* ((mol (interpret-markup layout props arg)))
543 (ly:stencil-aligned-to mol X CENTER)))
545 (def-markup-command (right-align layout props arg) (markup?)
546 "Align @var{arg} on its right edge. "
547 (let* ((m (interpret-markup layout props arg)))
548 (ly:stencil-aligned-to m X RIGHT)))
550 (def-markup-command (left-align layout props arg) (markup?)
551 "Align @var{arg} on its left edge. "
552 (let* ((m (interpret-markup layout props arg)))
553 (ly:stencil-aligned-to m X LEFT)))
555 (def-markup-command (general-align layout props axis dir arg) (integer? number? markup?)
556 "Align @var{arg} in @var{axis} direction to the @var{dir} side."
557 (let* ((m (interpret-markup layout props arg)))
558 (ly:stencil-aligned-to m axis dir)))
560 (def-markup-command (halign layout props dir arg) (number? markup?)
561 "Set horizontal alignment. If @var{dir} is @code{-1}, then it is
562 left-aligned, while @code{+1} is right. Values in between interpolate
563 alignment accordingly."
564 (let* ((m (interpret-markup layout props arg)))
565 (ly:stencil-aligned-to m X dir)))
568 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
570 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
572 (def-markup-command (fromproperty layout props symbol) (symbol?)
573 "Read the @var{symbol} from property settings, and produce a stencil
574 from the markup contained within. If @var{symbol} is not defined, it
575 returns an empty markup"
576 (let* ((m (chain-assoc-get symbol props)))
578 (interpret-markup layout props m)
579 (ly:make-stencil '() '(1 . -1) '(1 . -1)))))
582 (def-markup-command (on-the-fly layout props procedure arg) (symbol? markup?)
583 "Apply the @var{procedure} markup command to
584 @var{arg}. @var{procedure} should take a single argument."
585 (let* ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
586 (set-object-property! anonymous-with-signature
589 (interpret-markup layout props (list anonymous-with-signature arg))))
593 (def-markup-command (override layout props new-prop arg) (pair? markup?)
594 "Add the first argument in to the property list. Properties may be
595 any sort of property supported by @internalsref{font-interface} and
596 @internalsref{text-interface}, for example
599 \\override #'(font-family . married) \"bla\"
603 (interpret-markup layout (cons (list new-prop) props) arg))
605 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
607 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
610 (def-markup-command (bigger layout props arg) (markup?)
611 "Increase the font size relative to current setting"
612 (interpret-markup layout props
613 `(,fontsize-markup 1 ,arg)))
615 (def-markup-command (smaller layout props arg) (markup?)
616 "Decrease the font size relative to current setting"
617 (interpret-markup layout props
618 `(,fontsize-markup -1 ,arg)))
620 (def-markup-command larger (markup?) bigger-markup)
622 (def-markup-command (finger layout props arg) (markup?)
623 "Set the argument as small numbers."
624 (interpret-markup layout
625 (cons '((font-size . -5) (font-encoding . fetaNumber)) props)
629 (def-markup-command (fontsize layout props increment arg) (number? markup?)
630 "Add @var{increment} to the font-size. Adjust baseline skip accordingly."
632 (let* ((fs (chain-assoc-get 'font-size props 0))
633 (bs (chain-assoc-get 'baseline-skip props 2))
635 (cons 'baseline-skip (* bs (magstep increment)))
636 (cons 'font-size (+ fs increment )))))
638 (interpret-markup layout (cons entries props) arg)))
642 ;; FIXME -> should convert to font-size.
643 (def-markup-command (magnify layout props sz arg) (number? markup?)
644 "Set the font magnification for the its argument. In the following
645 example, the middle A will be 10% larger:
647 A \\magnify #1.1 @{ A @} A
650 Note: magnification only works if a font-name is explicitly selected.
651 Use @code{\\fontsize} otherwise."
654 (prepend-alist-chain 'font-magnification sz props)
657 (def-markup-command (bold layout props arg) (markup?)
658 "Switch to bold font-series"
659 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
661 (def-markup-command (sans layout props arg) (markup?)
662 "Switch to the sans serif family"
663 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
665 (def-markup-command (number layout props arg) (markup?)
666 "Set font family to @code{number}, which yields the font used for
667 time signatures and fingerings. This font only contains numbers and
668 some punctuation. It doesn't have any letters. "
669 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaNumber props) arg))
671 (def-markup-command (roman layout props arg) (markup?)
672 "Set font family to @code{roman}."
673 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
675 (def-markup-command (huge layout props arg) (markup?)
676 "Set font size to +2."
677 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
679 (def-markup-command (large layout props arg) (markup?)
680 "Set font size to +1."
681 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
683 (def-markup-command (normalsize layout props arg) (markup?)
684 "Set font size to default."
685 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
687 (def-markup-command (small layout props arg) (markup?)
688 "Set font size to -1."
689 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
691 (def-markup-command (tiny layout props arg) (markup?)
692 "Set font size to -2."
693 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
695 (def-markup-command (teeny layout props arg) (markup?)
696 "Set font size to -3."
697 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
699 (def-markup-command (caps layout props arg) (markup?)
700 "Set @code{font-shape} to @code{caps}."
701 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
703 ;(def-markup-command (latin-i layout props arg) (markup?)
704 ; "TEST latin1 encoding."
705 ; (interpret-markup layout (prepend-alist-chain 'font-shape 'latin1 props) arg))
707 (def-markup-command (dynamic layout props arg) (markup?)
708 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
709 @b{z}, @b{p}, and @b{r}. When producing phrases, like ``pi@`{u} @b{f}'', the
710 normal words (like ``pi@`{u}'') should be done in a different font. The
711 recommend font for this is bold and italic"
713 layout (prepend-alist-chain 'font-encoding 'fetaDynamic props) arg))
715 (def-markup-command (italic layout props arg) (markup?)
716 "Use italic @code{font-shape} for @var{arg}. "
717 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
719 (def-markup-command (typewriter layout props arg) (markup?)
720 "Use @code{font-family} typewriter for @var{arg}."
722 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
724 (def-markup-command (upright layout props arg) (markup?)
725 "Set font shape to @code{upright}."
727 layout (prepend-alist-chain 'font-shape 'upright props) arg))
730 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
732 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
734 (def-markup-command (doublesharp layout props) ()
735 "Draw a double sharp symbol."
737 (interpret-markup layout props (markup #:musicglyph "accidentals.4")))
739 (def-markup-command (sesquisharp layout props) ()
740 "Draw a 3/2 sharp symbol."
741 (interpret-markup layout props (markup #:musicglyph "accidentals.3")))
743 (def-markup-command (sharp layout props) ()
744 "Draw a sharp symbol."
745 (interpret-markup layout props (markup #:musicglyph "accidentals.2")))
747 (def-markup-command (semisharp layout props) ()
748 "Draw a semi sharp symbol."
749 (interpret-markup layout props (markup #:musicglyph "accidentals.1")))
751 (def-markup-command (natural layout props) ()
752 "Draw a natural symbol."
753 (interpret-markup layout props (markup #:musicglyph "accidentals.0")))
755 (def-markup-command (semiflat layout props) ()
757 (interpret-markup layout props (markup #:musicglyph "accidentals.M1")))
759 (def-markup-command (flat layout props) ()
760 "Draw a flat symbol."
761 (interpret-markup layout props (markup #:musicglyph "accidentals.M2")))
763 (def-markup-command (sesquiflat layout props) ()
764 "Draw a 3/2 flat symbol."
765 (interpret-markup layout props (markup #:musicglyph "accidentals.M3")))
767 (def-markup-command (doubleflat layout props) ()
768 "Draw a double flat symbol."
769 (interpret-markup layout props (markup #:musicglyph "accidentals.M4")))
771 (def-markup-command (with-color layout props color arg) (color? markup?)
772 "Draw @var{arg} in color specified by @var{color}"
774 (let* ((stil (interpret-markup layout props arg)))
776 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
777 (ly:stencil-extent stil X)
778 (ly:stencil-extent stil Y))))
781 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
783 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
785 (def-markup-command (musicglyph layout props glyph-name) (string?)
786 "This is converted to a musical symbol, e.g. @code{\\musicglyph
787 #\"accidentals.0\"} will select the natural sign from the music font.
788 See @usermanref{The Feta font} for a complete listing of the possible glyphs."
790 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
794 (def-markup-command (lookup layout props glyph-name) (string?)
795 "Lookup a glyph by name."
796 (ly:font-get-glyph (ly:paper-get-font layout props)
799 (def-markup-command (char layout props num) (integer?)
800 "Produce a single character, e.g. @code{\\char #65} produces the
802 (ly:get-glyph (ly:paper-get-font layout props) num))
805 (define number->mark-letter-vector (make-vector 25 #\A))
810 (if (= i (- (char->integer #\I) (char->integer #\A)))
812 (vector-set! number->mark-letter-vector j
813 (integer->char (+ i (char->integer #\A)))))
815 (define number->mark-alphabet-vector (list->vector
816 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
818 (define (number->markletter-string vec n)
819 "Double letters for big marks."
820 (let* ((lst (vector-length vec)))
823 (string-append (number->markletter-string vec (1- (quotient n lst)))
824 (number->markletter-string vec (remainder n lst)))
825 (make-string 1 (vector-ref vec n)))))
827 (def-markup-command (markletter layout props num) (integer?)
828 "Make a markup letter for @var{num}. The letters start with A to Z
829 (skipping I), and continues with double letters."
830 (Text_interface::interpret_markup layout props
831 (number->markletter-string number->mark-letter-vector num)))
833 (def-markup-command (markalphabet layout props num) (integer?)
834 "Make a markup letter for @var{num}. The letters start with A to Z
835 and continues with double letters."
836 (Text_interface::interpret_markup layout props
837 (number->markletter-string number->mark-alphabet-vector num)))
839 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
841 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
844 ;; TODO: better syntax.
846 (def-markup-command (note-by-number layout props log dot-count dir) (number? number? number?)
847 "Construct a note symbol, with stem. By using fractional values for
848 @var{dir}, you can obtain longer or shorter stems."
849 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic)) props)))
850 (size (chain-assoc-get 'font-size props 0))
851 (stem-length (* (magstep size) (max 3 (- log 1))))
852 (head-glyph (ly:font-get-glyph
854 (string-append "noteheads.s" (number->string (min log 2)))))
855 (stem-thickness 0.13)
856 (stemy (* dir stem-length))
857 (attachx (if (> dir 0)
858 (- (cdr (ly:stencil-extent head-glyph X)) stem-thickness)
860 (attachy (* dir 0.28))
861 (stem-glyph (and (> log 0)
863 (cons attachx (+ attachx stem-thickness))
864 (cons (min stemy attachy)
866 (/ stem-thickness 3))))
867 (dot (ly:font-get-glyph font "dots.dot"))
868 (dotwid (interval-length (ly:stencil-extent dot X)))
869 (dots (and (> dot-count 0)
870 (apply ly:stencil-add
872 (ly:stencil-translate-axis
873 dot (* (+ 1 (* 2 x)) dotwid) X))
874 (iota dot-count 1)))))
875 (flaggl (and (> log 2)
876 (ly:stencil-translate
877 (ly:font-get-glyph font
878 (string-append "flags."
879 (if (> dir 0) "u" "d")
880 (number->string log)))
881 (cons (+ attachx (/ stem-thickness 2)) stemy)))))
883 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
884 (if (ly:stencil? stem-glyph)
885 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
886 (set! stem-glyph head-glyph))
887 (if (ly:stencil? dots)
890 (ly:stencil-translate-axis
892 (+ (if (and (> dir 0) (> log 2))
895 ;; huh ? why not necessary?
896 ;;(cdr (ly:stencil-extent head-glyph X))
903 (let ((divisor (log 2)))
904 (lambda (z) (inexact->exact (/ (log z) divisor)))))
906 (define (parse-simple-duration duration-string)
907 "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a (log dots) list."
908 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string)))
909 (if (and match (string=? duration-string (match:substring match 0)))
910 (let ((len (match:substring match 1))
911 (dots (match:substring match 2)))
912 (list (cond ((string=? len "breve") -1)
913 ((string=? len "longa") -2)
914 ((string=? len "maxima") -3)
915 (else (log2 (string->number len))))
916 (if dots (string-length dots) 0)))
917 (ly:error (_ "not a valid duration string: ~a") duration-string))))
919 (def-markup-command (note layout props duration dir) (string? number?)
920 "This produces a note with a stem pointing in @var{dir} direction, with
921 the @var{duration} for the note head type and augmentation dots. For
922 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
923 a shortened down stem."
924 (let ((parsed (parse-simple-duration duration)))
925 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
927 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
929 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
931 (def-markup-command (lower layout props amount arg) (number? markup?)
933 Lower @var{arg}, by the distance @var{amount}.
934 A negative @var{amount} indicates raising, see also @code{\raise}.
936 (ly:stencil-translate-axis (interpret-markup layout props arg)
940 (def-markup-command (raise layout props amount arg) (number? markup?)
942 Raise @var{arg}, by the distance @var{amount}.
943 A negative @var{amount} indicates lowering, see also @code{\\lower}.
945 @lilypond[verbatim,fragment,relative=1]
946 c1^\\markup { C \\small \\raise #1.0 \\bold { \"9/7+\" }}
948 The argument to @code{\\raise} is the vertical displacement amount,
949 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
950 raise objects in relation to their surrounding markups.
952 If the text object itself is positioned above or below the staff, then
953 @code{\\raise} cannot be used to move it, since the mechanism that
954 positions it next to the staff cancels any shift made with
955 @code{\\raise}. For vertical positioning, use the @code{padding}
956 and/or @code{extra-offset} properties. "
957 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
959 (def-markup-command (fraction layout props arg1 arg2) (markup? markup?)
960 "Make a fraction of two markups."
961 (let* ((m1 (interpret-markup layout props arg1))
962 (m2 (interpret-markup layout props arg2)))
963 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
964 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
965 (let* ((x1 (ly:stencil-extent m1 X))
966 (x2 (ly:stencil-extent m2 X))
967 (line (ly:round-filled-box (interval-union x1 x2) '(-0.05 . 0.05) 0.0))
968 ;; should stack mols separately, to maintain LINE on baseline
969 (stack (stack-lines -1 0.2 0.6 (list m1 line m2))))
971 (ly:stencil-aligned-to stack Y CENTER))
973 (ly:stencil-aligned-to stack X LEFT))
974 ;; should have EX dimension
976 (ly:stencil-translate-axis stack 0.75 Y))))
982 (def-markup-command (normal-size-super layout props arg) (markup?)
983 "Set @var{arg} in superscript with a normal font size."
984 (ly:stencil-translate-axis
985 (interpret-markup layout props arg)
986 (* 0.5 (chain-assoc-get 'baseline-skip props)) Y))
988 (def-markup-command (super layout props arg) (markup?)
991 @cindex lowering text
993 @cindex translating text
995 @cindex @code{\\super}
998 Raising and lowering texts can be done with @code{\\super} and
1001 @lilypond[verbatim,fragment,relative=1]
1002 c1^\\markup { E \"=\" mc \\super \"2\" }
1006 (ly:stencil-translate-axis
1009 (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
1011 (* 0.5 (chain-assoc-get 'baseline-skip props))
1014 (def-markup-command (translate layout props offset arg) (number-pair? markup?)
1015 "This translates an object. Its first argument is a cons of numbers
1017 A \\translate #(cons 2 -3) @{ B C @} D
1019 This moves `B C' 2 spaces to the right, and 3 down, relative to its
1020 surroundings. This command cannot be used to move isolated scripts
1021 vertically, for the same reason that @code{\\raise} cannot be used for
1025 (ly:stencil-translate (interpret-markup layout props arg)
1028 (def-markup-command (sub layout props arg) (markup?)
1029 "Set @var{arg} in subscript."
1030 (ly:stencil-translate-axis
1033 (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
1035 (* -0.5 (chain-assoc-get 'baseline-skip props))
1038 (def-markup-command (normal-size-sub layout props arg) (markup?)
1039 "Set @var{arg} in subscript, in a normal font size."
1040 (ly:stencil-translate-axis
1041 (interpret-markup layout props arg)
1042 (* -0.5 (chain-assoc-get 'baseline-skip props))
1045 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1047 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1049 (def-markup-command (hbracket layout props arg) (markup?)
1050 "Draw horizontal brackets around @var{arg}."
1051 (let ((th 0.1) ;; todo: take from GROB.
1052 (m (interpret-markup layout props arg)))
1053 (bracketify-stencil m X th (* 2.5 th) th)))
1055 (def-markup-command (bracket layout props arg) (markup?)
1056 "Draw vertical brackets around @var{arg}."
1057 (let ((th 0.1) ;; todo: take from GROB.
1058 (m (interpret-markup layout props arg)))
1059 (bracketify-stencil m Y th (* 2.5 th) th)))
1061 (def-markup-command (bracketed-y-column layout props indices args)
1062 (list? markup-list?)
1063 "Make a column of the markups in @var{args}, putting brackets around
1064 the elements marked in @var{indices}, which is a list of numbers."
1065 (define (sublist lst start stop)
1066 (take (drop lst start) (- (1+ stop) start)))
1068 (define (stencil-list-extent ss axis)
1070 (apply min (map (lambda (x) (car (ly:stencil-extent x axis))) ss))
1071 (apply max (map (lambda (x) (cdr (ly:stencil-extent x axis))) ss))))
1074 (define (stack-stencils-vertically stencils bskip last-stencil)
1076 ((null? stencils) '())
1077 ((not (ly:stencil? last-stencil))
1078 (cons (car stencils)
1079 (stack-stencils-vertically (cdr stencils) bskip (car stencils))))
1081 (let* ((orig (car stencils))
1082 (dir (chain-assoc-get 'direction props DOWN))
1083 (new (ly:stencil-moved-to-edge last-stencil Y dir
1087 (cons new (stack-stencils-vertically (cdr stencils) bskip new))))))
1089 (define (make-brackets stencils indices acc)
1092 (pair? (cdr indices)))
1093 (let* ((encl (sublist stencils (car indices) (cadr indices)))
1094 (x-ext (stencil-list-extent encl X))
1095 (y-ext (stencil-list-extent encl Y))
1098 (protusion (* 2.5 thick))
1100 (ly:stencil-translate-axis
1101 (ly:bracket Y y-ext thick protusion)
1102 (- (car x-ext) pad) X))
1103 (rb (ly:stencil-translate-axis
1104 (ly:bracket Y y-ext thick (- protusion))
1105 (+ (cdr x-ext) pad) X)))
1108 stencils (cddr indices)
1121 (chain-assoc-get 'baseline-skip props))
1122 (stacked (stack-stencils-vertically
1123 (remove ly:stencil-empty? stencils) 1.25 #f))
1124 (brackets (make-brackets stacked indices '())))
1126 (apply ly:stencil-add
1127 (append stacked brackets))))