]> git.donarmstrong.com Git - lilypond.git/blob - lily/mensural-ligature.cc
Web-ja: update introduction
[lilypond.git] / lily / mensural-ligature.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2002--2015 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 "directional-element-interface.hh"
24 #include "font-interface.hh"
25 #include "international.hh"
26 #include "item.hh"
27 #include "lookup.hh"
28 #include "note-head.hh"
29 #include "output-def.hh"
30 #include "staff-symbol-referencer.hh"
31 #include "warn.hh"
32
33 /*
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.
37
38  * TODO: divide this function into mensural and neo-mensural style.
39  *
40  * TODO: move this function to class Lookup?
41  */
42 Stencil
43 brew_flexa (Grob *me,
44             bool solid,
45             Real width,
46             Real thickness,
47             bool begin)
48 {
49   Real staff_space = Staff_symbol_referencer::staff_space (me);
50
51   /*
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).
55   */
56   Real const horizontal_line_thickness = staff_space * 0.35;
57
58   // URGH!  vertical_line_thickness is adjustable (via thickness
59   // property), while horizontal_line_thickness is constant.
60   // Maybe both should be adjustable independently?
61
62   Real height = staff_space - horizontal_line_thickness;
63   Stencil stencil;
64   Real const interval
65     = robust_scm2double (me->get_property ("flexa-interval"), 0.0);
66   Real slope = (interval / 2.0 * staff_space) / width;
67
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;
73   Real blotdiameter
74     = me->layout ()->get_dimension (ly_symbol2scm ("blot-diameter"));
75   width += 2 * blotdiameter;
76
77   if (solid) // colorated flexae
78     {
79       stencil = Lookup::beam (corrected_slope, width * 0.5, staff_space, blotdiameter);
80     }
81   else // outline
82     {
83       stencil = Lookup::beam (corrected_slope, thickness, height, blotdiameter);
84       if (!begin)
85         {
86           stencil.translate_axis (width * 0.5 - thickness, X_AXIS);
87           stencil.translate_axis (corrected_slope * (width * 0.5 - thickness),
88                                   Y_AXIS);
89         }
90
91       Stencil bottom_edge
92         = Lookup::beam (corrected_slope, width * 0.5, horizontal_line_thickness,
93                         blotdiameter);
94       bottom_edge.translate_axis (-0.5 * height, Y_AXIS);
95       stencil.add_stencil (bottom_edge);
96
97       Stencil top_edge
98         = Lookup::beam (corrected_slope, width * 0.5, horizontal_line_thickness,
99                         blotdiameter);
100       top_edge.translate_axis (+0.5 * height, Y_AXIS);
101       stencil.add_stencil (top_edge);
102     }
103
104   if (begin)
105     stencil.translate_axis (ypos_correction, Y_AXIS);
106   else
107     {
108       stencil.translate_axis (0.5 * thickness - blotdiameter, X_AXIS);
109
110       stencil.translate_axis (interval / -4.0 * staff_space, Y_AXIS);
111     }
112
113   return stencil;
114 }
115
116 Stencil
117 internal_brew_primitive (Grob *me)
118 {
119   SCM primitive_scm = me->get_property ("primitive");
120   if (scm_is_null (primitive_scm))
121     {
122       programming_error ("Mensural_ligature:"
123                          " undefined primitive -> ignoring grob");
124       return Lookup::blank (Box (Interval (0, 0), Interval (0, 0)));
125     }
126   int primitive = scm_to_int (primitive_scm);
127
128   Real thickness = 0.0;
129   Real width = 0.0;
130   Real flexa_width = 0.0;
131   Real staff_space = Staff_symbol_referencer::staff_space (me);
132
133   SCM style = me->get_property ("style");
134   bool const black
135     = scm_is_eq (style, ly_symbol2scm ("blackpetrucci"));
136   bool const semi
137     = scm_is_eq (style, ly_symbol2scm ("semipetrucci"));
138
139   if (primitive & MLP_ANY)
140     {
141       thickness = robust_scm2double (me->get_property ("thickness"), .13);
142       width = robust_scm2double (me->get_property ("head-width"), staff_space);
143     }
144   if (primitive & MLP_FLEXA)
145     flexa_width = robust_scm2double (me->get_property ("flexa-width"), 2.0)
146                   * staff_space;
147
148   Stencil out;
149   int const note_shape = primitive & MLP_ANY;
150   int duration_log = 0;
151   Font_metric *fm = Font_interface::get_default_font (me);
152   string prefix = "noteheads.";
153   string index;
154   string suffix;
155   string color = "";
156   if (black)
157     color = "black";
158   if (semi)
159     color = "semi";
160
161   switch (note_shape)
162     {
163     case MLP_NONE:
164       return Lookup::blank (Box (Interval (0, 0), Interval (0, 0)));
165     case MLP_MAXIMA:
166       duration_log--;
167     case MLP_LONGA:
168       duration_log--;
169     case MLP_BREVIS:
170       duration_log--;
171       suffix = ::to_string (duration_log) + color
172                + (duration_log < -1 ? "lig" : "") + "mensural";
173       index = prefix + "s";
174       out = fm->find_by_name (index + "r" + suffix);
175       if (!out.is_empty ()
176           && !Staff_symbol_referencer::on_line
177           (me,
178            robust_scm2int (me->get_property ("staff-position"), 0)))
179         index += "r";
180       out = fm->find_by_name (index + suffix);
181       break;
182     case MLP_FLEXA_BEGIN:
183     case MLP_FLEXA_END:
184       out = brew_flexa (me, black, flexa_width, thickness,
185                         note_shape == MLP_FLEXA_BEGIN);
186       break;
187     default:
188       programming_error ("Mensural_ligature:"
189                          " unexpected case fall-through");
190       return Lookup::blank (Box (Interval (0, 0), Interval (0, 0)));
191     }
192
193   /*
194     we use thickness because the stem end of the glyph
195     "noteheads.sM2ligmensural" is round.
196   */
197   Real blotdiameter = thickness;
198   /*
199     instead of 2.5 the length of a longa stem should be used
200     Font_interface::get_default_font (???)->find_by_name
201     ("noteheads.sM2ligmensural").extent (Y_AXIS).length () * 0.5
202   */
203   Real stem_length = 2.5 * staff_space;
204
205   if (primitive & MLP_STEM)
206     {
207       // assume MLP_UP
208       Real y_bottom = 0.0, y_top = stem_length;
209
210       if (primitive & MLP_DOWN)
211         {
212           y_bottom = -y_top;
213           y_top = 0.0;
214         }
215
216       Interval x_extent (0, thickness);
217       Interval y_extent (y_bottom, y_top);
218       Box join_box (x_extent, y_extent);
219
220       Stencil join = Lookup::round_filled_box (join_box, blotdiameter);
221       out.add_stencil (join);
222     }
223
224   if (to_boolean (me->get_property ("add-join")))
225     {
226       int join_right = scm_to_int (me->get_property ("delta-position"));
227       if (join_right)
228         {
229           Real y_top = join_right * 0.5 * staff_space;
230           Real y_bottom = 0.0;
231
232           if (y_top < 0.0)
233             {
234               y_bottom = y_top;
235               y_top = 0.0;
236
237               /*
238                 if the previous note is longa-shaped,
239                 the joining line may hide the stem, so made it longer
240                 to serve as stem as well
241               */
242               if (primitive & MLP_LONGA)
243                 y_bottom -= stem_length + 0.25 * blotdiameter;
244             }
245
246           Interval x_extent (width - thickness, width);
247           Interval y_extent (y_bottom, y_top);
248           Box join_box (x_extent, y_extent);
249           Stencil join = Lookup::round_filled_box (join_box, blotdiameter);
250
251           out.add_stencil (join);
252         }
253       else
254         programming_error ("Mensural_ligature: (join_right == 0)");
255     }
256
257 #if 0 /* what happend with the ledger lines? */
258   int pos = Staff_symbol_referencer::get_rounded_position (me);
259   if (primitive & MLP_FLEXA)
260     {
261       pos += delta_pitch;
262       add_ledger_lines (me, &out, pos, 0.5 * delta_pitch, ledger_take_space);
263     }
264 #endif
265
266   return out;
267 }
268
269 MAKE_SCHEME_CALLBACK (Mensural_ligature, brew_ligature_primitive, 1);
270 SCM
271 Mensural_ligature::brew_ligature_primitive (SCM smob)
272 {
273   Grob *me = unsmob<Grob> (smob);
274   return internal_brew_primitive (me).smobbed_copy ();
275 }
276
277 MAKE_SCHEME_CALLBACK (Mensural_ligature, print, 1);
278 SCM
279 Mensural_ligature::print (SCM)
280 {
281   return SCM_EOL;
282 }
283
284 ADD_INTERFACE (Mensural_ligature,
285                "A mensural ligature.",
286
287                /* properties */
288                "delta-position "
289                "ligature-flexa "
290                "head-width "
291                "add-join "
292                "flexa-interval "
293                "primitive "
294                "thickness "
295               );