2 accidental.cc -- implement Accidental_interface
4 source file of the GNU LilyPond music typesetter
6 (c) 2001--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 #include "font-interface.hh"
11 #include "accidental-interface.hh"
12 #include "output-def.hh"
16 TODO: insert support for smaller cautionaries, tie-break-reminders.
17 Either here or in new-accidental-engraver.
19 'accidentals should go, for a single 'accidental property -- see
20 accidental-placement.cc
26 parenthesize (Grob*me, Stencil m)
28 Stencil open = Font_interface::get_default_font (me)->find_by_name (String ("accidentals-leftparen"));
29 Stencil close = Font_interface::get_default_font (me)->find_by_name (String ("accidentals-rightparen"));
30 m.add_at_edge (X_AXIS, LEFT, Stencil (open), 0,0);
31 m.add_at_edge (X_AXIS, RIGHT, Stencil (close), 0,0);
37 MAKE_SCHEME_CALLBACK (Accidental_interface,after_line_breaking,1);
39 Accidental_interface::after_line_breaking (SCM smob)
41 Grob *me = unsmob_grob (smob);
42 Grob *tie = unsmob_grob (me->get_property ("tie"));
44 if (tie && !tie->original_)
48 return SCM_UNSPECIFIED;
52 Accidental_interface::accurate_boxes (Grob *a,Grob**common)
55 b[X_AXIS] = a->extent (a, X_AXIS);
56 b[Y_AXIS] = a->extent (a, Y_AXIS);
61 if (to_boolean (a->get_property ("cautionary")))
63 SCM cstyle = a->get_property ("cautionary-style");
64 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 (!ly_c_symbol_p (scm_style)
72 && scm_ilength (accs) == 1)
74 if (ly_scm2int (ly_car (accs)) == FLAT)
80 we could make the stem thinner, but that places the flats
83 stem[X_AXIS][RIGHT] *= .5;
86 To prevent vertical alignment for 6ths
89 bulb[Y_AXIS][UP] *= .35;
96 TODO: add support for natural, double flat.
103 Offset o (a->relative_coordinate (common[X_AXIS], X_AXIS),
104 a->relative_coordinate (common[Y_AXIS], Y_AXIS));
105 for (int i = boxes.size (); i--;)
107 boxes[i].translate (o);
114 * Some styles do not provide all flavours of accidentals, e.g. there
115 * is currently no sharp accidental in vaticana style. In these cases
116 * this function falls back to one of the other styles.
120 todo: this sort of stuff in Scheme. --hwn.
123 Accidental_interface::get_fontcharname (String style, int alteration)
125 if (alteration == DOUBLE_FLAT
126 || alteration == DOUBLE_SHARP)
128 return to_string (alteration);
131 if (style == "hufnagel")
134 case FLAT: return "hufnagel-1";
135 case 0: return "vaticana0";
136 case SHARP: return "mensural1";
138 if (style == "medicaea")
141 case FLAT: return "medicaea-1";
142 case 0: return "vaticana0";
143 case SHARP: return "mensural1";
145 if (style == "vaticana")
148 case FLAT: return "vaticana-1";
149 case 0: return "vaticana0";
150 case SHARP: return "mensural1";
152 if (style == "mensural")
155 case FLAT: return "mensural-1";
156 case 0: return "vaticana0";
157 case SHARP: return "mensural1";
160 if (style == "neo_mensural")
161 style = ""; // currently same as default
162 if (style == "default")
164 return style + to_string (alteration);
167 MAKE_SCHEME_CALLBACK (Accidental_interface,print,1);
169 Accidental_interface::print (SCM smob)
171 Grob *me = unsmob_grob (smob);
172 bool smaller = false;
175 bool caut = to_boolean (me->get_property ("cautionary"));
178 SCM cstyle = me->get_property ("cautionary-style");
179 parens = ly_c_equal_p (cstyle, ly_symbol2scm ("parentheses"));
180 smaller = ly_c_equal_p (cstyle, ly_symbol2scm ("smaller"));
183 SCM scm_style = me->get_property ("style");
185 if (ly_c_symbol_p (scm_style))
187 style = ly_symbol2string (scm_style);
192 preferably no name for the default style.
200 SCM ac = Font_interface::text_font_alist_chain (me);
201 ac = scm_cons (scm_cons (scm_cons
202 (ly_symbol2scm ("font-size"),
203 scm_int2num (-2)), SCM_EOL),
205 fm = select_font (me->get_paper (), ac);
208 fm = Font_interface::get_default_font (me);
211 for (SCM s = me->get_property ("accidentals");
212 ly_c_pair_p (s); s = ly_cdr (s))
214 int alteration = ly_scm2int (ly_car (s));
215 String font_char = get_fontcharname (style, alteration);
216 Stencil acc (fm->find_by_name ("accidentals-" + font_char));
220 me->warning (_f ("accidental `%s' not found", font_char));
224 mol.add_at_edge (X_AXIS, RIGHT, acc, 0.1,0);
229 mol = parenthesize (me, mol);
231 return mol.smobbed_copy ();
236 ADD_INTERFACE (Accidental_interface, "accidental-interface",
237 "a single accidental",
238 "cautionary cautionary-style style tie accidentals");