2 accidental.cc -- implement Accidental_interface
4 (c) 2001--2003 Han-Wen Nienhuys
7 #include "font-interface.hh"
10 #include "accidental-interface.hh"
11 #include "paper-def.hh"
15 TODO: insert support for smaller cautionaries, tie-break-reminders.
16 Either here or in new-accidental-engraver.
18 'accidentals should go, for a single 'accidental property -- see
19 accidental-placement.cc
25 parenthesize (Grob*me, Molecule m)
27 Molecule open = Font_interface::get_default_font (me)->find_by_name (String ("accidentals-leftparen"));
28 Molecule close = Font_interface::get_default_font (me)->find_by_name (String ("accidentals-rightparen"));
29 m.add_at_edge (X_AXIS, LEFT, Molecule (open), 0,0);
30 m.add_at_edge (X_AXIS, RIGHT, Molecule (close), 0,0);
36 MAKE_SCHEME_CALLBACK (Accidental_interface,after_line_breaking,1);
38 Accidental_interface::after_line_breaking (SCM smob)
40 Grob *me = unsmob_grob (smob);
41 Grob *tie = unsmob_grob (me->get_grob_property ("tie"));
43 if (tie && !tie->original_)
47 return SCM_UNSPECIFIED;
51 Accidental_interface::accurate_boxes (Grob *a,Grob**common)
54 b[X_AXIS] = a->extent (a, X_AXIS);
55 b[Y_AXIS] = a->extent (a, Y_AXIS);
60 if (to_boolean (a->get_grob_property ("cautionary")))
62 SCM cstyle = a->get_grob_property ("cautionary-style");
63 parens = gh_equal_p (cstyle, ly_symbol2scm ("parentheses"));
67 SCM accs = a->get_grob_property ("accidentals");
68 SCM scm_style = a->get_grob_property ("style");
69 if (!gh_symbol_p (scm_style)
71 && scm_ilength (accs) == 1)
73 if (gh_scm2int (gh_car (accs)) == FLAT)
79 we could make the stem thinner, but that places the flats
82 stem[X_AXIS][RIGHT] *= .5;
83 bulb[Y_AXIS][UP] *= .35;
89 TODO: add support for natural, double flat.
96 Offset o (a->relative_coordinate (common[X_AXIS], X_AXIS),
97 a->relative_coordinate (common[Y_AXIS], Y_AXIS));
98 for(int i = boxes.size(); i--;)
100 boxes[i].translate(o);
107 * Some styles do not provide all flavours of accidentals, e.g. there
108 * is currently no sharp accidental in vaticana style. In these cases
109 * this function falls back to one of the other styles.
113 todo: this sort of stuff in Scheme. --hwn.
116 Accidental_interface::get_fontcharname (String style, int alteration)
118 if (alteration == DOUBLE_FLAT
119 || alteration == DOUBLE_SHARP)
121 return to_string (alteration);
124 if (style == "hufnagel")
127 case FLAT: return "hufnagel-1";
128 case 0: return "vaticana0";
129 case SHARP: return "mensural1";
131 if (style == "medicaea")
134 case FLAT: return "medicaea-1";
135 case 0: return "vaticana0";
136 case SHARP: return "mensural1";
138 if (style == "vaticana")
141 case FLAT: return "vaticana-1";
142 case 0: return "vaticana0";
143 case SHARP: return "mensural1";
145 if (style == "mensural")
148 case FLAT: return "mensural-1";
149 case 0: return "vaticana0";
150 case SHARP: return "mensural1";
153 if (style == "neo_mensural")
154 style = ""; // currently same as default
155 if (style == "default")
157 return style + to_string (alteration);
160 MAKE_SCHEME_CALLBACK (Accidental_interface,brew_molecule,1);
162 Accidental_interface::brew_molecule (SCM smob)
164 Grob *me = unsmob_grob (smob);
165 bool smaller = false;
168 bool caut = to_boolean (me->get_grob_property ("cautionary"));
171 SCM cstyle = me->get_grob_property ("cautionary-style");
172 parens = gh_equal_p (cstyle, ly_symbol2scm ("parentheses"));
173 smaller = gh_equal_p (cstyle, ly_symbol2scm ("smaller"));
176 SCM scm_style = me->get_grob_property ("style");
178 if (gh_symbol_p (scm_style))
180 style = ly_symbol2string (scm_style);
185 preferably no name for the default style.
193 SCM ac = Font_interface::font_alist_chain (me);
194 ac = gh_cons (gh_cons (gh_cons
195 (ly_symbol2scm ("font-relative-size"),
196 scm_int2num (-1)), SCM_EOL),
198 fm = select_font (me->get_paper (), ac);
201 fm = Font_interface::get_default_font (me);
204 for (SCM s = me->get_grob_property ("accidentals");
205 gh_pair_p (s); s = gh_cdr (s))
207 int alteration = gh_scm2int (gh_car (s));
208 String font_char = get_fontcharname (style, alteration);
209 Molecule acc (fm->find_by_name ("accidentals-" + font_char));
213 me->warning (_f ("accidental `%s' not found", font_char));
217 mol.add_at_edge (X_AXIS, RIGHT, acc, 0.1,0);
222 mol = parenthesize (me, mol);
224 return mol.smobbed_copy();
229 ADD_INTERFACE (Accidental_interface, "accidental-interface",
230 "a single accidental",
231 "cautionary cautionary-style style tie accidentals");