]> git.donarmstrong.com Git - lilypond.git/blob - scm/midi.scm
ly- -> ly:
[lilypond.git] / scm / midi.scm
1 ;;; midi.scm -- scm midi variables and functions
2 ;;;
3 ;;;  source file of the GNU LilyPond music typesetter
4 ;;; 
5 ;;; (c) 2000--2002 Jan Nieuwenhuizen <janneke@gnu.org>
6
7
8 ;; define factor of total volume per dynamic marking
9 (define absolute-volume-alist '())
10 (set! absolute-volume-alist
11       (append 
12       '(
13         ("sf" . 1.00)
14         ("fffff" . 0.95)
15         ("ffff" . 0.91)
16         ("fff" . 0.81)
17         ("ff" . 0.71)
18         ("f" . 0.61)
19         ("mf" . 0.50)
20         ("mp" . 0.40)
21         ("p" . 0.30)
22         ("pp" . 0.20)
23         ("ppp" . 0.10)
24         ("pppp" . 0.08)
25         ("ppppp" . 0.05)
26         )
27       absolute-volume-alist))
28
29 (define-public (default-dynamic-absolute-volume s)
30   (let ((entry (assoc s absolute-volume-alist)))
31     (if entry
32         (cdr entry))))
33
34 ;; define factors of total volume of minimum and maximum volume
35 (define instrument-equalizer-alist '())
36 (set! instrument-equalizer-alist
37       (append 
38        '(
39          ("flute" . (0 . 0.7))
40          ("oboe" . (0 . 0.7))
41          ("clarinet" . (0 . 0.7))
42          ("bassoon" . (0 . 0.6))
43          ("french horn" . (0.1 . 0.7))
44          ("trumpet" . (0.1 . 0.8))
45          ("timpani" . (0.2 . 0.9))
46          ("violin" . (0.2 . 1.0))
47          ("viola" . (0.1 . 0.7))
48          ("cello" . (0.2 . 0.8))
49          ("contrabass" . (0.2 . 0.8))
50          )
51        instrument-equalizer-alist))
52
53 ;; (name . program+32768*(channel10 ? 1 : 0) )
54 (define instrument-names-alist '())
55 (set! instrument-names-alist
56       (append
57        `(
58           ("acoustic grand" . ,(- 1 1))
59           ("bright acoustic" . ,(- 2 1))
60           ("electric grand" . ,(- 3 1))
61           ("honky-tonk" . ,(- 4 1))
62           ("electric piano 1" . ,(- 5 1))
63           ("electric piano 2" . ,(- 6 1))
64           ("harpsichord" . ,(- 7 1))
65           ("clav" . ,(- 8 1))
66
67           ; (9-16 chrom percussion)
68           ("celesta" . ,(- 9 1))
69           ("glockenspiel" . ,(- 10 1))
70           ("music box" . ,(- 11 1))
71           ("vibraphone" . ,(- 12 1))
72           ("marimba" . ,(- 13 1))
73           ("xylophone" . ,(- 14 1))
74           ("tubular bells" . ,(- 15 1))
75           ("dulcimer" . ,(- 16 1))
76
77           ; (17-24 organ)
78           ("drawbar organ" . ,(- 17 1))
79           ("percussive organ" . ,(- 18 1))
80           ("rock organ" . ,(- 19 1))
81           ("church organ" . ,(- 20 1))
82           ("reed organ" . ,(- 21 1))
83           ("accordion" . ,(- 22 1))
84           ("harmonica" . ,(- 23 1))
85           ("concertina" . ,(- 24 1))
86
87           ; (25-32 guitar)
88           ("acoustic guitar (nylon)" . ,(- 25 1))
89           ("acoustic guitar (steel)" . ,(- 26 1))
90           ("electric guitar (jazz)" . ,(- 27 1))
91           ("electric guitar (clean)" . ,(- 28 1))
92           ("electric guitar (muted)" . ,(- 29 1))
93           ("overdriven guitar" . ,(- 30 1))
94           ("distorted guitar" . ,(- 31 1))
95           ("guitar harmo(dinics" . ,(- 32 1))
96
97           ; (33-40 bass)
98           ("acoustic bass" . ,(- 33 1))
99           ("electric bass (finger)" . ,(- 34 1))
100           ("electric bass (pick)" . ,(- 35 1))
101           ("fretless bass" . ,(- 36 1))
102           ("slap bass 1" . ,(- 37 1))
103           ("slap bass 2" . ,(- 38 1))
104           ("synth bass 1" . ,(- 39 1))
105           ("synth bass 2" . ,(- 40 1))
106
107           ; (41-48 strings)
108           ("violin" . ,(- 41 1))
109           ("viola" . ,(- 42 1))
110           ("cello" . ,(- 43 1))
111           ("contrabass" . ,(- 44 1))
112           ("tremolo strings" . ,(- 45 1))
113           ("pizzicato strings" . ,(- 46 1))
114           ("orchestral strings" . ,(- 47 1))
115           ("timpani" . ,(- 48 1))
116
117           ; (49-56 ensemble)
118           ("string ensemble 1" . ,(- 49 1))
119           ("string ensemble 2" . ,(- 50 1))
120           ("synthstrings 1" . ,(- 51 1))
121           ("synthstrings 2" . ,(- 52 1))
122           ("choir aahs" . ,(- 53 1))
123           ("voice oohs" . ,(- 54 1))
124           ("synth voice" . ,(- 55 1))
125           ("orchestra hit" . ,(- 56 1))
126
127           ; (57-64 brass)
128           ("trumpet" . ,(- 57 1))
129           ("trombone" . ,(- 58 1))
130           ("tuba" . ,(- 59 1))
131           ("muted trumpet" . ,(- 60 1))
132           ("french horn" . ,(- 61 1))
133           ("brass section" . ,(- 62 1))
134           ("synthbrass 1" . ,(- 63 1))
135           ("synthbrass 2" . ,(- 64 1))
136
137           ; (65-72 reed)
138           ("soprano sax" . ,(- 65 1))
139           ("alto sax" . ,(- 66 1))
140           ("tenor sax" . ,(- 67 1))
141           ("baritone sax" . ,(- 68 1))
142           ("oboe" . ,(- 69 1))
143           ("english horn" . ,(- 70 1))
144           ("bassoon" . ,(- 71 1))
145           ("clarinet" . ,(- 72 1))
146
147           ; (73-80 pipe)
148           ("piccolo" . ,(- 73 1))
149           ("flute" . ,(- 74 1))
150           ("recorder" . ,(- 75 1))
151           ("pan flute" . ,(- 76 1))
152           ("blown bottle" . ,(- 77 1))
153           ("skakuhachi" . ,(- 78 1))
154           ("whistle" . ,(- 79 1))
155           ("ocarina" . ,(- 80 1))
156
157           ; (81-88 synth lead)
158           ("lead 1 (square)" . ,(- 81 1))
159           ("lead 2 (sawtooth)" . ,(- 82 1))
160           ("lead 3 (calliope)" . ,(- 83 1))
161           ("lead 4 (chiff)" . ,(- 84 1))
162           ("lead 5 (charang)" . ,(- 85 1))
163           ("lead 6 (voice)" . ,(- 86 1))
164           ("lead 7 (fifths)" . ,(- 87 1))
165           ("lead 8 (bass+lead)" . ,(- 88 1))
166
167           ; (89-96 synth pad)
168           ("pad 1 (new age)" . ,(- 89 1))
169           ("pad 2 (warm)" . ,(- 90 1))
170           ("pad 3 (polysynth)" . ,(- 91 1))
171           ("pad 4 (choir)" . ,(- 92 1))
172           ("pad 5 (bowed)" . ,(- 93 1))
173           ("pad 6 (metallic)" . ,(- 94 1))
174           ("pad 7 (halo)" . ,(- 95 1))
175           ("pad 8 (sweep)" . ,(- 96 1))
176
177           ; (97-104 synth effects)
178           ("fx 1 (rain)" . ,(- 97 1))
179           ("fx 2 (soundtrack)" . ,(- 98 1))
180           ("fx 3 (crystal)" . ,(- 99 1))
181           ("fx 4 (atmosphere)" . ,(- 100 1))
182           ("fx 5 (brightness)" . ,(- 101 1))
183           ("fx 6 (goblins)" . ,(- 102 1))
184           ("fx 7 (echoes)" . ,(- 103 1))
185           ("fx 8 (sci-fi)" . ,(- 104 1))
186
187           ; (105-112 ethnic)
188           ("sitar" . ,(- 105 1))
189           ("banjo" . ,(- 106 1))
190           ("shamisen" . ,(- 107 1))
191           ("koto" . ,(- 108 1))
192           ("kalimba" . ,(- 109 1))
193           ("bagpipe" . ,(- 110 1))
194           ("fiddle" . ,(- 111 1))
195           ("shanai" . ,(- 112 1))
196
197           ; (113-120 percussive)
198           ("tinkle bell" . ,(- 113 1))
199           ("agogo" . ,(- 114 1))
200           ("steel drums" . ,(- 115 1))
201           ("woodblock" . ,(- 116 1))
202           ("taiko drum" . ,(- 117 1))
203           ("melodic tom" . ,(- 118 1))
204           ("synth drum" . ,(- 119 1))
205           ("reverse cymbal" . ,(- 120 1))
206
207           ; (121-128 sound effects)
208           ("guitar fret noise" . ,(- 121 1))
209           ("breath noise" . ,(- 122 1))
210           ("seashore" . ,(- 123 1))
211           ("bird tweet" . ,(- 124 1))
212           ("telephone ring" . ,(- 125 1))
213           ("helicopter" . ,(- 126 1))
214           ("applause" . ,(- 127 1))
215           ("gunshot" . ,(- 128 1))
216
217           ; (channel 10 drum-kits - subtract 32768 to get program no.)
218           ("standard kit" .     ,(+ 32768 0))
219           ("standard drums" .   ,(+ 32768 0))
220           ("drums" .            ,(+ 32768 0))
221           ("room kit" .         ,(+ 32768 8))
222           ("room drums" .       ,(+ 32768 8))
223           ("power kit" .        ,(+ 32768 16))
224           ("power drums" .      ,(+ 32768 16))
225           ("rock drums" .       ,(+ 32768 16))
226           ("electronic kit" .   ,(+ 32768 24))
227           ("electronic drums" . ,(+ 32768 24))
228           ("tr-808 kit" .       ,(+ 32768 25))
229           ("tr-808 drums" .     ,(+ 32768 25))
230           ("jazz kit" .         ,(+ 32768 32))
231           ("jazz drums" .       ,(+ 32768 32))
232           ("brush kit" .        ,(+ 32768 40))
233           ("brush drums" .      ,(+ 32768 40))
234           ("orchestra kit" .    ,(+ 32768 48))
235           ("orchestra drums" .  ,(+ 32768 48))
236           ("classical drums" .  ,(+ 32768 48))
237           ("sfx kit" .          ,(+ 32768 56))
238           ("sfx drums" .        ,(+ 32768 56))
239           ("mt-32 kit" .        ,(+ 32768 127))
240           ("mt-32 drums" .      ,(+ 32768 127))
241           ("cm-64 kit" .        ,(+ 32768 127))
242           ("cm-64 drums" .      ,(+ 32768 127))
243         )
244         instrument-names-alist
245       )
246 )
247
248
249 (define-public (default-instrument-equalizer s)
250   (let ((entry (assoc s instrument-equalizer-alist)))
251     (if entry
252         (cdr entry))))
253
254
255 (define-public (percussion? instrument)
256   "
257 returns whether the instrument should use midi channel 9
258 "
259   (let* ((inst  (symbol->string instrument))
260          (entry (assoc inst instrument-names-alist))
261         )
262      (and entry (>= (cdr entry) 32768))
263   )
264 )
265 (define-public (midi-program instrument)
266 "
267 returns the program of the instrument
268 "
269   (let* ((inst  (symbol->string instrument))
270          (entry (assoc inst instrument-names-alist))
271         )
272     (if entry (modulo (cdr entry) 32768) #f )
273   )
274 )
275
276 ;; 90 == 90/127 == 0.71 is supposed to be the default value
277 ;; urg: we should set this at start of track
278 (define-public dynamic-default-volume 0.71)
279
280 (define-public (accidentals-in-key pitch-list)
281   "Count number of sharps minus number of flats"
282   (apply + (map cdr pitch-list)))
283
284 (define-public (major-key pitch-list)
285   "Characterise the key as major if the alteration of the 
286 third scale note is the same as that of the main note.
287 Note: MIDI cannot handle other tonalities than major/minor.
288 "
289   ;; This charactersition is only true for a scale that starts at `c'.
290   (if (not (equal? (car pitch-list) '(0 . 0)))
291       (begin
292         (ly:warn "Attempt to determine tonality of transposed scale")
293         #t)
294   (eq? (cdr (list-ref pitch-list 4)) (cdr (list-ref pitch-list 6)))))