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