]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/beam.hh
32a86dc40d93b5b7618e8c158a8f292065342f78
[lilypond.git] / lily / include / beam.hh
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1996--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
5   Jan Nieuwenhuizen <janneke@gnu.org>
6
7   LilyPond is free software: you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11
12   LilyPond is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #ifndef BEAM_HH
22 #define BEAM_HH
23
24 #include "grob-interface.hh"
25 #include "std-vector.hh"
26 #include "lily-proto.hh"
27 #include "stem-info.hh"
28
29 /*
30   TODO: move quanting in separate file.
31 */
32 struct Beam_quant_parameters
33 {
34   Real SECONDARY_BEAM_DEMERIT;
35   Real STEM_LENGTH_DEMERIT_FACTOR;
36   Real REGION_SIZE;
37
38   /*
39     threshold to combat rounding errors.
40   */
41   Real BEAM_EPS;
42
43   // possibly ridiculous, but too short stems just won't do
44   Real STEM_LENGTH_LIMIT_PENALTY;
45   Real DAMPING_DIRECTION_PENALTY;
46   Real MUSICAL_DIRECTION_FACTOR;
47   Real HINT_DIRECTION_PENALTY;
48   Real IDEAL_SLOPE_FACTOR;
49   Real ROUND_TO_ZERO_SLOPE;
50
51   void fill (Grob *him);
52 };
53
54 struct Beam_segment
55 {
56   int vertical_count_;
57   Interval horizontal_; 
58   Beam_segment ();
59 };
60
61 struct Beam_stem_segment 
62 {
63   Beam_stem_segment ();
64
65   Grob *stem_;
66   Real width_;
67   Real stem_x_;
68   int rank_;
69   vsize stem_index_;
70   bool gapped_;
71   Direction dir_;
72   int max_connect_;
73   
74 };
75
76
77 bool operator <(Beam_stem_segment const &a, Beam_stem_segment const &b);
78
79 class Beam
80 {
81 public:
82   static int normal_stem_count (Grob *);
83   static Grob *first_normal_stem (Grob *);
84   static Grob *last_normal_stem (Grob *);
85   DECLARE_GROB_INTERFACE();
86   static void add_stem (Grob *, Grob *);
87   static bool is_cross_staff (Grob *);
88   static bool is_knee (Grob *);
89   static void set_beaming (Grob *, Beaming_pattern const *);
90   static void set_stemlens (Grob *);
91   static int get_beam_count (Grob *me);
92   static Real get_beam_translation (Grob *me);
93   static Real get_beam_thickness (Grob *me);
94   static void connect_beams (Grob *me);
95   static vector<Beam_segment> get_beam_segments (Grob *me_grob, Grob **common); 
96   static Interval no_visible_stem_positions (Grob *me, Interval default_value);
97   
98   DECLARE_SCHEME_CALLBACK (rest_collision_callback, (SCM element, SCM prev_off));
99   DECLARE_SCHEME_CALLBACK (print, (SCM));
100   DECLARE_SCHEME_CALLBACK (calc_beaming, (SCM));
101   DECLARE_SCHEME_CALLBACK (calc_stem_shorten, (SCM));
102   DECLARE_SCHEME_CALLBACK (calc_direction, (SCM));
103   DECLARE_SCHEME_CALLBACK (calc_positions, (SCM));
104   DECLARE_SCHEME_CALLBACK (calc_least_squares_positions, (SCM, SCM));
105   DECLARE_SCHEME_CALLBACK (calc_normal_stems, (SCM));  
106   DECLARE_SCHEME_CALLBACK (calc_concaveness, (SCM));
107   DECLARE_SCHEME_CALLBACK (set_stem_lengths, (SCM));
108   DECLARE_SCHEME_CALLBACK (calc_cross_staff, (SCM));
109
110   /* position callbacks */
111   DECLARE_SCHEME_CALLBACK (shift_region_to_valid, (SCM, SCM));
112   DECLARE_SCHEME_CALLBACK (slope_damping, (SCM, SCM));
113   DECLARE_SCHEME_CALLBACK (quanting, (SCM, SCM));
114   
115 static Real score_slopes_dy (Real, Real, Real, Real, Real, bool, Beam_quant_parameters const *);
116
117   static Real score_stem_lengths (vector<Grob*> const &stems,
118                                   vector<Stem_info> const &stem_infos,
119                                   vector<Real> const &base_stem_ys,
120                                   vector<Real> const &stem_xs,
121                                   Real xl, Real xr,
122                                   bool knee,
123                                   Real yl, Real yr, Beam_quant_parameters const *);
124   static Real score_forbidden_quants (Real, Real,
125                                       Real, Real, Real, Real,
126                                       Drul_array<int>, Direction, Direction,
127                                       Beam_quant_parameters const *);
128
129   static int get_direction_beam_count (Grob *me, Direction d);
130 private:
131   static Direction get_default_dir (Grob *);
132   static void set_stem_directions (Grob *, Direction);
133   static void consider_auto_knees (Grob *);
134   static void set_stem_shorten (Grob *);
135   static Real calc_stem_y (Grob *, Grob *s, Grob **c,
136                            Real, Real, Direction,
137                            Drul_array<Real> pos, bool french);
138   static int forced_stem_count (Grob *);
139 };
140
141
142 #endif /* BEAM_HH */
143