]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/beam.hh
ae138911ee8b27988fbbc82a78b51fc71b71f72d
[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--2006 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 "lily-guile.hh"
17 #include "stem-info.hh"
18
19 /*
20   TODO: move quanting in separate file.
21 */
22 struct Beam_quant_parameters
23 {
24   Real INTER_QUANT_PENALTY;
25   Real SECONDARY_BEAM_DEMERIT;
26   Real STEM_LENGTH_DEMERIT_FACTOR;
27   Real REGION_SIZE;
28
29   /*
30     threshold to combat rounding errors.
31   */
32   Real BEAM_EPS;
33
34   // possibly ridiculous, but too short stems just won't do
35   Real STEM_LENGTH_LIMIT_PENALTY;
36   Real DAMPING_DIRECTION_PENALTY;
37   Real MUSICAL_DIRECTION_FACTOR;
38   Real IDEAL_SLOPE_FACTOR;
39   Real ROUND_TO_ZERO_SLOPE;
40
41   void fill (Grob *him);
42 };
43
44 struct Beam_segment
45 {
46   int vertical_count_;
47   Interval horizontal_; 
48   Beam_segment ();
49 };
50
51 struct Beam_stem_segment 
52 {
53   Beam_stem_segment ();
54
55   Grob *stem_;
56   Real width_;
57   Real stem_x_;
58   int rank_;
59   int stem_index_;
60   bool gapped_;
61   Direction dir_;
62   int max_connect_;
63   
64 };
65
66
67 bool operator <(Beam_stem_segment const &a, Beam_stem_segment const &b);
68
69 class Beam
70 {
71 public:
72   static int visible_stem_count (Grob *);
73   static Grob *first_visible_stem (Grob *);
74   static Grob *last_visible_stem (Grob *);
75   DECLARE_GROB_INTERFACE();
76   static void add_stem (Grob *, 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_thickness (Grob *me);
83   static void connect_beams (Grob *me);
84   static vector<Beam_segment> get_beam_segments (Grob *me_grob, Grob **common); 
85   
86   DECLARE_SCHEME_CALLBACK (rest_collision_callback, (SCM element, SCM prev_off));
87   DECLARE_SCHEME_CALLBACK (print, (SCM));
88   DECLARE_SCHEME_CALLBACK (calc_beaming, (SCM));
89   DECLARE_SCHEME_CALLBACK (calc_stem_shorten, (SCM));
90   DECLARE_SCHEME_CALLBACK (calc_direction, (SCM));
91   DECLARE_SCHEME_CALLBACK (calc_positions, (SCM));
92   DECLARE_SCHEME_CALLBACK (calc_least_squares_positions, (SCM, SCM));
93   DECLARE_SCHEME_CALLBACK (calc_concaveness, (SCM));
94   DECLARE_SCHEME_CALLBACK (set_stem_lengths, (SCM));
95
96   /* position callbacks */
97   DECLARE_SCHEME_CALLBACK (shift_region_to_valid, (SCM, SCM));
98   DECLARE_SCHEME_CALLBACK (slope_damping, (SCM, SCM));
99   DECLARE_SCHEME_CALLBACK (quanting, (SCM, SCM));
100   
101 static Real score_slopes_dy (Real, Real, Real, Real, Real, bool, Beam_quant_parameters const *);
102
103   static Real score_stem_lengths (vector<Grob*> const &stems,
104                                   vector<Stem_info> const &stem_infos,
105                                   vector<Real> const &base_stem_ys,
106                                   vector<Real> const &stem_xs,
107                                   Real xl, Real xr,
108                                   bool knee,
109                                   Real yl, Real yr, Beam_quant_parameters const *);
110   static Real score_forbidden_quants (Real, Real,
111                                       Real, Real, Real, Real,
112                                       Drul_array<int>, Direction, Direction,
113                                       Beam_quant_parameters const *);
114
115   static int get_direction_beam_count (Grob *me, Direction d);
116 private:
117   static Direction get_default_dir (Grob *);
118   static void set_stem_directions (Grob *, Direction);
119   static void consider_auto_knees (Grob *);
120   static void set_stem_shorten (Grob *);
121   static Real calc_stem_y (Grob *, Grob *s, Grob **c,
122                            Real, Real,
123                            Drul_array<Real> pos, bool french);
124   static int forced_stem_count (Grob *);
125 };
126
127
128 #endif /* BEAM_HH */
129