]> git.donarmstrong.com Git - lilypond.git/blob - lily/axis-group-engraver.cc
* lily/system.cc (do_derived_mark): don't mark from object_alist_
[lilypond.git] / lily / axis-group-engraver.cc
1 /*
2   axis-group-engraver.cc -- implement Axis_group_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1999--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "axis-group-engraver.hh"
10
11 #include "spanner.hh"
12 #include "paper-column.hh"
13 #include "axis-group-interface.hh"
14 #include "engraver-group-engraver.hh"
15 #include "warn.hh"
16 #include "context.hh"
17
18 Axis_group_engraver::Axis_group_engraver ()
19 {
20   must_be_last_ = true;
21   staffline_ = 0;
22 }
23
24 void
25 Axis_group_engraver::process_music ()
26 {
27   if (!staffline_)
28     {
29       staffline_ = get_spanner ();
30       Grob *it = unsmob_grob (get_property ("currentCommandColumn"));
31       staffline_->set_bound (LEFT, it);
32     }
33 }
34
35 Spanner *
36 Axis_group_engraver::get_spanner ()
37 {
38   return make_spanner ("VerticalAxisGroup", SCM_EOL);
39 }
40
41 /*
42   TODO: should we junk minimumVerticalExtent/extraVerticalExtent ?
43 */
44
45 void
46 Axis_group_engraver::finalize ()
47 {
48   if (!staffline_)
49     return;
50
51   String type = context ()->context_name ();
52   SCM dims = get_property ("verticalExtent");
53
54   if (is_number_pair (dims))
55     staffline_->set_extent (dims, Y_AXIS);
56
57   dims = get_property ("minimumVerticalExtent");
58   if (is_number_pair (dims))
59     staffline_->set_property ("minimum-Y-extent", dims);
60
61   dims = get_property ("extraVerticalExtent");
62   if (is_number_pair (dims))
63     staffline_->set_property ("extra-Y-extent", dims);
64
65   Grob *it = unsmob_grob (get_property ("currentCommandColumn"));
66
67   staffline_->set_bound (RIGHT, it);
68
69   staffline_ = 0;
70 }
71
72 void
73 Axis_group_engraver::acknowledge_grob (Grob_info i)
74 {
75   elts_.push (i.grob ());
76 }
77
78 /*
79   maybe should check if our parent is set, because we now get a
80   cyclic parent relationship if we have two Axis_group_engravers in
81   the context.  */
82 void
83 Axis_group_engraver::process_acknowledged_grobs ()
84 {
85   if (!staffline_)
86     return;
87
88   for (int i = 0; i < elts_.size (); i++)
89     {
90       if (!unsmob_grob (elts_[i]->get_object ("axis-group-parent-Y")))
91         {
92           if (staffline_->get_parent (Y_AXIS)
93               && staffline_->get_parent (Y_AXIS) == elts_[i])
94             {
95               staffline_->warning (_ ("Axis_group_engraver: vertical group already has a parent"));
96               staffline_->warning (_ ("are there two Axis_group_engravers?"));
97               staffline_->warning (_ ("removing this vertical group"));
98               staffline_->suicide ();
99               staffline_ = 0;
100               break;
101             }
102           else if (elts_[i]->is_empty (Y_AXIS))
103             {
104               /*
105                 We have to do _something_, otherwise staff objects will
106                 end up with System as parent.
107
108               */
109               elts_[i]->set_parent (staffline_, Y_AXIS);
110             }
111           else
112             add_element (elts_[i]);
113         }
114     }
115   elts_.clear ();
116 }
117
118 void
119 Axis_group_engraver::add_element (Grob *e)
120 {
121   Axis_group_interface::add_element (staffline_, e);
122 }
123
124 ADD_TRANSLATOR (Axis_group_engraver,
125                 /* descr */ "Group all objects created in this context in a VerticalAxisGroup spanner.",
126                 /* creats*/ "VerticalAxisGroup",
127                 /* accepts */ "",
128                 /* acks  */ "grob-interface",
129                 /* reads */ "verticalExtent minimumVerticalExtent extraVerticalExtent",
130                 /* write */ "");