]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-column.cc
release: 1.3.69
[lilypond.git] / lily / paper-column.cc
1 /*
2   paper-column.cc -- implement Paper_column
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include "moment.hh"
9 #include "paper-column.hh"
10 #include "paper-score.hh"
11 #include "debug.hh"
12 #include "axis-group-interface.hh"
13
14 void
15 Paper_column::add_rod (Paper_column * p, Real d)
16 {
17   Direction dir =  Direction (sign (rank_i(p)  -rank_i (this)));
18   
19   if (dir != RIGHT)
20     {
21       programming_error ("Must set minimum distance LTOR.");
22       return;
23     }
24   
25   for (int i=0; i < minimal_dists_.size (); i++)
26     {
27       Column_rod &rod = minimal_dists_[i];
28       if (rod.other_l_ == p)
29         {
30           rod.distance_f_ = rod.distance_f_ >? d;
31           return ;
32         }
33     }
34
35   Column_rod cr;
36   cr.distance_f_ = d;
37   cr.other_l_ = p;
38
39   minimal_dists_.push (cr);
40 }
41
42 void
43 Paper_column::add_spring (Paper_column * p, Real d, Real s)
44 {
45   Direction dir =  Direction (sign (rank_i(p)  -rank_i (this)));
46   
47   if (dir != RIGHT)
48     {
49       programming_error ("Must set springs LTOR");
50       return;
51     }
52   
53   for (int i=0; i < springs_.size (); i++)
54     {
55       Column_spring &spring = springs_[i];
56       if (spring.other_l_ == p)
57         {
58           spring.distance_f_ = spring.distance_f_ >? d;
59           return ;
60         }
61     }
62
63   Column_spring cr;
64   cr.distance_f_ = d;
65   cr.strength_f_ = s;  
66   cr.other_l_ = p;
67
68   springs_.push (cr);
69 }
70
71 int
72 Paper_column::rank_i(Score_element*me) 
73 {
74   return dynamic_cast<Paper_column*> (me)->rank_i_;
75 }
76
77 Line_of_score*
78 Paper_column::line_l() const
79 {
80   return line_l_;
81 }
82
83 Paper_column*
84 Paper_column::column_l () const
85 {
86   return (Paper_column*)(this);
87 }
88
89 Paper_column::Paper_column (SCM l)
90   : Item (l)            // guh.?
91 {
92   Axis_group_interface::set_interface (this);
93   Axis_group_interface::set_axes (this, X_AXIS, X_AXIS);
94   set_elt_property ("bounded-by-me", SCM_EOL);
95   line_l_=0;
96   rank_i_ = -1;
97 }
98
99 Moment
100 Paper_column::when_mom () const
101 {
102   SCM m = get_elt_property ("when");
103   Moment s (0);
104   if (SMOB_IS_TYPE_B(Moment, m))
105     {
106       s = *SMOB_TO_TYPE (Moment,m);
107     }
108   return s;
109 }
110   
111 bool
112 Paper_column::musical_b () const
113 {
114   SCM m = get_elt_property ("shortest-starter-duration");
115   Moment s (0);
116   if (SMOB_IS_TYPE_B(Moment, m))
117     {
118       s = *SMOB_TO_TYPE (Moment,m);
119     }
120   return s != Moment(0);
121 }
122
123 bool
124 Paper_column::used_b ()const
125 {
126   return gh_pair_p (get_elt_property ("elements")) ||  breakable_b ()
127     || gh_pair_p (get_elt_property ("bounded-by-me"))
128     ;
129 }