]> git.donarmstrong.com Git - lilypond.git/blob - lily/mensural-ligature.cc
Merge branch 'web-experimental' into lilypond/translation
[lilypond.git] / lily / mensural-ligature.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2002--2011 Juergen Reuter <reuter@ipd.uka.de>,
5   Pal Benko <benkop@freestart.hu>
6
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.
11
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.
16
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/>.
19 */
20
21 #include "mensural-ligature.hh"
22
23 #include "font-interface.hh"
24 #include "international.hh"
25 #include "item.hh"
26 #include "lookup.hh"
27 #include "note-head.hh"
28 #include "output-def.hh"
29 #include "staff-symbol-referencer.hh"
30 #include "warn.hh"
31
32 /*
33   draws one half a flexa, i.e. a portion corresponding to a single note.
34   this way coloration of the two notes building up the flexa can be
35   handled independently.
36
37  * TODO: divide this function into mensural and neo-mensural style.
38  *
39  * TODO: move this function to class Lookup?
40  */
41 Stencil
42 brew_flexa (Grob *me,
43             bool solid,
44             Real width,
45             Real thickness,
46             bool begin)
47 {
48   Real staff_space = Staff_symbol_referencer::staff_space (me);
49
50   /*
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).
54   */
55   Real const horizontal_line_thickness = staff_space * 0.35;
56
57   // URGH!  vertical_line_thickness is adjustable (via thickness
58   // property), while horizontal_line_thickness is constant.
59   // Maybe both should be adjustable independently?
60
61   Real height = staff_space - horizontal_line_thickness;
62   Stencil stencil;
63   Real const interval =
64     robust_scm2double (me->get_property ("flexa-interval"), 0.0);
65   Real slope = (interval / 2.0 * staff_space) / width;
66
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;
72
73   if (solid) // colorated flexae
74     {
75       stencil = Lookup::beam (corrected_slope, width * 0.5, staff_space, 0.0);
76     }
77   else // outline
78     {
79       stencil = Lookup::beam (corrected_slope, thickness, height, 0.0);
80       if (!begin)
81         {
82           stencil.translate_axis (width*0.5 - thickness, X_AXIS);
83           stencil.translate_axis (corrected_slope * (width*0.5 - thickness),
84                                   Y_AXIS);
85         }
86
87       Stencil bottom_edge =
88         Lookup::beam (corrected_slope, width * 0.5, horizontal_line_thickness,
89                       0.0);
90       bottom_edge.translate_axis (-0.5*height, Y_AXIS);
91       stencil.add_stencil (bottom_edge);
92
93       Stencil top_edge =
94         Lookup::beam (corrected_slope, width * 0.5, horizontal_line_thickness,
95                       0.0);
96       top_edge.translate_axis (+0.5*height, Y_AXIS);
97       stencil.add_stencil (top_edge);
98     }
99
100   if (begin)
101     stencil.translate_axis (ypos_correction, Y_AXIS);
102   else
103     {
104       stencil.translate_axis (0.5 * thickness, X_AXIS);
105
106       stencil.translate_axis (interval / -4.0 * staff_space, Y_AXIS);
107     }
108
109   return stencil;
110 }
111
112 Stencil
113 internal_brew_primitive (Grob *me)
114 {
115   SCM primitive_scm = me->get_property ("primitive");
116   if (primitive_scm == SCM_EOL)
117     {
118       programming_error ("Mensural_ligature:"
119                          " undefined primitive -> ignoring grob");
120       return Lookup::blank (Box (Interval (0, 0), Interval (0, 0)));
121     }
122   int primitive = scm_to_int (primitive_scm);
123
124   Stencil out;
125   Real thickness = 0.0;
126   Real width = 0.0;
127   Real flexa_width = 0.0;
128   Real staff_space = Staff_symbol_referencer::staff_space (me);
129
130   bool const color =
131     me->get_property ("style") == ly_symbol2scm ("blackpetrucci");
132   bool const semi =
133     me->get_property ("style") == ly_symbol2scm ("semipetrucci");
134
135   if (primitive & MLP_ANY)
136     {
137       thickness = robust_scm2double (me->get_property ("thickness"), .14);
138       width = robust_scm2double (me->get_property ("head-width"), staff_space);
139     }
140   if (primitive & MLP_FLEXA)
141     flexa_width = robust_scm2double (me->get_property ("flexa-width"), 2.0)
142       * staff_space;
143
144   int const note_shape = primitive & MLP_ANY;
145
146   switch (note_shape)
147     {
148     case MLP_NONE:
149       return Lookup::blank (Box (Interval (0, 0), Interval (0, 0)));
150     case MLP_LONGA: // mensural brevis head with right cauda
151       out = Font_interface::get_default_font (me)->find_by_name
152         (color ? "noteheads.sM2blackmensural" :
153          semi ? "noteheads.sM2semimensural" : "noteheads.sM2mensural");
154       break;
155     case MLP_BREVIS: // mensural brevis head
156       out = Font_interface::get_default_font (me)->find_by_name
157         (color ? "noteheads.sM1blackmensural" :
158          semi ? "noteheads.sM1semimensural" : "noteheads.sM1mensural");
159       break;
160     case MLP_MAXIMA: // should be mensural maxima head without stem
161       out = Font_interface::get_default_font (me)->find_by_name
162         (color ? "noteheads.sM3blackligmensural" :
163          semi ? "noteheads.sM3semiligmensural" : "noteheads.sM3ligmensural");
164       break;
165     case MLP_FLEXA_BEGIN:
166     case MLP_FLEXA_END:
167       out = brew_flexa (me, color, flexa_width, thickness,
168                         note_shape == MLP_FLEXA_BEGIN);
169       break;
170     default:
171       programming_error (_ ("Mensural_ligature:"
172                             " unexpected case fall-through"));
173       return Lookup::blank (Box (Interval (0, 0), Interval (0, 0)));
174     }
175
176   Real blotdiameter
177     = (me->layout ()->get_dimension (ly_symbol2scm ("blot-diameter")));
178
179   if (primitive & MLP_STEM)
180     {
181       // assume MLP_UP
182       Real y_bottom = 0.0, y_top = 3.0 * staff_space;
183
184       if (primitive & MLP_DOWN)
185         {
186           y_bottom = -y_top;
187           y_top = 0.0;
188         }
189
190       Interval x_extent (0, thickness);
191       Interval y_extent (y_bottom, y_top);
192       Box join_box (x_extent, y_extent);
193
194       Stencil join = Lookup::round_filled_box (join_box, blotdiameter);
195       out.add_stencil (join);
196     }
197
198   if (to_boolean (me->get_property ("add-join")))
199     {
200       int join_right = scm_to_int (me->get_property ("delta-position"));
201       if (join_right)
202         {
203           Real y_top = join_right * 0.5 * staff_space;
204           Real y_bottom = 0.0;
205
206           if (y_top < 0.0)
207             {
208               y_bottom = y_top;
209               y_top = 0.0;
210
211               /*
212                 if the previous note is longa-shaped,
213                 the joining line may hide the stem, so made it longer
214                 to serve as stem as well
215               */
216               if (primitive & MLP_LONGA)
217                 /*
218                   instead of 3.0 the length of a longa stem should be used
219                   Font_interface::get_default_font (???)->find_by_name
220                   ("noteheads.s-2mensural").extent (Y_AXIS).length () * 0.5
221                 */
222                 y_bottom -= 3.0 * staff_space;
223             }
224
225           Interval x_extent (width - thickness, width);
226           Interval y_extent (y_bottom, y_top);
227           Box join_box (x_extent, y_extent);
228           Stencil join = Lookup::round_filled_box (join_box, blotdiameter);
229
230           out.add_stencil (join);
231         }
232       else
233         programming_error (_ ("Mensural_ligature: (join_right == 0)"));
234     }
235
236 #if 0 /* what happend with the ledger lines? */
237   int pos = Staff_symbol_referencer::get_rounded_position (me);
238   if (primitive & MLP_FLEXA)
239     {
240       pos += delta_pitch;
241       add_ledger_lines (me, &out, pos, 0.5 * delta_pitch, ledger_take_space);
242     }
243 #endif
244
245   return out;
246 }
247
248 MAKE_SCHEME_CALLBACK (Mensural_ligature, brew_ligature_primitive, 1);
249 SCM
250 Mensural_ligature::brew_ligature_primitive (SCM smob)
251 {
252   Grob *me = unsmob_grob (smob);
253   return internal_brew_primitive (me).smobbed_copy ();
254 }
255
256 MAKE_SCHEME_CALLBACK (Mensural_ligature, print, 1);
257 SCM
258 Mensural_ligature::print (SCM)
259 {
260   return SCM_EOL;
261 }
262
263 ADD_INTERFACE (Mensural_ligature,
264                "A mensural ligature.",
265
266                /* properties */
267                "delta-position "
268                "ligature-flexa "
269                "head-width "
270                "add-join "
271                "flexa-interval "
272                "primitive "
273                "thickness "
274                );