]> git.donarmstrong.com Git - lilypond.git/blob - lily/script-row-engraver.cc
Issue 4550 (1/2) Avoid "using namespace std;" in included files
[lilypond.git] / lily / script-row-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
7   LilyPond is free software: you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11
12   LilyPond is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "engraver.hh"
22
23 #include "accidental-placement.hh"
24 #include "item.hh"
25 #include "script-column.hh"
26 #include "side-position-interface.hh"
27
28 #include "translator.icc"
29
30 using std::vector;
31
32 /**
33    Find potentially colliding scripts, and put them in a
34    Script_row
35 */
36 class Script_row_engraver : public Engraver
37 {
38   Grob *script_row_;
39   vector<Grob *> scripts_;
40
41 public:
42   TRANSLATOR_DECLARATIONS (Script_row_engraver);
43 protected:
44   DECLARE_ACKNOWLEDGER (accidental_placement);
45   DECLARE_ACKNOWLEDGER (side_position);
46   void process_acknowledged ();
47   void stop_translation_timestep ();
48 };
49
50 Script_row_engraver::Script_row_engraver ()
51 {
52   script_row_ = 0;
53 }
54
55 void
56 Script_row_engraver::stop_translation_timestep ()
57 {
58   if (script_row_)
59     {
60       for (vsize i = 0; i < scripts_.size (); i++)
61         if (has_interface<Accidental_placement> (scripts_[i])
62             || Side_position_interface::get_axis (scripts_[i]) == X_AXIS)
63           Script_column::add_side_positioned (script_row_, scripts_[i]);
64     }
65
66   scripts_.clear ();
67   script_row_ = 0;
68 }
69
70 void
71 Script_row_engraver::acknowledge_side_position (Grob_info inf)
72 {
73   Item *thing = dynamic_cast<Item *> (inf.grob ());
74   if (thing)
75     {
76       if (!Item::is_non_musical (thing))
77         scripts_.push_back (thing);
78     }
79 }
80
81 void
82 Script_row_engraver::acknowledge_accidental_placement (Grob_info inf)
83 {
84   scripts_.push_back (inf.grob ());
85 }
86
87 void
88 Script_row_engraver::process_acknowledged ()
89 {
90   if (!script_row_ && scripts_.size () > 1)
91     script_row_ = make_item ("ScriptRow", SCM_EOL);
92 }
93
94 ADD_ACKNOWLEDGER (Script_row_engraver, accidental_placement);
95 ADD_ACKNOWLEDGER (Script_row_engraver, side_position);
96 ADD_TRANSLATOR (Script_row_engraver,
97                 /* doc */
98                 "Determine order in horizontal side position elements.",
99
100                 /* create */
101                 "ScriptRow ",
102
103                 /* read */
104                 "",
105
106                 /* write */
107                 ""
108                );