2 mensural-ligature.cc -- implement Mensural_ligature
4 source file of the GNU LilyPond music typesetter
6 (c) 2002--2003 Juergen Reuter <reuter@ipd.uka.de>
11 #include "mensural-ligature.hh"
12 #include "font-interface.hh"
13 #include "molecule.hh"
15 #include "staff-symbol-referencer.hh"
16 #include "note-head.hh"
17 #include "paper-def.hh"
21 * TODO: divide this function into mensural and neo-mensural style.
23 * TODO: move this function to class Lookup?
32 Direction stem_direction)
34 Real staff_space = Staff_symbol_referencer::staff_space (me);
35 Real height = 0.6 * staff_space;
36 Molecule molecule = Molecule ();
40 bool consider_interval =
41 stem_direction * interval > 0.0;
43 Interval stem_box_x (0, thickness);
46 if (consider_interval)
48 Real y_length = max (interval/2.0*staff_space, 1.2*staff_space);
49 stem_box_y = Interval (0, y_length);
52 stem_box_y = Interval (0, staff_space);
55 (stem_direction == UP) ?
57 -0.5*height - stem_box_y.length();
59 Box stem_box (stem_box_x, stem_box_y);
60 Molecule stem = Lookup::filledbox (stem_box);
61 stem.translate_axis (y_correction, Y_AXIS);
62 molecule.add_molecule(stem);
65 Real slope = (interval / 2.0 * staff_space) / width;
67 // Compensate optical illusion regarding vertical position of left
68 // and right endings due to slope.
69 Real ypos_correction = -0.1*staff_space * sign(slope);
70 Real slope_correction = 0.2*staff_space * sign(slope);
71 Real corrected_slope = slope + slope_correction/width;
76 Lookup::horizontal_slope (width, corrected_slope, height);
77 molecule.add_molecule (solid_head);
82 Lookup::horizontal_slope (thickness, corrected_slope, height);
83 molecule.add_molecule(left_edge);
86 Lookup::horizontal_slope (thickness, corrected_slope, height);
87 right_edge.translate_axis (width-thickness, X_AXIS);
88 right_edge.translate_axis (corrected_slope * (width-thickness), Y_AXIS);
89 molecule.add_molecule(right_edge);
91 Molecule bottom_edge =
92 Lookup::horizontal_slope (width, corrected_slope, thickness);
93 bottom_edge.translate_axis (-0.5*height, Y_AXIS);
94 molecule.add_molecule (bottom_edge);
97 Lookup::horizontal_slope (width, corrected_slope, thickness);
98 top_edge.translate_axis (+0.5*height, Y_AXIS);
99 molecule.add_molecule (top_edge);
101 molecule.translate_axis (ypos_correction, Y_AXIS);
106 add_ledger_lines (Grob *me, Molecule *out, int pos, Real offs,
107 bool ledger_take_space)
109 int interspaces = Staff_symbol_referencer::line_count (me)-1;
110 if (abs (pos) - interspaces > 1)
112 Interval hd = out->extent (X_AXIS);
113 Real left_ledger_protusion = hd.length ()/4;
114 Real right_ledger_protusion = left_ledger_protusion;
116 Interval l_extents = Interval (hd[LEFT] - left_ledger_protusion,
117 hd[RIGHT] + right_ledger_protusion);
118 Molecule ledger_lines =
119 Note_head::brew_ledger_lines (me, pos, interspaces,
122 ledger_lines.translate_axis (offs, Y_AXIS);
123 out->add_molecule (ledger_lines);
128 internal_brew_primitive (Grob *me, bool ledger_take_space)
130 SCM primitive_scm = me->get_grob_property ("primitive");
131 if (primitive_scm == SCM_EOL)
133 programming_error ("Mensural_ligature:"
134 "undefined primitive -> ignoring grob");
139 int primitive = gh_scm2int (primitive_scm);
141 Real thickness = 0.0;
142 Real flexa_width = 0.0;
143 Real staff_space = Staff_symbol_referencer::staff_space (me);
144 if (primitive & MLP_ANY)
146 SCM thickness_scm = me->get_grob_property ("thickness");
147 if (thickness_scm != SCM_EOL)
149 thickness = gh_scm2double (thickness_scm);
153 programming_error (_f ("Mensural_ligature:"
154 "thickness undefined on flexa %d; assuming 1.4",
156 thickness = 1.4 * me->get_paper ()->get_var ("linethickness");
160 if (primitive & MLP_FLEXA)
162 SCM delta_pitch_scm = me->get_grob_property ("delta-pitch");
163 if (delta_pitch_scm != SCM_EOL)
165 delta_pitch = gh_scm2int (delta_pitch_scm);
169 programming_error (_f ("Mensural_ligature:"
170 "delta-pitch undefined on flexa %d; assuming 0",
175 SCM flexa_width_scm = me->get_grob_property ("flexa-width");
176 if (flexa_width_scm != SCM_EOL)
178 flexa_width = gh_scm2double (flexa_width_scm);
182 programming_error (_f ("Mensural_ligature:"
183 "flexa-width undefined on flexa %d; assuming 2.0",
185 flexa_width = 2.0 * staff_space;
194 out = brew_flexa (me, delta_pitch, false,
195 flexa_width, thickness, true, DOWN);
198 out = Font_interface::get_default_font (me)->find_by_name ("noteheads--2mensural");
201 out = Font_interface::get_default_font (me)->find_by_name ("noteheads--1mensural");
204 out = Font_interface::get_default_font (me)->find_by_name ("noteheads-lmensural");
207 out = brew_flexa (me, delta_pitch, false,
208 flexa_width, thickness, true, UP);
211 out = brew_flexa (me, delta_pitch, false,
212 flexa_width, thickness, false, CENTER);
215 programming_error (_f ("Mensural_ligature:"
216 "unexpected case fall-through"));
220 SCM join_left_scm = me->get_grob_property ("join-left-amount");
221 if (join_left_scm != SCM_EOL)
223 int join_left = gh_scm2int (join_left_scm);
225 programming_error (_f ("Mensural_ligature: (join_left == 0)"));
226 Real blotdiameter = (me->get_paper ()->get_var ("blotdiameter"));
227 Interval x_extent = Interval (0, thickness);
228 Interval y_extent = (join_left > 0) ?
229 Interval (-join_left * 0.5 * staff_space, 0) :
230 Interval (0, -join_left * 0.5 * staff_space);
231 Box stem_box (x_extent, y_extent);
233 Molecule stem = Lookup::roundfilledbox (stem_box, blotdiameter);
234 out.add_molecule (stem);
237 int pos = (int)rint (Staff_symbol_referencer::get_position (me));
238 add_ledger_lines(me, &out, pos, 0, ledger_take_space);
239 if (primitive & MLP_FLEXA)
242 add_ledger_lines(me, &out, pos, 0.5*delta_pitch, ledger_take_space);
248 MAKE_SCHEME_CALLBACK (Mensural_ligature, brew_ligature_primitive, 1);
250 Mensural_ligature::brew_ligature_primitive (SCM smob)
252 Grob *me = unsmob_grob (smob);
253 return internal_brew_primitive (me, false).smobbed_copy ();
256 MAKE_SCHEME_CALLBACK (Mensural_ligature, brew_molecule, 1);
258 Mensural_ligature::brew_molecule (SCM)
263 ADD_INTERFACE (Mensural_ligature, "mensural-ligature-interface",
264 "A mensural ligature",
265 "delta-pitch flexa-width head-width join-left "
266 "ligature-primitive-callback primitive thickness");