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;
90 TODO: add support for natural, double flat.
97 Offset o (a->relative_coordinate (common[X_AXIS], X_AXIS),
98 a->relative_coordinate (common[Y_AXIS], Y_AXIS));
99 for(int i = boxes.size(); i--;)
101 boxes[i].translate(o);
108 * Some styles do not provide all flavours of accidentals, e.g. there
109 * is currently no sharp accidental in vaticana style. In these cases
110 * this function falls back to one of the other styles.
114 todo: this sort of stuff in Scheme. --hwn.
117 Accidental_interface::get_fontcharname (String style, int alteration)
119 if (alteration == DOUBLE_FLAT
120 || alteration == DOUBLE_SHARP)
122 return to_string (alteration);
125 if (style == "hufnagel")
128 case FLAT: return "hufnagel-1";
129 case 0: return "vaticana0";
130 case SHARP: return "mensural1";
132 if (style == "medicaea")
135 case FLAT: return "medicaea-1";
136 case 0: return "vaticana0";
137 case SHARP: return "mensural1";
139 if (style == "vaticana")
142 case FLAT: return "vaticana-1";
143 case 0: return "vaticana0";
144 case SHARP: return "mensural1";
146 if (style == "mensural")
149 case FLAT: return "mensural-1";
150 case 0: return "vaticana0";
151 case SHARP: return "mensural1";
154 if (style == "neo_mensural")
155 style = ""; // currently same as default
156 if (style == "default")
158 return style + to_string (alteration);
161 MAKE_SCHEME_CALLBACK (Accidental_interface,brew_molecule,1);
163 Accidental_interface::brew_molecule (SCM smob)
165 Grob *me = unsmob_grob (smob);
166 bool smaller = false;
169 bool caut = to_boolean (me->get_grob_property ("cautionary"));
172 SCM cstyle = me->get_grob_property ("cautionary-style");
173 parens = gh_equal_p (cstyle, ly_symbol2scm ("parentheses"));
174 smaller = gh_equal_p (cstyle, ly_symbol2scm ("smaller"));
177 SCM scm_style = me->get_grob_property ("style");
179 if (gh_symbol_p (scm_style))
181 style = ly_symbol2string (scm_style);
186 preferably no name for the default style.
194 SCM ac = Font_interface::font_alist_chain (me);
195 ac = gh_cons (gh_cons (gh_cons
196 (ly_symbol2scm ("font-relative-size"),
197 scm_int2num (-1)), SCM_EOL),
199 fm = select_font (me->get_paper (), ac);
202 fm = Font_interface::get_default_font (me);
205 for (SCM s = me->get_grob_property ("accidentals");
206 gh_pair_p (s); s = gh_cdr (s))
208 int alteration = gh_scm2int (gh_car (s));
209 String font_char = get_fontcharname (style, alteration);
210 Molecule acc (fm->find_by_name ("accidentals-" + font_char));
214 me->warning (_f ("accidental `%s' not found", font_char));
218 mol.add_at_edge (X_AXIS, RIGHT, acc, 0.1,0);
223 mol = parenthesize (me, mol);
225 return mol.smobbed_copy();
230 ADD_INTERFACE (Accidental_interface, "accidental-interface",
231 "a single accidental",
232 "cautionary cautionary-style style tie accidentals");