]> git.donarmstrong.com Git - lilypond.git/blob - scm/output-lib.scm
* VERSION (MY_PATCH_LEVEL): make 1.7.0
[lilypond.git] / scm / output-lib.scm
1 ;;;; output-lib.scm -- implement Scheme output helper functions
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 ; Tablature functions, by Jiba (jiba@tuxfamily.org)
9
10 ; The TabNoteHead stem attachment function.
11 (define (tablature-stem-attachment-function style duration)
12   (cons 0.0 0.5) ;; UGH!
13 )
14
15 ; The TabNoteHead molecule callback.
16 ; Create a text molecule
17 (define (tablature-molecule-callback grob)
18   (let ((molecule (fontify-text
19                    (ly-get-default-font grob)
20                    (ly-get-grob-property grob 'text)
21                    )))
22     molecule ; return the molecule.
23     )
24   )
25
26 ; The TabNoteHead tablatureFormat callback.
27 ; Compute the text grob-property
28 (define (fret-number-tablature-format string tuning pitch)
29   (number->string
30    (- (pitch-semitones pitch)
31       (list-ref tuning
32                 (- string 1) ; remove 1 because list index starts at 0 and guitar string at 1.
33                 )
34       )
35    )
36   )
37
38 (define (hammer-molecule-callback grob)
39   (let* ((note-collums (ly-get-grob-property grob 'note-columns))
40          (note-column1 (cadr note-collums))
41          (note-column2 (car  note-collums))
42          (note1        (car (ly-get-grob-property note-column1 'note-heads)))
43          (note2        (car (ly-get-grob-property note-column2 'note-heads)))
44          (fret1        (string->number (ly-get-grob-property note1 'text)))
45          (fret2        (string->number (ly-get-grob-property note2 'text)))
46          (letter       (if (< fret1 fret2) "H"
47                        (if (> fret1 fret2) "P"
48                                            "")))
49          )
50     (let ((slur (Slur::brew_molecule grob))
51           (text (fontify-text (ly-get-default-font grob) letter)))
52     
53       (let ((x (/ (- (cdr (ly-get-molecule-extent slur 0)) 
54                      (/ (cdr (ly-get-molecule-extent text 0)) 2.0)
55                      )
56                   -2.0)))
57       
58         (ly-set-molecule-extent! text 0 (cons x x))
59         (ly-align-to! text 0 1)
60         )
61       
62       (ly-combine-molecule-at-edge slur 1 1 text -0.6)
63       )
64     )
65   )
66
67
68
69 (define guitar-tunings '(4 -1 -5 -10 -15 -20))
70
71 ; end of tablature functions
72
73
74 (define (make-molecule-boxer line-thick x-padding y-padding callback)
75    "Makes a routine that adds a box around the grob parsed as argument"
76   (define (molecule-boxer grob)
77   (let*
78    (
79     (mol    (callback grob))
80     (x-ext (widen-interval (ly-get-molecule-extent mol 0) x-padding))
81     (y-ext (widen-interval (ly-get-molecule-extent mol 1) y-padding))
82     (x-rule (box-molecule (widen-interval x-ext line-thick)
83                               (cons 0 line-thick)))
84     (y-rule (box-molecule (cons 0 line-thick) y-ext))
85     )
86     
87     (set! mol (ly-combine-molecule-at-edge mol 0 1 y-rule x-padding))
88     (set! mol (ly-combine-molecule-at-edge mol 0 -1  y-rule x-padding))
89     (set! mol (ly-combine-molecule-at-edge mol 1 1  x-rule 0))  
90     (set! mol (ly-combine-molecule-at-edge mol 1 -1 x-rule 0))
91     
92     mol
93  ))
94  molecule-boxer
95  )
96
97
98 (define (arg->string arg)
99   (cond ((number? arg) (inexact->string arg 10))
100         ((string? arg) (string-append "\"" arg "\""))
101         ((symbol? arg) (string-append "\"" (symbol->string arg) "\""))))
102
103 ;; ugh: naming.
104 (define (func name . args)
105   (string-append 
106    "(" name 
107    (if (null? args) 
108        ""
109        (apply string-append 
110               (map (lambda (x) (string-append " " (arg->string x))) args)))
111    ")\n"))
112
113
114 ;;(define (mm-to-pt x)
115 ;;  (* (/ 72.27 25.40) x))
116
117 ;; do nothing in .scm output
118 (define (comment s) "")
119
120 (define (numbers->string l)
121   (apply string-append (map ly-number->string l)))
122
123 ; (define (chop-decimal x) (if (< (abs x) 0.001) 0.0 x))
124
125 (define (number->octal-string x)
126   (let* ((n (inexact->exact x))
127          (n64 (quotient n 64))
128          (n8 (quotient (- n (* n64 64)) 8)))
129     (string-append
130      (number->string n64)
131      (number->string n8)
132      (number->string (remainder (- n (+ (* n64 64) (* n8 8))) 8)))))
133
134 (define (inexact->string x radix)
135   (let ((n (inexact->exact x)))
136     (number->string n radix)))
137
138
139 (define (control->string c)
140   (string-append (number->string (car c)) " "
141                  (number->string (cdr c)) " "))
142
143 (define (font i)
144   (string-append
145    "font"
146    (make-string 1 (integer->char (+ (char->integer #\A) i)))))
147
148 (define (scm-scm action-name)
149   1)
150
151
152 ;; silly, use alist? 
153 (define (find-notehead-symbol duration style)
154   (case style
155    ((xcircle) "2xcircle")
156    ((harmonic) "0neo_mensural")
157    ((baroque) 
158     ;; Oops, I actually would not call this "baroque", but, for
159     ;; backwards compatibility to 1.4, this is supposed to take
160     ;; brevis, longa and maxima from the neo-mensural font and all
161     ;; other note heads from the default font.  -- jr
162     (if (< duration 0)
163         (string-append (number->string duration) "neo_mensural")
164         (number->string duration)))
165    ((mensural)
166     (string-append (number->string duration) (symbol->string style)))
167    ((neo_mensural)
168     (string-append (number->string duration) (symbol->string style)))
169    ((default)
170     ;; The default font in mf/feta-bolletjes.mf defines a brevis, but
171     ;; neither a longa nor a maxima.  Hence let us, for the moment,
172     ;; take these from the neo-mensural font.  TODO: mf/feta-bolletjes
173     ;; should define at least a longa for the default font.  The longa
174     ;; should look exactly like the brevis of the default font, but
175     ;; with a stem exactly like that of the quarter note. -- jr
176     (if (< duration -1)
177         (string-append (number->string duration) "neo_mensural")
178         (number->string duration)))
179    (else
180     (if (string-match "vaticana*|hufnagel*|medicaea*" (symbol->string style))
181         (symbol->string style)
182         (string-append (number->string (max 0 duration))
183                        (symbol->string style))))))
184
185
186 (define (note-head-style->attachment-coordinates style duration)
187   "Return pair (X . Y), containing multipliers for the note head
188 bounding box, where to attach the stem. e.g.: X==0 means horizontally
189 centered, X==1 is at the right, X == -1 is at the left."
190
191   (case style
192     ((default)
193      (if (< duration -1)
194          '(0.0 . 0.6) ;; neo-mensural
195          '(1.0 . 0.5) ;; default
196          ))
197     ((cross) '(1.0 . 0.75))
198     ((mensural) '(0.0 . 0.6))
199     ((neo_mensural) '(0.0 . 0.6))
200     ((diamond) '(1.0 . 0.8))
201     ((transparent) '(1.0 . 1.0))
202     ((slash) '(1.0 . 1.0))
203     ((harmonic) '(1.0 0.0))
204     ((triangle) '(0.75 . 0.15))
205     ((baroque)
206      (if (< duration 0)
207          '(0.0 . 0.6) ;; neo-mensural
208          '(1.0 . 0.5) ;; default
209          ))
210     (else
211
212      ;; this also works for easy notation.
213      '(1.0 . 0.0)
214      )))
215
216 (define (string-encode-integer i)
217   (cond
218    ((= i  0) "o")
219    ((< i 0)   (string-append "n" (string-encode-integer (- i))))
220    (else (string-append
221           (make-string 1 (integer->char (+ 65 (modulo i 26))))
222           (string-encode-integer (quotient i 26))))))
223
224
225 (define ((every-nth-bar-number-visible n) barnum) (= 0 (modulo barnum n)))
226
227 (define (default-bar-number-visibility barnum) (> barnum 1))