]> git.donarmstrong.com Git - lilypond.git/blob - lily/spaceable-grob.cc
* scm/music-functions.scm (has-request-chord): don't use
[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
10 #include "spaceable-grob.hh"
11
12 #include <cstdio> 
13 #include <math.h>
14
15 #include "warn.hh"
16 #include "spring.hh"
17 #include "group-interface.hh"
18
19 SCM
20 Spaceable_grob::get_minimum_distances (Grob*me)
21 {
22   return me->get_property ("minimum-distances");
23 }
24
25 /*todo: merge code of spring & rod?
26  */
27 void
28 Spaceable_grob::add_rod (Grob *me , Grob * p, Real d)
29 {
30   //  printf ("rod %lf\n", d);
31
32   
33   SCM mins = get_minimum_distances (me);
34   SCM newdist = scm_make_real (d);
35   for (SCM s = mins; scm_is_pair (s); s = scm_cdr (s))
36     {
37       SCM dist = scm_car (s);
38       if (scm_car (dist) == p->self_scm ())
39         {
40           scm_set_cdr_x (dist, scm_max (scm_cdr (dist),
41                                        newdist));
42           return ;
43         }
44     }
45
46   mins = scm_cons (scm_cons (p->self_scm (), newdist), mins);
47   me->set_property ("minimum-distances", mins);
48 }
49
50 void
51 Spaceable_grob::add_spring (Grob*me, Grob * p, Real d, Real strength)
52 {
53   //  printf ("dist %lf, str %lf\n", d, strength); 
54   if (d <= 0.0 || strength <= 0.0)
55     {
56       programming_error ("Adding reverse spring! Setting to unit spring");
57       d = 1.0;
58       strength = 1.0;
59     }
60   
61   if (isinf (d) || isnan(d)
62       || isnan (strength))
63     {
64       /*
65         strength == INF is possible. It means fixed distance.
66        */
67       programming_error ("Insane distance found.");
68       d = 1.0;
69       strength = 1.0;
70     }
71     
72 #ifndef NDEBUG
73   SCM mins = me->get_property ("ideal-distances");
74   for (SCM s = mins; scm_is_pair (s); s = scm_cdr (s))
75     {
76       Spring_smob * sp = unsmob_spring(scm_car (s));
77       if (sp->other_ == p)
78         {
79           programming_error ("already have that spring");
80           return ;
81         }
82     }
83 #endif
84   
85   Spring_smob spring;
86   spring.strength_ = strength;
87   spring.distance_ = d;
88   spring.other_ = p;
89   
90   Group_interface::add_thing (me, ly_symbol2scm ("ideal-distances"), spring.smobbed_copy ());
91 }
92
93
94 void
95 Spaceable_grob::remove_interface (Grob*me)
96 {
97   me->set_property ("minimum-distances" , SCM_EOL);
98   me->set_property ("spacing-wishes", SCM_EOL);
99   me->set_property ("ideal-distances", SCM_EOL);
100 }
101
102
103
104 ADD_INTERFACE (Spaceable_grob, "spaceable-grob-interface",
105                "A layout object that takes part in the spacing problem. "
106                ,
107                "measure-length spacing-wishes penalty minimum-distances ideal-distances "
108                "allow-outside-line left-neighbors right-neighbors");
109