2 accidental.cc -- implement Accidental_interface
4 source file of the GNU LilyPond music typesetter
6 (c) 2001--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #include "accidental-interface.hh"
10 #include "font-interface.hh"
11 #include "international.hh"
13 #include "output-def.hh"
14 #include "paper-column.hh"
19 parenthesize (Grob *me, Stencil m)
22 = Font_interface::get_default_font (me);
24 = font->find_by_name ("accidentals.leftparen");
26 = font->find_by_name ("accidentals.rightparen");
28 m.add_at_edge (X_AXIS, LEFT, Stencil (open), 0);
29 m.add_at_edge (X_AXIS, RIGHT, Stencil (close), 0);
35 /* This callback exists for the sole purpose of allowing us to override
36 its pure equivalent to accidental-interface::pure-height */
37 MAKE_SCHEME_CALLBACK (Accidental_interface, height, 1);
39 Accidental_interface::height (SCM smob)
41 return Grob::stencil_height (smob);
44 MAKE_SCHEME_CALLBACK (Accidental_interface, pure_height, 3);
46 Accidental_interface::pure_height (SCM smob, SCM start_scm, SCM)
48 Item *me = dynamic_cast<Item*> (unsmob_grob (smob));
49 int start = scm_to_int (start_scm);
50 int rank = me->get_column ()->get_rank ();
52 bool visible = to_boolean (me->get_property ("forced"))
53 || !unsmob_grob (me->get_object ("tie"))
54 || rank != start + 1; /* we are in the middle of a line */
56 return visible ? Grob::stencil_height (smob) : ly_interval2scm (Interval ());
60 Accidental_interface::accurate_boxes (Grob *me, Grob **common)
63 b[X_AXIS] = me->extent (me, X_AXIS);
64 b[Y_AXIS] = me->extent (me, Y_AXIS);
68 bool parens = to_boolean (me->get_property ("parenthesized"));
72 SCM scm_style = me->get_property ("style");
73 if (!scm_is_symbol (scm_style)
74 && !to_boolean (me->get_property ("restore-first"))
78 = robust_scm2rational (me->get_property ("alteration"), 0);
79 if (alteration == FLAT_ALTERATION)
85 we could make the stem thinner, but that places the flats
88 stem[X_AXIS][RIGHT] *= .5;
91 To prevent vertical alignment for 6ths
94 bulb[Y_AXIS][UP] *= .35;
96 boxes.push_back (bulb);
97 boxes.push_back (stem);
99 else if (alteration == NATURAL_ALTERATION)
105 lstem[Y_AXIS] *= 1.1;
106 rstem[Y_AXIS] *= 1.1;
108 belly[Y_AXIS] *= 0.75;
109 lstem[X_AXIS][RIGHT] *= .33;
110 rstem[X_AXIS][LEFT] = rstem[X_AXIS].linear_combination (1.0 / 3.0);
111 lstem[Y_AXIS][DOWN] = belly[Y_AXIS][DOWN];
112 rstem[Y_AXIS][UP] = belly[Y_AXIS][UP];
113 boxes.push_back (belly);
114 boxes.push_back (lstem);
115 boxes.push_back (rstem);
118 TODO: add support for, double flat.
125 Offset o (me->relative_coordinate (common[X_AXIS], X_AXIS),
126 me->relative_coordinate (common[Y_AXIS], Y_AXIS));
128 for (vsize i = boxes.size (); i--;)
129 boxes[i].translate (o);
134 MAKE_SCHEME_CALLBACK (Accidental_interface, print, 1);
136 Accidental_interface::print (SCM smob)
138 Grob *me = unsmob_grob (smob);
139 Grob *tie = unsmob_grob (me->get_object ("tie"));
141 if (tie && !tie->original ()
142 && !to_boolean (me->get_property ("forced")))
148 Font_metric *fm = Font_interface::get_default_font (me);
150 SCM alist = me->get_property ("glyph-name-alist");
151 SCM alt = me->get_property ("alteration");
152 SCM glyph_name = ly_assoc_get (alt, alist, SCM_BOOL_F);
154 if (!scm_is_string (glyph_name))
156 me->warning (_f ("Could not find glyph-name for alteration %s",
157 ly_scm_write_string (alt).c_str ()));
161 Stencil mol (fm->find_by_name (scm_i_string_chars (glyph_name)));
162 if (to_boolean (me->get_property ("restore-first")))
165 this isn't correct for ancient accidentals, but they don't
166 use double flats/sharps anyway.
168 Stencil acc (fm->find_by_name ("accidentals.natural"));
171 me->warning (_ ("natural alteration glyph not found"));
173 mol.add_at_edge (X_AXIS, LEFT, acc, 0.1);
176 if (to_boolean (me->get_property ("parenthesized")))
177 mol = parenthesize (me, mol);
179 return mol.smobbed_copy ();
183 ADD_INTERFACE (Accidental_interface,
184 "a single accidental",