1 ;;;; lily.scm -- toplevel Scheme stuff
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 1998--2005 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)
19 (srfi srfi-13)) ; strings
23 (define-public (myd k v) (display k) (display ": ") (display v) (display ", "))
25 (define-public (print . args)
26 (apply format (cons (current-output-port) args)))
30 ;;; debugging evaluator is slower. This should
31 ;;; have a more sensible default.
33 (if (ly:get-option 'verbose)
36 (debug-enable 'backtrace)
37 (read-enable 'positions)))
41 ;; initialize defaults.
42 (ly:set-option 'command-line-settings
44 (preview-include-book-title . #t)
47 (define-public tex-backend?
48 (member (ly:output-backend) '("texstr" "tex")))
50 (define-public parser #f)
52 (define-public (lilypond-version)
54 (map (lambda (x) (if (symbol? x)
62 ;; cpp hack to get useful error message
63 (define ifdef "First run this through cpp.")
64 (define ifndef "First run this through cpp.")
66 ;; gettext wrapper for guile < 1.7.2
67 (if (defined? 'gettext)
68 (define-public _ gettext)
69 (define-public _ ly:gettext))
71 (define-public (ly:load x)
72 (let* ((file-name (%search-load-path x)))
73 (if (ly:get-option 'verbose)
74 (ly:progress "[~A" file-name))
75 (primitive-load file-name)
76 (if (ly:get-option 'verbose)
79 (define-public TEX_STRING_HASHLIMIT 10000000)
81 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
83 (define (type-check-list location signature arguments)
84 "Typecheck a list of arguments against a list of type
85 predicates. Print a message at LOCATION if any predicate failed."
86 (define (recursion-helper signature arguments count)
87 (define (helper pred? arg count)
94 #f (_ "wrong type for argument ~a. Expecting ~a, found ~s")
95 count (type-name pred?) arg))
101 (and (helper (car signature) (car arguments) count)
102 (recursion-helper (cdr signature) (cdr arguments) (1+ count)))))
103 (recursion-helper signature arguments 1))
105 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
109 ;;(define-public (output-framework) (write "hello\n"))
111 (define output-tex-module
112 (make-module 1021 (list (resolve-interface '(scm output-tex)))))
113 (define output-ps-module
114 (make-module 1021 (list (resolve-interface '(scm output-ps)))))
116 (define-public (ps-output-expression expr port)
117 (display (eval expr output-ps-module) port))
119 ;; TODO: generate this list by registering the stencil expressions
120 ;; stencil expressions should have docstrings.
121 (define-public (ly:all-stencil-expressions)
122 "Return list of stencil expressions."
150 ;; - generate this list by registering the output-backend-commands
151 ;; output-backend-commands should have docstrings.
152 ;; - remove hard copies in output-ps output-tex
153 (define-public (ly:all-output-backend-commands)
154 "Return list of output backend commands."
162 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
163 ;; Safe definitions utility
164 (define safe-objects (list))
166 (define-macro (define-safe-public arglist . body)
167 "Define a variable, export it, and mark it as safe, ie usable in LilyPond safe mode.
168 The syntax is the same as `define*-public'."
169 (define (get-symbol arg)
171 (get-symbol (car arg))
173 (let ((safe-symbol (get-symbol arglist)))
175 (define*-public ,arglist
177 (set! safe-objects (cons (cons ',safe-symbol ,safe-symbol)
182 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
189 "define-music-types.scm"
192 "chord-ignatzek-names.scm"
194 "chord-generic-names.scm"
198 "music-functions.scm"
200 "define-music-properties.scm"
206 "define-context-properties.scm"
207 "translation-functions.scm"
217 "define-markup-commands.scm"
218 "define-grob-properties.scm"
220 "define-grob-interfaces.scm"
225 "backend-library.scm"
228 ;; must be after everything has been defined
232 (set! type-p-name-alist
234 (,boolean-or-symbol? . "boolean or symbol")
235 (,boolean? . "boolean")
237 (,grob-list? . "list of grobs")
238 (,hash-table? . "hash table")
239 (,input-port? . "input port")
240 (,integer? . "integer")
242 (,ly:context? . "context")
243 (,ly:dimension? . "dimension, in staff space")
244 (,ly:dir? . "direction")
245 (,ly:duration? . "duration")
246 (,ly:grob? . "layout object")
247 (,ly:input-location? . "input location")
248 (,ly:moment? . "moment")
249 (,ly:music? . "music")
250 (,ly:pitch? . "pitch")
251 (,ly:translator? . "translator")
252 (,ly:font-metric? . "font metric")
253 (,markup-list? . "list of markups")
254 (,markup? . "markup")
255 (,ly:music-list? . "list of music")
256 (,number-or-grob? . "number or grob")
257 (,number-or-string? . "number or string")
258 (,number-pair? . "pair of numbers")
259 (,number? . "number")
260 (,output-port? . "output port")
262 (,procedure? . "procedure")
263 (,scheme? . "any type")
264 (,string? . "string")
265 (,symbol? . "symbol")
266 (,vector? . "vector")))
271 (define gc-protect-stat-count 0)
272 (define-public (dump-gc-protects)
273 (set! gc-protect-stat-count (1+ gc-protect-stat-count))
274 (let* ((protects (sort
275 (hash-table->alist (ly:protects))
277 (< (object-address (car a))
278 (object-address (car b))))))
279 (out-file-name (string-append
280 "gcstat-" (number->string gc-protect-stat-count)
282 (outfile (open-file out-file-name "w")))
284 (display "Dumping gc protected objs to ...\n")
287 (lambda (x) (not (symbol? x)))
294 (map object->string (list (object-address x) c x))
301 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
303 (define-public (lilypond-main files)
304 "Entry point for LilyPond."
306 (handler (lambda (key failed-file)
307 (set! failed (append (list failed-file) failed)))))
308 ;;(handler (lambda (key . arg) (set! failed (append arg failed)))))
311 (catch 'ly-file-failed
312 (lambda () (ly:parse-file f))
313 (lambda (x . args) (handler x f)))
314 ;;(lambda (x) (handler x f)))
320 (ly:error (_ "failed files: ~S") (string-join failed))
322 ;; HACK: be sure to exit with single newline
326 (define-public (tweak-grob-property grob sym val)
327 (set! (ly:grob-property grob sym) val))