]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-engraver.cc
unsmob_pitch -> Pitch::unsmob and related
[lilypond.git] / lily / text-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1998--2014 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 /**
32    typeset directions that are  plain text.
33 */
34
35 class Text_engraver : public Engraver
36 {
37   vector<Stream_event *> evs_;
38   vector<Grob *> scripts_;
39 public:
40   TRANSLATOR_DECLARATIONS (Text_engraver);
41 protected:
42   void stop_translation_timestep ();
43   void process_music ();
44
45   DECLARE_ACKNOWLEDGER (note_column);
46   DECLARE_TRANSLATOR_LISTENER (text_script);
47 };
48
49 IMPLEMENT_TRANSLATOR_LISTENER (Text_engraver, text_script);
50 void
51 Text_engraver::listen_text_script (Stream_event *ev)
52 {
53   evs_.push_back (ev);
54 }
55
56 void
57 Text_engraver::process_music ()
58 {
59   for (vsize i = 0; i < evs_.size (); i++)
60     {
61       Stream_event *ev = evs_[i];
62
63       Item *script = make_item ("TextScript", ev->self_scm ());
64       scripts_.push_back (script);
65
66       int priority = robust_scm2int (script->get_property ("script-priority"),
67                                      200);
68
69       /* see script-engraver.cc */
70       priority += i;
71
72       script->set_property ("script-priority", scm_from_int (priority));
73
74       Direction dir = to_dir (ev->get_property ("direction"));
75       if (dir)
76         set_grob_direction (script, dir);
77
78       SCM mark = ev->get_property ("text");
79
80       script->set_property ("text", mark);
81     }
82 }
83
84 void
85 Text_engraver::acknowledge_note_column (Grob_info info)
86 {
87   // Make note column (or rest, if there are no heads) the parent of the script.
88   extract_grob_set (info.grob (), "note-heads", heads);
89   Grob *x_parent = (heads.size ()
90                     ? info.grob ()
91                     : Grob::unsmob (info.grob ()->get_object ("rest")));
92
93   for (vsize i = 0; i < scripts_.size (); i++)
94     {
95       Grob *el = scripts_[i];
96
97       if (el && !el->get_parent (X_AXIS) && x_parent)
98         el->set_parent (x_parent, X_AXIS);
99     }
100 }
101
102 void
103 Text_engraver::stop_translation_timestep ()
104 {
105   evs_.clear ();
106   scripts_.clear ();
107 }
108
109 Text_engraver::Text_engraver ()
110 {
111 }
112
113 ADD_ACKNOWLEDGER (Text_engraver, note_column);
114
115 ADD_TRANSLATOR (Text_engraver,
116                 /* doc */
117                 "Create text scripts.",
118
119                 /* create */
120                 "TextScript ",
121
122                 /* read */
123                 "",
124
125                 /* write */
126                 ""
127                );