1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 2000--2015 Jan Nieuwenhuizen <janneke@gnu.org>
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
7 ;;;; the Free Software Foundation, either version 3 of the License, or
8 ;;;; (at your option) any later version.
10 ;;;; LilyPond is distributed in the hope that it will be useful,
11 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;;;; GNU General Public License for more details.
15 ;;;; You should have received a copy of the GNU General Public License
16 ;;;; along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
23 ;; this is broken: we should not ever export variables from Scheme.
25 ;; define factor of total volume per dynamic marking
26 (define-session-public absolute-volume-alist '())
27 (set! absolute-volume-alist
44 absolute-volume-alist))
46 (define-public (default-dynamic-absolute-volume s)
47 (assoc-get s absolute-volume-alist))
49 ;; define factors of total volume of minimum and maximum volume
50 (define-session-public instrument-equalizer-alist '())
51 (set! instrument-equalizer-alist
56 ("clarinet" . (0 . 0.7))
57 ("bassoon" . (0 . 0.6))
58 ("french horn" . (0.1 . 0.7))
59 ("trumpet" . (0.1 . 0.8))
60 ("timpani" . (0.2 . 0.9))
61 ("violin" . (0.2 . 1.0))
62 ("viola" . (0.1 . 0.7))
63 ("cello" . (0.2 . 0.8))
64 ("contrabass" . (0.2 . 0.8))
66 instrument-equalizer-alist))
68 (define-public (default-instrument-equalizer s)
69 (assoc-get s instrument-equalizer-alist))
71 ;; (name . program+32768*(channel10 ? 1 : 0))
72 (define instrument-names-alist '())
73 (set! instrument-names-alist
76 ("acoustic grand" . ,(- 1 1))
77 ("bright acoustic" . ,(- 2 1))
78 ("electric grand" . ,(- 3 1))
79 ("honky-tonk" . ,(- 4 1))
80 ("electric piano 1" . ,(- 5 1))
81 ("electric piano 2" . ,(- 6 1))
82 ("harpsichord" . ,(- 7 1))
85 ;; (9-16 chrom percussion)
86 ("celesta" . ,(- 9 1))
87 ("glockenspiel" . ,(- 10 1))
88 ("music box" . ,(- 11 1))
89 ("vibraphone" . ,(- 12 1))
90 ("marimba" . ,(- 13 1))
91 ("xylophone" . ,(- 14 1))
92 ("tubular bells" . ,(- 15 1))
93 ("dulcimer" . ,(- 16 1))
96 ("drawbar organ" . ,(- 17 1))
97 ("percussive organ" . ,(- 18 1))
98 ("rock organ" . ,(- 19 1))
99 ("church organ" . ,(- 20 1))
100 ("reed organ" . ,(- 21 1))
101 ("accordion" . ,(- 22 1))
102 ("harmonica" . ,(- 23 1))
103 ("concertina" . ,(- 24 1))
106 ("acoustic guitar (nylon)" . ,(- 25 1))
107 ("acoustic guitar (steel)" . ,(- 26 1))
108 ("electric guitar (jazz)" . ,(- 27 1))
109 ("electric guitar (clean)" . ,(- 28 1))
110 ("electric guitar (muted)" . ,(- 29 1))
111 ("overdriven guitar" . ,(- 30 1))
112 ("distorted guitar" . ,(- 31 1))
113 ("guitar harmonics" . ,(- 32 1))
116 ("acoustic bass" . ,(- 33 1))
117 ("electric bass (finger)" . ,(- 34 1))
118 ("electric bass (pick)" . ,(- 35 1))
119 ("fretless bass" . ,(- 36 1))
120 ("slap bass 1" . ,(- 37 1))
121 ("slap bass 2" . ,(- 38 1))
122 ("synth bass 1" . ,(- 39 1))
123 ("synth bass 2" . ,(- 40 1))
126 ("violin" . ,(- 41 1))
127 ("viola" . ,(- 42 1))
128 ("cello" . ,(- 43 1))
129 ("contrabass" . ,(- 44 1))
130 ("tremolo strings" . ,(- 45 1))
131 ("pizzicato strings" . ,(- 46 1))
132 ("orchestral harp" . ,(- 47 1))
133 ("timpani" . ,(- 48 1))
136 ("string ensemble 1" . ,(- 49 1))
137 ("string ensemble 2" . ,(- 50 1))
138 ("synthstrings 1" . ,(- 51 1))
139 ("synthstrings 2" . ,(- 52 1))
140 ("choir aahs" . ,(- 53 1))
141 ("voice oohs" . ,(- 54 1))
142 ("synth voice" . ,(- 55 1))
143 ("orchestra hit" . ,(- 56 1))
146 ("trumpet" . ,(- 57 1))
147 ("trombone" . ,(- 58 1))
149 ("muted trumpet" . ,(- 60 1))
150 ("french horn" . ,(- 61 1))
151 ("brass section" . ,(- 62 1))
152 ("synthbrass 1" . ,(- 63 1))
153 ("synthbrass 2" . ,(- 64 1))
156 ("soprano sax" . ,(- 65 1))
157 ("alto sax" . ,(- 66 1))
158 ("tenor sax" . ,(- 67 1))
159 ("baritone sax" . ,(- 68 1))
161 ("english horn" . ,(- 70 1))
162 ("bassoon" . ,(- 71 1))
163 ("clarinet" . ,(- 72 1))
166 ("piccolo" . ,(- 73 1))
167 ("flute" . ,(- 74 1))
168 ("recorder" . ,(- 75 1))
169 ("pan flute" . ,(- 76 1))
170 ("blown bottle" . ,(- 77 1))
171 ("shakuhachi" . ,(- 78 1))
172 ("whistle" . ,(- 79 1))
173 ("ocarina" . ,(- 80 1))
175 ;; (81-88 synth lead)
176 ("lead 1 (square)" . ,(- 81 1))
177 ("lead 2 (sawtooth)" . ,(- 82 1))
178 ("lead 3 (calliope)" . ,(- 83 1))
179 ("lead 4 (chiff)" . ,(- 84 1))
180 ("lead 5 (charang)" . ,(- 85 1))
181 ("lead 6 (voice)" . ,(- 86 1))
182 ("lead 7 (fifths)" . ,(- 87 1))
183 ("lead 8 (bass+lead)" . ,(- 88 1))
186 ("pad 1 (new age)" . ,(- 89 1))
187 ("pad 2 (warm)" . ,(- 90 1))
188 ("pad 3 (polysynth)" . ,(- 91 1))
189 ("pad 4 (choir)" . ,(- 92 1))
190 ("pad 5 (bowed)" . ,(- 93 1))
191 ("pad 6 (metallic)" . ,(- 94 1))
192 ("pad 7 (halo)" . ,(- 95 1))
193 ("pad 8 (sweep)" . ,(- 96 1))
195 ;; (97-104 synth effects)
196 ("fx 1 (rain)" . ,(- 97 1))
197 ("fx 2 (soundtrack)" . ,(- 98 1))
198 ("fx 3 (crystal)" . ,(- 99 1))
199 ("fx 4 (atmosphere)" . ,(- 100 1))
200 ("fx 5 (brightness)" . ,(- 101 1))
201 ("fx 6 (goblins)" . ,(- 102 1))
202 ("fx 7 (echoes)" . ,(- 103 1))
203 ("fx 8 (sci-fi)" . ,(- 104 1))
206 ("sitar" . ,(- 105 1))
207 ("banjo" . ,(- 106 1))
208 ("shamisen" . ,(- 107 1))
209 ("koto" . ,(- 108 1))
210 ("kalimba" . ,(- 109 1))
211 ("bagpipe" . ,(- 110 1))
212 ("fiddle" . ,(- 111 1))
213 ("shanai" . ,(- 112 1))
215 ;; (113-120 percussive)
216 ("tinkle bell" . ,(- 113 1))
217 ("agogo" . ,(- 114 1))
218 ("steel drums" . ,(- 115 1))
219 ("woodblock" . ,(- 116 1))
220 ("taiko drum" . ,(- 117 1))
221 ("melodic tom" . ,(- 118 1))
222 ("synth drum" . ,(- 119 1))
223 ("reverse cymbal" . ,(- 120 1))
225 ;; (121-128 sound effects)
226 ("guitar fret noise" . ,(- 121 1))
227 ("breath noise" . ,(- 122 1))
228 ("seashore" . ,(- 123 1))
229 ("bird tweet" . ,(- 124 1))
230 ("telephone ring" . ,(- 125 1))
231 ("helicopter" . ,(- 126 1))
232 ("applause" . ,(- 127 1))
233 ("gunshot" . ,(- 128 1))
235 ;; (channel 10 drum-kits - subtract 32768 to get program no.)
236 ("standard kit" . ,(+ 32768 0))
237 ("standard drums" . ,(+ 32768 0))
238 ("drums" . ,(+ 32768 0))
239 ("room kit" . ,(+ 32768 8))
240 ("room drums" . ,(+ 32768 8))
241 ("power kit" . ,(+ 32768 16))
242 ("power drums" . ,(+ 32768 16))
243 ("rock drums" . ,(+ 32768 16))
244 ("electronic kit" . ,(+ 32768 24))
245 ("electronic drums" . ,(+ 32768 24))
246 ("tr-808 kit" . ,(+ 32768 25))
247 ("tr-808 drums" . ,(+ 32768 25))
248 ("jazz kit" . ,(+ 32768 32))
249 ("jazz drums" . ,(+ 32768 32))
250 ("brush kit" . ,(+ 32768 40))
251 ("brush drums" . ,(+ 32768 40))
252 ("orchestra kit" . ,(+ 32768 48))
253 ("orchestra drums" . ,(+ 32768 48))
254 ("classical drums" . ,(+ 32768 48))
255 ("sfx kit" . ,(+ 32768 56))
256 ("sfx drums" . ,(+ 32768 56))
257 ("mt-32 kit" . ,(+ 32768 127))
258 ("mt-32 drums" . ,(+ 32768 127))
259 ("cm-64 kit" . ,(+ 32768 127))
260 ("cm-64 drums" . ,(+ 32768 127))
262 instrument-names-alist))
264 (define-public (percussion? instrument)
265 "Return @code{#t} if the instrument should use MIDI channel 9."
267 (let* ((inst (symbol->string instrument))
268 (entry (assoc-get inst instrument-names-alist)))
269 (and entry (>= entry 32768))))
271 (define-public (midi-program instrument)
272 "Return the program of the instrument."
274 (let* ((inst (symbol->string instrument))
275 (entry (assoc-get inst instrument-names-alist)))
280 ;; 90 == 90/127 == 0.71 is supposed to be the default value
281 ;; urg: we should set this at start of track
282 (define-public dynamic-default-volume 0.71)
284 (define-public (alterations-in-key pitch-list)
285 "Count number of sharps minus number of flats."
287 (apply + (map (lambda (p) (round (* (cdr p) 2))) pitch-list)) )
290 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
293 ;;; Adapted from the handle-metadata function in framework-ps.scm
294 (define (performance-name-from-header header)
295 (define (metadata-lookup-output overridevar fallbackvar)
296 (let* ((overrideval (ly:modules-lookup (list header) overridevar))
297 (fallbackval (ly:modules-lookup (list header) fallbackvar))
298 (val (if overrideval overrideval fallbackval)))
299 (if val (ly:encode-string-for-pdf (markup->string val)) "")))
302 (metadata-lookup-output 'midititle 'title)))
304 (define-public (write-performances-midis performances basename . rest)
305 (let ((midi-ext (ly:get-option 'midi-extension)))
308 ((perfs performances)
309 (count (if (null? rest) 0 (car rest))))
311 (let ((perf (car perfs)))
312 (ly:performance-write
315 (format #f "~a-~a.~a" basename count midi-ext)
316 (format #f "~a.~a" basename midi-ext))
317 (performance-name-from-header (ly:performance-header perf)))
318 (loop (cdr perfs) (1+ count)))))))