lilypond-1.5.10
[lilypond.git] / lily / spaceable-grob.cc
blob26bf4e8066b9165b7c54c81f05605dd298bd0141
1 /*
2 spaceable-grob.cc -- implement Spaceable_grob
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
10 #include "spaceable-grob.hh"
11 #include "grob.hh"
12 #include "warn.hh"
14 SCM
15 Spaceable_grob::get_minimum_distances (Grob*me)
17 return me->get_grob_property ("minimum-distances");
20 /*todo: merge code of spring & rod?
22 void
23 Spaceable_grob::add_rod (Grob *me , Grob * p, Real d)
25 SCM mins = get_minimum_distances (me);
26 SCM newdist = gh_double2scm (d);
27 for (SCM s = mins; gh_pair_p (s); s = gh_cdr (s))
29 SCM dist = gh_car (s);
30 if (gh_car (dist) == p->self_scm ())
32 gh_set_cdr_x (dist, scm_max (gh_cdr (dist),
33 newdist));
34 return ;
38 mins = gh_cons (gh_cons (p->self_scm (), newdist), mins);
39 me->set_grob_property ("minimum-distances", mins);
42 void
43 Spaceable_grob::add_spring (Grob*me, Grob * p, Real d, Real strength)
45 SCM mins = me->get_grob_property ("ideal-distances");
48 SCM newdist= gh_double2scm (d);
49 for (SCM s = mins; gh_pair_p (s); s = gh_cdr (s))
51 SCM dist = gh_car (s);
52 if (gh_car (dist) == p->self_scm ())
54 programming_error ("already have that spring");
55 return ;
58 SCM newstrength= gh_double2scm (strength);
60 mins = gh_cons (gh_cons (p->self_scm (), gh_cons (newdist, newstrength)), mins);
61 me->set_grob_property ("ideal-distances", mins);
65 void
66 Spaceable_grob::remove_interface (Grob*me)
68 me->remove_grob_property ("minimum-distances");
69 me->remove_grob_property ("ideal-distances");
70 me->remove_grob_property ("dir-list");
74 void
75 Spaceable_grob::set_interface (Grob*me)
77 me->set_interface (ly_symbol2scm ("spaceable-grob-interface"));