1 ;------------------------------------------------------------------;
2 ; opus_libre -- 90-makescore.scm ;
4 ; (c) 2008-2010 Valentin Villenave <valentin@villenave.net> ;
6 ; opus_libre is a free framework for GNU LilyPond: you may ;
7 ; redistribute it and/or modify it under the terms of the GNU ;
8 ; General Public License, version 3 or later: gnu.org/licenses ;
10 ;------------------------------------------------------------------;
13 (define current-part #f)
14 (define conf:structure numbers)
16 (define-public (include-ly dir)
17 "Include all LilyPond code found in DIR, recursively."
18 (let ((ly-files (find-files dir ".i?ly$" #t)))
20 (if (string-ci=? conf:local-ly-score
21 (string-take-right x (string-length conf:local-ly-score)))
22 (if (ly:get-option 'debug-messages)
23 (ly:message "Skipping local score file: ~a..." x))
24 (ly:parser-include-string parser (format #f "\\include \"~a\"" x))))
27 (define (alist-reverse alist)
29 (cons (cons (cdr (car alist)) (car (car alist)))
30 (alist-reverse (cdr alist)))))
32 (define (ls-index str lst)
33 (number->string (- (length lst) (length (member str lst)))))
35 (define (eval-skel file)
36 (eval-string (format #f
37 "(define-public (apply-skel arg instr-list)
38 (set! current-part (car arg))
39 (let* ((str (cdr arg))
40 (key (assoc-ref (alist-reverse instr-list) str)))
41 (if (string? key) #{ \\newStaff $key #}
43 (if (not (or (string=? \"\" str) (string=? lang:all)))
44 (if (ly:get-option 'debug-messages)
45 (ly:warning \"Unknown instrument variable;
46 ---> please check your `make' argument.\")))
48 (read-file (open-input-file file)))))
50 (define output-redirect
52 (let* ((orig-filename (if (defined-string? 'book-filename)
54 (ly:parser-output-name parser)))
55 (prefix (if (defined-string? 'conf:output-dir)
56 (string-append conf:output-dir "/")
58 (new-filename (if (defined-string? 'scores)
59 (ly:parser-lookup parser 'scores)
63 (string-append prefix new-filename)))))
66 (define-music-function (parser location arg) (string?)
70 (include-ly score-dir)
71 (let* ((defined-structure (ly:parser-lookup parser 'structure))
72 (struct (cond ((not defined-structure) conf:default-structure)
73 ((string? defined-structure) (list defined-structure))
74 ((list? defined-structure) defined-structure))))
75 (if (string? (member arg struct))
78 (let* ((skel-name (if (string? (find-skel arg)) arg (ly:parser-lookup parser 'skel)))
79 (skel-part (find-skel (string-append skel-name "-" part)))
80 (skel-num (find-skel (string-append skel-name "-" (ls-index part struct)))))
81 (if (string? skel-part) (eval-skel skel-part)
82 (if (string? skel-num) (eval-skel skel-num)
83 (eval-skel (find-skel skel-name))))
85 (let* ((music (apply-skel (cons part arg) lang:instruments))
86 (score (scorify-music music parser))
87 (layout (ly:output-def-clone $defaultlayout))
88 (header (make-module))
89 (title (make-this-text part lang:title-suffix)))
90 (module-define! header 'piece title)
92 (ly:score-set-header! score header)
93 (ly:score-add-output-def! score layout)
94 (add-score parser score)
98 (make-music 'Music 'void #t))))