]> git.donarmstrong.com Git - lilypond.git/blob - scm/music-functions.scm
d9ce891e75db7f929c81cecf5ed3dc1b929ad03f
[lilypond.git] / scm / music-functions.scm
1 ;;;; music-functions.scm -- implement Scheme output routines for PostScript
2 ;;;;
3 ;;;;  source file of the GNU LilyPond music typesetter
4 ;;;; 
5 ;;;; (c)  1998--2004 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
7
8 (use-modules (ice-9 optargs)) 
9
10 ;;; ly:music-property with setter
11 ;;; (ly:music-property my-music 'elements)
12 ;;;   ==> the 'elements property
13 ;;; (set! (ly:music-property my-music 'elements) value)
14 ;;;   ==> set the 'elements property and return it
15 (define-public ly:music-property
16   (make-procedure-with-setter ly:music-property
17                               ly:music-set-property!))
18
19 (define-public ly:grob-property
20   (make-procedure-with-setter ly:grob-property
21                               ly:grob-set-property!))
22
23 (define-public (music-map function music)
24   "Apply @var{function} to @var{music} and all of the music it contains. "
25   (let ((es (ly:music-property music 'elements))
26         (e (ly:music-property music 'element)))
27     (set! (ly:music-property music 'elements) 
28           (map (lambda (y) (music-map function y)) es))
29     (if (ly:music? e)
30         (set! (ly:music-property music 'element)
31               (music-map function  e)))
32     (function music)))
33
34 (define-public (music-filter pred? music)
35   "Filter out music expressions that do not satisfy PRED."
36   
37   (define (inner-music-filter pred? music)
38     "Recursive function."
39     (let* ((es (ly:music-property music 'elements))
40            (e (ly:music-property music 'element))
41            (as (ly:music-property music 'articulations))
42            (filtered-as (filter ly:music? (map (lambda (y) (inner-music-filter pred? y)) as)))
43            (filtered-e (if (ly:music? e)
44                            (inner-music-filter pred? e)
45                            e))
46            (filtered-es (filter ly:music? (map (lambda (y) (inner-music-filter pred? y)) es))))
47       (set! (ly:music-property music 'element) filtered-e)
48       (set! (ly:music-property music 'elements) filtered-es)
49       (set! (ly:music-property music 'articulations) filtered-as)
50       ;; if filtering emptied the expression, we remove it completely.
51       (if (or (pred? music)
52               (and (eq? filtered-es '()) (not (ly:music? e))
53                    (or (not (eq? es '()))
54                        (ly:music? e))))
55           (set! music '()))
56       music))
57
58   (set! music (inner-music-filter pred? music))
59   (if (ly:music? music)
60       music
61       (make-music 'Music)))       ;must return music.
62
63 (define-public (remove-tag tag)
64   (lambda (mus)
65     (music-filter
66      (lambda (m)
67        (let* ((tags (ly:music-property m 'tags))
68               (res (memq tag tags)))
69          res))
70      mus)))
71
72 (define-public (display-music music)
73   "Display music, not done with music-map for clarity of presentation."
74   (display music)
75   (display ": { ")  
76   (let ((es (ly:music-property music 'elements))
77         (e (ly:music-property music 'element)))
78     (display (ly:mutable-music-properties music))
79     (if (pair? es)
80         (begin (display "\nElements: {\n")
81                (map display-music es)
82                (display "}\n")))
83     (if (ly:music? e)
84         (begin
85           (display "\nChild:")
86           (display-music e))))
87   (display " }\n")
88   music)
89
90
91 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
92
93 (define (shift-one-duration-log music shift dot)
94   "  add SHIFT to ly:duration-log and optionally 
95   a dot to any note encountered. This scales the music up by a factor 
96   2^shift * (2 - (1/2)^dot)"
97   (let ((d (ly:music-property music 'duration)))
98     (if (ly:duration? d)
99         (let* ((cp (ly:duration-factor d))
100                (nd (ly:make-duration (+ shift (ly:duration-log d))
101                                      (+ dot (ly:duration-dot-count d))
102                                      (car cp)
103                                      (cdr cp))))
104           (set! (ly:music-property music 'duration) nd)))
105     music))
106
107
108
109 (define-public (shift-duration-log music shift dot)
110   (music-map (lambda (x) (shift-one-duration-log x shift dot))
111              music))
112   
113
114 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
115 ;; clusters.
116
117 (define-public (note-to-cluster music)
118   "Replace NoteEvents by ClusterNoteEvents."
119   (if (eq? (ly:music-property music 'name) 'NoteEvent)
120       (make-music 'ClusterNoteEvent
121                   'pitch (ly:music-property music 'pitch)
122                   'duration (ly:music-property music 'duration))
123       music))
124
125 (define-public (notes-to-clusters music)
126   (music-map note-to-cluster music))
127
128 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
129 ;; repeats.
130
131 (define-public (unfold-repeats music)
132   "
133 This function replaces all repeats  with unfold repeats. It was 
134 written by Rune Zedeler. "
135   (let ((es (ly:music-property music 'elements))
136         (e  (ly:music-property music 'element))
137         (n  (ly:music-name music)))
138     (if (equal? n "Repeated_music")
139         (begin
140           (if (equal? (ly:music-property music 'iterator-ctor)
141                       Chord_tremolo_iterator::constructor)
142               (shift-duration-log music (ly:intlog2 (ly:music-property music 'repeat-count)) 0))
143           (set! (ly:music-property music 'length)
144                 Repeated_music::unfolded_music_length)
145           (set! (ly:music-property music 'start-moment-function)
146                 Repeated_music::first_start)
147           (set! (ly:music-property music 'iterator-ctor)
148                 Unfolded_repeat_iterator::constructor)))
149     (if (pair? es)
150         (set! (ly:music-property music 'elements)
151               (map unfold-repeats es)))
152     (if (ly:music? e)
153         (set! (ly:music-property music 'element)
154               (unfold-repeats e)))
155     music))
156
157
158 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
159 ;; property setting music objs.
160
161 (define-public (make-grob-property-set grob gprop val)
162   "Make a Music expression that sets GPROP to VAL in GROB. Does a pop first,
163 i.e.  this is not an override"
164   (make-music 'OverrideProperty
165               'symbol grob
166               'grob-property gprop
167               'grob-value val
168               'pop-first #t))
169
170 (define-public (make-grob-property-override grob gprop val)
171   "Make a Music expression that sets GPROP to VAL in GROB. Does a pop first,
172 i.e.  this is not an override"
173   (make-music 'OverrideProperty
174               'symbol grob
175               'grob-property gprop
176               'grob-value val))
177
178 (define-public (make-grob-property-revert grob gprop)
179   "Revert the grob property GPROP for GROB."
180   (make-music 'OverrideProperty
181               'symbol grob
182               'grob-property gprop))
183
184 (define direction-polyphonic-grobs
185   '(Tie Rest Slur Script TextScript Stem Dots DotColumn))
186
187 (define-public (make-voice-props-set n)
188   (make-sequential-music
189    (append
190     (map (lambda (x) (make-grob-property-set x 'direction
191                                              (if (odd? n) -1 1)))
192          direction-polyphonic-grobs)
193     (list (make-grob-property-set 'NoteColumn 'horizontal-shift (quotient n 2))
194           (make-grob-property-set 'MultiMeasureRest 'staff-position
195                                   (if (odd? n) -4 4))))))
196
197 (define-public (make-voice-props-revert)
198   (make-sequential-music
199    (append
200     (map (lambda (x) (make-grob-property-revert x 'direction))
201          direction-polyphonic-grobs)
202     (list (make-grob-property-revert 'NoteColumn 'horizontal-shift)))))
203
204
205 (define*-public (context-spec-music m context #:optional id)
206   "Add \\context CONTEXT = ID to M. "
207   (let ((cm (make-music 'ContextSpeccedMusic
208                         'element m
209                         'context-type context)))
210     (if (string? id)
211         (set! (ly:music-property cm 'context-id) id))
212     cm))
213
214
215 (define*-public (descend-to-context m context)
216   "Like context-spec-music, but only descending. "
217   (let ((cm (context-spec-music m context)))
218     (ly:music-set-property! cm 'descend-only #t)
219     cm))
220
221 (define-public (make-apply-context func)
222   (make-music 'ApplyContext
223               'procedure func))
224
225 (define-public (make-sequential-music elts)
226   (make-music 'SequentialMusic
227               'elements elts))
228
229 (define-public (make-simultaneous-music elts)
230   (make-music 'SimultaneousMusic
231               'elements elts))
232
233 (define-public (make-event-chord elts)
234   (make-music 'EventChord
235               'elements elts))
236
237 (define-public (make-skip-music dur)
238   (make-music 'SkipMusic
239               'duration dur))
240
241 ;;;;;;;;;;;;;;;;
242
243 ;; mmrest
244 (define-public (make-multi-measure-rest duration location)
245   (make-music 'MultiMeasureRestMusicGroup
246               'origin location
247               'elements (list (make-music 'BarCheck
248                                           'origin location)
249                               (make-event-chord (list (make-music 'MultiMeasureRestEvent
250                                                                   'origin location
251                                                                   'duration duration)))
252                               (make-music 'BarCheck
253                                           'origin location))))
254
255 (define-public (glue-mm-rest-texts music)
256   "Check if we have R1*4-\\markup { .. }, and if applicable convert to
257 a property set for MultiMeasureRestNumber."
258   (define (script-to-mmrest-text script-music)
259     "Extract 'direction and 'text   from SCRIPT-MUSIC, and transform into property sets."
260     (let ((dir (ly:music-property script-music 'direction))
261           (p   (make-music 'MultiMeasureTextEvent
262                            'text (ly:music-property script-music 'text))))
263       (if (ly:dir? dir)
264           (set! (ly:music-property p 'direction) dir))
265       p))
266   (if (eq? (ly:music-property music 'name) 'MultiMeasureRestMusicGroup)
267       (let* ((text? (lambda (x) (memq 'script-event (ly:music-property x 'types))))
268              (es (ly:music-property  music 'elements))
269              (texts (map script-to-mmrest-text  (filter text? es)))
270              (others (remove text? es)))
271         (if (pair? texts)
272             (set! (ly:music-property music 'elements)
273                   (cons (make-event-chord texts) others)))))
274   music)
275
276
277 (define-public (make-property-set sym val)
278   (make-music 'PropertySet
279               'symbol sym
280               'value val))
281
282 (define-public (make-ottava-set octavation)
283   (let ((m (make-music 'ApplyContext)))
284     (define (ottava-modify context)
285       "Either reset middleCPosition to the stored original, or remember
286 old middleCPosition, add OCTAVATION to middleCPosition, and set
287 OTTAVATION to `8va', or whatever appropriate."      
288       (if (number? (ly:context-property  context 'middleCPosition))
289           (if (= octavation 0)
290               (let ((where (ly:context-property-where-defined context 'middleCPosition))
291                     (oc0 (ly:context-property context 'originalCentralCPosition)))
292                 (ly:context-set-property! context 'middleCPosition oc0)
293                 (ly:context-unset-property where 'originalCentralCPosition)
294                 (ly:context-unset-property where 'ottavation))
295               (let* ((where (ly:context-property-where-defined context 'middleCPosition))
296                      (c0 (ly:context-property context 'middleCPosition))
297                      (new-c0 (+ c0 (* -7 octavation)))
298                      (string (cdr (assoc octavation '((2 . "15ma")
299                                                       (1 . "8va")
300                                                       (0 . #f)
301                                                       (-1 . "8va bassa")
302                                                       (-2 . "15ma bassa"))))))
303                 (ly:context-set-property! context 'middleCPosition new-c0)
304                 (ly:context-set-property! context 'originalCentralCPosition c0)
305                 (ly:context-set-property! context 'ottavation string)))))
306     (set! (ly:music-property m 'procedure) ottava-modify)
307     (context-spec-music m 'Staff)))
308
309 (define-public (set-octavation ottavation)
310   (ly:export (make-ottava-set ottavation)))
311
312 (define-public (make-time-signature-set num den . rest)
313   " Set properties for time signature NUM/DEN.
314 Rest can contain a list of beat groupings "
315   (let* ((set1 (make-property-set 'timeSignatureFraction (cons num den)))
316          (beat (ly:make-moment 1 den))
317          (len  (ly:make-moment num den))
318          (set2 (make-property-set 'beatLength beat))
319          (set3 (make-property-set 'measureLength len))
320          (set4 (make-property-set 'beatGrouping (if (pair? rest)
321                                                     (car rest)
322                                                     '())))
323          (basic  (list set1 set2 set3 set4)))
324     (descend-to-context
325      (context-spec-music (make-sequential-music basic) 'Timing) 'Score)))
326
327 (define-public (make-mark-set label)
328   "make the music for the \\mark command."  
329   (let* ((set (if (integer? label)
330                   (context-spec-music (make-property-set 'rehearsalMark label)
331                                       'Score)
332                   #f))
333          (ev (make-music 'MarkEvent))
334          (ch (make-event-chord (list ev))))
335     (if set
336         (make-sequential-music (list set ch))
337         (begin
338           (set! (ly:music-property ev 'label) label)
339           ch))))
340
341 (define-public (set-time-signature num den . rest)
342   (ly:export (apply make-time-signature-set `(,num ,den . ,rest))))
343
344 (define-public (make-penalty-music pen)
345   (make-music 'BreakEvent
346               'penalty pen))
347
348 (define-public (make-articulation name)
349   (make-music 'ArticulationEvent
350               'articulation-type name))
351
352 (define-public (make-lyric-event string duration)
353   (make-music 'LyricEvent
354               'duration duration
355               'text string))
356
357 (define-public (make-span-event type spandir)
358   (make-music type
359               'span-direction spandir))
360
361 (define-public (set-mus-properties! m alist)
362   "Set all of ALIST as properties of M." 
363   (if (pair? alist)
364       (begin
365         (set! (ly:music-property m (caar alist)) (cdar alist))
366         (set-mus-properties! m (cdr alist)))))
367
368 (define-public (music-separator? m)
369   "Is M a separator?"
370   (let ((ts (ly:music-property m 'types)))
371     (memq 'separator ts)))
372
373
374 ;;; splitting chords into voices.
375 (define (voicify-list lst number)
376    "Make a list of Musics.
377
378    voicify-list :: [ [Music ] ] -> number -> [Music]
379    LST is a list music-lists.
380
381    NUMBER is 0-base, i.e. Voice=1 (upstems) has number 0.
382 "
383    (if (null? lst)
384        '()
385        (cons (context-spec-music
386               (make-sequential-music
387                (list (make-voice-props-set number)
388                      (make-simultaneous-music (car lst))))
389               'Voice  (number->string (1+ number)))
390              (voicify-list (cdr lst) (1+ number)))))
391
392 (define (voicify-chord ch)
393   "Split the parts of a chord into different Voices using separator"
394   (let ((es (ly:music-property ch 'elements)))
395     (set! (ly:music-property  ch 'elements)
396           (voicify-list (split-list es music-separator?) 0))
397     ch))
398
399 (define-public (voicify-music m)
400   "Recursively split chords that are separated with \\ "
401   (if (not (ly:music? m))
402       (begin (display m)
403              (error "not music!")))
404   (let ((es (ly:music-property m 'elements))
405         (e (ly:music-property m 'element)))
406     (if (pair? es)
407         (set! (ly:music-property m 'elements) (map voicify-music es)))
408     (if (ly:music? e)
409         (set! (ly:music-property m 'element)  (voicify-music e)))
410     (if (and (equal? (ly:music-name m) "Simultaneous_music")
411              (reduce (lambda (x y ) (or x y)) #f (map music-separator? es)))
412         (set! m (context-spec-music (voicify-chord m) 'Staff)))
413     m))
414
415 (define-public (empty-music)
416   (ly:export (make-music 'Music)))
417 ;;;
418
419 ; Make a function that checks score element for being of a specific type. 
420 (define-public (make-type-checker symbol)
421   (lambda (elt)
422     ;;(display  symbol)
423     ;;(eq? #t (ly:grob-property elt symbol))
424     (not (eq? #f (memq symbol (ly:grob-property elt 'interfaces))))))
425
426 (define-public ((outputproperty-compatibility func sym val) grob g-context ao-context)
427   (if (func grob)
428       (set! (ly:grob-property grob sym) val)))
429
430
431 (define-public ((set-output-property grob-name symbol val)  grob grob-c context)
432    "Usage:
433
434 \\applyoutput #(set-output-property 'Clef 'extra-offset '(0 . 1))
435
436 "
437    (let ((meta (ly:grob-property grob 'meta)))
438      (if (equal?  (cdr (assoc 'name meta)) grob-name)
439          (set! (ly:grob-property grob symbol) val))))
440
441
442 ;;
443 (define-public (smart-bar-check n)
444   "Make  a bar check that checks for a specific bar number. 
445 "
446   (let ((m (make-music 'ApplyContext)))
447     (define (checker tr)
448       (let* ((bn (ly:context-property tr 'currentBarNumber)))
449         (if (= bn n)
450             #t
451             (error
452              (format "Bar check failed, we should have reached ~a, instead at ~a\n"
453                      n bn)))))
454     (set! (ly:music-property m 'procedure) checker)
455     m))
456
457 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
458 ;; warn for bare chords at start.
459
460 (define (has-request-chord elts)
461   (reduce (lambda (x y) (or x y)) #f
462           (map (lambda (x)
463                  (equal? (ly:music-name x) "Request_chord"))
464                elts)))
465
466 (define (ly:music-message music msg)
467   (let ((ip (ly:music-property music 'origin)))
468     (if (ly:input-location? ip)
469         (ly:input-message ip msg)
470         (ly:warn msg))))
471   
472 (define (check-start-chords music)
473   "Check music expression for a Simultaneous_music containing notes\n(ie. Request_chords),
474 without context specification. Called  from parser."
475   (let ((es (ly:music-property music 'elements))
476         (e (ly:music-property music 'element))
477         (name (ly:music-name music)))
478     (cond ((equal? name "Context_specced_music") #t)
479           ((equal? name "Simultaneous_music")
480            (if (has-request-chord es)
481                (ly:music-message music "Starting score with a chord.\nPlease insert an explicit \\context before chord")
482                (map check-start-chords es)))
483           ((equal? name "Sequential_music")
484            (if (pair? es)
485                (check-start-chords (car es))))
486           (else (if (ly:music? e) (check-start-chords e)))))
487   music)
488
489
490
491 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
492 ;;
493 ;; setting stuff for grace context.
494 ;;
495
496 (define (vector-extend v x)
497   "Make a new vector consisting of V, with X added to the end."
498   (let*
499       ((n (vector-length v))
500        (nv (make-vector (+ n 1) '())))
501     (vector-move-left! v 0 n nv 0)
502     (vector-set! nv n x)
503     nv))
504
505 (define (vector-map f v)
506   "Map  F over V. This function returns nothing."
507   (do ((n (vector-length v))
508        (i 0 (+ i 1)))
509       ((>= i n))
510     (f (vector-ref v i))))
511
512 (define (vector-reverse-map f v)
513   "Map  F over V, N to 0 order. This function returns nothing."
514   (do ((i (- (vector-length v) 1) (- i 1)))
515       ((< i 0))
516     (f (vector-ref v i))))
517
518 ;; TODO:  make a remove-grace-property too.
519 (define-public (add-grace-property context-name grob sym val)
520   "Set SYM=VAL for GROB in CONTEXT-NAME. "
521   (define (set-prop context)
522     (let* ((where (ly:context-property-where-defined context 'graceSettings))
523            (current (ly:context-property where 'graceSettings))
524            (new-settings (vector-extend current (list context-name grob sym val))))
525       (ly:context-set-property! where 'graceSettings new-settings)))
526   (ly:export (context-spec-music (make-apply-context set-prop) 'Voice)))
527
528
529 (define-public (set-start-grace-properties context)
530   (define (execute-1 x)
531     (let ((tr (ly:context-find context (car x))))
532       (if (ly:context? tr)
533           (ly:context-pushpop-property tr (cadr x) (caddr x) (cadddr x)))))
534   
535   (let ((props (ly:context-property context 'graceSettings)))
536     (if (vector? props)
537         (vector-map execute-1 props))))
538
539 (define-public (set-stop-grace-properties context)
540   (define (execute-1 x)
541     (let ((tr (ly:context-find context (car x))))
542       (if (ly:context? tr)
543           (ly:context-pushpop-property tr (cadr x) (caddr x)))))
544   
545   (let ((props (ly:context-property context 'graceSettings)))
546     (if (vector? props)
547         (vector-reverse-map execute-1 props))))
548
549 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
550 ;; switch it on here, so parsing and init isn't checked (too slow!)
551 ;;
552 ;; automatic music transformations.
553
554 (define (switch-on-debugging m)
555   (if (defined? 'set-debug-cell-accesses!)
556       (set-debug-cell-accesses! 15000))
557   m)
558
559 (define-public toplevel-music-functions
560   (list
561    ;; check-start-chords ; ; no longer needed with chord syntax. 
562    voicify-music
563    (lambda (x) (music-map glue-mm-rest-texts x))
564    ;; switch-on-debugging
565    ))
566
567 ;;;;;;;;;;;;;;;;;
568 ;; lyrics
569
570 (define (apply-durations lyric-music durations) 
571   (define (apply-duration music)
572     (if (and (not (equal? (ly:music-length music) ZERO-MOMENT))
573              (ly:duration?  (ly:music-property music 'duration)))
574         (begin
575           (set! (ly:music-property music 'duration) (car durations))
576           (set! durations (cdr durations)))))
577   
578   (music-map apply-duration lyric-music))
579
580
581 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
582 ;;
583
584 (define-public ((add-balloon-text object-name text off) grob orig-context cur-context)
585    "Usage: see input/regression/balloon.ly "
586   (let* ((meta (ly:grob-property grob 'meta))
587          (nm (if (pair? meta) (cdr (assoc 'name meta)) "nonexistant"))
588          (cb (ly:grob-property grob 'print-function)))
589     (if (equal? nm object-name)
590         (begin
591           (set! (ly:grob-property grob 'print-function) Balloon_interface::print)
592           (set! (ly:grob-property grob 'balloon-original-callback) cb)
593           (set! (ly:grob-property grob 'balloon-text) text)
594           (set! (ly:grob-property grob 'balloon-text-offset) off)
595           (set! (ly:grob-property grob 'balloon-text-props) '((font-family . roman)))))))
596
597 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
598 ;; accidentals
599
600 (define-public (set-accidentals-properties extra-natural
601                                            auto-accs auto-cauts
602                                            context)
603   (context-spec-music
604    (make-sequential-music
605     (append (if (boolean? extra-natural)
606                 (list (make-property-set 'extraNatural extra-natural))
607                 '())
608             (list (make-property-set 'autoAccidentals auto-accs)
609                   (make-property-set 'autoCautionaries auto-cauts))))
610    context))
611
612 (define-public (set-accidental-style style . rest)
613   "Set accidental style to STYLE. Optionally takes a context argument,
614 e.g. 'Staff or 'Voice. The context defaults to Voice, except for piano styles, which
615 use PianoStaff as a context. "
616   (let ((context (if (pair? rest)
617                      (car rest) 'Staff))
618         (pcontext (if (pair? rest)
619                       (car rest) 'PianoStaff)))
620     (ly:export
621      (cond
622       ;; accidentals as they were common in the 18th century.
623       ((equal? style 'default)
624        (set-accidentals-properties #t '(Staff (same-octave . 0))
625                                    '() context))
626       ;; accidentals from one voice do NOT get cancelled in other voices
627       ((equal? style 'voice)
628        (set-accidentals-properties #t '(Voice (same-octave . 0))
629                                    '() context))
630       ;; accidentals as suggested by Kurt Stone, Music Notation in the 20th century.
631       ;; This includes all the default accidentals, but accidentals also needs cancelling
632       ;; in other octaves and in the next measure.
633       ((equal? style 'modern)
634        (set-accidentals-properties #f '(Staff (same-octave . 0) (any-octave . 0) (same-octave . 1))
635                                    '()  context))
636       ;; the accidentals that Stone adds to the old standard as cautionaries
637       ((equal? style 'modern-cautionary)
638        (set-accidentals-properties #f '(Staff (same-octave . 0))
639                                    '(Staff (any-octave . 0) (same-octave . 1))
640                                    context))
641       ;; Multivoice accidentals to be read both by musicians playing one voice
642       ;; and musicians playing all voices.
643       ;; Accidentals are typeset for each voice, but they ARE cancelled across voices.
644       ((equal? style 'modern-voice)
645        (set-accidentals-properties  #f
646                                     '(Voice (same-octave . 0) (any-octave . 0) (same-octave . 1)
647                                             Staff (same-octave . 0) (any-octave . 0) (same-octave . 1))
648                                     '()
649                                     context))
650       ;; same as modernVoiceAccidental eccept that all special accidentals are typeset
651       ;; as cautionaries
652       ((equal? style 'modern-voice-cautionary)
653        (set-accidentals-properties #f
654                                    '(Voice (same-octave . 0) )
655                                    '(Voice (any-octave . 0) (same-octave . 1)
656                                            Staff (same-octave . 0) (any-octave . 0) (same-octave . 1))
657                                    context))
658       ;; stone's suggestions for accidentals on grand staff.
659       ;; Accidentals are cancelled across the staves in the same grand staff as well
660       ((equal? style 'piano)
661        (set-accidentals-properties #f
662                                    '( Staff (same-octave . 0) (any-octave . 0) (same-octave . 1)
663                                             PianoStaff (any-octave . 0) (same-octave . 1))
664                                    '()
665                                    pcontext))
666       ((equal? style 'piano-cautionary)
667        (set-accidentals-properties #f
668                                    '(Staff (same-octave . 0))
669                                    '(Staff (any-octave . 0) (same-octave . 1)
670                                            PianoStaff (any-octave . 0) (same-octave . 1))
671                                    pcontext))
672       ;; do not set localKeySignature when a note alterated differently from
673       ;; localKeySignature is found.
674       ;; Causes accidentals to be printed at every note instead of
675       ;; remembered for the duration of a measure.
676       ;; accidentals not being remembered, causing accidentals always to be typeset relative to the time signature
677       ((equal? style 'forget)
678        (set-accidentals-properties '()
679                                    '(Staff (same-octave . -1))
680                                    '() context))
681       ;; Do not reset the key at the start of a measure.  Accidentals will be
682       ;; printed only once and are in effect until overridden, possibly many
683       ;; measures later.
684       ((equal? style 'no-reset)
685        (set-accidentals-properties '()
686                                    '(Staff (same-octave . #t))
687                                    '()
688                                    context))
689       (else
690        (ly:warn (string-append "Unknown accidental style: " (symbol->string style)))
691        (make-sequential-music '()))))))
692
693