lilypond-1.3.67
[lilypond.git] / lily / beaming-info.cc
blob9b92ddeb1a37987158be625144dba824685f06e7
1 /*
2 beaming-info.cc -- implement Beaming_info, Beaming_info_list
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
10 #include "beaming.hh"
12 Beaming_info::Beaming_info( )
14 start_mom_ = 0;
15 beams_i_drul_[LEFT] = 0;
16 beams_i_drul_[RIGHT] = 0;
19 Beaming_info::Beaming_info(Moment m, int i)
21 start_mom_ = m;
22 beams_i_drul_[LEFT] = i;
23 beams_i_drul_[RIGHT] = i;
26 const int infinity_i = INT_MAX; // guh.
28 int
29 Beaming_info_list::min_denominator_index () const
31 int minden = infinity_i;
32 int minidx = -1;
34 for (int i=1; i < infos_.size ( ); i++)
36 if (infos_[i].start_mom_.den_i () < minden)
38 minidx = i;
39 minden = infos_[i].start_mom_.den_i ();
43 return minidx;
46 int
47 Beaming_info_list::beam_extend_count (Direction d) const
49 if (infos_.size () == 1)
50 return infos_[0].beams_i_drul_[d];
52 Beaming_info thisbeam = infos_.boundary (d, 0);
53 Beaming_info next = infos_.boundary (d, 1);
55 return thisbeam.beams_i_drul_[-d] <? next.beams_i_drul_[d];
58 void
59 Beaming_info_list::beamify ()
61 if (infos_.size () <= 1)
62 return;
64 Drul_array<Beaming_info_list> splits;
65 int m = min_denominator_index ();
66 splits[LEFT].infos_ = infos_.slice (0,m);
67 splits[RIGHT].infos_ = infos_.slice (m, infos_.size ());
69 Direction d = LEFT;
73 splits[d].beamify ();
75 while (flip (&d) != LEFT);
77 int middle_beams = splits[RIGHT].beam_extend_count (LEFT) <?
78 splits[LEFT].beam_extend_count (RIGHT);
82 if (splits[d].infos_.size () != 1)
84 splits[d].infos_.boundary (-d, 0).beams_i_drul_[-d] = middle_beams;
87 while (flip (&d) != LEFT);
89 infos_ = splits[LEFT].infos_;
90 infos_.concat (splits[RIGHT].infos_);
93 void
94 Beaming_info_list::add_stem (Moment m, int b)
96 infos_.push (Beaming_info (m, b));