2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1996--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
5 Jan Nieuwenhuizen <janneke@gnu.org>
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.
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.
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/>.
21 #ifndef BEAM_SCORING_PROBLEM_HH
22 #define BEAM_SCORING_PROBLEM_HH
24 #include "interval.hh"
25 #include "lily-proto.hh"
26 #include "std-vector.hh"
27 #include "stem-info.hh"
28 #include "main.hh" // DEBUG_BEAM_SCORING
32 // Should be ordered by increasing expensiveness.
40 struct Beam_configuration
45 #if DEBUG_BEAM_SCORING
51 Beam_configuration ();
53 void add (Real demerit, const string &reason);
54 static Beam_configuration* new_config(Interval start,
58 // Comparator for a queue of Beam_configuration*.
59 class Beam_configuration_less
61 bool operator() (Beam_configuration* const& l, Beam_configuration* const& r)
63 return l->demerits < r->demerits;
68 struct Beam_quant_parameters
70 Real SECONDARY_BEAM_DEMERIT;
71 Real STEM_LENGTH_DEMERIT_FACTOR;
75 threshold to combat rounding errors.
79 // possibly ridiculous, but too short stems just won't do
80 Real STEM_LENGTH_LIMIT_PENALTY;
81 Real DAMPING_DIRECTION_PENALTY;
82 Real MUSICAL_DIRECTION_FACTOR;
83 Real HINT_DIRECTION_PENALTY;
84 Real IDEAL_SLOPE_FACTOR;
85 Real ROUND_TO_ZERO_SLOPE;
87 void fill (Grob *him);
93 Parameters for a single beam. Precomputed to save time in
94 scoring individual configurations.
96 TODO - use trailing _ on data members.
99 class Beam_scoring_problem
102 Beam_scoring_problem (Grob *me, Drul_array<Real> ys);
103 Drul_array<Real> solve() const;
108 Interval unquanted_y;
117 vector<Stem_info> stem_infos;
120 Do stem computations. These depend on YL and YR linearly, so we can
121 precompute for every stem 2 factors.
123 We store some info to quickly interpolate. The stemlengths are
124 affine linear in YL and YR. If YL == YR == 0, then we might have
125 stem_y != 0.0, when we're cross staff.
127 vector<Real> base_lengths;
128 vector<Real> stem_xpositions;
134 Beam_quant_parameters parameters;
137 Drul_array<int> edge_beam_counts;
138 Drul_array<Direction> edge_dirs;
139 Real beam_translation;
143 // Scoring functions:
144 void score_forbidden_quants (Beam_configuration *config) const;
145 void score_slopes_dy (Beam_configuration *config) const;
146 void score_stem_lengths (Beam_configuration* config) const;
147 void generate_quants(vector<Beam_configuration*>* scores) const;
150 #endif /* BEAM_SCORING_PROBLEM_HH */