]> git.donarmstrong.com Git - lilypond.git/blob - lily/break-algorithm.cc
release: 1.2.9
[lilypond.git] / lily / break-algorithm.cc
1 /*
2   break.cc -- implement Break_algorithm
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1996,  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "score-column.hh"
10 #include "break.hh"
11 #include "paper-def.hh"
12 #include "spring-spacer.hh"
13 #include "debug.hh"
14 #include "line-of-score.hh"
15 #include "paper-score.hh"
16 #include "paper-column.hh"
17 #include "cpu-timer.hh"
18 #include "command-request.hh"
19 #include "spring-spacer.hh"
20 #include "simple-spacer.hh"
21
22
23
24
25
26 Array<int>
27 Break_algorithm::find_break_indices () const
28 {
29   Line_of_cols all (pscore_l_->col_l_arr_);
30   Array<int> retval;
31
32   for (int i=0; i < all.size (); i++)
33     if (all[i]->breakable_b ())
34       retval.push (i);
35
36   if (linelength <=0)
37     while (retval.size () >2)
38       retval.del (1);
39
40   return retval;
41 }
42
43
44 Line_of_cols
45 Break_algorithm::find_breaks () const
46 {
47   Line_of_cols all (pscore_l_->col_l_arr_);
48   Line_of_cols retval;
49
50   for (int i=0; i < all.size (); i++)
51     if (all[i]->breakable_b ())
52       retval.push (all[i]);
53
54   if (linelength <=0)
55     while (retval.size () >2)
56       retval.del (1);
57
58   return retval;
59 }
60
61
62 Line_spacer*
63 Break_algorithm::generate_spacing_problem (Line_of_cols curline, Interval line) const
64 {
65   Real r = pscore_l_->paper_l_->get_var ("simple_spacing_solver");
66     
67   Line_spacer * sp = 0;
68   if (r)
69     sp = new Simple_spacer;
70   else
71     sp = new Spring_spacer;
72   
73   sp->default_space_f_ = pscore_l_->paper_l_->get_var ("loose_column_distance");
74
75   sp->indent_f_ = line[LEFT];
76
77   /*
78     sort out how interfacing this should work;
79    */
80   if (line.empty_b())
81     {
82      sp->line_len_f_ = -1;
83     }
84   else
85     sp->line_len_f_ = line.length ();
86   
87   sp->add_columns (curline);
88   sp->prepare ();
89
90   return sp;
91 }
92
93 Break_algorithm::Break_algorithm ()
94 {
95   pscore_l_ = 0;
96   get_line_spacer =0;
97   linelength = 0;
98 }
99
100 void
101 Break_algorithm::set_pscore (Paper_score*s)
102 {
103   pscore_l_ = s;
104   linelength = s->paper_l_->linewidth_f ();
105   do_set_pscore ();
106 }
107
108 bool
109 Break_algorithm::feasible (Line_of_cols curline) const
110 {
111   if (linelength <=  0)
112     return true;
113
114   for (int i=0; i < curline.size (); i++)
115     {
116       if (i && i < curline.size () -1
117           && ((dynamic_cast<Score_column*>(curline[i]))->break_penalty_i () >= Break_req::FORCE))
118         return false;
119     }
120   return true;
121 }
122
123 void
124 Break_algorithm::problem_OK () const
125 {
126   if (pscore_l_->col_l_arr_.empty ())
127     error (_("Score does not have any columns"));
128   OK ();
129 }
130
131 void
132 Break_algorithm::OK () const
133 {
134 }
135
136 Array<Column_x_positions>
137 Break_algorithm::solve () const
138 {
139   Array<Column_x_positions> h= do_solve ();
140   
141   return h;
142 }
143
144 void
145 Break_algorithm::do_set_pscore ()
146 {
147
148 }