2 accidental.cc -- implement Accidental_interface
4 source file of the GNU LilyPond music typesetter
6 (c) 2001--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #include "accidental-interface.hh"
10 #include "font-interface.hh"
11 #include "international.hh"
13 #include "output-def.hh"
18 parenthesize (Grob *me, Stencil m)
21 = Font_interface::get_default_font (me);
23 = font->find_by_name ("accidentals.leftparen");
25 = font->find_by_name ("accidentals.rightparen");
27 m.add_at_edge (X_AXIS, LEFT, Stencil (open), 0, 0);
28 m.add_at_edge (X_AXIS, RIGHT, Stencil (close), 0, 0);
34 Hmm. Need separate callback, or perhaps #'live bool property.
36 MAKE_SCHEME_CALLBACK (Accidental_interface, after_line_breaking, 1);
38 Accidental_interface::after_line_breaking (SCM smob)
40 Grob *me = unsmob_grob (smob);
41 Grob *tie = unsmob_grob (me->get_object ("tie"));
43 if (tie && !tie->original ()
44 && !to_boolean (me->get_property ("forced")))
49 return SCM_UNSPECIFIED;
53 Accidental_interface::accurate_boxes (Grob *me, Grob **common)
56 b[X_AXIS] = me->extent (me, X_AXIS);
57 b[Y_AXIS] = me->extent (me, Y_AXIS);
61 bool parens = to_boolean (me->get_property ("parenthesized"));
63 SCM scm_style = me->get_property ("style");
64 if (!scm_is_symbol (scm_style)
65 && !to_boolean (me->get_property ("restore-first"))
68 int acc = scm_to_int (me->get_property ("alteration"));
77 we could make the stem thinner, but that places the flats
80 stem[X_AXIS][RIGHT] *= .5;
83 To prevent vertical alignment for 6ths
86 bulb[Y_AXIS][UP] *= .35;
88 boxes.push_back (bulb);
89 boxes.push_back (stem);
101 belly[Y_AXIS] *= 0.75;
102 lstem[X_AXIS][RIGHT] *= .33;
103 rstem[X_AXIS][LEFT] = rstem[X_AXIS].linear_combination (1.0 / 3.0);
104 lstem[Y_AXIS][DOWN] = belly[Y_AXIS][DOWN];
105 rstem[Y_AXIS][UP] = belly[Y_AXIS][UP];
106 boxes.push_back (belly);
107 boxes.push_back (lstem);
108 boxes.push_back (rstem);
112 TODO: add support for, double flat.
120 Offset o (me->relative_coordinate (common[X_AXIS], X_AXIS),
121 me->relative_coordinate (common[Y_AXIS], Y_AXIS));
123 for (vsize i = boxes.size (); i--;)
124 boxes[i].translate (o);
130 * Some styles do not provide all flavours of accidentals, e.g. there
131 * is currently no sharp accidental in vaticana style. In these cases
132 * this function falls back to one of the other styles.
136 todo: this sort of stuff in Scheme. --hwn.
139 Accidental_interface::get_fontcharname (string style, int alteration)
141 if (alteration == DOUBLE_FLAT
142 || alteration == DOUBLE_SHARP)
143 return to_string (alteration);
145 if (style == "hufnagel")
148 case FLAT: return "hufnagel-1";
149 case 0: return "vaticana0";
150 case SHARP: return "mensural1";
152 if (style == "medicaea")
155 case FLAT: return "medicaea-1";
156 case 0: return "vaticana0";
157 case SHARP: return "mensural1";
159 if (style == "vaticana")
162 case FLAT: return "vaticana-1";
163 case 0: return "vaticana0";
164 case SHARP: return "mensural1";
166 if (style == "mensural")
169 case FLAT: return "mensural-1";
170 case 0: return "vaticana0";
171 case SHARP: return "mensural1";
174 if (style == "neomensural")
175 style = ""; // currently same as default
176 if (style == "default")
179 return style + to_string (alteration);
182 MAKE_SCHEME_CALLBACK (Accidental_interface, print, 1);
184 Accidental_interface::print (SCM smob)
186 Grob *me = unsmob_grob (smob);
187 bool parens = to_boolean (me->get_property ("parenthesized"));
189 SCM scm_style = me->get_property ("style");
191 if (scm_is_symbol (scm_style))
192 style = ly_symbol2string (scm_style);
195 preferably no name for the default style.
199 Font_metric *fm = Font_interface::get_default_font (me);
201 SCM stencils = me->get_property ("stencils");
202 if (!scm_is_pair (stencils)
203 || !unsmob_stencil (scm_car (stencils)))
206 Stencil mol (*unsmob_stencil (scm_car (stencils)));
207 if (to_boolean (me->get_property ("restore-first")))
209 string font_char = get_fontcharname (style, 0);
210 Stencil acc (fm->find_by_name ("accidentals." + font_char));
213 me->warning (_f ("accidental `%s' not found", font_char));
215 mol.add_at_edge (X_AXIS, LEFT, acc, 0.1, 0);
219 mol = parenthesize (me, mol);
221 return mol.smobbed_copy ();
224 MAKE_SCHEME_CALLBACK (Accidental_interface, calc_stencils, 1);
226 Accidental_interface::calc_stencils (SCM smob)
228 Grob *me = unsmob_grob (smob);
230 SCM scm_style = me->get_property ("style");
232 if (scm_is_symbol (scm_style))
233 style = ly_symbol2string (scm_style);
236 preferably no name for the default style.
241 Font_metric *fm = Font_interface::get_default_font (me);
242 SCM acc = me->get_property ("alteration");
243 if (scm_is_number (acc))
245 string font_char = get_fontcharname (style, scm_to_int (acc));
247 Stencil acc_stencil (fm->find_by_name ("accidentals." + font_char));
249 return scm_list_1 (acc_stencil.smobbed_copy ());
256 ADD_INTERFACE (Accidental_interface,
257 "a single accidental",