]> git.donarmstrong.com Git - lilypond.git/blob - scm/output-lib.scm
*** empty log message ***
[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 1.0)
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 ; end of tablature functions
39
40
41 (define (arg->string arg)
42   (cond ((number? arg) (inexact->string arg 10))
43         ((string? arg) (string-append "\"" arg "\""))
44         ((symbol? arg) (string-append "\"" (symbol->string arg) "\""))))
45
46 ;; ugh: naming.
47 (define (func name . args)
48   (string-append 
49    "(" name 
50    (if (null? args) 
51        ""
52        (apply string-append 
53               (map (lambda (x) (string-append " " (arg->string x))) args)))
54    ")\n"))
55
56
57 ;;(define (mm-to-pt x)
58 ;;  (* (/ 72.27 25.40) x))
59
60 ;; do nothing in .scm output
61 (define (comment s) "")
62
63 (define (numbers->string l)
64   (apply string-append (map ly-number->string l)))
65
66 ; (define (chop-decimal x) (if (< (abs x) 0.001) 0.0 x))
67
68 (define (number->octal-string x)
69   (let* ((n (inexact->exact x))
70          (n64 (quotient n 64))
71          (n8 (quotient (- n (* n64 64)) 8)))
72     (string-append
73      (number->string n64)
74      (number->string n8)
75      (number->string (remainder (- n (+ (* n64 64) (* n8 8))) 8)))))
76
77 (define (inexact->string x radix)
78   (let ((n (inexact->exact x)))
79     (number->string n radix)))
80
81
82 (define (control->string c)
83   (string-append (number->string (car c)) " "
84                  (number->string (cdr c)) " "))
85
86 (define (font i)
87   (string-append
88    "font"
89    (make-string 1 (integer->char (+ (char->integer #\A) i)))))
90
91 (define (scm-scm action-name)
92   1)
93
94
95 ;; silly, use alist? 
96 (define (find-notehead-symbol duration style)
97   (case style
98    ((xcircle) (cons "2xcircle" "music"))
99    ((harmonic) (cons "0neo_mensural" "music"))
100    ((baroque) 
101     ;; Oops, I actually would not call this "baroque", but, for
102     ;; backwards compatibility to 1.4, this is supposed to take
103     ;; brevis, longa and maxima from the neo-mensural font and all
104     ;; other note heads from the default font.  -- jr
105     (if (< duration 0)
106         (cons (string-append (number->string duration) "neo_mensural") "ancient")
107         (cons (number->string duration) "music")))
108    ((mensural)
109     (cons (string-append (number->string duration) (symbol->string style))
110      "ancient"))
111    ((neo_mensural)
112     (cons (string-append (number->string duration) (symbol->string style))
113      "ancient"))
114    ((default)
115     ;; The default font in mf/feta-bolletjes.mf defines a brevis, but
116     ;; neither a longa nor a maxima.  Hence let us, for the moment,
117     ;; take these from the neo-mensural font.  TODO: mf/feta-bolletjes
118     ;; should define at least a longa for the default font.  The longa
119     ;; should look exactly like the brevis of the default font, but
120     ;; with a stem exactly like that of the quarter note. -- jr
121     (if (< duration -1)
122         (cons (string-append (number->string duration) "neo_mensural") "ancient")
123         (cons (number->string duration) "music")))
124    (else
125     (cons (string-append (number->string (max 0 duration)) (symbol->string style))
126      "music"))))
127
128
129 (define (note-head-style->attachment-coordinates style duration)
130   "Return pair (X . Y), containing multipliers for the note head
131 bounding box, where to attach the stem. e.g.: X==0 means horizontally
132 centered, X==1 is at the right, X == -1 is at the left."
133
134   (case style
135     ((default)
136      (if (< duration -1)
137          '(0.0 . 0.6) ;; neo-mensural
138          '(1.0 . 0.5) ;; default
139          ))
140     ((cross) '(1.0 . 0.75))
141     ((mensural) '(0.0 . 0.6))
142     ((neo_mensural) '(0.0 . 0.6))
143     ((diamond) '(1.0 . 0.8))
144     ((transparent) '(1.0 . 1.0))
145     ((slash) '(1.0 . 1.0))
146     ((harmonic) '(1.0 0.0))
147     ((triangle) '(0.75 . 0.15))
148     ((baroque)
149      (if (< duration 0)
150          '(0.0 . 0.6) ;; neo-mensural
151          '(1.0 . 0.5) ;; default
152          ))
153     (else
154
155      ;; this also works for easy notation.
156      '(1.0 . 0.0)
157      )))
158                      
159 (define (string-encode-integer i)
160   (cond
161    ((= i  0) "o")
162    ((< i 0)   (string-append "n" (string-encode-integer (- i))))
163    (else (string-append
164           (make-string 1 (integer->char (+ 65 (modulo i 26))))
165           (string-encode-integer (quotient i 26))))))
166
167
168
169
170