]> git.donarmstrong.com Git - lilypond.git/blob - ly/music-functions-init.ly
(process_music): delta-pitch -> delta-step.
[lilypond.git] / ly / music-functions-init.ly
1 % -*-Scheme-*-
2
3 \version "2.9.12"
4
5 %% need SRFI-1 filter 
6
7 #(use-modules (srfi srfi-1))  
8 %% FIXME: guile-1.7 required?
9 %#(use-modules (scm display-lily))invalid module name for use-syntax ((srfi srfi-39))
10
11 #(use-modules (scm display-lily))
12 #(display-lily-init parser)
13
14
15 acciaccatura =
16 #(def-grace-function startAcciaccaturaMusic stopAcciaccaturaMusic)
17
18 addquote =
19 #(define-music-function (parser location name music) (string? ly:music?)
20    "Add a piece of music to be quoted "
21    (add-quotable name music)
22    (make-music 'SequentialMusic 'void #t))
23
24
25 afterGraceFraction =
26 #(cons 6 8)
27
28 afterGrace =
29 #(define-music-function
30   (parser location main grace)
31   (ly:music? ly:music?)
32
33   (let*
34       ((main-length (ly:music-length main))
35        (fraction  (ly:parser-lookup parser 'afterGraceFraction)))
36     
37     (make-simultaneous-music
38      (list
39       main
40       (make-sequential-music
41        (list
42
43         (make-music 'SkipMusic
44                     'duration (ly:make-duration
45                                0 0
46                                (* (ly:moment-main-numerator main-length)
47                                   (car fraction))
48                                (* (ly:moment-main-denominator main-length)
49                                   (cdr fraction)) ))
50         (make-music 'GraceMusic
51                     'element grace)))))))
52
53 applyMusic =
54 #(define-music-function (parser location func music) (procedure? ly:music?)
55                (func music))
56
57
58 applyOutput =
59 #(define-music-function (parser location ctx proc) (symbol? procedure?)
60                 (make-music 'ApplyOutputEvent
61                   'origin location
62                   'procedure proc
63                   'context-type ctx))
64
65 appoggiatura =
66 #(def-grace-function startAppoggiaturaMusic stopAppoggiaturaMusic)
67
68
69
70 % for regression testing purposes.
71 assertBeamQuant =
72 #(define-music-function (parser location l r) (pair? pair?)
73   (make-grob-property-override 'Beam 'positions
74    (ly:make-simple-closure
75     (ly:make-simple-closure
76      (append
77       (list chain-grob-member-functions `(,cons 0 0))
78       (check-quant-callbacks l r))))))
79     
80 % for regression testing purposes.
81 assertBeamSlope =
82 #(define-music-function (parser location comp) (procedure?)
83   (make-grob-property-override 'Beam 'positions
84    (ly:make-simple-closure
85     (ly:make-simple-closure
86      (append
87       (list chain-grob-member-functions `(,cons 0 0))
88       (check-slope-callbacks comp))))))
89
90
91
92 autochange =
93 #(define-music-function (parser location music) (ly:music?)
94                (make-autochange-music music))
95
96 applyContext =
97 #(define-music-function (parser location proc) (procedure?)
98                  (make-music 'ApplyContext 
99                    'origin location
100                    'procedure proc))
101
102 bar =
103 #(define-music-function (parser location type)
104    (string?)
105    (context-spec-music
106     (make-property-set 'whichBar type)
107     'Timing))
108
109
110 barNumberCheck =
111 #(define-music-function (parser location n) (integer?)
112    (make-music 'ApplyContext 
113                'origin location
114                'procedure 
115                (lambda (c)
116                  (let*
117                      ((cbn (ly:context-property c 'currentBarNumber)))
118                    (if (not (= cbn n))
119                        (ly:input-message location "Barcheck failed got ~a expect ~a"
120                                          cbn n))))))
121
122
123 %% why a function?
124 breathe =
125 #(define-music-function (parser location) ()
126             (make-music 'EventChord 
127               'origin location
128               'elements (list (make-music 'BreathingSignEvent))))
129
130 bendAfter =
131 #(define-music-function (parser location delta) (integer?)
132               
133   (make-music 'BendAfterEvent
134    'delta-step delta))
135
136 clef =
137 #(define-music-function (parser location type)
138    (string?)
139    
140    "Set the current clef."
141
142    (make-clef-set type))
143
144
145 compressMusic =
146 #(define-music-function
147                   (parser location fraction music) (number-pair? ly:music?)
148                   (ly:music-compress music (ly:make-moment (car fraction) (cdr fraction))))
149
150
151 cueDuring = 
152 #(define-music-function
153   (parser location what dir main-music)
154   (string? ly:dir? ly:music?)
155   (make-music 'QuoteMusic
156               'element main-music 
157               'quoted-context-type 'Voice
158               'quoted-context-id "cue"
159               'quoted-music-name what
160               'quoted-voice-direction dir
161               'origin location))
162
163
164 displayLilyMusic =
165 #(define-music-function (parser location music) (ly:music?)
166    (display-lily-music music)
167    music)
168
169 displayMusic =
170 #(define-music-function (parser location music) (ly:music?)
171                  (display-scheme-music music)
172                  music)
173
174 featherDurations=
175 #(define-music-function (parser location factor argument) (ly:moment? ly:music?)
176
177    "Rearrange durations in ARGUMENT so there is an
178 acceleration/deceleration. "
179    
180    (let*
181        ((orig-duration (ly:music-length argument))
182         (multiplier (ly:make-moment 1 1)))
183
184      (music-map 
185       (lambda (mus)
186         (if (and (eq? (ly:music-property mus 'name) 'EventChord)
187                  (< 0 (ly:moment-main-denominator (ly:music-length mus))))
188             (begin
189               (ly:music-compress mus multiplier)
190               (set! multiplier (ly:moment-mul factor multiplier)))
191             )
192         mus)
193       argument)
194
195      (ly:music-compress
196       argument
197       (ly:moment-div orig-duration (ly:music-length argument)))
198
199      argument))
200
201 grace =
202 #(def-grace-function startGraceMusic stopGraceMusic)
203
204 keepWithTag =
205 #(define-music-function
206   (parser location tag music) (symbol? ly:music?)
207   (music-filter
208    (lambda (m)
209     (let* ((tags (ly:music-property m 'tags))
210            (res (memq tag tags)))
211      (or
212       (eq? tags '())
213       res)))
214    music))
215
216
217
218 killCues =
219 #(define-music-function
220    (parser location music)
221    (ly:music?)
222    (music-map
223     (lambda (mus)
224       (if (string? (ly:music-property mus 'quoted-music-name))
225           (ly:music-property mus 'element)
226           mus)) music))
227    
228
229 makeClusters =
230 #(define-music-function
231                 (parser location arg) (ly:music?)
232                 (music-map note-to-cluster arg))
233
234 musicMap =
235 #(define-music-function (parser location proc mus) (procedure? ly:music?)
236              (music-map proc mus))
237
238
239
240 oldaddlyrics =
241 #(define-music-function (parser location music lyrics) (ly:music? ly:music?)
242
243               (make-music 'OldLyricCombineMusic 
244                           'origin location
245                           'elements (list music lyrics)))
246
247
248 overrideProperty =
249 #(define-music-function (parser location name property value)
250    (string? symbol? scheme?)
251
252
253    "Set @var{property} to @var{value} in all grobs named @var{name}.
254 The @var{name} argument is a string of the form @code{\"Context.GrobName\"}
255 or @code{\"GrobName\"}"
256
257    (let*
258        ((name-components (string-split name #\.))
259         (context-name 'Bottom)
260         (grob-name #f))
261
262      (if (> 2 (length name-components))
263          (set! grob-name (string->symbol (car name-components)))
264          (begin
265            (set! grob-name (string->symbol (list-ref name-components 1)))
266            (set! context-name (string->symbol (list-ref name-components 0)))))
267
268      (make-music 'ApplyOutputEvent
269                  'origin location
270                  'context-type context-name
271                  'procedure
272                  (lambda (grob orig-context context)
273                    (if (equal?
274                         (cdr (assoc 'name (ly:grob-property grob 'meta)))
275                         grob-name)
276                        (set! (ly:grob-property grob property) value))))))
277
278
279 removeWithTag = 
280 #(define-music-function
281   (parser location tag music) (symbol? ly:music?)
282   (music-filter
283    (lambda (m)
284     (let* ((tags (ly:music-property m 'tags))
285            (res (memq tag tags)))
286      (not res)))
287  music))
288
289 %% Todo:
290 %% doing
291 %% define-music-function in a .scm causes crash.
292
293
294 octave =
295 #(define-music-function (parser location pitch-note) (ly:music?)
296    "octave check"
297
298    (make-music 'RelativeOctaveCheck
299                'origin location
300                'pitch (pitch-of-note pitch-note) 
301                ))
302 partcombine =
303 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
304                 (make-part-combine-music (list part1 part2)))
305
306               
307 pitchedTrill =
308 #(define-music-function
309    (parser location main-note secondary-note)
310    (ly:music? ly:music?)
311    (let*
312        ((get-notes (lambda (ev-chord)
313                      (filter
314                       (lambda (m) (eq? 'NoteEvent (ly:music-property m 'name)))
315                       (ly:music-property ev-chord 'elements))))
316         (sec-note-events (get-notes secondary-note))
317         (trill-events (filter (lambda (m) (memq 'trill-span-event (ly:music-property m 'types)))
318                               (ly:music-property main-note 'elements)))
319
320         (trill-pitch
321          (if (pair? sec-note-events)
322              (ly:music-property (car sec-note-events) 'pitch)
323              )))
324      
325      (if (ly:pitch? trill-pitch)
326          (for-each (lambda (m) (ly:music-set-property! m 'pitch trill-pitch))
327                    trill-events)
328          (begin
329            (ly:warning (_ "Second argument of \\pitchedTrill should be single note: "))
330            (display sec-note-events)))
331
332      main-note))
333
334
335
336
337
338    
339 parenthesize =
340 #(define-music-function (parser loc arg) (ly:music?)
341    "Tag @var{arg} to be parenthesized."
342
343    (set! (ly:music-property arg 'parenthesize) #t)
344    arg)
345
346 parallelMusic =
347 #(define-music-function (parser location voice-ids music) (list? ly:music?)
348   "Define parallel music sequences, separated by '|' (bar check signs),
349 and assign them to the identifiers provided in @var{voice-ids}.
350
351 @var{voice-ids}: a list of music identifiers (symbols containing only letters)
352
353 @var{music}: a music sequence, containing BarChecks as limiting expressions.
354
355 Example:
356   \\parallelMusic #'(A B C) {
357     c c | d d | e e |
358     d d | e e | f f |
359   }
360 <==>
361   A = { c c | d d | }
362   B = { d d | e e | }
363   C = { e e | f f | }
364 "
365   (let* ((voices (apply circular-list (make-list (length voice-ids) (list))))
366          (current-voices voices)
367          (current-sequence (list)))
368     ;;
369     ;; utilities
370     (define (push-music m)
371       "Push the music expression into the current sequence"
372       (set! current-sequence (cons m current-sequence)))
373     (define (change-voice)
374       "Stores the previously built sequence into the current voice and
375        change to the following voice."
376       (list-set! current-voices 0 (cons (make-music 'SequentialMusic 
377                                          'elements (reverse! current-sequence))
378                                         (car current-voices)))
379       (set! current-sequence (list))
380       (set! current-voices (cdr current-voices)))
381     (define (bar-check? m)
382       "Checks whether m is a bar check."
383       (eq? (ly:music-property m 'name) 'BarCheck))
384     (define (music-origin music)
385       "Recursively search an origin location stored in music."
386       (cond ((null? music) #f)
387             ((not (null? (ly:music-property music 'origin)))
388              (ly:music-property music 'origin))
389             (else (or (music-origin (ly:music-property music 'element))
390                       (let ((origins (remove not (map music-origin 
391                                                       (ly:music-property music 'elements)))))
392                         (and (not (null? origins)) (car origins)))))))
393     ;;
394     ;; first, split the music and fill in voices
395     (map-in-order (lambda (m)
396                     (push-music m)
397                     (if (bar-check? m) (change-voice)))
398                   (ly:music-property music 'elements))
399     (if (not (null? current-sequence)) (change-voice))
400     ;; un-circularize `voices' and reorder the voices
401     (set! voices (map-in-order (lambda (dummy seqs)
402                                  (reverse! seqs))
403                                voice-ids voices))
404     ;;
405     ;; set origin location of each sequence in each voice
406     ;; for better type error tracking
407     (for-each (lambda (voice)
408                 (for-each (lambda (seq)
409                             (set! (ly:music-property seq 'origin)
410                                   (or (music-origin seq) location)))
411                           voice))
412               voices)
413     ;;
414     ;; check sequence length
415     (apply for-each (lambda (. seqs)
416                       (let ((moment-reference (ly:music-length (car seqs))))
417                         (for-each (lambda (seq moment)
418                                     (if (not (equal? moment moment-reference))
419                                         (ly:music-message seq 
420                                          "Bars in parallel music don't have the same length")))
421                           seqs (map-in-order ly:music-length seqs))))
422            voices)
423    ;;
424    ;; bind voice identifiers to the voices
425    (map (lambda (voice-id voice)
426           (ly:parser-define! parser voice-id 
427                              (make-music 'SequentialMusic 
428                                'origin location
429                                'elements voice)))
430         voice-ids voices))
431  ;; Return an empty sequence. this function is actually a "void" function.
432  (make-music 'SequentialMusic 'void #t))
433
434
435
436 quoteDuring = #
437 (define-music-function
438   (parser location what main-music)
439   (string? ly:music?)
440   (make-music 'QuoteMusic
441               'element main-music
442               'quoted-music-name what
443               'origin location))
444
445
446
447 resetRelativeOctave  =
448 #(define-music-function
449     (parser location reference-note)
450     (ly:music?)
451     "Set the octave inside a \\relative section."
452
453    (let*
454     ((notes (ly:music-property reference-note 'elements))
455      (pitch (ly:music-property (car notes) 'pitch)))
456
457     (set! (ly:music-property reference-note 'elements) '())
458     (set! (ly:music-property reference-note
459        'to-relative-callback)
460        (lambda (music last-pitch)
461         pitch))
462
463     reference-note))
464
465
466
467 shiftDurations =
468 #(define-music-function (parser location dur dots arg) (integer? integer? ly:music?)
469    ""
470
471    
472    (music-map
473     (lambda (x)
474       (shift-one-duration-log x dur dots)) arg))
475
476
477 %% this is a stub. Write your own to suit the spacing tweak output.
478 spacingTweaks =
479 #(define-music-function (parser location parameters) (list?)
480    (make-music 'SequentialMusic 'void #t))
481
482
483 transposedCueDuring = #
484 (define-music-function
485   (parser location what dir pitch-note main-music)
486   (string? ly:dir? ly:music? ly:music?)
487
488   "Insert notes from the part @var{what} into a voice called @code{cue},
489 using the transposition defined by @var{pitch-note}.  This happens
490 simultaneously with @var{main-music}, which is usually a rest.  The
491 argument @var{dir} determines whether the cue notes should be notated
492 as a first or second voice."
493
494   (make-music 'QuoteMusic
495               'element main-music
496               'quoted-context-type 'Voice
497               'quoted-context-id "cue"
498               'quoted-music-name what
499               'quoted-voice-direction dir
500               'quoted-transposition (pitch-of-note pitch-note)
501               'origin location))
502
503
504
505
506
507 tweak = #(define-music-function (parser location sym val arg)
508            (symbol? scheme? ly:music?)
509
510            "Add @code{sym . val} to the @code{tweaks} property of @var{arg}."
511
512            
513            (set!
514             (ly:music-property arg 'tweaks)
515             (acons sym val
516                    (ly:music-property arg 'tweaks)))
517            arg)
518
519 tag = #(define-music-function (parser location tag arg)
520    (symbol? ly:music?)
521
522    "Add @var{tag} to the @code{tags} property of @var{arg}."
523
524    (set!
525     (ly:music-property arg 'tags)
526     (cons tag
527           (ly:music-property arg 'tags)))
528    arg)
529
530
531 unfoldRepeats =
532 #(define-music-function (parser location music) (ly:music?)
533                   (unfold-repeats music))