]> git.donarmstrong.com Git - lilypond.git/blob - scm/define-markup-commands.scm
* scm/translation-functions.scm (format-metronome-markup): make
[lilypond.git] / scm / define-markup-commands.scm
1 ;;;; define-markup-commands.scm -- markup commands
2 ;;;;
3 ;;;;  source file of the GNU LilyPond music typesetter
4 ;;;; 
5 ;;;; (c)  2000--2004  Han-Wen Nienhuys <hanwen@cs.uu.nl>
6 ;;;;                  Jan Nieuwenhuizen <janneke@gnu.org>
7
8 ;;; markup commands
9 ;;; TODO:
10 ;;;  * each markup function should have a doc string with
11 ;;     syntax, description and example. 
12
13
14 (def-markup-command (stencil paper props stil) (ly:stencil?)
15   "Stencil as markup"
16   stil)
17
18
19 (def-markup-command (score paper props score) (ly:score?)
20   (let*
21       ((systems (ly:score-embedded-format score paper))
22        (1st (vector-ref systems 0))
23        (stencil (ly:paper-system-stencil 1st)) )
24
25     (ly:stencil-align-to! stencil Y CENTER)
26     (display (ly:stencil-extent stencil X))
27     (display (ly:stencil-extent stencil Y))
28 ;    (set! stencil (ly:stencil-translate-axis stencil -20 X))
29 ;    (set! stencil (ly:stencil-translate-axis stencil 20 Y))
30     stencil))
31
32 (def-markup-command (simple paper props str) (string?)
33   "A simple text string; @code{\\markup @{ foo @}} is equivalent with
34 @code{\\markup @{ \\simple #\"foo\" @}}."
35     (interpret-markup paper props str))
36
37 (def-markup-command (encoded-simple paper props sym str) (symbol? string?)
38   "A text string, encoded with encoding @var{sym}. "
39   (Text_item::interpret_string paper
40                                props sym str))
41
42 ;; TODO: use font recoding.
43 ;;                    (make-line-markup
44 ;;                     (map make-word-markup (string-tokenize str)))))
45
46 (define-public empty-markup
47   (make-simple-markup ""))
48
49 ;;(def-markup-command (fill-line paper props line-width markups)
50 ;;  (number? markup-list?)
51 ;; no parser tag -- should make number? markuk-list? thingy
52 (def-markup-command (fill-line paper props markups)
53   (markup-list?)
54   "Put @var{markups} in a horizontal line of width @var{line-width}.
55    The markups are spaced/flushed to fill the entire line."
56
57   (let* ((stencils (map (lambda (x) (interpret-markup paper props x))
58                         markups))
59          (text-width (apply + (map interval-length
60                                    (map (lambda (x)
61                                           (ly:stencil-extent x X))
62                                         stencils))))
63         (word-count (length markups))
64         (word-space (chain-assoc-get 'word-space props))
65         (line-width (chain-assoc-get 'linewidth props))
66         (fill-space (if (< line-width text-width)
67                         word-space
68                         (/ (- line-width text-width)
69                            (if (= word-count 1) 2 (- word-count 1)))))
70         (line-stencils (if (= word-count 1)
71                            (map (lambda (x) (interpret-markup paper props x))
72                                 (list (make-simple-markup "")
73                                       (make-stencil-markup (car stencils))
74                                       (make-simple-markup "")))
75                                 stencils)))
76     (stack-stencil-line fill-space line-stencils)))
77   
78 (define (font-markup qualifier value)
79   (lambda (paper props arg)
80     (interpret-markup paper
81                       (prepend-alist-chain qualifier value props)
82                       arg)))
83
84 (def-markup-command (line paper props args) (markup-list?)
85   "Put @var{args} in a horizontal line.  The property @code{word-space}
86 determines the space between each markup in @var{args}."
87   (stack-stencil-line
88    (chain-assoc-get 'word-space props)
89    (map (lambda (m) (interpret-markup paper props m)) args)))
90
91 (def-markup-command (combine paper props m1 m2) (markup? markup?)
92   "Print two markups on top of each other."
93   (let*
94       ((s1 (interpret-markup paper props m1))
95        (s2 (interpret-markup paper props m2)))
96              
97     (ly:stencil-add s1 s2)))
98
99 (def-markup-command (finger paper props arg) (markup?)
100   "Set the argument as small numbers."
101   (interpret-markup paper
102                     (cons '((font-size . -5) (font-family . number)) props)
103                     arg))
104
105 (def-markup-command (fontsize paper props mag arg) (number? markup?)
106   "This sets the relative font size, e.g.
107 @example
108 A \\fontsize #2 @{ B C @} D
109 @end example
110
111
112 This will enlarge the B and the C by two steps.
113 "
114   (interpret-markup
115    paper 
116    (prepend-alist-chain 'font-size mag props)
117    arg))
118
119 (def-markup-command (magnify paper props sz arg) (number? markup?)
120   "This sets the font magnification for the its argument. In the following
121 example, the middle A will be 10% larger:
122 @example
123 A \\magnify #1.1 @{ A @} A
124 @end example
125
126 Note: magnification only works if a font-name is explicitly selected.
127 Use @code{\\fontsize} otherwise."
128
129   (interpret-markup
130    paper 
131    (prepend-alist-chain 'font-magnification sz props)
132    arg))
133
134 (def-markup-command (bold paper props arg) (markup?)
135   "Switch to bold font-series"
136   (interpret-markup paper (prepend-alist-chain 'font-series 'bold props) arg))
137
138 (def-markup-command (sans paper props arg) (markup?)
139   "Switch to the sans-serif family"
140   (interpret-markup paper (prepend-alist-chain 'font-family 'sans props) arg))
141
142 (def-markup-command (number paper props arg) (markup?)
143   "Set font family to @code{number}, which yields the font used for
144 time signatures and fingerings.  This font only contains numbers and
145 some punctuation. It doesn't have any letters.  "
146   (interpret-markup paper (prepend-alist-chain 'font-encoding 'fetaNumber props) arg))
147
148 (def-markup-command (roman paper props arg) (markup?)
149   "Set font family to @code{roman}."
150   (interpret-markup paper (prepend-alist-chain 'font-family 'roman props) arg))
151
152 (def-markup-command (huge paper props arg) (markup?)
153   "Set font size to +2."
154   (interpret-markup paper (prepend-alist-chain 'font-size 2 props) arg))
155
156 (def-markup-command (large paper props arg) (markup?)
157   "Set font size to +1."
158   (interpret-markup paper (prepend-alist-chain 'font-size 1 props) arg))
159
160 (def-markup-command (normalsize paper props arg) (markup?)
161   "Set font size to default."
162   (interpret-markup paper (prepend-alist-chain 'font-size 0 props) arg))
163
164 (def-markup-command (small paper props arg) (markup?)
165   "Set font size to -1."
166   (interpret-markup paper (prepend-alist-chain 'font-size -1 props) arg))
167
168 (def-markup-command (tiny paper props arg) (markup?)
169   "Set font size to -2."
170   (interpret-markup paper (prepend-alist-chain 'font-size -2 props) arg))
171
172 (def-markup-command (teeny paper props arg) (markup?)
173   "Set font size to -3."
174   (interpret-markup paper (prepend-alist-chain 'font-size -3 props) arg))
175
176 (def-markup-command (caps paper props arg) (markup?)
177   "Set font shape to @code{caps}."
178   (interpret-markup paper (prepend-alist-chain 'font-shape 'caps props) arg))
179
180 (def-markup-command (latin-i paper props arg) (markup?)
181   "TEST latin1 encoding."
182   (interpret-markup paper (prepend-alist-chain 'font-shape 'latin1 props) arg))
183
184 (def-markup-command (dynamic paper props arg) (markup?)
185   "Use the dynamic font.  This font only contains @b{s}, @b{f}, @b{m},
186 @b{z}, @b{p}, and @b{r}.  When producing phrases, like ``pi@`{u} @b{f}'', the
187 normal words (like ``pi@`{u}'') should be done in a different font.  The
188 recommend font for this is bold and italic"
189   (interpret-markup
190    paper (prepend-alist-chain 'font-encoding 'fetaDynamic props) arg))
191
192 (def-markup-command (italic paper props arg) (markup?)
193   "Use italic @code{font-shape} for @var{arg}. "
194   (interpret-markup paper (prepend-alist-chain 'font-shape 'italic props) arg))
195
196 (def-markup-command (typewriter paper props arg) (markup?)
197   "Use @code{font-family} typewriter for @var{arg}."
198   (interpret-markup
199    paper (prepend-alist-chain 'font-family 'typewriter props) arg))
200
201 (def-markup-command (upright paper props arg) (markup?)
202   "Set font shape to @code{upright}."
203   (interpret-markup
204    paper (prepend-alist-chain 'font-shape 'upright props) arg))
205
206 (def-markup-command (doublesharp paper props) ()
207   "Draw a double sharp symbol."
208
209   (interpret-markup paper props (markup #:musicglyph "accidentals-4")))
210 (def-markup-command (sesquisharp paper props) ()
211   "Draw a 3/2 sharp symbol."
212   (interpret-markup paper props (markup #:musicglyph "accidentals-3")))
213
214 (def-markup-command (sharp paper props) ()
215   "Draw a sharp symbol."
216   (interpret-markup paper props (markup #:musicglyph "accidentals-2")))
217 (def-markup-command (semisharp paper props) ()
218   "Draw a semi sharp symbol."
219   (interpret-markup paper props (markup #:musicglyph "accidentals-1")))
220 (def-markup-command (natural paper props) ()
221   "Draw a natural symbol."
222
223   (interpret-markup paper props (markup #:musicglyph "accidentals-0")))
224 (def-markup-command (semiflat paper props) ()
225   "Draw a semiflat."
226   (interpret-markup paper props (markup #:musicglyph "accidentals--1")))
227 (def-markup-command (flat paper props) ()
228   "Draw a flat symbol."
229   
230   (interpret-markup paper props (markup #:musicglyph "accidentals--2")))
231 (def-markup-command (sesquiflat paper props) ()
232   "Draw a 3/2 flat symbol."
233   
234   (interpret-markup paper props (markup #:musicglyph "accidentals--3")))
235 (def-markup-command (doubleflat paper props) ()
236   "Draw a double flat symbol."
237
238   (interpret-markup paper props (markup #:musicglyph "accidentals--4")))
239
240
241 (def-markup-command (column paper props args) (markup-list?)
242   "Stack the markups in @var{args} vertically."
243   (stack-lines
244    -1 0.0 (chain-assoc-get 'baseline-skip props)
245    (map (lambda (m) (interpret-markup paper props m)) args)))
246
247 (def-markup-command (dir-column paper props args) (markup-list?)
248   "Make a column of args, going up or down, depending on the setting
249 of the @code{#'direction} layout property."
250   (let* ((dir (chain-assoc-get 'direction props)))
251     (stack-lines
252      (if (number? dir) dir -1)
253      0.0
254       (chain-assoc-get 'baseline-skip props)
255      (map (lambda (x) (interpret-markup paper props x)) args))))
256
257 (def-markup-command (center-align paper props args) (markup-list?)
258   "Put @code{args} in a centered column. "
259   (let* ((mols (map (lambda (x) (interpret-markup paper props x)) args))
260          (cmols (map (lambda (x) (ly:stencil-align-to! x X CENTER)) mols)))
261     (stack-lines -1 0.0 (chain-assoc-get 'baseline-skip props) mols)))
262
263 (def-markup-command (vcenter paper props arg) (markup?)
264   "Align @code{arg} to its center. "
265   (let* ((mol (interpret-markup paper props arg)))
266     (ly:stencil-align-to! mol Y CENTER)
267     mol))
268
269 (def-markup-command (right-align paper props arg) (markup?)
270   (let* ((m (interpret-markup paper props arg)))
271     (ly:stencil-align-to! m X RIGHT)
272     m))
273
274 (def-markup-command (left-align paper props arg) (markup?)
275   "Align @var{arg} on its left edge. "
276   
277   (let* ((m (interpret-markup paper props arg)))
278     (ly:stencil-align-to! m X LEFT)
279     m))
280
281 (def-markup-command (general-align paper props axis dir arg)  (integer? number? markup?)
282   "Align @var{arg} in @var{axis} direction to the @var{dir} side."
283   (let* ((m (interpret-markup paper props arg)))
284
285     (ly:stencil-align-to! m axis dir)
286     m
287   ))
288
289 (def-markup-command (halign paper props dir arg) (number? markup?)
290   "Set horizontal alignment. If @var{dir} is -1, then it is
291 left-aligned, while+1 is right. Values in between interpolate alignment
292 accordingly."
293
294   
295   (let* ((m (interpret-markup paper props arg)))
296     (ly:stencil-align-to! m X dir)
297     m))
298
299 (def-markup-command (musicglyph paper props glyph-name) (string?)
300   "This is converted to a musical symbol, e.g. @code{\\musicglyph
301 #\"accidentals-0\"} will select the natural sign from the music font.
302 See @usermanref{The Feta font} for  a complete listing of the possible glyphs.
303 "
304   (ly:find-glyph-by-name
305    (ly:paper-get-font paper (cons '((font-encoding . fetaMusic))
306                                   props))
307    glyph-name))
308
309
310 (def-markup-command (lookup paper props glyph-name) (string?)
311   "Lookup a glyph by name."
312   (ly:find-glyph-by-name (ly:paper-get-font paper props)
313                          glyph-name))
314
315 (def-markup-command (char paper props num) (integer?)
316   "This produces a single character, e.g. @code{\\char #65} produces the 
317 letter 'A'."
318   (ly:get-glyph (ly:paper-get-font paper props) num))
319
320 (def-markup-command (raise paper props amount arg) (number? markup?)
321   "
322 This  raises  @var{arg}, by the distance @var{amount}.
323 A negative @var{amount} indicates lowering:
324 @c
325 @lilypond[verbatim,fragment,relative=1]
326  c1^\\markup { C \\small \\raise #1.0 \\bold { \"9/7+\" }}
327 @end lilypond
328 The argument to @code{\\raise} is the vertical displacement amount,
329 measured in (global) staff spaces.  @code{\\raise} and @code{\\super}
330 raise objects in relation to their surrounding markups.
331
332 If the text object itself is positioned above or below the staff, then
333 @code{\\raise} cannot be used to move it, since the mechanism that
334 positions it next to the staff cancels any shift made with
335 @code{\\raise}. For vertical positioning, use the @code{padding}
336 and/or @code{extra-offset} properties. "
337
338   
339   (ly:stencil-translate-axis (interpret-markup paper props arg)
340                               amount Y))
341
342 (def-markup-command (fraction paper props arg1 arg2) (markup? markup?)
343   "Make a fraction of two markups."
344   
345   (let* ((m1 (interpret-markup paper props arg1))
346          (m2 (interpret-markup paper props arg2)))
347     (ly:stencil-align-to! m1 X CENTER)
348     (ly:stencil-align-to! m2 X CENTER)    
349     (let* ((x1 (ly:stencil-extent m1 X))
350            (x2 (ly:stencil-extent m2 X))
351            (line (ly:round-filled-box (interval-union x1 x2) '(-0.05 . 0.05) 0.0))
352            ;; should stack mols separately, to maintain LINE on baseline
353            (stack (stack-lines -1 0.2 0.6 (list m1 line m2))))
354       (ly:stencil-align-to! stack Y CENTER)
355       (ly:stencil-align-to! stack X LEFT)
356       ;; should have EX dimension
357       ;; empirical anyway
358       (ly:stencil-translate-axis stack 0.75 Y))))
359
360
361 ;; TODO: better syntax.
362
363 (def-markup-command (note-by-number paper props log dot-count dir) (number? number? number?)
364   "Construct a note symbol, with stem.  By using fractional values for
365 @var{dir}, you can obtain longer or shorter stems."
366   
367   (let* ((font (ly:paper-get-font paper (cons '((font-encoding . fetaMusic)) props)))
368          (stemlen (max 3 (- log 1)))
369          (headgl (ly:find-glyph-by-name
370                   font
371                   (string-append "noteheads-" (number->string (min log 2)))))
372          (stemth 0.13)
373          (stemy (* dir stemlen))
374          (attachx (if (> dir 0)
375                       (- (cdr (ly:stencil-extent headgl X)) stemth)
376                       0))
377          (attachy (* dir 0.28))
378          (stemgl (and (> log 0)
379                       (ly:round-filled-box
380                        (cons attachx (+ attachx  stemth))
381                        (cons (min stemy attachy)
382                              (max stemy attachy))
383                        (/ stemth 3))))
384          (dot (ly:find-glyph-by-name font "dots-dot"))
385          (dotwid (interval-length (ly:stencil-extent dot X)))
386          (dots (and (> dot-count 0)
387                     (apply ly:stencil-add
388                            (map (lambda (x)
389                                   (ly:stencil-translate-axis
390                                    dot  (* (+ 1 (* 2 x)) dotwid) X) )
391                                 (iota dot-count 1)))))
392          (flaggl (and (> log 2)
393                       (ly:stencil-translate
394                        (ly:find-glyph-by-name font
395                                               (string-append "flags-"
396                                                              (if (> dir 0) "u" "d")
397                                                              (number->string log)))
398                        (cons (+ attachx (/ stemth 2)) stemy)))))
399     (if flaggl
400         (set! stemgl (ly:stencil-add flaggl stemgl)))
401     (if (ly:stencil? stemgl)
402         (set! stemgl (ly:stencil-add stemgl headgl))
403         (set! stemgl headgl))
404     (if (ly:stencil? dots)
405         (set! stemgl
406               (ly:stencil-add
407                (ly:stencil-translate-axis dots
408                                            (+ (if (and (> dir 0) (> log 2))
409                                                   (* 1.5 dotwid)
410                                                   0)
411                                               ;; huh ? why not necessary?
412                                               ;;(cdr (ly:stencil-extent headgl X))
413                                               dotwid)
414                                            X)
415                stemgl)))
416     stemgl))
417
418 (use-modules (ice-9 regex))
419
420 (define-public log2 
421   (let ((divisor (log 2)))
422     (lambda (z) (inexact->exact (/ (log z) divisor)))))
423
424 (define (parse-simple-duration duration-string)
425   "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a (log dots) list."
426   (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string)))
427     (if (and match (string=? duration-string (match:substring match 0)))
428         (let ((len  (match:substring match 1))
429               (dots (match:substring match 2)))
430           (list (cond ((string=? len "breve")  -1)
431                       ((string=? len "longa")  -2)
432                       ((string=? len "maxima") -3)
433                       (else (log2 (string->number len))))
434                 (if dots (string-length dots) 0)))
435         (error "This is not a valid duration string:" duration-string))))
436
437 (def-markup-command (note paper props duration dir) (string? number?)
438   "This produces a note with a stem pointing in @var{dir} direction, with
439 the @var{duration} for the note head type and augmentation dots. For
440 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
441 a shortened down stem."
442   
443   (let ((parsed (parse-simple-duration duration)))
444     (note-by-number-markup paper props (car parsed) (cadr parsed) dir)))
445
446 (def-markup-command (normal-size-super paper props arg) (markup?)
447   "A superscript which does not use a smaller font."
448   
449   (ly:stencil-translate-axis (interpret-markup
450                                paper
451                                props arg)
452                               (* 0.5  (chain-assoc-get 'baseline-skip props))
453                               Y))
454
455 (def-markup-command (super paper props arg) (markup?)
456   "
457 @cindex raising text
458 @cindex lowering text
459 @cindex moving text
460 @cindex translating text
461
462 @cindex @code{\\super}
463
464
465 Raising and lowering texts can be done with @code{\\super} and
466 @code{\\sub}:
467
468 @lilypond[verbatim,fragment,relative=1]
469  c1^\\markup { E \"=\" mc \\super \"2\" }
470 @end lilypond
471
472 "
473   
474   (ly:stencil-translate-axis
475    (interpret-markup
476     paper
477     (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
478     arg)
479    (* 0.5 (chain-assoc-get 'baseline-skip props))
480    Y))
481
482 (def-markup-command (translate paper props offset arg) (number-pair? markup?)
483   "This translates an object. Its first argument is a cons of numbers
484 @example
485 A \\translate #(cons 2 -3) @{ B C @} D
486 @end example
487 This moves `B C' 2 spaces to the right, and 3 down, relative to its
488 surroundings. This command cannot be used to move isolated scripts
489 vertically, for the same reason that @code{\\raise} cannot be used for
490 that.
491
492 . "
493   (ly:stencil-translate (interpret-markup  paper props arg)
494                          offset))
495
496 (def-markup-command (sub paper props arg) (markup?)
497   "Set @var{arg} in subscript."
498   
499   (ly:stencil-translate-axis
500    (interpret-markup
501     paper
502     (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
503     arg)
504    (* -0.5 (chain-assoc-get 'baseline-skip props))
505    Y))
506
507 (def-markup-command (normal-size-sub paper props arg) (markup?)
508   "Set @var{arg} in subscript, in a normal font size."
509
510   (ly:stencil-translate-axis
511    (interpret-markup paper props arg)
512    (* -0.5 (chain-assoc-get 'baseline-skip props))
513    Y))
514
515 (def-markup-command (hbracket paper props arg) (markup?)
516   "Draw horizontal brackets around @var{arg}."  
517   (let ((th 0.1) ;; todo: take from GROB.
518         (m (interpret-markup paper props arg)))
519     (bracketify-stencil m X th (* 2.5 th) th)))
520
521 (def-markup-command (bracket paper props arg) (markup?)
522   "Draw vertical brackets around @var{arg}."  
523   (let ((th 0.1) ;; todo: take from GROB.
524         (m (interpret-markup paper props arg)))
525     (bracketify-stencil m Y th (* 2.5 th) th)))
526
527 ;; todo: fix negative space
528 (def-markup-command (hspace paper props amount) (number?)
529   "This produces a invisible object taking horizontal space.
530 @example 
531 \\markup @{ A \\hspace #2.0 B @} 
532 @end example
533 will put extra space between A and B, on top of the space that is
534 normally inserted before elements on a line.
535 "
536   (if (> amount 0)
537       (ly:make-stencil "" (cons 0 amount) '(-1 . 1) )
538       (ly:make-stencil "" (cons amount amount) '(-1 . 1))))
539
540 (def-markup-command (override paper props new-prop arg) (pair? markup?)
541   "Add the first argument in to the property list.  Properties may be
542 any sort of property supported by @internalsref{font-interface} and
543 @internalsref{text-interface}, for example
544
545 @verbatim
546 \\override #'(font-family . married) \"bla\"
547 @end verbatim
548
549 "
550   (interpret-markup paper (cons (list new-prop) props) arg))
551
552 (def-markup-command (smaller paper props arg) (markup?)
553   "Decrease the font size relative to current setting"
554   (let* ((fs (chain-assoc-get 'font-size props 0))
555          (entry (cons 'font-size (- fs 1))))
556     (interpret-markup paper (cons (list entry) props) arg)))
557
558
559 (def-markup-command (bigger paper props arg) (markup?)
560   "Increase the font size relative to current setting"
561   (let* ((fs (chain-assoc-get 'font-size props 0))
562          (entry (cons 'font-size (+ fs 1))))
563     (interpret-markup paper (cons (list entry) props) arg)))
564
565 (def-markup-command larger (markup?)
566   bigger-markup)
567
568 (def-markup-command (box paper props arg) (markup?)
569   "Draw a box round @var{arg}"
570   
571   (let ((th 0.1)
572         (pad 0.2)
573         (m (interpret-markup paper props arg)))
574     (box-stencil m th pad)))
575
576 (def-markup-command (strut paper props) ()
577   
578   "Create a box of the same height as the space in the current font.
579
580 FIXME: is this working? 
581 "
582   
583   (let ((m (Text_item::interpret_markup paper props " ")))
584     (ly:stencil-set-extent! m X '(1000 . -1000))
585     m))
586
587 (define number->mark-letter-vector (make-vector 25 #\A))
588
589 (do ((i 0 (1+ i))
590      (j 0 (1+ j)))
591     ((>= i 26))
592   (if (= i (- (char->integer #\I) (char->integer #\A)))
593       (set! i (1+ i)))
594   (vector-set! number->mark-letter-vector j
595                (integer->char (+ i (char->integer #\A)))))
596
597 (define (number->markletter-string n)
598   "Double letters for big marks."
599   (let*
600       ((l (vector-length number->mark-letter-vector)))
601     
602   (if (>= n l)
603       (string-append (number->markletter-string (1- (quotient n l)))
604                      (number->markletter-string (remainder n l)))
605       (make-string 1 (vector-ref number->mark-letter-vector n)))))
606
607
608 (def-markup-command (markletter paper props num) (integer?)
609    "Make a markup letter for @var{num}.  The letters start with A to Z
610  (skipping I), and continues with double letters."
611  
612    (Text_item::interpret_markup paper props (number->markletter-string num)))
613
614
615
616
617 (def-markup-command (bracketed-y-column paper props indices args)
618   (list? markup-list?)
619   "Make a column of the markups in @var{args}, putting brackets around
620 the elements marked in @var{indices}, which is a list of numbers."
621
622     (define (sublist l start stop)
623     (take (drop l start)  (- (1+ stop) start)) )
624
625   (define (stencil-list-extent ss axis)
626     (cons
627      (apply min (map (lambda (x) (car (ly:stencil-extent x axis))) ss))
628      (apply max (map (lambda (x) (cdr (ly:stencil-extent x axis))) ss))))
629             
630   (define (stack-stencils stencils bskip last-stencil)
631     (cond
632      ((null? stencils) '())
633      ((not last-stencil)
634       (cons (car stencils)
635             (stack-stencils (cdr stencils) bskip (car stencils))))
636      (else
637       (let*
638           ((orig (car stencils))
639            (dir (chain-assoc-get 'direction  props DOWN))
640            (new (ly:stencil-moved-to-edge last-stencil Y dir
641                                           orig
642                                           0.1 bskip))
643            )
644
645         (cons new (stack-stencils (cdr stencils) bskip new))))
646     ))
647
648   (define (make-brackets stencils indices acc)
649     (if (and stencils
650              (pair? indices)
651              (pair? (cdr indices)))
652         (let*
653             ((encl (sublist stencils (car indices) (cadr indices)))
654              (x-ext (stencil-list-extent encl X))
655              (y-ext (stencil-list-extent encl Y))
656              (thick 0.10)
657              (pad 0.35)
658              (protusion (* 2.5 thick))
659              (lb
660               (ly:stencil-translate-axis 
661                (ly:bracket Y y-ext thick protusion)
662                (- (car x-ext) pad) X))
663              (rb (ly:stencil-translate-axis
664                   (ly:bracket Y y-ext thick (- protusion))
665                   (+ (cdr x-ext) pad) X))
666              )
667
668           (make-brackets
669            stencils (cddr indices)
670            (append
671             (list lb rb)
672              acc)))
673         acc))
674
675   (let*
676       ((stencils
677         (map (lambda (x)
678                (interpret-markup
679                 paper
680                 props
681                 x)) args))
682        (leading
683          (chain-assoc-get 'baseline-skip props))
684        (stacked (stack-stencils stencils 1.25 #f))
685        (brackets (make-brackets stacked indices '()))
686        )
687
688     (apply ly:stencil-add
689            (append stacked brackets)
690            )))
691
692
693              
694
695   
696   
697
698