]> git.donarmstrong.com Git - lilypond.git/blob - mf/feta-bolletjes.mf
release: 1.5.41
[lilypond.git] / mf / feta-bolletjes.mf
1 %  -*-Fundamental-*-
2 % feta-bolletjes.mf --  implement noteheads
3
4 % source file of LilyPond's pretty-but-neat music font
5
6 % (c) 1997--2002 Jan Nieuwenhuizen <janneke@gnu.org>
7 % & Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 % & Juergen Reuter <reuter@ipd.uka.de>
9
10
11
12 % most beautiful noteheads are pronounced, not circular, 
13 % and not even symmetric.
14 % These examples are inspired by [Wanske], see literature list
15
16
17 save black_notehead_width;
18 numeric black_notehead_width;
19
20 fet_begingroup("noteheads");
21
22 noteheight#:=staff_space#+ (1 + overdone_heads) *stafflinethickness#;
23 define_pixels(noteheight);
24
25 %
26
27 %%% TODO: Document these!
28 %
29
30 % setup user vars
31 def setup_notehead_vars =
32         save a_b,err_y_a,tilt,superness;
33         save ai_a,ai_bi,err_y_ai,err_x_bi,inner_tilt,inner_superness;
34         save b_h,a_w;
35         enddef;
36
37 % setup addititional vars and calc them
38 def notehead_calc =
39         save a,beta,ai,bi, ht, wd;
40         ht# =noteheight#;
41         2beta#=ht#*b_h;
42         a# = beta#*a_b;
43         wd# = 2a# / a_w;
44         ai# = a# * ai_a;
45         bi# = ai#/ai_bi;
46         define_pixels(a,beta);
47         define_pixels(ai,bi);
48         set_char_box(0, wd#, .5 ht#, .5 ht#);
49         enddef;
50
51
52 % draw the outer and inner ellipse.
53 def notehead_draw =
54         path black,white;
55         black=distorted_ellipse(a,beta,a*err_y_a,0,superness);
56         white=distorted_ellipse(ai,bi,ai*err_y_ai,bi*err_x_bi,inner_superness);
57 if test>1: %fixme
58                 save x;
59                 x1=-x3=a; x2=x4=0; y1=y3=0; y2=-y4=b;
60                 penlabels(1,2,3,4);
61                 test_grid;
62 else:
63                 black:=black rotated tilt;
64                 black:=black shifted (w/2,0);
65                 white:=white rotated inner_tilt;
66                 white:=white shifted (w/2,0);
67 fi
68                 fill black;
69                 unfill white;
70
71                 
72         enddef;
73
74 def draw_whole_head =
75         setup_notehead_vars;
76         
77         a_b:=1.80;
78         err_y_a:=0; % no slant
79         tilt:=0;
80         superness:=0.707;
81         ai_a:=0.508;
82         % ai_bi:=1.23;
83         ai_bi:=1.30; % jcn
84         % err_y_ai:=0.0938;
85         % err_x_bi:=0;
86         err_y_ai:=0;
87         err_x_bi:=0.115;
88         % inner_tilt:=135;
89         inner_tilt:=125; % jcn
90         % inner_superness:=0.69;
91         inner_superness:=0.68; % jcn
92         b_h:=1; %no rotate-> no height correction
93         a_w:=1; % no rotate-> no width correction
94
95         notehead_calc;
96         whole_notehead_width# := wd#;
97         notehead_draw;
98 enddef;
99
100
101 %
102 % dimensions aren't entirely right.
103 %
104 fet_beginchar ("Brevis notehead", "-1", "brevishead");
105         save stemthick, fudge;
106         define_pixels (stemthick);
107         fudge = blot_diameter /2;
108         stemthick# = 2 stafflinethickness#;
109
110         draw_whole_head;
111
112         pickup pencircle scaled stemthick;
113
114         bot y1 = -d;
115         top y2 = h;
116         rt x1 - fudge = 0;
117         x1 = x2;
118
119         fudge + lft x3 = w;
120         x4 = x3;
121         y4 = y2;
122         y3 = y1;
123
124         draw_gridline(z1,z2,stemthick);
125         draw_gridline(z3,z4,stemthick);
126 fet_endchar;
127
128 % whole note
129 % Wanske, p.38
130 fet_beginchar("Whole notehead", "0", "wholehead")
131         draw_whole_head;
132 fet_endchar;
133
134
135
136 % half note
137 % Wanske, p.39
138 fet_beginchar("Half notehead", "1", 
139         "halfhead")
140         setup_notehead_vars;
141                 % a_b:=1.49; % after text
142         a_b:=1.50; % after drawing
143         err_y_a:=0.157;
144         tilt:=34;
145         % superness:=0.66;
146         superness:=0.67; % jcn
147         % ai_a:=0.863;
148         ai_a:=0.850; % jcn
149         % ai_bi:=3.14;
150         ai_bi:=3.30; % jcn
151         err_y_ai:=0;
152         err_x_bi:=-0.12;
153         inner_tilt:=tilt;
154         inner_superness:=0.80;
155         b_h:=0.935;
156         a_w:=1.12;
157
158         notehead_calc;
159         half_notehead_width# := wd#;
160         notehead_draw;
161 fet_endchar;
162
163
164
165 % quarter note
166 % Wanske p.38
167 fet_beginchar("Quart notehead", "2", "quarthead")
168         setup_notehead_vars;
169         % a_b:=1.57; % after text
170         a_b:=1.54; % after drawing
171         err_y_a:=0.044;
172         tilt:=32;
173         superness:=0.707;
174         ai_a:=0;
175         ai_bi:=1;
176         err_y_ai:=0;
177         err_x_bi:=0;
178         inner_tilt:=0;
179         inner_superness:=0.707;
180         b_h:=0.85;
181         a_w:=1.09;
182
183         notehead_calc;
184         black_notehead_width# := wd#;
185         notehead_draw;
186 fet_endchar;
187
188
189 % whole note
190 % Wanske, p.38
191 fet_beginchar("Whole diamondhead", "0diamond", "wholediamondhead")
192         setup_notehead_vars;
193         
194         a_b:=1.80;
195         err_y_a:=0; % no slant
196         tilt:=0;
197         superness:=0.495;
198         ai_a:=0.350;
199         % ai_bi:=1.23;
200         ai_bi:=1.30; % jcn
201         % err_y_ai:=0.0938;
202         % err_x_bi:=0;
203         err_y_ai:=0;
204         err_x_bi:=0.115;
205         % inner_tilt:=135;
206         inner_tilt:=125; % jcn
207         % inner_superness:=0.69;
208         inner_superness:=0.6; % jcn
209         b_h:=1; %no rotate-> no height correction
210         a_w:=1; % no rotate-> no width correction
211
212         notehead_calc;
213         whole_notehead_width# := wd#;
214         notehead_draw;
215 fet_endchar;
216
217
218 % half note
219 % Wanske, p.39
220 fet_beginchar("Half diamondhead", "1diamond", 
221         "halfdiamondhead")
222         setup_notehead_vars;
223
224         a_b := 1.50; % after drawing
225         err_y_a:=0.157;
226
227         tilt:=34;
228         superness:=0.49; % jcn
229         ai_a:=0.550; % jcn
230         ai_bi:=3.30; % jcn
231
232         err_y_ai:=0;
233         err_x_bi:=-0.12;
234         inner_tilt:=tilt;
235         inner_superness:=0.80;
236
237         b_h:= 1.03;
238         a_w:= 1.2;
239
240         notehead_calc;
241         half_notehead_width# := wd#;
242         notehead_draw;
243 fet_endchar;
244
245
246 % quarter note
247 % Wanske p.38
248 fet_beginchar("Quart diamondhead", "2diamond", "diamondhead")
249         set_char_box(0, black_notehead_width#, noteheight#/2, noteheight#/2);
250         save a_b,err_y_a,tilt,superness;
251         save b_h,a_w;
252         save a,beta,ai,bi, ht, wd;
253
254         a_b:= 1.8;
255         err_y_a:=-0.044;
256         b_h:=0.90;
257         a_w:=1.1;
258         tilt:=35;
259         superness:=0.495;
260
261         ht# =noteheight#;
262         2beta#=ht#*b_h;
263         a# = beta#*a_b;
264
265         define_pixels(a,beta);
266
267         black := distorted_ellipse(.72 noteheight, .45 noteheight, -.2 noteheight ,   0, superness)
268                                 
269 %                       beta,a*err_y_a,0,superness);
270
271         black:=black rotated tilt;
272         black:=black shifted (w/2,0);
273         fill black;
274 fet_endchar;
275
276
277
278 begingroup;
279 def def_triangle =
280         save triangle,kern; path triangle;
281         kern = 1/3(x2-x1);
282         z2 = z1 rotated 120;
283         z3 = z1 rotated 240;
284         z12 = caveness[.5[z1,z2],z3];
285         z23 = z12 rotated 120;
286         z31 = z12 rotated 240;
287         triangle = z1 .. z12 .. z2 ..
288                     z2 .. z23 .. z3 ..
289                     z3 .. z31 .. z1 ..
290                     cycle;
291         triangle := triangle shifted (-x1+pent/2-kern,0) xscaled xs;
292         pickup pencircle scaled pent xscaled xs;
293         hei = max(y1,-y2)+pent/2; 
294         %set_char_box(-kern*xs*fac, ((x3-x1)*fac+pent#)*xs,hei*fac,hei*fac);
295         set_char_box(0, ((x3-x1-kern)*fac+pent#)*xs,hei*fac,hei*fac);
296 enddef;
297 save fac,pent;
298 fac = noteheight#/noteheight;
299 pent# = 2stafflinethickness#;
300 define_pixels(pent);
301
302
303 fet_beginchar("Whole trianglehead", "0triangle", "wholetrianglehead")
304         save hei,xs;
305         z1 = dir(130)*3/4noteheight;
306         xs = 1.5;
307         caveness:=0.1;
308         def_triangle;
309         draw triangle;
310 fet_endchar;
311
312 fet_beginchar("Half trianglehead", "1triangle", "halftrianglehead")
313         save hei,xs;
314         z1 = dir(130)*2/3noteheight;
315         xs = 1.2;
316         caveness:=0.1;
317         def_triangle;
318         draw triangle;
319 fet_endchar;
320
321 fet_beginchar("Quart trianglehead", "2triangle", "trianglehead")
322         save hei,xs;
323         z1 = dir(130)*2/3noteheight;
324         xs = 1.0;
325         caveness:=0.1;
326         def_triangle;
327         filldraw triangle;
328 fet_endchar;
329
330 endgroup;
331
332 %%% Editable values:
333
334 slash_slope := 1.7; % slope of slash. From scm/grob-description.scm. How to auto-copy?
335 slt# := 2/3*0.48staff_space#; % thickness of lines. quarter notes get 1.5slt width.
336 slh# := 2staff_space#; % height of char.
337
338 %%% Calculated values:
339 sxa# := 0; % how much the char exceeds the boundingbox horizontally:
340
341  % Width of hor. pen - with thanks to Pythagoras
342 slxt# := sqrt(slt#*slt#+(slt#/slash_slope)*(slt#/slash_slope));
343 slw# := slh#/slash_slope; % width of sloping part of slash:
344
345 define_pixels(slt,slh,sxa,slxt,slw);
346
347
348 %
349 %
350 % UUGGGH! FIXME -- get rid of those sharp corners. 
351 %
352 %
353 %
354
355
356 def draw_slash(expr hwid_hash) =
357         wid# := slw#+2slxt#+hwid_hash;
358         set_char_box(0,wid#-2sxa#,slh#/2,slh#/2);
359         define_pixels (wid#);
360         pickup penrazor scaled slxt;
361         draw (-b+slxt/2-sxa,-d) -- (-b+slxt/2+slw-sxa,h);
362         draw (w-slxt/2-slw+sxa,-d) -- (w-slxt/2+sxa,h);
363         pickup penrazor scaled slt rotated 90;
364         draw (-b+slxt-sxa,-d+slt/2) -- (w-slw+sxa,-d+slt/2);
365         draw (-b+slw-sxa,h-slt/2) -- (w-slxt+sxa,h-slt/2);
366 enddef;
367
368 fet_beginchar("Whole slashhead","0slash","wholeslashhead")
369         draw_slash(staff_space#);
370 fet_endchar;
371
372 fet_beginchar("Half slashhead","1slash","halfslashhead")
373         draw_slash(0.6staff_space#);
374 fet_endchar;
375
376 fet_beginchar("Quart slashhead","2slash","quartslashhead")
377         draw_slash(-slxt#/2);
378 fet_endchar;
379
380 % thick is the distance between the two parallel lines in the cross (distance between centres of lines)
381 def draw_cross(expr thick) =
382         pent := 1.2stafflinethickness;
383         pickup pencircle scaled pent;
384         % alfa is the slant of the lines (i.e. 1 means 45 degrees)
385         alfa := (2h-pent)/(w-pent);
386         % llen is the length of the little outer lines
387         % llen = thick / sin(2atan(alfa))
388         llen := thick/(ypart(dir(2angle(1,alfa))));
389         xa := llen/sqrt(1+alfa**2);
390         ya := xa*alfa;
391         xl := w/2-xa-pent/2;
392         yl := h-ya-pent/2;
393         save crz; path crz;
394         crz = (xa,0) -- (xa+xl,yl) -- (xl,yl+ya) -- (0,ya);
395         draw crz shifted(w/2,0);
396         draw crz xscaled -1 shifted(w/2,0);
397         draw crz yscaled -1 shifted(w/2,0);
398         draw crz scaled -1 shifted(w/2,0);
399 enddef;
400
401 fet_beginchar("Whole Crossed notehead", "0cross", "wholecrossedhead")
402         wid# := black_notehead_width#+4stafflinethickness#;
403         hei# := noteheight#+stafflinethickness#;
404         set_char_box(0, wid#,hei#/2,hei#/2);
405         draw_cross(3.75stafflinethickness);
406 fet_endchar;
407
408 fet_beginchar("Half Crossed notehead", "1cross", "halfcrossedhead")
409         wid# := black_notehead_width#+2stafflinethickness#;
410         hei# := noteheight#+stafflinethickness#/2;
411         set_char_box(0, wid#,hei#/2,hei#/2);
412         draw_cross(3stafflinethickness);
413 fet_endchar;
414
415 fet_beginchar("Crossed notehead", "2cross", "crossedhead")
416         wid# := black_notehead_width#;
417         hei# := noteheight#;
418         set_char_box(0, wid#,hei#/2,hei#/2);
419         draw_cross(stafflinethickness/4);
420 fet_endchar;
421
422 fet_beginchar("X-Circled notehead", "2xcircle", "xcircledhead")
423         wid# := black_notehead_width#*sqrt(sqrt2);
424         hei# := noteheight#*sqrt(sqrt2);
425         set_char_box(0, wid#,hei#/2,hei#/2);
426         cthick := (1.2+1/4)*stafflinethickness;
427         cxr := w/2-cthick/2;
428         cyr := h-cthick/2;
429         pickup pencircle scaled cthick;
430         draw fullcircle xscaled 2cxr yscaled 2cyr shifted (w/2,0);
431         xpos := cxr/sqrt2;
432         ypos := cyr/sqrt2;
433         draw (-xpos+w/2,-ypos) -- (xpos+w/2,ypos);
434         draw (-xpos+w/2,ypos) -- (xpos+w/2,-ypos);
435 fet_endchar;
436
437
438 %%%%%%%%%%%%
439 %
440 %
441 % ledger (leger) lines
442 %
443 fet_beginchar("Ledger ending", "ledgerending", "ledgerending")
444 set_char_box (5/2 ledgerlinethickness#, 5/2 ledgerlinethickness#,
445                 ledgerlinethickness#/2,ledgerlinethickness#/2);
446
447
448         draw_rounded_block((-b,-d),(w,h), 0.8 ledgerlinethickness);
449 fet_endchar;
450
451
452 fet_endgroup("noteheads");
453 define_pixels(black_notehead_width);