1 ; lily.scm -- implement Scheme output routines for TeX and PostScript
3 ; source file of the GNU LilyPond music typesetter
5 ; (c) 1998 Jan Nieuwenhuizen <janneke@gnu.org>
8 ;(debug-enable 'backtrace)
12 (use-modules (ice-9 regex))
14 ;; do nothing in .scm output
15 (define (comment s) "")
21 (define (cons-map f x)
22 (cons (f (car x)) (f (cdr x))))
24 (define (reduce operator list)
25 (if (null? (cdr list)) (car list)
26 (operator (car list) (reduce operator (cdr list)))
30 (define (glue-2-strings a b)
31 (string-append a " " b))
33 (define (numbers->string l)
34 (reduce glue-2-strings (map number->string l)))
36 (define (chop-decimal x) (if (< (abs x) 0.001) 0.0 x))
38 (define (number->octal-string x)
39 (let* ((n (inexact->exact x))
41 (n8 (quotient (- n (* n64 64)) 8)))
45 (number->string (remainder (- n (+ (* n64 64) (* n8 8))) 8)))))
47 (define (inexact->string x radix)
48 (let ((n (inexact->exact x)))
49 (number->string n radix)))
55 (string-append (number->string (car c)) " ")
56 (string-append (number->string (cdr c)) " ")))
62 (make-string 1 (integer->char (+ (char->integer #\A) i)))
67 (define (scm-scm action-name)
70 (define security-paranoia #f)
73 ;; See documentation of Item::visibility_lambda_
74 (define (postbreak-only-visibility d) (if (= d 1) '(#f . #f) '(#t . #t)))
75 (define (spanbar-non-postbreak-visibility d) (if (= d -1) '(#t . #t) '(#f . #f)))
76 (define (all-visibility d) '(#f . #f))
77 (define (non-postbreak-visibility d) (if (= d 1) '(#t . #t) '(#f . #f)))
78 (define (non-prebreak-visibility d) (if (= d -1) '(#t . #t) '(#f . #f)))
81 ;; Score_span_bars are only visible at start of line
82 ;; i.e. if break_dir == RIGHT == 1
83 (define Span_bar_engraver-visibility non-postbreak-visibility)
84 (define Base_span_bar_engraver-visibility non-postbreak-visibility)
85 (define mark-visibility non-prebreak-visibility)
86 (define Span_score_bar_engraver-visibility postbreak-only-visibility)
87 (define Piano_bar_engraver-visibility postbreak-only-visibility)
88 (define Staff_group_bar_engraver-visibility postbreak-only-visibility)
90 ;; Spacing constants for prefatory matter.
92 ;; rules for this spacing are much more complicated than this. See [Wanske] page 126 -- 134, [Ross] pg 143 -- 147
96 ;; (Measured in staff space)
99 (("" "Clef_item") . (minimum-space 1.0))
100 (("" "Staff_bar") . (minimum-space 0.0))
101 (("" "Clef_item") . (minimum-space 1.0))
102 (("" "Key_item") . (minimum-space 0.5))
103 (("" "Span_bar") . (extra-space 0.0))
104 (("" "Time_signature") . (extra-space 0.0))
105 (("" "begin-of-note") . (minimum-space 1.5))
106 (("Clef_item" "Key_item") . (minimum-space 4.0))
107 (("Key_item" "Time_signature") . (extra-space 1.0))
108 (("Clef_item" "Time_signature") . (minimum-space 3.5))
109 (("Staff_bar" "Clef_item") . (minimum-space 1.0))
110 (("Clef_item" "Staff_bar") . (minimum-space 3.7))
111 (("Time_signature" "Staff_bar") . (minimum-space 2.0))
112 (("Key_item" "Staff_bar") . (extra-space 1.0))
113 (("Span_bar" "Clef_item") . (extra-space 1.0))
114 (("Clef_item" "Span_bar") . (minimum-space 3.7))
115 (("Time_signature" "Span_bar") . (minimum-space 2.0))
116 (("Key_item" "Span_bar") . (minimum-space 2.5))
117 (("Staff_bar" "Time_signature") . (minimum-space 1.5)) ;double check this.
118 (("Time_signature" "begin-of-note") . (extra-space 2.0)) ;double check this.
119 (("Key_item" "begin-of-note") . (extra-space 2.5))
120 (("Staff_bar" "begin-of-note") . (extra-space 1.0))
121 (("Clef_item" "begin-of-note") . (minimum-space 5.0))
122 (("" "Breathing_sign") . (minimum-space 0.0))
123 (("Breathing_sign" "Key_item") . (minimum-space 1.5))
124 (("Breathing_sign" "begin-of-note") . (minimum-space 1.0))
125 (("Breathing_sign" "Staff_bar") . (minimum-space 1.5))
126 (("Breathing_sign" "Clef_item") . (minimum-space 2.0))
130 (define (break-align-spacer this next)
131 (let ((entry (assoc `(,this ,next) space-alist)))
134 (begin (ly-warn (string-append "Unknown spacing pair `" this "', `" next "'"))
135 '(minimum-space 0.0)))))
141 ;; this is silly, can't we use something like
142 ;; roman-0, roman-1 roman+1 ?
145 ("brace" . "feta-braces")
146 ("default" . "cmr10")
147 ("dynamic" . "feta-din")
151 ("finger" . "feta-nummer")
152 ("typewriter" . "cmtt")
158 ("mark" . "feta-nummer")
159 ("number" . "feta-nummer")
160 ("volta" . "feta-nummer"))
163 (define (string-encode-integer i)
166 ((< i 0) (string-append "n" (string-encode-integer (- i))))
168 (make-string 1 (integer->char (+ 65 (modulo i 26))))
169 (string-encode-integer (quotient i 26))
176 (cdr (assoc i '((-4 . 482)
189 (define script-alist '())
190 (define (articulation-to-scriptdef a)
191 (assoc a script-alist)
194 ;; Map style names to TeX font names. Return false if
195 ;; no font name found.
196 (define (style-to-cmr s)
202 (define font-name-alist '())
203 (define (font-command name-mag)
205 (string-append "magfont"
206 (string-encode-integer (hashq (car name-mag) 1000000))
208 (string-encode-integer (cdr name-mag)))
212 (define (define-fonts names)
213 (set! font-name-alist (map font-command names))
216 (font-load-command (car x) (cdr x))) font-name-alist)
220 (define (tex-scm action-name)
225 (define (select-font font-name-symbol)
228 (c (assoc font-name-symbol font-name-alist))
233 (ly-warn (string-append
234 "Programming error: No such font known " (car font-name-symbol)))
235 "") ; issue no command
236 (string-append "\\" (cdr c)))
241 (define (beam width slope thick)
242 (embedded-ps ((ps-scm 'beam) width slope thick)))
244 (define (bracket arch_angle arch_width arch_height width height arch_thick thick)
245 (embedded-ps ((ps-scm 'bracket) arch_angle arch_width arch_height width height arch_thick thick)))
247 (define (dashed-slur thick dash l)
248 (embedded-ps ((ps-scm 'dashed-slur) thick dash l)))
250 (define (crescendo thick w h cont)
251 (embedded-ps ((ps-scm 'crescendo) thick w h cont)))
254 (string-append "\\char" (inexact->string i 10) " "))
256 (define (decrescendo thick w h cont)
257 (embedded-ps ((ps-scm 'decrescendo) thick w h cont)))
259 ;This sets CTM so that you get to the currentpoint
260 ; by executing a 0 0 moveto
265 (define (font-load-command name-mag command)
267 "\\font\\" command "="
268 (symbol->string (car name-mag))
270 (number->string (magstep (cdr name-mag)))
274 (define (embedded-ps s)
275 (string-append "\\embeddedps{" s "}"))
278 (string-append "% " s))
281 "\n\\EndLilyPondOutput")
283 (define (experimental-on)
286 (define (font-switch i)
290 (define (font-def i s)
292 "\\font" (font-switch i) "=" s "\n"))
298 ;(ly-gulp-file "lily.ps")
300 (regexp-substitute/global #f "\n" (ly-gulp-file "lily.ps") 'pre " %\n" 'post)
302 "\\input lilyponddefs \\turnOnPostScript"))
304 (define (header creator generate)
306 "%created by: " creator generate "\n"))
308 (define (invoke-char s i)
310 "\n\\" s "{" (inexact->string i 10) "}" ))
312 (define (invoke-dim1 s d)
314 "\n\\" s "{" (number->dim d) "}"))
319 ;; need to do something to make this really safe.
321 (define (output-tex-string s)
322 (if security-paranoia
323 (regexp-substitute/global #f "\\\\" s 'pre "$\\backslash$" 'post)
326 (define (lily-def key val)
330 (regexp-substitute/global #f "_" (output-tex-string key) 'pre "X" 'post)
331 ;(output-tex-string key)
332 "{" (output-tex-string val) "}\n"))
334 (define (number->dim x)
336 (number->string (chop-decimal x)) " pt "))
338 (define (placebox x y s)
341 (number->dim y) "}{" (number->dim x) "}{" s "}\n"))
343 (define (bezier-sandwich l thick)
344 (embedded-ps ((ps-scm 'bezier-sandwich) l thick)))
346 (define (start-line ht)
347 (string-append"\\vbox to " (number->dim ht) "{\\hbox{%\n"))
350 "}\\vss}\\interscoreline")
351 (define (stop-last-line)
353 (define (filledbox breapth width depth height)
355 "\\kern" (number->dim (- breapth))
356 "\\vrule width " (number->dim (+ breapth width))
357 "depth " (number->dim depth)
358 "height " (number->dim height) " "))
361 (string-append "\\hbox{" (output-tex-string s) "}"))
363 (define (tuplet ht gapx dx dy thick dir)
364 (embedded-ps ((ps-scm 'tuplet) ht gapx dx dy thick dir)))
366 (define (volta h w thick vert_start vert_end)
367 (embedded-ps ((ps-scm 'volta) h w thick vert_start vert_end)))
370 ;; The procedures listed below form the public interface of TeX-scm.
371 ;; (should merge the 2 lists)
372 (cond ((eq? action-name 'all-definitions)
374 (define font-load-command ,font-load-command)
376 (define bezier-sandwich ,bezier-sandwich)
377 (define bracket ,bracket)
379 (define crescendo ,crescendo)
380 (define dashed-slur ,dashed-slur)
381 (define decrescendo ,decrescendo)
382 (define end-output ,end-output)
383 (define experimental-on ,experimental-on)
384 (define filledbox ,filledbox)
385 (define font-def ,font-def)
386 (define font-switch ,font-switch)
387 (define header-end ,header-end)
388 (define lily-def ,lily-def)
389 (define header ,header)
390 (define invoke-char ,invoke-char)
391 (define invoke-dim1 ,invoke-dim1)
392 (define placebox ,placebox)
393 (define select-font ,select-font)
394 (define start-line ,start-line)
395 (define stop-line ,stop-line)
396 (define stop-last-line ,stop-last-line)
398 (define tuplet ,tuplet)
399 (define volta ,volta)
402 ((eq? action-name 'beam) beam)
403 ((eq? action-name 'tuplet) tuplet)
404 ((eq? action-name 'bracket) bracket)
405 ((eq? action-name 'crescendo) crescendo)
406 ((eq? action-name 'dashed-slur) dashed-slur)
407 ((eq? action-name 'decrescendo) decrescendo)
408 ((eq? action-name 'end-output) end-output)
409 ((eq? action-name 'experimental-on) experimental-on)
410 ((eq? action-name 'font-def) font-def)
411 ((eq? action-name 'font-switch) font-switch)
412 ((eq? action-name 'header-end) header-end)
413 ((eq? action-name 'lily-def) lily-def)
414 ((eq? action-name 'header) header)
415 ((eq? action-name 'invoke-char) invoke-char)
416 ((eq? action-name 'invoke-dim1) invoke-dim1)
417 ((eq? action-name 'placebox) placebox)
418 ((eq? action-name 'bezier-sandwich) bezier-sandwich)
419 ((eq? action-name 'start-line) start-line)
420 ((eq? action-name 'stem) stem)
421 ((eq? action-name 'stop-line) stop-line)
422 ((eq? action-name 'stop-last-line) stop-last-line)
423 ((eq? action-name 'volta) volta)
424 (else (error "unknown tag -- PS-TEX " action-name))
430 (define (ps-scm action-name)
433 ;; alist containing fontname -> fontcommand assoc (both strings)
434 (define font-alist '())
435 (define font-count 0)
436 (define current-font "")
439 (define (cached-fontname i)
442 (make-string 1 (integer->char (+ 65 i)))))
444 (define (mag-to-size m)
445 (number->string (case m
448 (2 14) ; really: 14.400
449 (3 17) ; really: 17.280
450 (4 21) ; really: 20.736
451 (5 24) ; really: 24.888
452 (6 30) ; really: 29.856
456 (define (select-font font-name-symbol)
459 (c (assoc font-name-symbol font-name-alist))
464 (ly-warn (string-append
465 "Programming error: No such font known " (car font-name-symbol)))
466 "") ; issue no command
467 (string-append " " (cdr c) " "))
472 (define (font-load-command name-mag command)
476 (symbol->string (car name-mag))
478 (number->string (magstep (cdr name-mag)))
479 " 1000 div 12 mul scalefont setfont } bind def "
483 (define (beam width slope thick)
485 (numbers->string (list width slope thick)) " draw_beam" ))
488 (string-append "% " s))
490 (define (bracket arch_angle arch_width arch_height width height arch_thick thick)
492 (numbers->string (list arch_angle arch_width arch_height width height arch_thick thick)) " draw_bracket" ))
495 (invoke-char " show" i))
497 (define (crescendo thick w h cont )
499 (numbers->string (list w h (inexact->exact cont) thick))
502 ;; what the heck is this interface ?
503 (define (dashed-slur thick dash l)
505 (apply string-append (map control->string l))
506 (number->string thick)
508 (number->string dash)
510 (number->string (* 10 thick)) ;UGH. 10 ?
511 " ] 0 draw_dashed_slur"))
513 (define (decrescendo thick w h cont)
515 (numbers->string (list w h (inexact->exact cont) thick))
516 " draw_decrescendo"))
522 (define (experimental-on) "")
524 (define (filledbox breapth width depth height)
525 (string-append (numbers->string (list breapth width depth height))
529 (define (font-def i s)
532 (substring s 0 (- (string-length s) 4))
533 " findfont 12 scalefont setfont} bind def \n"))
535 (define (font-switch i)
536 (string-append (font i) " "))
540 (ly-gulp-file "lilyponddefs.ps")
541 " {exch pop //systemdict /run get exec} "
542 (ly-gulp-file "lily.ps")
543 "{ exch pop //systemdict /run get exec } "
546 (define (lily-def key val)
548 (if (string=? (substring key 0 (min (string-length "mudelapaper") (string-length key))) "mudelapaper")
549 (string-append "/" key " {" val "} bind def\n")
550 (string-append "/" key " (" val ") def\n")
554 (define (header creator generate)
557 "%%Creator: " creator generate "\n"))
559 (define (invoke-char s i)
561 "(\\" (inexact->string i 8) ") " s " " ))
563 (define (invoke-dim1 s d)
565 (number->string (* d (/ 72.27 72))) " " s ))
567 (define (placebox x y s)
569 (number->string x) " " (number->string y) " {" s "} placebox "))
571 (define (bezier-sandwich l thick)
573 (apply string-append (map control->string l))
574 (number->string thick)
575 " draw_bezier_sandwich"))
577 (define (start-line height)
580 (define (stem breapth width depth height)
581 (string-append (numbers->string (list breapth width depth height))
588 (string-append "(" s ") show "))
591 (define (volta h w thick vert_start vert_end)
593 (numbers->string (list h w thick (inexact->exact vert_start) (inexact->exact vert_end)))
596 (define (tuplet ht gap dx dy thick dir)
598 (numbers->string (list ht gap dx dy thick (inexact->exact dir)))
607 (cond ((eq? action-name 'all-definitions)
610 (define tuplet ,tuplet)
611 (define bracket ,bracket)
613 (define crescendo ,crescendo)
614 (define volta ,volta)
615 (define bezier-sandwich ,bezier-sandwich)
616 (define dashed-slur ,dashed-slur)
617 (define decrescendo ,decrescendo)
618 (define end-output ,end-output)
619 (define experimental-on ,experimental-on)
620 (define filledbox ,filledbox)
621 (define font-def ,font-def)
622 (define font-switch ,font-switch)
623 (define header-end ,header-end)
624 (define lily-def ,lily-def)
625 (define font-load-command ,font-load-command)
626 (define header ,header)
627 (define invoke-char ,invoke-char)
628 (define invoke-dim1 ,invoke-dim1)
629 (define placebox ,placebox)
630 (define select-font ,select-font)
631 (define start-line ,start-line)
633 (define stop-line ,stop-line)
634 (define stop-last-line ,stop-line)
637 ((eq? action-name 'tuplet) tuplet)
638 ((eq? action-name 'beam) beam)
639 ((eq? action-name 'bezier-sandwich) bezier-sandwich)
640 ((eq? action-name 'bracket) bracket)
641 ((eq? action-name 'char) char)
642 ((eq? action-name 'crescendo) crescendo)
643 ((eq? action-name 'dashed-slur) dashed-slur)
644 ((eq? action-name 'decrescendo) decrescendo)
645 ((eq? action-name 'experimental-on) experimental-on)
646 ((eq? action-name 'filledbox) filledbox)
647 ((eq? action-name 'select-font) select-font)
648 ((eq? action-name 'volta) volta)
649 (else (error "unknown tag -- PS-SCM " action-name))
654 (define (arg->string arg)
655 (cond ((number? arg) (inexact->string arg 10))
656 ((string? arg) (string-append "\"" arg "\""))
657 ((symbol? arg) (string-append "\"" (symbol->string arg) "\""))))
659 (define (func name . args)
665 (map (lambda (x) (string-append " " (arg->string x))) args)))
671 (inexact->exact (/ x (abs x)))))
674 (define (as-scm action-name)
676 (define (beam width slope thick)
678 (func "set-line-char" "#")
679 (func "rline-to" width (* width slope))
683 (define (bezier-sandwich l thick)
690 (dy (- (cdr c3) (cdr c0)))
692 (c1-dx (- (car c1) x))
693 (c1-line-y (+ (cdr c0) (* c1-dx rc)))
694 (dir (if (< c1-line-y (cdr c1)) 1 -1))
695 (y (+ -1 (* dir (max (* dir (cdr c0)) (* dir (cdr c3)))))))
697 (func "rmove-to" x y)
698 (func "put" (if (< 0 dir) "/" "\\\\"))
699 (func "rmove-to" 1 (if (< 0 dir) 1 0))
700 (func "set-line-char" "_")
701 (func "h-line" (- dx 1))
702 (func "rmove-to" (- dx 1) (if (< 0 dir) -1 0))
703 (func "put" (if (< 0 dir) "\\\\" "/"))))))
705 (define (bracket arch_angle arch_width arch_height width height arch_thick thick)
707 (func "rmove-to" (+ width 1) (- (/ height -2) 1))
709 (func "set-line-char" "|")
710 (func "rmove-to" 0 1)
711 (func "v-line" (+ height 1))
712 (func "rmove-to" 0 (+ height 1))
722 (define (experimental-on)
725 (define (filledbox breapth width depth height)
726 (let ((dx (+ width breapth))
727 (dy (+ depth height)))
729 (func "rmove-to" (* -1 breapth) (* -1 depth))
732 (func "set-line-char"
733 (if (<= dx 1) "|" "#"))
736 (func "set-line-char"
737 (if (<= dy 1) "-" "="))
738 (func "h-line" dx))))))
740 (define (font-load-command name-mag command)
741 (func "load-font" (car name-mag) (magstep (cdr name-mag))))
743 (define (header creator generate)
744 (func "header" creator generate))
749 ;; urg: this is good for half of as2text's execution time
750 (define (xlily-def key val)
751 (string-append "(define " key " " (arg->string val) ")\n"))
753 (define (lily-def key val)
755 (or (equal? key "mudelapaperlinewidth")
756 (equal? key "mudelapaperstaffheight"))
757 (string-append "(define " key " " (arg->string val) ")\n")
760 (define (placebox x y s)
761 (let ((ey (inexact->exact y)))
762 (string-append "(move-to " (number->string (inexact->exact x)) " "
763 (if (= 0.5 (- (abs y) (abs ey)))
768 (define (select-font font-name-symbol)
769 (let* ((c (assoc font-name-symbol font-name-alist)))
774 "Programming error: No such font known "
775 (car font-name-symbol)))
776 "") ; issue no command
777 (func "select-font" (car font-name-symbol)))))
779 (define (start-line height)
780 (func "start-line" height))
788 (define (volta h w thick vert-start vert-end)
791 (func "set-line-char" "|")
792 (func "rmove-to" 0 -4)
793 ;; definition strange-way around
797 (func "rmove-to" 1 h)
798 (func "set-line-char" "_")
799 (func "h-line" (- w 1))
800 (func "set-line-char" "|")
803 (func "rmove-to" (- w 1) (* -1 h))
804 (func "v-line" (* -1 h)))
807 (cond ((eq? action-name 'all-definitions)
810 (define bracket ,bracket)
812 ;;(define crescendo ,crescendo)
813 (define bezier-sandwich ,bezier-sandwich)
814 ;;(define dashed-slur ,dashed-slur)
815 ;;(define decrescendo ,decrescendo)
816 (define end-output ,end-output)
817 (define experimental-on ,experimental-on)
818 (define filledbox ,filledbox)
819 ;;(define font-def ,font-def)
820 (define font-load-command ,font-load-command)
821 ;;(define font-switch ,font-switch)
822 (define header ,header)
823 (define header-end ,header-end)
824 (define lily-def ,lily-def)
825 ;;(define invoke-char ,invoke-char)
826 ;;(define invoke-dim1 ,invoke-dim1)
827 (define placebox ,placebox)
828 (define select-font ,select-font)
829 (define start-line ,start-line)
830 ;;(define stem ,stem)
831 (define stop-line ,stop-line)
832 (define stop-last-line ,stop-line)
834 ;;(define tuplet ,tuplet)
835 (define volta ,volta)
837 ;;((eq? action-name 'tuplet) tuplet)
838 ;;((eq? action-name 'beam) beam)
839 ;;((eq? action-name 'bezier-sandwich) bezier-sandwich)
840 ;;((eq? action-name 'bracket) bracket)
841 ((eq? action-name 'char) char)
842 ;;((eq? action-name 'crescendo) crescendo)
843 ;;((eq? action-name 'dashed-slur) dashed-slur)
844 ;;((eq? action-name 'decrescendo) decrescendo)
845 ;;((eq? action-name 'experimental-on) experimental-on)
846 ((eq? action-name 'filledbox) filledbox)
847 ((eq? action-name 'select-font) select-font)
848 ;;((eq? action-name 'volta) volta)
849 (else (error "unknown tag -- MUSA-SCM " action-name))
854 (define (gulp-file name)
855 (let* ((port (open-file name "r"))
856 (content (let loop ((text ""))
857 (let ((line (read-line port)))
858 (if (or (eof-object? line)
861 (loop (string-append text line "\n")))))))
865 (define (scm-gulp-file name)
868 (getenv 'LILYPONDPREFIX) "/ps") %load-path))
869 (let ((path (%search-load-path name)))
874 (define (scm-tex-output)
875 (eval (tex-scm 'all-definitions)))
877 (define (scm-ps-output)
878 (eval (ps-scm 'all-definitions)))
880 (define (scm-as-output)
881 (eval (as-scm 'all-definitions)))
883 ; Russ McManus, <mcmanus@IDT.NET>
885 ; I use the following, which should definitely be provided somewhere
886 ; in guile, but isn't, AFAIK:
890 (define (hash-table-for-each fn ht)
892 ((= i (vector-length ht)))
893 (do ((alist (vector-ref ht i) (cdr alist)))
895 (fn (car (car alist)) (cdr (car alist))))))
897 (define (hash-table-map fn ht)
900 ((= i (vector-length ht)) (reverse ret-ls))
901 (do ((alist (vector-ref ht i) (cdr alist)))
903 (set! ret-ls (cons (fn (car (car alist)) (cdr (car alist))) ret-ls)))))
907 (define (index-cell cell dir)
913 ; How should a bar line behave at a break?
915 (define (break-barline glyph dir)
916 (let ((result (assoc glyph
917 '((":|:" . (":|" . "|:"))
920 ("|:" . ("|" . "|:"))
921 ("|." . ("|." . nil))
922 (":|" . (":|" . nil))
923 ("||" . ("||" . nil))
924 (".|." . (".|." . nil))
925 ("scorebar" . (nil . "scorepostbreak"))
926 ("brace" . (nil . "brace"))
927 ("bracket" . (nil . "bracket"))
931 (if (equal? result #f)
932 (ly-warn (string-append "Unknown bar glyph: `" glyph "'"))
933 (index-cell (cdr result) dir))
938 (define (slur-ugly ind ht)
943 (> ht (+ (* 2 ind) -4))
944 (< ht (+ (* -2 ind) 8)))