1 ;;;; lily.scm -- implement Scheme output routines for TeX and PostScript
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 1998--2002 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 (use-modules (ice-9 regex))
15 ;; debugging evaluator is slower.
18 ;(debug-enable 'backtrace)
19 (read-enable 'positions)
22 (define-public (line-column-location line col file)
23 "Print an input location, including column number ."
24 (string-append (number->string line) ":"
25 (number->string col) " " file)
28 (define-public (line-location line col file)
29 "Print an input location, without column number ."
30 (string-append (number->string line) " " file)
33 (define-public point-and-click #f)
35 ;; cpp hack to get useful error message
36 (define ifdef "First run this through cpp.")
37 (define ifndef "First run this through cpp.")
41 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
45 (define-public START -1)
46 (define-public STOP 1)
47 (define-public LEFT -1)
48 (define-public RIGHT 1)
50 (define-public DOWN -1)
51 (define-public CENTER 0)
53 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
54 ;; lily specific variables.
55 (define-public default-script-alist '())
57 (define-public security-paranoia #f)
59 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
60 ;;; Unassorted utility functions.
62 (define (uniqued-alist alist acc)
64 (if (assoc (caar alist) acc)
65 (uniqued-alist (cdr alist) acc)
66 (uniqued-alist (cdr alist) (cons (car alist) acc)))))
68 (define (other-axis a)
69 (remainder (+ a 1) 2))
72 (define-public (widen-interval iv amount)
73 (cons (- (car iv) amount)
79 (define (index-cell cell dir)
84 (define (cons-map f x)
85 "map F to contents of X"
86 (cons (f (car x)) (f (cdr x))))
89 (define-public (reduce operator list)
90 "reduce OP [A, B, C, D, ... ] =
93 (if (null? (cdr list)) (car list)
94 (operator (car list) (reduce operator (cdr list)))))
96 (define (take-from-list-until todo gathered crit?)
97 "return (G, T), where (reverse G) + T = GATHERED + TODO, and the last of G
98 is the first to satisfy CRIT
100 (take-from-list-until '(1 2 3 4 5) '() (lambda (x) (eq? x 3)))
107 (if (crit? (car todo))
108 (cons (cons (car todo) gathered) (cdr todo))
109 (take-from-list-until (cdr todo) (cons (car todo) gathered) crit?)
114 (define-public (reduce-list list between)
115 "Create new list, inserting BETWEEN between elements of LIST"
118 (if (null? (cdr list))
121 (cons between (reduce-list (cdr list) between)))
125 (define-public (string-join str-list sep)
126 "append the list of strings in STR-LIST, joining them with SEP"
127 (apply string-append (reduce-list str-list sep))
136 (define (write-me n x)
145 (define-public (filter-list pred? list)
146 "return that part of LIST for which PRED is true."
148 (let* ((rest (filter-list pred? (cdr list))))
149 (if (pred? (car list))
150 (cons (car list) rest)
153 (define-public (filter-out-list pred? list)
154 "return that part of LIST for which PRED is true."
156 (let* ((rest (filter-list pred? (cdr list))))
157 (if (not (pred? (car list)))
158 (cons (car list) rest)
161 (define-public (uniqued-alist alist acc)
162 (if (null? alist) acc
163 (if (assoc (caar alist) acc)
164 (uniqued-alist (cdr alist) acc)
165 (uniqued-alist (cdr alist) (cons (car alist) acc)))))
167 (define-public (uniq-list list)
169 (if (null? (cdr list))
171 (if (equal? (car list) (cadr list))
172 (uniq-list (cdr list))
173 (cons (car list) (uniq-list (cdr list)))))))
175 (define-public (alist<? x y)
176 (string<? (symbol->string (car x))
177 (symbol->string (car y))))
179 (define-public (pad-string-to str wid)
180 (string-append str (make-string (max (- wid (string-length str)) 0) #\ ))
183 (define-public (ly:load x)
185 (fn (%search-load-path x))
189 (format (current-error-port) "[~A]" fn))
190 (primitive-load fn)))
193 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
195 (use-modules (scm tex)
206 ("tex" . ("TeX output. The default output form." ,tex-output-expression))
207 ("ps" . ("Direct postscript. Requires setting GS_LIB and GS_FONTPATH" ,ps-output-expression))
208 ("scm" . ("Scheme dump: debug scheme molecule expressions" ,write))
209 ("as" . ("Asci-script. Postprocess with as2txt to get ascii art" ,as-output-expression))
210 ("sketch" . ("Bare bones Sketch output." ,sketch-output-expression))
211 ("sodipodi" . ("Bare bones Sodipodi output." ,sodipodi-output-expression))
212 ("pdftex" . ("PDFTeX output. Was last seen nonfunctioning." ,pdftex-output-expression))
216 (define (document-format-dumpers)
219 (display (string-append (pad-string-to 5 (car x)) (cadr x) "\n"))
223 (define-public (find-dumper format )
225 ((d (assoc format output-alist)))
229 (scm-error "Could not find dumper for format ~s" format))
232 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
243 "grob-property-description.scm"
244 "context-description.scm"
245 "interface-description.scm"
250 "music-functions.scm"
251 "music-property-description.scm"
254 "basic-properties.scm"
256 "grob-description.scm"
257 "translator-property-description.scm"
267 (set! type-p-name-alist
269 (,ly:dir? . "direction")
270 (,scheme? . "any type")
271 (,number-pair? . "pair of numbers")
272 (,ly:input-location? . "input location")
273 (,ly:grob? . "grob (GRaphical OBject)")
274 (,grob-list? . "list of grobs")
275 (,ly:duration? . "duration")
277 (,integer? . "integer")
279 (,symbol? . "symbol")
280 (,string? . "string")
281 (,boolean? . "boolean")
282 (,ly:moment? . "moment")
283 (,ly:input-location? . "input location")
284 (,music-list? . "list of music")
285 (,ly:music? . "music")
286 (,number? . "number")
288 (,input-port? . "input port")
289 (,output-port? . "output port")
290 (,vector? . "vector")
291 (,procedure? . "procedure")
292 (,boolean-or-symbol? . "boolean or symbol")
293 (,number-or-string? . "number or string")
294 (,markup? . "markup")
295 (,markup-list? . "list of markups")
296 (,number-or-grob? . "number or grob")