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>
11 #include "mensural-ligature.hh"
13 #include "font-interface.hh"
15 #include "staff-symbol-referencer.hh"
16 #include "note-head.hh"
17 #include "output-def.hh"
21 * TODO: divide this function into mensural and neo-mensural style.
23 * TODO: move this function to class Lookup?
30 Real vertical_line_thickness)
32 Real staff_space = Staff_symbol_referencer::staff_space (me);
33 Real slope = (interval / 2.0 * staff_space) / width;
35 // Compensate optical illusion regarding vertical position of left
36 // and right endings due to slope.
37 Real ypos_correction = -0.1 * staff_space * sign (slope);
38 Real slope_correction = 0.2 * staff_space * sign (slope);
39 Real corrected_slope = slope + slope_correction / width;
42 if (solid) // colorated flexae
45 = Lookup::beam (corrected_slope, width, staff_space, 0.0);
46 stencil.add_stencil (solid_head);
51 The thickness of the horizontal lines of the flexa shape
52 should be equal to that of the horizontal lines of the
53 neomensural brevis note head (see mf/parmesan-heads.mf).
55 Real const horizontal_line_thickness = staff_space * 0.35;
57 // URGH! vertical_line_thickness is adjustable (via thickness
58 // property), while horizontal_line_thickness is constant.
59 // Maybe both should be adjustable independently?
61 Real height = staff_space - horizontal_line_thickness;
64 = Lookup::beam (corrected_slope, vertical_line_thickness, height, 0.0);
65 stencil.add_stencil (left_edge);
68 = Lookup::beam (corrected_slope, vertical_line_thickness, height, 0.0);
69 right_edge.translate_axis (width - vertical_line_thickness, X_AXIS);
70 right_edge.translate_axis ((width - vertical_line_thickness) *
71 corrected_slope, Y_AXIS);
72 stencil.add_stencil (right_edge);
75 = Lookup::beam (corrected_slope, width,
76 horizontal_line_thickness, 0.0);
77 bottom_edge.translate_axis (-0.5 * height, Y_AXIS);
78 stencil.add_stencil (bottom_edge);
81 = Lookup::beam (corrected_slope, width,
82 horizontal_line_thickness, 0.0);
83 top_edge.translate_axis (+0.5 * height, Y_AXIS);
84 stencil.add_stencil (top_edge);
86 stencil.translate_axis (ypos_correction, Y_AXIS);
91 internal_brew_primitive (Grob *me)
93 SCM primitive_scm = me->get_property ("primitive");
94 if (primitive_scm == SCM_EOL)
96 programming_error ("Mensural_ligature: "
97 "undefined primitive -> ignoring grob");
100 int primitive = scm_to_int (primitive_scm);
104 Real thickness = 0.0;
106 Real staff_space = Staff_symbol_referencer::staff_space (me);
107 if (primitive & MLP_ANY)
108 thickness = robust_scm2double (me->get_property ("thickness"), .14);
110 if (primitive & MLP_FLEXA)
112 delta_pitch = robust_scm2int (me->get_property ("delta-pitch"),
115 = robust_scm2double (me->get_property ("flexa-width"), 2.0 * staff_space);
117 if (primitive & MLP_SINGLE_HEAD)
118 width = robust_scm2double (me->get_property ("head-width"), staff_space);
120 switch (primitive & MLP_ANY)
124 case MLP_LONGA: // mensural brevis head with right cauda
125 out = Font_interface::get_default_font (me)->find_by_name
126 ("noteheads.s-2mensural");
128 case MLP_BREVIS: // mensural brevis head
129 out = Font_interface::get_default_font (me)->find_by_name
130 ("noteheads.s-1mensural");
132 case MLP_MAXIMA: // should be mensural maxima head without stem
133 out = Font_interface::get_default_font (me)->find_by_name
134 ("noteheads.s-1neomensural");
137 out = brew_flexa (me, delta_pitch, false, width, thickness);
140 programming_error (_f ("Mensural_ligature: "
141 "unexpected case fall-through"));
146 = (me->get_layout ()->get_dimension (ly_symbol2scm ("blotdiameter")));
148 if (primitive & MLP_STEM)
151 Real y_bottom = 0.0, y_top = 3.0 * staff_space;
153 if (primitive & MLP_DOWN)
159 Interval x_extent (0, thickness);
160 Interval y_extent (y_bottom, y_top);
161 Box join_box (x_extent, y_extent);
163 Stencil join = Lookup::round_filled_box (join_box, blotdiameter);
164 out.add_stencil (join);
167 SCM join_right_scm = me->get_property ("join-right-amount");
169 if (join_right_scm != SCM_EOL)
171 int join_right = scm_to_int (join_right_scm);
174 Real y_top = join_right * 0.5 * staff_space;
183 Interval x_extent (width - thickness, width);
184 Interval y_extent (y_bottom, y_top);
185 Box join_box (x_extent, y_extent);
186 Stencil join = Lookup::round_filled_box (join_box, blotdiameter);
188 out.add_stencil (join);
191 programming_error (_f ("Mensural_ligature: (join_right == 0)"));
194 #if 0 /* what happend with the ledger lines? */
195 int pos = Staff_symbol_referencer::get_rounded_position (me);
196 if (primitive & MLP_FLEXA)
199 add_ledger_lines (me, &out, pos, 0.5 * delta_pitch, ledger_take_space);
206 MAKE_SCHEME_CALLBACK (Mensural_ligature, brew_ligature_primitive, 1);
208 Mensural_ligature::brew_ligature_primitive (SCM smob)
210 Grob *me = unsmob_grob (smob);
211 return internal_brew_primitive (me).smobbed_copy ();
214 MAKE_SCHEME_CALLBACK (Mensural_ligature, print, 1);
216 Mensural_ligature::print (SCM)
221 ADD_INTERFACE (Mensural_ligature, "mensural-ligature-interface",
222 "A mensural ligature",
223 "delta-pitch flexa-width head-width join-right-amount " // "add-join "
224 "primitive thickness");