Use scalar instead of embedded_scm for context mod overrides.
[lilypond/mpolesky.git] / lily / separating-line-group-engraver.cc
blob38bb5a3b402a429d4ebe7e6779217089c80b55a3
1 /*
2 separating-line-group-engraver.cc -- implement Separating_line_group_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "engraver.hh"
11 #include "separation-item.hh"
12 #include "paper-column.hh"
13 #include "output-def.hh"
14 #include "axis-group-interface.hh"
15 #include "note-spacing.hh"
16 #include "accidental-placement.hh"
17 #include "context.hh"
18 #include "spanner.hh"
19 #include "grob-array.hh"
20 #include "pointer-group-interface.hh"
22 #include "translator.icc"
24 struct Spacings
26 Item *staff_spacing_;
27 vector<Item*> note_spacings_;
29 Spacings ()
31 staff_spacing_ = 0;
34 bool is_empty () const
36 return !staff_spacing_ && !note_spacings_.size ();
38 void clear ()
40 staff_spacing_ = 0;
41 note_spacings_.clear ();
45 class Separating_line_group_engraver : public Engraver
47 protected:
48 Spacings current_spacings_;
49 Spacings last_spacings_;
51 DECLARE_ACKNOWLEDGER (item);
52 DECLARE_ACKNOWLEDGER (break_aligned);
53 void stop_translation_timestep ();
54 void start_translation_timestep ();
56 vector<Grob*> break_aligned_;
57 public:
58 TRANSLATOR_DECLARATIONS (Separating_line_group_engraver);
61 Separating_line_group_engraver::Separating_line_group_engraver ()
65 void
66 Separating_line_group_engraver::acknowledge_item (Grob_info i)
68 Item *it = i.item ();
70 if (Note_spacing::has_interface (it))
72 current_spacings_.note_spacings_.push_back (it);
73 return;
76 if (Item::is_non_musical (it)
77 && !current_spacings_.staff_spacing_
78 && to_boolean (get_property ("createSpacing")))
80 Grob *col = unsmob_grob (get_property ("currentCommandColumn"));
82 current_spacings_.staff_spacing_ = make_item ("StaffSpacing", SCM_EOL);
83 context ()->set_property ("hasStaffSpacing", SCM_BOOL_T);
85 Pointer_group_interface::add_grob (current_spacings_.staff_spacing_,
86 ly_symbol2scm ("left-items"),
87 col);
89 if (!last_spacings_.note_spacings_.size ()
90 && last_spacings_.staff_spacing_)
92 SCM ri = last_spacings_.staff_spacing_->get_object ("right-items");
93 Grob_array *ga = unsmob_grob_array (ri);
94 if (!ga)
96 SCM ga_scm = Grob_array::make_array ();
97 last_spacings_.staff_spacing_->set_object ("right-items", ga_scm);
98 ga = unsmob_grob_array (ga_scm);
101 ga->clear ();
102 ga->add (col);
107 void
108 Separating_line_group_engraver::acknowledge_break_aligned (Grob_info gi)
110 break_aligned_.push_back (gi.grob ());
113 void
114 Separating_line_group_engraver::start_translation_timestep ()
116 context ()->unset_property (ly_symbol2scm ("hasStaffSpacing"));
119 void
120 Separating_line_group_engraver::stop_translation_timestep ()
122 for (vsize i = 0; i < break_aligned_.size (); i++)
124 SCM smob = break_aligned_[i]->self_scm ();
126 if (Item *sp = current_spacings_.staff_spacing_)
127 Pointer_group_interface::add_grob (sp, ly_symbol2scm ("left-break-aligned"), smob);
129 for (vsize j = 0; j < last_spacings_.note_spacings_.size (); j++)
130 Pointer_group_interface::add_grob (last_spacings_.note_spacings_[j],
131 ly_symbol2scm ("right-break-aligned"), smob);
134 if (!current_spacings_.is_empty ())
135 last_spacings_ = current_spacings_;
137 if (Item *sp = current_spacings_.staff_spacing_)
138 if (Grob *col = unsmob_grob (get_property ("currentMusicalColumn")))
139 Pointer_group_interface::add_grob (sp, ly_symbol2scm ("right-items"), col);
141 current_spacings_.clear ();
142 break_aligned_.clear ();
145 ADD_ACKNOWLEDGER (Separating_line_group_engraver, item);
146 ADD_ACKNOWLEDGER (Separating_line_group_engraver, break_aligned);
148 ADD_TRANSLATOR (Separating_line_group_engraver,
149 /* doc */
150 "Generate objects for computing spacing parameters.",
152 /* create */
153 "StaffSpacing ",
155 /* read */
156 "createSpacing ",
158 /* write */
159 "hasStaffSpacing "