2 mensural-ligature.cc -- implement Mensural_ligature
4 source file of the GNU LilyPond music typesetter
6 (c) 2002--2004 Juergen Reuter <reuter@ipd.uka.de>
9 #include "mensural-ligature.hh"
14 #include "font-interface.hh"
16 #include "staff-symbol-referencer.hh"
17 #include "note-head.hh"
18 #include "output-def.hh"
22 * TODO: divide this function into mensural and neo-mensural style.
24 * TODO: move this function to class Lookup?
33 Direction cauda_direction)
35 Real staff_space = Staff_symbol_referencer::staff_space (me);
36 Real height = 0.6 * staff_space;
41 bool consider_interval =
42 cauda_direction * interval > 0.0;
44 Interval cauda_box_x (0, thickness);
47 if (consider_interval)
49 Real y_length = max (interval/2.0*staff_space, 1.2*staff_space);
50 cauda_box_y = Interval (0, y_length);
53 cauda_box_y = Interval (0, staff_space);
56 (cauda_direction == UP) ?
58 -0.5*height - cauda_box_y.length ();
60 Box cauda_box (cauda_box_x, cauda_box_y);
61 Stencil cauda = Lookup::filled_box (cauda_box);
62 cauda.translate_axis (y_correction, Y_AXIS);
63 stencil.add_stencil (cauda);
66 Real slope = (interval / 2.0 * staff_space) / width;
68 // Compensate optical illusion regarding vertical position of left
69 // and right endings due to slope.
70 Real ypos_correction = -0.1*staff_space * sign (slope);
71 Real slope_correction = 0.2*staff_space * sign (slope);
72 Real corrected_slope = slope + slope_correction/width;
77 Lookup::beam (corrected_slope, width, height, 0.0);
78 stencil.add_stencil (solid_head);
83 Lookup::beam (corrected_slope, thickness, height, 0.0);
84 stencil.add_stencil (left_edge);
87 Lookup::beam (corrected_slope, thickness, height, 0.0);
88 right_edge.translate_axis (width-thickness, X_AXIS);
89 right_edge.translate_axis (corrected_slope * (width-thickness), Y_AXIS);
90 stencil.add_stencil (right_edge);
93 Lookup::beam (corrected_slope, width, thickness, 0.0);
94 bottom_edge.translate_axis (-0.5*height, Y_AXIS);
95 stencil.add_stencil (bottom_edge);
98 Lookup::beam (corrected_slope, width, thickness, 0.0);
99 top_edge.translate_axis (+0.5*height, Y_AXIS);
100 stencil.add_stencil (top_edge);
102 stencil.translate_axis (ypos_correction, Y_AXIS);
107 internal_brew_primitive (Grob *me)
109 SCM primitive_scm = me->get_property ("primitive");
110 if (primitive_scm == SCM_EOL)
112 programming_error ("Mensural_ligature:"
113 "undefined primitive -> ignoring grob");
118 int primitive = scm_to_int (primitive_scm);
120 Real thickness = 0.0;
121 Real flexa_width = 0.0;
122 Real staff_space = Staff_symbol_referencer::staff_space (me);
123 if (primitive & MLP_ANY)
125 thickness = robust_scm2double ( me->get_property ("thickness"), .14);
128 if (primitive & MLP_FLEXA)
130 delta_pitch = robust_scm2int (me->get_property ("delta-pitch"),
133 flexa_width = robust_scm2double (me->get_property ("flexa-width"), 2.0 * staff_space);
141 out = brew_flexa (me, delta_pitch, false,
142 flexa_width, thickness, true, DOWN);
144 case MLP_sc: // mensural brevis head with right cauda
145 out = Font_interface::get_default_font (me)->find_by_name ("noteheads.-2mensural");
147 case MLP_ss: // mensural brevis head
148 out = Font_interface::get_default_font (me)->find_by_name ("noteheads.-1mensural");
150 case MLP_cs: // mensural brevis head with left cauda
151 out = Font_interface::get_default_font (me)->find_by_name ("noteheads.lmensural");
154 out = brew_flexa (me, delta_pitch, false,
155 flexa_width, thickness, true, UP);
158 out = brew_flexa (me, delta_pitch, false,
159 flexa_width, thickness, false, CENTER);
162 programming_error (_f ("Mensural_ligature:"
163 "unexpected case fall-through"));
167 SCM join_left_scm = me->get_property ("join-left-amount");
168 if (join_left_scm != SCM_EOL)
170 int join_left = scm_to_int (join_left_scm);
172 programming_error (_f ("Mensural_ligature: (join_left == 0)"));
173 Real blotdiameter = (me->get_layout ()->get_dimension (ly_symbol2scm ("blotdiameter")));
174 Interval x_extent = Interval (0, thickness);
175 Interval y_extent = (join_left > 0) ?
176 Interval (-join_left * 0.5 * staff_space, 0) :
177 Interval (0, -join_left * 0.5 * staff_space);
178 Box join_box (x_extent, y_extent);
180 Stencil join = Lookup::round_filled_box (join_box, blotdiameter);
181 out.add_stencil (join);
184 int pos = Staff_symbol_referencer::get_rounded_position (me);
185 if (primitive & MLP_FLEXA)
193 MAKE_SCHEME_CALLBACK (Mensural_ligature, brew_ligature_primitive, 1);
195 Mensural_ligature::brew_ligature_primitive (SCM smob)
197 Grob *me = unsmob_grob (smob);
198 return internal_brew_primitive (me).smobbed_copy ();
201 MAKE_SCHEME_CALLBACK (Mensural_ligature, print, 1);
203 Mensural_ligature::print (SCM)
208 ADD_INTERFACE (Mensural_ligature, "mensural-ligature-interface",
209 "A mensural ligature",
210 "delta-pitch flexa-width head-width join-left join-left-amount "
211 "ligature-primitive-callback primitive thickness");