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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
81 ;; lily specific variables.
82 (define-public default-script-alist '())
84 (define-public security-paranoia #f)
86 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
87 ;;; Unassorted utility functions.
92 (define (uniqued-alist alist acc)
94 (if (assoc (caar alist) acc)
95 (uniqued-alist (cdr alist) acc)
96 (uniqued-alist (cdr alist) (cons (car alist) acc)))))
99 (define (assoc-get key alist)
100 "Return value if KEY in ALIST, else #f."
101 (let ((entry (assoc key alist)))
102 (if entry (cdr entry) #f)))
104 (define (assoc-get-default key alist default)
105 "Return value if KEY in ALIST, else DEFAULT."
106 (let ((entry (assoc key alist)))
107 (if entry (cdr entry) default)))
110 (define-public (uniqued-alist alist acc)
111 (if (null? alist) acc
112 (if (assoc (caar alist) acc)
113 (uniqued-alist (cdr alist) acc)
114 (uniqued-alist (cdr alist) (cons (car alist) acc)))))
116 (define-public (alist<? x y)
117 (string<? (symbol->string (car x))
118 (symbol->string (car y))))
122 (define (chain-assoc x alist-list)
123 (if (null? alist-list)
125 (let* ((handle (assoc x (car alist-list))))
128 (chain-assoc x (cdr alist-list))))))
131 (define (map-alist-vals func list)
132 "map FUNC over the vals of LIST, leaving the keys."
135 (cons (cons (caar list) (func (cdar list)))
136 (map-alist-vals func (cdr list)))
139 (define (map-alist-keys func list)
140 "map FUNC over the keys of an alist LIST, leaving the vals. "
143 (cons (cons (func (caar list)) (cdar list))
144 (map-alist-keys func (cdr list)))
152 (define (flatten-list lst)
156 (if (pair? (car lst))
157 (append (flatten-list (car lst)) (flatten-list (cdr lst)))
158 (cons (car lst) (flatten-list (cdr lst))))
161 (define (list-minus a b)
162 "Return list of elements in A that are not in B."
163 (lset-difference eq? a b))
166 ;; TODO: use the srfi-1 partition function.
167 (define-public (uniq-list list)
168 "Uniq LIST, assuming that it is sorted"
170 (if (null? (cdr list))
172 (if (equal? (car list) (cadr list))
173 (uniq-list (cdr list))
174 (cons (car list) (uniq-list (cdr list)))))))
176 (define (split-at-predicate predicate l)
177 "Split L = (a_1 a_2 ... a_k b_1 ... b_k)
178 into L1 = (a_1 ... a_k ) and L2 =(b_1 .. b_k)
179 Such that (PREDICATE a_i a_{i+1}) and not (PREDICATE a_k b_1).
180 L1 is copied, L2 not.
182 (split-at-predicate (lambda (x y) (= (- y x) 2)) '(1 3 5 9 11) (cons '() '()))"
187 (define (inner-split predicate l acc)
191 (set-car! acc (cons (car l) (car acc)))
193 ((predicate (car l) (cadr l))
194 (set-car! acc (cons (car l) (car acc)))
195 (inner-split predicate (cdr l) acc))
197 (set-car! acc (cons (car l) (car acc)))
198 (set-cdr! acc (cdr l))
205 (inner-split predicate l c)
206 (set-car! c (reverse! (car c)))
211 (define-public (split-list l sep?)
213 (display (split-list '(a b c / d e f / g) (lambda (x) (equal? x '/))) )
215 ((a b c) (d e f) (g))
220 (define (split-one sep? l acc)
221 "Split off the first parts before separator and return both parts."
226 (split-one sep? (cdr l) (cons (car l) acc))
232 (let* ((c (split-one sep? l '())))
233 (cons (reverse! (car c) '()) (split-list (cdr c) sep?))
237 (define-public (interval-length x)
238 "Length of the number-pair X, when an interval"
239 (max 0 (- (cdr x) (car x)))
243 (define (other-axis a)
244 (remainder (+ a 1) 2))
247 (define-public (interval-widen iv amount)
248 (cons (- (car iv) amount)
249 (+ (cdr iv) amount)))
252 (define-public (interval-union i1 i2)
253 (cons (min (car i1) (car i2))
254 (max (cdr i1) (cdr i2))))
257 (define-public (write-me message x)
258 "Return X. Display MESSAGE and write X. Handy for debugging, possibly turned off."
259 (display message) (write x) (newline) x)
262 (define (index-cell cell dir)
267 (define (cons-map f x)
268 "map F to contents of X"
269 (cons (f (car x)) (f (cdr x))))
272 (define-public (list-insert-separator lst between)
273 "Create new list, inserting BETWEEN between elements of LIST"
277 (cons x (cons between y))
279 (fold-right conc #f lst))
288 (define-public (!= l r)
291 (define-public (ly:load x)
293 (fn (%search-load-path x))
296 (if (ly:get-option 'verbose)
297 (format (current-error-port) "[~A]" fn))
298 (primitive-load fn)))
301 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
303 (use-modules (scm output-tex)
305 (scm output-ascii-script)
307 (scm output-sodipodi)
313 ("tex" . ("TeX output. The default output form." ,tex-output-expression))
314 ("ps" . ("Direct postscript. Requires setting GS_LIB and GS_FONTPATH" ,ps-output-expression))
315 ("scm" . ("Scheme dump: debug scheme molecule expressions" ,write))
316 ("as" . ("Asci-script. Postprocess with as2txt to get ascii art" ,as-output-expression))
317 ("sketch" . ("Bare bones Sketch output." ,sketch-output-expression))
318 ("sodipodi" . ("Bare bones Sodipodi output." ,sodipodi-output-expression))
319 ("pdftex" . ("PDFTeX output. Was last seen nonfunctioning." ,pdftex-output-expression))
323 (define (document-format-dumpers)
326 (display (string-append (pad-string-to 5 (car x)) (cadr x) "\n"))
330 (define-public (find-dumper format )
332 ((d (assoc format output-alist)))
336 (scm-error "Could not find dumper for format ~s" format))
339 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
344 '("define-music-types.scm"
347 "chord-ignatzek-names.scm"
349 "chord-generic-names.scm"
353 "music-functions.scm"
354 "define-music-properties.scm"
358 "define-translator-properties.scm"
359 "translation-functions.scm"
369 "define-grob-properties.scm"
371 "define-grob-interfaces.scm"
378 (set! type-p-name-alist
380 (,boolean-or-symbol? . "boolean or symbol")
381 (,boolean? . "boolean")
383 (,grob-list? . "list of grobs")
384 (,input-port? . "input port")
385 (,integer? . "integer")
387 (,ly:context? . "context")
388 (,ly:dimension? . "dimension, in staff space")
389 (,ly:dir? . "direction")
390 (,ly:duration? . "duration")
391 (,ly:grob? . "grob (GRaphical OBject)")
392 (,ly:input-location? . "input location")
393 (,ly:input-location? . "input location")
394 (,ly:moment? . "moment")
395 (,ly:music? . "music")
396 (,ly:pitch? . "pitch")
397 (,ly:translator? . "translator")
398 (,markup-list? . "list of markups")
399 (,markup? . "markup")
400 (,music-list? . "list of music")
401 (,number-or-grob? . "number or grob")
402 (,number-or-string? . "number or string")
403 (,number-pair? . "pair of numbers")
404 (,number? . "number")
405 (,output-port? . "output port")
407 (,procedure? . "procedure")
408 (,scheme? . "any type")
409 (,string? . "string")
410 (,symbol? . "symbol")
411 (,vector? . "vector")