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, 0);
29 m.add_at_edge (X_AXIS, RIGHT, Stencil (close), 0, 0);
35 Hmm. Need separate callback, or perhaps #'live bool property.
37 MAKE_SCHEME_CALLBACK (Accidental_interface, after_line_breaking, 1);
39 Accidental_interface::after_line_breaking (SCM smob)
41 Grob *me = unsmob_grob (smob);
42 Grob *tie = unsmob_grob (me->get_object ("tie"));
44 if (tie && !tie->original ()
45 && !to_boolean (me->get_property ("forced")))
50 return SCM_UNSPECIFIED;
53 /* This callback exists for the sole purpose of allowing us to override
54 its pure equivalent to accidental-interface::pure-height */
55 MAKE_SCHEME_CALLBACK (Accidental_interface, height, 1);
57 Accidental_interface::height (SCM smob)
59 return Grob::stencil_height (smob);
62 MAKE_SCHEME_CALLBACK (Accidental_interface, pure_height, 3);
64 Accidental_interface::pure_height (SCM smob, SCM start_scm, SCM)
66 Item *me = dynamic_cast<Item*> (unsmob_grob (smob));
67 int start = scm_to_int (start_scm);
68 int rank = me->get_column ()->get_rank ();
70 bool visible = to_boolean (me->get_property ("forced"))
71 || !unsmob_grob (me->get_object ("tie"))
72 || rank != start + 1; /* we are in the middle of a line */
74 return visible ? Grob::stencil_height (smob) : ly_interval2scm (Interval ());
78 Accidental_interface::accurate_boxes (Grob *me, Grob **common)
81 b[X_AXIS] = me->extent (me, X_AXIS);
82 b[Y_AXIS] = me->extent (me, Y_AXIS);
86 bool parens = to_boolean (me->get_property ("parenthesized"));
88 SCM scm_style = me->get_property ("style");
89 if (!scm_is_symbol (scm_style)
90 && !to_boolean (me->get_property ("restore-first"))
93 Rational alteration = ly_scm2rational (me->get_property ("alteration"));
94 if (alteration == FLAT_ALTERATION)
100 we could make the stem thinner, but that places the flats
103 stem[X_AXIS][RIGHT] *= .5;
106 To prevent vertical alignment for 6ths
109 bulb[Y_AXIS][UP] *= .35;
111 boxes.push_back (bulb);
112 boxes.push_back (stem);
114 else if (alteration == NATURAL_ALTERATION)
120 lstem[Y_AXIS] *= 1.1;
121 rstem[Y_AXIS] *= 1.1;
123 belly[Y_AXIS] *= 0.75;
124 lstem[X_AXIS][RIGHT] *= .33;
125 rstem[X_AXIS][LEFT] = rstem[X_AXIS].linear_combination (1.0 / 3.0);
126 lstem[Y_AXIS][DOWN] = belly[Y_AXIS][DOWN];
127 rstem[Y_AXIS][UP] = belly[Y_AXIS][UP];
128 boxes.push_back (belly);
129 boxes.push_back (lstem);
130 boxes.push_back (rstem);
133 TODO: add support for, double flat.
140 Offset o (me->relative_coordinate (common[X_AXIS], X_AXIS),
141 me->relative_coordinate (common[Y_AXIS], Y_AXIS));
143 for (vsize i = boxes.size (); i--;)
144 boxes[i].translate (o);
149 MAKE_SCHEME_CALLBACK (Accidental_interface, print, 1);
151 Accidental_interface::print (SCM smob)
153 Grob *me = unsmob_grob (smob);
155 Font_metric *fm = Font_interface::get_default_font (me);
157 SCM alist = me->get_property ("glyph-name-alist");
158 SCM alt = me->get_property ("alteration");
159 SCM glyph_name = ly_assoc_get (alt, alist, SCM_BOOL_F);
161 if (!scm_is_string (glyph_name))
163 me->warning (_f ("Could not find glyph-name for alteration %s",
164 ly_scm2rational (alt).to_string ().c_str ()));
168 Stencil mol (fm->find_by_name (scm_i_string_chars (glyph_name)));
169 if (to_boolean (me->get_property ("restore-first")))
172 this isn't correct for ancient accidentals, but they don't
173 use double flats/sharps anyway.
175 Stencil acc (fm->find_by_name ("accidentals.natural"));
178 me->warning (_ ("natural alteration glyph not found"));
180 mol.add_at_edge (X_AXIS, LEFT, acc, 0.1, 0);
183 if (to_boolean (me->get_property ("parenthesized")))
184 mol = parenthesize (me, mol);
186 return mol.smobbed_copy ();
190 ADD_INTERFACE (Accidental_interface,
191 "a single accidental",