]> git.donarmstrong.com Git - lilypond.git/blob - lily/mensural-ligature.cc
* lily/tie-column.cc (set_manual_tie_configuration): new function.
[lilypond.git] / lily / mensural-ligature.cc
1 /*
2   mensural-ligature.cc -- implement Mensural_ligature
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2002--2005 Juergen Reuter <reuter@ipd.uka.de>,
7   Pal Benko <benkop@freestart.hu>
8 */
9
10 #include <cmath>
11 using namespace std;
12
13 #include "mensural-ligature.hh"
14 #include "item.hh"
15 #include "font-interface.hh"
16 #include "lookup.hh"
17 #include "staff-symbol-referencer.hh"
18 #include "note-head.hh"
19 #include "output-def.hh"
20 #include "warn.hh"
21
22 /*
23  * TODO: divide this function into mensural and neo-mensural style.
24  *
25  * TODO: move this function to class Lookup?
26  */
27 Stencil
28 brew_flexa (Grob *me,
29             Real interval,
30             bool solid,
31             Real width,
32             Real vertical_line_thickness)
33 {
34   Real staff_space = Staff_symbol_referencer::staff_space (me);
35   Real slope = (interval / 2.0 * staff_space) / width;
36
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;
42
43   Stencil stencil;
44   if (solid) // colorated flexae
45     {
46       Stencil solid_head
47         = Lookup::beam (corrected_slope, width, staff_space, 0.0);
48       stencil.add_stencil (solid_head);
49     }
50   else // outline
51     {
52       /*
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).
56       */
57       Real const horizontal_line_thickness = staff_space * 0.35;
58
59       // URGH!  vertical_line_thickness is adjustable (via thickness
60       // property), while horizontal_line_thickness is constant.
61       // Maybe both should be adjustable independently?
62
63       Real height = staff_space - horizontal_line_thickness;
64
65       Stencil left_edge
66         = Lookup::beam (corrected_slope, vertical_line_thickness, height, 0.0);
67       stencil.add_stencil (left_edge);
68
69       Stencil right_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);
75
76       Stencil bottom_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);
81
82       Stencil top_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);
87     }
88   stencil.translate_axis (ypos_correction, Y_AXIS);
89   return stencil;
90 }
91
92 Stencil
93 internal_brew_primitive (Grob *me)
94 {
95   SCM primitive_scm = me->get_property ("primitive");
96   if (primitive_scm == SCM_EOL)
97     {
98       programming_error ("Mensural_ligature: "
99                          "undefined primitive -> ignoring grob");
100       return Stencil ();
101     }
102   int primitive = scm_to_int (primitive_scm);
103
104   Stencil out;
105   int delta_pitch = 0;
106   Real thickness = 0.0;
107   Real width = 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);
111
112   if (primitive & MLP_FLEXA)
113     {
114       delta_pitch = robust_scm2int (me->get_property ("delta-pitch"),
115                                     0);
116       width
117         = robust_scm2double (me->get_property ("flexa-width"), 2.0 * staff_space);
118     }
119   if (primitive & MLP_SINGLE_HEAD)
120     width = robust_scm2double (me->get_property ("head-width"), staff_space);
121
122   switch (primitive & MLP_ANY)
123     {
124     case MLP_NONE:
125       return Stencil ();
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");
129       break;
130     case MLP_BREVIS: // mensural brevis head
131       out = Font_interface::get_default_font (me)->find_by_name
132         ("noteheads.s-1mensural");
133       break;
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");
137       break;
138     case MLP_FLEXA:
139       out = brew_flexa (me, delta_pitch, false, width, thickness);
140       break;
141     default:
142       programming_error (_f ("Mensural_ligature: "
143                              "unexpected case fall-through"));
144       return Stencil ();
145     }
146
147   Real blotdiameter
148     = (me->get_layout ()->get_dimension (ly_symbol2scm ("blotdiameter")));
149
150   if (primitive & MLP_STEM)
151     {
152       // assume MLP_UP
153       Real y_bottom = 0.0, y_top = 3.0 * staff_space;
154
155       if (primitive & MLP_DOWN)
156         {
157           y_bottom = -y_top;
158           y_top = 0.0;
159         }
160
161       Interval x_extent (0, thickness);
162       Interval y_extent (y_bottom, y_top);
163       Box join_box (x_extent, y_extent);
164
165       Stencil join = Lookup::round_filled_box (join_box, blotdiameter);
166       out.add_stencil (join);
167     }
168
169   SCM join_right_scm = me->get_property ("join-right-amount");
170
171   if (join_right_scm != SCM_EOL)
172     {
173       int join_right = scm_to_int (join_right_scm);
174       if (join_right)
175         {
176           Real y_top = join_right * 0.5 * staff_space;
177           Real y_bottom = 0.0;
178
179           if (y_top < 0.0)
180             {
181               y_bottom = y_top;
182               y_top = 0.0;
183             }
184
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);
189
190           out.add_stencil (join);
191         }
192       else
193         programming_error (_f ("Mensural_ligature: (join_right == 0)"));
194     }
195
196 #if 0 /* what happend with the ledger lines? */
197   int pos = Staff_symbol_referencer::get_rounded_position (me);
198   if (primitive & MLP_FLEXA)
199     {
200       pos += delta_pitch;
201       add_ledger_lines (me, &out, pos, 0.5 * delta_pitch, ledger_take_space);
202     }
203 #endif
204
205   return out;
206 }
207
208 MAKE_SCHEME_CALLBACK (Mensural_ligature, brew_ligature_primitive, 1);
209 SCM
210 Mensural_ligature::brew_ligature_primitive (SCM smob)
211 {
212   Grob *me = unsmob_grob (smob);
213   return internal_brew_primitive (me).smobbed_copy ();
214 }
215
216 MAKE_SCHEME_CALLBACK (Mensural_ligature, print, 1);
217 SCM
218 Mensural_ligature::print (SCM)
219 {
220   return SCM_EOL;
221 }
222
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");