2 accidental.cc -- implement Accidental_interface
4 source file of the GNU LilyPond music typesetter
6 (c) 2001--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "font-interface.hh"
12 #include "accidental-interface.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
26 parenthesize (Grob*me, Stencil m)
28 Stencil open = Font_interface::get_default_font (me)->find_by_name ("accidentals.leftparen");
29 Stencil close = Font_interface::get_default_font (me)->find_by_name ("accidentals.rightparen");
31 m.add_at_edge (X_AXIS, LEFT, Stencil (open), 0, 0);
32 m.add_at_edge (X_AXIS, RIGHT, Stencil (close), 0, 0);
38 MAKE_SCHEME_CALLBACK (Accidental_interface, after_line_breaking, 1);
40 Accidental_interface::after_line_breaking (SCM smob)
42 Grob *me = unsmob_grob (smob);
43 Grob *tie = unsmob_grob (me->get_property ("tie"));
45 if (tie && !tie->original_)
49 return SCM_UNSPECIFIED;
53 Accidental_interface::accurate_boxes (Grob *a, Grob**common)
56 b[X_AXIS] = a->extent (a, X_AXIS);
57 b[Y_AXIS] = a->extent (a, Y_AXIS);
62 if (to_boolean (a->get_property ("cautionary")))
64 SCM cstyle = a->get_property ("cautionary-style");
65 parens = ly_c_equal_p (cstyle, ly_symbol2scm ("parentheses"));
68 SCM accs = a->get_property ("accidentals");
69 SCM scm_style = a->get_property ("style");
70 if (!scm_is_symbol (scm_style)
72 && scm_ilength (accs) == 1)
74 switch (scm_to_int (scm_car (accs))
82 we could make the stem thinner, but that places the flats
85 stem[X_AXIS][RIGHT] *= .5;
88 To prevent vertical alignment for 6ths
91 bulb[Y_AXIS][UP] *= .35;
103 lstem[Y_AXIS] *= 1.1;
104 rstem[Y_AXIS] *= 1.1;
106 belly[Y_AXIS] *= 0.75;
107 lstem[X_AXIS][RIGHT] *= .5;
108 rstem[X_AXIS][LEFT] = lstem[X_AXIS][RIGHT];
109 lstem[Y_AXIS][DOWN] = belly[Y_AXIS][DOWN];
110 rstem[Y_AXIS][UP] = belly[Y_AXIS][UP];
117 TODO: add support for, double flat.
124 Offset o (a->relative_coordinate (common[X_AXIS], X_AXIS),
125 a->relative_coordinate (common[Y_AXIS], Y_AXIS));
126 for (int i = boxes.size (); i--;)
128 boxes[i].translate (o);
135 * Some styles do not provide all flavours of accidentals, e.g. there
136 * is currently no sharp accidental in vaticana style. In these cases
137 * this function falls back to one of the other styles.
141 todo: this sort of stuff in Scheme. --hwn.
144 Accidental_interface::get_fontcharname (String style, int alteration)
146 if (alteration == DOUBLE_FLAT
147 || alteration == DOUBLE_SHARP)
149 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_c_equal_p (cstyle, ly_symbol2scm ("parentheses"));
201 smaller = ly_c_equal_p (cstyle, ly_symbol2scm ("smaller"));
204 SCM scm_style = me->get_property ("style");
206 if (scm_is_symbol (scm_style))
208 style = ly_symbol2string (scm_style);
213 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->get_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));
244 me->warning (_f ("accidental `%s' not found", font_char));
248 mol.add_at_edge (X_AXIS, RIGHT, acc, 0.1, 0);
253 mol = parenthesize (me, mol);
255 return mol.smobbed_copy ();
260 TODO: should move inside-slur into item?
263 ADD_INTERFACE (Accidental_interface, "accidental-interface",
264 "a single accidental",
265 "inside-slur cautionary cautionary-style style tie accidentals");