]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-spacing-engraver.cc
Issue 4550 (1/2) Avoid "using namespace std;" in included files
[lilypond.git] / lily / note-spacing-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2006--2015 Han-Wen Nienhuys <hanwen@lilypond.org>
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 "grob-array.hh"
23 #include "context.hh"
24 #include "item.hh"
25 #include "pointer-group-interface.hh"
26
27 #include <map>
28
29 #include "translator.icc"
30
31 using std::map;
32
33 class Note_spacing_engraver : public Engraver
34 {
35   typedef map <Context *, Grob *> Last_spacing_map;
36   Last_spacing_map last_spacings_;
37   Grob *last_spacing_;
38
39   Grob *spacing_;
40
41   void add_spacing_item (Grob *);
42   TRANSLATOR_DECLARATIONS (Note_spacing_engraver);
43 protected:
44
45   DECLARE_ACKNOWLEDGER (rhythmic_grob);
46   DECLARE_ACKNOWLEDGER (note_column);
47   void stop_translation_timestep ();
48   virtual void finalize ();
49   virtual void derived_mark () const;
50 };
51
52 void
53 Note_spacing_engraver::derived_mark () const
54 {
55   for (Last_spacing_map::const_iterator i = last_spacings_.begin ();
56        i != last_spacings_.end (); i++)
57     scm_gc_mark (i->first->self_scm ());
58 }
59
60 Note_spacing_engraver::Note_spacing_engraver ()
61 {
62   spacing_ = 0;
63   last_spacing_ = 0;
64 }
65
66 void
67 Note_spacing_engraver::add_spacing_item (Grob *g)
68 {
69   if (!spacing_)
70     {
71       spacing_ = make_item ("NoteSpacing", g->self_scm ());
72     }
73
74   if (spacing_)
75     {
76       Pointer_group_interface::add_grob (spacing_,
77                                          ly_symbol2scm ("left-items"),
78                                          g);
79
80       if (last_spacing_)
81         Pointer_group_interface::add_grob (last_spacing_,
82                                            ly_symbol2scm ("right-items"),
83                                            g);
84     }
85 }
86
87 void
88 Note_spacing_engraver::acknowledge_note_column (Grob_info gi)
89 {
90   add_spacing_item (gi.grob ());
91 }
92
93 void
94 Note_spacing_engraver::acknowledge_rhythmic_grob (Grob_info gi)
95 {
96   add_spacing_item (gi.grob ());
97 }
98
99 void
100 Note_spacing_engraver::finalize ()
101 {
102   Context *parent = context ()->get_parent_context ();
103   Grob *last_spacing = last_spacings_[parent];
104
105   if (last_spacing
106       && !unsmob<Grob_array> (last_spacing->get_object ("right-items")))
107     {
108       Grob *col = unsmob<Grob> (get_property ("currentCommandColumn"));
109
110       Pointer_group_interface::add_grob (last_spacing,
111                                          ly_symbol2scm ("right-items"),
112                                          col);
113     }
114 }
115
116 void
117 Note_spacing_engraver::stop_translation_timestep ()
118 {
119   Context *parent = context ()->get_parent_context ();
120   Grob *last_spacing = last_spacings_[parent];
121
122   if (last_spacing
123       && to_boolean (get_property ("hasStaffSpacing")))
124     {
125       Grob *col = unsmob<Grob> (get_property ("currentCommandColumn"));
126       Pointer_group_interface::add_grob (last_spacing,
127                                          ly_symbol2scm ("right-items"),
128                                          col);
129     }
130
131   if (spacing_)
132     {
133       last_spacings_[parent] = spacing_;
134       last_spacing_ = spacing_;
135       spacing_ = 0;
136     }
137
138 }
139
140 ADD_ACKNOWLEDGER (Note_spacing_engraver, note_column);
141 ADD_ACKNOWLEDGER (Note_spacing_engraver, rhythmic_grob);
142
143 ADD_TRANSLATOR (Note_spacing_engraver,
144                 /* doc */
145                 "Generate @code{NoteSpacing}, an object linking horizontal"
146                 " lines for use in spacing.",
147
148                 /* create */
149                 "NoteSpacing ",
150
151                 /* read */
152                 "",
153
154                 /* write */
155                 ""
156                );