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