Add easy staff-switching macros.
[opus_libre.git] / bin / macros.scm
blobf0ce3b18e59426240d441069cb27a5f7bace995c
1 ;------------------------------------------------------------------;
2 ; opus_libre -- macros.scm                                         ;
3 ;                                                                  ;
4 ; (c) 2008-2010 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, version 3 or later: gnu.org/licenses     ;
9 ;                                                                  ;
10 ;------------------------------------------------------------------;
12 ; Input macros.
14 ;; Rhythm shortcuts -----------------------------------------------;
15 (make-simple-function lang:tuplet-letter ; default: \t
16   #{ \times 2/3 $x #})
18 (make-simple-function lang:tuplet-letter-double ; \tt
19   #{ \times 4/5 $x #})
21 (make-simple-function lang:tuplet-letter-triple ; \ttt
22   #{ \times 4/6 $x #})
24 (make-simple-function lang:tuplet-letter-quad ; \tttt
25   #{ \times 4/7 $x #})
28 ;; Composite dynamics ---------------------------------------------;
29 (define dyn
30  ;;syntax: -\dyn instead of \dyn (see Issue #1264).
31  (define-music-function (parser location arg) (markup?)
32   (make-music 'AbsoluteDynamicEvent
33               'text (cond
34                      ((string? arg)
35                       (if (string-every char-set:dynamics arg)
36                           arg
37                           (markup #:dynamic-string arg)))
38                      (else arg)))))
41 ;; Auto octavation ------------------------------------------------;
42 (define oct
43  (define-music-function (parser location mus) (ly:music?)
44   (octavize mus)))
46 ;; Articulation shortcuts -----------------------------------------;
47 ;;TODO: how about an alist? (see libmusic.scm)
48 (make-script '(st . "staccato"))
49 (make-script '(acc . "accent"))
50 (make-script '(det . "tenuto")) ; as in "détaché"
51 (make-script '(stdet . "portato"))
52 (make-script '(accdet . '("tenuto" "accent")))
53 (make-script '(accst . '("accent" "staccato")))
54 (make-script '(dwnb . "downbow"))
56 (define ten
57   (define-music-function (parser location music) (ly:music?)
58    (if
59      (equal? (ly:music-property music 'name) 'EventChord)
60      (set! (ly:music-property music 'elements)
61            (append (ly:music-property music 'elements)
62                   (list (make-music 'TextScriptEvent 'text
63                     ;; ugh. Haphazard alignment.
64                     (markup #:translate-scaled (cons 4 0)
65                     #:indic "(ten.)"))))))
66                  music))
69 ;; Polyphony shortcuts --------------------------------------------;
70 (define pl
71   (define-music-function (parser location one two)
72                          (ly:music? ly:music?)
73 #{ << { \voiceTwo $one } \\ { \voiceOne $two } >> #}))
75 (staff-change-command lang:upper-hand) ;; depending on your input language:
76 (staff-change-command lang:lower-hand) ;; \rh or \md etc. for switching staves.