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