1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 1998--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
4 ;;;; Jan Nieuwenhuizen <janneke@gnu.org>
5 ;;;; Neil Puttock <n.puttock@gmail.com>
6 ;;;; Carl Sorensen <c_sorensen@byu.edu>
8 ;;;; LilyPond is free software: you can redistribute it and/or modify
9 ;;;; it under the terms of the GNU General Public License as published by
10 ;;;; the Free Software Foundation, either version 3 of the License, or
11 ;;;; (at your option) any later version.
13 ;;;; LilyPond is distributed in the hope that it will be useful,
14 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;;;; GNU General Public License for more details.
18 ;;;; You should have received a copy of the GNU General Public License
19 ;;;; along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
21 ;; TODO: should link back into user manual.
23 (define (mm-rest-child-list music)
24 "Generate events for multimeasure rests,
25 to be used by the sequential-iterator"
26 (let ((location (ly:music-property music 'location)))
27 (list (make-music 'BarCheck
29 (make-music 'MultiMeasureRestEvent
30 (ly:music-deep-copy music))
34 (define (make-unfolded-set music)
35 (let ((n (ly:music-property music 'repeat-count))
36 (alts (ly:music-property music 'elements))
37 (body (ly:music-property music 'element)))
39 ((null? alts) (make-list n body))
42 (zip (make-list n body)
43 (append! (make-list (max 0 (- n (length alts)))
47 (define (make-volta-set music)
48 (let* ((alts (ly:music-property music 'elements))
50 (times (ly:music-property music 'repeat-count)))
55 ;; set properties for proper bar numbering
57 (list (make-music 'AlternativeEvent
58 'alternative-dir (if (= y 0)
61 'alternative-increment
68 (list (make-music 'AlternativeEvent
70 'alternative-increment 0))
75 (define (make-ottava-set music)
76 "Set context properties for an ottava bracket."
77 (let ((octavation (ly:music-property music 'ottava-number)))
79 (list (context-spec-music
82 (let ((offset (* -7 octavation))
83 (string (assoc-get octavation '((2 . "15ma")
88 (set! (ly:context-property context 'middleCOffset) offset)
89 (set! (ly:context-property context 'ottavation) string)
90 (ly:set-middle-C! context))))
93 (define (make-time-signature-set music)
94 "Set context properties for a time signature."
95 (let* ((num (ly:music-property music 'numerator))
96 (den (ly:music-property music 'denominator))
97 (structure (ly:music-property music 'beat-structure))
98 (fraction (cons num den)))
99 (list (descend-to-context
103 (let* ((time-signature-settings
104 (ly:context-property context 'timeSignatureSettings))
106 (base-length fraction time-signature-settings))
108 (if (null? structure)
109 (beat-structure my-base-length
111 time-signature-settings)
114 (beam-exceptions fraction time-signature-settings))
115 (new-measure-length (ly:make-moment num den)))
116 (ly:context-set-property!
117 context 'timeSignatureFraction fraction)
118 (ly:context-set-property!
119 context 'baseMoment (ly:make-moment my-base-length))
120 (ly:context-set-property!
121 context 'beatStructure my-beat-structure)
122 (ly:context-set-property!
123 context 'beamExceptions beaming-exception)
124 (ly:context-set-property!
125 context 'measureLength new-measure-length))))
128 (make-music 'TimeSignatureEvent music))))
130 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
131 ;; Some MIDI callbacks -- is this a good place for them?
133 (define-public (breathe::midi-length len context)
134 ;;Shorten by half, or by up to a second, but always by a power of 2
135 (let* ((desired (min (ly:moment-main (seconds->moment 1 context))
136 (* (ly:moment-main len) 1/2)))
137 (scale (inexact->exact (ceiling (/ (log desired) (log 1/2)))))
138 (breath (ly:make-moment (expt 1/2 scale))))
139 (ly:moment-sub (ly:make-moment (ly:moment-main len)) breath)))