]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-column.cc
* lily/mark-engraver.cc (stop_translation_timestep): set grob
[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                
35                "\n\n"
36                "They are\n"
37                "  numbered, the first (leftmost) is column 0. Numbering happens before\n"
38                "  line-breaking, and columns are not renumbered after line breaking.\n"
39                "  Since many columns go unused, you should only use the rank field to\n"
40                "  get ordering information.  Two adjacent columns may have\n"
41                "  non-adjacent numbers.\n",
42                
43                
44                "between-cols "
45                "bounded-by-me "
46                "page-penalty "
47                "shortest-playing-duration "
48                "shortest-starter-duration "
49                "when ");
50
51 void
52 Paper_column::do_break_processing ()
53 {
54   Spaceable_grob::remove_interface (this);
55   Item::do_break_processing ();
56 }
57
58 int
59 Paper_column::get_rank (Grob *me)
60 {
61   return dynamic_cast<Paper_column *> (me)->rank_;
62 }
63
64 System *
65 Paper_column::get_system () const
66 {
67   return system_;
68 }
69
70 Paper_column *
71 Paper_column::get_column () const
72 {
73   return (Paper_column *) (this);
74 }
75
76 Paper_column::Paper_column (SCM l, Object_key const *key)
77   : Item (l, key)               // guh.?
78 {
79   system_ = 0;
80   rank_ = -1;
81 }
82
83 Paper_column::Paper_column (Paper_column const &src, int count)
84   : Item (src, count)
85 {
86   system_ = 0;
87   rank_ = src.rank_;
88 }
89
90 Moment
91 Paper_column::when_mom (Grob *me)
92 {
93   SCM m = me->get_property ("when");
94   if (Moment *when = unsmob_moment (m))
95     return *when;
96   return Moment (0);
97 }
98
99 bool
100 Paper_column::is_musical (Grob *me)
101 {
102   SCM m = me->get_property ("shortest-starter-duration");
103   Moment s (0);
104   if (unsmob_moment (m))
105     s = *unsmob_moment (m);
106   return s != Moment (0);
107 }
108
109 bool
110 Paper_column::is_used (Grob *me)
111 {
112   extract_grob_set (me, "elements", elts);
113   if (elts.size ())
114     return true;
115
116   extract_grob_set (me, "bounded-by-me", bbm);
117   if (bbm.size ())
118     return true;
119   
120   return Item::is_breakable (me);
121 }
122
123 /*
124   Print a vertical line and  the rank number, to aid debugging.
125 */
126
127 MAKE_SCHEME_CALLBACK (Paper_column, print, 1);
128 SCM
129 Paper_column::print (SCM p)
130 {
131   Grob *me = unsmob_grob (p);
132
133   String r = to_string (Paper_column::get_rank (me));
134
135   Moment *mom = unsmob_moment (me->get_property ("when"));
136   String when = mom ? mom->to_string () : "?/?";
137
138   SCM properties = Font_interface::text_font_alist_chain (me);
139
140   SCM scm_mol = Text_interface::interpret_markup (me->get_layout ()->self_scm (),
141                                                   properties,
142                                                   scm_makfrom0str (r.to_str0 ()));
143   SCM when_mol = Text_interface::interpret_markup (me->get_layout ()->self_scm (),
144                                                    properties,
145                                                    scm_makfrom0str (when.to_str0 ()));
146   Stencil t = *unsmob_stencil (scm_mol);
147   t.add_at_edge (Y_AXIS, DOWN, *unsmob_stencil (when_mol), 0.1, 0.1);
148   t.align_to (X_AXIS, CENTER);
149   t.align_to (Y_AXIS, DOWN);
150
151   Stencil l = Lookup::filled_box (Box (Interval (-0.01, 0.01),
152                                        Interval (-2, -1)));
153
154   t.add_stencil (l);
155   return t.smobbed_copy ();
156 }
157
158 /*
159   This is all too hairy. We use bounded-by-me to make sure that some
160   columns are kept "alive". Unfortunately, when spanners are suicided,
161   this falls apart again, because suicided spanners are still in
162   bounded-by-me
163
164   THIS IS BROKEN KLUDGE. WE SHOULD INVENT SOMETHING BETTER.
165 */
166 MAKE_SCHEME_CALLBACK (Paper_column, before_line_breaking, 1);
167 SCM
168 Paper_column::before_line_breaking (SCM grob)
169 {
170   Grob *me = unsmob_grob (grob);
171
172   SCM bbm = me->get_object ("bounded-by-me");
173   Grob_array *ga = unsmob_grob_array (bbm);
174   if (!ga)
175     return SCM_UNSPECIFIED;
176
177   Link_array<Grob> &array (ga->array_reference ());
178
179   for (int i = array.size (); i--;)
180     {
181       Grob *g = array[i];
182
183       if (!g || !g->is_live ())
184         {                       // UGH . potentially quadratic.
185           array.del (i);
186         }
187     }
188
189   return SCM_UNSPECIFIED;
190 }