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 TODO: insert support for smaller cautionaries, tie-break-reminders.
19 Either here or in new-accidental-engraver.
21 'accidentals should go, for a single 'accidental property -- see
22 accidental-placement.cc
25 parenthesize (Grob *me, Stencil m)
28 = Font_interface::get_default_font (me);
30 = font->find_by_name ("accidentals.leftparen");
32 = font->find_by_name ("accidentals.rightparen");
34 m.add_at_edge (X_AXIS, LEFT, Stencil (open), 0, 0);
35 m.add_at_edge (X_AXIS, RIGHT, Stencil (close), 0, 0);
41 Hmm. Need separate callback, or perhaps #'live bool property.
43 MAKE_SCHEME_CALLBACK (Accidental_interface, after_line_breaking, 1);
45 Accidental_interface::after_line_breaking (SCM smob)
47 Grob *me = unsmob_grob (smob);
48 Grob *tie = unsmob_grob (me->get_object ("tie"));
50 if (tie && !tie->original ()
51 && !to_boolean (me->get_property ("forced")))
56 return SCM_UNSPECIFIED;
60 Accidental_interface::accurate_boxes (Grob *a, Grob **common)
63 b[X_AXIS] = a->extent (a, X_AXIS);
64 b[Y_AXIS] = a->extent (a, Y_AXIS);
69 if (to_boolean (a->get_property ("cautionary")))
71 SCM cstyle = a->get_property ("cautionary-style");
72 parens = ly_is_equal (cstyle, ly_symbol2scm ("parentheses"));
75 SCM accs = a->get_property ("accidentals");
76 SCM scm_style = a->get_property ("style");
77 if (!scm_is_symbol (scm_style)
79 && scm_ilength (accs) == 1)
81 switch (scm_to_int (scm_car (accs)))
89 we could make the stem thinner, but that places the flats
92 stem[X_AXIS][RIGHT] *= .5;
95 To prevent vertical alignment for 6ths
98 bulb[Y_AXIS][UP] *= .35;
100 boxes.push_back (bulb);
101 boxes.push_back (stem);
110 lstem[Y_AXIS] *= 1.1;
111 rstem[Y_AXIS] *= 1.1;
113 belly[Y_AXIS] *= 0.75;
114 lstem[X_AXIS][RIGHT] *= .33;
115 rstem[X_AXIS][LEFT] = rstem[X_AXIS].linear_combination (1.0 / 3.0);
116 lstem[Y_AXIS][DOWN] = belly[Y_AXIS][DOWN];
117 rstem[Y_AXIS][UP] = belly[Y_AXIS][UP];
118 boxes.push_back (belly);
119 boxes.push_back (lstem);
120 boxes.push_back (rstem);
124 TODO: add support for, double flat.
132 Offset o (a->relative_coordinate (common[X_AXIS], X_AXIS),
133 a->relative_coordinate (common[Y_AXIS], Y_AXIS));
134 for (vsize i = boxes.size (); i--;)
135 boxes[i].translate (o);
141 * Some styles do not provide all flavours of accidentals, e.g. there
142 * is currently no sharp accidental in vaticana style. In these cases
143 * this function falls back to one of the other styles.
147 todo: this sort of stuff in Scheme. --hwn.
150 Accidental_interface::get_fontcharname (string style, int alteration)
152 if (alteration == DOUBLE_FLAT
153 || alteration == DOUBLE_SHARP)
154 return to_string (alteration);
156 if (style == "hufnagel")
159 case FLAT: return "hufnagel-1";
160 case 0: return "vaticana0";
161 case SHARP: return "mensural1";
163 if (style == "medicaea")
166 case FLAT: return "medicaea-1";
167 case 0: return "vaticana0";
168 case SHARP: return "mensural1";
170 if (style == "vaticana")
173 case FLAT: return "vaticana-1";
174 case 0: return "vaticana0";
175 case SHARP: return "mensural1";
177 if (style == "mensural")
180 case FLAT: return "mensural-1";
181 case 0: return "vaticana0";
182 case SHARP: return "mensural1";
185 if (style == "neomensural")
186 style = ""; // currently same as default
187 if (style == "default")
189 return style + to_string (alteration);
192 MAKE_SCHEME_CALLBACK (Accidental_interface, print, 1);
194 Accidental_interface::print (SCM smob)
196 Grob *me = unsmob_grob (smob);
197 bool smaller = false;
200 bool caut = to_boolean (me->get_property ("cautionary"));
203 SCM cstyle = me->get_property ("cautionary-style");
204 parens = ly_is_equal (cstyle, ly_symbol2scm ("parentheses"));
205 smaller = ly_is_equal (cstyle, ly_symbol2scm ("smaller"));
208 SCM scm_style = me->get_property ("style");
210 if (scm_is_symbol (scm_style))
211 style = ly_symbol2string (scm_style);
214 preferably no name for the default style.
221 SCM ac = Font_interface::music_font_alist_chain (me);
223 TODO: should calc font-size by adding -2 to current font-size
225 ac = scm_cons (scm_list_1 (scm_cons
226 (ly_symbol2scm ("font-size"),
229 fm = select_font (me->layout (), ac);
232 fm = Font_interface::get_default_font (me);
235 for (SCM s = me->get_property ("accidentals");
236 scm_is_pair (s); s = scm_cdr (s))
238 int alteration = scm_to_int (scm_car (s));
239 string font_char = get_fontcharname (style, alteration);
240 Stencil acc (fm->find_by_name ("accidentals." + font_char));
243 me->warning (_f ("accidental `%s' not found", font_char));
245 mol.add_at_edge (X_AXIS, RIGHT, acc, 0.1, 0);
249 mol = parenthesize (me, mol);
251 return mol.smobbed_copy ();
255 TODO: should move avoid-slur into item?
257 ADD_INTERFACE (Accidental_interface, "accidental-interface",
258 "a single accidental",