1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 1998--2012 Jan Nieuwenhuizen <janneke@gnu.org>
4 ;;;; Han-Wen Nienhuys <hanwen@xs4all.nl>
6 ;;;; LilyPond is free software: you can redistribute it and/or modify
7 ;;;; it under the terms of the GNU General Public License as published by
8 ;;;; the Free Software Foundation, either version 3 of the License, or
9 ;;;; (at your option) any later version.
11 ;;;; LilyPond is distributed in the hope that it will be useful,
12 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;;; GNU General Public License for more details.
16 ;;;; You should have received a copy of the GNU General Public License
17 ;;;; along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
19 ;; Internationalisation: (_i "to be translated") gets an entry in the
20 ;; POT file; (gettext ...) must be invoked explicitly to do the actual
23 ;; (define-macro (_i x) x)
24 ;; (define-macro-public _i (x) x)
25 ;; (define-public-macro _i (x) x)
28 (defmacro-public _i (x) x)
30 ;;; Boolean thunk - are we integrating Guile V2.0 or higher with LilyPond?
31 (define-public (guile-v2)
32 (string>? (version) "1.9.10"))
34 (read-enable 'positions)
38 (debug-enable 'backtrace)
39 (debug-set! show-file-name #t)))
41 (define-public PLATFORM
44 (car (string-tokenize (utsname:sysname (uname)))))))
47 ;; Session-handling variables and procedures.
49 ;; A "session" corresponds to one .ly file processed on a LilyPond
50 ;; command line. Every session gets to see a reasonably fresh state
51 ;; of LilyPond and should work independently from previous files.
53 ;; Session management relies on cooperation, namely the user not
54 ;; trying to change variables and data structures internal to
55 ;; LilyPond. It is not proof against in-place modification of data
56 ;; structures (as they are just reinitialized with the original
57 ;; identities), and it is not proof against tampering with internals.
59 ;; As a consequence, session management is not sufficient for
60 ;; separating multiple independent .ly files in "-dsafe" mode: you
61 ;; should give each its own LilyPond process when reliable separation
64 ;; For standard tasks and programming practices, multiple sessions in
65 ;; the same LilyPond job should work reasonably independently and
66 ;; without "bleed-over" while still loading and compiling the
67 ;; relevant .scm and .ly files only once.
70 (define lilypond-declarations '())
71 (define after-session-hook (make-hook))
73 (define-public (call-after-session thunk)
74 (if (ly:undead? lilypond-declarations)
75 (ly:error (_ "call-after-session used after session start")))
76 (add-hook! after-session-hook thunk #t))
78 (defmacro-public define-session (name value)
79 "This defines a variable @var{name} with the starting value
80 @var{value} that is reinitialized at the start of each session.
81 A@tie{}session basically corresponds to one LilyPond file on the
82 command line. The value is recorded at the start of the first session
83 after loading all initialization files and before loading the user
84 file and is reinstated for all of the following sessions. This
85 happens just by replacing the value, not by copying structures, so you
86 should not destructively modify them. For example, lists defined in
87 this manner should be changed within a session only be adding material
88 to their front or replacing them altogether, not by modifying parts of
89 them. It is an error to call @code{define-session} after the first
91 (define (add-session-variable name value)
92 (if (ly:undead? lilypond-declarations)
93 (ly:error (_ "define-session used after session start")))
94 (let ((var (make-variable value)))
95 (module-add! (current-module) name var)
96 (set! lilypond-declarations (cons var lilypond-declarations))))
97 `(,add-session-variable ',name ,value))
99 (defmacro-public define-session-public (name value)
100 "Like @code{define-session}, but also exports @var{name}."
102 (define-session ,name ,value)
105 (define (session-terminate)
106 (if (ly:undead? lilypond-declarations)
109 (lambda (p) (variable-set! (cadr p) (cddr p)))
110 (ly:get-undead lilypond-declarations))
111 (run-hook after-session-hook))))
113 (define lilypond-interfaces #f)
115 (define-public (session-initialize thunk)
116 "Initialize this session. The first session in a LilyPond run is
117 initialized by calling @var{thunk}, then recording the values of all
118 variables in the current module as well as those defined with
119 @code{define-session}. Subsequent calls of @code{session-initialize}
120 ignore @var{thunk} and instead just reinitialize all recorded
121 variables to their value after the initial call of @var{thunk}."
123 ;; We need to save the variables of the current module along with
124 ;; their values: functions defined in the module might refer to the
127 ;; The entries in lilypond-declarations consist of a cons* consisting
128 ;; of symbol, variable, and value. Variables defined with
129 ;; define-session have the symbol set to #f.
131 (if (ly:undead? lilypond-declarations)
133 (module-use-interfaces! (current-module) (reverse lilypond-interfaces))
138 (variable-set! var val)
140 (module-add! (current-module) (car p) var))))
141 (ly:get-undead lilypond-declarations)))
144 (set! lilypond-interfaces
145 (filter (lambda (m) (eq? 'interface (module-kind m)))
146 (module-uses (current-module))))
147 (let ((decl (map! (lambda (v)
148 (cons* #f v (variable-ref v)))
149 lilypond-declarations)))
152 (let ((val (variable-ref v)))
153 (if (not (ly:lily-parser? val))
159 (set! lilypond-declarations (ly:make-undead decl))))))
161 (define scheme-options-definitions
165 ;; - [subject-]object-object-verb +"ing"
166 ;; - [subject-]-verb-object-object
168 ;; Avoid overlong lines in `lilypond -dhelp'! Strings should not
169 ;; be longer than 48 characters per line.
172 "Render at higher resolution (using given factor)
173 and scale down result to prevent jaggies in
177 "Create .tex, .texi, .count files in the
181 "Select backend. Possible values: 'eps, 'null,
182 'ps, 'scm, 'socket, 'svg.")
183 (check-internal-types
185 "Check every property assignment for types.")
188 "Generate cut-out snippets of a score.")
191 "LilyPond prefix for data files (read-only).")
194 "Dump memory debugging statistics.")
195 (debug-gc-assert-parsed-dead
197 "For memory debugging: Ensure that all
198 references to parsed objects are dead. This is
199 an internal option, and is switched on
200 automatically for `-ddebug-gc'.")
203 "Debug the flex lexer.")
204 (debug-page-breaking-scoring
206 "Dump scores for many different page breaking
210 "Debug the bison parser.")
211 (debug-property-callbacks
213 "Debug cyclic callback chains.")
217 (delete-intermediate-files
219 "Delete unusable, intermediate PostScript files.")
222 "Dump memory and time information for each file.")
225 "Dump timing information (system-dependent).")
228 "Dump output signatures of each system. Used for
229 regression testing.")
232 "Pad left edge of the output EPS bounding box by
233 given amount (in mm).")
236 "Load fonts via Ghostscript.")
239 "Load only LilyPond fonts via Ghostscript.")
242 "Run LilyPond from a GUI and redirect stderr to
247 (include-book-title-preview
249 "Include book titles in preview images.")
252 "Include fonts in separate-system EPS files.")
255 "Include file for global settings, included before the score is processed.")
258 "Process in parallel, using the given number of
262 "If string FOO is given as argument, redirect
263 output to log file `FOO.log'.")
266 "Maximum depth for the markup tree. If a markup has more levels,
267 assume it will not terminate on its own, print a warning and return a
268 null markup instead.")
269 (midi-extension ,(if (eq? PLATFORM 'windows)
272 "Set the default file extension for MIDI output
273 file to given string.")
274 (music-strings-to-paths
276 "Convert text strings to paths when glyphs belong
280 "Add point & click links to PDF output.")
283 "Set default paper size.")
286 "Set GhostScript's output format for pixel images.")
289 "Create preview images also.")
292 "Print pages in the normal way.")
293 (protected-scheme-parsing
295 "Continue when errors in inline scheme are caught
296 in the parser. If #f, halt on errors and print
298 (profile-property-accesses
300 "Keep statistics of get_property() calls.")
303 "Set resolution for generating PNG pixmaps to
304 given value (in dpi).")
307 "Specify name of a file which contains a list of
308 input files to be processed.")
311 "When processing an \\include command, look for
312 the included file relative to the current file\
313 \n(instead of the root file)")
316 "Run in safer mode.")
319 "For input files `FILE1.ly', `FILE2.ly', ...
320 output log data to files `FILE1.log',
322 (show-available-fonts
324 "List available font names.")
325 (strict-infinity-checking
327 "Force a crash on encountering Inf and NaN
328 floating point exceptions.")
331 "Don't use directories from input files while
332 constructing output file names.")
335 "Set the PostScript strokeadjust operator explicitly.
336 This employs different drawing primitives, resulting in
337 large PDF file size increases but often markedly better
341 "Use woff font files in SVG backend.")
342 (trace-memory-frequency
344 "Record Scheme cell usage this many times per
345 second. Dump results to `FILE.stacks' and
347 (trace-scheme-coverage
349 "Record coverage of Scheme files in `FILE.cov'.")
350 (verbose ,(ly:verbose-output?)
351 "Verbose output, i.e. loglevel at least DEBUG (read-only).")
354 "Change all warning and programming_error
355 messages into errors.")
358 ;; Need to do this in the beginning. Other parts of the Scheme
359 ;; initialization depend on these options.
361 (for-each (lambda (x)
362 (ly:add-option (car x) (cadr x) (caddr x)))
363 scheme-options-definitions)
365 (for-each (lambda (x)
366 (ly:set-option (car x) (cdr x)))
367 (eval-string (ly:command-line-options)))
371 (if (defined? 'set-debug-cell-accesses!)
372 (set-debug-cell-accesses! #f))
374 ;;(set-debug-cell-accesses! 1000)
376 (use-modules (ice-9 regex)
388 (scm safe-utility-defs))
390 (define-public _ gettext)
391 ;;; There are new modules defined in Guile V2.0 which we need to use.
393 ;; Modules and scheme files loaded by lily.scm use currying
394 ;; in Guile V2 this needs a module which is not present in Guile V1.8
399 (ly:debug (_ "Using (ice-9 curried-definitions) module\n"))
400 (use-modules (ice-9 curried-definitions)))
402 (ly:debug (_ "Guile 1.8\n"))))
404 ;; TODO add in modules for V1.8.7 deprecated in V2.0 and integrated
405 ;; into Guile base code, like (ice-9 syncase).
408 (define-public fancy-format
411 (define-public (ergonomic-simple-format dest . rest)
412 "Like ice-9's @code{format}, but without the memory consumption."
414 (apply simple-format (cons #f (cons dest rest)))
415 (apply simple-format (cons dest rest))))
418 ergonomic-simple-format)
421 (define-public (myd k v)
428 (define-public (print . args)
429 (apply format (cons (current-output-port) args)))
432 ;;; General settings.
434 ;;; Debugging evaluator is slower. This should have a more sensible
438 (if (or (ly:get-option 'verbose)
439 (ly:get-option 'trace-memory-frequency)
440 (ly:get-option 'trace-scheme-coverage))
442 (ly:set-option 'protected-scheme-parsing #f)
443 (debug-enable 'backtrace)
444 (read-enable 'positions)))
446 (if (ly:get-option 'trace-scheme-coverage)
449 (define-public parser #f)
451 (define music-string-to-path-backends
454 (if (memq (ly:get-option 'backend) music-string-to-path-backends)
455 (ly:set-option 'music-strings-to-paths #t))
457 (define-public (ly:load x)
458 (let* ((file-name (%search-load-path x)))
459 (ly:debug "[~A" file-name)
461 (ly:error (_ "cannot find: ~A") x))
462 (primitive-load-path file-name) ;; to support Guile V2 autocompile
463 ;; TODO: Any chance to use ly:debug here? Need to extend it to prevent
464 ;; a newline in this case
465 (if (ly:get-option 'verbose)
466 (ly:progress "]\n"))))
469 (let ((platform (string-tokenize
470 (vector-ref (uname) 0) char-set:letter+digit)))
471 (if (null? (cdr platform)) #f
472 (member (string-downcase (cadr platform)) '("95" "98" "me")))))
475 (if (string-index x #\\)
477 (string-regexp-substitute
479 (string-regexp-substitute "\\\\" "/" x))))
481 (define-public (ly-getcwd)
482 (if (eq? PLATFORM 'windows)
486 (define-public (is-absolute? file-name)
487 (let ((file-name-length (string-length file-name)))
488 (if (= file-name-length 0)
490 (or (eq? (string-ref file-name 0) #\/)
491 (and (eq? PLATFORM 'windows)
492 (> file-name-length 2)
493 (eq? (string-ref file-name 1) #\:)
494 (eq? (string-ref file-name 2) #\/))))))
496 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
497 ;;; If necessary, emulate Guile V2 module_export_all! for Guile V1.8.n
500 (define (module-export-all! mod)
501 (define (fresh-interface!)
502 (let ((iface (make-module)))
503 (set-module-name! iface (module-name mod))
504 ;; for guile 2: (set-module-version! iface (module-version mod))
505 (set-module-kind! iface 'interface)
506 (set-module-public-interface! mod iface)
508 (let ((iface (or (module-public-interface mod)
509 (fresh-interface!))))
510 (set-module-obarray! iface (module-obarray mod))))))
513 (define-safe-public (lilypond-version)
515 (map (lambda (x) (if (symbol? x)
521 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
524 (ly:set-default-scale (ly:make-scale #(0 1 2 5/2 7/2 9/2 11/2)))
526 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
530 ;; List of Scheme files to be loaded into the (lily) module.
532 ;; - Library definitions, need to be at the head of the list
533 (define init-scheme-files-lib
536 ;; - Files containing definitions used later by other files later in load
537 (define init-scheme-files-used
538 '("markup-macros.scm"
539 "parser-ly-from-scheme.scm"))
540 ;; - Main body of files to be loaded
541 (define init-scheme-files-body
543 "define-event-classes.scm"
544 "define-music-callbacks.scm"
545 "define-music-types.scm"
546 "define-note-names.scm"
551 "define-markup-commands.scm"
553 "modal-transforms.scm"
554 "chord-generic-names.scm"
555 "chord-ignatzek-names.scm"
556 "music-functions.scm"
559 "define-music-properties.scm"
560 "time-signature-settings.scm"
564 "ly-syntax-constructors.scm"
566 "define-context-properties.scm"
567 "translation-functions.scm"
581 "define-woodwind-diagrams.scm"
582 "display-woodwind-diagrams.scm"
583 "predefined-fretboards.scm"
584 "define-grob-properties.scm"
586 "define-grob-interfaces.scm"
587 "define-stencil-commands.scm"
588 "scheme-engravers.scm"
593 "backend-library.scm"
595 ;; - Files to be loaded last
596 (define init-scheme-files-tail
597 ;; - must be after everything has been defined
600 ;; Now construct the load list
602 (define init-scheme-files
603 (append init-scheme-files-lib
604 init-scheme-files-used
605 init-scheme-files-body
606 init-scheme-files-tail))
608 (for-each ly:load init-scheme-files)
610 (define-public r5rs-primary-predicates
611 `((,boolean? . "boolean")
612 (,char? . "character")
613 (,number? . "number")
616 (,procedure? . "procedure")
617 (,string? . "string")
618 (,symbol? . "symbol")
619 (,vector? . "vector")))
621 (define-public r5rs-secondary-predicates
622 `((,char-alphabetic? . "alphabetic character")
623 (,char-lower-case? . "lower-case character")
624 (,char-numeric? . "numeric character")
625 (,char-upper-case? . "upper-case character")
626 (,char-whitespace? . "whitespace character")
628 (,complex? . "complex number")
629 (,even? . "even number")
630 (,exact? . "exact number")
631 (,inexact? . "inexact number")
632 (,integer? . "integer")
633 (,negative? . "negative number")
634 (,odd? . "odd number")
635 (,positive? . "positive number")
636 (,rational? . "rational number")
637 (,real? . "real number")
643 (,input-port? . "input port")
644 (,output-port? . "output port")
646 ;; would this ever be used?
647 (,eof-object? . "end-of-file object")
650 (define-public guile-predicates
651 `((,hash-table? . "hash table")
654 (define-public lilypond-scheme-predicates
655 `((,boolean-or-symbol? . "boolean or symbol")
657 (,cheap-list? . "list")
658 (,fraction? . "fraction, as pair")
659 (,grob-list? . "list of grobs")
660 (,index? . "non-negative integer")
661 (,markup? . "markup")
662 (,markup-command-list? . "markup command list")
663 (,markup-list? . "markup list")
664 (,moment-pair? . "pair of moment objects")
665 (,number-list? . "number list")
666 (,number-or-grob? . "number or grob")
667 (,number-or-markup? . "number or markup")
668 (,number-or-pair? . "number or pair")
669 (,number-or-string? . "number or string")
670 (,number-pair? . "pair of numbers")
671 (,number-pair-list? . "list of number pairs")
672 (,rhythmic-location? . "rhythmic location")
673 (,scheme? . "any type")
674 (,string-or-pair? . "string or pair")
675 (,string-or-music? . "string or music")
676 (,string-or-symbol? . "string or symbol")
677 (,symbol-list? . "symbol list")
678 (,symbol-list-or-music? . "symbol list or music")
679 (,symbol-list-or-symbol? . "symbol list or symbol")
683 (define-public lilypond-exported-predicates
684 `((,ly:book? . "book")
686 (,ly:context? . "context")
687 (,ly:context-def? . "context definition")
688 (,ly:context-mod? . "context modification")
689 (,ly:dimension? . "dimension, in staff space")
690 (,ly:dir? . "direction")
691 (,ly:dispatcher? . "dispatcher")
692 (,ly:duration? . "duration")
693 (,ly:event? . "post event")
694 (,ly:font-metric? . "font metric")
695 (,ly:grob? . "graphical (layout) object")
696 (,ly:grob-array? . "array of grobs")
697 (,ly:input-location? . "input location")
699 (,ly:iterator? . "iterator")
700 (,ly:lily-lexer? . "lily-lexer")
701 (,ly:lily-parser? . "lily-parser")
702 (,ly:listener? . "listener")
703 (,ly:moment? . "moment")
704 (,ly:music? . "music")
705 (,ly:music-function? . "music function")
706 (,ly:music-list? . "list of music objects")
707 (,ly:music-output? . "music output")
708 (,ly:otf-font? . "OpenType font")
709 (,ly:output-def? . "output definition")
710 (,ly:page-marker? . "page marker")
711 (,ly:pango-font? . "pango font")
712 (,ly:paper-book? . "paper book")
713 (,ly:paper-system? . "paper-system Prob")
714 (,ly:pitch? . "pitch")
715 (,ly:prob? . "property object")
716 (,ly:score? . "score")
717 (,ly:simple-closure? . "simple closure")
718 (,ly:skyline? . "skyline")
719 (,ly:skyline-pair? . "pair of skylines")
720 (,ly:source-file? . "source file")
721 (,ly:spanner? . "spanner")
722 (,ly:spring? . "spring")
723 (,ly:stencil? . "stencil")
724 (,ly:stream-event? . "stream event")
725 (,ly:translator? . "translator")
726 (,ly:translator-group? . "translator group")
727 (,ly:unpure-pure-container? . "unpure/pure container")
731 (set! type-p-name-alist
732 (append r5rs-primary-predicates
733 r5rs-secondary-predicates
735 lilypond-scheme-predicates
736 lilypond-exported-predicates))
739 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
742 (define (profile-measurements)
745 (list (- (+ (tms:cutime t)
747 (assoc-get 'gc-time-taken stats))
748 (assoc-get 'total-cells-allocated stats 0))))
750 (define (dump-profile base last this)
751 (let* ((outname (format #f "~a.profile" (dir-basename base ".ly")))
752 (diff (map (lambda (y) (apply - y)) (zip this last))))
753 (ly:progress "\nWriting timing to ~a..." outname)
754 (format (open-file outname "w")
755 "time: ~a\ncells: ~a\n"
756 (if (ly:get-option 'dump-cpu-profile)
761 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
762 ;; debug memory leaks
767 (define gc-protect-stat-count
770 ;; Undead objects that should be ignored after the first time round
772 (make-weak-key-hash-table 0))
774 (define-public (dump-live-object-stats outfile)
775 (for-each (lambda (x)
776 (format outfile "~a: ~a\n" (car x) (cdr x)))
777 (sort (gc-live-object-stats)
779 (string<? (car x) (car y))))))
781 (define-public (dump-gc-protects)
782 (set! gc-protect-stat-count (1+ gc-protect-stat-count))
783 (let* ((protects (sort (hash-table->alist (ly:protects))
785 (< (object-address (car a))
786 (object-address (car b))))))
787 (out-file-name (string-append
788 "gcstat-" (number->string gc-protect-stat-count)
790 (outfile (open-file out-file-name "w")))
792 (ly:progress "Dumping GC statistics ~a...\n" out-file-name)
793 (for-each (lambda (y)
796 (format outfile "~a (~a) = ~a\n" (object-address x) c x)))
799 (not (symbol? (car x))))
801 (format outfile "\nprotected symbols: ~a\n"
802 (apply + (map (lambda (obj-count)
803 (if (symbol? (car obj-count))
808 ;; (display (ly:smob-protects))
810 (if (defined? 'gc-live-object-stats)
812 (ly:progress "Live object statistics: GC'ing\n")
816 (ly:progress "Asserting dead objects\n")
817 (ly:set-option 'debug-gc-assert-parsed-dead #t)
819 (ly:set-option 'debug-gc-assert-parsed-dead #f)
822 (if (not (hashq-ref gc-zombies x))
824 (ly:programming-error "Parsed object should be dead: ~a" x)
825 (hashq-set! gc-zombies x #t))))
826 (ly:parsed-undead-list!))
827 (set! stats (gc-live-object-stats))
828 (ly:progress "Dumping live object statistics.\n")
829 (dump-live-object-stats outfile)))
831 (let* ((stats (gc-stats)))
832 (for-each (lambda (sym)
833 (format outfile "~a ~a ~a\n"
834 gc-protect-stat-count
836 (assoc-get sym stats "?")))
837 '(protected-objects bytes-malloced cell-heap-size)))
839 (close-port outfile)))
841 (define (check-memory)
842 "Read `/proc/self' to check up on memory use."
843 (define (gulp-file name)
844 (let* ((file (open-input-file name))
845 (text (read-delimited "" file)))
849 (let* ((stat (gulp-file "/proc/self/status"))
850 (lines (string-split stat #\newline))
851 (interesting (filter-map
853 (string-match "^VmData:[ \t]*([0-9]*) kB" l))
855 (mem (string->number (match:substring (car interesting) 1))))
856 (format #t "VMDATA: ~a\n" mem)
860 (begin (dump-gc-protects)
863 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
865 (define (multi-fork count)
866 "Split this process into COUNT helpers. Returns either a list of
867 PIDs or the number of the process."
868 (define (helper count acc)
870 (let* ((pid (primitive-fork)))
873 (helper (1- count) (cons pid acc))))
878 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
880 (define* (ly:exit status #:optional (silently #f))
881 "Exit function for lilypond"
884 ((0) (ly:basic-progress (_ "Success: compilation successfully completed")))
885 ((1) (ly:warning (_ "Compilation completed with warnings or errors")))
886 (else (ly:message ""))))
889 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
891 (define-public (lilypond-main files)
892 "Entry point for LilyPond."
893 (eval-string (ly:command-line-code))
894 (if (ly:get-option 'help)
895 (begin (ly:option-usage)
897 (if (ly:get-option 'show-available-fonts)
898 (begin (ly:font-config-display-fonts)
900 (if (ly:get-option 'gui)
905 (if (ly:get-option 'read-file-list)
910 (string-split (string-delete (ly:gulp-file f) #\cr) #\nl))
912 (if (and (number? (ly:get-option 'job-count))
913 (>= (length files) (ly:get-option 'job-count)))
914 (let* ((count (ly:get-option 'job-count))
915 (split-todo (split-list files count))
916 (joblist (multi-fork count))
918 (if (not (string-or-symbol? (ly:get-option 'log-file)))
919 (ly:set-option 'log-file "lilypond-multi-run"))
920 (if (number? joblist)
921 (begin (ly:set-option
922 'log-file (format #f "~a-~a"
923 (ly:get-option 'log-file) joblist))
924 (set! files (vector-ref split-todo joblist)))
925 (begin (ly:progress "\nForking into jobs: ~a\n" joblist)
928 (let* ((stat (cdr (waitpid pid))))
931 (acons (list-element-index joblist pid)
938 (logfile (format #f "~a-~a.log"
939 (ly:get-option 'log-file) job))
940 (log (ly:gulp-file logfile))
941 (len (string-length log))
942 (tail (substring log (max 0 (- len 1024)))))
943 (if (status:term-sig state)
946 (format #f (_ "job ~a terminated with signal: ~a")
947 job (status:term-sig state)))
949 (_ "logfile ~a (exit ~a):\n~a")
950 logfile (status:exit-val state) tail))))
953 (ly:error "Children ~a exited with errors."
955 ;; must overwrite individual entries
956 (if (ly:get-option 'dump-profile)
957 (dump-profile "lily-run-total"
958 '(0 0) (profile-measurements)))
963 (if (string-or-symbol? (ly:get-option 'log-file))
964 (ly:stderr-redirect (format #f "~a.log" (ly:get-option 'log-file)) "w"))
965 (let ((failed (lilypond-all files)))
966 (if (ly:get-option 'trace-scheme-coverage)
968 (coverage:show-all (lambda (f)
969 (string-contains f "lilypond")))))
971 (begin (ly:error (_ "failed files: ~S") (string-join failed))
977 (define-public (lilypond-all files)
979 (separate-logs (ly:get-option 'separate-log-files))
982 (if (string-or-symbol? (ly:get-option 'log-file))
983 (open-file (format #f "~a.log" (ly:get-option 'log-file))
986 (do-measurements (ly:get-option 'dump-profile))
987 (handler (lambda (key failed-file)
988 (set! failed (append (list failed-file) failed)))))
992 (let* ((start-measurements (if do-measurements
993 (profile-measurements)
995 (base (dir-basename x ".ly"))
996 (all-settings (ly:all-options)))
998 (ly:stderr-redirect (format #f "~a.log" base) "w"))
1000 (format ping-log "Processing ~a\n" base))
1001 (if (ly:get-option 'trace-memory-frequency)
1002 (mtrace:start-trace (ly:get-option 'trace-memory-frequency)))
1003 (lilypond-file handler x)
1004 (ly:check-expected-warnings)
1006 (if start-measurements
1007 (dump-profile x start-measurements (profile-measurements)))
1008 (if (ly:get-option 'trace-memory-frequency)
1009 (begin (mtrace:stop-trace)
1010 (mtrace:dump-results base)))
1011 (for-each (lambda (s)
1012 (ly:set-option (car s) (cdr s)))
1014 (ly:set-option 'debug-gc-assert-parsed-dead #t)
1016 (ly:set-option 'debug-gc-assert-parsed-dead #f)
1019 (if (not (hashq-ref gc-zombies x))
1021 (ly:programming-error "Parsed object should be dead: ~a" x)
1022 (hashq-set! gc-zombies x #t))))
1023 (ly:parsed-undead-list!))
1024 (if (ly:get-option 'debug-gc)
1026 (ly:reset-all-fonts))
1030 ;; Ensure a notice re failed files is written to aggregate logfile.
1032 (format ping-log "Failed files: ~a\n" failed))
1033 (if (ly:get-option 'dump-profile)
1034 (dump-profile "lily-run-total" '(0 0) (profile-measurements)))
1037 (define (lilypond-file handler file-name)
1038 (catch 'ly-file-failed
1039 (lambda () (ly:parse-file file-name))
1040 (lambda (x . args) (handler x file-name))))
1042 (use-modules (scm editor))
1044 (define-public (gui-main files)
1046 (gui-no-files-handler))
1047 (if (not (string? (ly:get-option 'log-file)))
1048 (let* ((base (dir-basename (car files) ".ly"))
1049 (log-name (string-append base ".log")))
1050 (if (not (ly:get-option 'gui))
1051 (ly:message (_ "Redirecting output to ~a...") log-name))
1052 (ly:stderr-redirect log-name "w")
1053 (ly:message "# -*-compilation-*-"))
1054 (let ((failed (lilypond-all files)))
1058 (ly:stderr-redirect "foo" "r")
1059 (system (get-editor-command log-name 0 0 0))
1060 (ly:error (_ "failed files: ~S") (string-join failed))
1065 (define (gui-no-files-handler)
1066 (let* ((ly (string-append (ly:effective-prefix) "/ly/"))
1067 ;; FIXME: soft-code, localize
1068 (welcome-ly (string-append ly "Welcome_to_LilyPond.ly"))
1069 (cmd (get-editor-command welcome-ly 0 0 0)))
1070 (ly:message (_ "Invoking `~a'...\n") cmd)