1 ;;; lily.scm -- implement Scheme output routines for TeX and PostScript
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 1998--2003 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 (use-modules (ice-9 regex)
13 (srfi srfi-13) ;strings
17 ;;; debugging evaluator is slower. This should
18 ;;; have a more sensible default.
23 ;(debug-enable 'backtrace)
24 (read-enable 'positions)
27 (define-public (line-column-location line col file)
28 "Print an input location, including column number ."
29 (string-append (number->string line) ":"
30 (number->string col) " " file)
33 (define-public (line-location line col file)
34 "Print an input location, without column number ."
35 (string-append (number->string line) " " file)
38 (define-public point-and-click #f)
40 (define-public (lilypond-version)
42 (map (lambda (x) (if (symbol? x)
50 ;; cpp hack to get useful error message
51 (define ifdef "First run this through cpp.")
52 (define ifndef "First run this through cpp.")
56 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
60 (define-public START -1)
61 (define-public STOP 1)
62 (define-public LEFT -1)
63 (define-public RIGHT 1)
65 (define-public DOWN -1)
66 (define-public CENTER 0)
68 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
69 ;; lily specific variables.
70 (define-public default-script-alist '())
72 (define-public security-paranoia #f)
74 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
75 ;;; Unassorted utility functions.
80 (define (uniqued-alist alist acc)
82 (if (assoc (caar alist) acc)
83 (uniqued-alist (cdr alist) acc)
84 (uniqued-alist (cdr alist) (cons (car alist) acc)))))
87 (define (assoc-get key alist)
88 "Return value if KEY in ALIST, else #f."
89 (let ((entry (assoc key alist)))
90 (if entry (cdr entry) #f)))
92 (define (assoc-get-default key alist default)
93 "Return value if KEY in ALIST, else DEFAULT."
94 (let ((entry (assoc key alist)))
95 (if entry (cdr entry) default)))
98 (define-public (uniqued-alist alist acc)
100 (if (assoc (caar alist) acc)
101 (uniqued-alist (cdr alist) acc)
102 (uniqued-alist (cdr alist) (cons (car alist) acc)))))
104 (define-public (alist<? x y)
105 (string<? (symbol->string (car x))
106 (symbol->string (car y))))
110 (define (chain-assoc x alist-list)
111 (if (null? alist-list)
113 (let* ((handle (assoc x (car alist-list))))
116 (chain-assoc x (cdr alist-list))))))
119 (define (map-alist-vals func list)
120 "map FUNC over the vals of LIST, leaving the keys."
123 (cons (cons (caar list) (func (cdar list)))
124 (map-alist-vals func (cdr list)))
127 (define (map-alist-keys func list)
128 "map FUNC over the keys of an alist LIST, leaving the vals. "
131 (cons (cons (func (caar list)) (cdar list))
132 (map-alist-keys func (cdr list)))
140 (define (flatten-list lst)
144 (if (pair? (car lst))
145 (append (flatten-list (car lst)) (flatten-list (cdr lst)))
146 (cons (car lst) (flatten-list (cdr lst))))
149 (define (list-minus a b)
150 "Return list of elements in A that are not in B."
151 (lset-difference eq? a b))
154 ;; TODO: use the srfi-1 partition function.
155 (define-public (uniq-list list)
156 "Uniq LIST, assuming that it is sorted"
158 (if (null? (cdr list))
160 (if (equal? (car list) (cadr list))
161 (uniq-list (cdr list))
162 (cons (car list) (uniq-list (cdr list)))))))
164 (define (split-at-predicate predicate l)
165 "Split L = (a_1 a_2 ... a_k b_1 ... b_k)
166 into L1 = (a_1 ... a_k ) and L2 =(b_1 .. b_k)
167 Such that (PREDICATE a_i a_{i+1}) and not (PREDICATE a_k b_1).
168 L1 is copied, L2 not.
170 (split-at-predicate (lambda (x y) (= (- y x) 2)) '(1 3 5 9 11) (cons '() '()))"
175 (define (inner-split predicate l acc)
179 (set-car! acc (cons (car l) (car acc)))
181 ((predicate (car l) (cadr l))
182 (set-car! acc (cons (car l) (car acc)))
183 (inner-split predicate (cdr l) acc))
185 (set-car! acc (cons (car l) (car acc)))
186 (set-cdr! acc (cdr l))
193 (inner-split predicate l c)
194 (set-car! c (reverse! (car c)))
199 (define-public (split-list l sep?)
201 (display (split-list '(a b c / d e f / g) (lambda (x) (equal? x '/))) )
203 ((a b c) (d e f) (g))
208 (define (split-one sep? l acc)
209 "Split off the first parts before separator and return both parts."
214 (split-one sep? (cdr l) (cons (car l) acc))
220 (let* ((c (split-one sep? l '())))
221 (cons (reverse! (car c) '()) (split-list (cdr c) sep?))
225 (define-public (interval-length x)
226 "Length of the number-pair X, when an interval"
227 (max 0 (- (cdr x) (car x)))
231 (define (other-axis a)
232 (remainder (+ a 1) 2))
235 (define-public (widen-interval iv amount)
236 (cons (- (car iv) amount)
240 (define-public (write-me message x)
241 "Return X. Display MESSAGE and write X. Handy for debugging, possibly turned off."
242 (display message) (write x) (newline) x)
245 (define (index-cell cell dir)
250 (define (cons-map f x)
251 "map F to contents of X"
252 (cons (f (car x)) (f (cdr x))))
255 (define-public (list-insert-separator lst between)
256 "Create new list, inserting BETWEEN between elements of LIST"
260 (cons x (cons between y))
262 (fold-right conc #f lst))
271 (define-public (!= l r)
274 (define-public (ly:load x)
276 (fn (%search-load-path x))
280 (format (current-error-port) "[~A]" fn))
281 (primitive-load fn)))
284 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
286 (use-modules (scm output-tex)
288 (scm output-ascii-script)
290 (scm output-sodipodi)
296 ("tex" . ("TeX output. The default output form." ,tex-output-expression))
297 ("ps" . ("Direct postscript. Requires setting GS_LIB and GS_FONTPATH" ,ps-output-expression))
298 ("scm" . ("Scheme dump: debug scheme molecule expressions" ,write))
299 ("as" . ("Asci-script. Postprocess with as2txt to get ascii art" ,as-output-expression))
300 ("sketch" . ("Bare bones Sketch output." ,sketch-output-expression))
301 ("sodipodi" . ("Bare bones Sodipodi output." ,sodipodi-output-expression))
302 ("pdftex" . ("PDFTeX output. Was last seen nonfunctioning." ,pdftex-output-expression))
306 (define (document-format-dumpers)
309 (display (string-append (pad-string-to 5 (car x)) (cadr x) "\n"))
313 (define-public (find-dumper format )
315 ((d (assoc format output-alist)))
319 (scm-error "Could not find dumper for format ~s" format))
322 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
327 '("define-music-types.scm"
330 "chord-ignatzek-names.scm"
332 "chord-generic-names.scm"
336 "music-functions.scm"
337 "define-music-properties.scm"
341 "define-translator-properties.scm"
342 "translation-functions.scm"
352 "define-grob-properties.scm"
354 "define-grob-interfaces.scm"
361 (set! type-p-name-alist
363 (,boolean-or-symbol? . "boolean or symbol")
364 (,boolean? . "boolean")
366 (,grob-list? . "list of grobs")
367 (,input-port? . "input port")
368 (,integer? . "integer")
370 (,ly:context? . "context")
371 (,ly:dimension? . "dimension, in staff space")
372 (,ly:dir? . "direction")
373 (,ly:duration? . "duration")
374 (,ly:grob? . "grob (GRaphical OBject)")
375 (,ly:input-location? . "input location")
376 (,ly:input-location? . "input location")
377 (,ly:moment? . "moment")
378 (,ly:music? . "music")
379 (,ly:pitch? . "pitch")
380 (,ly:translator? . "translator")
381 (,markup-list? . "list of markups")
382 (,markup? . "markup")
383 (,music-list? . "list of music")
384 (,number-or-grob? . "number or grob")
385 (,number-or-string? . "number or string")
386 (,number-pair? . "pair of numbers")
387 (,number? . "number")
388 (,output-port? . "output port")
390 (,procedure? . "procedure")
391 (,scheme? . "any type")
392 (,string? . "string")
393 (,symbol? . "symbol")
394 (,vector? . "vector")