]> git.donarmstrong.com Git - lilypond.git/blob - ly/music-functions-init.ly
* scm/define-markup-commands.scm (text): add \text markup command.
[lilypond.git] / ly / music-functions-init.ly
1 % -*-Scheme-*-
2
3 \version "2.6.0"
4
5 %% need SRFI-1 filter 
6
7 #(use-modules (srfi srfi-1))  
8
9 applymusic = #(def-music-function (parser location func music) (procedure? ly:music?)
10                (func music))
11
12 oldaddlyrics = #(def-music-function (parser location music lyrics) (ly:music? ly:music?)
13
14               (make-music 'OldLyricCombineMusic 
15                           'origin location
16                           'elements (list music lyrics)))
17
18 grace = #(def-grace-function startGraceMusic stopGraceMusic)
19
20 acciaccatura = #(def-grace-function startAcciaccaturaMusic stopAcciaccaturaMusic)
21 appoggiatura = #(def-grace-function startAppoggiaturaMusic stopAppoggiaturaMusic)
22
23 partcombine = #(def-music-function (parser location part1 part2) (ly:music? ly:music?)
24                 (make-part-combine-music (list part1 part2)))
25
26 autochange = #(def-music-function (parser location music) (ly:music?)
27                (make-autochange-music music))
28
29 applycontext = #(def-music-function (parser location proc) (procedure?)
30                  (make-music 'ApplyContext 
31                    'origin location
32                    'procedure proc))
33
34 musicMap = #(def-music-function (parser location proc mus) (procedure? ly:music?)
35              (music-map proc mus))
36
37 displayMusic = #(def-music-function (parser location music) (ly:music?)
38                  (display-scheme-music music)
39                  music)
40 applyoutput = #(def-music-function (parser location proc) (procedure?)
41                 (make-music 'ApplyOutputEvent 
42                   'origin location
43                   'procedure proc))
44
45 breathe = #(def-music-function (parser location) ()
46             (make-music 'EventChord 
47               'origin location
48               'elements (list (make-music 'BreathingSignEvent))))
49
50
51 unfoldRepeats = #(def-music-function (parser location music) (ly:music?)
52                   (unfold-repeats music))
53
54 compressMusic = #(def-music-function
55                   (parser location fraction music) (number-pair? ly:music?)
56                   (ly:music-compress music (ly:make-moment (car fraction) (cdr fraction))))
57
58 makeClusters = #(def-music-function
59                 (parser location arg) (ly:music?)
60                 (music-map note-to-cluster arg))
61
62
63 removeWithTag = 
64 #(def-music-function
65   (parser location tag music) (symbol? ly:music?)
66   (music-filter
67    (lambda (m)
68     (let* ((tags (ly:music-property m 'tags))
69            (res (memq tag tags)))
70      (not res)))
71  music))
72               
73 keepWithTag =
74 #(def-music-function
75   (parser location tag music) (symbol? ly:music?)
76   (music-filter
77    (lambda (m)
78     (let* ((tags (ly:music-property m 'tags))
79            (res (memq tag tags)))
80      (or
81       (eq? tags '())
82       res)))
83    music))
84
85
86 %% Todo:
87 %% doing
88 %% def-music-function in a .scm causes crash.
89
90 cueDuring = 
91 #(def-music-function
92   (parser location what dir main-music)
93   (string? ly:dir? ly:music?)
94   (make-music 'QuoteMusic
95               'element main-music 
96               'quoted-context-type 'Voice
97               'quoted-context-id "cue"
98               'quoted-music-name what
99               'quoted-voice-direction dir
100               'origin location))
101
102
103 quoteDuring = #
104 (def-music-function
105   (parser location what main-music)
106   (string? ly:music?)
107   (make-music 'QuoteMusic
108               'element main-music
109               'quoted-music-name what
110               'origin location))
111
112
113
114 pitchedTrill =
115 #(def-music-function
116    (parser location main-note secondary-note)
117    (ly:music? ly:music?)
118    (let*
119        ((get-notes (lambda (ev-chord)
120                      (filter
121                       (lambda (m) (eq? 'NoteEvent (ly:music-property m 'name)))
122                       (ly:music-property ev-chord 'elements))))
123         (sec-note-events (get-notes secondary-note))
124         (trill-events (filter (lambda (m) (memq 'trill-span-event (ly:music-property m 'types)))
125                               (ly:music-property main-note 'elements)))
126
127         (trill-pitch
128          (if (pair? sec-note-events)
129              (ly:music-property (car sec-note-events) 'pitch)
130              )))
131      
132      (if (ly:pitch? trill-pitch)
133          (for-each (lambda (m) (ly:music-set-property! m 'trill-pitch trill-pitch))
134                    trill-events)
135          (ly:warning (_ "Second argument of \\pitchedTrill should be single note.")))
136
137      main-note))
138
139 killCues =
140 #(def-music-function
141    (parser location music)
142    (ly:music?)
143    (music-map
144     (lambda (mus)
145       (if (string? (ly:music-property mus 'quoted-music-name))
146           (ly:music-property mus 'element)
147           mus)) music))
148    
149
150 afterGraceFraction = #(cons 6 8)
151
152 afterGrace =
153 #(def-music-function
154   (parser location main grace)
155   (ly:music? ly:music?)
156
157   (let*
158       ((main-length (ly:music-length main))
159        (fraction  (ly:parser-lookup parser 'afterGraceFraction)))
160     
161     (make-simultaneous-music
162      (list
163       main
164       (make-sequential-music
165        (list
166
167         (make-music 'SkipMusic
168                     'duration (ly:make-duration
169                                0 0
170                                (* (ly:moment-main-numerator main-length)
171                                   (car fraction))
172                                (* (ly:moment-main-denominator main-length)
173                                   (cdr fraction)) ))
174         (make-music 'GraceMusic
175                     'element grace)))))))
176
177 %{
178
179 TODO:
180
181 remove these from the parser, and softcode here:
182
183  * \tag
184
185 with small syntax changes, we could also do
186
187  * \bar
188  *  ?
189
190 %}