]> git.donarmstrong.com Git - lilypond.git/blob - lily/separation-item.cc
* lily/accidental-placement.cc (split_accidentals): new function
[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--2002 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 Interval
31 Separation_item::conditional_width (Grob * me, Grob * left)
32 {
33   Interval w = width (me);
34
35   Item *item = dynamic_cast<Item*> (me);
36   Paper_column * pc = item->column_l ();
37   
38   
39   for (SCM s =  me->get_grob_property ("conditional-elements"); gh_pair_p (s); s = ly_cdr (s))
40     {
41       SCM elt = ly_car (s);
42       if (!unsmob_grob (elt))
43         continue;
44       
45       Item *il = unsmob_item (elt);
46       if (pc != il->column_l ())
47         {
48           /* this shouldn't happen, but let's continue anyway. */
49           programming_error (_ ("Separation_item:  I've been drinking too much"));
50           continue;             /*UGH UGH*/ 
51         }
52
53       if (to_boolean (il->get_grob_property ("no-spacing-rods")))
54         {
55           continue;
56         }
57
58       if (Accidental_placement::has_interface (il))
59         {
60           w.unite (Accidental_placement::get_relevant_accidental_extent (il, pc, left));
61         }
62     }
63
64   SCM pad = me->get_grob_property ("padding");
65
66   if (gh_number_p (pad))
67     {
68       w[RIGHT] += gh_scm2double (pad)/2;
69       w[LEFT] -= gh_scm2double (pad)/2;    
70     }
71   return w;
72 }
73
74 Interval
75 Separation_item::width (Grob *me)
76 {
77   SCM sw = me->get_grob_property ("extent-X");
78   if (ly_number_pair_p (sw))
79     {
80       return ly_scm2interval (sw);
81     }
82
83   Item *item = dynamic_cast<Item*> (me);
84   Paper_column * pc = item->column_l ();
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->column_l ())
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.empty_b ())
108         {
109           w.unite (iv);
110         }
111     }
112
113   SCM pad = me->get_grob_property ("padding");
114
115   if (gh_number_p (pad))
116   {
117     w[RIGHT] += gh_scm2double (pad)/2;
118     w[LEFT] -= gh_scm2double (pad)/2;    
119   }
120
121
122   me->set_grob_property ("extent-X", ly_interval2scm (w));
123   
124   
125   return w;
126  // add this->offset_ ? this-> relative_coordinate ()? 
127 }
128
129
130
131
132
133 ADD_INTERFACE (Separation_item,"separation-item-interface",
134   "Item that computes widths to generate spacing rods.
135
136 Calc dimensions for the Separating_group_spanner; this has to be
137 an item to get dependencies correct.  It can't be an grob_group
138 since these usually are in a different X_group
139 ",
140   "extent-X conditional-elements elements");