1 ;;;; lily.scm -- implement Scheme output routines for TeX and PostScript
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>
11 (if (defined? 'set-debug-cell-accesses!)
12 (set-debug-cell-accesses! #f))
14 ;(set-debug-cell-accesses! 5000)
16 (use-modules (ice-9 regex)
20 (srfi srfi-13)) ; strings
25 (define-public (myd k v) (display k) (display ": ") (display v) (display ", "))
27 (define-public (print . args)
28 (apply format (cons (current-output-port) args)))
32 ;;; debugging evaluator is slower. This should
33 ;;; have a more sensible default.
35 (if (ly:get-option 'verbose)
38 (debug-enable 'backtrace)
39 (read-enable 'positions)))
41 (define-public (line-column-location file line col)
42 "Print an input location, including column number ."
43 (string-append (number->string line) ":"
44 (number->string col) " " file))
46 (define-public (line-location file line col)
47 "Print an input location, without column number ."
48 (string-append (number->string line) " " file))
50 (define-public point-and-click #f)
52 (define-public parser #f)
54 (define-public (lilypond-version)
56 (map (lambda (x) (if (symbol? x)
64 ;; cpp hack to get useful error message
65 (define ifdef "First run this through cpp.")
66 (define ifndef "First run this through cpp.")
68 ;; gettext wrapper for guile < 1.7.2
69 (if (defined? 'gettext)
70 (define-public _ gettext)
71 (define-public _ ly:gettext))
73 (define-public (ly:load x)
74 (let* ((fn (%search-load-path x)))
75 (if (ly:get-option 'verbose)
76 (format (current-error-port) "[~A]" fn))
79 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
81 (define (type-check-list location signature arguments)
82 "Typecheck a list of arguments against a list of type
83 predicates. Print a message at LOCATION if any predicate failed."
84 (define (recursion-helper signature arguments count)
85 (define (helper pred? arg count)
89 (ly:input-message location
91 (_ "wrong type for argument ~a. Expecting ~a, found ~s")
92 count (type-name pred?) arg))
98 (and (helper (car signature) (car arguments) count)
99 (recursion-helper (cdr signature) (cdr arguments) (1+ count)))
101 (recursion-helper signature arguments 1))
103 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
107 ;;(define-public (output-framework) (write "hello\n"))
109 (define output-tex-module
110 (make-module 1021 (list (resolve-interface '(scm output-tex)))))
111 (define output-ps-module
112 (make-module 1021 (list (resolve-interface '(scm output-ps)))))
114 (define-public (ps-output-expression expr port)
115 (display (eval expr output-ps-module) port))
117 ;; TODO: generate this list by registering the stencil expressions
118 ;; stencil expressions should have docstrings.
119 (define-public (ly:all-stencil-expressions)
120 "Return list of stencil expressions."
146 ;; - generate this list by registering the output-backend-commands
147 ;; output-backend-commands should have docstrings.
148 ;; - remove hard copies in output-ps output-tex
149 (define-public (ly:all-output-backend-commands)
150 "Return list of output backend commands."
159 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
165 "define-music-types.scm"
168 "chord-ignatzek-names.scm"
170 "chord-generic-names.scm"
174 "music-functions.scm"
176 "define-music-properties.scm"
182 "define-context-properties.scm"
183 "translation-functions.scm"
193 "define-markup-commands.scm"
194 "define-grob-properties.scm"
196 "define-grob-interfaces.scm"
207 (set! type-p-name-alist
209 (,boolean-or-symbol? . "boolean or symbol")
210 (,boolean? . "boolean")
212 (,grob-list? . "list of grobs")
213 (,hash-table? . "hash table")
214 (,input-port? . "input port")
215 (,integer? . "integer")
217 (,ly:context? . "context")
218 (,ly:dimension? . "dimension, in staff space")
219 (,ly:dir? . "direction")
220 (,ly:duration? . "duration")
221 (,ly:grob? . "layout object")
222 (,ly:input-location? . "input location")
223 (,ly:moment? . "moment")
224 (,ly:music? . "music")
225 (,ly:pitch? . "pitch")
226 (,ly:translator? . "translator")
227 (,ly:font-metric? . "font metric")
228 (,markup-list? . "list of markups")
229 (,markup? . "markup")
230 (,ly:music-list? . "list of music")
231 (,number-or-grob? . "number or grob")
232 (,number-or-string? . "number or string")
233 (,number-pair? . "pair of numbers")
234 (,number? . "number")
235 (,output-port? . "output port")
237 (,procedure? . "procedure")
238 (,scheme? . "any type")
239 (,string? . "string")
240 (,symbol? . "symbol")
241 (,vector? . "vector")
247 (define gc-protect-stat-count 0)
248 (define-public (dump-gc-protects)
249 (set! gc-protect-stat-count (1+ gc-protect-stat-count) )
252 (hash-table->alist (ly:protects))
254 (< (object-address (car a))
255 (object-address (car b))))))
256 (outfile (open-file (string-append
257 "gcstat-" (number->string gc-protect-stat-count)
261 (display "DUMPING...\n")
264 (lambda (x) (not (symbol? x)))
272 (map object->string (list (object-address x) c x))
279 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
281 (define-public (ly:system command)
286 (string-append command (if (ly:get-option 'verbose)
288 " > /dev/null 2>&1 "))))
290 (if (ly:get-option 'verbose)
291 (format (current-error-port) (_ "Invoking `~a'...\n") command))
293 (set! status (system silenced))
296 (format (current-error-port)
297 (_ "Error invoking `~a'. Return value ~a") silenced status)
298 (newline (current-error-port))))))
300 (define-public (sanitize-command-option str)
303 (regexp-substitute/global #f "[^- 0-9,.a-zA-Z'\"\\]" str 'pre 'post)
306 (define-public (postscript->pdf papersizename name)
307 (let* ((cmd (string-append "ps2pdf "
311 (sanitize-command-option papersizename)
314 (pdf-name (string-append (basename name ".ps") ".pdf" )))
316 (if (access? pdf-name W_OK)
317 (delete-file pdf-name))
319 (format (current-error-port) (_ "Converting to `~a'...") pdf-name)
322 (define-public (postscript->png resolution name)
325 "ps2png --resolution="
326 (if (number? resolution)
327 (number->string resolution)
329 (if (ly:get-option 'verbose)
335 (define-public (lilypond-main files)
336 "Entry point for LilyPond."
338 (handler (lambda (key arg) (set! failed (cons arg failed)))))
341 (catch 'ly-file-failed (lambda () (ly:parse-file f)) handler)
342 ;;; (dump-gc-protects)
348 (newline (current-error-port))
349 (display (_ "error: failed files: ") (current-error-port))
350 (display (string-join failed) (current-error-port))
351 (newline (current-error-port))
352 (newline (current-error-port))