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