]> git.donarmstrong.com Git - lilypond.git/blob - scm/c++.scm
release: 1.3.148
[lilypond.git] / scm / c++.scm
1 ;;;; c++.scm -- implement Scheme frontends to C++ 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 ;;; Note: this file can't be used without LilyPond executable
9
10 (define (number-pair?  x)
11   (and (pair? x)
12        (number? (car x)) (number? (cdr x))))
13
14 (define (moment-pair?  x)
15   (and (pair? x)
16        (moment? (car x)) (moment? (cdr x))))
17
18 (define (boolean-or-symbol? x)
19   (or (boolean? x) (symbol? x)))
20
21 (define (number-or-boolean? x)
22   (or (number? x) (boolean? x)))
23
24 (define (number-or-string? x)
25   (or (number? x) (string? x)))
26
27 (define (markup? x)
28   (or (string? x) (list? x)))
29
30 (define (scheme? x) #t)
31
32 (define type-p-name-alist
33   `(
34    (,dir? . "direction")
35    (,scheme? . "any type")
36    (,number-pair? . "pair of numbers")
37    (,ly-input-location? . "input location")   
38    (,ly-grob? . "grob (GRaphical OBject)")
39    (,duration? . "duration")
40    (,pair? . "pair")
41    (,integer? . "integer")
42    (,list? . "list")
43    (,symbol? . "symbol")
44    (,string? . "string")
45    (,boolean? . "boolean")
46    (,moment? . "moment")
47    (,ly-input-location? . "input location")
48    (,music? . "music")
49    (,number? . "number")
50    (,char? . "char")
51    (,input-port? . "input port")
52    (,output-port? . "output port")   
53    (,vector? . "vector")
54    (,procedure? . "procedure") 
55    (,boolean-or-symbol? . "boolean or symbol")
56    (,number-or-string? . "number or string")
57    (,number-or-boolean? . "number or boolean")
58    (,markup? . "markup (list or string)")
59    ))
60
61
62 (define (match-predicate obj alist)
63   (if (null? alist)
64       "Unknown type"
65       (if (apply (caar alist) obj)
66           (cdar alist)
67           (match-predicate obj (cdr alist))
68           )
69       ))
70
71 (define (object-type obj)
72   (match-predicate obj type-p-name-alist))
73
74 (define (type-name  predicate)
75   (let ((entry (assoc predicate type-p-name-alist)))
76     (if (pair? entry) (cdr entry)
77         "unknown"
78         )))
79
80 (define (uniqued-alist  alist acc)
81   (if (null? alist) acc
82       (if (assoc (caar alist) acc)
83           (uniqued-alist (cdr alist) acc)
84           (uniqued-alist (cdr alist) (cons (car alist) acc)))))
85
86
87 ;; used in denneboom.ly
88 (define (cons-map f x)
89   (cons (f (car x)) (f (cdr x))))
90
91 ;; used where?
92 ;;(define (reduce operator list)
93 ;;      (if (null? (cdr list)) (car list)
94 ;;        (operator (car list) (reduce operator (cdr list)))))
95
96
97
98 ; Make a function that checks score element for being of a specific type. 
99 (define (make-type-checker symbol)
100   (lambda (elt)
101     ;;(display  symbol)
102     ;;(eq? #t (ly-get-grob-property elt symbol))
103     (not (eq? #f (memq symbol (ly-get-grob-property elt 'interfaces))))))
104
105
106 (define (index-cell cell dir)
107   (if (equal? dir 1)
108       (cdr cell)
109       (car cell)))
110
111 (define (repeat-name-to-ctor name)
112   (let*
113       ((supported-reps
114         `(("volta" . ((iterator-ctor . ,Volta_repeat_iterator::constructor)
115                       (length . ,Repeated_music::volta_music_length)))
116             ("unfold" . ((iterator-ctor . ,Unfolded_repeat_iterator::constructor)
117                        (length . ,Repeated_music::unfolded_music_length)))
118             ("fold" . ((iterator-ctor  . ,Folded_repeat_iterator::constructor)
119                        (length . ,Repeated_music::folded_music_length)))
120             ("percent" . ((iterator-ctor . ,Percent_repeat_iterator::constructor)
121                           (length . ,Repeated_music::unfolded_music_length)))
122             ("tremolo" . ((iterator-ctor . ,Chord_tremolo_iterator::constructor)
123                           (length . ,Repeated_music::unfolded_music_length)))))
124           
125        (handle (assoc name supported-reps)))
126
127     (if (pair? handle)
128         (cdr handle)
129         (begin
130           (ly-warn
131            (string-append "Unknown repeat type `" name "'\nSee scm/c++.scm for supported repeats"))
132           '(type . 'repeated-music)))))