]> git.donarmstrong.com Git - lilypond.git/blob - lily/separating-line-group-engraver.cc
Doc-es: update Vocal.
[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--2011 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 struct Spacings
36 {
37   Item *staff_spacing_;
38   vector<Item *> note_spacings_;
39
40   Spacings ()
41   {
42     staff_spacing_ = 0;
43   }
44
45   bool is_empty () const
46   {
47     return !staff_spacing_ && !note_spacings_.size ();
48   }
49   void clear ()
50   {
51     staff_spacing_ = 0;
52     note_spacings_.clear ();
53   }
54 };
55
56 class Separating_line_group_engraver : public Engraver
57 {
58 protected:
59   Spacings current_spacings_;
60   Spacings last_spacings_;
61
62   DECLARE_ACKNOWLEDGER (item);
63   DECLARE_ACKNOWLEDGER (break_aligned);
64   void stop_translation_timestep ();
65   void start_translation_timestep ();
66
67   vector<Grob *> break_aligned_;
68 public:
69   TRANSLATOR_DECLARATIONS (Separating_line_group_engraver);
70 };
71
72 Separating_line_group_engraver::Separating_line_group_engraver ()
73 {
74 }
75
76 void
77 Separating_line_group_engraver::acknowledge_item (Grob_info i)
78 {
79   Item *it = i.item ();
80
81   if (Note_spacing::has_interface (it))
82     {
83       current_spacings_.note_spacings_.push_back (it);
84       return;
85     }
86
87   if (Item::is_non_musical (it)
88       && !current_spacings_.staff_spacing_
89       && to_boolean (get_property ("createSpacing")))
90     {
91       Grob *col = unsmob_grob (get_property ("currentCommandColumn"));
92
93       current_spacings_.staff_spacing_ = make_item ("StaffSpacing", SCM_EOL);
94       context ()->set_property ("hasStaffSpacing", SCM_BOOL_T);
95
96       Pointer_group_interface::add_grob (current_spacings_.staff_spacing_,
97                                          ly_symbol2scm ("left-items"),
98                                          col);
99
100       if (!last_spacings_.note_spacings_.size ()
101           && last_spacings_.staff_spacing_)
102         {
103           SCM ri = last_spacings_.staff_spacing_->get_object ("right-items");
104           Grob_array *ga = unsmob_grob_array (ri);
105           if (!ga)
106             {
107               SCM ga_scm = Grob_array::make_array ();
108               last_spacings_.staff_spacing_->set_object ("right-items", ga_scm);
109               ga = unsmob_grob_array (ga_scm);
110             }
111
112           ga->clear ();
113           ga->add (col);
114         }
115     }
116 }
117
118 void
119 Separating_line_group_engraver::acknowledge_break_aligned (Grob_info gi)
120 {
121   break_aligned_.push_back (gi.grob ());
122 }
123
124 void
125 Separating_line_group_engraver::start_translation_timestep ()
126 {
127   context ()->unset_property (ly_symbol2scm ("hasStaffSpacing"));
128 }
129
130 void
131 Separating_line_group_engraver::stop_translation_timestep ()
132 {
133   for (vsize i = 0; i < break_aligned_.size (); i++)
134     {
135       SCM smob = break_aligned_[i]->self_scm ();
136
137       if (Item *sp = current_spacings_.staff_spacing_)
138         Pointer_group_interface::add_grob (sp, ly_symbol2scm ("left-break-aligned"), smob);
139
140       for (vsize j = 0; j < last_spacings_.note_spacings_.size (); j++)
141         Pointer_group_interface::add_grob (last_spacings_.note_spacings_[j],
142                                            ly_symbol2scm ("right-break-aligned"), smob);
143     }
144
145   if (!current_spacings_.is_empty ())
146     last_spacings_ = current_spacings_;
147
148   if (Item *sp = current_spacings_.staff_spacing_)
149     if (Grob *col = unsmob_grob (get_property ("currentMusicalColumn")))
150       Pointer_group_interface::add_grob (sp, ly_symbol2scm ("right-items"), col);
151
152   current_spacings_.clear ();
153   break_aligned_.clear ();
154 }
155
156 ADD_ACKNOWLEDGER (Separating_line_group_engraver, item);
157 ADD_ACKNOWLEDGER (Separating_line_group_engraver, break_aligned);
158
159 ADD_TRANSLATOR (Separating_line_group_engraver,
160                 /* doc */
161                 "Generate objects for computing spacing parameters.",
162
163                 /* create */
164                 "StaffSpacing ",
165
166                 /* read */
167                 "createSpacing ",
168
169                 /* write */
170                 "hasStaffSpacing "
171                );