Use new \tuplet syntax
[opus_libre.git] / bin / macros.scm
blobfcbec14c08df99f306d9c2e5e598d926bfc47a3a
1 ;------------------------------------------------------------------;
2 ; opus_libre -- macros.scm                                         ;
3 ;                                                                  ;
4 ; (c) 2008-2011 Valentin Villenave <valentin@villenave.net>        ;
5 ;                                                                  ;
6 ;     opus_libre is a free framework for GNU LilyPond: you may     ;
7 ; redistribute it and/or modify it under the terms of the GNU      ;
8 ; General Public License as published by the Free Software         ;
9 ; Foundation, either version 3 of the License, or (at your option) ;
10 ; any later version.                                               ;
11 ;     This program is distributed WITHOUT ANY WARRANTY; without    ;
12 ; even the implied warranty of MERCHANTABILITY or FITNESS FOR A    ;
13 ; PARTICULAR PURPOSE.  You should have received a copy of the GNU  ;
14 ; General Public License along with this program (typically in the ;
15 ; share/doc/ directory).  If not, see http://www.gnu.org/licenses/ ;
16 ;                                                                  ;
17 ;------------------------------------------------------------------;
20 ; Input macros.
22 (load "../lib/libmusic.scm")
24 ;; TODO: use make-simple-function everywhere possible.
26 ;; Rhythm shortcuts -----------------------------------------------;
27 (make-function lang:tuplet-letter ; default: \t
28   (define-music-function (parser location span music)
29     ((ly:duration? '()) ly:music?)
30     #{ \tuplet 3/2 $(if (not-null? span) span) $music #}))
32 (make-function lang:tuplet-letter-double ; \tt
33   (define-music-function (parser location span music)
34     ((ly:duration? '()) ly:music?)
35     #{ \tuplet 5/4 $(if (not-null? span) span) $music #}))
37 (make-function lang:tuplet-letter-triple ; \ttt
38   (define-music-function (parser location span music)
39     ((ly:duration? '()) ly:music?)
40     #{ \tuplet 6/4 $(if (not-null? span) span) $music #}))
42 (make-function lang:tuplet-letter-quad ; \tttt
43   (define-music-function (parser location span music)
44     ((ly:duration? '()) ly:music?)
45     #{ \tuplet 7/4 $(if (not-null? span) span) $music #}))
48 ;; Time signature equivalence
49 (define equiv
50  (define-music-function (parser location str) (string?)
51    (let* ((mark-ev (make-music 'MarkEvent))
52           (mark-ch (make-event-chord (list mark-ev)))
53           (equiv-lst (string-split str #\= ))
54           (before (parse-my-duration (car equiv-lst)))
55           (after (parse-my-duration (cadr equiv-lst)))
56           (before-mark (make-note-by-number-markup (car before) (cadr before) 1))
57           (after-mark (make-note-by-number-markup (car after) (cadr after) 1))
58           (equiv-mark
59             (make-concat-markup
60               (list
61                 (make-general-align-markup Y DOWN
62                   (make-smaller-markup before-mark))
63                 (make-simple-markup " ")
64                 (make-simple-markup "=")
65                 (make-simple-markup " ")
66                 (make-general-align-markup Y DOWN
67                   (make-smaller-markup after-mark))
68                 )))
69           (mark-set (context-spec-music
70               (make-property-set 'rehearsalMark equiv-mark)
71               'Score)))
72          (ly:music-set-property! mark-ev 'origin location)
73          (ly:music-set-property! mark-ev 'label equiv-mark)
74          mark-ch)))
76 ;; Auto octavation ------------------------------------------------;
77 (define oct
78   (define-music-function (parser location x) (ly:music?)
79     (octavize x)))
81 ;; Polyphony shortcuts --------------------------------------------;
82 (define pl
83   (define-music-function (parser location one two)
84     (ly:music? ly:music?)
85     #{ << { \voiceTwo $one } \\ { \voiceOne $two } >> #}))
87 (staff-change-command lang:upper-hand) ;; depending on your input language:
88 (staff-change-command lang:lower-hand) ;; \rh or \md etc. for switching staves.
91 (define hideNote #{
92 \once \override Dots #'transparent = ##t
93 \once \override NoteHead #'transparent = ##t
94 \once \override NoteHead #'no-ledgers = ##t
95 \once \override Stem #'transparent = ##t
96 \once \override Flag #'transparent = ##t
97 \once \override Beam #'transparent = ##t
98 \once \override Accidental #'transparent = ##t
99 #})
101 (define hideNoteHead #{
102 \once \override NoteHead #'transparent = ##t
105 (define hideNoteHeads
106   (define-music-function (parser location x) (ly:music?)
107   #{\override NoteHead #'transparent = ##t $x \revert NoteHead #'transparent #}))
109 (define noTuplet #{
110 \once \override TupletBracket #'transparent = ##t
111 \once \override TupletNumber #'transparent = ##t
114 (define noTuplets
115   (define-music-function (parser location x) (ly:music?)
116   #{
117 \override TupletBracket #'transparent = ##t
118 \override TupletNumber #'transparent = ##t
120 \revert TupletBracket #'transparent
121 \revert TupletNumber #'transparent
122 #}))
124 (define tupletsOff #{
125 \override TupletBracket #'transparent = ##t
126 \override TupletNumber #'transparent = ##t
129 (define tupletsOn #{
130 \override TupletBracket #'transparent = ##f
131 \override TupletNumber #'transparent = ##f
134 (define oneStemDown #{
135 \once \override Stem #'direction = #DOWN
138 (define oneStemUp #{
139 \once \override Stem #'direction = #UP
142 (define graceNote #{
143 %% Pasted from graceSettings definition in engraver-init.ly
144 %% \once \override Stem #'direction = #UP
145 \once \override Stem #'font-size = #-3
146 \once \override NoteHead #'font-size = #-3
147 \once \override TabNoteHead #'font-size = #-4
148 \once \override Dots #'font-size = #-3
149 \once \override Stem #'length-fraction = #0.8
150 \once \override Flag #'font-size = #-3
151 %% \once \override Stem #'no-stem-extend = ##t
152 \once \override Beam #'beam-thickness = #0.384
153 \once \override Beam #'length-fraction = #0.8
154 \once \override Accidental #'font-size = #-4
155 \once \override AccidentalCautionary #'font-size = #-4
156 %% \once \override Slur #'direction = #DOWN
157 \once \override Script #'font-size = #-3
158 \once \override Fingering #'font-size = #-8
159 \once \override StringNumber #'font-size = #-8
162 (define graceNotes
163   (define-music-function (parser location x) (ly:music?)
164   #{
165 %% \override Stem #'direction = #UP %% Nope.
166 \override Stem #'font-size = #-3
167 \override Flag #'font-size = #-3
168 \override NoteHead #'font-size = #-3
169 \override TabNoteHead #'font-size = #-4
170 \override Dots #'font-size = #-3
171 \override Stem #'length-fraction = #0.8
172 %% \override Stem #'no-stem-extend = ##t %% Not sure.
173 \override Beam #'beam-thickness = #0.384
174 \override Beam #'length-fraction = #0.8
175 \override Accidental #'font-size = #-4
176 \override AccidentalCautionary #'font-size = #-4
177 %% \override Slur #'direction = #DOWN
178 \override Script #'font-size = #-3
179 \override Fingering #'font-size = #-8
180 \override StringNumber #'font-size = #-8
182 %% \revert Stem #'direction
183 \revert Stem #'font-size
184 \revert NoteHead #'font-size
185 \revert TabNoteHead #'font-size
186 \revert Dots #'font-size
187 \revert Stem #'length-fraction
188 %% \revert Stem #'no-stem-extend
189 \revert Beam #'beam-thickness
190 \revert Beam #'length-fraction
191 \revert Accidental #'font-size
192 \revert AccidentalCautionary #'font-size
193 %% \revert Slur #'direction
194 \revert Script #'font-size
195 \revert Fingering #'font-size
196 \revert StringNumber #'font-size
197 #}))
199 (define lightBeam #{
200 \once \override Beam #'beam-thickness = #0.384
201 \once \override Beam #'gap = #0.5
202 \override Flag #'font-size = #-3
205 (define lightBeams
206   (define-music-function (parser location x) (ly:music?) #{
207 \override Beam #'beam-thickness = #0.384
208 \override Beam #'gap = #0.5
209 \override Flag #'font-size = #-3
211 \revert Beam #'beam-thickness
212 \revert Beam #'gap
213 \revert Flag #'font-size
214 #}))
216 (define longHairpin #{
217 \once \override Hairpin #'to-barline = ##f
220 (define longHairpins
221   (define-music-function (parser location x) (ly:music?) #{
222 \override Hairpin #'to-barline = ##f
224 \revert Hairpin #'to-barline
225 #}))
227 (define whiteNote
228   (define-music-function (parser location x) (ly:music?)
229     (set! (ly:music-property x 'tweaks)
230                                (acons 'duration-log 1
231                                   (ly:music-property x 'tweaks)))
232                          x))
234 (define blackNote
235   (define-music-function (parser location x) (ly:music?)
236     (set! (ly:music-property x 'tweaks)
237        (acons 'before-line-breaking
238               (lambda (grob)
239                 (let ((dots (ly:grob-object grob 'dot)))
240                   (ly:grob-set-property! grob 'duration-log 2)
241                   (and (ly:grob? dots)
242                        (ly:grob-set-property! dots 'dot-count 0))))
243               (ly:music-property x 'tweaks)))
244         x))
246 (define parlato
247  (define-music-function (parser location x) (ly:music?)
249 \override NoteHead #'style = #'cross
251 \revert NoteHead #'style
252 #}))
254 (define slap ;;TODO: adapt accordingly to stem direction?
255  (define-music-function (parser location x) (ly:music?)
257 \override NoteHead #'stencil = #ly:text-interface::print
258 \override NoteHead #'text = \markup \musicglyph #"scripts.sforzato"
259 \override NoteHead #'extra-offset = #'(0.1 . 0.0 )
261 \revert NoteHead #'stencil
262 \revert NoteHead #'text
263 \revert NoteHead #'extra-offset
264 #}))
266 (define harmoChord ;; FIXME: overly complicated.
267  (define-music-function (parser location chord result) (ly:music? ly:music?)
268  #{
269 << \oneStemDown $chord \\ { \stemUp %FIXME: ties could look better.
270 \override NoteHead #'stencil = #ly:text-interface::print
271 \override NoteHead #'text = \markup { \null \musicglyph #"noteheads.s2"}
272 \once \override NoteHead #'text = \markup {\null \override #'(direction . 1)
273   \dir-column {\musicglyph #"noteheads.s2" \teeny \musicglyph #"eight"}}
274 \override Stem #'stencil = ##f $result
275 \revert Stem #'stencil \revert NoteHead #'stencil \stemNeutral } >> #}))
277 (define harmonics
278  (define-music-function (parser location x) (ly:music?)
280 \override Dots #'transparent = ##t
281 \override Stem #'transparent = ##t
282 \override Beam #'transparent = ##t
283 \override NoteHead #'style = #'harmonic
285 \revert NoteHead #'style
286 \revert Beam #'transparent
287 \revert Stem #'transparent
288 \revert Dots #'transparent #}))
290 (define smart
291  (define-music-function (parser location x) (ly:music?)
292    (naturalize x)))