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))))))
121 (define (flatten-list lst)
125 (if (pair? (car lst))
126 (append (flatten-list (car lst)) (flatten-list (cdr lst)))
127 (cons (car lst) (flatten-list (cdr lst))))
130 (define (list-minus a b)
131 "Return list of elements in A that are not in B."
132 (lset-difference eq? a b))
135 ;; TODO: use the srfi-1 partition function.
136 (define-public (uniq-list list)
137 "Uniq LIST, assuming that it is sorted"
139 (if (null? (cdr list))
141 (if (equal? (car list) (cadr list))
142 (uniq-list (cdr list))
143 (cons (car list) (uniq-list (cdr list)))))))
145 (define (split-at-predicate predicate l)
146 "Split L = (a_1 a_2 ... a_k b_1 ... b_k)
147 into L1 = (a_1 ... a_k ) and L2 =(b_1 .. b_k)
148 Such that (PREDICATE a_i a_{i+1}) and not (PREDICATE a_k b_1).
149 L1 is copied, L2 not.
151 (split-at-predicate (lambda (x y) (= (- y x) 2)) '(1 3 5 9 11) (cons '() '()))"
156 (define (inner-split predicate l acc)
160 (set-car! acc (cons (car l) (car acc)))
162 ((predicate (car l) (cadr l))
163 (set-car! acc (cons (car l) (car acc)))
164 (inner-split predicate (cdr l) acc))
166 (set-car! acc (cons (car l) (car acc)))
167 (set-cdr! acc (cdr l))
174 (inner-split predicate l c)
175 (set-car! c (reverse! (car c)))
180 (define-public (split-list l sep?)
182 (display (split-list '(a b c / d e f / g) (lambda (x) (equal? x '/))) )
184 ((a b c) (d e f) (g))
189 (define (split-one sep? l acc)
190 "Split off the first parts before separator and return both parts."
195 (split-one sep? (cdr l) (cons (car l) acc))
201 (let* ((c (split-one sep? l '())))
202 (cons (reverse! (car c) '()) (split-list (cdr c) sep?))
206 (define-public (interval-length x)
207 "Length of the number-pair X, when an interval"
208 (max 0 (- (cdr x) (car x)))
212 (define (other-axis a)
213 (remainder (+ a 1) 2))
216 (define-public (widen-interval iv amount)
217 (cons (- (car iv) amount)
221 (define-public (write-me message x)
222 "Return X. Display MESSAGE and write X. Handy for debugging, possibly turned off."
223 (display message) (write x) (newline) x)
226 (define (index-cell cell dir)
231 (define (cons-map f x)
232 "map F to contents of X"
233 (cons (f (car x)) (f (cdr x))))
236 (define-public (list-insert-separator lst between)
237 "Create new list, inserting BETWEEN between elements of LIST"
241 (cons x (cons between y))
243 (fold-right conc #f lst))
252 (define-public (!= l r)
255 (define-public (ly:load x)
257 (fn (%search-load-path x))
261 (format (current-error-port) "[~A]" fn))
262 (primitive-load fn)))
265 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
267 (use-modules (scm output-tex)
269 (scm output-ascii-script)
271 (scm output-sodipodi)
277 ("tex" . ("TeX output. The default output form." ,tex-output-expression))
278 ("ps" . ("Direct postscript. Requires setting GS_LIB and GS_FONTPATH" ,ps-output-expression))
279 ("scm" . ("Scheme dump: debug scheme molecule expressions" ,write))
280 ("as" . ("Asci-script. Postprocess with as2txt to get ascii art" ,as-output-expression))
281 ("sketch" . ("Bare bones Sketch output." ,sketch-output-expression))
282 ("sodipodi" . ("Bare bones Sodipodi output." ,sodipodi-output-expression))
283 ("pdftex" . ("PDFTeX output. Was last seen nonfunctioning." ,pdftex-output-expression))
287 (define (document-format-dumpers)
290 (display (string-append (pad-string-to 5 (car x)) (cadr x) "\n"))
294 (define-public (find-dumper format )
296 ((d (assoc format output-alist)))
300 (scm-error "Could not find dumper for format ~s" format))
303 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
308 '("define-music-types.scm"
311 "chord-ignatzek-names.scm"
313 "chord-generic-names.scm"
317 "music-functions.scm"
318 "define-music-properties.scm"
322 "define-translator-properties.scm"
323 "translation-functions.scm"
333 "define-grob-properties.scm"
335 "define-grob-interfaces.scm"
342 (set! type-p-name-alist
344 (,ly:dir? . "direction")
345 (,scheme? . "any type")
346 (,number-pair? . "pair of numbers")
347 (,ly:input-location? . "input location")
348 (,ly:grob? . "grob (GRaphical OBject)")
349 (,grob-list? . "list of grobs")
350 (,ly:duration? . "duration")
352 (,integer? . "integer")
354 (,symbol? . "symbol")
355 (,string? . "string")
356 (,boolean? . "boolean")
357 (,ly:pitch? . "pitch")
358 (,ly:moment? . "moment")
359 (,ly:dimension? . "dimension, in staff space")
360 (,ly:input-location? . "input location")
361 (,music-list? . "list of music")
362 (,ly:music? . "music")
363 (,number? . "number")
365 (,input-port? . "input port")
366 (,output-port? . "output port")
367 (,vector? . "vector")
368 (,procedure? . "procedure")
369 (,boolean-or-symbol? . "boolean or symbol")
370 (,number-or-string? . "number or string")
371 (,markup? . "markup")
372 (,markup-list? . "list of markups")
373 (,number-or-grob? . "number or grob")