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