]> git.donarmstrong.com Git - lilypond.git/blob - lily/separating-group-spanner.cc
6b5c2302a82d96992e443e587bb8022ab18e2345
[lilypond.git] / lily / separating-group-spanner.cc
1 /*   
2   separating-group-spanner.cc --  implement Separating_group_spanner
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1998--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "separating-group-spanner.hh"
11 #include "separation-item.hh"
12 #include "paper-column.hh"
13 #include "paper-def.hh"
14 #include "dimensions.hh"
15 #include "group-interface.hh"
16
17 static Rod
18 make_rod (Item *l, Item *r)
19 {
20   Rod rod;
21
22   Interval li (Separation_item::my_width (l));
23   Interval ri (Separation_item::my_width (r));
24
25   rod.item_l_drul_[LEFT] =l;
26   rod.item_l_drul_[RIGHT]=r;
27
28   if (li.empty_b () || ri.empty_b ())
29     rod.distance_f_ = 0;
30   else
31     rod.distance_f_ = li[RIGHT] - ri[LEFT];
32
33   rod.columnize ();
34   return rod;
35 }
36   
37
38 Array<Rod>
39 Separating_group_spanner::get_rods () const
40 {
41   Array<Rod> a;
42   
43   for (SCM s = get_elt_property ("elements"); gh_pair_p (s) && gh_pair_p (gh_cdr (s)); s = gh_cdr (s))
44     {
45       /*
46         Order of elements is reversed!
47        */
48       SCM elt = gh_cadr (s);
49       SCM next_elt = gh_car (s);
50
51       Item *l = dynamic_cast<Item*> (unsmob_element (elt));
52       Item *r = dynamic_cast<Item*> (unsmob_element ( next_elt));
53
54       if (!r || !l)
55         continue;
56       
57       Item *lb
58         = dynamic_cast<Item*>(l->find_prebroken_piece (RIGHT));
59
60       Item *rb
61         = dynamic_cast<Item*>(r->find_prebroken_piece (LEFT));
62       
63       a.push (make_rod(l,  r));
64       if (lb)
65         {
66           Rod rod(make_rod (lb, r));
67           a.push (rod);
68         }
69       
70       if (rb)
71         {
72           a.push (make_rod (l, rb));
73         }
74       
75       if (lb && rb)
76         {
77           Rod rod(make_rod (lb, rb));
78           a.push (rod);
79         }
80     }
81
82   /*
83     We've done our job, so we get lost. 
84    */
85   for (SCM s = get_elt_property ("elements"); gh_pair_p (s); s = gh_cdr (s))
86     {
87       Item * it =dynamic_cast<Item*>(unsmob_element (gh_car (s)));
88       if (it && it->broken_b ())
89         {
90           it->find_prebroken_piece (LEFT) ->suicide ();
91           it->find_prebroken_piece (RIGHT)->suicide ();
92         }
93       it->suicide ();
94     }
95   
96   ((Separating_group_spanner *)this)->suicide ();
97   
98   return a;
99 }
100
101 void
102 Separating_group_spanner::add_spacing_unit (Score_element* me ,Item*i)
103 {
104   Pointer_group_interface (me, "elements").add_element (i);
105   me->add_dependency (i);
106 }
107
108
109 Separating_group_spanner::Separating_group_spanner (SCM s)
110   : Spanner (s)  
111 {
112   set_elt_property ("elements", SCM_EOL);
113 }