2 beaming-info.cc -- implement Beaming_info, Beaming_info_list
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 Beaming_info::Beaming_info ()
14 beams_i_drul_[LEFT] = 0;
15 beams_i_drul_[RIGHT] = 0;
18 Beaming_info::Beaming_info (Moment m, int i)
21 beams_i_drul_[LEFT] = i;
22 beams_i_drul_[RIGHT] = i;
25 const int infinity_i = INT_MAX; // guh.
26 const int at_beat = 1<<15;
29 Beaming_info_list::best_splitpoint_index (Moment &beat_length, bool subdivide) const
31 int minden = infinity_i;
35 for (int i = 1; i < infos_.size (); i++)
37 beat_pos = infos_[i].start_mom_ / beat_length;
38 int den = beat_pos.den ();
39 if (infos_[i].beams_i_drul_[LEFT] == infos_[i - 1].beams_i_drul_[RIGHT] && !subdivide)
48 return minidx | (minden == 1 && subdivide ? at_beat : 0);
52 Beaming_info_list::beam_extend_count (Direction d) const
54 if (infos_.size () == 1)
55 return infos_[0].beams_i_drul_[d];
57 Beaming_info thisbeam = infos_.boundary (d, 0);
58 Beaming_info next = infos_.boundary (d, 1);
60 return thisbeam.beams_i_drul_[-d] <? next.beams_i_drul_[d];
64 Beaming_info_list::beamify (Moment &beat_length, bool subdivide)
66 if (infos_.size () <= 1)
69 Drul_array<Beaming_info_list> splits;
70 int m = best_splitpoint_index (beat_length, subdivide);
71 bool split = subdivide && (m & at_beat); m = m & ~at_beat;
72 splits[LEFT].infos_ = infos_.slice (0, m);
73 splits[RIGHT].infos_ = infos_.slice (m, infos_.size ());
79 splits[d].beamify (beat_length, subdivide);
81 while (flip (&d) != LEFT);
83 int middle_beams = (split ? 1
84 : splits[RIGHT].beam_extend_count (LEFT) <?
85 splits[LEFT].beam_extend_count (RIGHT));
89 if (splits[d].infos_.size () != 1)
90 splits[d].infos_.boundary (-d, 0).beams_i_drul_[-d] = middle_beams;
92 while (flip (&d) != LEFT);
94 infos_ = splits[LEFT].infos_;
95 infos_.concat (splits[RIGHT].infos_);
99 Beaming_info_list::add_stem (Moment m, int b)
101 infos_.push (Beaming_info (m, b));