2 mensural-ligature.cc -- implement Mensural_ligature
4 source file of the GNU LilyPond music typesetter
6 (c) 2002--2005 Juergen Reuter <reuter@ipd.uka.de>,
7 Pal Benko <benkop@freestart.hu>
13 #include "mensural-ligature.hh"
15 #include "font-interface.hh"
17 #include "staff-symbol-referencer.hh"
18 #include "note-head.hh"
19 #include "output-def.hh"
23 * TODO: divide this function into mensural and neo-mensural style.
25 * TODO: move this function to class Lookup?
32 Real vertical_line_thickness)
34 Real staff_space = Staff_symbol_referencer::staff_space (me);
35 Real slope = (interval / 2.0 * staff_space) / width;
37 // Compensate optical illusion regarding vertical position of left
38 // and right endings due to slope.
39 Real ypos_correction = -0.1 * staff_space * sign (slope);
40 Real slope_correction = 0.2 * staff_space * sign (slope);
41 Real corrected_slope = slope + slope_correction / width;
44 if (solid) // colorated flexae
47 = Lookup::beam (corrected_slope, width, staff_space, 0.0);
48 stencil.add_stencil (solid_head);
53 The thickness of the horizontal lines of the flexa shape
54 should be equal to that of the horizontal lines of the
55 neomensural brevis note head (see mf/parmesan-heads.mf).
57 Real const horizontal_line_thickness = staff_space * 0.35;
59 // URGH! vertical_line_thickness is adjustable (via thickness
60 // property), while horizontal_line_thickness is constant.
61 // Maybe both should be adjustable independently?
63 Real height = staff_space - horizontal_line_thickness;
66 = Lookup::beam (corrected_slope, vertical_line_thickness, height, 0.0);
67 stencil.add_stencil (left_edge);
70 = Lookup::beam (corrected_slope, vertical_line_thickness, height, 0.0);
71 right_edge.translate_axis (width - vertical_line_thickness, X_AXIS);
72 right_edge.translate_axis ((width - vertical_line_thickness) *
73 corrected_slope, Y_AXIS);
74 stencil.add_stencil (right_edge);
77 = Lookup::beam (corrected_slope, width,
78 horizontal_line_thickness, 0.0);
79 bottom_edge.translate_axis (-0.5 * height, Y_AXIS);
80 stencil.add_stencil (bottom_edge);
83 = Lookup::beam (corrected_slope, width,
84 horizontal_line_thickness, 0.0);
85 top_edge.translate_axis (+0.5 * height, Y_AXIS);
86 stencil.add_stencil (top_edge);
88 stencil.translate_axis (ypos_correction, Y_AXIS);
93 internal_brew_primitive (Grob *me)
95 SCM primitive_scm = me->get_property ("primitive");
96 if (primitive_scm == SCM_EOL)
98 programming_error ("Mensural_ligature: "
99 "undefined primitive -> ignoring grob");
102 int primitive = scm_to_int (primitive_scm);
106 Real thickness = 0.0;
108 Real staff_space = Staff_symbol_referencer::staff_space (me);
109 if (primitive & MLP_ANY)
110 thickness = robust_scm2double (me->get_property ("thickness"), .14);
112 if (primitive & MLP_FLEXA)
114 delta_pitch = robust_scm2int (me->get_property ("delta-pitch"),
117 = robust_scm2double (me->get_property ("flexa-width"), 2.0 * staff_space);
119 if (primitive & MLP_SINGLE_HEAD)
120 width = robust_scm2double (me->get_property ("head-width"), staff_space);
122 switch (primitive & MLP_ANY)
126 case MLP_LONGA: // mensural brevis head with right cauda
127 out = Font_interface::get_default_font (me)->find_by_name
128 ("noteheads.s-2mensural");
130 case MLP_BREVIS: // mensural brevis head
131 out = Font_interface::get_default_font (me)->find_by_name
132 ("noteheads.s-1mensural");
134 case MLP_MAXIMA: // should be mensural maxima head without stem
135 out = Font_interface::get_default_font (me)->find_by_name
136 ("noteheads.s-1neomensural");
139 out = brew_flexa (me, delta_pitch, false, width, thickness);
142 programming_error (_f ("Mensural_ligature: "
143 "unexpected case fall-through"));
148 = (me->get_layout ()->get_dimension (ly_symbol2scm ("blotdiameter")));
150 if (primitive & MLP_STEM)
153 Real y_bottom = 0.0, y_top = 3.0 * staff_space;
155 if (primitive & MLP_DOWN)
161 Interval x_extent (0, thickness);
162 Interval y_extent (y_bottom, y_top);
163 Box join_box (x_extent, y_extent);
165 Stencil join = Lookup::round_filled_box (join_box, blotdiameter);
166 out.add_stencil (join);
169 SCM join_right_scm = me->get_property ("join-right-amount");
171 if (join_right_scm != SCM_EOL)
173 int join_right = scm_to_int (join_right_scm);
176 Real y_top = join_right * 0.5 * staff_space;
185 Interval x_extent (width - thickness, width);
186 Interval y_extent (y_bottom, y_top);
187 Box join_box (x_extent, y_extent);
188 Stencil join = Lookup::round_filled_box (join_box, blotdiameter);
190 out.add_stencil (join);
193 programming_error (_f ("Mensural_ligature: (join_right == 0)"));
196 #if 0 /* what happend with the ledger lines? */
197 int pos = Staff_symbol_referencer::get_rounded_position (me);
198 if (primitive & MLP_FLEXA)
201 add_ledger_lines (me, &out, pos, 0.5 * delta_pitch, ledger_take_space);
208 MAKE_SCHEME_CALLBACK (Mensural_ligature, brew_ligature_primitive, 1);
210 Mensural_ligature::brew_ligature_primitive (SCM smob)
212 Grob *me = unsmob_grob (smob);
213 return internal_brew_primitive (me).smobbed_copy ();
216 MAKE_SCHEME_CALLBACK (Mensural_ligature, print, 1);
218 Mensural_ligature::print (SCM)
223 ADD_INTERFACE (Mensural_ligature, "mensural-ligature-interface",
224 "A mensural ligature",
225 "delta-pitch flexa-width head-width join-right-amount " // "add-join "
226 "ligature-primitive-callback primitive thickness");