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