lilypond-0.1.59
[lilypond.git] / lily / abbrev.cc
blobd91899c75656fea84879e996c1f4da3f36e30f8e
1 /*
2 abbrev.cc -- implement Abbreviation
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
8 */
10 #include "abbrev.hh"
11 #include "debug.hh"
12 #include "beam.hh"
13 #include "paper-def.hh"
14 #include "lookup.hh"
15 #include "stem.hh"
16 #include "dimen.hh"
18 Abbreviation::Abbreviation ()
20 stem_l_ = 0;
21 abbrev_flags_i_ = 1;
24 void
25 Abbreviation::do_print () const
27 DOUT << "abbrev_flags_i_ " << abbrev_flags_i_;
30 Molecule*
31 Abbreviation::brew_molecule_p () const
33 Real dy = paper ()->interbeam_f ();
34 Real w = 1.5 * paper ()->lookup_l ()->ball (2).dim_.x ().length ();
35 Real interline_f = paper ()->interline_f ();
36 Real beamdy = interline_f/2;
38 int beams_i = 0;
39 Real slope_f = paper ()->internote_f () / 4;
41 if (stem_l_ && stem_l_->beam_l_) {
42 // huh?
43 slope_f = 2 * stem_l_->beam_l_->slope_f_;
44 // ugh, rather calc from Abbreviation_req
45 beams_i = stem_l_->beams_right_i_ >? stem_l_->beams_left_i_;
47 paper ()->lookup_l ()->beam (slope_f, 20 PT, 1 PT);
49 Atom a (paper ()->lookup_l ()->beam (slope_f, w, .48 * interline_f));
50 a.translate (Offset (-w/2, w / 2 * slope_f));
52 Molecule *beams= new Molecule;
53 for (int i = 0; i < abbrev_flags_i_; i++)
55 Atom b (a);
56 b.translate_axis (dy * i, Y_AXIS);
57 beams->add (b);
59 beams->translate_axis (-beams->extent ()[Y_AXIS].center (), Y_AXIS);
61 if (stem_l_)
63 /* Try to be in the middle of the open part of the stem and
64 between on the staff.
66 (urgh)
68 Direction sd = stem_l_->dir_;
69 Interval empty_stem (stem_l_->chord_start_f () * sd ,
70 (stem_l_->stem_end_f ()* sd) - beams_i * dy);
71 empty_stem *= sd;
73 Interval instaff = empty_stem;
74 instaff.intersect (interline_f * Interval (-2,2));
75 if (instaff.empty_b ())
76 instaff = empty_stem;
78 instaff.print ();
79 beams->translate (Offset(stem_l_->hpos_f () - hpos_f (),
80 instaff.center ()));
83 return beams;
86 void
87 Abbreviation::do_substitute_dependent (Score_elem*o, Score_elem*n)
89 if (stem_l_ == o)
90 stem_l_ = n ? (Stem*)n->item () : 0;
94 void
95 Abbreviation::set_stem (Stem *s)
97 stem_l_ = s;
98 add_dependency (s);