]> git.donarmstrong.com Git - lilypond.git/blob - lily/spaceable-grob.cc
* lily/tie-column.cc (set_manual_tie_configuration): new function.
[lilypond.git] / lily / spaceable-grob.cc
1 /*
2   spaceable-grob.cc -- implement Spaceable_grob
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2000--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "spaceable-grob.hh"
10
11 #include <cstdio>
12 #include <cmath>
13 using namespace std;
14
15 #include "warn.hh"
16 #include "spring.hh"
17 #include "pointer-group-interface.hh"
18 #include "grob.hh"
19 #include "paper-column.hh"
20
21 SCM
22 Spaceable_grob::get_minimum_distances (Grob *me)
23 {
24   return me->get_object ("minimum-distances");
25 }
26
27 /*todo: merge code of spring & rod?
28  */
29 void
30 Spaceable_grob::add_rod (Grob *me, Grob *p, Real d)
31 {
32   //  printf ("rod %lf\n", d);
33   if (d < 0)
34     return;
35
36   if (isinf (d))
37     programming_error ("infinite rod");
38
39   SCM mins = get_minimum_distances (me);
40   SCM newdist = scm_from_double (d);
41   for (SCM s = mins; scm_is_pair (s); s = scm_cdr (s))
42     {
43       SCM dist = scm_car (s);
44       if (scm_car (dist) == p->self_scm ())
45         {
46           scm_set_cdr_x (dist, scm_max (scm_cdr (dist),
47                                         newdist));
48           return;
49         }
50     }
51
52   if (Paper_column::get_rank (p) < Paper_column::get_rank (me))
53     programming_error ("Adding reverse rod");
54
55   mins = scm_cons (scm_cons (p->self_scm (), newdist), mins);
56   me->set_object ("minimum-distances", mins);
57 }
58
59 void
60 Spaceable_grob::add_spring (Grob *me, Grob *other,
61                             Real distance, Real inverse_strength)
62 {
63   if (distance <= 0.0 || inverse_strength < 0.0)
64     {
65       programming_error ("adding reverse spring, setting to unit");
66       distance = 1.0;
67       inverse_strength = 1.0;
68     }
69
70   if (isinf (distance) || isnan (distance)
71       || isnan (inverse_strength))
72     {
73       /* strength == INF is possible. It means fixed distance.  */
74       programming_error ("insane distance found");
75       distance = 1.0;
76       inverse_strength = 1.0;
77     }
78
79 #ifndef NDEBUG
80   SCM mins = me->get_object ("ideal-distances");
81   for (SCM s = mins; scm_is_pair (s); s = scm_cdr (s))
82     {
83       Spring_smob *sp = unsmob_spring (scm_car (s));
84       if (sp->other_ == other)
85         {
86           programming_error ("already have that spring");
87           return;
88         }
89     }
90 #endif
91
92   Spring_smob spring;
93   spring.inverse_strength_ = inverse_strength;
94   spring.distance_ = distance;
95   spring.other_ = other;
96
97   SCM ideal = me->get_object ("ideal-distances");
98   ideal = scm_cons (spring.smobbed_copy (), ideal);
99   me->set_object ("ideal-distances", ideal);
100 }
101
102 void
103 Spaceable_grob::get_spring (Grob *me, Grob *other, Real *dist, Real *inv_strength)
104 {
105   for (SCM s = me->get_object ("ideal-distances");
106        scm_is_pair (s); s = scm_cdr (s))
107     {
108       Spring_smob *spring = unsmob_spring (scm_car (s));
109       if (spring && spring->other_ == other)
110         {
111           *dist = spring->distance_;
112           *inv_strength = spring->inverse_strength_;
113         }
114     }
115 }
116
117 void
118 Spaceable_grob::remove_interface (Grob *me)
119 {
120   me->set_object ("minimum-distances", SCM_EOL);
121   me->set_object ("spacing-wishes", SCM_EOL);
122   me->set_object ("ideal-distances", SCM_EOL);
123 }
124
125 ADD_INTERFACE (Spaceable_grob, "spaceable-grob-interface",
126                "A layout object that takes part in the spacing problem. ",
127                "measure-length spacing-wishes penalty minimum-distances ideal-distances "
128                "keep-inside-line left-neighbors right-neighbors");
129