]> git.donarmstrong.com Git - lilypond.git/blob - lily/item.cc
release: 1.3.39
[lilypond.git] / lily / item.cc
1 /*
2   item.cc -- implement Item
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "dimension-cache.hh"
10 #include "paper-score.hh"
11 #include "debug.hh"
12 #include "item.hh"
13 #include "paper-column.hh"
14 #include "spanner.hh"
15 #include "lily-guile.hh"
16
17 Item::Item ()
18 {
19   broken_to_drul_[LEFT] = broken_to_drul_[RIGHT]=0;
20 }
21
22 /**
23    Item copy ctor.  Copy nothing: everything should be a elt property
24    or a special purpose poitner (such as broken_to_drul_[]) */
25 Item::Item (Item const &s)
26   : Score_element (s)
27 {
28   broken_to_drul_[LEFT] = broken_to_drul_[RIGHT] =0;
29 }
30
31
32
33 bool
34 Item::breakable_b () const
35 {
36   if (original_l_ )
37     return false;
38   
39   Item * i  =dynamic_cast<Item*> (parent_l (X_AXIS));
40   return (i) ?  i->breakable_b () : to_boolean (get_elt_property( "breakable"));
41 }
42
43 Line_of_score *
44 Item::line_l() const
45 {
46   Score_element *g = parent_l (X_AXIS);
47   return g ?  g->line_l () : 0;
48 }
49
50
51 void
52 Item::copy_breakable_items()
53 {
54   Drul_array<Item *> new_copies;
55   Direction  i=LEFT;
56   do 
57     {
58       Score_element * dolly = clone();
59       Item * item_p = dynamic_cast<Item*>(dolly);
60       pscore_l_->typeset_element (item_p);
61       new_copies[i] =item_p;
62     }
63   while (flip(&i) != LEFT);
64   broken_to_drul_= new_copies;
65
66   do 
67     {
68        broken_to_drul_[i]->handle_prebroken_dependencies();
69        broken_to_drul_[i]->try_visibility_lambda();
70     }
71   while (flip(&i) != LEFT);
72 }
73
74 void
75 Item::try_visibility_lambda ()
76 {
77   SCM vis = remove_elt_property ("visibility-lambda");
78   if (gh_procedure_p (vis))
79     {
80       SCM args = scm_listify (gh_int2scm (break_status_dir ()), SCM_UNDEFINED);
81       SCM result = gh_apply (vis, args);
82       bool trans = gh_scm2bool (gh_car (result));
83       bool empty = gh_scm2bool (gh_cdr (result));
84
85       if (empty)
86         {
87           set_empty (X_AXIS);
88           set_empty ( Y_AXIS);
89         }
90       if (trans)
91         set_elt_property ("transparent", SCM_BOOL_T);
92     }
93 }
94
95 bool
96 Item::broken_b () const
97 {
98   return broken_to_drul_[LEFT] || broken_to_drul_[RIGHT];
99 }
100
101 void
102 Item::do_break ()
103 {
104   if (broken_b ())
105     return;
106
107   if (breakable_b ())
108     {
109       copy_breakable_items();
110       handle_prebroken_dependencies();
111   
112       /*
113     Otherwise the broken items won't be pre_process()'ed.
114   */
115   
116       if (broken_to_drul_[LEFT])
117         {
118           add_dependency (broken_to_drul_[LEFT]);
119           add_dependency (broken_to_drul_[RIGHT]);
120         }
121     }
122   try_visibility_lambda ();     // ugh.
123 }
124
125 void
126 Item::do_breakable_col_processing()
127 {
128   do_break ();
129 }
130
131 Score_element*
132 Item::find_broken_piece (Line_of_score*l) const
133 {
134   if (line_l() == l) 
135     return (Item*)(this);
136
137   Direction d = LEFT;
138   do {
139     Score_element *s = find_broken_piece (d);
140     if (s && s->line_l () == l)
141       return s;
142   }
143   while (flip (&d) != LEFT);
144
145   return 0;
146 }
147
148 Item*
149 Item::find_broken_piece (Direction d) const
150 {
151   Item * me = (Item *) (this);  
152   if (!d)
153     return me;
154   else if (breakable_b ())
155     {
156       me->do_break ();
157       return dynamic_cast<Item*> (broken_to_drul_[d]);
158     }
159   else
160     return 0;
161 }
162
163 Paper_column *
164 Item::column_l () const
165 {
166   return dynamic_cast<Item*> (parent_l (X_AXIS))->column_l ();
167 }
168
169 Direction
170 Item::break_status_dir () const
171 {
172   if (original_l_)
173     {
174       Item * i = dynamic_cast<Item*> (original_l_);
175
176       return (i->broken_to_drul_[LEFT] == this) ? LEFT : RIGHT;
177     }
178   else
179     return CENTER;
180 }
181
182