]> git.donarmstrong.com Git - lilypond.git/blob - lily/spaceable-grob.cc
Doc-es: various updates.
[lilypond.git] / lily / spaceable-grob.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2000--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "spaceable-grob.hh"
21
22 #include <cstdio>
23
24 #include "warn.hh"
25 #include "spring.hh"
26 #include "pointer-group-interface.hh"
27 #include "grob.hh"
28 #include "paper-column.hh"
29 #include "international.hh"
30
31 SCM
32 Spaceable_grob::get_minimum_distances (Grob *me)
33 {
34   return me->get_object ("minimum-distances");
35 }
36
37 /*todo: merge code of spring & rod?
38  */
39 void
40 Spaceable_grob::add_rod (Grob *me, Grob *p, Real d)
41 {
42   //  printf ("rod %lf\n", d);
43   if (d < 0)
44     return;
45
46   if (isinf (d))
47     programming_error ("infinite rod");
48
49   SCM mins = get_minimum_distances (me);
50   SCM newdist = scm_from_double (d);
51   for (SCM s = mins; scm_is_pair (s); s = scm_cdr (s))
52     {
53       SCM dist = scm_car (s);
54       if (scm_is_eq (scm_car (dist), p->self_scm ()))
55         {
56           scm_set_cdr_x (dist, scm_max (scm_cdr (dist),
57                                         newdist));
58           return;
59         }
60     }
61
62   if (Paper_column::get_rank (p) < Paper_column::get_rank (me))
63     programming_error ("Adding reverse rod");
64
65   mins = scm_cons (scm_cons (p->self_scm (), newdist), mins);
66   me->set_object ("minimum-distances", mins);
67 }
68
69 void
70 Spaceable_grob::add_spring (Grob *me, Grob *other, Spring sp)
71 {
72   SCM ideal = me->get_object ("ideal-distances");
73
74   ideal = scm_cons (scm_cons (sp.smobbed_copy (), other->self_scm ()), ideal);
75   me->set_object ("ideal-distances", ideal);
76 }
77
78 Spring
79 Spaceable_grob::get_spring (Grob *this_col, Grob *next_col)
80 {
81   Spring *spring = 0;
82
83   for (SCM s = this_col->get_object ("ideal-distances");
84        !spring && scm_is_pair (s);
85        s = scm_cdr (s))
86     {
87       if (scm_is_pair (scm_car (s))
88           && unsmob<Grob> (scm_cdar (s)) == next_col
89           && unsmob<Spring> (scm_caar (s)))
90         spring = unsmob<Spring> (scm_caar (s));
91     }
92
93   if (!spring)
94     programming_error (to_string ("No spring between column %d and next one",
95                                   Paper_column::get_rank (this_col)));
96
97   return spring ? *spring : Spring ();
98 }
99
100 ADD_INTERFACE (Spaceable_grob,
101                "A layout object that takes part in the spacing problem.",
102
103                /* properties */
104                "allow-loose-spacing "
105                "ideal-distances "
106                "keep-inside-line "
107                "left-neighbor "
108                "measure-length "
109                "minimum-distances "
110                "right-neighbor "
111                "spacing-wishes "
112               );
113