1 ;;;; midi.scm -- scm midi variables and functions
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2000--2007 Jan Nieuwenhuizen <janneke@gnu.org>
12 ;; this is broken: we should not ever export variables from Scheme.
14 ;; define factor of total volume per dynamic marking
15 (define-public absolute-volume-alist '())
16 (set! absolute-volume-alist
33 absolute-volume-alist))
35 (define-public (default-dynamic-absolute-volume s)
36 (let ((entry (assoc s absolute-volume-alist)))
40 ;; define factors of total volume of minimum and maximum volume
41 (define-public instrument-equalizer-alist '())
42 (set! instrument-equalizer-alist
47 ("clarinet" . (0 . 0.7))
48 ("bassoon" . (0 . 0.6))
49 ("french horn" . (0.1 . 0.7))
50 ("trumpet" . (0.1 . 0.8))
51 ("timpani" . (0.2 . 0.9))
52 ("violin" . (0.2 . 1.0))
53 ("viola" . (0.1 . 0.7))
54 ("cello" . (0.2 . 0.8))
55 ("contrabass" . (0.2 . 0.8))
57 instrument-equalizer-alist))
59 (define-public (default-instrument-equalizer s)
60 (let ((entry (assoc s instrument-equalizer-alist)))
64 ;; (name . program+32768*(channel10 ? 1 : 0))
65 (define instrument-names-alist '())
66 (set! instrument-names-alist
69 ("acoustic grand" . ,(- 1 1))
70 ("bright acoustic" . ,(- 2 1))
71 ("electric grand" . ,(- 3 1))
72 ("honky-tonk" . ,(- 4 1))
73 ("electric piano 1" . ,(- 5 1))
74 ("electric piano 2" . ,(- 6 1))
75 ("harpsichord" . ,(- 7 1))
78 ; (9-16 chrom percussion)
79 ("celesta" . ,(- 9 1))
80 ("glockenspiel" . ,(- 10 1))
81 ("music box" . ,(- 11 1))
82 ("vibraphone" . ,(- 12 1))
83 ("marimba" . ,(- 13 1))
84 ("xylophone" . ,(- 14 1))
85 ("tubular bells" . ,(- 15 1))
86 ("dulcimer" . ,(- 16 1))
89 ("drawbar organ" . ,(- 17 1))
90 ("percussive organ" . ,(- 18 1))
91 ("rock organ" . ,(- 19 1))
92 ("church organ" . ,(- 20 1))
93 ("reed organ" . ,(- 21 1))
94 ("accordion" . ,(- 22 1))
95 ("harmonica" . ,(- 23 1))
96 ("concertina" . ,(- 24 1))
99 ("acoustic guitar (nylon)" . ,(- 25 1))
100 ("acoustic guitar (steel)" . ,(- 26 1))
101 ("electric guitar (jazz)" . ,(- 27 1))
102 ("electric guitar (clean)" . ,(- 28 1))
103 ("electric guitar (muted)" . ,(- 29 1))
104 ("overdriven guitar" . ,(- 30 1))
105 ("distorted guitar" . ,(- 31 1))
106 ("guitar harmo(dinics" . ,(- 32 1))
109 ("acoustic bass" . ,(- 33 1))
110 ("electric bass (finger)" . ,(- 34 1))
111 ("electric bass (pick)" . ,(- 35 1))
112 ("fretless bass" . ,(- 36 1))
113 ("slap bass 1" . ,(- 37 1))
114 ("slap bass 2" . ,(- 38 1))
115 ("synth bass 1" . ,(- 39 1))
116 ("synth bass 2" . ,(- 40 1))
119 ("violin" . ,(- 41 1))
120 ("viola" . ,(- 42 1))
121 ("cello" . ,(- 43 1))
122 ("contrabass" . ,(- 44 1))
123 ("tremolo strings" . ,(- 45 1))
124 ("pizzicato strings" . ,(- 46 1))
125 ("orchestral strings" . ,(- 47 1))
126 ("timpani" . ,(- 48 1))
129 ("string ensemble 1" . ,(- 49 1))
130 ("string ensemble 2" . ,(- 50 1))
131 ("synthstrings 1" . ,(- 51 1))
132 ("synthstrings 2" . ,(- 52 1))
133 ("choir aahs" . ,(- 53 1))
134 ("voice oohs" . ,(- 54 1))
135 ("synth voice" . ,(- 55 1))
136 ("orchestra hit" . ,(- 56 1))
139 ("trumpet" . ,(- 57 1))
140 ("trombone" . ,(- 58 1))
142 ("muted trumpet" . ,(- 60 1))
143 ("french horn" . ,(- 61 1))
144 ("brass section" . ,(- 62 1))
145 ("synthbrass 1" . ,(- 63 1))
146 ("synthbrass 2" . ,(- 64 1))
149 ("soprano sax" . ,(- 65 1))
150 ("alto sax" . ,(- 66 1))
151 ("tenor sax" . ,(- 67 1))
152 ("baritone sax" . ,(- 68 1))
154 ("english horn" . ,(- 70 1))
155 ("bassoon" . ,(- 71 1))
156 ("clarinet" . ,(- 72 1))
159 ("piccolo" . ,(- 73 1))
160 ("flute" . ,(- 74 1))
161 ("recorder" . ,(- 75 1))
162 ("pan flute" . ,(- 76 1))
163 ("blown bottle" . ,(- 77 1))
164 ("shakuhachi" . ,(- 78 1))
165 ("whistle" . ,(- 79 1))
166 ("ocarina" . ,(- 80 1))
169 ("lead 1 (square)" . ,(- 81 1))
170 ("lead 2 (sawtooth)" . ,(- 82 1))
171 ("lead 3 (calliope)" . ,(- 83 1))
172 ("lead 4 (chiff)" . ,(- 84 1))
173 ("lead 5 (charang)" . ,(- 85 1))
174 ("lead 6 (voice)" . ,(- 86 1))
175 ("lead 7 (fifths)" . ,(- 87 1))
176 ("lead 8 (bass+lead)" . ,(- 88 1))
179 ("pad 1 (new age)" . ,(- 89 1))
180 ("pad 2 (warm)" . ,(- 90 1))
181 ("pad 3 (polysynth)" . ,(- 91 1))
182 ("pad 4 (choir)" . ,(- 92 1))
183 ("pad 5 (bowed)" . ,(- 93 1))
184 ("pad 6 (metallic)" . ,(- 94 1))
185 ("pad 7 (halo)" . ,(- 95 1))
186 ("pad 8 (sweep)" . ,(- 96 1))
188 ; (97-104 synth effects)
189 ("fx 1 (rain)" . ,(- 97 1))
190 ("fx 2 (soundtrack)" . ,(- 98 1))
191 ("fx 3 (crystal)" . ,(- 99 1))
192 ("fx 4 (atmosphere)" . ,(- 100 1))
193 ("fx 5 (brightness)" . ,(- 101 1))
194 ("fx 6 (goblins)" . ,(- 102 1))
195 ("fx 7 (echoes)" . ,(- 103 1))
196 ("fx 8 (sci-fi)" . ,(- 104 1))
199 ("sitar" . ,(- 105 1))
200 ("banjo" . ,(- 106 1))
201 ("shamisen" . ,(- 107 1))
202 ("koto" . ,(- 108 1))
203 ("kalimba" . ,(- 109 1))
204 ("bagpipe" . ,(- 110 1))
205 ("fiddle" . ,(- 111 1))
206 ("shanai" . ,(- 112 1))
208 ; (113-120 percussive)
209 ("tinkle bell" . ,(- 113 1))
210 ("agogo" . ,(- 114 1))
211 ("steel drums" . ,(- 115 1))
212 ("woodblock" . ,(- 116 1))
213 ("taiko drum" . ,(- 117 1))
214 ("melodic tom" . ,(- 118 1))
215 ("synth drum" . ,(- 119 1))
216 ("reverse cymbal" . ,(- 120 1))
218 ; (121-128 sound effects)
219 ("guitar fret noise" . ,(- 121 1))
220 ("breath noise" . ,(- 122 1))
221 ("seashore" . ,(- 123 1))
222 ("bird tweet" . ,(- 124 1))
223 ("telephone ring" . ,(- 125 1))
224 ("helicopter" . ,(- 126 1))
225 ("applause" . ,(- 127 1))
226 ("gunshot" . ,(- 128 1))
228 ; (channel 10 drum-kits - subtract 32768 to get program no.)
229 ("standard kit" . ,(+ 32768 0))
230 ("standard drums" . ,(+ 32768 0))
231 ("drums" . ,(+ 32768 0))
232 ("room kit" . ,(+ 32768 8))
233 ("room drums" . ,(+ 32768 8))
234 ("power kit" . ,(+ 32768 16))
235 ("power drums" . ,(+ 32768 16))
236 ("rock drums" . ,(+ 32768 16))
237 ("electronic kit" . ,(+ 32768 24))
238 ("electronic drums" . ,(+ 32768 24))
239 ("tr-808 kit" . ,(+ 32768 25))
240 ("tr-808 drums" . ,(+ 32768 25))
241 ("jazz kit" . ,(+ 32768 32))
242 ("jazz drums" . ,(+ 32768 32))
243 ("brush kit" . ,(+ 32768 40))
244 ("brush drums" . ,(+ 32768 40))
245 ("orchestra kit" . ,(+ 32768 48))
246 ("orchestra drums" . ,(+ 32768 48))
247 ("classical drums" . ,(+ 32768 48))
248 ("sfx kit" . ,(+ 32768 56))
249 ("sfx drums" . ,(+ 32768 56))
250 ("mt-32 kit" . ,(+ 32768 127))
251 ("mt-32 drums" . ,(+ 32768 127))
252 ("cm-64 kit" . ,(+ 32768 127))
253 ("cm-64 drums" . ,(+ 32768 127))
255 instrument-names-alist))
257 (define-public (percussion? instrument)
259 returns whether the instrument should use midi channel 9
261 (let* ((inst (symbol->string instrument))
262 (entry (assoc inst instrument-names-alist)))
263 (and entry (>= (cdr entry) 32768))))
265 (define-public (midi-program instrument)
267 returns the program of the instrument
269 (let* ((inst (symbol->string instrument))
270 (entry (assoc inst instrument-names-alist)))
271 (if entry (modulo (cdr entry) 32768) #f)))
273 ;; 90 == 90/127 == 0.71 is supposed to be the default value
274 ;; urg: we should set this at start of track
275 (define-public dynamic-default-volume 0.71)
277 (define-public (alterations-in-key pitch-list)
278 "Count number of sharps minus number of flats"
280 (* (apply + (map cdr pitch-list)) 2))
284 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
287 (define-public (write-performances-midis performances basename)
290 ((perfs performances)
296 (ly:performance-write
299 (format #f "~a-~a.midi" basename count)
300 (format #f "~a.midi" basename)))
301 (loop (cdr perfs) (1+ count))))))