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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
78 (define (type-check-list location signature arguments)
79 "Typecheck a list of arguments against a list of type
80 predicates. Print a message at LOCATION if any predicate failed."
81 (define (recursion-helper signature arguments count)
82 (define (helper pred? arg count)
86 (ly:input-message location
88 (_ "wrong type for argument ~a. Expecting ~a, found ~s")
89 count (type-name pred?) arg))
95 (and (helper (car signature) (car arguments) count)
96 (recursion-helper (cdr signature) (cdr arguments) (1+ count)))))
97 (recursion-helper signature arguments 1))
99 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
103 ;;(define-public (output-framework) (write "hello\n"))
105 (define output-tex-module
106 (make-module 1021 (list (resolve-interface '(scm output-tex)))))
107 (define output-ps-module
108 (make-module 1021 (list (resolve-interface '(scm output-ps)))))
110 (define-public (ps-output-expression expr port)
111 (display (eval expr output-ps-module) port))
113 ;; TODO: generate this list by registering the stencil expressions
114 ;; stencil expressions should have docstrings.
115 (define-public (ly:all-stencil-expressions)
116 "Return list of stencil expressions."
139 ;; - generate this list by registering the output-backend-commands
140 ;; output-backend-commands should have docstrings.
141 ;; - remove hard copies in output-ps output-tex
142 (define-public (ly:all-output-backend-commands)
143 "Return list of output backend commands."
151 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
157 "define-music-types.scm"
160 "chord-ignatzek-names.scm"
162 "chord-generic-names.scm"
166 "music-functions.scm"
168 "define-music-properties.scm"
174 "define-context-properties.scm"
175 "translation-functions.scm"
185 "define-markup-commands.scm"
186 "define-grob-properties.scm"
188 "define-grob-interfaces.scm"
198 (set! type-p-name-alist
200 (,boolean-or-symbol? . "boolean or symbol")
201 (,boolean? . "boolean")
203 (,grob-list? . "list of grobs")
204 (,hash-table? . "hash table")
205 (,input-port? . "input port")
206 (,integer? . "integer")
208 (,ly:context? . "context")
209 (,ly:dimension? . "dimension, in staff space")
210 (,ly:dir? . "direction")
211 (,ly:duration? . "duration")
212 (,ly:grob? . "layout object")
213 (,ly:input-location? . "input location")
214 (,ly:moment? . "moment")
215 (,ly:music? . "music")
216 (,ly:pitch? . "pitch")
217 (,ly:translator? . "translator")
218 (,ly:font-metric? . "font metric")
219 (,markup-list? . "list of markups")
220 (,markup? . "markup")
221 (,ly:music-list? . "list of music")
222 (,number-or-grob? . "number or grob")
223 (,number-or-string? . "number or string")
224 (,number-pair? . "pair of numbers")
225 (,number? . "number")
226 (,output-port? . "output port")
228 (,procedure? . "procedure")
229 (,scheme? . "any type")
230 (,string? . "string")
231 (,symbol? . "symbol")
232 (,vector? . "vector")))
237 (define gc-protect-stat-count 0)
238 (define-public (dump-gc-protects)
239 (set! gc-protect-stat-count (1+ gc-protect-stat-count) )
240 (let* ((protects (sort
241 (hash-table->alist (ly:protects))
243 (< (object-address (car a))
244 (object-address (car b))))))
245 (out-file-name (string-append
246 "gcstat-" (number->string gc-protect-stat-count)
248 (outfile (open-file out-file-name "w")))
250 (display "Dumping gc protected objs to ...\n")
253 (lambda (x) (not (symbol? x)))
260 (map object->string (list (object-address x) c x))
267 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
269 (define-public (ly:system command)
273 (string-append command (if (ly:get-option 'verbose)
275 " > /dev/null 2>&1 "))))
277 (if (ly:get-option 'verbose)
278 (format (current-error-port) (_ "Invoking `~a'...\n") command))
280 (set! status (system silenced))
283 (format (current-error-port)
284 (_ "Error invoking `~a'. Return value ~a") silenced status)
285 (newline (current-error-port))))))
287 (define-public (sanitize-command-option str)
290 (regexp-substitute/global #f "[^- 0-9,.a-zA-Z'\"\\]" str 'pre 'post)
293 (define-public (postscript->pdf papersizename name)
294 (let* ((cmd (string-append "ps2pdf "
297 (sanitize-command-option papersizename)
300 (pdf-name (string-append (basename name ".ps") ".pdf" )))
302 (if (access? pdf-name W_OK)
303 (delete-file pdf-name))
305 (format (current-error-port) (_ "Converting to `~a'...") pdf-name)
308 (define-public (postscript->png resolution name)
309 (let ((cmd (string-append
310 "ps2png --resolution="
311 (if (number? resolution)
312 (number->string resolution)
314 (if (ly:get-option 'verbose)
320 (define-public (lilypond-main files)
321 "Entry point for LilyPond."
323 (handler (lambda (key arg) (set! failed (cons arg failed)))))
326 (catch 'ly-file-failed (lambda () (ly:parse-file f)) handler)
333 (newline (current-error-port))
334 (display (_ "error: failed files: ") (current-error-port))
335 (display (string-join failed) (current-error-port))
336 (newline (current-error-port))
337 (newline (current-error-port))
341 (define-public (tweak-grob-property grob sym val)
342 (set! (ly:grob-property grob sym) val))