summaryrefslogtreecommitdiff
path: root/muse2/share/scoreglyphs/feta-original/parmesan-clefs.mf
blob: afd5058e7da507709cc8a77d3e5a9eddb2ead8c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
% -%-Fundamental-%- -*-Metafont-*-
% parmesan-clefs.mf -- implement ancient clefs
% 
% source file of LilyPond's pretty-but-neat music font
%
% (c) 2001--2009 Juergen Reuter <reuter@ipd.uka.de>
%

fet_begingroup ("clefs");

%
% character aligment:
%
%   Each clef is associated with a particular pitch: the treble clef
%   with the `g', the alto clef with the `c', the bass clef with the
%   `f', etc.  The shape of each clef character defines a vertical
%   position that is assumed to represent this pitch.  For the treble
%   clef, it is the vertical position of the center of the spiral
%   ending that represents the `g' pitch.  For the bass clef, it is
%   the center between the two fat dots that define the vertical
%   position of the `f' pitch.  For the alto clef, it is the vertical
%   center of the clef that is aligned with the `c' pitch.  For each
%   clef character, this center should be vertically aligned with the
%   point (0, 0).  The horizontal alignment of each clef character
%   should be such that the vertical line through the point (0, 0)
%   touches the left-most edge of the clef.
%
%   TODO: document exact_center
%
% set_char_box() conventions:
%
% * breapth: Ignored (as far as I know).  Should be set to 0.
%
% * width: Should match the clef's width.
%
% * depth: Should match the bottom edge of the clef.  Affects vertical
%   collision handling.
%
% * height: Should match the top edge of the clef.  Affects vertical
%   collision handling.
%


