]> git.donarmstrong.com Git - lilypond.git/blob - lily/abbrev.cc
eb87945cd775fbac66812fdb3a74982a89f005f3
[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@cs.uu.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
17 Abbreviation::Abbreviation ()
18 {
19   stem_l_ = 0;
20   abbrev_flags_i_ = 1;
21 }
22
23 void
24 Abbreviation::do_print () const
25 {
26   DOUT << "abbrev_flags_i_ " << abbrev_flags_i_;
27 }
28
29 Molecule*
30 Abbreviation::brew_molecule_p () const
31 {
32   Real interbeam_f = paper ()->interbeam_f (stem_l_->mult_i_);
33   Real w = 1.5 * lookup_l ()->ball (2).dim_.x ().length ();
34   Real internote_f = paper ()->internote_f ();
35   Real beam_f = paper ()->beam_thickness_f ();
36
37   int beams_i = 0;
38   Real slope_f = internote_f / 4 / internote_f;
39
40   if (stem_l_ && stem_l_->beam_l_) {
41     slope_f = stem_l_->beam_l_->slope_f_;
42     // ugh, rather calc from Abbreviation_req
43     beams_i = stem_l_->beams_right_i_ >? stem_l_->beams_left_i_;
44   } 
45   Real sl = slope_f * internote_f;
46
47   Atom a (lookup_l ()->beam (sl, w, beam_f));
48   a.translate (Offset (-w/2, w / 2 * slope_f));
49
50   Molecule *beams= new Molecule; 
51   for (int i = 0; i < abbrev_flags_i_; i++)
52     {
53       Atom b (a);
54       b.translate_axis (interbeam_f * i, Y_AXIS);
55       beams->add_atom (b);
56     }
57 #define EGCS_ICE
58 #ifndef EGCS_ICE
59   beams->translate_axis (-beams->extent ()[Y_AXIS].center (), Y_AXIS);
60 #else
61   beams->translate_axis (-(beams->extent ()[Y_AXIS].min () + 
62     beams->extent ()[Y_AXIS].max ()) / 2 , Y_AXIS);
63 #endif
64
65   if (stem_l_)
66     { 
67       if (stem_l_->beam_l_)
68         {
69           beams->translate (Offset(stem_l_->hpos_f () - hpos_f (),
70             stem_l_->stem_end_f () * internote_f - 
71             stem_l_->beam_l_->dir_ * beams_i * interbeam_f));
72         }
73       else
74 #if 1
75         {  
76           /*
77             Beams should intersect one beamthickness below staff end
78            */
79           Real dy = - beams->extent ()[Y_AXIS].length () / 2 * stem_l_->dir_;
80           dy /= internote_f;
81           dy += stem_l_->stem_end_f ();
82           dy *= internote_f;
83 // urg: can't: stem should be stetched first
84 //        dy -= paper ()->beam_thickness_f () * stem_l_->dir_;
85           beams->translate (Offset(stem_l_->hpos_f () - hpos_f (), dy));
86         }
87 #else
88         {
89           /* 
90              urg: this is wrong, even if coded correctly
91
92              Try to be in the middle of the open part of the stem and
93              between on the staff.
94
95              (urgh)
96           */
97           Direction sd  = stem_l_->dir_;
98           // watch out: chord_start_f is (the only one) not in dim(internote)
99           Interval empty_stem (stem_l_->chord_start_f () / internote_f * sd
100             + interline_f, (stem_l_->stem_end_f ()* sd));
101           empty_stem *= sd;
102           
103           Interval instaff = empty_stem;
104           /*
105             huh? i don't understand, hw
106             what about:
107             .fly= \stemup d'''2:16
108             instaff.intersect (Interval (-4,4));
109             */
110           // hmm, let's try
111           if (stem_l_->get_default_dir () == stem_l_->dir_)
112             instaff.intersect (Interval (-4,4));
113
114           if (instaff.empty_b ())
115             instaff = empty_stem;
116
117           instaff.print (); 
118           instaff *= internote_f;
119           beams->translate (Offset(stem_l_->hpos_f () - hpos_f (),
120                               instaff.center ()));
121         }
122 #endif
123     }
124   
125   return beams;
126 }
127
128 void
129 Abbreviation::do_substitute_dependent (Score_element*o, Score_element*n)
130 {
131   if (stem_l_ == o)
132     stem_l_ = n ? dynamic_cast<Stem*> (n) : 0;
133 }
134
135
136 void
137 Abbreviation::set_stem (Stem *s)
138 {
139   stem_l_ = s;
140   add_dependency (s);
141 }