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