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.
21 (if (ly:get-option 'verbose)
24 (debug-enable 'backtrace)
25 (read-enable 'positions)))
28 (define-public (line-column-location line col file)
29 "Print an input location, including column number ."
30 (string-append (number->string line) ":"
31 (number->string col) " " file)
34 (define-public (line-location line col file)
35 "Print an input location, without column number ."
36 (string-append (number->string line) " " file)
39 (define-public point-and-click #f)
41 (define-public (lilypond-version)
43 (map (lambda (x) (if (symbol? x)
51 ;; cpp hack to get useful error message
52 (define ifdef "First run this through cpp.")
53 (define ifndef "First run this through cpp.")
57 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
61 (define-public START -1)
62 (define-public STOP 1)
63 (define-public LEFT -1)
64 (define-public RIGHT 1)
66 (define-public DOWN -1)
67 (define-public CENTER 0)
69 (define-public DOUBLE-FLAT -4)
70 (define-public THREE-Q-FLAT -3)
71 (define-public FLAT -2)
72 (define-public SEMI-FLAT -1)
73 (define-public NATURAL 0)
74 (define-public SEMI-SHARP 1)
75 (define-public SHARP 2)
76 (define-public THREE-Q-SHARP 3)
77 (define-public DOUBLE-SHARP 4)
78 (define-public SEMI-TONE 2)
80 (define-public ZERO-MOMENT (ly:make-moment 0 1))
82 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
83 ;; lily specific variables.
84 (define-public default-script-alist '())
86 (define-public security-paranoia #f)
88 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
89 ;;; Unassorted utility functions.
94 (define (uniqued-alist alist acc)
96 (if (assoc (caar alist) acc)
97 (uniqued-alist (cdr alist) acc)
98 (uniqued-alist (cdr alist) (cons (car alist) acc)))))
101 (define (assoc-get key alist)
102 "Return value if KEY in ALIST, else #f."
103 (let ((entry (assoc key alist)))
104 (if entry (cdr entry) #f)))
106 (define (assoc-get-default key alist default)
107 "Return value if KEY in ALIST, else DEFAULT."
108 (let ((entry (assoc key alist)))
109 (if entry (cdr entry) default)))
112 (define-public (uniqued-alist alist acc)
113 (if (null? alist) acc
114 (if (assoc (caar alist) acc)
115 (uniqued-alist (cdr alist) acc)
116 (uniqued-alist (cdr alist) (cons (car alist) acc)))))
118 (define-public (alist<? x y)
119 (string<? (symbol->string (car x))
120 (symbol->string (car y))))
124 (define (chain-assoc x alist-list)
125 (if (null? alist-list)
127 (let* ((handle (assoc x (car alist-list))))
130 (chain-assoc x (cdr alist-list))))))
132 (define (chain-assoc-get x alist-list default)
133 (if (null? alist-list)
135 (let* ((handle (assoc x (car alist-list))))
138 (chain-assoc-get x (cdr alist-list) default)))))
141 (define (map-alist-vals func list)
142 "map FUNC over the vals of LIST, leaving the keys."
145 (cons (cons (caar list) (func (cdar list)))
146 (map-alist-vals func (cdr list)))
149 (define (map-alist-keys func list)
150 "map FUNC over the keys of an alist LIST, leaving the vals. "
153 (cons (cons (func (caar list)) (cdar list))
154 (map-alist-keys func (cdr list)))
162 (define (flatten-list lst)
166 (if (pair? (car lst))
167 (append (flatten-list (car lst)) (flatten-list (cdr lst)))
168 (cons (car lst) (flatten-list (cdr lst))))
171 (define (list-minus a b)
172 "Return list of elements in A that are not in B."
173 (lset-difference eq? a b))
176 ;; TODO: use the srfi-1 partition function.
177 (define-public (uniq-list list)
178 "Uniq LIST, assuming that it is sorted"
180 (if (null? (cdr list))
182 (if (equal? (car list) (cadr list))
183 (uniq-list (cdr list))
184 (cons (car list) (uniq-list (cdr list)))))))
186 (define (split-at-predicate predicate l)
187 "Split L = (a_1 a_2 ... a_k b_1 ... b_k)
188 into L1 = (a_1 ... a_k ) and L2 =(b_1 .. b_k)
189 Such that (PREDICATE a_i a_{i+1}) and not (PREDICATE a_k b_1).
190 L1 is copied, L2 not.
192 (split-at-predicate (lambda (x y) (= (- y x) 2)) '(1 3 5 9 11) (cons '() '()))"
197 (define (inner-split predicate l acc)
201 (set-car! acc (cons (car l) (car acc)))
203 ((predicate (car l) (cadr l))
204 (set-car! acc (cons (car l) (car acc)))
205 (inner-split predicate (cdr l) acc))
207 (set-car! acc (cons (car l) (car acc)))
208 (set-cdr! acc (cdr l))
215 (inner-split predicate l c)
216 (set-car! c (reverse! (car c)))
221 (define-public (split-list l sep?)
223 (display (split-list '(a b c / d e f / g) (lambda (x) (equal? x '/))) )
225 ((a b c) (d e f) (g))
230 (define (split-one sep? l acc)
231 "Split off the first parts before separator and return both parts."
236 (split-one sep? (cdr l) (cons (car l) acc))
242 (let* ((c (split-one sep? l '())))
243 (cons (reverse! (car c) '()) (split-list (cdr c) sep?))
247 (define-public (interval-length x)
248 "Length of the number-pair X, when an interval"
249 (max 0 (- (cdr x) (car x)))
253 (define (other-axis a)
254 (remainder (+ a 1) 2))
257 (define-public (interval-widen iv amount)
258 (cons (- (car iv) amount)
259 (+ (cdr iv) amount)))
261 (define-public (interval-union i1 i2)
262 (cons (min (car i1) (car i2))
263 (max (cdr i1) (cdr i2))))
266 (define-public (write-me message x)
267 "Return X. Display MESSAGE and write X. Handy for debugging, possibly turned off."
268 (display message) (write x) (newline) x)
271 (define (index-cell cell dir)
276 (define (cons-map f x)
277 "map F to contents of X"
278 (cons (f (car x)) (f (cdr x))))
281 (define-public (list-insert-separator lst between)
282 "Create new list, inserting BETWEEN between elements of LIST"
286 (cons x (cons between y))
288 (fold-right conc #f lst))
297 (define-public (!= l r)
300 (define-public (ly:load x)
302 (fn (%search-load-path x))
305 (if (ly:get-option 'verbose)
306 (format (current-error-port) "[~A]" fn))
307 (primitive-load fn)))
310 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
312 (use-modules (scm output-tex)
314 (scm output-ascii-script)
316 (scm output-sodipodi)
322 ("tex" . ("TeX output. The default output form." ,tex-output-expression))
323 ("ps" . ("Direct postscript. Requires setting GS_LIB and GS_FONTPATH" ,ps-output-expression))
324 ("scm" . ("Scheme dump: debug scheme molecule expressions" ,write))
325 ("as" . ("Asci-script. Postprocess with as2txt to get ascii art" ,as-output-expression))
326 ("sketch" . ("Bare bones Sketch output." ,sketch-output-expression))
327 ("sodipodi" . ("Bare bones Sodipodi output." ,sodipodi-output-expression))
328 ("pdftex" . ("PDFTeX output. Was last seen nonfunctioning." ,pdftex-output-expression))
332 (define (document-format-dumpers)
335 (display (string-append (pad-string-to 5 (car x)) (cadr x) "\n"))
339 (define-public (find-dumper format )
341 ((d (assoc format output-alist)))
345 (scm-error "Could not find dumper for format ~s" format))
348 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
353 '("define-music-types.scm"
356 "chord-ignatzek-names.scm"
358 "chord-generic-names.scm"
362 "music-functions.scm"
363 "define-music-properties.scm"
367 "define-translator-properties.scm"
368 "translation-functions.scm"
378 "define-grob-properties.scm"
380 "define-grob-interfaces.scm"
387 (set! type-p-name-alist
389 (,boolean-or-symbol? . "boolean or symbol")
390 (,boolean? . "boolean")
392 (,grob-list? . "list of grobs")
393 (,input-port? . "input port")
394 (,integer? . "integer")
396 (,ly:context? . "context")
397 (,ly:dimension? . "dimension, in staff space")
398 (,ly:dir? . "direction")
399 (,ly:duration? . "duration")
400 (,ly:grob? . "grob (GRaphical OBject)")
401 (,ly:input-location? . "input location")
402 (,ly:input-location? . "input location")
403 (,ly:moment? . "moment")
404 (,ly:music? . "music")
405 (,ly:pitch? . "pitch")
406 (,ly:translator? . "translator")
407 (,markup-list? . "list of markups")
408 (,markup? . "markup")
409 (,music-list? . "list of music")
410 (,number-or-grob? . "number or grob")
411 (,number-or-string? . "number or string")
412 (,number-pair? . "pair of numbers")
413 (,number? . "number")
414 (,output-port? . "output port")
416 (,procedure? . "procedure")
417 (,scheme? . "any type")
418 (,string? . "string")
419 (,symbol? . "symbol")
420 (,vector? . "vector")