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