]> git.donarmstrong.com Git - lilypond.git/blob - lily/spaceable-element.cc
37cac89a5e29e8a316c4bc4461241b0bbe7b59a3
[lilypond.git] / lily / spaceable-element.cc
1 /*   
2   spaceable-element.cc --  implement Spaceable_element
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "spaceable-element.hh"
11 #include "score-element.hh"
12 #include "warn.hh"
13
14 SCM
15 Spaceable_element::get_minimum_distances ( Score_element*me)
16 {
17   return me->get_elt_property ("minimum-distances");
18 }
19
20 /*todo: merge code of spring & rod?
21  */
22 void
23 Spaceable_element::add_rod (Score_element *me , Score_element * p, Real d)
24 {
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))
28     {
29       SCM dist = gh_car (s);
30       if (gh_car (dist) == p->self_scm ())
31         {
32           gh_set_cdr_x (dist, scm_max (gh_cdr (dist),
33                                        newdist));
34           return ;
35         }
36     }
37
38   mins = gh_cons (gh_cons (p->self_scm (), newdist), mins);
39   me->set_elt_property ("minimum-distances", mins);
40 }
41
42 void
43 Spaceable_element::add_spring (Score_element*me, Score_element * p, Real d, Real strength)
44 {
45   SCM mins = get_ideal_distances (me);
46   SCM newdist= gh_double2scm (d);
47   for (SCM s = mins; gh_pair_p (s); s = gh_cdr (s))
48     {
49       SCM dist = gh_car (s);
50       if (gh_car (dist) == p->self_scm ())
51         {
52           programming_error("already have that spring");
53           return ;
54         }
55     }
56   SCM newstrength= gh_double2scm (strength);  
57   
58   mins = gh_cons (gh_cons (p->self_scm (), gh_cons (newdist, newstrength)), mins);
59   me->set_elt_property ("ideal-distances", mins);
60 }
61
62 SCM
63 Spaceable_element::get_ideal_distances (Score_element*me)
64 {
65   return me->get_elt_property ("ideal-distances");
66 }
67
68
69 void
70 Spaceable_element::remove_interface (Score_element*me)
71 {
72   me->remove_elt_property ("minimum-distances");
73   me->remove_elt_property ("ideal-distances");
74   me->remove_elt_property ("dir-list");
75 }
76
77
78 void
79 Spaceable_element::set_interface (Score_element*me)
80 {
81 }