]> git.donarmstrong.com Git - lilypond.git/blob - lily/script-row-engraver.cc
Run grand-replace (issue 3765)
[lilypond.git] / lily / script-row-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2006--2014 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 /**
31    Find potentially colliding scripts, and put them in a
32    Script_row
33 */
34 class Script_row_engraver : public Engraver
35 {
36   Grob *script_row_;
37   vector<Grob *> scripts_;
38
39 public:
40   TRANSLATOR_DECLARATIONS (Script_row_engraver);
41 protected:
42   DECLARE_ACKNOWLEDGER (accidental_placement);
43   DECLARE_ACKNOWLEDGER (side_position);
44   void process_acknowledged ();
45   void stop_translation_timestep ();
46 };
47
48 Script_row_engraver::Script_row_engraver ()
49 {
50   script_row_ = 0;
51 }
52
53 void
54 Script_row_engraver::stop_translation_timestep ()
55 {
56   if (script_row_)
57     {
58       for (vsize i = 0; i < scripts_.size (); i++)
59         if (Accidental_placement::has_interface (scripts_[i])
60             || Side_position_interface::get_axis (scripts_[i]) == X_AXIS)
61           Script_column::add_side_positioned (script_row_, scripts_[i]);
62     }
63
64   scripts_.clear ();
65   script_row_ = 0;
66 }
67
68 void
69 Script_row_engraver::acknowledge_side_position (Grob_info inf)
70 {
71   Item *thing = dynamic_cast<Item *> (inf.grob ());
72   if (thing)
73     {
74       if (!Item::is_non_musical (thing))
75         scripts_.push_back (thing);
76     }
77 }
78
79 void
80 Script_row_engraver::acknowledge_accidental_placement (Grob_info inf)
81 {
82   scripts_.push_back (inf.grob ());
83 }
84
85 void
86 Script_row_engraver::process_acknowledged ()
87 {
88   if (!script_row_ && scripts_.size () > 1)
89     script_row_ = make_item ("ScriptRow", SCM_EOL);
90 }
91
92 ADD_ACKNOWLEDGER (Script_row_engraver, accidental_placement);
93 ADD_ACKNOWLEDGER (Script_row_engraver, side_position);
94 ADD_TRANSLATOR (Script_row_engraver,
95                 /* doc */
96                 "Determine order in horizontal side position elements.",
97
98                 /* create */
99                 "ScriptRow ",
100
101                 /* read */
102                 "",
103
104                 /* write */
105                 ""
106                );