1 ;;;; music-functions.scm --
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 1998--2005 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 ;; (use-modules (ice-9 optargs))
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!))
19 (define-public ly:grob-property
20 (make-procedure-with-setter ly:grob-property
21 ly:grob-set-property!))
23 (define-public (music-map function music)
24 "Apply @var{function} to @var{music} and all of the music it contains.
26 First it recurses over the children, then the function is applied to MUSIC.
28 (let ((es (ly:music-property music 'elements))
29 (e (ly:music-property music 'element)))
30 (set! (ly:music-property music 'elements)
31 (map (lambda (y) (music-map function y)) es))
33 (set! (ly:music-property music 'element)
34 (music-map function e)))
37 (define-public (music-filter pred? music)
38 "Filter out music expressions that do not satisfy PRED."
40 (define (inner-music-filter pred? music)
42 (let* ((es (ly:music-property music 'elements))
43 (e (ly:music-property music 'element))
44 (as (ly:music-property music 'articulations))
45 (filtered-as (filter ly:music? (map (lambda (y) (inner-music-filter pred? y)) as)))
46 (filtered-e (if (ly:music? e)
47 (inner-music-filter pred? e)
49 (filtered-es (filter ly:music? (map (lambda (y) (inner-music-filter pred? y)) es))))
50 (set! (ly:music-property music 'element) filtered-e)
51 (set! (ly:music-property music 'elements) filtered-es)
52 (set! (ly:music-property music 'articulations) filtered-as)
53 ;; if filtering emptied the expression, we remove it completely.
54 (if (or (not (pred? music))
55 (and (eq? filtered-es '()) (not (ly:music? e))
56 (or (not (eq? es '()))
61 (set! music (inner-music-filter pred? music))
64 (make-music 'Music))) ;must return music.
66 (define-public (display-music music)
67 "Display music, not done with music-map for clarity of presentation."
70 (let ((es (ly:music-property music 'elements))
71 (e (ly:music-property music 'element)))
72 (display (ly:music-mutable-properties music))
74 (begin (display "\nElements: {\n")
75 (map display-music es)
85 ;;; A scheme music pretty printer
87 (define (markup-expression->make-markup markup-expression)
88 "Transform `markup-expression' into an equivalent, hopefuly readable, scheme expression.
90 \\markup \\bold \\italic hello
92 (markup #:line (#:bold (#:italic (#:simple \"hello\"))))"
93 (define (proc->command-keyword proc)
94 "Return a keyword, eg. `#:bold', from the `proc' function, eg. #<procedure bold-markup (layout props arg)>"
95 (let ((cmd-markup (symbol->string (procedure-name proc))))
96 (symbol->keyword (string->symbol (substring cmd-markup 0 (- (string-length cmd-markup)
97 (string-length "-markup")))))))
98 (define (transform-arg arg)
99 (cond ((and (pair? arg) (pair? (car arg))) ;; a markup list
100 (apply append (map inner-markup->make-markup arg)))
101 ((pair? arg) ;; a markup
102 (inner-markup->make-markup arg))
105 (define (inner-markup->make-markup mrkup)
106 (let ((cmd (proc->command-keyword (car mrkup)))
107 (args (map transform-arg (cdr mrkup))))
110 `(markup ,@(inner-markup->make-markup markup-expression)))
112 (define (music-expression? obj)
115 (define*-public (music-pretty-string obj #:optional (depth 0))
116 "Return a string describing `obj', in particular music expression
117 will be printed as: (make-music 'MusicType 'property ...)"
119 (cond (;; markup expression
121 (format #f "~a" (markup-expression->make-markup obj)))
123 (music-expression? obj)
124 (format #f "(make-music '~a~{~a~})"
125 (ly:music-property obj 'name)
127 (format #f "~%~v_'~a ~a"
130 (cond (;; property is a markup expression
132 (music-pretty-string (cdr prop) (1+ depth)))
133 (;; property is a list
135 (format #f "(list ~{~a~})"
139 (music-pretty-string mus (1+ depth))))
141 (;; property is a string
143 (string-append "\"" (cdr prop) "\""))
144 (else ;; property is something else
145 (music-pretty-string (cdr prop) (1+ depth))))))
146 (remove (lambda (prop)
147 (eqv? (car prop) 'origin))
148 (ly:music-mutable-properties obj)))))
150 (string? obj) (format #f "~s" obj))
152 (symbol? obj) (format #f "'~a" obj))
154 (ly:duration? obj) (format #f "(ly:make-duration ~a ~a ~a ~a)"
155 (ly:duration-log obj)
156 (ly:duration-dot-count obj)
157 (car (ly:duration-factor obj))
158 (cdr (ly:duration-factor obj))))
160 (ly:pitch? obj) (format #f "(ly:make-pitch ~a ~a ~a)"
161 (ly:pitch-octave obj)
162 (ly:pitch-notename obj)
163 (ly:pitch-alteration obj)))
165 (procedure? obj) (or (procedure-name obj) (format #f "(lambda ...)")))
167 (format #f "~a" obj))))
169 (define-public (display-scheme-music obj)
170 "Displays `obj', typically a music expression, in a friendly fashion,
171 which often can be read back in order to generate an equivalent expression."
172 (display (music-pretty-string obj))
175 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
177 (define (shift-one-duration-log music shift dot)
178 " add SHIFT to ly:duration-log and optionally
179 a dot to any note encountered. This scales the music up by a factor
180 2^shift * (2 - (1/2)^dot)"
181 (let ((d (ly:music-property music 'duration)))
183 (let* ((cp (ly:duration-factor d))
184 (nd (ly:make-duration (+ shift (ly:duration-log d))
185 (+ dot (ly:duration-dot-count d))
188 (set! (ly:music-property music 'duration) nd)))
193 (define-public (shift-duration-log music shift dot)
194 (music-map (lambda (x) (shift-one-duration-log x shift dot))
197 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
200 (define-public (note-to-cluster music)
201 "Replace NoteEvents by ClusterNoteEvents."
202 (if (eq? (ly:music-property music 'name) 'NoteEvent)
203 (make-music 'ClusterNoteEvent
204 'pitch (ly:music-property music 'pitch)
205 'duration (ly:music-property music 'duration))
208 (define-public (notes-to-clusters music)
209 (music-map note-to-cluster music))
211 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
214 (define-public (unfold-repeats music)
216 This function replaces all repeats with unfold repeats. "
218 (let ((es (ly:music-property music 'elements))
219 (e (ly:music-property music 'element))
221 (if (memq 'repeated-music (ly:music-property music 'types))
223 (if (equal? (ly:music-property music 'iterator-ctor)
224 Chord_tremolo_iterator::constructor)
225 (let* ((seq-arg? (memq 'sequential-music
226 (ly:music-property e 'types)))
227 (count (ly:music-property music 'repeat-count))
228 (dot-shift (if (= 0 (remainder count 3))
232 (set! count (* 2 (quotient count 3))))
234 (shift-duration-log music (+ (if seq-arg? 1 0)
235 (ly:intlog2 count)) dot-shift)
238 (ly:music-compress e (ly:make-moment (length (ly:music-property e 'elements)) 1)))))
240 (set! (ly:music-property music 'length-callback)
241 Repeated_music::unfolded_music_length)
242 (set! (ly:music-property music 'start-callback)
243 Repeated_music::first_start)
244 (set! (ly:music-property music 'iterator-ctor)
245 Unfolded_repeat_iterator::constructor)))
248 (set! (ly:music-property music 'elements)
249 (map unfold-repeats es)))
251 (set! (ly:music-property music 'element)
255 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
256 ;; property setting music objs.
258 (define-public (make-grob-property-set grob gprop val)
259 "Make a Music expression that sets GPROP to VAL in GROB. Does a pop first,
260 i.e. this is not an override"
261 (make-music 'OverrideProperty
267 (define-public (make-grob-property-override grob gprop val)
268 "Make a Music expression that sets GPROP to VAL in GROB. Does a pop first,
269 i.e. this is not an override"
270 (make-music 'OverrideProperty
275 (define-public (make-grob-property-revert grob gprop)
276 "Revert the grob property GPROP for GROB."
277 (make-music 'OverrideProperty
279 'grob-property gprop))
281 (define direction-polyphonic-grobs
282 '(Stem Tie Rest Slur Script TextScript Dots DotColumn Fingering))
284 (define-safe-public (make-voice-props-set n)
285 (make-sequential-music
287 (map (lambda (x) (make-grob-property-set x 'direction
289 direction-polyphonic-grobs)
291 (make-grob-property-set 'NoteColumn 'horizontal-shift (quotient n 2))
292 (make-grob-property-set 'MultiMeasureRest 'staff-position (if (odd? n) -4 4))))))
294 (define-safe-public (make-voice-props-revert)
295 (make-sequential-music
297 (map (lambda (x) (make-grob-property-revert x 'direction))
298 direction-polyphonic-grobs)
299 (list (make-grob-property-revert 'NoteColumn 'horizontal-shift))
300 (list (make-grob-property-revert 'MultiMeasureRest 'staff-position)))))
303 (define-safe-public (context-spec-music m context #:optional id)
304 "Add \\context CONTEXT = ID to M. "
305 (let ((cm (make-music 'ContextSpeccedMusic
307 'context-type context)))
309 (set! (ly:music-property cm 'context-id) id))
312 (define-public (descend-to-context m context)
313 "Like context-spec-music, but only descending. "
314 (let ((cm (context-spec-music m context)))
315 (ly:music-set-property! cm 'descend-only #t)
318 (define-public (make-non-relative-music mus)
319 (make-music 'UnrelativableMusic
322 (define-public (make-apply-context func)
323 (make-music 'ApplyContext
326 (define-public (make-sequential-music elts)
327 (make-music 'SequentialMusic
330 (define-public (make-simultaneous-music elts)
331 (make-music 'SimultaneousMusic
334 (define-safe-public (make-event-chord elts)
335 (make-music 'EventChord
338 (define-public (make-skip-music dur)
339 (make-music 'SkipMusic
342 (define-public (make-grace-music music)
343 (make-music 'GraceMusic
349 (define-public (make-multi-measure-rest duration location)
350 (make-music 'MultiMeasureRestMusicGroup
352 'elements (list (make-music 'BarCheck
354 (make-event-chord (list (make-music 'MultiMeasureRestEvent
356 'duration duration)))
357 (make-music 'BarCheck
360 (define-public (glue-mm-rest-texts music)
361 "Check if we have R1*4-\\markup { .. }, and if applicable convert to
362 a property set for MultiMeasureRestNumber."
363 (define (script-to-mmrest-text script-music)
364 "Extract 'direction and 'text from SCRIPT-MUSIC, and transform into property sets."
365 (let ((dir (ly:music-property script-music 'direction))
366 (p (make-music 'MultiMeasureTextEvent
367 'text (ly:music-property script-music 'text))))
369 (set! (ly:music-property p 'direction) dir))
371 (if (eq? (ly:music-property music 'name) 'MultiMeasureRestMusicGroup)
372 (let* ((text? (lambda (x) (memq 'script-event (ly:music-property x 'types))))
373 (es (ly:music-property music 'elements))
374 (texts (map script-to-mmrest-text (filter text? es)))
375 (others (remove text? es)))
377 (set! (ly:music-property music 'elements)
378 (cons (make-event-chord texts) others)))))
382 (define-public (make-property-set sym val)
383 (make-music 'PropertySet
387 (define-public (make-ottava-set octavation)
388 (let ((m (make-music 'ApplyContext)))
389 (define (ottava-modify context)
390 "Either reset middleCPosition to the stored original, or remember
391 old middleCPosition, add OCTAVATION to middleCPosition, and set
392 OTTAVATION to `8va', or whatever appropriate."
393 (if (number? (ly:context-property context 'middleCPosition))
395 (let ((where (ly:context-property-where-defined context 'middleCPosition))
396 (oc0 (ly:context-property context 'originalCentralCPosition)))
397 (ly:context-set-property! context 'middleCPosition oc0)
398 (ly:context-unset-property where 'originalCentralCPosition)
399 (ly:context-unset-property where 'ottavation))
400 (let* ((where (ly:context-property-where-defined context 'middleCPosition))
401 (c0 (ly:context-property context 'middleCPosition))
402 (new-c0 (+ c0 (* -7 octavation)))
403 (string (cdr (assoc octavation '((2 . "15ma")
407 (-2 . "15ma bassa"))))))
408 (ly:context-set-property! context 'middleCPosition new-c0)
409 (ly:context-set-property! context 'originalCentralCPosition c0)
410 (ly:context-set-property! context 'ottavation string)))))
411 (set! (ly:music-property m 'procedure) ottava-modify)
412 (context-spec-music m 'Staff)))
414 (define-public (set-octavation ottavation)
415 (ly:export (make-ottava-set ottavation)))
417 (define-public (make-time-signature-set num den . rest)
418 "Set properties for time signature NUM/DEN. Rest can contain a list
420 (let* ((set1 (make-property-set 'timeSignatureFraction (cons num den)))
421 (beat (ly:make-moment 1 den))
422 (len (ly:make-moment num den))
423 (set2 (make-property-set 'beatLength beat))
424 (set3 (make-property-set 'measureLength len))
425 (set4 (make-property-set 'beatGrouping (if (pair? rest)
428 (basic (list set1 set2 set3 set4)))
430 (context-spec-music (make-sequential-music basic) 'Timing) 'Score)))
432 (define-public (make-mark-set label)
433 "Make the music for the \\mark command."
434 (let* ((set (if (integer? label)
435 (context-spec-music (make-property-set 'rehearsalMark label)
438 (ev (make-music 'MarkEvent))
439 (ch (make-event-chord (list ev))))
441 (make-sequential-music (list set ch))
443 (set! (ly:music-property ev 'label) label)
446 (define-public (set-time-signature num den . rest)
447 (ly:export (apply make-time-signature-set `(,num ,den . ,rest))))
449 (define-safe-public (make-penalty-music pen page-pen)
450 (make-music 'BreakEvent
452 'page-penalty page-pen))
454 (define-safe-public (make-articulation name)
455 (make-music 'ArticulationEvent
456 'articulation-type name))
458 (define-public (make-lyric-event string duration)
459 (make-music 'LyricEvent
463 (define-safe-public (make-span-event type spandir)
465 'span-direction spandir))
467 (define-public (set-mus-properties! m alist)
468 "Set all of ALIST as properties of M."
471 (set! (ly:music-property m (caar alist)) (cdar alist))
472 (set-mus-properties! m (cdr alist)))))
474 (define-public (music-separator? m)
476 (let ((ts (ly:music-property m 'types)))
477 (memq 'separator ts)))
479 ;;; splitting chords into voices.
480 (define (voicify-list lst number)
481 "Make a list of Musics.
483 voicify-list :: [ [Music ] ] -> number -> [Music]
484 LST is a list music-lists.
486 NUMBER is 0-base, i.e. Voice=1 (upstems) has number 0.
490 (cons (context-spec-music
491 (make-sequential-music
492 (list (make-voice-props-set number)
493 (make-simultaneous-music (car lst))))
494 'Voice (number->string (1+ number)))
495 (voicify-list (cdr lst) (1+ number)))))
497 (define (voicify-chord ch)
498 "Split the parts of a chord into different Voices using separator"
499 (let ((es (ly:music-property ch 'elements)))
500 (set! (ly:music-property ch 'elements)
501 (voicify-list (split-list es music-separator?) 0))
504 (define-public (voicify-music m)
505 "Recursively split chords that are separated with \\ "
506 (if (not (ly:music? m))
508 (error "not music!")))
509 (let ((es (ly:music-property m 'elements))
510 (e (ly:music-property m 'element)))
513 (set! (ly:music-property m 'elements) (map voicify-music es)))
515 (set! (ly:music-property m 'element) (voicify-music e)))
516 (if (and (equal? (ly:music-property m 'name) 'SimultaneousMusic)
517 (reduce (lambda (x y ) (or x y)) #f (map music-separator? es)))
518 (set! m (context-spec-music (voicify-chord m) 'Staff)))
521 (define-public (empty-music)
522 (ly:export (make-music 'Music)))
525 ; Make a function that checks score element for being of a specific type.
526 (define-public (make-type-checker symbol)
529 ;;(eq? #t (ly:grob-property elt symbol))
530 (not (eq? #f (memq symbol (ly:grob-property elt 'interfaces))))))
532 (define-public ((outputproperty-compatibility func sym val) grob g-context ao-context)
534 (set! (ly:grob-property grob sym) val)))
537 (define-public ((set-output-property grob-name symbol val) grob grob-c context)
540 \\applyoutput #(set-output-property 'Clef 'extra-offset '(0 . 1))
543 (let ((meta (ly:grob-property grob 'meta)))
544 (if (equal? (cdr (assoc 'name meta)) grob-name)
545 (set! (ly:grob-property grob symbol) val))))
549 (define-public (smart-bar-check n)
550 "Make a bar check that checks for a specific bar number.
552 (let ((m (make-music 'ApplyContext)))
554 (let* ((bn (ly:context-property tr 'currentBarNumber)))
558 (format "Bar check failed, we should have reached ~a, instead at ~a\n"
560 (set! (ly:music-property m 'procedure) checker)
563 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
564 ;; warn for bare chords at start.
566 (define (has-request-chord elts)
567 (reduce (lambda (x y) (or x y)) #f
569 (equal? (ly:music-property x 'name) 'RequestChord))
572 (define (ly:music-message music msg)
573 (let ((ip (ly:music-property music 'origin)))
574 (if (ly:input-location? ip)
575 (ly:input-message ip msg)
578 (define (check-start-chords music)
579 "Check music expression for a Simultaneous_music containing notes\n(ie. Request_chords),
580 without context specification. Called from parser."
581 (let ((es (ly:music-property music 'elements))
582 (e (ly:music-property music 'element))
583 (name (ly:music-property music 'name)))
584 (cond ((equal? name "Context_specced_music") #t)
585 ((equal? name "Simultaneous_music")
586 (if (has-request-chord es)
587 (ly:music-message music "Starting score with a chord.\nInsert an explicit \\context before chord")
588 (map check-start-chords es)))
589 ((equal? name "SequentialMusic")
591 (check-start-chords (car es))))
592 (else (if (ly:music? e) (check-start-chords e)))))
597 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
599 ;; setting stuff for grace context.
602 (define (vector-extend v x)
603 "Make a new vector consisting of V, with X added to the end."
604 (let* ((n (vector-length v))
605 (nv (make-vector (+ n 1) '())))
606 (vector-move-left! v 0 n nv 0)
610 (define (vector-map f v)
611 "Map F over V. This function returns nothing."
612 (do ((n (vector-length v))
615 (f (vector-ref v i))))
617 (define (vector-reverse-map f v)
618 "Map F over V, N to 0 order. This function returns nothing."
619 (do ((i (- (vector-length v) 1) (- i 1)))
621 (f (vector-ref v i))))
623 ;; TODO: make a remove-grace-property too.
624 (define-public (add-grace-property context-name grob sym val)
625 "Set SYM=VAL for GROB in CONTEXT-NAME. "
626 (define (set-prop context)
627 (let* ((where (ly:context-property-where-defined context 'graceSettings))
628 (current (ly:context-property where 'graceSettings))
629 (new-settings (append current
630 (list (list context-name grob sym val)))))
631 (ly:context-set-property! where 'graceSettings new-settings)))
632 (ly:export (context-spec-music (make-apply-context set-prop) 'Voice)))
636 (defmacro-public def-grace-function (start stop)
637 `(def-music-function (parser location music) (ly:music?)
638 (make-music 'GraceMusic
640 'element (make-music 'SequentialMusic
641 'elements (list (ly:music-deep-copy ,start)
643 (ly:music-deep-copy ,stop))))))
645 (defmacro-public def-music-function (args signature . body)
646 "Helper macro for `ly:make-music-function'.
648 (def-music-function (parser location arg1 arg2 ...) (arg1-type? arg2-type? ...)
651 `(ly:make-music-function (list ,@signature)
656 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
658 (define-public (cue-substitute quote-music)
659 "Must happen after quote-substitute."
661 (if (vector? (ly:music-property quote-music 'quoted-events))
662 (let* ((dir (ly:music-property quote-music 'quoted-voice-direction))
663 (main-voice (if (eq? 1 dir) 1 0))
664 (cue-voice (if (eq? 1 dir) 0 1))
665 (main-music (ly:music-property quote-music 'element))
666 (return-value quote-music))
668 (if (or (eq? 1 dir) (eq? -1 dir))
670 ;; if we have stem dirs, change both quoted and main music
671 ;; to have opposite stems.
675 ;; cannot context-spec Quote-music, since context
676 ;; for the quotes is determined in the iterator.
677 (make-sequential-music
679 (context-spec-music (make-voice-props-set cue-voice) 'Voice "cue")
681 (context-spec-music (make-voice-props-revert) 'Voice "cue"))))
683 (make-sequential-music
685 (make-voice-props-set main-voice)
687 (make-voice-props-revert))))
688 (set! (ly:music-property quote-music 'element) main-music)))
693 (define-public ((quote-substitute quote-tab) music)
694 (let* ((quoted-name (ly:music-property music 'quoted-music-name))
695 (quoted-vector (if (string? quoted-name)
696 (hash-ref quote-tab quoted-name #f)
699 (if (string? quoted-name)
700 (if (vector? quoted-vector)
701 (set! (ly:music-property music 'quoted-events) quoted-vector)
702 (ly:warn "Cannot find quoted music `~S'" quoted-name)))
707 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
708 ;; switch it on here, so parsing and init isn't checked (too slow!)
710 ;; automatic music transformations.
712 (define (switch-on-debugging m)
713 (if (defined? 'set-debug-cell-accesses!)
714 (set-debug-cell-accesses! 15000))
717 (define (music-check-error music)
720 (if (and (ly:music? m)
721 (eq? (ly:music-property m 'error-found) #t))
724 (for-each signal (ly:music-property music 'elements))
725 (signal (ly:music-property music 'element))
728 (set! (ly:music-property music 'error-found) #t))
731 (define (precompute-music-length music)
732 (set! (ly:music-property music 'length)
733 (ly:music-length music))
736 (define-public toplevel-music-functions
738 ;; check-start-chords ; ; no longer needed with chord syntax.
739 (lambda (music parser) (voicify-music music))
740 (lambda (x parser) (music-map glue-mm-rest-texts x))
741 (lambda (x parser) (music-map music-check-error x))
742 (lambda (x parser) (music-map precompute-music-length x))
743 (lambda (music parser)
745 (music-map (quote-substitute (ly:parser-lookup parser 'musicQuotes)) music))
746 ;; switch-on-debugging
747 (lambda (x parser) (music-map cue-substitute x))))
752 (define (apply-durations lyric-music durations)
753 (define (apply-duration music)
754 (if (and (not (equal? (ly:music-length music) ZERO-MOMENT))
755 (ly:duration? (ly:music-property music 'duration)))
757 (set! (ly:music-property music 'duration) (car durations))
758 (set! durations (cdr durations)))))
760 (music-map apply-duration lyric-music))
763 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
766 (define-public ((add-balloon-text object-name text off) grob orig-context cur-context)
767 "Usage: see input/regression/balloon.ly "
768 (let* ((meta (ly:grob-property grob 'meta))
769 (nm (if (pair? meta) (cdr (assoc 'name meta)) "nonexistant"))
770 (cb (ly:grob-property grob 'print-function)))
771 (if (equal? nm object-name)
773 (set! (ly:grob-property grob 'print-function) Balloon_interface::print)
774 (set! (ly:grob-property grob 'balloon-original-callback) cb)
775 (set! (ly:grob-property grob 'balloon-text) text)
776 (set! (ly:grob-property grob 'balloon-text-offset) off)
777 (set! (ly:grob-property grob 'balloon-text-props) '((font-family . roman)))))))
779 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
782 (define-public (set-accidentals-properties extra-natural
786 (make-sequential-music
787 (append (if (boolean? extra-natural)
788 (list (make-property-set 'extraNatural extra-natural))
790 (list (make-property-set 'autoAccidentals auto-accs)
791 (make-property-set 'autoCautionaries auto-cauts))))
794 (define-public (set-accidental-style style . rest)
795 "Set accidental style to STYLE. Optionally takes a context argument,
796 e.g. 'Staff or 'Voice. The context defaults to Voice, except for piano styles, which
797 use GrandStaff as a context. "
798 (let ((context (if (pair? rest)
800 (pcontext (if (pair? rest)
801 (car rest) 'GrandStaff)))
804 ;; accidentals as they were common in the 18th century.
805 ((equal? style 'default)
806 (set-accidentals-properties #t '(Staff (same-octave . 0))
808 ;; accidentals from one voice do NOT get cancelled in other voices
809 ((equal? style 'voice)
810 (set-accidentals-properties #t '(Voice (same-octave . 0))
812 ;; accidentals as suggested by Kurt Stone, Music Notation in the 20th century.
813 ;; This includes all the default accidentals, but accidentals also needs cancelling
814 ;; in other octaves and in the next measure.
815 ((equal? style 'modern)
816 (set-accidentals-properties #f '(Staff (same-octave . 0) (any-octave . 0) (same-octave . 1))
818 ;; the accidentals that Stone adds to the old standard as cautionaries
819 ((equal? style 'modern-cautionary)
820 (set-accidentals-properties #f '(Staff (same-octave . 0))
821 '(Staff (any-octave . 0) (same-octave . 1))
823 ;; Multivoice accidentals to be read both by musicians playing one voice
824 ;; and musicians playing all voices.
825 ;; Accidentals are typeset for each voice, but they ARE cancelled across voices.
826 ((equal? style 'modern-voice)
827 (set-accidentals-properties #f
828 '(Voice (same-octave . 0) (any-octave . 0) (same-octave . 1)
829 Staff (same-octave . 0) (any-octave . 0) (same-octave . 1))
832 ;; same as modernVoiceAccidental eccept that all special accidentals are typeset
834 ((equal? style 'modern-voice-cautionary)
835 (set-accidentals-properties #f
836 '(Voice (same-octave . 0))
837 '(Voice (any-octave . 0) (same-octave . 1)
838 Staff (same-octave . 0) (any-octave . 0) (same-octave . 1))
840 ;; stone's suggestions for accidentals on grand staff.
841 ;; Accidentals are cancelled across the staves in the same grand staff as well
842 ((equal? style 'piano)
843 (set-accidentals-properties #f
844 '(Staff (same-octave . 0)
845 (any-octave . 0) (same-octave . 1)
846 GrandStaff (any-octave . 0) (same-octave . 1))
849 ((equal? style 'piano-cautionary)
850 (set-accidentals-properties #f
851 '(Staff (same-octave . 0))
852 '(Staff (any-octave . 0) (same-octave . 1)
853 GrandStaff (any-octave . 0) (same-octave . 1))
855 ;; do not set localKeySignature when a note alterated differently from
856 ;; localKeySignature is found.
857 ;; Causes accidentals to be printed at every note instead of
858 ;; remembered for the duration of a measure.
859 ;; accidentals not being remembered, causing accidentals always to be typeset relative to the time signature
860 ((equal? style 'forget)
861 (set-accidentals-properties '()
862 '(Staff (same-octave . -1))
864 ;; Do not reset the key at the start of a measure. Accidentals will be
865 ;; printed only once and are in effect until overridden, possibly many
867 ((equal? style 'no-reset)
868 (set-accidentals-properties '()
869 '(Staff (same-octave . #t))
873 (ly:warn "Unknown accidental style: ~S" (symbol->string style))
874 (make-sequential-music '()))))))
876 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
878 (define-public (skip-of-length mus)
879 "Create a skip of exactly the same length as MUS."
883 'duration (ly:make-duration 0 0))))
885 (make-event-chord (list (ly:music-compress skip (ly:music-length mus))))))
887 (define-public (mmrest-of-length mus)
888 "Create a mmrest of exactly the same length as MUS."
891 (make-multi-measure-rest
892 (ly:make-duration 0 0) '())))
893 (ly:music-compress skip (ly:music-length mus))