]> git.donarmstrong.com Git - lilypond.git/blob - lily/separation-item.cc
bb8c4594db5d1c2a442084e1c664af336309f044
[lilypond.git] / lily / separation-item.cc
1 /*   
2      separation-item.cc --  implement Separation_item
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1998--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "separation-item.hh"
11 #include "paper-column.hh"
12 #include "warn.hh"
13 #include "group-interface.hh"
14 #include "accidental-placement.hh"
15
16 void
17 Separation_item::add_item (Grob*s,Item* i)
18 {
19   assert (i);
20   Pointer_group_interface::add_grob (s, ly_symbol2scm ("elements"),i);
21   s->add_dependency (i);
22 }
23
24 void
25 Separation_item::add_conditional_item (Grob* me , Grob *e)
26 {
27   Pointer_group_interface::add_grob (me, ly_symbol2scm ("conditional-elements"), e);
28 }
29
30 /*
31   Return the width of ME given that we are considering the object on
32   the LEFT.
33  */
34 Interval
35 Separation_item::conditional_width (Grob * me, Grob * left)
36 {
37   Interval w = width (me);
38   
39   Item *item = dynamic_cast<Item*> (me);
40   Paper_column * pc = item->get_column ();
41   
42   
43   for (SCM s =  me->get_grob_property ("conditional-elements"); gh_pair_p (s); s = ly_cdr (s))
44     {
45       SCM elt = ly_car (s);
46       if (!unsmob_grob (elt))
47         continue;
48       
49       Item *il = unsmob_item (elt);
50       if (pc != il->get_column ())
51         {
52           /* this shouldn't happen, but let's continue anyway. */
53           programming_error (_ ("Separation_item:  I've been drinking too much"));
54           continue;             /*UGH UGH*/ 
55         }
56
57       if (to_boolean (il->get_grob_property ("no-spacing-rods")))
58         {
59           continue;
60         }
61
62       if (Accidental_placement::has_interface (il))
63         {
64           w.unite (Accidental_placement::get_relevant_accidental_extent (il, pc, left));
65         }
66     }
67
68   SCM pad = me->get_grob_property ("padding");
69
70   w.widen (robust_scm2double (pad, 0.0));
71   return w;
72 }
73
74 Interval
75 Separation_item::width (Grob *me)
76 {
77   SCM sw = me->get_grob_property ("X-extent");
78   if (is_number_pair (sw))
79     {
80       return ly_scm2interval (sw);
81     }
82
83   Item *item = dynamic_cast<Item*> (me);
84   Paper_column * pc = item->get_column ();
85   Interval w;
86   
87   for (SCM s =  me->get_grob_property ("elements"); gh_pair_p (s); s = ly_cdr (s))
88     {
89       SCM elt = ly_car (s);
90       if (!unsmob_grob (elt))
91         continue;
92
93       Item *il = unsmob_item (elt);
94       if (pc != il->get_column ())
95         {
96           /* this shouldn't happen, but let's continue anyway. */
97           programming_error (_ ("Separation_item:  I've been drinking too much"));
98           continue;             /*UGH UGH*/ 
99         }
100
101       if (to_boolean (il->get_grob_property ("no-spacing-rods")))
102         {
103           continue;
104         }
105
106       Interval iv (il->extent (pc, X_AXIS));
107       if (!iv.is_empty ())
108         {
109           w.unite (iv);
110         }
111     }
112
113   SCM pad = me->get_grob_property ("padding");
114
115   w.widen (robust_scm2double (pad, 0.0));
116
117   me->set_grob_property ("X-extent", ly_interval2scm (w));
118   
119   return w;
120 }
121
122 Interval
123 Separation_item::relative_width (Grob * me, Grob * common)
124 {
125   Interval iv = width (me);
126
127   return dynamic_cast<Item*>(me)->get_column ()->relative_coordinate (common, X_AXIS) + iv ;
128 }
129
130
131 /*
132   Try to find the break-aligned symbol in SEPARATION_ITEM that is
133   sticking out at direction D. The x size is put in LAST_EXT
134 */
135 Grob*
136 Separation_item::extremal_break_aligned_grob (Grob *separation_item, Direction d,
137                                             Interval * last_ext)
138 {
139   Grob *col = dynamic_cast<Item*> (separation_item)->get_column ();
140   last_ext->set_empty ();
141   Grob *last_grob = 0;
142   for (SCM s = separation_item->get_grob_property ("elements");
143        gh_pair_p (s); s = gh_cdr (s))
144     {
145       Grob * break_item = unsmob_grob (gh_car (s));
146       
147       if (!gh_symbol_p (break_item->get_grob_property ("break-align-symbol")))
148         continue;
149
150       Interval ext = break_item->extent (col, X_AXIS);
151
152       if (ext.is_empty ())
153         continue;
154       if (!last_grob
155           || (last_grob && d * (ext[d]- (*last_ext)[d]) > 0) )
156         {
157           *last_ext = ext;
158           last_grob = break_item; 
159         }
160     }
161
162   return last_grob;  
163 }
164
165
166
167
168
169 ADD_INTERFACE (Separation_item,"separation-item-interface",
170   "Item that computes widths to generate spacing rods.\n"
171 "\n"
172 "Calculate dimensions for the Separating_group_spanner; this has to be "
173 "an item to get dependencies correct.  "
174 , "padding X-extent conditional-elements elements");