2 beaming-info.cc -- implement Beaming_info, Beaming_info_list
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
12 Beaming_info::Beaming_info ()
15 beams_i_drul_
[LEFT
] = 0;
16 beams_i_drul_
[RIGHT
] = 0;
19 Beaming_info::Beaming_info (Moment m
, int i
)
22 beams_i_drul_
[LEFT
] = i
;
23 beams_i_drul_
[RIGHT
] = i
;
26 const int infinity_i
= INT_MAX
; // guh.
27 const int at_beat
= 1<<15;
30 Beaming_info_list::best_splitpoint_index (Moment
&beat_length
,bool subdivide
) const
32 int minden
= infinity_i
;
36 for (int i
=1; i
< infos_
.size (); i
++)
38 beat_pos
= infos_
[i
].start_mom_
/ beat_length
;
39 int den
= beat_pos
.den ();
40 if (infos_
[i
].beams_i_drul_
[LEFT
] == infos_
[i
-1].beams_i_drul_
[RIGHT
] && !subdivide
)
49 return minidx
|(minden
==1 && subdivide
? at_beat
: 0);
53 Beaming_info_list::beam_extend_count (Direction d
) const
55 if (infos_
.size () == 1)
56 return infos_
[0].beams_i_drul_
[d
];
58 Beaming_info thisbeam
= infos_
.boundary (d
, 0);
59 Beaming_info next
= infos_
.boundary (d
, 1);
61 return thisbeam
.beams_i_drul_
[-d
] <? next
.beams_i_drul_
[d
];
65 Beaming_info_list::beamify (Moment
&beat_length
,bool subdivide
)
67 if (infos_
.size () <= 1)
70 Drul_array
<Beaming_info_list
> splits
;
71 int m
= best_splitpoint_index (beat_length
,subdivide
);
72 bool split
= subdivide
&& (m
& at_beat
); m
= m
& ~at_beat
;
73 splits
[LEFT
].infos_
= infos_
.slice (0,m
);
74 splits
[RIGHT
].infos_
= infos_
.slice (m
, infos_
.size ());
80 splits
[d
].beamify (beat_length
,subdivide
);
82 while (flip (&d
) != LEFT
);
84 int middle_beams
= (split
? 1 :
85 splits
[RIGHT
].beam_extend_count (LEFT
) <?
86 splits
[LEFT
].beam_extend_count (RIGHT
));
90 if (splits
[d
].infos_
.size () != 1)
91 splits
[d
].infos_
.boundary (-d
, 0).beams_i_drul_
[-d
] = middle_beams
;
93 while (flip (&d
) != LEFT
);
95 infos_
= splits
[LEFT
].infos_
;
96 infos_
.concat (splits
[RIGHT
].infos_
);
100 Beaming_info_list::add_stem (Moment m
, int b
)
102 infos_
.push (Beaming_info (m
, b
));