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 (define-public empty-stencil (ly:make-stencil '() '(1 . -1) '(1 . -1)))
16 (define-public point-stencil (ly:make-stencil "" '(0 . 0) '(0 . 0)))
18 (def-markup-command (stencil layout props stil) (ly:stencil?)
22 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26 (def-markup-command (draw-circle layout props radius thickness fill)
27 (number? number? boolean?)
28 "A circle of radius @var{radius}, thickness @var{thickness} and
30 (make-circle-stencil radius thickness fill))
32 (def-markup-command (triangle layout props filled) (boolean?)
33 "A triangle, filled or not"
35 ((th (chain-assoc-get 'thickness props 0.1))
36 (size (chain-assoc-get 'font-size props 0))
39 (chain-assoc-get 'baseline-skip props 2))))
53 (def-markup-command (circle layout props arg) (markup?)
54 "Draw a circle around @var{arg}. Use @code{thickness},
55 @code{circle-padding} and @code{font-size} properties to determine line
56 thickness and padding around the markup."
57 (let* ((th (chain-assoc-get 'thickness props 0.1))
58 (size (chain-assoc-get 'font-size props 0))
61 (chain-assoc-get 'circle-padding props 0.2)))
62 (m (interpret-markup layout props arg)))
63 (circle-stencil m th pad)))
65 (def-markup-command (with-url layout props url arg) (string? markup?)
66 "Add a link to URL @var{url} around @var{arg}. This only works in
68 (let* ((stil (interpret-markup layout props arg))
69 (xextent (ly:stencil-extent stil X))
70 (yextent (ly:stencil-extent stil Y))
71 (old-expr (ly:stencil-expr stil))
72 (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
73 (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
76 (def-markup-command (beam layout props width slope thickness)
77 (number? number? number?)
78 "Create a beam with the specified parameters."
79 (let* ((y (* slope width))
80 (yext (cons (min 0 y) (max 0 y)))
81 (half (/ thickness 2)))
87 (ly:output-def-lookup layout 'blotdiameter))
89 (cons (+ (- half) (car yext))
90 (+ half (cdr yext))))))
93 (def-markup-command (box layout props arg) (markup?)
94 "Draw a box round @var{arg}. Looks at @code{thickness},
95 @code{box-padding} and @code{font-size} properties to determine line
96 thickness and padding around the markup."
97 (let* ((th (chain-assoc-get 'thickness props 0.1))
98 (size (chain-assoc-get 'font-size props 0))
99 (pad (* (magstep size)
100 (chain-assoc-get 'box-padding props 0.2)))
101 (m (interpret-markup layout props arg)))
102 (box-stencil m th pad)))
106 (def-markup-command (filled-box layout props xext yext blot)
107 (number-pair? number-pair? number?)
108 "Draw a box with rounded corners of dimensions @var{xext} and @var{yext}."
112 (def-markup-command (whiteout layout props arg) (markup?)
113 "Provide a white underground for @var{arg}"
114 (let* ((stil (interpret-markup layout props
115 (make-with-color-markup black arg)))
117 (interpret-markup layout props
118 (make-with-color-markup
120 (make-filled-box-markup
121 (ly:stencil-extent stil X)
122 (ly:stencil-extent stil Y)
125 (ly:stencil-add white stil)))
127 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
129 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
131 ;;FIXME: is this working?
132 (def-markup-command (strut layout props) ()
133 "Create a box of the same height as the space in the current font."
134 (let ((m (Text_interface::interpret_markup layout props " ")))
135 (ly:make-stencil (ly:stencil-expr m)
136 (ly:stencil-extent m X)
140 ;; todo: fix negative space
141 (def-markup-command (hspace layout props amount) (number?)
142 "This produces a invisible object taking horizontal space.
144 \\markup @{ A \\hspace #2.0 B @}
146 will put extra space between A and B, on top of the space that is
147 normally inserted before elements on a line.
150 (ly:make-stencil "" (cons 0 amount) '(-1 . 1))
151 (ly:make-stencil "" (cons amount amount) '(-1 . 1))))
154 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
155 ;; importing graphics.
156 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
160 (make-regexp "%%BoundingBox: ([0-9-]+) ([0-9-]+) ([0-9-]+) ([0-9-]+)"))
162 (define (get-postscript-bbox string)
163 "Extract the bbox from STRING, or return #f if not present."
165 ((match (regexp-exec bbox-regexp string)))
169 (string->number (match:substring match x)))
174 (def-markup-command (epsfile layout props file-name) (string?)
175 "Inline an EPS image. The image is scaled such that 10 PS units is
178 (if (ly:get-option 'safe)
179 (interpret-markup layout props "not allowed in safe")
181 ((contents (ly:gulp-file file-name))
182 (bbox (get-postscript-bbox contents))
185 (map (lambda (x) (/ x 10)) bbox)
187 (ly:warn (_ "can't find bounding box of `~a'")
202 (format "\n%%BeginDocument: ~a\n" file-name)
207 (cons (list-ref scaled-bbox 0) (list-ref scaled-bbox 2))
208 (cons (list-ref scaled-bbox 1) (list-ref scaled-bbox 3)))
210 (ly:make-stencil "" '(0 . 0) '(0 . 0))))))
213 (def-markup-command (postscript layout props str) (string?)
214 "This inserts @var{str} directly into the output as a PostScript
215 command string. Due to technicalities of the output backends,
216 different scales should be used for the @TeX{} and PostScript backend,
217 selected with @code{-f}.
220 For the TeX backend, the following string prints a rotated text
225 0 0 moveto /ecrm10 findfont
226 1.75 scalefont setfont 90 rotate (hello) show
230 The magical constant 1.75 scales from LilyPond units (staff spaces) to
233 For the postscript backend, use the following
236 gsave /ecrm10 findfont
237 10.0 output-scale div
238 scalefont setfont 90 rotate (hello) show grestore
243 (list 'embedded-ps str)
247 (def-markup-command (score layout props score) (ly:score?)
248 "Inline an image of music."
249 (let* ((output (ly:score-embedded-format score layout)))
251 (if (ly:music-output? output)
252 (ly:paper-system-stencil
253 (vector-ref (ly:paper-score-paper-systems output) 0))
255 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
258 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
260 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
262 (def-markup-command (simple layout props str) (string?)
263 "A simple text string; @code{\\markup @{ foo @}} is equivalent with
264 @code{\\markup @{ \\simple #\"foo\" @}}."
265 (interpret-markup layout props str))
268 ;; TODO: use font recoding.
270 ;; (map make-word-markup (string-tokenize str)))))
272 (define-public empty-markup
273 (make-simple-markup ""))
276 (def-markup-command (fill-line layout props markups)
278 "Put @var{markups} in a horizontal line of width @var{line-width}.
279 The markups are spaced/flushed to fill the entire line.
280 If there are no arguments, return an empty stencil.
284 (define (get-fill-space word-count line-width text-widths)
285 "Calculate the necessary paddings between each two adjacent texts.
286 The lengths of all texts are stored in @var{text-widths}.
287 The normal formula for the padding between texts a and b is:
288 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
289 The first and last padding have to be calculated specially using the
290 whole length of the first or last text.
291 Return a list of paddings.
294 ((null? text-widths) '())
296 ;; special case first padding
297 ((= (length text-widths) word-count)
299 (- (- (/ line-width (1- word-count)) (car text-widths))
300 (/ (car (cdr text-widths)) 2))
301 (get-fill-space word-count line-width (cdr text-widths))))
302 ;; special case last padding
303 ((= (length text-widths) 2)
304 (list (- (/ line-width (1- word-count))
305 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
308 (- (/ line-width (1- word-count))
309 (/ (+ (car text-widths) (car (cdr text-widths))) 2))
310 (get-fill-space word-count line-width (cdr text-widths))))))
313 (let* ((orig-stencils
314 (map (lambda (x) (interpret-markup layout props x))
318 (if (ly:stencil-empty? stc)
320 stc)) orig-stencils))
323 (if (ly:stencil-empty? stc)
325 (interval-length (ly:stencil-extent stc X))))
327 (text-width (apply + text-widths))
328 (word-count (length stencils))
329 (word-space (chain-assoc-get 'word-space props))
330 (line-width (chain-assoc-get 'linewidth props))
335 (/ (- line-width text-width) 2)
336 (/ (- line-width text-width) 2)))
339 (- line-width text-width)))
341 (get-fill-space word-count line-width text-widths))))
349 (line-stencils (if (= word-count 1)
356 (if (null? (remove ly:stencil-empty? orig-stencils))
358 (stack-stencils-padding-list X RIGHT fill-space-normal line-stencils))))
360 (def-markup-command (line layout props args) (markup-list?)
361 "Put @var{args} in a horizontal line. The property @code{word-space}
362 determines the space between each markup in @var{args}."
364 ((stencils (map (lambda (m) (interpret-markup layout props m)) args))
365 (space (chain-assoc-get 'word-space props)))
369 (remove ly:stencil-empty? stencils))))
373 (def-markup-command (combine layout props m1 m2) (markup? markup?)
374 "Print two markups on top of each other."
375 (let* ((s1 (interpret-markup layout props m1))
376 (s2 (interpret-markup layout props m2)))
377 (ly:stencil-add s1 s2)))
380 ;; TODO: should extract baseline-skip from each argument somehow..
382 (def-markup-command (column layout props args) (markup-list?)
383 "Stack the markups in @var{args} vertically. The property
384 @code{baseline-skip} determines the space between each markup in @var{args}."
386 -1 0.0 (chain-assoc-get 'baseline-skip props)
387 (remove ly:stencil-empty?
388 (map (lambda (m) (interpret-markup layout props m)) args))))
390 (def-markup-command (dir-column layout props args) (markup-list?)
391 "Make a column of args, going up or down, depending on the setting
392 of the @code{#'direction} layout property."
393 (let* ((dir (chain-assoc-get 'direction props)))
395 (if (number? dir) dir -1)
397 (chain-assoc-get 'baseline-skip props)
398 (map (lambda (x) (interpret-markup layout props x)) args))))
400 (def-markup-command (center-align layout props args) (markup-list?)
401 "Put @code{args} in a centered column. "
402 (let* ((mols (map (lambda (x) (interpret-markup layout props x)) args))
403 (cmols (map (lambda (x) (ly:stencil-aligned-to x X CENTER)) mols)))
404 (stack-lines -1 0.0 (chain-assoc-get 'baseline-skip props) cmols)))
406 (def-markup-command (vcenter layout props arg) (markup?)
407 "Align @code{arg} to its Y center. "
408 (let* ((mol (interpret-markup layout props arg)))
409 (ly:stencil-aligned-to mol Y CENTER)))
411 (def-markup-command (hcenter layout props arg) (markup?)
412 "Align @code{arg} to its X center. "
413 (let* ((mol (interpret-markup layout props arg)))
414 (ly:stencil-aligned-to mol X CENTER)))
416 (def-markup-command (right-align layout props arg) (markup?)
417 "Align @var{arg} on its right edge. "
418 (let* ((m (interpret-markup layout props arg)))
419 (ly:stencil-aligned-to m X RIGHT)))
421 (def-markup-command (left-align layout props arg) (markup?)
422 "Align @var{arg} on its left edge. "
423 (let* ((m (interpret-markup layout props arg)))
424 (ly:stencil-aligned-to m X LEFT)))
426 (def-markup-command (general-align layout props axis dir arg) (integer? number? markup?)
427 "Align @var{arg} in @var{axis} direction to the @var{dir} side."
428 (let* ((m (interpret-markup layout props arg)))
429 (ly:stencil-aligned-to m axis dir)))
431 (def-markup-command (halign layout props dir arg) (number? markup?)
432 "Set horizontal alignment. If @var{dir} is @code{-1}, then it is
433 left-aligned, while @code{+1} is right. Values in between interpolate
434 alignment accordingly."
435 (let* ((m (interpret-markup layout props arg)))
436 (ly:stencil-aligned-to m X dir)))
439 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
441 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
443 (def-markup-command (fromproperty layout props symbol) (symbol?)
444 "Read the @var{symbol} from property settings, and produce a stencil
445 from the markup contained within. If @var{symbol} is not defined, it
446 returns an empty markup"
447 (let* ((m (chain-assoc-get symbol props)))
449 (interpret-markup layout props m)
450 (ly:make-stencil '() '(1 . -1) '(1 . -1)))))
453 (def-markup-command (on-the-fly layout props procedure arg) (symbol? markup?)
454 "Apply the @var{procedure} markup command to
455 @var{arg}. @var{procedure} should take a single argument."
456 (let* ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
457 (set-object-property! anonymous-with-signature
460 (interpret-markup layout props (list anonymous-with-signature arg))))
464 (def-markup-command (override layout props new-prop arg) (pair? markup?)
465 "Add the first argument in to the property list. Properties may be
466 any sort of property supported by @internalsref{font-interface} and
467 @internalsref{text-interface}, for example
470 \\override #'(font-family . married) \"bla\"
474 (interpret-markup layout (cons (list new-prop) props) arg))
476 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
478 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
481 (def-markup-command (bigger layout props arg) (markup?)
482 "Increase the font size relative to current setting"
483 (interpret-markup layout props
484 `(,fontsize-markup 1 ,arg)))
486 (def-markup-command (smaller layout props arg) (markup?)
487 "Decrease the font size relative to current setting"
488 (interpret-markup layout props
489 `(,fontsize-markup -1 ,arg)))
491 (def-markup-command larger (markup?) bigger-markup)
493 (def-markup-command (finger layout props arg) (markup?)
494 "Set the argument as small numbers."
495 (interpret-markup layout
496 (cons '((font-size . -5) (font-encoding . fetaNumber)) props)
500 (def-markup-command (fontsize layout props increment arg) (number? markup?)
501 "Add @var{increment} to the font-size. Adjust baseline skip accordingly."
503 (let* ((fs (chain-assoc-get 'font-size props 0))
504 (bs (chain-assoc-get 'baseline-skip props 2))
506 (cons 'baseline-skip (* bs (magstep increment)))
507 (cons 'font-size (+ fs increment )))))
509 (interpret-markup layout (cons entries props) arg)))
513 ;; FIXME -> should convert to font-size.
514 (def-markup-command (magnify layout props sz arg) (number? markup?)
515 "Set the font magnification for the its argument. In the following
516 example, the middle A will be 10% larger:
518 A \\magnify #1.1 @{ A @} A
521 Note: magnification only works if a font-name is explicitly selected.
522 Use @code{\\fontsize} otherwise."
525 (prepend-alist-chain 'font-magnification sz props)
528 (def-markup-command (bold layout props arg) (markup?)
529 "Switch to bold font-series"
530 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
532 (def-markup-command (sans layout props arg) (markup?)
533 "Switch to the sans serif family"
534 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
536 (def-markup-command (number layout props arg) (markup?)
537 "Set font family to @code{number}, which yields the font used for
538 time signatures and fingerings. This font only contains numbers and
539 some punctuation. It doesn't have any letters. "
540 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaNumber props) arg))
542 (def-markup-command (roman layout props arg) (markup?)
543 "Set font family to @code{roman}."
544 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
546 (def-markup-command (huge layout props arg) (markup?)
547 "Set font size to +2."
548 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
550 (def-markup-command (large layout props arg) (markup?)
551 "Set font size to +1."
552 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
554 (def-markup-command (normalsize layout props arg) (markup?)
555 "Set font size to default."
556 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
558 (def-markup-command (small layout props arg) (markup?)
559 "Set font size to -1."
560 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
562 (def-markup-command (tiny layout props arg) (markup?)
563 "Set font size to -2."
564 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
566 (def-markup-command (teeny layout props arg) (markup?)
567 "Set font size to -3."
568 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
570 (def-markup-command (caps layout props arg) (markup?)
571 "Set @code{font-shape} to @code{caps}."
572 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
574 ;(def-markup-command (latin-i layout props arg) (markup?)
575 ; "TEST latin1 encoding."
576 ; (interpret-markup layout (prepend-alist-chain 'font-shape 'latin1 props) arg))
578 (def-markup-command (dynamic layout props arg) (markup?)
579 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
580 @b{z}, @b{p}, and @b{r}. When producing phrases, like ``pi@`{u} @b{f}'', the
581 normal words (like ``pi@`{u}'') should be done in a different font. The
582 recommend font for this is bold and italic"
584 layout (prepend-alist-chain 'font-encoding 'fetaDynamic props) arg))
586 (def-markup-command (italic layout props arg) (markup?)
587 "Use italic @code{font-shape} for @var{arg}. "
588 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
590 (def-markup-command (typewriter layout props arg) (markup?)
591 "Use @code{font-family} typewriter for @var{arg}."
593 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
595 (def-markup-command (upright layout props arg) (markup?)
596 "Set font shape to @code{upright}."
598 layout (prepend-alist-chain 'font-shape 'upright props) arg))
601 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
603 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
605 (def-markup-command (doublesharp layout props) ()
606 "Draw a double sharp symbol."
608 (interpret-markup layout props (markup #:musicglyph "accidentals.4")))
610 (def-markup-command (sesquisharp layout props) ()
611 "Draw a 3/2 sharp symbol."
612 (interpret-markup layout props (markup #:musicglyph "accidentals.3")))
614 (def-markup-command (sharp layout props) ()
615 "Draw a sharp symbol."
616 (interpret-markup layout props (markup #:musicglyph "accidentals.2")))
618 (def-markup-command (semisharp layout props) ()
619 "Draw a semi sharp symbol."
620 (interpret-markup layout props (markup #:musicglyph "accidentals.1")))
622 (def-markup-command (natural layout props) ()
623 "Draw a natural symbol."
624 (interpret-markup layout props (markup #:musicglyph "accidentals.0")))
626 (def-markup-command (semiflat layout props) ()
628 (interpret-markup layout props (markup #:musicglyph "accidentals.M1")))
630 (def-markup-command (flat layout props) ()
631 "Draw a flat symbol."
632 (interpret-markup layout props (markup #:musicglyph "accidentals.M2")))
634 (def-markup-command (sesquiflat layout props) ()
635 "Draw a 3/2 flat symbol."
636 (interpret-markup layout props (markup #:musicglyph "accidentals.M3")))
638 (def-markup-command (doubleflat layout props) ()
639 "Draw a double flat symbol."
640 (interpret-markup layout props (markup #:musicglyph "accidentals.M4")))
642 (def-markup-command (with-color layout props color arg) (color? markup?)
643 "Draw @var{arg} in color specified by @var{color}"
645 (let* ((stil (interpret-markup layout props arg)))
647 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
648 (ly:stencil-extent stil X)
649 (ly:stencil-extent stil Y))))
652 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
654 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
656 (def-markup-command (musicglyph layout props glyph-name) (string?)
657 "This is converted to a musical symbol, e.g. @code{\\musicglyph
658 #\"accidentals.0\"} will select the natural sign from the music font.
659 See @usermanref{The Feta font} for a complete listing of the possible glyphs."
661 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
665 (def-markup-command (lookup layout props glyph-name) (string?)
666 "Lookup a glyph by name."
667 (ly:font-get-glyph (ly:paper-get-font layout props)
670 (def-markup-command (char layout props num) (integer?)
671 "Produce a single character, e.g. @code{\\char #65} produces the
673 (ly:get-glyph (ly:paper-get-font layout props) num))
676 (define number->mark-letter-vector (make-vector 25 #\A))
681 (if (= i (- (char->integer #\I) (char->integer #\A)))
683 (vector-set! number->mark-letter-vector j
684 (integer->char (+ i (char->integer #\A)))))
686 (define number->mark-alphabet-vector (list->vector
687 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
689 (define (number->markletter-string vec n)
690 "Double letters for big marks."
691 (let* ((lst (vector-length vec)))
694 (string-append (number->markletter-string vec (1- (quotient n lst)))
695 (number->markletter-string vec (remainder n lst)))
696 (make-string 1 (vector-ref vec n)))))
698 (def-markup-command (markletter layout props num) (integer?)
699 "Make a markup letter for @var{num}. The letters start with A to Z
700 (skipping I), and continues with double letters."
701 (Text_interface::interpret_markup layout props
702 (number->markletter-string number->mark-letter-vector num)))
704 (def-markup-command (markalphabet layout props num) (integer?)
705 "Make a markup letter for @var{num}. The letters start with A to Z
706 and continues with double letters."
707 (Text_interface::interpret_markup layout props
708 (number->markletter-string number->mark-alphabet-vector num)))
710 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
712 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
715 ;; TODO: better syntax.
717 (def-markup-command (note-by-number layout props log dot-count dir) (number? number? number?)
718 "Construct a note symbol, with stem. By using fractional values for
719 @var{dir}, you can obtain longer or shorter stems."
720 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic)) props)))
721 (size (chain-assoc-get 'font-size props 0))
722 (stem-length (* (magstep size) (max 3 (- log 1))))
723 (head-glyph (ly:font-get-glyph
725 (string-append "noteheads.s" (number->string (min log 2)))))
726 (stem-thickness 0.13)
727 (stemy (* dir stem-length))
728 (attachx (if (> dir 0)
729 (- (cdr (ly:stencil-extent head-glyph X)) stem-thickness)
731 (attachy (* dir 0.28))
732 (stem-glyph (and (> log 0)
734 (cons attachx (+ attachx stem-thickness))
735 (cons (min stemy attachy)
737 (/ stem-thickness 3))))
738 (dot (ly:font-get-glyph font "dots.dot"))
739 (dotwid (interval-length (ly:stencil-extent dot X)))
740 (dots (and (> dot-count 0)
741 (apply ly:stencil-add
743 (ly:stencil-translate-axis
744 dot (* (+ 1 (* 2 x)) dotwid) X))
745 (iota dot-count 1)))))
746 (flaggl (and (> log 2)
747 (ly:stencil-translate
748 (ly:font-get-glyph font
749 (string-append "flags."
750 (if (> dir 0) "u" "d")
751 (number->string log)))
752 (cons (+ attachx (/ stem-thickness 2)) stemy)))))
754 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
755 (if (ly:stencil? stem-glyph)
756 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
757 (set! stem-glyph head-glyph))
758 (if (ly:stencil? dots)
761 (ly:stencil-translate-axis
763 (+ (if (and (> dir 0) (> log 2))
766 ;; huh ? why not necessary?
767 ;;(cdr (ly:stencil-extent head-glyph X))
774 (let ((divisor (log 2)))
775 (lambda (z) (inexact->exact (/ (log z) divisor)))))
777 (define (parse-simple-duration duration-string)
778 "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a (log dots) list."
779 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string)))
780 (if (and match (string=? duration-string (match:substring match 0)))
781 (let ((len (match:substring match 1))
782 (dots (match:substring match 2)))
783 (list (cond ((string=? len "breve") -1)
784 ((string=? len "longa") -2)
785 ((string=? len "maxima") -3)
786 (else (log2 (string->number len))))
787 (if dots (string-length dots) 0)))
788 (ly:error (_ "not a valid duration string: ~a") duration-string))))
790 (def-markup-command (note layout props duration dir) (string? number?)
791 "This produces a note with a stem pointing in @var{dir} direction, with
792 the @var{duration} for the note head type and augmentation dots. For
793 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
794 a shortened down stem."
795 (let ((parsed (parse-simple-duration duration)))
796 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
798 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
800 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
802 (def-markup-command (lower layout props amount arg) (number? markup?)
804 Lower @var{arg}, by the distance @var{amount}.
805 A negative @var{amount} indicates raising, see also @code{\raise}.
807 (ly:stencil-translate-axis (interpret-markup layout props arg)
811 (def-markup-command (raise layout props amount arg) (number? markup?)
813 Raise @var{arg}, by the distance @var{amount}.
814 A negative @var{amount} indicates lowering, see also @code{\\lower}.
816 @lilypond[verbatim,fragment,relative=1]
817 c1^\\markup { C \\small \\raise #1.0 \\bold { \"9/7+\" }}
819 The argument to @code{\\raise} is the vertical displacement amount,
820 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
821 raise objects in relation to their surrounding markups.
823 If the text object itself is positioned above or below the staff, then
824 @code{\\raise} cannot be used to move it, since the mechanism that
825 positions it next to the staff cancels any shift made with
826 @code{\\raise}. For vertical positioning, use the @code{padding}
827 and/or @code{extra-offset} properties. "
828 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
830 (def-markup-command (fraction layout props arg1 arg2) (markup? markup?)
831 "Make a fraction of two markups."
832 (let* ((m1 (interpret-markup layout props arg1))
833 (m2 (interpret-markup layout props arg2)))
834 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
835 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
836 (let* ((x1 (ly:stencil-extent m1 X))
837 (x2 (ly:stencil-extent m2 X))
838 (line (ly:round-filled-box (interval-union x1 x2) '(-0.05 . 0.05) 0.0))
839 ;; should stack mols separately, to maintain LINE on baseline
840 (stack (stack-lines -1 0.2 0.6 (list m1 line m2))))
842 (ly:stencil-aligned-to stack Y CENTER))
844 (ly:stencil-aligned-to stack X LEFT))
845 ;; should have EX dimension
847 (ly:stencil-translate-axis stack 0.75 Y))))
853 (def-markup-command (normal-size-super layout props arg) (markup?)
854 "Set @var{arg} in superscript with a normal font size."
855 (ly:stencil-translate-axis
856 (interpret-markup layout props arg)
857 (* 0.5 (chain-assoc-get 'baseline-skip props)) Y))
859 (def-markup-command (super layout props arg) (markup?)
862 @cindex lowering text
864 @cindex translating text
866 @cindex @code{\\super}
869 Raising and lowering texts can be done with @code{\\super} and
872 @lilypond[verbatim,fragment,relative=1]
873 c1^\\markup { E \"=\" mc \\super \"2\" }
877 (ly:stencil-translate-axis
880 (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
882 (* 0.5 (chain-assoc-get 'baseline-skip props))
885 (def-markup-command (translate layout props offset arg) (number-pair? markup?)
886 "This translates an object. Its first argument is a cons of numbers
888 A \\translate #(cons 2 -3) @{ B C @} D
890 This moves `B C' 2 spaces to the right, and 3 down, relative to its
891 surroundings. This command cannot be used to move isolated scripts
892 vertically, for the same reason that @code{\\raise} cannot be used for
896 (ly:stencil-translate (interpret-markup layout props arg)
899 (def-markup-command (sub layout props arg) (markup?)
900 "Set @var{arg} in subscript."
901 (ly:stencil-translate-axis
904 (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
906 (* -0.5 (chain-assoc-get 'baseline-skip props))
909 (def-markup-command (normal-size-sub layout props arg) (markup?)
910 "Set @var{arg} in subscript, in a normal font size."
911 (ly:stencil-translate-axis
912 (interpret-markup layout props arg)
913 (* -0.5 (chain-assoc-get 'baseline-skip props))
916 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
918 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
920 (def-markup-command (hbracket layout props arg) (markup?)
921 "Draw horizontal brackets around @var{arg}."
922 (let ((th 0.1) ;; todo: take from GROB.
923 (m (interpret-markup layout props arg)))
924 (bracketify-stencil m X th (* 2.5 th) th)))
926 (def-markup-command (bracket layout props arg) (markup?)
927 "Draw vertical brackets around @var{arg}."
928 (let ((th 0.1) ;; todo: take from GROB.
929 (m (interpret-markup layout props arg)))
930 (bracketify-stencil m Y th (* 2.5 th) th)))
932 (def-markup-command (bracketed-y-column layout props indices args)
934 "Make a column of the markups in @var{args}, putting brackets around
935 the elements marked in @var{indices}, which is a list of numbers."
936 (define (sublist lst start stop)
937 (take (drop lst start) (- (1+ stop) start)))
939 (define (stencil-list-extent ss axis)
941 (apply min (map (lambda (x) (car (ly:stencil-extent x axis))) ss))
942 (apply max (map (lambda (x) (cdr (ly:stencil-extent x axis))) ss))))
944 (define (stack-stencils stencils bskip last-stencil)
946 ((null? stencils) '())
947 ((not (ly:stencil? last-stencil))
949 (stack-stencils (cdr stencils) bskip (car stencils))))
951 (let* ((orig (car stencils))
952 (dir (chain-assoc-get 'direction props DOWN))
953 (new (ly:stencil-moved-to-edge last-stencil Y dir
957 (cons new (stack-stencils (cdr stencils) bskip new))))))
959 (define (make-brackets stencils indices acc)
962 (pair? (cdr indices)))
963 (let* ((encl (sublist stencils (car indices) (cadr indices)))
964 (x-ext (stencil-list-extent encl X))
965 (y-ext (stencil-list-extent encl Y))
968 (protusion (* 2.5 thick))
970 (ly:stencil-translate-axis
971 (ly:bracket Y y-ext thick protusion)
972 (- (car x-ext) pad) X))
973 (rb (ly:stencil-translate-axis
974 (ly:bracket Y y-ext thick (- protusion))
975 (+ (cdr x-ext) pad) X)))
978 stencils (cddr indices)
991 (chain-assoc-get 'baseline-skip props))
992 (stacked (stack-stencils
993 (remove ly:stencil-empty? stencils) 1.25 #f))
994 (brackets (make-brackets stacked indices '())))
996 (apply ly:stencil-add
997 (append stacked brackets))))