]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-column.cc
* scm/output-lib.scm (grace-spacing::calc-shortest-duration): new function.
[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--2006 Han-Wen Nienhuys <hanwen@xs4all.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 void
30 Paper_column::do_break_processing ()
31 {
32   Spaceable_grob::remove_interface (this);
33   Item::do_break_processing ();
34 }
35
36 int
37 Paper_column::get_rank (Grob *me)
38 {
39   return dynamic_cast<Paper_column *> (me)->rank_;
40 }
41
42 System *
43 Paper_column::get_system () const
44 {
45   return system_;
46 }
47
48 Paper_column *
49 Paper_column::get_column () const
50 {
51   return (Paper_column *) (this);
52 }
53
54 Paper_column::Paper_column (SCM l, Object_key const *key)
55   : Item (l, key)               // guh.?
56 {
57   system_ = 0;
58   rank_ = -1;
59 }
60
61 Paper_column::Paper_column (Paper_column const &src, int count)
62   : Item (src, count)
63 {
64   system_ = 0;
65   rank_ = src.rank_;
66 }
67
68 int
69 Paper_column::compare (Grob * const &a,
70                        Grob * const &b)
71 {
72   return sign (dynamic_cast<Paper_column*> (a)->rank_
73                - dynamic_cast<Paper_column*> (b)->rank_);
74 }
75
76 Moment
77 Paper_column::when_mom (Grob *me)
78 {
79   SCM m = me->get_property ("when");
80   if (Moment *when = unsmob_moment (m))
81     return *when;
82   return Moment (0);
83 }
84
85 bool
86 Paper_column::is_musical (Grob *me)
87 {
88   SCM m = me->get_property ("shortest-starter-duration");
89   Moment s (0);
90   if (unsmob_moment (m))
91     s = *unsmob_moment (m);
92   return s != Moment (0);
93 }
94
95 bool
96 Paper_column::is_used (Grob *me)
97 {
98   extract_grob_set (me, "elements", elts);
99   if (elts.size ())
100     return true;
101
102   extract_grob_set (me, "bounded-by-me", bbm);
103   if (bbm.size ())
104     return true;
105   
106   if (Paper_column::is_breakable (me))
107     return true;
108
109   if (to_boolean (me->get_property ("used")))
110     return true;
111   return false;
112 }
113
114 bool
115 Paper_column::is_breakable (Grob *me)
116 {
117   return scm_is_symbol (me->get_property ("line-break-permission"));
118 }
119
120 /*
121   Print a vertical line and  the rank number, to aid debugging.
122 */
123
124 MAKE_SCHEME_CALLBACK (Paper_column, print, 1);
125 SCM
126 Paper_column::print (SCM p)
127 {
128   Grob *me = unsmob_grob (p);
129
130   string r = to_string (Paper_column::get_rank (me));
131
132   Moment *mom = unsmob_moment (me->get_property ("when"));
133   string when = mom ? mom->to_string () : "?/?";
134
135   SCM properties = Font_interface::text_font_alist_chain (me);
136
137   SCM scm_mol = Text_interface::interpret_markup (me->layout ()->self_scm (),
138                                                   properties,
139                                                   scm_makfrom0str (r.c_str ()));
140   SCM when_mol = Text_interface::interpret_markup (me->layout ()->self_scm (),
141                                                    properties,
142                                                    scm_makfrom0str (when.c_str ()));
143   Stencil t = *unsmob_stencil (scm_mol);
144   t.add_at_edge (Y_AXIS, DOWN, *unsmob_stencil (when_mol), 0.1, 0.1);
145   t.align_to (X_AXIS, CENTER);
146   t.align_to (Y_AXIS, DOWN);
147
148   Stencil l = Lookup::filled_box (Box (Interval (-0.01, 0.01),
149                                        Interval (-2, -1)));
150
151   t.add_stencil (l);
152   return t.smobbed_copy ();
153 }
154
155 /*
156   This is all too hairy. We use bounded-by-me to make sure that some
157   columns are kept "alive". Unfortunately, when spanners are suicided,
158   this falls apart again, because suicided spanners are still in
159   bounded-by-me
160
161   THIS IS BROKEN KLUDGE. WE SHOULD INVENT SOMETHING BETTER.
162 */
163 MAKE_SCHEME_CALLBACK (Paper_column, before_line_breaking, 1);
164 SCM
165 Paper_column::before_line_breaking (SCM grob)
166 {
167   Grob *me = unsmob_grob (grob);
168
169   SCM bbm = me->get_object ("bounded-by-me");
170   Grob_array *ga = unsmob_grob_array (bbm);
171   if (!ga)
172     return SCM_UNSPECIFIED;
173
174   vector<Grob*> &array (ga->array_reference ());
175
176   for (vsize i = array.size (); i--;)
177     {
178       Grob *g = array[i];
179
180       if (!g || !g->is_live ())
181         /* UGH . potentially quadratic. */
182         array.erase (array.begin () + i);
183     }
184
185   return SCM_UNSPECIFIED;
186 }
187
188
189 ADD_INTERFACE (Paper_column,
190
191                "paper-column-interface",
192                "@code{Paper_column} objects form the top-most X-parents for items."
193                "  The are two types of columns: musical columns, where are attached to, and "
194                "  non-musical columns, where bar-lines, clefs etc. are attached to. "
195                "  The spacing engine determines the X-positions of these objects."
196                
197                "\n\n"
198                "They are\n"
199                "  numbered, the first (leftmost) is column 0. Numbering happens before\n"
200                "  line-breaking, and columns are not renumbered after line breaking.\n"
201                "  Since many columns go unused, you should only use the rank field to\n"
202                "  get ordering information.  Two adjacent columns may have\n"
203                "  non-adjacent numbers.\n",
204                
205
206                /* properties */
207                "between-cols "
208                "bounded-by-me "
209                "grace-spacing " 
210                "line-break-system-details "
211                "line-break-penalty "
212                "line-break-permission "
213                "page-break-penalty "
214                "page-break-permission "
215                "page-turn-penalty "
216                "page-turn-permission "
217                "shortest-playing-duration "
218                "shortest-starter-duration "
219                "used "
220                "when ");
221