]> git.donarmstrong.com Git - lilypond.git/blob - lily/abbrev.cc
release: 0.1.61
[lilypond.git] / lily / abbrev.cc
1 /*   
2   abbrev.cc --  implement Abbreviation
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c)  1997--1998 Han-Wen Nienhuys <hanwen@stack.nl>
7   
8  */
9
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"
17
18 Abbreviation::Abbreviation ()
19 {
20   stem_l_ = 0;
21   abbrev_flags_i_ = 1;
22 }
23
24 void
25 Abbreviation::do_print () const
26 {
27   DOUT << "abbrev_flags_i_ " << abbrev_flags_i_;
28 }
29
30 Molecule*
31 Abbreviation::brew_molecule_p () const
32 {
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;
37
38   int beams_i = 0;
39   Real slope_f = paper ()->internote_f () / 4;
40
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_;
46   }
47   paper ()->lookup_l ()->beam (slope_f, 20 PT, 1 PT);
48
49   Atom a (paper ()->lookup_l ()->beam (slope_f, w, .48 * interline_f));
50   a.translate (Offset (-w/2, w / 2 * slope_f));
51
52   Molecule *beams= new Molecule; 
53   for (int i = 0; i < abbrev_flags_i_; i++)
54     {
55       Atom b (a);
56       b.translate_axis (dy * i, Y_AXIS);
57       beams->add (b);
58     }
59   beams->translate_axis (-beams->extent ()[Y_AXIS].center (), Y_AXIS);
60
61   if (stem_l_)
62     {
63       /* Try to be in the middle of the open part of the stem and
64          between on the staff.
65
66          (urgh)
67       */
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;
72       
73       Interval instaff = empty_stem;
74       instaff.intersect (interline_f * Interval (-2,2));
75       if (instaff.empty_b ())
76         instaff = empty_stem;
77
78       instaff.print (); 
79       beams->translate (Offset(stem_l_->hpos_f () - hpos_f (),
80                           instaff.center ()));
81     }
82   
83   return beams;
84 }
85
86 void
87 Abbreviation::do_substitute_dependent (Score_elem*o, Score_elem*n)
88 {
89   if (stem_l_ == o)
90     stem_l_ = n ? (Stem*)n->item () : 0;
91 }
92
93
94 void
95 Abbreviation::set_stem (Stem *s)
96 {
97   stem_l_ = s;
98   add_dependency (s);
99 }