]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/beam.hh
2b877ad644b6c2b34357cca84f46a69a84e229ed
[lilypond.git] / lily / include / beam.hh
1 /*
2   beam.hh -- part of GNU LilyPond
3
4   source file of the LilyPond music typesetter
5
6   (c) 1996--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
7   Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9
10 #ifndef BEAM_HH
11 #define BEAM_HH
12
13 #include "grob-interface.hh"
14 #include "std-vector.hh"
15 #include "lily-proto.hh"
16 #include "stem-info.hh"
17
18 /*
19   TODO: move quanting in separate file.
20 */
21 struct Beam_quant_parameters
22 {
23   Real SECONDARY_BEAM_DEMERIT;
24   Real STEM_LENGTH_DEMERIT_FACTOR;
25   Real REGION_SIZE;
26
27   /*
28     threshold to combat rounding errors.
29   */
30   Real BEAM_EPS;
31
32   // possibly ridiculous, but too short stems just won't do
33   Real STEM_LENGTH_LIMIT_PENALTY;
34   Real DAMPING_DIRECTION_PENALTY;
35   Real MUSICAL_DIRECTION_FACTOR;
36   Real HINT_DIRECTION_PENALTY;
37   Real IDEAL_SLOPE_FACTOR;
38   Real ROUND_TO_ZERO_SLOPE;
39
40   void fill (Grob *him);
41 };
42
43 struct Beam_segment
44 {
45   int vertical_count_;
46   Interval horizontal_; 
47   Beam_segment ();
48 };
49
50 struct Beam_stem_segment 
51 {
52   Beam_stem_segment ();
53
54   Grob *stem_;
55   Real width_;
56   Real stem_x_;
57   int rank_;
58   vsize stem_index_;
59   bool gapped_;
60   Direction dir_;
61   int max_connect_;
62   
63 };
64
65
66 bool operator <(Beam_stem_segment const &a, Beam_stem_segment const &b);
67
68 class Beam
69 {
70 public:
71   static int normal_stem_count (Grob *);
72   static Grob *first_normal_stem (Grob *);
73   static Grob *last_normal_stem (Grob *);
74   DECLARE_GROB_INTERFACE();
75   static void add_stem (Grob *, Grob *);
76   static bool is_cross_staff (Grob *);
77   static bool is_knee (Grob *);
78   static void set_beaming (Grob *, Beaming_pattern const *);
79   static void set_stemlens (Grob *);
80   static int get_beam_count (Grob *me);
81   static Real get_beam_translation (Grob *me);
82   static Real get_beam_thickness (Grob *me);
83   static void connect_beams (Grob *me);
84   static vector<Beam_segment> get_beam_segments (Grob *me_grob, Grob **common); 
85   static Interval no_visible_stem_positions (Grob *me, Interval default_value);
86   
87   DECLARE_SCHEME_CALLBACK (rest_collision_callback, (SCM element, SCM prev_off));
88   DECLARE_SCHEME_CALLBACK (print, (SCM));
89   DECLARE_SCHEME_CALLBACK (calc_beaming, (SCM));
90   DECLARE_SCHEME_CALLBACK (calc_stem_shorten, (SCM));
91   DECLARE_SCHEME_CALLBACK (calc_direction, (SCM));
92   DECLARE_SCHEME_CALLBACK (calc_positions, (SCM));
93   DECLARE_SCHEME_CALLBACK (calc_least_squares_positions, (SCM, SCM));
94   DECLARE_SCHEME_CALLBACK (calc_normal_stems, (SCM));  
95   DECLARE_SCHEME_CALLBACK (calc_concaveness, (SCM));
96   DECLARE_SCHEME_CALLBACK (set_stem_lengths, (SCM));
97   DECLARE_SCHEME_CALLBACK (calc_cross_staff, (SCM));
98
99   /* position callbacks */
100   DECLARE_SCHEME_CALLBACK (shift_region_to_valid, (SCM, SCM));
101   DECLARE_SCHEME_CALLBACK (slope_damping, (SCM, SCM));
102   DECLARE_SCHEME_CALLBACK (quanting, (SCM, SCM));
103   
104 static Real score_slopes_dy (Real, Real, Real, Real, Real, bool, Beam_quant_parameters const *);
105
106   static Real score_stem_lengths (vector<Grob*> const &stems,
107                                   vector<Stem_info> const &stem_infos,
108                                   vector<Real> const &base_stem_ys,
109                                   vector<Real> const &stem_xs,
110                                   Real xl, Real xr,
111                                   bool knee,
112                                   Real yl, Real yr, Beam_quant_parameters const *);
113   static Real score_forbidden_quants (Real, Real,
114                                       Real, Real, Real, Real,
115                                       Drul_array<int>, Direction, Direction,
116                                       Beam_quant_parameters const *);
117
118   static int get_direction_beam_count (Grob *me, Direction d);
119 private:
120   static Direction get_default_dir (Grob *);
121   static void set_stem_directions (Grob *, Direction);
122   static void consider_auto_knees (Grob *);
123   static void set_stem_shorten (Grob *);
124   static Real calc_stem_y (Grob *, Grob *s, Grob **c,
125                            Real, Real, Direction,
126                            Drul_array<Real> pos, bool french);
127   static int forced_stem_count (Grob *);
128 };
129
130
131 #endif /* BEAM_HH */
132