]> git.donarmstrong.com Git - lilypond.git/blob - scm/output-lib.scm
jiba tab
[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)
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                    (string-append
21                     (number->string
22                      (- (pitch-semitones (ly-get-mus-property (ly-get-grob-property grob 'cause) 'pitch))
23                         (list-ref
24                          (ly-get-grob-property grob 'string-tunings)
25                          (- (ly-get-grob-property grob 'tab-string)
26                             1 ; remove 1 because list index starts at 0 and guitar string at 1.
27                             ))
28                         )
29                      )
30                     )
31                    )))
32     molecule ; return the molecule.
33     )
34   )
35
36 ; end of tablature functions
37
38
39 (define (arg->string arg)
40   (cond ((number? arg) (inexact->string arg 10))
41         ((string? arg) (string-append "\"" arg "\""))
42         ((symbol? arg) (string-append "\"" (symbol->string arg) "\""))))
43
44 ;; ugh: naming.
45 (define (func name . args)
46   (string-append 
47    "(" name 
48    (if (null? args) 
49        ""
50        (apply string-append 
51               (map (lambda (x) (string-append " " (arg->string x))) args)))
52    ")\n"))
53
54
55 ;;(define (mm-to-pt x)
56 ;;  (* (/ 72.27 25.40) x))
57
58 ;; do nothing in .scm output
59 (define (comment s) "")
60
61 (define (numbers->string l)
62   (apply string-append (map ly-number->string l)))
63
64 ; (define (chop-decimal x) (if (< (abs x) 0.001) 0.0 x))
65
66 (define (number->octal-string x)
67   (let* ((n (inexact->exact x))
68          (n64 (quotient n 64))
69          (n8 (quotient (- n (* n64 64)) 8)))
70     (string-append
71      (number->string n64)
72      (number->string n8)
73      (number->string (remainder (- n (+ (* n64 64) (* n8 8))) 8)))))
74
75 (define (inexact->string x radix)
76   (let ((n (inexact->exact x)))
77     (number->string n radix)))
78
79
80 (define (control->string c)
81   (string-append (number->string (car c)) " "
82                  (number->string (cdr c)) " "))
83
84 (define (font i)
85   (string-append
86    "font"
87    (make-string 1 (integer->char (+ (char->integer #\A) i)))))
88
89 (define (scm-scm action-name)
90   1)
91
92
93 ;; silly, use alist? 
94 (define (find-notehead-symbol duration style)
95   (case style
96    ((xcircle) "2xcircle")
97    ((harmonic) "0neo_mensural")
98    ((baroque) 
99     (string-append (number->string duration)
100                    (if (< duration 0) "neo_mensural" "")))
101    ((mensural) (string-append (number->string duration) (symbol->string style)))
102    ((neo_mensural) (string-append (number->string duration) (symbol->string style)))
103    ((default) (number->string duration))
104    (else
105     (string-append (number->string (max 0 duration)) (symbol->string style)))))
106
107
108 (define (note-head-style->attachment-coordinates style)
109   "Return pair (X . Y), containing multipliers for the note head
110 bounding box, where to attach the stem. e.g.: X==0 means horizontally
111 centered, X==1 is at the right, X == -1 is at the left."
112
113   (case style
114     ((default) '(1.0 . 0.5))
115     ((cross) '(1.0 . 0.75))
116     ((mensural) '(0.0 . 0.6))
117     ((neo_mensural) '(0.0 . 0.6))
118     ((diamond) '(1.0 . 0.8))
119     ((transparent) '(1.0 . 1.0))
120     ((slash) '(1.0 . 1.0))
121     ((harmonic) '(1.0 0.0))
122     ((triangle) '(0.75 . 0.15))
123     (else
124
125      ;; this also works for easy notation.
126      '(1.0 . 0.0)
127      )))
128                      
129 (define (string-encode-integer i)
130   (cond
131    ((= i  0) "o")
132    ((< i 0)   (string-append "n" (string-encode-integer (- i))))
133    (else (string-append
134           (make-string 1 (integer->char (+ 65 (modulo i 26))))
135           (string-encode-integer (quotient i 26))))))
136
137
138
139
140