2 accidental.cc -- implement Accidental_interface
4 source file of the GNU LilyPond music typesetter
6 (c) 2001--2009 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);
34 /* If this gets called before line breaking, we will return a non-trivial
35 extent even if we belong to a tie and won't actually get printed. */
37 get_extent (Grob
*me
, Axis a
)
39 Stencil
*s
= unsmob_stencil (Accidental_interface::get_stencil (me
));
42 return ly_interval2scm (s
->extent (a
));
43 return ly_interval2scm (Interval ());
46 MAKE_SCHEME_CALLBACK (Accidental_interface
, height
, 1);
48 Accidental_interface::height (SCM smob
)
50 return get_extent (unsmob_grob (smob
), Y_AXIS
);
53 MAKE_SCHEME_CALLBACK (Accidental_interface
, width
, 1);
55 Accidental_interface::width (SCM smob
)
57 return get_extent (unsmob_grob (smob
), X_AXIS
);
60 MAKE_SCHEME_CALLBACK (Accidental_interface
, pure_height
, 3);
62 Accidental_interface::pure_height (SCM smob
, SCM start_scm
, SCM
)
64 Item
*me
= dynamic_cast<Item
*> (unsmob_grob (smob
));
65 int start
= scm_to_int (start_scm
);
66 int rank
= me
->get_column ()->get_rank ();
68 if (to_boolean (me
->get_property ("forced"))
69 || !unsmob_grob (me
->get_object ("tie"))
70 || (rank
== start
+ 1 && /* we are at the start of a line */
71 !to_boolean (me
->get_property ("hide-tied-accidental-after-break"))))
73 Stencil
*s
= unsmob_stencil (get_stencil (me
));
75 return ly_interval2scm (s
->extent (Y_AXIS
));
78 return ly_interval2scm (Interval ());
82 Accidental_interface::accurate_boxes (Grob
*me
, Grob
**common
)
85 b
[X_AXIS
] = me
->extent (me
, X_AXIS
);
86 b
[Y_AXIS
] = me
->extent (me
, Y_AXIS
);
90 bool parens
= to_boolean (me
->get_property ("parenthesized"));
94 if (!to_boolean (me
->get_property ("restore-first"))
97 SCM alist
= me
->get_property ("glyph-name-alist");
98 SCM alt
= me
->get_property ("alteration");
99 string glyph_name
= robust_scm2string (ly_assoc_get (alt
, alist
, SCM_BOOL_F
),
102 if (glyph_name
== "accidentals.flat"
103 || glyph_name
== "accidentals.mirroredflat")
109 we could make the stem thinner, but that places the flats
113 glyph_name
== "accidentals.mirroredflat" ? LEFT
: RIGHT
;
114 stem
[X_AXIS
][bulb_dir
] = stem
[X_AXIS
].center ();
117 To prevent vertical alignment for 6ths
120 bulb
[Y_AXIS
][UP
] *= .35;
122 boxes
.push_back (bulb
);
123 boxes
.push_back (stem
);
125 else if (glyph_name
== "accidentals.natural")
131 lstem
[Y_AXIS
] *= 1.1;
132 rstem
[Y_AXIS
] *= 1.1;
134 belly
[Y_AXIS
] *= 0.75;
135 lstem
[X_AXIS
][RIGHT
] *= .33;
136 rstem
[X_AXIS
][LEFT
] = rstem
[X_AXIS
].linear_combination (1.0 / 3.0);
137 lstem
[Y_AXIS
][DOWN
] = belly
[Y_AXIS
][DOWN
];
138 rstem
[Y_AXIS
][UP
] = belly
[Y_AXIS
][UP
];
139 boxes
.push_back (belly
);
140 boxes
.push_back (lstem
);
141 boxes
.push_back (rstem
);
144 TODO: add support for, double flat.
151 Offset
o (me
->relative_coordinate (common
[X_AXIS
], X_AXIS
),
152 me
->relative_coordinate (common
[Y_AXIS
], Y_AXIS
));
154 for (vsize i
= boxes
.size (); i
--;)
155 boxes
[i
].translate (o
);
160 MAKE_SCHEME_CALLBACK (Accidental_interface
, print
, 1);
162 Accidental_interface::print (SCM smob
)
164 Grob
*me
= unsmob_grob (smob
);
165 Grob
*tie
= unsmob_grob (me
->get_object ("tie"));
168 (to_boolean (me
->get_property ("hide-tied-accidental-after-break"))
169 || (!tie
->original () && !to_boolean (me
->get_property ("forced")))))
175 return get_stencil (me
);
179 Accidental_interface::get_stencil (Grob
*me
)
181 Font_metric
*fm
= Font_interface::get_default_font (me
);
183 SCM alist
= me
->get_property ("glyph-name-alist");
184 SCM alt
= me
->get_property ("alteration");
185 SCM glyph_name
= ly_assoc_get (alt
, alist
, SCM_BOOL_F
);
187 if (!scm_is_string (glyph_name
))
189 me
->warning (_f ("Could not find glyph-name for alteration %s",
190 ly_scm_write_string (alt
).c_str ()));
194 Stencil
mol (fm
->find_by_name (ly_scm2string (glyph_name
)));
195 if (to_boolean (me
->get_property ("restore-first")))
198 this isn't correct for ancient accidentals, but they don't
199 use double flats/sharps anyway.
201 Stencil
acc (fm
->find_by_name ("accidentals.natural"));
204 me
->warning (_ ("natural alteration glyph not found"));
206 mol
.add_at_edge (X_AXIS
, LEFT
, acc
, 0.1);
209 if (to_boolean (me
->get_property ("parenthesized")))
210 mol
= parenthesize (me
, mol
);
212 return mol
.smobbed_copy ();
216 ADD_INTERFACE (Accidental_interface
,
217 "A single accidental.",
224 "hide-tied-accidental-after-break "