]> git.donarmstrong.com Git - lilypond.git/blob - scm/lily.scm
eace878d5cc2d42de765eaeb1bf24197982a335a
[lilypond.git] / scm / lily.scm
1 ;;;; lily.scm -- implement Scheme output routines for TeX and PostScript
2 ;;;;
3 ;;;;  source file of the GNU LilyPond music typesetter
4 ;;;; 
5 ;;;; (c) 1998--2001 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
7
8 ;;; Library functions
9
10 (use-modules (ice-9 regex))
11
12 ;;(write standalone (current-error-port))
13
14
15 ;;; General settings
16 ;; debugging evaluator is slower.
17
18 (debug-enable 'debug)
19 ;(debug-enable 'backtrace)
20 (read-enable 'positions)
21
22
23 (define-public (line-column-location line col file)
24   "Print an input location, including column number ."
25   (string-append (number->string line) ":"
26                  (number->string col) " " file)
27   )
28
29 (define-public (line-location line col file)
30   "Print an input location, without column number ."
31   (string-append (number->string line) " " file)
32   )
33
34 ;; cpp hack to get useful error message
35 (define ifdef "First run this through cpp.")
36 (define ifndef "First run this through cpp.")
37
38
39 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
40
41 (define-public X 0)
42 (define-public Y 1)
43 (define-public START -1)
44 (define-public STOP 1)
45 (define-public LEFT -1)
46 (define-public RIGHT 1)
47 (define-public UP 1)
48 (define-public DOWN -1)
49 (define-public CENTER 0)
50
51 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
52 ;; lily specific variables.
53 (define-public default-script-alist '())
54
55 (define-public security-paranoia #f)
56 (if (not (defined? 'standalone))
57     (define-public standalone (not (defined? 'ly-gulp-file))))
58
59
60 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
61 ;;; Unassorted utility functions.
62
63 (define (uniqued-alist  alist acc)
64   (if (null? alist) acc
65       (if (assoc (caar alist) acc)
66           (uniqued-alist (cdr alist) acc)
67           (uniqued-alist (cdr alist) (cons (car alist) acc)))))
68
69 (define (other-axis a)
70   (remainder (+ a 1) 2))
71   
72
73 (define-public (widen-interval iv amount)
74    (cons (- (car iv) amount)
75          (+ (cdr iv) amount))
76 )
77
78
79
80 (define (index-cell cell dir)
81   (if (equal? dir 1)
82       (cdr cell)
83       (car cell)))
84
85 (define (cons-map f x)
86   "map F to contents of X"
87   (cons (f (car x)) (f (cdr x))))
88
89 ;; used where?
90 (define-public (reduce operator list)
91   "reduce OP [A, B, C, D, ... ] =
92    A op (B op (C ... ))
93 "
94       (if (null? (cdr list)) (car list)
95           (operator (car list) (reduce operator (cdr list)))))
96
97 (define (take-from-list-until todo gathered crit?)
98   "return (G, T), where (reverse G) + T = GATHERED + TODO, and the last of G
99 is the  first to satisfy CRIT
100
101  (take-from-list-until '(1 2 3  4 5) '() (lambda (x) (eq? x 3)))
102 =>
103  ((3 2 1) 4 5)
104
105 "
106   (if (null? todo)
107       (cons gathered todo)
108       (if (crit? (car todo))
109           (cons (cons (car todo) gathered) (cdr todo))
110           (take-from-list-until (cdr todo) (cons (car todo) gathered) crit?)
111       )
112   ))
113
114 (define (sign x)
115   (if (= x 0)
116       0
117       (if (< x 0) -1 1)))
118
119 (define (write-me n x)
120   (display n)
121   (write x)
122   (newline)
123   x)
124
125 (define (!= l r)
126   (not (= l r)))
127
128 (define-public (filter-list pred? list)
129   "return that part of LIST for which PRED is true."
130   (if (null? list) '()
131       (let* ((rest  (filter-list pred? (cdr list))))
132         (if (pred?  (car list))
133             (cons (car list)  rest)
134             rest))))
135
136 (define-public (filter-out-list pred? list)
137   "return that part of LIST for which PRED is true."
138   (if (null? list) '()
139       (let* ((rest  (filter-list pred? (cdr list))))
140         (if (not (pred?  (car list)))
141             (cons (car list)  rest)
142             rest))))
143
144 (define-public (uniqued-alist  alist acc)
145   (if (null? alist) acc
146       (if (assoc (caar alist) acc)
147           (uniqued-alist (cdr alist) acc)
148           (uniqued-alist (cdr alist) (cons (car alist) acc)))))
149
150 (define-public (uniq-list list)
151   (if (null? list) '()
152       (if (null? (cdr list))
153           list
154           (if (equal? (car list) (cadr list))
155               (uniq-list (cdr list))
156               (cons (car list) (uniq-list (cdr list)))))))
157
158 (define-public (alist<? x y)
159   (string<? (symbol->string (car x))
160             (symbol->string (car y))))
161
162 (define-public (pad-string-to str wid)
163   (string-append str (make-string (max (- wid (string-length str)) 0) #\ ))
164   )
165
166 (define-public (ly-load x)
167   (let* ((fn (%search-load-path x)))
168     (if (ly-verbose)
169         (format (current-error-port) "[~A]" fn))
170     (primitive-load fn)))
171
172
173 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
174 ;;  output
175 (use-modules (scm tex)
176              (scm ps)
177              (scm pysk)
178              (scm ascii-script)
179              (scm sketch)
180              (scm pdftex)
181              )
182
183 (define output-alist
184   `(
185     ("tex" . ("TeX output. The default output form." ,tex-output-expression))
186     ("ps" . ("Direct postscript. Requires setting GS_LIB and GS_FONTPATH" ,ps-output-expression))
187     ("scm" . ("Scheme dump: debug scheme molecule expressions" ,write))
188     ("as" . ("Asci-script. Postprocess with as2txt to get ascii art"  ,as-output-expression))
189     ("sketch" . ("Bare bones Sketch output. Requires sketch 0.7" ,sketch-output-expression))
190     ("pdftex" . ("PDFTeX output. Was last seen nonfunctioning." ,pdftex-output-expression))
191     ))
192
193
194 (define (document-format-dumpers)
195   (map
196    (lambda (x)
197      (display (string-append  (pad-string-to 5 (car x)) (cadr x) "\n"))
198      output-alist)
199    ))
200
201 (define-public (find-dumper format )
202   (let*
203       ((d (assoc format output-alist)))
204     
205     (if (pair? d)
206         (caddr d)
207         (scm-error "Could not find dumper for format ~s" format))
208     ))
209
210 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
211 ;; other files.
212
213 (if (not standalone)
214     (map ly-load
215                                         ; load-from-path
216          '("music-types.scm"
217            "output-lib.scm"
218            "c++.scm"
219            "molecule.scm"
220            "bass-figure.scm"
221            "grob-property-description.scm"
222            "context-description.scm"
223            "interface-description.scm"
224            "beam.scm"
225            "clef.scm"
226            "slur.scm"
227            "font.scm"
228            "music-functions.scm"
229            "music-property-description.scm"
230            "auto-beam.scm"
231            "basic-properties.scm"
232            "chord-name.scm"
233            "grob-description.scm"
234            "translator-property-description.scm"
235            "script.scm"
236            "drums.scm"
237            "midi.scm"
238            )))
239