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."
145 ;; - generate this list by registering the output-backend-commands
146 ;; output-backend-commands should have docstrings.
147 ;; - remove hard copies in output-ps output-tex
148 (define-public (ly:all-output-backend-commands)
149 "Return list of output backend commands."
158 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
164 "define-music-types.scm"
167 "chord-ignatzek-names.scm"
169 "chord-generic-names.scm"
173 "music-functions.scm"
175 "define-music-properties.scm"
181 "define-context-properties.scm"
182 "translation-functions.scm"
192 "define-markup-commands.scm"
193 "define-grob-properties.scm"
195 "define-grob-interfaces.scm"
206 (set! type-p-name-alist
208 (,boolean-or-symbol? . "boolean or symbol")
209 (,boolean? . "boolean")
211 (,grob-list? . "list of grobs")
212 (,hash-table? . "hash table")
213 (,input-port? . "input port")
214 (,integer? . "integer")
216 (,ly:context? . "context")
217 (,ly:dimension? . "dimension, in staff space")
218 (,ly:dir? . "direction")
219 (,ly:duration? . "duration")
220 (,ly:grob? . "layout object")
221 (,ly:input-location? . "input location")
222 (,ly:moment? . "moment")
223 (,ly:music? . "music")
224 (,ly:pitch? . "pitch")
225 (,ly:translator? . "translator")
226 (,ly:font-metric? . "font metric")
227 (,markup-list? . "list of markups")
228 (,markup? . "markup")
229 (,ly:music-list? . "list of music")
230 (,number-or-grob? . "number or grob")
231 (,number-or-string? . "number or string")
232 (,number-pair? . "pair of numbers")
233 (,number? . "number")
234 (,output-port? . "output port")
236 (,procedure? . "procedure")
237 (,scheme? . "any type")
238 (,string? . "string")
239 (,symbol? . "symbol")
240 (,vector? . "vector")
246 (define gc-protect-stat-count 0)
247 (define-public (dump-gc-protects)
248 (set! gc-protect-stat-count (1+ gc-protect-stat-count) )
251 (hash-table->alist (ly:protects))
253 (< (object-address (car a))
254 (object-address (car b))))))
255 (outfile (open-file (string-append
256 "gcstat-" (number->string gc-protect-stat-count)
260 (display "DUMPING...\n")
263 (lambda (x) (not (symbol? x)))
271 (map object->string (list (object-address x) c x))
278 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
280 (define-public (ly:system command)
285 (string-append command (if (ly:get-option 'verbose)
287 " > /dev/null 2>&1 "))))
289 (if (ly:get-option 'verbose)
290 (format (current-error-port) (_ "Invoking `~a'...\n") command))
292 (set! status (system silenced))
295 (format (current-error-port)
296 (_ "Error invoking `~a'. Return value ~a") silenced status)
297 (newline (current-error-port))))))
299 (define-public (sanitize-command-option str)
302 (regexp-substitute/global #f "[^- 0-9,.a-zA-Z'\"\\]" str 'pre 'post)
305 (define-public (postscript->pdf papersizename name)
306 (let* ((cmd (string-append "ps2pdf "
309 (sanitize-command-option papersizename)
312 (pdf-name (string-append (basename name ".ps") ".pdf" )))
314 (if (access? pdf-name W_OK)
315 (delete-file pdf-name))
317 (format (current-error-port) (_ "Converting to `~a'...") pdf-name)
320 (define-public (postscript->png resolution name)
323 "ps2png --resolution="
324 (if (number? resolution)
325 (number->string resolution)
327 (if (ly:get-option 'verbose)
333 (define-public (lilypond-main files)
334 "Entry point for LilyPond."
336 (handler (lambda (key arg) (set! failed (cons arg failed)))))
339 (catch 'ly-file-failed (lambda () (ly:parse-file f)) handler)
340 ;;; (dump-gc-protects)
346 (newline (current-error-port))
347 (display (_ "error: failed files: ") (current-error-port))
348 (display (string-join failed) (current-error-port))
349 (newline (current-error-port))
350 (newline (current-error-port))