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 ())
52 return SCM_UNSPECIFIED;
56 Accidental_interface::accurate_boxes (Grob *a, Grob **common)
59 b[X_AXIS] = a->extent (a, X_AXIS);
60 b[Y_AXIS] = a->extent (a, Y_AXIS);
65 if (to_boolean (a->get_property ("cautionary")))
67 SCM cstyle = a->get_property ("cautionary-style");
68 parens = ly_is_equal (cstyle, ly_symbol2scm ("parentheses"));
71 SCM accs = a->get_property ("accidentals");
72 SCM scm_style = a->get_property ("style");
73 if (!scm_is_symbol (scm_style)
75 && scm_ilength (accs) == 1)
77 switch (scm_to_int (scm_car (accs)))
85 we could make the stem thinner, but that places the flats
88 stem[X_AXIS][RIGHT] *= .5;
91 To prevent vertical alignment for 6ths
94 bulb[Y_AXIS][UP] *= .35;
96 boxes.push_back (bulb);
97 boxes.push_back (stem);
106 lstem[Y_AXIS] *= 1.1;
107 rstem[Y_AXIS] *= 1.1;
109 belly[Y_AXIS] *= 0.75;
110 lstem[X_AXIS][RIGHT] *= .33;
111 rstem[X_AXIS][LEFT] = rstem[X_AXIS].linear_combination (1.0 / 3.0);
112 lstem[Y_AXIS][DOWN] = belly[Y_AXIS][DOWN];
113 rstem[Y_AXIS][UP] = belly[Y_AXIS][UP];
114 boxes.push_back (belly);
115 boxes.push_back (lstem);
116 boxes.push_back (rstem);
120 TODO: add support for, double flat.
128 Offset o (a->relative_coordinate (common[X_AXIS], X_AXIS),
129 a->relative_coordinate (common[Y_AXIS], Y_AXIS));
130 for (vsize i = boxes.size (); i--;)
131 boxes[i].translate (o);
137 * Some styles do not provide all flavours of accidentals, e.g. there
138 * is currently no sharp accidental in vaticana style. In these cases
139 * this function falls back to one of the other styles.
143 todo: this sort of stuff in Scheme. --hwn.
146 Accidental_interface::get_fontcharname (string style, int alteration)
148 if (alteration == DOUBLE_FLAT
149 || alteration == DOUBLE_SHARP)
150 return to_string (alteration);
152 if (style == "hufnagel")
155 case FLAT: return "hufnagel-1";
156 case 0: return "vaticana0";
157 case SHARP: return "mensural1";
159 if (style == "medicaea")
162 case FLAT: return "medicaea-1";
163 case 0: return "vaticana0";
164 case SHARP: return "mensural1";
166 if (style == "vaticana")
169 case FLAT: return "vaticana-1";
170 case 0: return "vaticana0";
171 case SHARP: return "mensural1";
173 if (style == "mensural")
176 case FLAT: return "mensural-1";
177 case 0: return "vaticana0";
178 case SHARP: return "mensural1";
181 if (style == "neomensural")
182 style = ""; // currently same as default
183 if (style == "default")
185 return style + to_string (alteration);
188 MAKE_SCHEME_CALLBACK (Accidental_interface, print, 1);
190 Accidental_interface::print (SCM smob)
192 Grob *me = unsmob_grob (smob);
193 bool smaller = false;
196 bool caut = to_boolean (me->get_property ("cautionary"));
199 SCM cstyle = me->get_property ("cautionary-style");
200 parens = ly_is_equal (cstyle, ly_symbol2scm ("parentheses"));
201 smaller = ly_is_equal (cstyle, ly_symbol2scm ("smaller"));
204 SCM scm_style = me->get_property ("style");
206 if (scm_is_symbol (scm_style))
207 style = ly_symbol2string (scm_style);
210 preferably no name for the default style.
217 SCM ac = Font_interface::music_font_alist_chain (me);
219 TODO: should calc font-size by adding -2 to current font-size
221 ac = scm_cons (scm_list_1 (scm_cons
222 (ly_symbol2scm ("font-size"),
225 fm = select_font (me->layout (), ac);
228 fm = Font_interface::get_default_font (me);
231 for (SCM s = me->get_property ("accidentals");
232 scm_is_pair (s); s = scm_cdr (s))
234 int alteration = scm_to_int (scm_car (s));
235 string font_char = get_fontcharname (style, alteration);
236 Stencil acc (fm->find_by_name ("accidentals." + font_char));
239 me->warning (_f ("accidental `%s' not found", font_char));
241 mol.add_at_edge (X_AXIS, RIGHT, acc, 0.1, 0);
245 mol = parenthesize (me, mol);
247 return mol.smobbed_copy ();
251 TODO: should move avoid-slur into item?
253 ADD_INTERFACE (Accidental_interface, "accidental-interface",
254 "a single accidental",