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