%%%%%%%%
%
%
%
% Editio Vaticana
%
%
%
def draw_vaticana_do_clef (expr exact_center, reduction) = 
	save reduced_il;

	reduced_il# = staff_space# * reduction;

	set_char_box (0 - xpart exact_center,
		      0.5 reduced_il# + xpart exact_center,
		      0.8 reduced_il# - ypart exact_center,
		      0.8 reduced_il# + ypart exact_center);

	define_pixels (reduced_il);

	save pat, ellipse, clef, T;
	path pat, ellipse, clef;
	transform T;

	T := identity xscaled 0.6 linethickness
		      yscaled 0.6 reduced_il;
	pickup pencircle transformed T;
	ellipse := reverse fullcircle transformed T;

	save xoffs, yoffs;

	xoffs# = xpart exact_center;
	yoffs# = ypart exact_center;

	define_pixels (xoffs, yoffs);

	rt z11 = (xoffs + 0.50 reduced_il, yoffs - .45 reduced_il);
	z12 = (xoffs + 0.25 reduced_il, yoffs - .50 reduced_il);
	lft z13 = (xoffs + 0.00 reduced_il, yoffs - .28 reduced_il);
	lft z14 = (xoffs, yoffs);

	pat := z11
	       .. z12
	       .. z13
	       -- z14;

	save shift;
	pair shift;

	% adjust vertically to fit into bounding box
	shift = find_tangent_shift (((0, -d + 0.3 reduced_il)
				     -- (w, -d + 0.3 reduced_il)), pat,
				    (0, -d / 2), (0, d / 2));
	pat := pat shifted shift;

	clef := rt z14{down}
		.. top (point 1 of pat)
		.. get_subpath (ellipse,
				-direction 0 of pat, direction 0 of pat,
				point 0 of pat)
		.. bot (point 1 of pat)
		.. get_subpath (ellipse,
				direction 2 of pat, up,
				point 2 of pat);

	fill clef
	     -- reverse clef yscaled -1
	     -- cycle;

	labels (11, 12, 13, 14);
enddef;


fet_beginchar ("Ed. Vat. do clef", "vaticana.do");
	if test = 1:
		draw_staff (-1, 3, 0.0);
	fi;
	draw_vaticana_do_clef ((0, 0), 1.0);
fet_endchar;


fet_beginchar ("Ed. Vat. do clef", "vaticana.do_change");
	draw_vaticana_do_clef ((0, 0), 1.0); % no reduction
fet_endchar;


def draw_vaticana_fa_clef (expr exact_center, reduction) = 
	save reduced_il, xoffs, yoffs;

	reduced_il# = staff_space# * reduction;
	xoffs# = xpart exact_center;
	yoffs# = ypart exact_center;

	define_pixels (reduced_il, xoffs, yoffs);

	% left-handed punctum
	save ellipse, pat, T;
	path ellipse, pat;
	transform T;

	T := identity xscaled 0.6 linethickness
		      yscaled 0.5 reduced_il;
	pickup pencircle transformed T;
	ellipse := reverse fullcircle transformed T;

	lft z21 = (xoffs + 0.00 reduced_il, yoffs + 0.00 reduced_il);
	z22 = (xoffs + 0.25 reduced_il, yoffs + 0.05 reduced_il);
	rt z23 = (xoffs + 0.50 reduced_il, yoffs - 0.05 reduced_il);

	pat := z21
	       .. z22
	       .. z23;	

	fill get_subpath (ellipse,
			  -direction 0 of pat, direction 0 of pat, z21)
	     .. top z22
	     .. get_subpath (ellipse,
			     direction 2 of pat, -direction 2 of pat, z23)
	     .. bot z22
	     .. cycle;

	% stem
	pickup pencircle scaled 0.6 linethickness;

	x23 = x24;
	yoffs = bot y24 + 1.5 reduced_il;

	draw_rounded_block (bot lft z24, top rt z23, 0.6 linethickness);

	labels (21, 22, 23, 24);

	% right-handed puncta as in do clef
	draw_vaticana_do_clef (exact_center + (0.55 reduced_il#, 0),
			       reduction);

	set_char_box (0 - xpart exact_center,
		      1.05 reduced_il# + xpart exact_center,
		      1.5 reduced_il# - ypart exact_center,
		      0.8 reduced_il# + ypart exact_center);
enddef;


fet_beginchar ("Ed. Vat. fa clef", "vaticana.fa");
	if test = 1:
		draw_staff (-1, 3, 0.0);
	fi;
	draw_vaticana_fa_clef ((0, 0), 1.0);
fet_endchar;


fet_beginchar ("Ed. Vat. fa clef", "vaticana.fa_change");
	draw_vaticana_fa_clef ((0, 0), 1.0); % no reduction
fet_endchar;


%%%%%%%%
%
%
%
% Editio Medicaea
%
%
%
def draw_medicaea_do_clef (expr exact_center, reduction) = 
	save reduced_il, reduced_slt;

	reduced_il# = staff_space# * reduction;
	reduced_slt# = linethickness# * reduction;

	define_pixels (reduced_il);
	define_pixels (reduced_slt);

	set_char_box (0 - xpart exact_center,
		      1.0 reduced_il# + xpart exact_center,
		      1.5 reduced_il# - ypart exact_center,
		      1.5 reduced_il# + ypart exact_center);

	save flag_height;

	flag_height# = 0.5 reduced_il#;

	define_pixels (flag_height);

	save xoffs, yoffs;

	xoffs# = xpart exact_center;
	yoffs# = ypart exact_center;

	define_pixels (xoffs, yoffs);

	% flags
	save ellipse, T;
	path ellipse;
	transform T;

	T := identity xscaled reduced_slt
		      yscaled flag_height;
	pickup pencircle transformed T;
	ellipse := reverse fullcircle transformed T;

	xoffs = lft x1 = rt x2 - reduced_il;
	y1 = yoffs + 0.5 (reduced_il - flag_height - staff_space);
	y2 = y1 - reduced_il + flag_height;

	fill top z1
	     -- get_subpath (ellipse, z2 - z1, z1 - z2, z2)
	     -- bot z1
	     -- cycle;

	xoffs = lft x3 = rt x4 - reduced_il;
	y3 = yoffs + 0.5 (reduced_il - flag_height + staff_space);
	y4 = y3 - reduced_il + flag_height;

	fill top z3
	     -- get_subpath (ellipse, z4 - z3, z3 - z4, z4)
	     -- bot z3
	     -- cycle;

	% stem
	pickup pencircle scaled reduced_slt;

	lft x5 = lft x6 = xoffs;
	yoffs = top y6 - 1.5 reduced_il = bot y5 + 1.5 reduced_il;

	draw_rounded_block (bot lft z5, top rt z6, reduced_slt);

	labels (1, 2, 3, 4, 5, 6);
enddef;


fet_beginchar ("Ed. Med. do clef", "medicaea.do");
	if test = 1:
		draw_staff (-1, 3, 0.0);
	fi;
	draw_medicaea_do_clef ((0, 0), 1.0);
fet_endchar;


fet_beginchar ("Ed. Med. do clef", "medicaea.do_change");
	draw_medicaea_do_clef ((0, 0), .8);
fet_endchar;


def draw_medicaea_fa_clef (expr exact_center, reduction) = 
	% inspired by Regensburger Edition of Medicaea (1885/86), in:
	% MGG, volume 2, col. 1327 ("Choralreform"), fig. 2.

	save reduced_il, reduced_slt;

	reduced_il# = staff_space# * reduction;
	reduced_slt# = linethickness# * reduction;

	define_pixels (reduced_il);
	define_pixels (reduced_slt);

	save xoffs, yoffs;

	xoffs# = xpart exact_center;
	yoffs# = ypart exact_center;

	define_pixels (xoffs, yoffs);

	% stem
	pickup pencircle scaled reduced_slt;

	x11 = x12 = xoffs + 0.4 reduced_il;
	y11 = yoffs = bot y12 + 1.5 reduced_il;

	draw_rounded_block (bot lft z12, top rt z11, reduced_slt);

	% left-handed punctum
	save ellipse, T;
	path ellipse;
	transform T;

	T := identity xscaled reduced_slt
		      yscaled reduced_il;
	pickup pencircle transformed T;
	ellipse := reverse fullcircle transformed T;

	lft z13 = (xoffs, yoffs);
	rt z14 = z11 + (reduced_slt / 2, 0);

	fill get_subpath (ellipse, left, right, z13)
	     -- get_subpath (ellipse, right, left, z14)
	     -- cycle;

	labels (11, 12, 13, 14);

	% right-handed puncta as in do clef
	draw_medicaea_do_clef (exact_center + (0.7 reduced_il#, 0),
			       reduction);

	set_char_box (0 - xpart exact_center,
		      1.7 reduced_il# + xpart exact_center,
		      1.5 reduced_il# - ypart exact_center,
		      1.5 reduced_il# + ypart exact_center);
enddef;


fet_beginchar ("Ed. Med. fa clef", "medicaea.fa");
	if test = 1:
		draw_staff (-1, 3, 0.0);
	fi;
	draw_medicaea_fa_clef ((0, 0), 1.0);
fet_endchar;


fet_beginchar ("Ed. Med. fa clef", "medicaea.fa_change");
	draw_medicaea_fa_clef ((0, 0), .8);
fet_endchar;


%%%%%%%%
%
%
%
% Mensural Notation
%
%
%

%
% width:        interval from left end to right end
% height:       interval from bottom of lower beam to top of upper beam
% exact_center: the coordinates of the vertical center point of the
%               left edge.
%
def draw_brevis (expr exact_center, bwidth, bheight, blinethickness) =
	save brevis_width, brevis_height, linethickness;

	brevis_width# = bwidth;
	brevis_height# = bheight;
	linethickness# = blinethickness;

	save beam_width, beam_height;
	save serif_size, serif_protrude, hole_height;

	beam_width# = 1.4 linethickness#;
	hole_height# = 3 linethickness#;
	2 beam_height# + hole_height# = brevis_height#;
	serif_size# = (hole_height# - linethickness#) / 2;
	serif_protrude# = 1.5 serif_size#;

	save xoffs, yoffs;

	xoffs# = xpart exact_center;
	yoffs# = ypart exact_center;

	define_pixels (xoffs, yoffs);
	define_pixels (brevis_width, brevis_height, linethickness);
	define_pixels (beam_width, beam_height, serif_size, serif_protrude);

	z1l = (xoffs, yoffs - linethickness);
	z2r = z1r + serif_size * (1, -1);
	z3l = z2l + (-serif_size, -serif_protrude);

	penpos1 (beam_width, 0);
	penpos2 (beam_height, 90);
	penpos3 (beam_width, 180);

	save pat_in, pat_out;
	path pat_in, pat_out;

	pat_out := z3r{down}
		   .. z3l{up}
		   .. z2l{right};
	pat_out := pat_out
		   -- reverse pat_out xscaled -1
				      shifted (2 xoffs + brevis_width, 0);
	pat_out := pat_out
		   -- reverse pat_out yscaled -1
				      shifted (0, 2 yoffs)
		   -- cycle;

	pat_in := z1r{down}
		  .. z2r{right};
	pat_in := pat_in
		  -- reverse pat_in xscaled -1
				    shifted (2 xoffs + brevis_width, 0);
	pat_in := pat_in
		  -- reverse pat_in yscaled -1
				    shifted (0, 2 yoffs)
		  -- cycle;

	fill pat_out;
	unfill pat_in;

	penlabels (1, 2, 3);
enddef;

%
% Draw two brevis notes; the second one shifted down by `shift'.
% The other parameters are the same as with `draw_brevis'.
%
def draw_double_brevis (expr exact_center, bwidth, bheight,
			     blinethickness, shift) =
	save brevis_width, brevis_height, linethickness;

	brevis_width# = bwidth;
	brevis_height# = bheight;
	linethickness# = blinethickness;

	save beam_width, beam_height;
	save serif_size, serif_protrude, hole_height;

	beam_width# = 1.4 linethickness#;
	hole_height# = 3 linethickness#;
	2 beam_height# + hole_height# = brevis_height#;
	serif_size# = (hole_height# - linethickness#) / 2;
	serif_protrude# = 1.5 serif_size#;

	save xoffs, yoffs;

	xoffs# = xpart exact_center;
	yoffs# = ypart exact_center;

	define_pixels (xoffs, yoffs);
	define_pixels (brevis_width, brevis_height, linethickness);
	define_pixels (beam_width, beam_height, serif_size, serif_protrude);

	z1l = (xoffs, yoffs - linethickness);
	z2r = z1r + serif_size * (1, -1);
	z3l = z2l + (-serif_size, -serif_protrude);

	penpos1 (beam_width, 0);
	penpos2 (beam_height, 90);
	penpos3 (beam_width, 180);

	z4 = z1 shifted (0, -shift);
	z5 = z2 shifted (0, -shift);
	z6 = z3 shifted (0, -shift);
	
	penpos4 (beam_width, 0);
	penpos5 (beam_height, 90);
	penpos6 (beam_width, 180);

	save pat_in, pat_out;
	path pat_in, pat_out;

	pat_out := z6r{down}
		   .. z6l{up}
		   .. z5l{right};
	pat_out := pat_out
		   -- reverse pat_out xscaled -1
				      shifted (2 xoffs + brevis_width, 0);
	pat_out := pat_out
		   -- reverse pat_out yscaled -1
				      shifted (0, shift - 2 yoffs)
		   -- cycle;

	fill pat_out;

	pat_in := z1r{down}
		  .. z2r{right};
	pat_in := pat_in
		  -- reverse pat_in xscaled -1
				    shifted (2 xoffs + brevis_width, 0);
	pat_in := pat_in
		  -- reverse pat_in yscaled -1
				    shifted (0, 2 yoffs)
		  -- cycle;

	unfill pat_in;
	unfill pat_in shifted (0, -shift);

	penlabels (1, 2, 3, 4, 5, 6);
enddef;


%
% Draw three brevis notes; the second one shifted down by `shift',
% the third one by `2 shift'.
% The other parameters are the same as with `draw_brevis'.
%
def draw_triple_brevis (expr exact_center, bwidth, bheight,
			     blinethickness, shift) =
	save brevis_width, brevis_height, linethickness;

	brevis_width# = bwidth;
	brevis_height# = bheight;
	linethickness# = blinethickness;

	save beam_width, beam_height;
	save serif_size, serif_protrude, hole_height;

	beam_width# = 1.4 linethickness#;
	hole_height# = 3 linethickness#;
	2 beam_height# + hole_height# = brevis_height#;
	serif_size# = (hole_height# - linethickness#) / 2;
	serif_protrude# = 1.5 serif_size#;

	save xoffs, yoffs;

	xoffs# = xpart exact_center;
	yoffs# = ypart exact_center;

	define_pixels (xoffs, yoffs);
	define_pixels (brevis_width, brevis_height, linethickness);
	define_pixels (beam_width, beam_height, serif_size, serif_protrude);

	z1l = (xoffs, yoffs - linethickness);
	z2r = z1r + serif_size * (1, -1);
	z3l = z2l + (-serif_size, -serif_protrude);

	penpos1 (beam_width, 0);
	penpos2 (beam_height, 90);
	penpos3 (beam_width, 180);

	z7 = z1 shifted (0, -2 shift);
	z8 = z2 shifted (0, -2 shift);
	z9 = z3 shifted (0, -2 shift);
	
	penpos7 (beam_width, 0);
	penpos8 (beam_height, 90);
	penpos9 (beam_width, 180);

	save pat_in, pat_out;
	path pat_in, pat_out;

	pat_out := z9r{down}
		   .. z9l{up}
		   .. z8l{right};
	pat_out := pat_out
		   -- reverse pat_out xscaled -1
				      shifted (2 xoffs + brevis_width, 0);
	pat_out := pat_out
		   -- reverse pat_out yscaled -1
				      shifted (0, -2 yoffs)
		   -- cycle;

	fill pat_out;

	pat_in := z1r{down}
		  .. z2r{right};
	pat_in := pat_in
		  -- reverse pat_in xscaled -1
				    shifted (2 xoffs + brevis_width, 0);
	pat_in := pat_in
		  -- reverse pat_in yscaled -1
				    shifted (0, 2 yoffs)
		  -- cycle;

	unfill pat_in;
	unfill pat_in shifted (0, -shift);
	unfill pat_in shifted (0, -2 shift);

	penlabels (1, 2, 3, 7, 8, 9);
enddef;


def draw_neomensural_c_clef (expr exact_center, reduction) = 
	save reduced_il, reduced_slt, stem_width;

	reduced_il# = staff_space# * reduction;
	reduced_slt# = linethickness# * reduction;
	stem_width# = 1.4 reduced_slt#;

	define_pixels (reduced_il, reduced_slt, stem_width);

	set_char_box (0 - xpart exact_center,
		      2 reduced_il# + 6 reduced_slt# + xpart exact_center,
		      2 reduced_il# - ypart exact_center,
		      2 reduced_il# + ypart exact_center);

	draw_brevis (exact_center + (3 reduced_slt#, 0),
		     2 reduced_il#, reduced_il#, reduced_slt#);

	save xoffs, yoffs;

	xoffs# = xpart exact_center;
	yoffs# = ypart exact_center;

	define_pixels (xoffs, yoffs);

	save ellipse, pat, T;
	path ellipse, pat;
	transform T;

	T := identity xscaled stem_width
		      yscaled blot_diameter;
	pickup pencircle transformed T;
	ellipse := fullcircle transformed T;

	lft x11 = lft x12 = xoffs;
	top y12 - bot y11 = 4 reduced_il;
	top y12 + bot y11 = 2 yoffs;
	x13 = x3;
	y13 = y11;
	rt x14 = rt x15 = w;
	y14 = y11;
	y15 = y12;

	pat := get_subpath (ellipse, down, up, z13)
	       -- z3l
	       -- z3r
	       -- cycle;

	fill get_subpath (ellipse, down, up, z11)
	     -- get_subpath (ellipse, up, down, z12)
	     -- cycle;
	fill get_subpath (ellipse, down, up, z14)
	     -- get_subpath (ellipse, up, down, z15)
	     -- cycle;

	fill pat;
	fill pat xscaled -1
		 shifted (w, 0);
	fill pat yscaled -1
		 shifted (0, 2 yoffs);
	fill pat scaled -1
		 shifted (w, 2 yoffs);

	labels (11, 12, 13, 14, 15);
enddef;


fet_beginchar ("neo-mensural c clef", "neomensural.c");
	if test = 1:
		draw_staff (-1, 3, 0.0);
	fi;
	draw_neomensural_c_clef ((0, 0), 1.0);
fet_endchar;


fet_beginchar ("neo-mensural c clef", "neomensural.c_change");
	draw_neomensural_c_clef ((0, 0), .8);
fet_endchar;


def draw_petrucci_c_clef (expr exact_center, flare_align, reduction) = 
	% inspired by Josquin Desprez, "Stabat Mater", Libro tertio,
	% 1519, printed by Petrucci, in: MGG, volume 7, Table 11.
	% Also by Petrucci's Canti C, Venedig 1503.  In: MGG, volume
	% 9, p. 1681/1682.

	save reduced_il, reduced_slt;

	reduced_il# = staff_space# * reduction;
	reduced_slt# = linethickness# * reduction;

	define_pixels (reduced_il);

	draw_double_brevis (exact_center + (0, 0.5 staff_space#),
			    reduced_il#, reduced_il#, reduced_slt#,
			    staff_space);

	save half_reduced_il, left_depth, left_height;

	half_reduced_il# = staff_space# * sqrt (reduction);
	left_height# = half_reduced_il# * min (3.2, 3.2 + 0.2 + flare_align);
	left_depth# = half_reduced_il# * min (3.2, 3.2 + 0.2 - flare_align);

	define_pixels (half_reduced_il);
	define_pixels (left_depth, left_height);

	set_char_box (0 - xpart exact_center,
		      reduced_il# + xpart exact_center,
		      left_depth# - ypart exact_center,
		      left_height# + ypart exact_center);

	save xoffs, yoffs;

	xoffs# = xpart exact_center;
	yoffs# = ypart exact_center;

	define_pixels (xoffs, yoffs);

	save ellipse, T;
	path ellipse;
	transform T;

	T := identity xscaled 1.4 linethickness
		      yscaled blot_diameter;
	pickup pencircle transformed T;
	ellipse := fullcircle transformed T;

	lft x11 = lft x13 = xoffs;
	top y11 = yoffs + left_height;
	bot y13 = yoffs - left_depth;
	rt x15 = rt x17 = xoffs + brevis_width;
	y15 = min (y11 - 0.2 half_reduced_il, yoffs + 2.2 half_reduced_il);
	y17 = max (y13 + 0.2 half_reduced_il, yoffs - 2.2 half_reduced_il);

	z12 = z14 yscaled -1;
	z14 = z6;
	z16 = z18 yscaled -1;
	rt z18 = lft z14 shifted (brevis_width, 0);

	penpos12 (1.4 linethickness, 0);
	penpos14 (1.4 linethickness, 0);
	penpos16 (1.4 linethickness, 0);
	penpos18 (1.4 linethickness, 0);

	if top y11 > -y6 + 0.7 linethickness:
		fill get_subpath (ellipse, up, down, z11)
		     -- z12l
		     -- z12r
		     -- cycle;
	fi;
	if bot y13 < y6 - 0.7 linethickness:
		fill get_subpath (ellipse, down, up, z13)
		     -- z14r
		     -- z14l
		     -- cycle;
	fi;
	if top y15 > -y6 + 0.7 linethickness:
		fill get_subpath (ellipse, up, down, z15)
		     -- z16l
		     -- z16r
		     -- cycle;
	fi;
	if bot y17 < y6 - 0.7 linethickness:
		fill get_subpath (ellipse, down, up, z17)
		     -- z18r
		     -- z18l
		     -- cycle;
	fi;

	labels (11, 13, 15, 17);
	penlabels (12, 14, 16, 18);
enddef;


fet_beginchar ("petrucci c1 clef", "petrucci.c1");
	if test = 1:
		draw_staff (-1, 3, 0.0);
	fi;
	draw_petrucci_c_clef ((0, 0), +2, 1.0);
fet_endchar;


fet_beginchar ("petrucci c1 clef", "petrucci.c1_change");
	draw_petrucci_c_clef ((0, 0), +2, .8);
fet_endchar;


fet_beginchar ("petrucci c2 clef", "petrucci.c2");
	if test = 1:
		draw_staff (-1, 3, 0.0);
	fi;
	draw_petrucci_c_clef ((0, 0), +1, 1.0);
fet_endchar;


fet_beginchar ("petrucci c2 clef", "petrucci.c2_change");
	draw_petrucci_c_clef ((0, 0), +1, .8);
fet_endchar;


fet_beginchar ("petrucci c3 clef", "petrucci.c3");
	if test = 1:
		draw_staff (-1, 3, 0.0);
	fi;
	draw_petrucci_c_clef ((0, 0), 0, 1.0);
fet_endchar;


fet_beginchar ("petrucci c3 clef", "petrucci.c3_change");
	draw_petrucci_c_clef ((0, 0), 0, .8);
fet_endchar;


fet_beginchar ("petrucci c4 clef", "petrucci.c4");
	if test = 1:
		draw_staff (-1, 3, 0.0);
	fi;
	draw_petrucci_c_clef ((0, 0), -1, 1.0);
fet_endchar;


fet_beginchar ("petrucci c4 clef", "petrucci.c4_change");
	draw_petrucci_c_clef ((0, 0), -1, .8);
fet_endchar;


fet_beginchar ("petrucci c5 clef", "petrucci.c5");
	if test = 1:
		draw_staff (-1, 3, 0.0);
	fi;
	draw_petrucci_c_clef ((0, 0), -2, 1.0);
fet_endchar;


fet_beginchar ("petrucci c5 clef", "petrucci.c5_change");
	draw_petrucci_c_clef ((0, 0), -2, .8);
fet_endchar;


def draw_mensural_c_clef (expr exact_center, reduction) =
	% inspired by Ockeghem, "Missa Prolationum", in: MGG, volume
	% 9, table 94.

	save reduced_il;

	reduced_il# = staff_space# * reduction;

	define_pixels (reduced_il);

	draw_triple_brevis (exact_center + (0, 0.5 staff_space#),
			    2 reduced_il#, 0.8 staff_space#,
			    0.8 linethickness#, staff_space);

	save half_reduced_il;

	half_reduced_il# = staff_space# * sqrt (reduction);

	define_pixels (half_reduced_il);

	set_char_box (0 - xpart exact_center,
		      2 reduced_il# + xpart exact_center,
		      2.2 half_reduced_il# + staff_space# -
			2 ypart exact_center,
		      2.2 half_reduced_il# + 2 ypart exact_center);

	save xoffs, yoffs;

	xoffs# = xpart exact_center;
	yoffs# = ypart exact_center;

	define_pixels (xoffs, yoffs);

	save ellipse, T;
	path ellipse;
	transform T;

	T := identity xscaled 1.4 linethickness
		      yscaled blot_diameter;
	pickup pencircle transformed T;
	ellipse := fullcircle transformed T;

	lft x11 = lft x13 = xoffs;
	top y11 = yoffs + 2.2 half_reduced_il;
	bot y13 = yoffs - 2.2 half_reduced_il - staff_space;
	rt x15 = rt x17 = xoffs + brevis_width;
	y15 = yoffs + 1.4 half_reduced_il;
	y17 = yoffs - 1.4 half_reduced_il - staff_space;

	z12 = z14 yscaled -1 shifted (0, -staff_space);
	z14 = z9;
	z16 = z18 yscaled -1 shifted (0, -staff_space);
	rt z18 = lft z14 shifted (brevis_width, 0);

	penpos12 (1.4 linethickness, 0);
	penpos14 (1.4 linethickness, 0);
	penpos16 (1.4 linethickness, 0);
	penpos18 (1.4 linethickness, 0);

	fill get_subpath (ellipse, up, down, z11)
	     -- z12l
	     -- z12r
	     -- cycle;
	fill get_subpath (ellipse, down, up, z13)
	     -- z14r
	     -- z14l
	     -- cycle;
	fill get_subpath (ellipse, up, down, z15)
	     -- z16l
	     -- z16r
	     -- cycle;
	fill get_subpath (ellipse, down, up, z17)
	     -- z18r
	     -- z18l
	     -- cycle;

	labels (11, 13, 15, 17);
	penlabels (12, 14, 16, 18);
enddef;


fet_beginchar ("mensural c clef", "mensural.c");
	if test = 1:
		draw_staff (-1, 3, 0.0);
	fi;
	draw_mensural_c_clef ((0, 0), 1.0);
fet_endchar;


fet_beginchar ("mensural c clef", "mensural.c_change");
	draw_mensural_c_clef ((0, 0), .8);
fet_endchar;


def draw_diamond (expr exact_center, reduction) =
	save stem_width, reduced_nht, holeheight, beamheight;
	save rh_height, rh_width;

	stem_width# = 1.4 reduced_slt#;
	reduced_nht# = noteheight# * reduction;
	holeheight# = 3 reduced_slt#;
	beamheight# = 0.4 (reduced_nht# - holeheight#);

	rh_height# = 1.2 staff_space# * reduction;
	rh_width# / rh_height# = tand (30);

	define_pixels (beamheight, stem_width);
	define_pixels (rh_height, rh_width);

	save xoffs, yoffs;

	xoffs# = xpart exact_center;
	yoffs# = ypart exact_center;

	define_pixels (xoffs, yoffs);

	save ellipse, T;
	path ellipse;
	transform T;

	T := identity xscaled beamheight
		      yscaled stem_width
		      rotated 45;
	pickup pencircle transformed T;
	ellipse := reverse fullcircle transformed T;

	x21 := xoffs - rh_width / 2;
	y21 := yoffs;
	x22 := xoffs;
	y22 := yoffs + rh_height / 2;
	x23 := xoffs + rh_width / 2;
	y23 := yoffs;
	x24 := xoffs;
	y24 := yoffs - rh_height / 2;

	fill get_subpath (ellipse, z21 - z24, z22 - z21, z21)
	     -- get_subpath (ellipse, z22 - z21, z23 - z22, z22)
	     -- get_subpath (ellipse, z23 - z22, z24 - z23, z23)
	     -- get_subpath (ellipse, z24 - z23, z21 - z24, z24)
	     -- cycle;

	save l;
	path l[];

	l2122 := (directionpoint (z21 - z22) of ellipse) shifted z21
		 -- (directionpoint (z21 - z22) of ellipse) shifted z22;
	l2223 := (directionpoint (z22 - z23) of ellipse) shifted z22
		 -- (directionpoint (z22 - z23) of ellipse) shifted z23;
	l2324 := (directionpoint (z23 - z24) of ellipse) shifted z23
		 -- (directionpoint (z23 - z24) of ellipse) shifted z24;
	l2421 := (directionpoint (z24 - z21) of ellipse) shifted z24
		 -- (directionpoint (z24 - z21) of ellipse) shifted z21;

	unfill l2122 intersectionpoint l2223
	       -- l2223 intersectionpoint l2324
	       -- l2324 intersectionpoint l2421
	       -- l2421 intersectionpoint l2122
	       -- cycle;

	labels (21, 22, 23, 24);
enddef;


def draw_petrucci_f_clef (expr exact_center, reduction) =
	% inspired by L'homme arme super voces musicales in Misse
	% Josquin, 1502, Petrucci, in: MGG, volume 7, col. 200; also
	% inspired by Gaspar van Weerbeke, "Virgo Maria" (1502), in:
	% MGG, volume 9, col. 653 ("Motette"), fig. 3.; also by Andr'e
	% Campra, "Entr'ee des s'er'enades" (1710), in: MGG, volume 2,
	% col. 1649 ("Contredanse"), fig. 2.

	save interline, reduced_il, reduced_slt;

	interline# = staff_space#;
	reduced_il# = staff_space# * reduction;
	reduced_slt# = linethickness# * reduction;

	draw_brevis (exact_center, reduced_il#, reduced_il#, reduced_slt#);
	draw_diamond (exact_center +
			(1.6 interline# * reduction, interline# / 2),
		     reduction);
	draw_diamond (exact_center +
			(1.6 interline# * reduction, -interline# / 2),
		     reduction);

	define_pixels (interline, reduced_il, reduced_slt);

	save stem_width;

	stem_width# = 1.4 reduced_slt#;

	define_pixels (stem_width);

	save xoffs, yoffs;

	xoffs# = xpart exact_center;
	yoffs# = ypart exact_center;

	define_pixels (xoffs, yoffs);

	% brevis stem
	save ellipse, T;
	path ellipse;
	transform T;

	T := identity xscaled stem_width
		      yscaled blot_diameter;
	pickup pencircle transformed T;
	ellipse := fullcircle transformed T;

	rt x8 = xoffs + reduced_il;
	y8 = y3;
	rt z9 = (xoffs + reduced_il, yoffs - 4 reduced_il);

	penpos8 (stem_width, 0);

	fill get_subpath (ellipse, down, up, z9)
	     -- z8r
	     -- z8l
	     -- cycle;

	% upper diamond's stem
	z10 = (xoffs + 1.6 interline * reduction + stem_width / 2,
	       yoffs + interline * reduction);
	top z11 = z10 + (0, 1.5 interline * reduction);

	penpos10 (stem_width, 0);

	fill get_subpath (ellipse, up, down, z11)
	     -- z10l
	     -- z10r
	     -- cycle;

	% lower diamond's stem
	z12 = (xoffs + 1.6 interline * reduction - stem_width / 2,
	       yoffs - interline * reduction);
	bot z13 = z12 + (0, -3.5 interline * reduction);

	penpos12 (stem_width, 0);

	fill get_subpath (ellipse, down, up, z13)
	     -- z12r
	     -- z12l
	     -- cycle;

	save reduced_il, rh_height, rh_width;

	reduced_il# = staff_space# * reduction;
	rh_height# = 1.2 reduced_il#;
	rh_width# / rh_height# = tand (30);

	set_char_box (0 - xpart exact_center,
		      1.6 interline# * reduction + 0.5 rh_width# +
			xpart exact_center,
		      4.5 interline# * reduction - ypart exact_center,
		      2.5 interline# * reduction + ypart exact_center);

	labels (9, 11, 13);
	penlabels (8, 10, 12);
enddef;


fet_beginchar ("petrucci f clef", "petrucci.f");
	if test = 1:
		draw_staff (-1, 3, 0.0);
	fi;
	draw_petrucci_f_clef ((0, 0), 1.0);
fet_endchar;


fet_beginchar ("petrucci f clef", "petrucci.f_change");
	draw_petrucci_f_clef ((0, 0), .8);
fet_endchar;


def draw_mensural_f_clef (expr exact_center, reduction) =
	% inspired by Philippe le Duc, "Dite Signori" (1590), in: MGG,
	% volume 3, col. 848 ("Duc"); also by John Dowland, "The First
	% Booke of Songes" (1597), in: MGG, volume 3, col. 721
	% ("Dowland"), fig. 3.

	save width, reduced_slt, stem_width, dot_diameter;

	width# = 1.2 staff_space# * reduction;
	reduced_slt# = linethickness# * reduction;
	stem_width# = 1.4 reduced_slt#;
	dot_diameter# = 0.1 reduction * staff_space#;

	define_pixels (width, stem_width, staff_space, dot_diameter);

	save xoffs, yoffs;

	xoffs# = xpart exact_center;
	yoffs# = ypart exact_center;

	define_pixels (xoffs, yoffs);

	save ellipse, T;
	path ellipse;
	transform T;

	T := identity xscaled 0.2 width
		      yscaled stem_width
		      rotated 45;
	pickup pencircle transformed T;
	ellipse := fullcircle transformed T;

	% half circle
	lft z10 = (0, 0);

	save pat;
	path pat;

	pat := halfcircle scaled width
			  rotated -90
			  shifted (z10 - (xoffs, yoffs));

	z5 = point 0 of pat;
	z6 = point 1 of pat;
	z7 = point 2 of pat;
	z8 = point 3 of pat;
	z9 = point 4 of pat;

	save dirs;
	pair dirs[];

	dirs5 := direction 0 of pat;
	dirs6 := direction 1 of pat;
	dirs7 := direction 2 of pat;
	dirs8 := direction 3 of pat;
	dirs9 := direction 4 of pat;

	% we approximate `draw pat'
	fill get_subpath (ellipse, -dirs5, dirs5, z5)
	     .. get_subpoint (ellipse, dirs6, z6)
	     .. get_subpoint (ellipse, dirs7, z7)
	     .. get_subpoint (ellipse, dirs8, z8)
	     .. get_subpath (ellipse, dirs9, -dirs9, z9)
	     .. get_subpoint (ellipse, -dirs8, z8)
	     .. get_subpoint (ellipse, -dirs7, z7)
	     .. get_subpoint (ellipse, -dirs6, z6)
	     .. cycle;

	% upper dot
	rt x2 = xoffs + width;
	top y1 = yoffs + 0.5 width;
	z2 - z1 = (dot_diameter, -dot_diameter);

	fill get_subpath (ellipse, z1 - z2, z2 - z1, z1)
	     -- get_subpath (ellipse, z2 - z1, z1 - z2, z2)
	     -- cycle;

	% lower dot
	x3 = x1;
	top y1 - bot y4 = width;
	z4 - z3 = (dot_diameter, -dot_diameter);

	fill get_subpath (ellipse, z3 - z4, z4 - z3, z3)
	     -- get_subpath (ellipse, z4 - z3, z3 - z4, z4)
	     -- cycle;

	set_char_box (0 - xpart exact_center,
		      width# + xpart exact_center,
		      0.5 width# - ypart exact_center,
		      0.5 width# + ypart exact_center);

	labels (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
enddef;


fet_beginchar ("mensural f clef", "mensural.f");
	if test = 1:
		draw_staff (-1, 3, 0.0);
	fi;
	draw_mensural_f_clef ((0, 0), 1.0);
fet_endchar;


fet_beginchar ("mensural f clef", "mensural.f_change");
	draw_mensural_f_clef ((0, 0), .8);
fet_endchar;


def draw_petrucci_g_clef (expr exact_center, reduction) =
	% inspired by Josquin Desprez, "Stabat Mater", Libro tertio,
	% 1519, printed by Petrucci, in: MGG, volume 7, Table 11.

	save reduced_il, reduced_slt;

	reduced_il# = staff_space# * reduction;
	reduced_slt# = linethickness# * reduction;
	define_pixels (reduced_il, reduced_slt);

	set_char_box (0 - xpart exact_center,
		      1.25 reduced_il# + xpart exact_center,
		      0.65 reduced_il# - ypart exact_center,
		      3.80 reduced_il# + ypart exact_center);

	save xoffs, yoffs;

	xoffs# = xpart exact_center;
	yoffs# = ypart exact_center;

	define_pixels (xoffs, yoffs);

	save ellipse, paths, sub_path, outlines, sub_outlines, T;
	path ellipse, paths[], sub_path, outlines[], sub_outlines[];
	transform T;

	T := identity xscaled 0.5 reduced_slt
		      yscaled 0.22 reduced_il
		      rotated -35;
	pickup pencircle transformed T;
	ellipse := fullcircle transformed T;

	lft z1 = (xoffs + 0.80 reduced_il, yoffs + 0.00 reduced_il);
	lft z2 = (xoffs + 1.00 reduced_il, yoffs + 1.20 reduced_il);
	lft z3 = (xoffs + 0.70 reduced_il, yoffs + 2.00 reduced_il);
	lft z4 = (xoffs + 0.30 reduced_il, yoffs + 3.00 reduced_il);
	lft z5 = (xoffs + 0.80 reduced_il, yoffs + 3.70 reduced_il);
	lft z6 = (xoffs + 1.00 reduced_il, yoffs + 3.00 reduced_il);
	lft z7 = (xoffs + 0.60 reduced_il, yoffs + 2.00 reduced_il);
	lft z8 = (xoffs + 0.30 reduced_il, yoffs + 1.70 reduced_il);
	lft z9 = (xoffs + 0.00 reduced_il, yoffs + 0.75 reduced_il);
	lft z10 = (xoffs + 0.20 reduced_il, yoffs + 0.60 reduced_il);

	paths1 := z1{-1, 2}
		  .. z2
		  .. z3
		  .. z4
		  .. z5
		  .. z6
		  .. z7
		  .. z8
		  .. z9
		  .. z10;

	save dirs, s;
	pair dirs[];

	s := 1/4;

	% we approximate `draw paths1'
	for i = 1 step s until (length paths1 + 1):
		dirs[i] := direction (i - 1) of paths1;
	endfor;

	outlines1 := get_subpath (ellipse, -dirs1, dirs1, z1)
		     for i = (1 + s) step s until (length paths1 + 1 - s):
			     .. get_subpoint (ellipse, dirs[i],
					      point (i - 1) of paths1)
		     endfor
		     .. get_subpath (ellipse, dirs10, -dirs10, z10)
		     for i = (length paths1 + 1 - s) step -s until (1 + s):
			     .. get_subpoint (ellipse, -dirs[i],
					      point (i - 1) of paths1)
		     endfor
		     .. cycle;

	save len;

	len := length outlines1;

	sub_outlines1 := subpath (0,
				  floor (1/4 len)) of outlines1;
	sub_outlines2 := subpath (floor (1/4 len),
				  floor (2/4 len)) of outlines1;
	sub_outlines3 := subpath (floor (2/4 len),
				  floor (3/4 len)) of outlines1;
	sub_outlines4 := subpath (floor (3/4 len),
				  len) of outlines1;

	save times;
	numeric times[];

	(times12, times21) = sub_outlines1 intersectiontimes sub_outlines2;
	(times13, times31) = sub_outlines1 intersectiontimes sub_outlines3;
	(times42, times24) = sub_outlines4 intersectiontimes sub_outlines2;
	(times43, times34) = sub_outlines4 intersectiontimes sub_outlines3;

	T := identity xscaled 0.75 reduced_slt
		      yscaled 0.33 reduced_il
		      rotated -35;
	pickup pencircle transformed T;
	ellipse := fullcircle transformed T;

	lft z21 = (xoffs + 1.05 reduced_il, yoffs + 0.45 reduced_il);
	lft z22 = (xoffs + 0.55 reduced_il, yoffs + 0.45 reduced_il);
	lft z23 = (xoffs + 0.55 reduced_il, yoffs - 0.45 reduced_il);
	lft z24 = (xoffs + 1.05 reduced_il, yoffs - 0.45 reduced_il);
	lft z25 = (xoffs + 1.10 reduced_il, yoffs + 0.00 reduced_il);
	lft z26 = (xoffs + 0.80 reduced_il, yoffs + 0.00 reduced_il);

	paths2 := z21
		  .. z22
		  .. z23
		  .. z24
		  .. {up}z25
		  -- z26;

	sub_path := subpath (0, 1) of paths2;

	times1 = xpart (sub_outlines1 intersectiontimes sub_path);
	times4 = xpart (sub_outlines4 intersectiontimes sub_path);

	% we have to find the envelope intersections (if any)
	save t;
	numeric t[];

	t1 = find_envelope_cusp (reverse ellipse,
				 subpath (1, 2) of paths2,
				 1/256) + 1;
	if t1 < 1:
		t1 := 1;
		t2 := 1;
	else:
		t2 = find_envelope_cusp (ellipse,
					 subpath (3, 4) of reverse paths2,
					 1/256) + 3;
		t2 := length paths2 - t2;
	fi;

	t3 = find_envelope_cusp (reverse ellipse,
				 subpath (2, 4 - epsilon) of paths2,
				 1/256) + 2;
	if t3 < 2:
		t3 := 3;
		t4 := 3;
	else:
		t4 = find_envelope_cusp (ellipse,
					 subpath (1 + epsilon, 3)
					   of reverse paths2,
					 1/256) + 1;
		t4 := length paths2 - t4;
	fi;

	fill subpath (times1 + s / 4, times13) of sub_outlines1
	     -- subpath (times31, infinity) of sub_outlines3
	     & subpath (0, times42) of sub_outlines4
	     -- subpath (times24, infinity) of sub_outlines2
	     & subpath (0, times34) of sub_outlines3
	     -- subpath (times43, times4 - s / 4) of sub_outlines4
	     -- cycle;
	unfill subpath (times12, infinity) of sub_outlines1
	       & subpath (0, times21) of sub_outlines2
	       -- cycle;
	fill subpath (times4 + s / 4, infinity) of sub_outlines4
	     & subpath (0, times1 - s / 4) of sub_outlines1
	     -- cycle;


	% we approximate `draw paths2'
	for i = 1 step s until (length paths2 - s):
		dirs[i + 20] := direction (i - 1) of paths2;
	endfor;

	sub_outlines21 := get_subpath (ellipse, -dirs21, dirs21, z21)
			  for i = (1 + s) step s until (length paths2 - s):
				  .. get_subpoint (ellipse, dirs[i + 20],
						   point (i - 1) of paths2)
			  endfor
			  .. get_subpath (ellipse, up, z26 - z25, z25);
	sub_outlines22 := get_subpath (ellipse, z26 - z25, z25 - z26, z26)
			  -- get_subpoint (ellipse, z25 - z26, z25);
	sub_outlines23 := get_subpoint (ellipse, down, z25)
			  for i = (length paths2 - s) step -s until (t4 + 1):
				  .. get_subpoint (ellipse, -dirs[i + 20],
						   point (i - 1) of paths2)
			  endfor
			  .. get_subpoint (ellipse, -direction t4 of paths2,
					   point t4 of paths2);
	sub_outlines24 := get_subpoint (ellipse, -direction t3 of paths2,
					point t3 of paths2)
			  for i = (floor (t3 / s) * s + 1) step -s until (t2 + 1):
				  .. get_subpoint (ellipse, -dirs[i + 20],
						   point (i - 1) of paths2)
			  endfor
			  .. get_subpoint (ellipse, -direction t2 of paths2,
					   point t2 of paths2);
	sub_outlines25 := get_subpoint (ellipse, -direction t1 of paths2,
					point t1 of paths2)
			  for i = (floor (t1 / s) * s + 1) step -s until (1 + s):
				  .. get_subpoint (ellipse, -dirs[i + 20],
						   point (i - 1) of paths2)
			  endfor;

	(times2223, times2322) = sub_outlines22 intersectiontimes sub_outlines23;
	(times2324, times2423) = sub_outlines23 intersectiontimes sub_outlines24;
	(times2425, times2524) = sub_outlines24 intersectiontimes sub_outlines25;

	fill sub_outlines21
	     -- subpath (0, times2223) of sub_outlines22
	     -- subpath (times2322, times2324) of sub_outlines23
	     -- subpath (times2423, times2425) of sub_outlines24
	     -- subpath (times2524, infinity) of sub_outlines25
	     .. cycle;

	labels (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
	labels (21, 22, 23, 24, 25, 26);
enddef;


fet_beginchar ("petrucci g clef", "petrucci.g");
	if test = 1:
		draw_staff (-1, 3, 0.0);
	fi;
	draw_petrucci_g_clef ((0, 0), 1.0);
fet_endchar;


fet_beginchar ("petrucci g clef", "petrucci.g_change");
	draw_petrucci_g_clef ((0, 0), .8);
fet_endchar;


def draw_mensural_g_clef (expr exact_center, reduction) =
  % TODO: Rewrite me.  The former mensural g clef looked ugly, and the
  % code was removed when it broke for small font sizes after some
  % global changes in the font.  Currently, the character is mapped to
  % a copy of the petrucci g clef (which, after all, *is* a mensural g
  % clef, but not the one that we have in mind here). -- jr
  %
  % Possible sources of inspiration for this clef include: Francisco
  % Guerrero, "Lib. 1.  Missarum" (1566), in: MGG, volume 3, col. 858
  % ("Ducis"); Stefano Fabri, "Quam speciosa veteranis" (1611), in:
  % MGG, volume 3, col. 1698 ("Fabri"); Philippus Dulichius,
  % "Fasciculus novus ..."  (1598), in: MGG, volume 3, col. 919
  % ("Dulichius"), fig. 1; Noe Faignient, "Ic sal de Heer myn God
  % gebenedye" (1568), in: MGG, volume 3, col. 1735 ("Faignient").
enddef;


%
% FIXME: This clef is preliminarily mapped to the petrucci g clef
% until the code for the mensural g clef will be rewritten.
%
fet_beginchar ("mensural g clef", "mensural.g");
	if test = 1:
		draw_staff (-1, 3, 0.0);
	fi;
	draw_petrucci_g_clef ((0, 0), 1.0);
fet_endchar;


fet_beginchar ("mensural g clef", "mensural.g_change");
	draw_petrucci_g_clef ((0, 0), .8);
fet_endchar;



%%%%%%%%
%
%
%
% Hufnagel
%
%
%
def draw_hufnagel_do_clef (expr exact_center, reduction) =
	% inspired by Graduale of Friedrich Zollner (1442), in: MGG,
	% volume 9, col. 1413 ("Neustift"), fig. 1.

	save reduced_il;

	reduced_il# = staff_space# * reduction;

	define_pixels (reduced_il);

	set_char_box (0 - xpart exact_center,
		      1.10 reduced_il# + xpart exact_center,
		      0.70 reduced_il# - ypart exact_center,
		      0.75 reduced_il# + ypart exact_center);

	save xoffs, yoffs;

	xoffs# = xpart exact_center;
	yoffs# = ypart exact_center;

	define_pixels (xoffs, yoffs);

	save ellipse, pat, T;
	path ellipse, pat;
	transform T;

	T := identity xscaled 0.6 reduced_il
		      yscaled 0.1 reduced_il
		      rotated 40;
	pickup pencircle transformed T;
	ellipse := fullcircle transformed T;

	z1 = (xoffs + 0.90 reduced_il, yoffs + .45 reduced_il);
	z2 = (xoffs + 0.80 reduced_il, yoffs + .45 reduced_il);
	z3 = (xoffs + 0.50 reduced_il, yoffs + .60 reduced_il);
	z4 = (xoffs + 0.20 reduced_il, yoffs + .45 reduced_il);
	z5 = (xoffs + 0.20 reduced_il, yoffs - .45 reduced_il);
	z6 = (xoffs + 0.40 reduced_il, yoffs - .55 reduced_il);

	pat := z1
	       .. z2
	       .. z3
	       -- z4
	       -- z5
	       -- z6;

	fill get_subpath (ellipse,
			  -direction 0 of pat, direction 0 of pat, z1)
	     .. get_subpoint (ellipse, direction 1 of pat, z2)
	     .. get_subpath (ellipse,
			     direction (2 - epsilon) of pat, z4 - z3, z3)
	     -- get_subpath (ellipse,
			     z4 - z3, z5 - z4, z4)
	     -- get_subpath (ellipse,
			     z5 - z4, z6 - z5, z5)
	     -- get_subpath (ellipse,
			     z6 - z5, z5 - z6, z6)
	     -- get_subpoint (ellipse, z5 - z6, z5)
	     -- get_subpoint (ellipse, z4 - z5, z5)
	     -- get_subpoint (ellipse, z4 - z5, z4)
	     -- get_subpoint (ellipse, -direction (2 - epsilon) of pat, z3)
	     .. get_subpath (ellipse,
			     -direction 1 of pat, -direction 1 of pat, z2)
	     .. cycle;

	labels (1, 2, 3, 4, 5, 6);
enddef;


fet_beginchar ("Hufnagel do clef", "hufnagel.do");
	if test = 1:
		draw_staff (-1, 3, 0.0);
	fi;
	draw_hufnagel_do_clef ((0, 0), 1.0);
fet_endchar;


fet_beginchar ("Hufnagel do clef", "hufnagel.do_change");
	draw_hufnagel_do_clef ((0, 0), .8);
fet_endchar;


def draw_hufnagel_fa_clef (expr exact_center, reduction) =
	% inspired by Bamberger Manuscript (15th century), in:
	% MGG, volume 2, table 59.

	save reduced_il;

	reduced_il# = staff_space# * reduction;

	define_pixels (reduced_il);

	set_char_box (0 - xpart exact_center,
		      1.20 reduced_il# + xpart exact_center,
		      1.15 reduced_il# - ypart exact_center,
		      1.00 reduced_il# + ypart exact_center);

	save xoffs, yoffs;

	xoffs# = xpart exact_center;
	yoffs# = ypart exact_center;

	define_pixels (xoffs, yoffs);

	save ellipse, pat, T;
	path ellipse, pat;
	transform T;

	T := identity xscaled 0.6 reduced_il
		      yscaled 0.1 reduced_il
		      rotated 40;
	pickup pencircle transformed T;
	ellipse := fullcircle transformed T;

	z11 = (xoffs + 0.90 reduced_il, yoffs + 0.70 reduced_il);
	z12 = (xoffs + 0.80 reduced_il, yoffs + 0.70 reduced_il);
	z13 = (xoffs + 0.50 reduced_il, yoffs + 0.85 reduced_il);
	z14 = (xoffs + 0.20 reduced_il, yoffs + 0.70 reduced_il);
	z15 = (xoffs + 0.20 reduced_il, yoffs - 1.10 reduced_il);

	pat := z11
	       .. z12
	       .. z13
	       -- z14
	       -- z15;

	fill get_subpath (ellipse,
			  -direction 0 of pat, direction 0 of pat, z11)
	     .. get_subpoint (ellipse, direction 1 of pat, z12)
	     .. get_subpath (ellipse,
			     direction (2 - epsilon) of pat, z14 - z13, z13)
	     -- get_subpath (ellipse,
			     z14 - z13, z15 - z14, z14)
	     -- get_subpath (ellipse,
			     z15 - z14, z14 - z15, z15)
	     -- get_subpoint (ellipse, z14 - z15, z14)
	     -- get_subpoint (ellipse, -direction (2 - epsilon) of pat, z13)
	     .. get_subpath (ellipse,
			     -direction 1 of pat, -direction 1 of pat, z12)
	     .. cycle;

	z16 = (xoffs + 0.90 reduced_il, yoffs - 0.05 reduced_il);
	z17 = (xoffs + 0.80 reduced_il, yoffs - 0.05 reduced_il);
	z18 = (xoffs + 0.50 reduced_il, yoffs + 0.10 reduced_il);
	z19 = (xoffs + 0.20 reduced_il, yoffs - 0.05 reduced_il);

	pat := z16
	       .. z17
	       .. z18
	       -- z19;

	fill get_subpath (ellipse,
			  -direction 0 of pat, direction 0 of pat, z16)
	     .. get_subpoint (ellipse, direction 1 of pat, z17)
	     .. get_subpath (ellipse,
			     direction (2 - epsilon) of pat, z19 - z18, z18)
	     -- get_subpoint (ellipse, z19 - z18, z19)
	     -- get_subpoint (ellipse, -direction (2 - epsilon) of pat, z18)
	     .. get_subpoint (ellipse, -direction 1 of pat, z17)
	     .. cycle;

	labels (11, 12, 13, 14, 15, 16, 17, 18, 19);
enddef;


fet_beginchar ("Hufnagel fa clef", "hufnagel.fa");
	if test = 1:
		draw_staff (-1, 3, 0.0);
	fi;
	draw_hufnagel_fa_clef ((0, 0), 1.0);
fet_endchar;


fet_beginchar ("Hufnagel fa clef", "hufnagel.fa_change");
	draw_hufnagel_fa_clef ((0, 0), .8);
fet_endchar;


def draw_hufnagel_do_fa_clef (expr exact_center, reduction) =
	draw_hufnagel_do_clef (exact_center, reduction);
	draw_hufnagel_fa_clef (exact_center + (0, -2 staff_space#), reduction);

	set_char_box (0 - xpart exact_center,
		      1.20 reduced_il# + xpart exact_center,
		      1.15 reduced_il# + 2 staff_space# - ypart exact_center,
		      0.75 reduced_il# + ypart exact_center);
enddef;


fet_beginchar ("Hufnagel do/fa clef", "hufnagel.do.fa");
	if test = 1:
		draw_staff (-1, 3, 0.0);
	fi;
	draw_hufnagel_do_fa_clef ((0, 0), 1.0);
fet_endchar;


fet_beginchar ("Hufnagel do/fa clef", "hufnagel.do.fa_change");
	draw_hufnagel_do_fa_clef ((0, 0), .8);
fet_endchar;


fet_endgroup ("clefs");