]> git.donarmstrong.com Git - lilypond.git/blob - mf/feta-bolletjes.mf
(Multi measure rests): more
[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--2003 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 save pent;
278 pen_thick# = 2stafflinethickness#;
279 define_pixels(pen_thick);
280
281
282 begingroup;
283
284
285 def def_triangle_old =
286         save triangle,kern; path triangle;
287         kern = 1/3(x2-x1);
288         z2 = z1 rotated 120;
289         z3 = z1 rotated 240;
290         z12 = caveness[.5[z1,z2],z3];
291         z23 = z12 rotated 120;
292         z31 = z12 rotated 240;
293         triangle = z1 .. z12 .. z2 ..
294                     z2 .. z23 .. z3 ..
295                     z3 .. z31 .. z1 ..
296                     cycle;
297         triangle := triangle shifted (-x1+pent/2-kern,0) xscaled xs;
298         pickup pencircle scaled pent xscaled xs;
299         hei = max(y1,-y2)+pent/2; 
300         %set_char_box(-kern*xs*fac, ((x3-x1)*fac+pent#)*xs,hei*fac,hei*fac);
301         set_char_box(0, ((x3-x1-kern)*fac+pent#)*xs,hei*fac,hei*fac);
302 enddef;
303
304
305 def def_triangle =
306         save triangle,kern; path triangle;
307         save left_point, height, width;
308         pair exact_left_point;
309
310         exact_left_point := llap# * dir (90 + tilt);
311         height# = max (ypart exact_left_point,
312                         -ypart  (exact_left_point rotated 120)) + pen_thick#/2;
313
314         kern# = 1/3 xpart (exact_left_point - (exact_left_point rotated 120));
315         width# = xpart (-exact_left_point + (exact_left_point rotated 240));
316         define_pixels (kern);   
317         z1 = (hround_pixels (xpart exact_left_point), vround_pixels  (ypart exact_left_point));
318         z2 = z1 rotated 120;
319         z3 = z1 rotated 240;
320
321         z12 = caveness[.5[z1,z2],z3];
322         z23 = z12 rotated 120;
323         z31 = z12 rotated 240;
324         triangle = z1 .. z12 .. z2 ..
325                     z2 .. z23 .. z3 ..
326                     z3 .. z31 .. z1 ..
327                     cycle;
328         triangle := triangle shifted (-x1+pen_thick/2-kern,0) xscaled xs;
329         pickup pencircle scaled pen_thick xscaled xs;
330 %       labels(1,2,12,23,31,3);
331         set_char_box(0, width# - kern#+ pen_thick#, height#, height#);
332 enddef;
333
334 fet_beginchar("Whole trianglehead", "0triangle", "wholetrianglehead")
335         save hei,xs;
336         save llap;
337         save tilt;
338
339         tilt = 40;
340         llap# = 3/4noteheight#;
341
342         xs = 1.5;
343         caveness:=0.1;
344         def_triangle;
345         draw triangle;
346 fet_endchar;
347
348 fet_beginchar("Half trianglehead", "1triangle", "halftrianglehead")
349         save hei,xs;
350         save llap;
351         save tilt;
352
353         tilt = 40;
354         llap# = 2/3noteheight#;
355         xs = 1.2;
356         caveness:=0.1;
357         def_triangle;
358         draw triangle;
359 fet_endchar;
360
361 fet_beginchar("Quart trianglehead", "2triangle", "trianglehead")
362         save hei,xs;
363         save llap;
364         save tilt;
365         tilt = 40;
366         llap# = 2/3noteheight#;
367         xs = 1.0;
368         caveness:=0.1;
369         def_triangle;
370         filldraw triangle;
371 fet_endchar;
372
373 endgroup;
374
375 %%% Editable values:
376
377 slash_slope := 1.7; % slope of slash. From scm/grob-description.scm. How to auto-copy?
378 slt# := 2/3*0.48staff_space#; % thickness of lines. quarter notes get 1.5slt width.
379 slh# := 2staff_space#; % height of char.
380
381 %%% Calculated values:
382 sxa# := 0; % how much the char exceeds the boundingbox horizontally:
383
384  % Width of hor. pen - with thanks to Pythagoras
385 slxt# := sqrt(slt#*slt#+(slt#/slash_slope)*(slt#/slash_slope));
386 slw# := slh#/slash_slope; % width of sloping part of slash:
387
388 define_pixels(slt,slh,sxa,slxt,slw);
389
390
391 %
392 %
393 % UUGGGH! FIXME -- get rid of those sharp corners. 
394 %
395 %
396 %
397
398
399 def draw_slash(expr hwid_hash) =
400         wid# := slw#+2slxt#+hwid_hash;
401         set_char_box(0,wid#-2sxa#,slh#/2,slh#/2);
402         define_pixels (wid#);
403         pickup penrazor scaled slxt;
404         draw (-b+slxt/2-sxa,-d) -- (-b+slxt/2+slw-sxa,h);
405         draw (w-slxt/2-slw+sxa,-d) -- (w-slxt/2+sxa,h);
406         pickup penrazor scaled slt rotated 90;
407         draw (-b+slxt-sxa,-d+slt/2) -- (w-slw+sxa,-d+slt/2);
408         draw (-b+slw-sxa,h-slt/2) -- (w-slxt+sxa,h-slt/2);
409 enddef;
410
411 fet_beginchar("Whole slashhead","0slash","wholeslashhead")
412         draw_slash(staff_space#);
413 fet_endchar;
414
415 fet_beginchar("Half slashhead","1slash","halfslashhead")
416         draw_slash(0.6staff_space#);
417 fet_endchar;
418
419 fet_beginchar("Quart slashhead","2slash","quartslashhead")
420         draw_slash(-slxt#/2);
421 fet_endchar;
422
423 % thick is the distance between the two parallel lines in the cross (distance between centres of lines)
424 def draw_cross(expr thick) =
425         pent := 1.2stafflinethickness;
426         pickup pencircle scaled pent;
427         % alfa is the slant of the lines (i.e. 1 means 45 degrees)
428         alfa := (2h-pent)/(w-pent);
429         % llen is the length of the little outer lines
430         % llen = thick / sin(2atan(alfa))
431         llen := thick/(ypart(dir(2angle(1,alfa))));
432         xa := llen/sqrt(1+alfa**2);
433         ya := xa*alfa;
434         xl := w/2-xa-pent/2;
435         yl := h-ya-pent/2;
436         save crz; path crz;
437         crz = (xa,0) -- (xa+xl,yl) -- (xl,yl+ya) -- (0,ya);
438         draw crz shifted(w/2,0);
439         draw crz xscaled -1 shifted(w/2,0);
440         draw crz yscaled -1 shifted(w/2,0);
441         draw crz scaled -1 shifted(w/2,0);
442 enddef;
443
444 fet_beginchar("Whole Crossed notehead", "0cross", "wholecrossedhead")
445         wid# := black_notehead_width#+4stafflinethickness#;
446         hei# := noteheight#+stafflinethickness#;
447         set_char_box(0, wid#,hei#/2,hei#/2);
448         draw_cross(3.75stafflinethickness);
449 fet_endchar;
450
451 fet_beginchar("Half Crossed notehead", "1cross", "halfcrossedhead")
452         wid# := black_notehead_width#+2stafflinethickness#;
453         hei# := noteheight#+stafflinethickness#/2;
454         set_char_box(0, wid#,hei#/2,hei#/2);
455         draw_cross(3stafflinethickness);
456 fet_endchar;
457
458 fet_beginchar("Crossed notehead", "2cross", "crossedhead")
459         wid# := black_notehead_width#;
460         hei# := noteheight#;
461         set_char_box(0, wid#,hei#/2,hei#/2);
462         draw_cross(stafflinethickness/4);
463 fet_endchar;
464
465 fet_beginchar("X-Circled notehead", "2xcircle", "xcircledhead")
466         wid# := black_notehead_width#*sqrt(sqrt2);
467         hei# := noteheight#*sqrt(sqrt2);
468         set_char_box(0, wid#,hei#/2,hei#/2);
469         cthick := (1.2+1/4)*stafflinethickness;
470         cxr := w/2-cthick/2;
471         cyr := h-cthick/2;
472         pickup pencircle scaled cthick;
473         draw fullcircle xscaled 2cxr yscaled 2cyr shifted (w/2,0);
474         xpos := cxr/sqrt2;
475         ypos := cyr/sqrt2;
476         draw (-xpos+w/2,-ypos) -- (xpos+w/2,ypos);
477         draw (-xpos+w/2,ypos) -- (xpos+w/2,-ypos);
478 fet_endchar;
479
480
481 %%%%%%%%%%%%
482 %
483 %
484 % ledger (leger) lines
485 %
486 fet_beginchar("Ledger ending", "ledgerending", "ledgerending")
487 set_char_box (5/2 ledgerlinethickness#, 5/2 ledgerlinethickness#,
488                 ledgerlinethickness#/2,ledgerlinethickness#/2);
489
490
491         draw_rounded_block((-b,-d),(w,h), 0.8 ledgerlinethickness);
492 fet_endchar;
493
494
495 fet_endgroup("noteheads");
496 define_pixels(black_notehead_width);