2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2002--2011 Juergen Reuter <reuter@ipd.uka.de>,
5 Pal Benko <benkop@freestart.hu>
7 LilyPond is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 LilyPond is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
21 #include "mensural-ligature.hh"
23 #include "directional-element-interface.hh"
24 #include "font-interface.hh"
25 #include "international.hh"
28 #include "note-head.hh"
29 #include "output-def.hh"
30 #include "staff-symbol-referencer.hh"
34 draws one half a flexa, i.e. a portion corresponding to a single note.
35 this way coloration of the two notes building up the flexa can be
36 handled independently.
38 * TODO: divide this function into mensural and neo-mensural style.
40 * TODO: move this function to class Lookup?
49 Real staff_space = Staff_symbol_referencer::staff_space (me);
52 The thickness of the horizontal lines of the flexa shape
53 should be equal to that of the horizontal lines of the
54 neomensural brevis note head (see mf/parmesan-heads.mf).
56 Real const horizontal_line_thickness = staff_space * 0.35;
58 // URGH! vertical_line_thickness is adjustable (via thickness
59 // property), while horizontal_line_thickness is constant.
60 // Maybe both should be adjustable independently?
62 Real height = staff_space - horizontal_line_thickness;
65 = robust_scm2double (me->get_property ("flexa-interval"), 0.0);
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;
74 if (solid) // colorated flexae
76 stencil = Lookup::beam (corrected_slope, width * 0.5, staff_space, 0.0);
80 stencil = Lookup::beam (corrected_slope, thickness, height, 0.0);
83 stencil.translate_axis (width * 0.5 - thickness, X_AXIS);
84 stencil.translate_axis (corrected_slope * (width * 0.5 - thickness),
89 = Lookup::beam (corrected_slope, width * 0.5, horizontal_line_thickness,
91 bottom_edge.translate_axis (-0.5 * height, Y_AXIS);
92 stencil.add_stencil (bottom_edge);
95 = Lookup::beam (corrected_slope, width * 0.5, horizontal_line_thickness,
97 top_edge.translate_axis (+0.5 * height, Y_AXIS);
98 stencil.add_stencil (top_edge);
102 stencil.translate_axis (ypos_correction, Y_AXIS);
105 stencil.translate_axis (0.5 * thickness, X_AXIS);
107 stencil.translate_axis (interval / -4.0 * staff_space, Y_AXIS);
114 internal_brew_primitive (Grob *me)
116 SCM primitive_scm = me->get_property ("primitive");
117 if (primitive_scm == SCM_EOL)
119 programming_error ("Mensural_ligature:"
120 " undefined primitive -> ignoring grob");
121 return Lookup::blank (Box (Interval (0, 0), Interval (0, 0)));
123 int primitive = scm_to_int (primitive_scm);
125 Real thickness = 0.0;
127 Real flexa_width = 0.0;
128 Real staff_space = Staff_symbol_referencer::staff_space (me);
130 SCM style = me->get_property ("style");
132 = scm_is_eq (style, ly_symbol2scm ("blackpetrucci"));
134 = scm_is_eq (style, ly_symbol2scm ("semipetrucci"));
136 if (primitive & MLP_ANY)
138 thickness = robust_scm2double (me->get_property ("thickness"), .13);
139 width = robust_scm2double (me->get_property ("head-width"), staff_space);
141 if (primitive & MLP_FLEXA)
142 flexa_width = robust_scm2double (me->get_property ("flexa-width"), 2.0)
146 int const note_shape = primitive & MLP_ANY;
147 int duration_log = 0;
148 Font_metric *fm = Font_interface::get_default_font (me);
149 string prefix = "noteheads.";
161 return Lookup::blank (Box (Interval (0, 0), Interval (0, 0)));
168 suffix = to_string (duration_log) + color
169 + (duration_log == -3 ? "lig" : "") + "mensural";
170 index = prefix + "s";
171 out = fm->find_by_name (index + suffix);
173 index = prefix + "d";
174 out = fm->find_by_name (index + "r" + suffix);
176 && !Staff_symbol_referencer::on_line
178 robust_scm2int (me->get_property ("staff-position"), 0)))
180 out = fm->find_by_name (index + suffix);
182 case MLP_FLEXA_BEGIN:
184 out = brew_flexa (me, black, flexa_width, thickness,
185 note_shape == MLP_FLEXA_BEGIN);
188 programming_error ("Mensural_ligature:"
189 " unexpected case fall-through");
190 return Lookup::blank (Box (Interval (0, 0), Interval (0, 0)));
194 = (me->layout ()->get_dimension (ly_symbol2scm ("blot-diameter")));
196 if (primitive & MLP_STEM)
199 Real y_bottom = 0.5 * staff_space, y_top = 2.5 * staff_space;
201 if (primitive & MLP_DOWN)
204 y_top = -0.5 * staff_space;
207 Interval x_extent (0, thickness);
208 Interval y_extent (y_bottom, y_top);
209 Box join_box (x_extent, y_extent);
211 Stencil join = Lookup::round_filled_box (join_box, blotdiameter);
212 out.add_stencil (join);
215 if (to_boolean (me->get_property ("add-join")))
217 int join_right = scm_to_int (me->get_property ("delta-position"));
220 Real y_top = join_right * 0.5 * staff_space;
229 if the previous note is longa-shaped,
230 the joining line may hide the stem, so made it longer
231 to serve as stem as well
233 if (primitive & MLP_LONGA)
235 instead of 3.0 the length of a longa stem should be used
236 Font_interface::get_default_font (???)->find_by_name
237 ("noteheads.s-2mensural").extent (Y_AXIS).length () * 0.5
239 y_bottom -= 2.5 * staff_space;
242 Interval x_extent (width - thickness, width);
243 Interval y_extent (y_bottom, y_top);
244 Box join_box (x_extent, y_extent);
245 Stencil join = Lookup::round_filled_box (join_box, blotdiameter);
247 out.add_stencil (join);
250 programming_error ("Mensural_ligature: (join_right == 0)");
253 #if 0 /* what happend with the ledger lines? */
254 int pos = Staff_symbol_referencer::get_rounded_position (me);
255 if (primitive & MLP_FLEXA)
258 add_ledger_lines (me, &out, pos, 0.5 * delta_pitch, ledger_take_space);
265 MAKE_SCHEME_CALLBACK (Mensural_ligature, brew_ligature_primitive, 1);
267 Mensural_ligature::brew_ligature_primitive (SCM smob)
269 Grob *me = unsmob_grob (smob);
270 return internal_brew_primitive (me).smobbed_copy ();
273 MAKE_SCHEME_CALLBACK (Mensural_ligature, print, 1);
275 Mensural_ligature::print (SCM)
280 ADD_INTERFACE (Mensural_ligature,
281 "A mensural ligature.",