]> git.donarmstrong.com Git - lilypond.git/blob - lily/separating-line-group-engraver.cc
Issue 4550 (1/2) Avoid "using namespace std;" in included files
[lilypond.git] / lily / separating-line-group-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1998--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "engraver.hh"
21
22 #include "separation-item.hh"
23 #include "paper-column.hh"
24 #include "output-def.hh"
25 #include "axis-group-interface.hh"
26 #include "note-spacing.hh"
27 #include "accidental-placement.hh"
28 #include "context.hh"
29 #include "spanner.hh"
30 #include "grob-array.hh"
31 #include "pointer-group-interface.hh"
32
33 #include "translator.icc"
34
35 using std::vector;
36
37 struct Spacings
38 {
39   Item *staff_spacing_;
40   vector<Item *> note_spacings_;
41
42   Spacings ()
43   {
44     staff_spacing_ = 0;
45   }
46
47   bool is_empty () const
48   {
49     return !staff_spacing_ && !note_spacings_.size ();
50   }
51   void clear ()
52   {
53     staff_spacing_ = 0;
54     note_spacings_.clear ();
55   }
56 };
57
58 class Separating_line_group_engraver : public Engraver
59 {
60 protected:
61   Spacings current_spacings_;
62   Spacings last_spacings_;
63
64   DECLARE_ACKNOWLEDGER (item);
65   DECLARE_ACKNOWLEDGER (break_aligned);
66   void stop_translation_timestep ();
67   void start_translation_timestep ();
68
69   vector<Grob *> break_aligned_;
70 public:
71   TRANSLATOR_DECLARATIONS (Separating_line_group_engraver);
72 };
73
74 Separating_line_group_engraver::Separating_line_group_engraver ()
75 {
76 }
77
78 void
79 Separating_line_group_engraver::acknowledge_item (Grob_info i)
80 {
81   Item *it = i.item ();
82
83   if (has_interface<Note_spacing> (it))
84     {
85       current_spacings_.note_spacings_.push_back (it);
86       return;
87     }
88
89   if (Item::is_non_musical (it)
90       && !current_spacings_.staff_spacing_
91       && to_boolean (get_property ("createSpacing")))
92     {
93       Grob *col = unsmob<Grob> (get_property ("currentCommandColumn"));
94
95       current_spacings_.staff_spacing_ = make_item ("StaffSpacing", SCM_EOL);
96       context ()->set_property ("hasStaffSpacing", SCM_BOOL_T);
97
98       Pointer_group_interface::add_grob (current_spacings_.staff_spacing_,
99                                          ly_symbol2scm ("left-items"),
100                                          col);
101
102       if (!last_spacings_.note_spacings_.size ()
103           && last_spacings_.staff_spacing_)
104         {
105           SCM ri = last_spacings_.staff_spacing_->get_object ("right-items");
106           Grob_array *ga = unsmob<Grob_array> (ri);
107           if (!ga)
108             {
109               SCM ga_scm = Grob_array::make_array ();
110               last_spacings_.staff_spacing_->set_object ("right-items", ga_scm);
111               ga = unsmob<Grob_array> (ga_scm);
112             }
113
114           ga->clear ();
115           ga->add (col);
116         }
117     }
118 }
119
120 void
121 Separating_line_group_engraver::acknowledge_break_aligned (Grob_info gi)
122 {
123   break_aligned_.push_back (gi.grob ());
124 }
125
126 void
127 Separating_line_group_engraver::start_translation_timestep ()
128 {
129   context ()->unset_property (ly_symbol2scm ("hasStaffSpacing"));
130 }
131
132 void
133 Separating_line_group_engraver::stop_translation_timestep ()
134 {
135   for (vsize i = 0; i < break_aligned_.size (); i++)
136     {
137       SCM smob = break_aligned_[i]->self_scm ();
138
139       if (Item *sp = current_spacings_.staff_spacing_)
140         Pointer_group_interface::add_grob (sp, ly_symbol2scm ("left-break-aligned"), smob);
141
142       for (vsize j = 0; j < last_spacings_.note_spacings_.size (); j++)
143         Pointer_group_interface::add_grob (last_spacings_.note_spacings_[j],
144                                            ly_symbol2scm ("right-break-aligned"), smob);
145     }
146
147   if (!current_spacings_.is_empty ())
148     last_spacings_ = current_spacings_;
149
150   if (Item *sp = current_spacings_.staff_spacing_)
151     if (Grob *col = unsmob<Grob> (get_property ("currentMusicalColumn")))
152       Pointer_group_interface::add_grob (sp, ly_symbol2scm ("right-items"), col);
153
154   current_spacings_.clear ();
155   break_aligned_.clear ();
156 }
157
158 ADD_ACKNOWLEDGER (Separating_line_group_engraver, item);
159 ADD_ACKNOWLEDGER (Separating_line_group_engraver, break_aligned);
160
161 ADD_TRANSLATOR (Separating_line_group_engraver,
162                 /* doc */
163                 "Generate objects for computing spacing parameters.",
164
165                 /* create */
166                 "StaffSpacing ",
167
168                 /* read */
169                 "createSpacing ",
170
171                 /* write */
172                 "hasStaffSpacing "
173                );