]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-column.cc
* lily/system.cc (do_derived_mark): don't mark from object_alist_
[lilypond.git] / lily / paper-column.cc
1 /*
2   paper-column.cc -- implement Paper_column
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "paper-column.hh"
10
11 #include "moment.hh"
12 #include "paper-score.hh"
13 #include "warn.hh"
14 #include "axis-group-interface.hh"
15 #include "spaceable-grob.hh"
16 #include "text-interface.hh"
17 #include "lookup.hh"
18 #include "font-interface.hh"
19 #include "output-def.hh"
20 #include "pointer-group-interface.hh"
21 #include "grob-array.hh"
22
23 Grob *
24 Paper_column::clone (int count) const
25 {
26   return new Paper_column (*this, count);
27 }
28
29 ADD_INTERFACE (Paper_column, "paper-column-interface",
30                "@code{Paper_column} objects form the top-most X-parents for items. "
31                "  The are two types of columns: musical columns, where are attached to, and "
32                "  non-musical columns, where bar-lines, clefs etc. are attached to. "
33                "  The spacing engine determines the X-positions of these objects."
34                "\n\n"
35                "They are\n"
36                "  numbered, the first (leftmost) is column 0. Numbering happens before\n"
37                "  line-breaking, and columns are not renumbered after line breaking.\n"
38                "  Since many columns go unused, you should only use the rank field to\n"
39                "  get ordering information.  Two adjacent columns may have\n"
40                "  non-adjacent numbers.\n"
41                "\n",
42                "between-cols when bounded-by-me "
43                "page-penalty shortest-playing-duration shortest-starter-duration");
44
45 void
46 Paper_column::do_break_processing ()
47 {
48   Spaceable_grob::remove_interface (this);
49   Item::do_break_processing ();
50 }
51
52 int
53 Paper_column::get_rank (Grob *me)
54 {
55   return dynamic_cast<Paper_column *> (me)->rank_;
56 }
57
58 System *
59 Paper_column::get_system () const
60 {
61   return system_;
62 }
63
64 Paper_column *
65 Paper_column::get_column () const
66 {
67   return (Paper_column *) (this);
68 }
69
70 Paper_column::Paper_column (SCM l, Object_key const *key)
71   : Item (l, key)               // guh.?
72 {
73   system_ = 0;
74   rank_ = -1;
75 }
76
77 Paper_column::Paper_column (Paper_column const &src, int count)
78   : Item (src, count)
79 {
80   system_ = 0;
81   rank_ = src.rank_;
82 }
83
84 Moment
85 Paper_column::when_mom (Grob *me)
86 {
87   SCM m = me->get_property ("when");
88   if (Moment *when = unsmob_moment (m))
89     return *when;
90   return Moment (0);
91 }
92
93 bool
94 Paper_column::is_musical (Grob *me)
95 {
96   SCM m = me->get_property ("shortest-starter-duration");
97   Moment s (0);
98   if (unsmob_moment (m))
99     {
100       s = *unsmob_moment (m);
101     }
102   return s != Moment (0);
103 }
104
105 bool
106 Paper_column::is_used (Grob *me)
107 {
108   extract_grob_set (me ,"elements", elts);
109   if (elts.size())
110     return true;
111   
112   extract_grob_set (me ,"bounded-by-me", bbm);
113   if (bbm.size())
114     return true;
115   return Item::is_breakable (me);
116 }
117
118 /*
119   Print a vertical line and  the rank number, to aid debugging.
120 */
121
122 MAKE_SCHEME_CALLBACK (Paper_column, print, 1);
123 SCM
124 Paper_column::print (SCM p)
125 {
126   Grob *me = unsmob_grob (p);
127
128   String r = to_string (Paper_column::get_rank (me));
129
130   Moment *mom = unsmob_moment (me->get_property ("when"));
131   String when = mom ? mom->to_string () : "?/?";
132     
133   SCM properties = Font_interface::text_font_alist_chain (me);
134
135   SCM scm_mol = Text_interface::interpret_markup (me->get_layout ()->self_scm (),
136                                                   properties,
137                                                   scm_makfrom0str (r.to_str0 ()));
138   SCM when_mol = Text_interface::interpret_markup (me->get_layout ()->self_scm (),
139                                                    properties,
140                                                    scm_makfrom0str (when.to_str0 ()));
141   Stencil t = *unsmob_stencil (scm_mol);
142   t.add_at_edge (Y_AXIS, DOWN, *unsmob_stencil (when_mol), 0.1, 0.1);
143   t.align_to (X_AXIS, CENTER);
144   t.align_to (Y_AXIS, DOWN);
145
146   Stencil l = Lookup::filled_box (Box (Interval (-0.01, 0.01),
147                                        Interval (-2, -1)));
148
149   t.add_stencil (l);
150   return t.smobbed_copy ();
151 }
152
153 /*
154   This is all too hairy. We use bounded-by-me to make sure that some
155   columns are kept "alive". Unfortunately, when spanners are suicided,
156   this falls apart again, because suicided spanners are still in
157   bounded-by-me
158
159   THIS IS BROKEN KLUDGE. WE SHOULD INVENT SOMETHING BETTER.
160 */
161 MAKE_SCHEME_CALLBACK (Paper_column, before_line_breaking, 1);
162 SCM
163 Paper_column::before_line_breaking (SCM grob)
164 {
165   Grob *me = unsmob_grob (grob);
166
167   SCM bbm = me->get_object ("bounded-by-me");
168   Grob_array * ga = unsmob_grob_array (bbm);
169   if (!ga)
170     return SCM_UNSPECIFIED;
171    
172   Link_array<Grob> &array (ga->array_reference ());
173   
174   for (int i = array.size(); i--; )
175     {
176       Grob *g = array[i];
177
178       if (!g || !g->is_live ())
179         {                       // UGH . potentially quadratic.
180           array.del (i);
181         }
182     }
183
184   return SCM_UNSPECIFIED;
185 }