LEFT | RIGHT |
1 %%%% This file is part of LilyPond, the GNU music typesetter. | 1 %%%% This file is part of LilyPond, the GNU music typesetter. |
2 %%%% | 2 %%%% |
3 %%%% Copyright (C) 2011--2015 Graham Percival <graham@percival-music.ca> | 3 %%%% Copyright (C) 2011--2015 Graham Percival <graham@percival-music.ca> |
4 %%%% | 4 %%%% |
5 %%%% LilyPond is free software: you can redistribute it and/or modify | 5 %%%% LilyPond is free software: you can redistribute it and/or modify |
6 %%%% it under the terms of the GNU General Public License as published by | 6 %%%% it under the terms of the GNU General Public License as published by |
7 %%%% the Free Software Foundation, either version 3 of the License, or | 7 %%%% the Free Software Foundation, either version 3 of the License, or |
8 %%%% (at your option) any later version. | 8 %%%% (at your option) any later version. |
9 %%%% | 9 %%%% |
10 %%%% LilyPond is distributed in the hope that it will be useful, | 10 %%%% LilyPond is distributed in the hope that it will be useful, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 (ly:moment-main-denominator moment)))) | 59 (ly:moment-main-denominator moment)))) |
60 | 60 |
61 #(define (moment-grace->string moment) | 61 #(define (moment-grace->string moment) |
62 "Prints a moment without grace note(s) as a float such as | 62 "Prints a moment without grace note(s) as a float such as |
63 0.25000. Grace notes are written with the grace duration as a | 63 0.25000. Grace notes are written with the grace duration as a |
64 separate \"dashed\" number, i.e. 0.25000-0.12500. This allows any | 64 separate \"dashed\" number, i.e. 0.25000-0.12500. This allows any |
65 program using the output of this function to interpret grace notes | 65 program using the output of this function to interpret grace notes |
66 however they want (half duration, quarter duration? before beat, | 66 however they want (half duration, quarter duration? before beat, |
67 after beat? etc.)." | 67 after beat? etc.)." |
68 (if | 68 (if |
69 (eq? 0 (ly:moment-grace-numerator moment)) | 69 (zero? (ly:moment-grace-numerator moment)) |
70 (ly:format "~a" (format-moment moment)) | 70 (ly:format "~a" (format-moment moment)) |
71 ;; grace notes have a negative numerator, so no "-" necessary | 71 ;; grace notes have a negative numerator, so no "-" necessary |
72 (ly:format | 72 (ly:format |
73 "~a~a" | 73 "~a~a" |
74 (format-moment moment) | 74 (format-moment moment) |
75 (format-moment | 75 (format-moment |
76 (ly:make-moment | 76 (ly:make-moment |
77 (ly:moment-grace-numerator moment) | 77 (ly:moment-grace-numerator moment) |
78 (ly:moment-grace-denominator moment)))))) | 78 (ly:moment-grace-denominator moment)))))) |
79 | 79 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 #(define (format-rest engraver event) | 115 #(define (format-rest engraver event) |
116 (print-line engraver | 116 (print-line engraver |
117 "rest" | 117 "rest" |
118 (ly:duration->string | 118 (ly:duration->string |
119 (ly:event-property event 'duration)) | 119 (ly:event-property event 'duration)) |
120 (format-moment (ly:duration-length | 120 (format-moment (ly:duration-length |
121 (ly:event-property event 'duration))))) | 121 (ly:event-property event 'duration))))) |
122 | 122 |
123 #(define (format-note engraver event) | 123 #(define (format-note engraver event) |
124 (let* ((origin (ly:input-file-line-char-column | 124 (let* ((origin (ly:input-file-line-char-column |
125 (ly:event-property event 'origin)))) | 125 (ly:event-property event 'origin))) |
| 126 (drum-type (ly:event-property event 'drum-type)) |
| 127 (pitch (ly:event-property event 'pitch))) |
126 (print-line engraver | 128 (print-line engraver |
127 "note" | 129 (if (ly:pitch? pitch) |
128 ;; get a MIDI pitch value. | 130 "note" |
129 (+ 60 (ly:pitch-semitones | 131 "type") |
130 (ly:event-property event 'pitch))) | 132 (if (ly:pitch? pitch) |
| 133 ;; get a MIDI pitch value. |
| 134 (+ 60 (ly:pitch-semitones |
| 135 (ly:event-property event 'pitch))) |
| 136 drum-type) |
131 (ly:duration->string | 137 (ly:duration->string |
132 (ly:event-property event 'duration)) | 138 (ly:event-property event 'duration)) |
133 (format-moment (ly:duration-length | 139 (format-moment (ly:duration-length |
134 (ly:event-property event 'duration))) | 140 (ly:event-property event 'duration))) |
135 ;; point and click info | 141 ;; point and click info |
136 (ly:format "point-and-click ~a ~a" | 142 (ly:format "point-and-click ~a ~a" |
137 (caddr origin) | 143 (caddr origin) |
138 (cadr origin))))) | 144 (cadr origin))))) |
139 | |
140 #(define (format-drumnote engraver event) | |
141 (let* ((origin (ly:input-file-line-char-column | |
142 (ly:event-property event 'origin)))) | |
143 (print-line engraver | |
144 "note" | |
145 ;; get a drum name value. | |
146 (ly:event-property event 'drum-type) | |
147 (ly:duration->string | |
148 (ly:event-property event 'duration)) | |
149 (format-moment (ly:duration-length | |
150 (ly:event-property event 'duration))) | |
151 ;; point and click info | |
152 (ly:format "point-and-click ~a ~a" | |
153 (caddr origin) | |
154 (cadr origin))))) | |
155 | 145 |
156 #(define (format-tempo engraver event) | 146 #(define (format-tempo engraver event) |
157 (print-line engraver | 147 (print-line engraver |
158 "tempo" | 148 "tempo" |
159 ; get length of quarter notes, in seconds | 149 ; get length of quarter notes, in seconds |
160 (/ (ly:event-property event 'metronome-count) | 150 (/ (ly:event-property event 'metronome-count) |
161 (format-moment (ly:duration-length (ly:event-property | 151 (format-moment (ly:duration-length (ly:event-property |
162 event | 152 event |
163 'tempo-unit)))))) | 153 'tempo-unit)))))) |
164 | 154 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 (print-line engraver | 205 (print-line engraver |
216 "set_string" | 206 "set_string" |
217 (ly:event-property event 'span-direction) | 207 (ly:event-property event 'span-direction) |
218 left-text))) | 208 left-text))) |
219 | 209 |
220 | 210 |
221 %%%% The actual engraver definition: We just install some listeners so we | 211 %%%% The actual engraver definition: We just install some listeners so we |
222 %%%% are notified about all notes and rests. We don't create any grobs or | 212 %%%% are notified about all notes and rests. We don't create any grobs or |
223 %%%% change any settings. | 213 %%%% change any settings. |
224 | 214 |
| 215 #(define event-listener-engraver |
| 216 (make-engraver |
| 217 (listeners |
| 218 (tempo-change-event . format-tempo) |
| 219 (rest-event . format-rest) |
| 220 (note-event . format-note) ;; works for notes and drum notes |
| 221 (articulation-event . format-articulation) |
| 222 (text-script-event . format-text) |
| 223 (slur-event . format-slur) |
| 224 (breathing-event . format-breathe) |
| 225 (dynamic-event . format-dynamic) |
| 226 (crescendo-event . format-cresc) |
| 227 (decrescendo-event . format-decresc) |
| 228 (text-span-event . format-textspan) |
| 229 (glissando-event . format-glissando) |
| 230 (tie-event . format-tie)))) |
| 231 |
225 \layout { | 232 \layout { |
226 \context { | 233 \context { |
227 \Voice | 234 \Voice |
228 \consists #(make-engraver | 235 \consists #event-listener-engraver |
229 (listeners | |
230 (tempo-change-event . format-tempo) | |
231 (rest-event . format-rest) | |
232 (note-event . format-note) | |
233 (articulation-event . format-articulation) | |
234 (text-script-event . format-text) | |
235 (slur-event . format-slur) | |
236 (breathing-event . format-breathe) | |
237 (dynamic-event . format-dynamic) | |
238 (crescendo-event . format-cresc) | |
239 (decrescendo-event . format-decresc) | |
240 (text-span-event . format-textspan) | |
241 (glissando-event . format-glissando) | |
242 (tie-event . format-tie))) | |
243 } | 236 } |
244 | 237 \context { |
245 \context { | 238 \DrumVoice |
246 \DrumVoice | 239 \consists #event-listener-engraver |
247 \consists #(make-engraver | |
248 (listeners | |
249 (tempo-change-event . format-tempo) | |
250 (rest-event . format-rest) | |
251 (note-event . format-drumnote) | |
252 (articulation-event . format-articulation) | |
253 (text-script-event . format-text) | |
254 (slur-event . format-slur) | |
255 (breathing-event . format-breathe) | |
256 (dynamic-event . format-dynamic) | |
257 (crescendo-event . format-cresc) | |
258 (decrescendo-event . format-decresc) | |
259 (text-span-event . format-textspan) | |
260 (glissando-event . format-glissando) | |
261 (tie-event . format-tie))) | |
262 } | 240 } |
263 } | 241 } |
LEFT | RIGHT |