]> git.donarmstrong.com Git - lilypond.git/blob - lily/separating-group-spanner.cc
* lily/accidental-placement.cc (split_accidentals): new function
[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--2002 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 void
18 Separating_group_spanner::find_rods (Item * r, SCM next)
19 {
20
21   /*
22     This is an inner loop, however, in most cases, the interesting L
23     will just be the first entry of NEXT, making it linear in most of
24     the cases.  */
25   for(; gh_pair_p (next); next = ly_cdr (next))
26     {
27       Item *l = dynamic_cast<Item*> (unsmob_grob (ly_car( next)));
28       Item *lb = l->find_prebroken_piece (RIGHT);
29
30       if (lb)
31         {
32           Interval li (Separation_item::width (lb));
33           Interval ri (Separation_item::conditional_width (r, lb));
34           if (!li.empty_b () && !ri.empty_b())
35             {
36               Rod rod;
37
38               rod.item_l_drul_[LEFT] = lb;
39               rod.item_l_drul_[RIGHT] = r;
40
41               rod.distance_f_ = li[RIGHT] - ri[LEFT];
42         
43               rod.columnize ();
44               rod.add_to_cols ();
45             }
46         }
47
48       Interval li (Separation_item::width (l));
49       Interval ri (Separation_item::conditional_width (r, l));
50       if (!li.empty_b () && !ri.empty_b())
51         {
52           Rod rod;
53
54           rod.item_l_drul_[LEFT] =l;
55           rod.item_l_drul_[RIGHT]=r;
56
57           rod.distance_f_ = li[RIGHT] - ri[LEFT];
58         
59           rod.columnize ();
60           rod.add_to_cols ();
61
62           break;
63         }
64       else
65         /*
66           this grob doesn't cause a constraint. We look further until we
67           find one that does.  */
68         ;
69     }
70 }
71
72 MAKE_SCHEME_CALLBACK (Separating_group_spanner,set_spacing_rods_and_seqs,1);
73 SCM
74 Separating_group_spanner::set_spacing_rods_and_seqs (SCM smob)
75 {
76   set_spacing_rods (smob);
77
78   return SCM_UNSPECIFIED;
79 }
80
81 MAKE_SCHEME_CALLBACK (Separating_group_spanner,set_spacing_rods,1);
82 SCM
83 Separating_group_spanner::set_spacing_rods (SCM smob)
84 {
85   Grob*me = unsmob_grob (smob);
86   
87   for (SCM s = me->get_grob_property ("elements"); gh_pair_p (s) && gh_pair_p (ly_cdr (s)); s = ly_cdr (s))
88     {
89       /*
90         Order of elements is reversed!
91        */
92       SCM elt = ly_car (s);
93       Item *r = unsmob_item (elt);
94
95       if (!r)
96         continue;
97
98       Item *rb
99         = dynamic_cast<Item*> (r->find_prebroken_piece (LEFT));
100       
101       find_rods (r, ly_cdr (s));
102       if (rb)
103         find_rods (rb, ly_cdr (s));
104     }
105
106   return SCM_UNSPECIFIED ;
107 }
108
109 void
110 Separating_group_spanner::add_spacing_unit (Grob* me ,Item*i)
111 {
112   Pointer_group_interface::add_grob (me, ly_symbol2scm ("elements"), i);
113   me->add_dependency (i);
114 }
115
116
117
118
119
120 ADD_INTERFACE (Separating_group_spanner,"separation-spanner-interface",
121   "Spanner that containing @code{separation-item-interface} grobs to calculate rods",
122   "");