1 ;;;; lily.scm -- toplevel Scheme stuff
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 1998--2004 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 (if (defined? 'set-debug-cell-accesses!)
10 (set-debug-cell-accesses! #f))
12 ;;(set-debug-cell-accesses! 5000)
14 (use-modules (ice-9 regex)
18 (srfi srfi-13)) ; strings
22 (define-public (myd k v) (display k) (display ": ") (display v) (display ", "))
24 (define-public (print . args)
25 (apply format (cons (current-output-port) args)))
29 ;;; debugging evaluator is slower. This should
30 ;;; have a more sensible default.
32 (if (ly:get-option 'verbose)
35 (debug-enable 'backtrace)
36 (read-enable 'positions)))
38 (define-public (line-column-location file line col)
39 "Print an input location, including column number ."
40 (string-append (number->string line) ":"
41 (number->string col) " " file))
43 (define-public (line-location file line col)
44 "Print an input location, without column number ."
45 (string-append (number->string line) " " file))
47 (define-public point-and-click #f)
49 (define-public parser #f)
51 (define-public (lilypond-version)
53 (map (lambda (x) (if (symbol? x)
61 ;; cpp hack to get useful error message
62 (define ifdef "First run this through cpp.")
63 (define ifndef "First run this through cpp.")
65 ;; gettext wrapper for guile < 1.7.2
66 (if (defined? 'gettext)
67 (define-public _ gettext)
68 (define-public _ ly:gettext))
70 (define-public (ly:load x)
71 (let* ((fn (%search-load-path x)))
72 (if (ly:get-option 'verbose)
73 (format (current-error-port) "[~A]" fn))
76 (define-public TEX_STRING_HASHLIMIT 10000000)
78 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
80 (define (type-check-list location signature arguments)
81 "Typecheck a list of arguments against a list of type
82 predicates. Print a message at LOCATION if any predicate failed."
83 (define (recursion-helper signature arguments count)
84 (define (helper pred? arg count)
88 (ly:input-message location
90 (_ "wrong type for argument ~a. Expecting ~a, found ~s")
91 count (type-name pred?) arg))
97 (and (helper (car signature) (car arguments) count)
98 (recursion-helper (cdr signature) (cdr arguments) (1+ count)))))
99 (recursion-helper signature arguments 1))
101 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
105 ;;(define-public (output-framework) (write "hello\n"))
107 (define output-tex-module
108 (make-module 1021 (list (resolve-interface '(scm output-tex)))))
109 (define output-ps-module
110 (make-module 1021 (list (resolve-interface '(scm output-ps)))))
112 (define-public (ps-output-expression expr port)
113 (display (eval expr output-ps-module) port))
115 ;; TODO: generate this list by registering the stencil expressions
116 ;; stencil expressions should have docstrings.
117 (define-public (ly:all-stencil-expressions)
118 "Return list of stencil expressions."
143 ;; - generate this list by registering the output-backend-commands
144 ;; output-backend-commands should have docstrings.
145 ;; - remove hard copies in output-ps output-tex
146 (define-public (ly:all-output-backend-commands)
147 "Return list of output backend commands."
155 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
161 "define-music-types.scm"
164 "chord-ignatzek-names.scm"
166 "chord-generic-names.scm"
170 "music-functions.scm"
172 "define-music-properties.scm"
178 "define-context-properties.scm"
179 "translation-functions.scm"
189 "define-markup-commands.scm"
190 "define-grob-properties.scm"
192 "define-grob-interfaces.scm"
202 (set! type-p-name-alist
204 (,boolean-or-symbol? . "boolean or symbol")
205 (,boolean? . "boolean")
207 (,grob-list? . "list of grobs")
208 (,hash-table? . "hash table")
209 (,input-port? . "input port")
210 (,integer? . "integer")
212 (,ly:context? . "context")
213 (,ly:dimension? . "dimension, in staff space")
214 (,ly:dir? . "direction")
215 (,ly:duration? . "duration")
216 (,ly:grob? . "layout object")
217 (,ly:input-location? . "input location")
218 (,ly:moment? . "moment")
219 (,ly:music? . "music")
220 (,ly:pitch? . "pitch")
221 (,ly:translator? . "translator")
222 (,ly:font-metric? . "font metric")
223 (,markup-list? . "list of markups")
224 (,markup? . "markup")
225 (,ly:music-list? . "list of music")
226 (,number-or-grob? . "number or grob")
227 (,number-or-string? . "number or string")
228 (,number-pair? . "pair of numbers")
229 (,number? . "number")
230 (,output-port? . "output port")
232 (,procedure? . "procedure")
233 (,scheme? . "any type")
234 (,string? . "string")
235 (,symbol? . "symbol")
236 (,vector? . "vector")))
241 (define gc-protect-stat-count 0)
242 (define-public (dump-gc-protects)
243 (set! gc-protect-stat-count (1+ gc-protect-stat-count))
244 (let* ((protects (sort
245 (hash-table->alist (ly:protects))
247 (< (object-address (car a))
248 (object-address (car b))))))
249 (out-file-name (string-append
250 "gcstat-" (number->string gc-protect-stat-count)
252 (outfile (open-file out-file-name "w")))
254 (display "Dumping gc protected objs to ...\n")
257 (lambda (x) (not (symbol? x)))
264 (map object->string (list (object-address x) c x))
271 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
273 (define-public (ly:system command)
277 (string-append command (if (ly:get-option 'verbose)
279 " > /dev/null 2>&1 "))))
281 (if (ly:get-option 'verbose)
282 (format (current-error-port) (_ "Invoking `~a'...\n") command))
284 (set! status (system silenced))
287 (format (current-error-port)
288 (_ "Error invoking `~a'. Return value ~a") silenced status)
289 (newline (current-error-port))))))
291 (define-public (sanitize-command-option str)
294 (regexp-substitute/global #f "[^- 0-9,.a-zA-Z'\"\\]" str 'pre 'post)
297 (define-public (postscript->pdf papersizename name)
298 (let* ((cmd (string-append "ps2pdf "
301 (sanitize-command-option papersizename)
304 (pdf-name (string-append (basename name ".ps") ".pdf" )))
306 (if (access? pdf-name W_OK)
307 (delete-file pdf-name))
309 (format (current-error-port) (_ "Converting to `~a'...") pdf-name)
312 (define-public (postscript->png resolution name)
313 (let ((cmd (string-append
314 "ps2png --resolution="
315 (if (number? resolution)
316 (number->string resolution)
318 (if (ly:get-option 'verbose)
324 (define-public (lilypond-main files)
325 "Entry point for LilyPond."
327 (handler (lambda (key arg) (set! failed (cons arg failed)))))
330 (catch 'ly-file-failed (lambda () (ly:parse-file f)) handler)
337 (newline (current-error-port))
338 (display (_ "error: failed files: ") (current-error-port))
339 (display (string-join failed) (current-error-port))
340 (newline (current-error-port))
341 (newline (current-error-port))
345 (define-public (tweak-grob-property grob sym val)
346 (set! (ly:grob-property grob sym) val))