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
24 parenthesize (Grob*me, Stencil m)
26 Stencil open = Font_interface::get_default_font (me)->find_by_name (String ("accidentals-leftparen"));
27 Stencil close = Font_interface::get_default_font (me)->find_by_name (String ("accidentals-rightparen"));
28 m.add_at_edge (X_AXIS, LEFT, Stencil (open), 0,0);
29 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 (!ly_c_symbol_p (scm_style)
69 && scm_ilength (accs) == 1)
71 if (ly_scm2int (ly_car (accs)) == FLAT)
77 we could make the stem thinner, but that places the flats
80 stem[X_AXIS][RIGHT] *= .5;
83 To prevent vertical alignment for 6ths
86 bulb[Y_AXIS][UP] *= .35;
93 TODO: add support for natural, double flat.
100 Offset o (a->relative_coordinate (common[X_AXIS], X_AXIS),
101 a->relative_coordinate (common[Y_AXIS], Y_AXIS));
102 for (int i = boxes.size (); i--;)
104 boxes[i].translate (o);
111 * Some styles do not provide all flavours of accidentals, e.g. there
112 * is currently no sharp accidental in vaticana style. In these cases
113 * this function falls back to one of the other styles.
117 todo: this sort of stuff in Scheme. --hwn.
120 Accidental_interface::get_fontcharname (String style, int alteration)
122 if (alteration == DOUBLE_FLAT
123 || alteration == DOUBLE_SHARP)
125 return to_string (alteration);
128 if (style == "hufnagel")
131 case FLAT: return "hufnagel-1";
132 case 0: return "vaticana0";
133 case SHARP: return "mensural1";
135 if (style == "medicaea")
138 case FLAT: return "medicaea-1";
139 case 0: return "vaticana0";
140 case SHARP: return "mensural1";
142 if (style == "vaticana")
145 case FLAT: return "vaticana-1";
146 case 0: return "vaticana0";
147 case SHARP: return "mensural1";
149 if (style == "mensural")
152 case FLAT: return "mensural-1";
153 case 0: return "vaticana0";
154 case SHARP: return "mensural1";
157 if (style == "neo_mensural")
158 style = ""; // currently same as default
159 if (style == "default")
161 return style + to_string (alteration);
164 MAKE_SCHEME_CALLBACK (Accidental_interface,print,1);
166 Accidental_interface::print (SCM smob)
168 Grob *me = unsmob_grob (smob);
169 bool smaller = false;
172 bool caut = to_boolean (me->get_property ("cautionary"));
175 SCM cstyle = me->get_property ("cautionary-style");
176 parens = ly_c_equal_p (cstyle, ly_symbol2scm ("parentheses"));
177 smaller = ly_c_equal_p (cstyle, ly_symbol2scm ("smaller"));
180 SCM scm_style = me->get_property ("style");
182 if (ly_c_symbol_p (scm_style))
184 style = ly_symbol2string (scm_style);
189 preferably no name for the default style.
197 SCM ac = Font_interface::music_font_alist_chain (me);
198 ac = scm_cons (scm_list_1 (scm_cons
199 (ly_symbol2scm ("font-size"),
202 fm = select_font (me->get_paper (), ac);
205 fm = Font_interface::get_default_font (me);
208 for (SCM s = me->get_property ("accidentals");
209 ly_c_pair_p (s); s = ly_cdr (s))
211 int alteration = ly_scm2int (ly_car (s));
212 String font_char = get_fontcharname (style, alteration);
213 Stencil acc (fm->find_by_name ("accidentals-" + font_char));
217 me->warning (_f ("accidental `%s' not found", font_char));
221 mol.add_at_edge (X_AXIS, RIGHT, acc, 0.1,0);
226 mol = parenthesize (me, mol);
228 return mol.smobbed_copy ();
233 ADD_INTERFACE (Accidental_interface, "accidental-interface",
234 "a single accidental",
235 "cautionary cautionary-style style tie accidentals");