Backup des projets privés
[nenuvar.git] / common / catalogue.ily
blob1b7c13bfb4f447e810ad95543dd9190cc1d238bb
1 \version "2.15.0"
2 \include "common/common.ily"
4 #(use-modules (ice-9 optargs))
6 #(define-markup-command (column layout props args) (markup-list?)
7    #:properties ((baseline-skip))
8    (let ((arg-stencils (interpret-markup-list layout props args)))
9      (stack-lines -1 0.0 0
10                   (space-lines baseline-skip
11                                (remove ly:stencil-empty? arg-stencils)))))
13 #(define (print-score key name title . rest)
14    (markup #:hspace 5 "⁃" title))
16 #(define* (print-opus title #:key description key opus url main parts)
17    (let ((title-markup (make-fontsize-markup
18                         1
19                         (make-concat-markup
20                          (append! (if opus
21                                       (list (markup #:fontsize -2 #:concat ("[" opus "]")
22                                                     #:hspace 1))
23                                       (list))
24                                   (list (markup #:italic title))))))
25          (descr-markup (make-column-markup (if description (list description) (list))))
26          (books-markup (make-column-markup
27                          (if main
28                              (map (lambda (book-spec)
29                                     (markup #:hspace 3 (cadr book-spec)))
30                                   (filter cadr main))
31                              (list))))
32          (parts-markup (make-column-markup
33                          (if parts
34                              (cons (markup #:hspace 3 "Parties séparées :")
35                                    (map (lambda (part-spec)
36                                           (apply print-score key part-spec))
37                                         parts))
38                              (list))))
39          (url-markup (make-column-markup
40                       (if url
41                           (list (markup #:fontsize -2 #:with-url url #:typewriter url))
42                           (list)))))
43      (markup #:force-line-width-ratio 0.45
44              #:column (#:fontsize 1 title-markup
45                                   descr-markup
46                                   books-markup
47                                   parts-markup
48                                   url-markup
49                                   #:vspace 1))))
51 #(define-markup-command (composer-section layout props composer-works) (list?)
52    #:properties ((column-number 2)
53                  (inter-column-padding 6))
54    (let* ((title-item (car composer-works))
55           (items (cadr composer-works))
56           (item-stencils
57            (map (lambda (item)
58                   (interpret-markup layout props
59                                     (apply print-opus item)))
60                 items))
61           (title-stencil
62            (if (null? title-item)
63                empty-stencil
64                (interpret-markup
65                 layout props
66                 (markup #:column (#:fill-line (#:fontsize 3 #:italic title-item) #:vspace 0.5)))))
67           (total-height (reduce + 0 (map (lambda (stencil)
68                                            (interval-length (ly:stencil-extent stencil Y)))
69                                          item-stencils)))
70           (average-height (/ total-height column-number)))
71      (let fill-columns ((lines item-stencils)
72                         (current-column-index 1)
73                         (current-column-height 0)
74                         (current-column-lines '())
75                         (previous-columns '()))
76        (if (null? lines)
77            ;; the end result: the section title and the items on several columns
78            (stack-lines
79             DOWN 0 0
80             (list title-stencil
81                   (stack-stencil-line
82                    0
83                    (reverse! (if current-column-lines
84                                  (cons (stack-lines
85                                         DOWN 0 0
86                                         (reverse! current-column-lines))
87                                        previous-columns)
88                                  previous-columns)))))
89            ;; go on collecting the item stencils into columns
90            (let* ((line (car lines))
91                   (height (interval-length (ly:stencil-extent line Y))))
92              (if (and (< current-column-index column-number)
93                       (>= (+ current-column-height height) average-height))
94                  ;; this line ends filling this column
95                  ;; => start a new column after it
96                  (fill-columns (cdr lines)
97                                (1+ current-column-index)
98                                0
99                                '()
100                                (cons (ly:make-stencil
101                                       "" (cons 0 inter-column-padding) '(0 . 0))
102                                      (cons (stack-lines
103                                             DOWN 0 0
104                                             (reverse! (cons line current-column-lines)))
105                                            previous-columns)))
106                  ;; there is still room in this column
107                  ;; => go on filling it
108                  (fill-columns (cdr lines)
109                                current-column-index
110                                (+ current-column-height height)
111                                (cons line current-column-lines)
112                                previous-columns)))))))
114 #(define-markup-list-command (catalog layout props catalog) (list?)
115    (interpret-markup-list
116     layout props
117     (make-column-lines-markup-list
118      (map (lambda (composer-works)
119             (markup #:composer-section composer-works))
120           catalog))))
123 %%% Makefile generation
126 #(define* (print-makefile-score is-part key name title #:key score-file options part)
127    (let ((target (format #f "~a~a"
128                          key
129                          (if name (format #f "-~a" name) "")))
130          (output (format #f "$(OUTPUT_DIR)/~a~a"
131                            (basename key)
132                            (if name (format #f "-~a" name) "")))
133          (all-options (cond (is-part
134                              (format #f "-dpart=~a ~a"
135                                      (or part name) (or options "")))
136                             (options options)
137                             (else "")))
138          (ly-file (format #f "~a/~a"
139                            key
140                           (or score-file
141                               (if is-part "part.ly" "main.ly")))))
142      (format #t "# ~a
144         $(LILYPOND_CMD) \\
145         -o ~a ~a \\
146         ~a
147 .PHONY: ~a~%"
148              (or title name) target output all-options ly-file target)
149      (cons target (format #f "~a.pdf" output))))
151 #(define* (print-makefile-opus title #:key description key opus url main parts)
152    (let* ((split-path (string-split key #\/))
153           (delivery-dir (format #f "$(DELIVERY_DIR)/~a/~a"
154                                 (car split-path)
155                                 (car (reverse split-path)))))
156      (format #t "### ~a~%" title)
157      (let ((pdfs '())
158            (score-targets '()))
159        (if main
160            (for-each (lambda (book-spec)
161                        (let ((target+pdf (apply print-makefile-score #f key book-spec)))
162                          (set! pdfs (cons (cdr target+pdf) pdfs))
163                          (set! score-targets (cons (car target+pdf) score-targets))))
164                      main))
165        (if parts
166            (for-each (lambda (part-spec)
167                        (let ((target+pdf (apply print-makefile-score #t key part-spec)))
168                          (set! pdfs (cons (cdr target+pdf) pdfs))
169                          (set! score-targets (cons (car target+pdf) score-targets))))
170                      parts))
171        (set! pdfs (reverse! pdfs))
172        (set! score-targets (reverse! score-targets))
173        ;; -delivery rule: PDF, MIDI archive, source archive
174        (format #t "~%~a-delivery:
175         @mkdir -p ~a~{~%~a~}
176         @if [ -e $(OUTPUT_DIR)/~a-1.midi ]; then tar zcf ~a/~a-midi.tar.gz $(OUTPUT_DIR)/~a.midi $(OUTPUT_DIR)/~a-[0-9]*.midi; elif [ -e $(OUTPUT_DIR)/~a.midi ]; then cp $(OUTPUT_DIR)/~a.midi ~a/ ; fi
177         git archive --prefix=~a/ HEAD ~a common out templates Makefile README | gzip > ~a/~a.tar.gz~%"
178                key
179                delivery-dir
180                (map (lambda (pdf)
181                       (format #f "      @if [ -e ~a ]; then mv -fv ~a ~a; fi" pdf pdf delivery-dir))
182                     pdfs)
183                (basename key) delivery-dir (basename key) (basename key) (basename key)
184                (basename key) (basename key) delivery-dir
185                (basename key) key delivery-dir (basename key))
186        ;; -backup rule, for source archive (used for non-public projects)
187        (format #t "~%~a-backup:
188         git archive --prefix=~a/ HEAD ~a | gzip > ~~/Google\\ Drive/backup/~a.tar.gz~%"
189                key
190                (basename key) key (basename key))
191        ;; -clean rule
192        (format #t "~%~a-clean:
193         @rm -f $(OUTPUT_DIR)/~a-* $(OUTPUT_DIR)/~a.*~%"
194                key (basename key) (basename key))
195        ;; -all rule
196        (format #t "~%~a-all:~{ \\~%     ~a~}\\
197         ~a-delivery\\
198         ~a-clean
200 .PHONY: ~a-delivery ~a-clean ~a-all~2%"
201                key score-targets key key key key key))))
203 #(define (print-makefile-composer-work composer-work)
204    (format #t "###~%### ~a~%###~%" (car composer-work))
205    (for-each (lambda (opus-spec)
206                (apply print-makefile-opus opus-spec))
207              (cadr composer-work)))
208    
210 #(define-public (export-makefile filename catalog)
211    (format #t "~%Exporting ~a..." filename)
212    (with-output-to-file filename
213      (lambda ()
214        (format #t "### File generated by LilyPond
215 ### run: lilypond catalogue.ly
217 OUTPUT_DIR=out
218 DELIVERY_DIR=delivery
219 LILYPOND_CMD=lilypond --loglevel=WARN -ddelete-intermediate-files -dno-protected-scheme-parsing~2%")
220        (for-each print-makefile-composer-work catalog))))
223 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
225 \header {
226   tagline = ##f
227   longcopyright = ##f