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"
14 TODO: insert support for smaller cautionaries, tie-break-reminders.
15 Either here or in new-accidental-engraver.
17 'accidentals should go, for a single 'accidental property -- see
18 accidental-placement.cc
24 parenthesize (Grob*me, Molecule m)
26 Molecule open = Font_interface::get_default_font (me)->find_by_name (String ("accidentals-leftparen"));
27 Molecule close = Font_interface::get_default_font (me)->find_by_name (String ("accidentals-rightparen"));
28 m.add_at_edge (X_AXIS, LEFT, Molecule (open), 0,0);
29 m.add_at_edge (X_AXIS, RIGHT, Molecule (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_grob_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_grob_property ("cautionary")))
61 SCM cstyle = a->get_grob_property ("cautionary-style");
62 parens = gh_equal_p (cstyle, ly_symbol2scm ("parentheses"));
66 SCM accs = a->get_grob_property ("accidentals");
67 SCM scm_style = a->get_grob_property ("style");
68 if (!gh_symbol_p (scm_style)
70 && scm_ilength (accs) == 1)
72 if (gh_scm2int (gh_car (accs)) == -1)
78 we could make the stem thinner, but that places the flats
81 stem[X_AXIS][RIGHT] *= .5;
82 bulb[Y_AXIS][UP] *= .35;
88 TODO: add support for natural, double flat.
95 Offset o (a->relative_coordinate (common[X_AXIS], X_AXIS),
96 a->relative_coordinate (common[Y_AXIS], Y_AXIS));
97 for(int i = boxes.size(); i--;)
99 boxes[i].translate(o);
106 * Some styles do not provide all flavours of accidentals, e.g. there
107 * is currently no sharp accidental in vaticana style. In these cases
108 * this function falls back to one of the other styles.
111 Accidental_interface::get_fontcharname(String style, int alteration)
113 if (style == "hufnagel")
116 case -2: return "-2";
117 case -1: return "hufnagel-1";
118 case 0: return "vaticana0";
119 case 1: return "mensural1";
122 if (style == "medicaea")
125 case -2: return "-2";
126 case -1: return "medicaea-1";
127 case 0: return "vaticana0";
128 case 1: return "mensural1";
131 if (style == "vaticana")
134 case -2: return "-2";
135 case -1: return "vaticana-1";
136 case 0: return "vaticana0";
137 case 1: return "mensural1";
140 if (style == "mensural")
143 case -2: return "-2";
144 case -1: return "mensural-1";
145 case 0: return "vaticana0";
146 case 1: return "mensural1";
149 if (style == "neo_mensural")
150 style = ""; // currently same as default
151 if (style == "default")
153 return style + to_string (alteration);
156 MAKE_SCHEME_CALLBACK (Accidental_interface,brew_molecule,1);
158 Accidental_interface::brew_molecule (SCM smob)
160 Grob *me = unsmob_grob (smob);
161 bool smaller = false;
164 bool caut = to_boolean (me->get_grob_property ("cautionary"));
167 SCM cstyle = me->get_grob_property ("cautionary-style");
168 parens = gh_equal_p (cstyle, ly_symbol2scm ("parentheses"));
169 smaller = gh_equal_p (cstyle, ly_symbol2scm ("smaller"));
172 SCM scm_style = me->get_grob_property ("style");
174 if (gh_symbol_p (scm_style))
176 style = ly_symbol2string (scm_style);
181 preferably no name for the default style.
189 SCM ac = Font_interface::font_alist_chain (me);
190 ac = gh_cons (gh_cons (gh_cons
191 (ly_symbol2scm ("font-relative-size"),
192 scm_int2num (-1)), SCM_EOL),
194 fm = select_font (me->get_paper (), ac);
197 fm = Font_interface::get_default_font (me);
200 for (SCM s = me->get_grob_property ("accidentals");
201 gh_pair_p (s); s = gh_cdr (s))
203 int alteration = gh_scm2int (gh_car (s));
204 String font_char = get_fontcharname (style, alteration);
205 Molecule acc (fm->find_by_name ("accidentals-" + font_char));
209 me->warning (_f ("accidental `%s' not found", font_char));
213 mol.add_at_edge (X_AXIS, RIGHT, acc, 0.1,0);
218 mol = parenthesize (me, mol);
220 return mol.smobbed_copy();
225 ADD_INTERFACE (Accidental_interface, "accidental-interface",
226 "a single accidental",
227 "cautionary cautionary-style style tie accidentals");