Add easy staff-switching macros.
[opus_libre.git] / lib / 80-buildskel.scm
blobe58d7f111981b8238533f31433c98d7051829285
1 ;------------------------------------------------------------------;
2 ; opus_libre -- 80-buildskel.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 ;------------------------------------------------------------------;
13 (define (include-music name)
14   (let ((mus (ly:parser-lookup parser (string->symbol name))))
15     (if (ly:music? mus)
16         (begin (if (ly:get-option 'debug-messages)
17                   (ly:message "Loading music from ~a..." name))
18                mus)
19         (begin (if (ly:get-option 'debug-messages)
20                   (ly:message "Variable ~a doesn't exist." name))
21                (make-music 'Music 'void #t)))))
23 (define newStaff
24   (define-music-function (parser location name) (string?)
25     (let* ((name (assoc-name lang:instruments name))
26            (mus-name (string-append current-part name))
27            (music (ly:parser-lookup parser (string->symbol mus-name)))
28            (instr (make-this-text name lang:instr-suffix))
29            (short-instr (make-this-text name lang:short-instr-suffix))
30            (lyrics (ly:parser-lookup parser
31                                      (string->symbol
32                                       (string-append mus-name lang:lyrics-suffix)))))
33       (if (ly:get-option 'debug-messages) (ly:message "Loading music from ~a..." mus-name))
34       (if (ly:music? music)
35 ;;  (if (ly:moment<? (ly:music-length music) (ly:make-moment 1 1000))
36           #{ <<
37              \new Staff \with {
38                instrumentName = $instr
39                shortInstrumentName = $short-instr
40              }
41              \new Voice = $name $music
42                $(if (ly:music? lyrics)
43                   #{ \new Lyrics \lyricsto $name $lyrics #})
44           >> #}
45           (begin (if (ly:get-option 'debug-messages)
46                      (ly:message "Variable ~a doesn't exist." mus-name))
47               (make-music 'Music 'void #t))))))
49 (define newLyrics
50   (define-music-function (parser location name) (string?)
51     (let* ((name (assoc-name lang:instruments name))
52            (mus-name (string-append current-part name)))
53       #{
54         $(let* ((musiclist (list #{ {} #}))
55                 (numlist (if (ly:get-option 'only-suffixed-varnames)
56                             lang:numbers
57                             (cons "" lang:numbers))))
58           (map (lambda (x)
59                   (let* ((lyr-name (string-append mus-name lang:lyrics-suffix
60                                                   (string-capitalize x)))
61                         (lyrics (ly:parser-lookup parser (string->symbol lyr-name))))
62                     (if (ly:music? lyrics)
63                         (append! musiclist (list
64                                             #{ \new Lyrics \lyricsto $name $lyrics #})))))
65                 lang:numbers)
66           (make-simultaneous-music musiclist))
67       #})))
69 (define newGrandStaff
70   (define-music-function (parser location name) (string?)
71     #{ \new GrandStaff
72        $(let* ((name (assoc-name lang:instruments name))
73                (mus-name (string-append current-part name))
74                (musiclist (list #{ {} #}))
75                (numlist (if (ly:get-option 'only-suffixed-varnames)
76                             lang:numbers
77                             (cons "" lang:numbers))))
78           (map (lambda (x)
79                   (let ((staff-name (string-append mus-name (string-capitalize x))))
80                      (append! musiclist (list
81                         #{ \newStaff $staff-name #}))))
82             lang:numbers)
83           (make-simultaneous-music musiclist))
84      #} ))
86 (define newPianoStaff ;; TODO: include lyrics?
87   (define-music-function (parser location name) (string?)
88     (let* ((current-name (string-append current-part (assoc-name lang:instruments name)))
89            (upper (string-append current-name (string-capitalize lang:upper-hand)))
90            (lower (string-append current-name (string-capitalize lang:lower-hand)))
91            (dynamics (string-append current-name lang:dynamics-suffix))
92            (instr (make-this-text name lang:instr-suffix))
93            (short-instr (make-this-text name lang:short-instr-suffix)))
94     #{ \new PianoStaff \with {
95          instrumentName = $instr
96          shortInstrumentName = $short-instr
97        }
98      <<
99          \new Staff = $lang:upper-hand $(include-music upper)
100          \new Dynamics $(include-music dynamics)
101          \new Staff = $lang:lower-hand $(include-music lower)
102      >> #})))