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 (define-public DOUBLE-FLAT -2)
69 (define-public FLAT -1)
70 (define-public SHARP 1)
71 (define-public DOUBLE-SHARP 2)
72 (define-public NATURAL 0)
75 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
76 ;; lily specific variables.
77 (define-public default-script-alist '())
79 (define-public security-paranoia #f)
81 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
82 ;;; Unassorted utility functions.
87 (define (uniqued-alist alist acc)
89 (if (assoc (caar alist) acc)
90 (uniqued-alist (cdr alist) acc)
91 (uniqued-alist (cdr alist) (cons (car alist) acc)))))
94 (define (assoc-get key alist)
95 "Return value if KEY in ALIST, else #f."
96 (let ((entry (assoc key alist)))
97 (if entry (cdr entry) #f)))
99 (define (assoc-get-default key alist default)
100 "Return value if KEY in ALIST, else DEFAULT."
101 (let ((entry (assoc key alist)))
102 (if entry (cdr entry) default)))
105 (define-public (uniqued-alist alist acc)
106 (if (null? alist) acc
107 (if (assoc (caar alist) acc)
108 (uniqued-alist (cdr alist) acc)
109 (uniqued-alist (cdr alist) (cons (car alist) acc)))))
111 (define-public (alist<? x y)
112 (string<? (symbol->string (car x))
113 (symbol->string (car y))))
117 (define (chain-assoc x alist-list)
118 (if (null? alist-list)
120 (let* ((handle (assoc x (car alist-list))))
123 (chain-assoc x (cdr alist-list))))))
126 (define (map-alist-vals func list)
127 "map FUNC over the vals of LIST, leaving the keys."
130 (cons (cons (caar list) (func (cdar list)))
131 (map-alist-vals func (cdr list)))
134 (define (map-alist-keys func list)
135 "map FUNC over the keys of an alist LIST, leaving the vals. "
138 (cons (cons (func (caar list)) (cdar list))
139 (map-alist-keys func (cdr list)))
147 (define (flatten-list lst)
151 (if (pair? (car lst))
152 (append (flatten-list (car lst)) (flatten-list (cdr lst)))
153 (cons (car lst) (flatten-list (cdr lst))))
156 (define (list-minus a b)
157 "Return list of elements in A that are not in B."
158 (lset-difference eq? a b))
161 ;; TODO: use the srfi-1 partition function.
162 (define-public (uniq-list list)
163 "Uniq LIST, assuming that it is sorted"
165 (if (null? (cdr list))
167 (if (equal? (car list) (cadr list))
168 (uniq-list (cdr list))
169 (cons (car list) (uniq-list (cdr list)))))))
171 (define (split-at-predicate predicate l)
172 "Split L = (a_1 a_2 ... a_k b_1 ... b_k)
173 into L1 = (a_1 ... a_k ) and L2 =(b_1 .. b_k)
174 Such that (PREDICATE a_i a_{i+1}) and not (PREDICATE a_k b_1).
175 L1 is copied, L2 not.
177 (split-at-predicate (lambda (x y) (= (- y x) 2)) '(1 3 5 9 11) (cons '() '()))"
182 (define (inner-split predicate l acc)
186 (set-car! acc (cons (car l) (car acc)))
188 ((predicate (car l) (cadr l))
189 (set-car! acc (cons (car l) (car acc)))
190 (inner-split predicate (cdr l) acc))
192 (set-car! acc (cons (car l) (car acc)))
193 (set-cdr! acc (cdr l))
200 (inner-split predicate l c)
201 (set-car! c (reverse! (car c)))
206 (define-public (split-list l sep?)
208 (display (split-list '(a b c / d e f / g) (lambda (x) (equal? x '/))) )
210 ((a b c) (d e f) (g))
215 (define (split-one sep? l acc)
216 "Split off the first parts before separator and return both parts."
221 (split-one sep? (cdr l) (cons (car l) acc))
227 (let* ((c (split-one sep? l '())))
228 (cons (reverse! (car c) '()) (split-list (cdr c) sep?))
232 (define-public (interval-length x)
233 "Length of the number-pair X, when an interval"
234 (max 0 (- (cdr x) (car x)))
238 (define (other-axis a)
239 (remainder (+ a 1) 2))
242 (define-public (interval-widen iv amount)
243 (cons (- (car iv) amount)
244 (+ (cdr iv) amount)))
247 (define-public (interval-union i1 i2)
248 (cons (min (car i1) (car i2))
249 (max (cdr i1) (cdr i2))))
252 (define-public (write-me message x)
253 "Return X. Display MESSAGE and write X. Handy for debugging, possibly turned off."
254 (display message) (write x) (newline) x)
257 (define (index-cell cell dir)
262 (define (cons-map f x)
263 "map F to contents of X"
264 (cons (f (car x)) (f (cdr x))))
267 (define-public (list-insert-separator lst between)
268 "Create new list, inserting BETWEEN between elements of LIST"
272 (cons x (cons between y))
274 (fold-right conc #f lst))
283 (define-public (!= l r)
286 (define-public (ly:load x)
288 (fn (%search-load-path x))
292 (format (current-error-port) "[~A]" fn))
293 (primitive-load fn)))
296 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
298 (use-modules (scm output-tex)
300 (scm output-ascii-script)
302 (scm output-sodipodi)
308 ("tex" . ("TeX output. The default output form." ,tex-output-expression))
309 ("ps" . ("Direct postscript. Requires setting GS_LIB and GS_FONTPATH" ,ps-output-expression))
310 ("scm" . ("Scheme dump: debug scheme molecule expressions" ,write))
311 ("as" . ("Asci-script. Postprocess with as2txt to get ascii art" ,as-output-expression))
312 ("sketch" . ("Bare bones Sketch output." ,sketch-output-expression))
313 ("sodipodi" . ("Bare bones Sodipodi output." ,sodipodi-output-expression))
314 ("pdftex" . ("PDFTeX output. Was last seen nonfunctioning." ,pdftex-output-expression))
318 (define (document-format-dumpers)
321 (display (string-append (pad-string-to 5 (car x)) (cadr x) "\n"))
325 (define-public (find-dumper format )
327 ((d (assoc format output-alist)))
331 (scm-error "Could not find dumper for format ~s" format))
334 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
339 '("define-music-types.scm"
342 "chord-ignatzek-names.scm"
344 "chord-generic-names.scm"
348 "music-functions.scm"
349 "define-music-properties.scm"
353 "define-translator-properties.scm"
354 "translation-functions.scm"
364 "define-grob-properties.scm"
366 "define-grob-interfaces.scm"
373 (set! type-p-name-alist
375 (,boolean-or-symbol? . "boolean or symbol")
376 (,boolean? . "boolean")
378 (,grob-list? . "list of grobs")
379 (,input-port? . "input port")
380 (,integer? . "integer")
382 (,ly:context? . "context")
383 (,ly:dimension? . "dimension, in staff space")
384 (,ly:dir? . "direction")
385 (,ly:duration? . "duration")
386 (,ly:grob? . "grob (GRaphical OBject)")
387 (,ly:input-location? . "input location")
388 (,ly:input-location? . "input location")
389 (,ly:moment? . "moment")
390 (,ly:music? . "music")
391 (,ly:pitch? . "pitch")
392 (,ly:translator? . "translator")
393 (,markup-list? . "list of markups")
394 (,markup? . "markup")
395 (,music-list? . "list of music")
396 (,number-or-grob? . "number or grob")
397 (,number-or-string? . "number or string")
398 (,number-pair? . "pair of numbers")
399 (,number? . "number")
400 (,output-port? . "output port")
402 (,procedure? . "procedure")
403 (,scheme? . "any type")
404 (,string? . "string")
405 (,symbol? . "symbol")
406 (,vector? . "vector")