]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-engraver.cc
Issue 4550 (1/2) Avoid "using namespace std;" in included files
[lilypond.git] / lily / text-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 "directional-element-interface.hh"
21 #include "engraver.hh"
22 #include "item.hh"
23 #include "note-column.hh"
24 #include "pointer-group-interface.hh"
25 #include "side-position-interface.hh"
26 #include "stream-event.hh"
27 #include "text-interface.hh"
28
29 #include "translator.icc"
30
31 using std::vector;
32
33 /**
34    typeset directions that are  plain text.
35 */
36
37 class Text_engraver : public Engraver
38 {
39   vector<Stream_event *> evs_;
40   vector<Grob *> scripts_;
41 public:
42   TRANSLATOR_DECLARATIONS (Text_engraver);
43 protected:
44   void stop_translation_timestep ();
45   void process_music ();
46
47   DECLARE_ACKNOWLEDGER (note_column);
48   DECLARE_TRANSLATOR_LISTENER (text_script);
49 };
50
51 IMPLEMENT_TRANSLATOR_LISTENER (Text_engraver, text_script);
52 void
53 Text_engraver::listen_text_script (Stream_event *ev)
54 {
55   evs_.push_back (ev);
56 }
57
58 void
59 Text_engraver::process_music ()
60 {
61   for (vsize i = 0; i < evs_.size (); i++)
62     {
63       Stream_event *ev = evs_[i];
64
65       Item *script = make_item ("TextScript", ev->self_scm ());
66       scripts_.push_back (script);
67
68       int priority = robust_scm2int (script->get_property ("script-priority"),
69                                      200);
70
71       /* see script-engraver.cc */
72       priority += i;
73
74       script->set_property ("script-priority", scm_from_int (priority));
75
76       Direction dir = to_dir (ev->get_property ("direction"));
77       if (dir)
78         set_grob_direction (script, dir);
79
80       SCM mark = ev->get_property ("text");
81
82       script->set_property ("text", mark);
83     }
84 }
85
86 void
87 Text_engraver::acknowledge_note_column (Grob_info info)
88 {
89   // Make note column (or rest, if there are no heads) the parent of the script.
90   extract_grob_set (info.grob (), "note-heads", heads);
91   Grob *x_parent = (heads.size ()
92                     ? info.grob ()
93                     : unsmob<Grob> (info.grob ()->get_object ("rest")));
94
95   for (vsize i = 0; i < scripts_.size (); i++)
96     {
97       Grob *el = scripts_[i];
98
99       if (el && !el->get_parent (X_AXIS) && x_parent)
100         el->set_parent (x_parent, X_AXIS);
101     }
102 }
103
104 void
105 Text_engraver::stop_translation_timestep ()
106 {
107   evs_.clear ();
108   scripts_.clear ();
109 }
110
111 Text_engraver::Text_engraver ()
112 {
113 }
114
115 ADD_ACKNOWLEDGER (Text_engraver, note_column);
116
117 ADD_TRANSLATOR (Text_engraver,
118                 /* doc */
119                 "Create text scripts.",
120
121                 /* create */
122                 "TextScript ",
123
124                 /* read */
125                 "",
126
127                 /* write */
128                 ""
129                );