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"
17 TODO: insert support for smaller cautionaries, tie-break-reminders.
18 Either here or in new-accidental-engraver.
20 'accidentals should go, for a single 'accidental property -- see
21 accidental-placement.cc
24 parenthesize (Grob *me, Stencil m)
26 Stencil open = Font_interface::get_default_font (me)->find_by_name ("accidentals.leftparen");
27 Stencil close = Font_interface::get_default_font (me)->find_by_name ("accidentals.rightparen");
29 m.add_at_edge (X_AXIS, LEFT, Stencil (open), 0, 0);
30 m.add_at_edge (X_AXIS, RIGHT, Stencil (close), 0, 0);
35 MAKE_SCHEME_CALLBACK (Accidental_interface, after_line_breaking, 1);
37 Accidental_interface::after_line_breaking (SCM smob)
39 Grob *me = unsmob_grob (smob);
40 Grob *tie = unsmob_grob (me->get_property ("tie"));
42 if (tie && !tie->original_)
46 return SCM_UNSPECIFIED;
50 Accidental_interface::accurate_boxes (Grob *a, Grob **common)
53 b[X_AXIS] = a->extent (a, X_AXIS);
54 b[Y_AXIS] = a->extent (a, Y_AXIS);
59 if (to_boolean (a->get_property ("cautionary")))
61 SCM cstyle = a->get_property ("cautionary-style");
62 parens = ly_c_equal_p (cstyle, ly_symbol2scm ("parentheses"));
65 SCM accs = a->get_property ("accidentals");
66 SCM scm_style = a->get_property ("style");
67 if (!scm_is_symbol (scm_style)
69 && scm_ilength (accs) == 1)
71 switch (scm_to_int (scm_car (accs))
79 we could make the stem thinner, but that places the flats
82 stem[X_AXIS][RIGHT] *= .5;
85 To prevent vertical alignment for 6ths
88 bulb[Y_AXIS][UP] *= .35;
100 lstem[Y_AXIS] *= 1.1;
101 rstem[Y_AXIS] *= 1.1;
103 belly[Y_AXIS] *= 0.75;
104 lstem[X_AXIS][RIGHT] *= .5;
105 rstem[X_AXIS][LEFT] = lstem[X_AXIS][RIGHT];
106 lstem[Y_AXIS][DOWN] = belly[Y_AXIS][DOWN];
107 rstem[Y_AXIS][UP] = belly[Y_AXIS][UP];
114 TODO: add support for, double flat.
121 Offset o (a->relative_coordinate (common[X_AXIS], X_AXIS),
122 a->relative_coordinate (common[Y_AXIS], Y_AXIS));
123 for (int i = boxes.size (); i--;)
125 boxes[i].translate (o);
132 * Some styles do not provide all flavours of accidentals, e.g. there
133 * is currently no sharp accidental in vaticana style. In these cases
134 * this function falls back to one of the other styles.
138 todo: this sort of stuff in Scheme. --hwn.
141 Accidental_interface::get_fontcharname (String style, int alteration)
143 if (alteration == DOUBLE_FLAT
144 || alteration == DOUBLE_SHARP)
146 return to_string (alteration);
149 if (style == "hufnagel")
152 case FLAT: return "hufnagel-1";
153 case 0: return "vaticana0";
154 case SHARP: return "mensural1";
156 if (style == "medicaea")
159 case FLAT: return "medicaea-1";
160 case 0: return "vaticana0";
161 case SHARP: return "mensural1";
163 if (style == "vaticana")
166 case FLAT: return "vaticana-1";
167 case 0: return "vaticana0";
168 case SHARP: return "mensural1";
170 if (style == "mensural")
173 case FLAT: return "mensural-1";
174 case 0: return "vaticana0";
175 case SHARP: return "mensural1";
178 if (style == "neomensural")
179 style = ""; // currently same as default
180 if (style == "default")
182 return style + to_string (alteration);
185 MAKE_SCHEME_CALLBACK (Accidental_interface, print, 1);
187 Accidental_interface::print (SCM smob)
189 Grob *me = unsmob_grob (smob);
190 bool smaller = false;
193 bool caut = to_boolean (me->get_property ("cautionary"));
196 SCM cstyle = me->get_property ("cautionary-style");
197 parens = ly_c_equal_p (cstyle, ly_symbol2scm ("parentheses"));
198 smaller = ly_c_equal_p (cstyle, ly_symbol2scm ("smaller"));
201 SCM scm_style = me->get_property ("style");
203 if (scm_is_symbol (scm_style))
205 style = ly_symbol2string (scm_style);
210 preferably no name for the default style.
218 SCM ac = Font_interface::music_font_alist_chain (me);
220 TODO: should calc font-size by adding -2 to current font-size
222 ac = scm_cons (scm_list_1 (scm_cons
223 (ly_symbol2scm ("font-size"),
226 fm = select_font (me->get_layout (), ac);
229 fm = Font_interface::get_default_font (me);
232 for (SCM s = me->get_property ("accidentals");
233 scm_is_pair (s); s = scm_cdr (s))
235 int alteration = scm_to_int (scm_car (s));
236 String font_char = get_fontcharname (style, alteration);
237 Stencil acc (fm->find_by_name ("accidentals." + font_char));
241 me->warning (_f ("accidental `%s' not found", font_char));
245 mol.add_at_edge (X_AXIS, RIGHT, acc, 0.1, 0);
250 mol = parenthesize (me, mol);
252 return mol.smobbed_copy ();
256 TODO: should move inside-slur into item?
259 ADD_INTERFACE (Accidental_interface, "accidental-interface",
260 "a single accidental",
261 "inside-slur cautionary cautionary-style style tie accidentals");